Exemple #1
0
struct VFile* VFileMemChunk(const void* mem, size_t size) {
	struct VFileMem* vfm = malloc(sizeof(struct VFileMem));
	if (!vfm) {
		return 0;
	}

	vfm->size = size;
	vfm->bufferSize = toPow2(size);
	if (size) {
		vfm->mem = anonymousMemoryMap(vfm->bufferSize);
		if (mem) {
			memcpy(vfm->mem, mem, size);
		}
	} else {
		vfm->mem = 0;
	}
	vfm->offset = 0;
	vfm->d.close = _vfmCloseFree;
	vfm->d.seek = _vfmSeekExpanding;
	vfm->d.read = _vfmRead;
	vfm->d.readline = VFileReadline;
	vfm->d.write = _vfmWriteExpanding;
	vfm->d.map = _vfmMap;
	vfm->d.unmap = _vfmUnmap;
	vfm->d.truncate = _vfmTruncate;
	vfm->d.size = _vfmSize;
	vfm->d.sync = _vfmSync;

	return &vfm->d;
}
Exemple #2
0
bool TextureOpenGL::create_from_surface(ISurface *p_surface)
{
    destroy();

	const u32 width  = p_surface->get_width();
	const u32 height = p_surface->get_height();
    const u32 size   = toPow2( (width < height) ? height : width );
	SurfaceSDL surface_rgb;
	bool success = surface_rgb.create_empty(size, size, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
    
    if ( !success ) {
        printf("failed create surface\n");
		return false;
    }
    
	surface_rgb.blit(static_cast<ISurface*>(p_surface), NULL, NULL);
    if ( !success ) {
        printf("failed blit surface\n");
		return false;
    }
    
    GLuint tex = _create_from_surface(&surface_rgb);
    m_tex_name    = tex;
    m_desc.width  = surface_rgb.get_width();
    m_desc.height = surface_rgb.get_height();
	return true;
}
Exemple #3
0
static void mGLContextSetDimensions(struct VideoBackend* v, unsigned width, unsigned height) {
	struct mGLContext* context = (struct mGLContext*) v;
	v->width = width;
	v->height = height;

	glBindTexture(GL_TEXTURE_2D, context->tex);
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, toPow2(width), toPow2(height), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
#else
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, toPow2(width), toPow2(height), 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0);
#endif
#elif defined(__BIG_ENDIAN__)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, toPow2(width), toPow2(height), 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
#else
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, toPow2(width), toPow2(height), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
#endif
}
Exemple #4
0
void _vfmExpand(struct VFileMem* vfm, size_t newSize) {
	size_t alignedSize = toPow2(newSize);
	if (alignedSize > vfm->bufferSize) {
		void* oldBuf = vfm->mem;
		vfm->mem = anonymousMemoryMap(alignedSize);
		if (oldBuf) {
			if (newSize < vfm->size) {
				memcpy(vfm->mem, oldBuf, newSize);
			} else {
				memcpy(vfm->mem, oldBuf, vfm->size);
			}
			mappedMemoryFree(oldBuf, vfm->bufferSize);
		}
		vfm->bufferSize = alignedSize;
	}
	vfm->size = newSize;
}
Exemple #5
0
static inline U32
bhv_msk(U32 sz)
{
  return toPow2(sz)-1;
}