feat: allow mixed texture allocation
This commit is contained in:
parent
5ff3bf0b13
commit
bb89a40678
|
@ -228,7 +228,11 @@ void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit) {
|
||||||
if(enableMipmaps){
|
if(enableMipmaps){
|
||||||
context->txr.base = tx1->data;
|
context->txr.base = tx1->data;
|
||||||
} else {
|
} else {
|
||||||
|
if(tx1->mipmap > 1)
|
||||||
context->txr.base = _glGetMipmapLocation((TextureObject*)tx1,0);
|
context->txr.base = _glGetMipmapLocation((TextureObject*)tx1,0);
|
||||||
|
/* We should need this? */
|
||||||
|
else
|
||||||
|
context->txr.base = tx1->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->txr.format = tx1->color;
|
context->txr.format = tx1->color;
|
||||||
|
|
69
GL/texture.c
69
GL/texture.c
|
@ -888,12 +888,12 @@ GLboolean _glIsMipmapComplete(const TextureObject* obj) {
|
||||||
|
|
||||||
GLsizei i = 0;
|
GLsizei i = 0;
|
||||||
for(; i < (GLubyte)(obj->mipmapCount-3); ++i) {
|
for(; i < (GLubyte)(obj->mipmapCount-3); ++i) {
|
||||||
if((obj->mipmap & (1 << i)) == 1) {
|
if((obj->mipmap & (1 << i)) == 0) {
|
||||||
return GL_TRUE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return GL_FALSE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TWIDTAB(x) ( (x&1)|((x&2)<<1)|((x&4)<<2)|((x&8)<<3)|((x&16)<<4)| \
|
#define TWIDTAB(x) ( (x&1)|((x&2)<<1)|((x&4)<<2)|((x&8)<<3)|((x&16)<<4)| \
|
||||||
|
@ -901,12 +901,39 @@ GLboolean _glIsMipmapComplete(const TextureObject* obj) {
|
||||||
|
|
||||||
#define TWIDOUT(x, y) ( TWIDTAB((y)) | (TWIDTAB((x)) << 1) )
|
#define TWIDOUT(x, y) ( TWIDTAB((y)) | (TWIDTAB((x)) << 1) )
|
||||||
|
|
||||||
|
void _glAllocateSpaceForMipmaps(TextureObject* active) {
|
||||||
|
if(!active->data){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(active->data && active->mipmap > 1) {
|
||||||
|
/* Already done */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = active->height*active->width*active->dataStride;
|
||||||
|
|
||||||
|
/* We've allocated level 0 before, but now we're allocating
|
||||||
|
* a level beyond that, we need to reallocate the data, copy level 0
|
||||||
|
* then free the original
|
||||||
|
*/
|
||||||
|
GLubyte* temp = malloc(size);
|
||||||
|
memcpy(temp, active->data, size);
|
||||||
|
pvr_mem_free(active->data);
|
||||||
|
active->data = pvr_mem_malloc(_glGetMipmapDataSize(active));
|
||||||
|
|
||||||
|
/* If there was existing data, then copy it where it should go */
|
||||||
|
memcpy(_glGetMipmapLocation(active,0), temp, size);
|
||||||
|
}
|
||||||
|
|
||||||
void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
GLsizei width, GLsizei height, GLint border,
|
GLsizei width, GLsizei height, GLint border,
|
||||||
GLenum format, GLenum type, const GLvoid *data) {
|
GLenum format, GLenum type, const GLvoid *data) {
|
||||||
|
|
||||||
TRACE();
|
TRACE();
|
||||||
|
if(!data) {
|
||||||
|
/* No data? Do nothing! */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(target != GL_TEXTURE_2D) {
|
if(target != GL_TEXTURE_2D) {
|
||||||
_glKosThrowError(GL_INVALID_ENUM, "glTexImage2D");
|
_glKosThrowError(GL_INVALID_ENUM, "glTexImage2D");
|
||||||
|
@ -994,7 +1021,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
GLint destStride = isPaletted ? 1 : 2;
|
GLint destStride = isPaletted ? 1 : 2;
|
||||||
GLuint bytes = (width * height * destStride);
|
GLuint bytes = (width * height * destStride);
|
||||||
|
|
||||||
if(!active->data) {
|
if(!active->data && (level == 0)) {
|
||||||
assert(active);
|
assert(active);
|
||||||
assert(width);
|
assert(width);
|
||||||
assert(height);
|
assert(height);
|
||||||
|
@ -1006,16 +1033,24 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
active->color = pvr_format;
|
active->color = pvr_format;
|
||||||
/* Set the required mipmap count */
|
/* Set the required mipmap count */
|
||||||
active->mipmapCount = _glGetMipmapLevelCount(active);
|
active->mipmapCount = _glGetMipmapLevelCount(active);
|
||||||
|
active->mipmap_bias = GL_KOS_INTERNAL_DEFAULT_MIPMAP_LOD_BIAS; // in the scale of -8 - 8 moved to 1-15, -4 = 4
|
||||||
|
|
||||||
active->dataStride = destStride;
|
active->dataStride = destStride;
|
||||||
|
|
||||||
GLuint size = _glGetMipmapDataSize(active);
|
active->data = pvr_mem_malloc(destStride*width*height);
|
||||||
assert(size);
|
|
||||||
|
|
||||||
active->data = pvr_mem_malloc(size);
|
|
||||||
assert(active->data);
|
assert(active->data);
|
||||||
|
|
||||||
active->isCompressed = GL_FALSE;
|
active->isCompressed = GL_FALSE;
|
||||||
active->isPaletted = isPaletted;
|
active->isPaletted = isPaletted;
|
||||||
|
} else if(!active->data && (level != 0)){
|
||||||
|
printf("Spooky!\n");
|
||||||
|
assert(0 && "GLdc broken, sorry! @neo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we need to re-alloc and move texture data */
|
||||||
|
if(level > 0){
|
||||||
|
_glAllocateSpaceForMipmaps(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark this level as set in the mipmap bitmask */
|
/* Mark this level as set in the mipmap bitmask */
|
||||||
|
@ -1047,13 +1082,17 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
needsConversion = GL_FALSE;
|
needsConversion = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLubyte* targetData = _glGetMipmapLocation(active, level);
|
GLubyte* targetData = NULL;
|
||||||
|
|
||||||
|
if(active->mipmap == 1 && level==0){
|
||||||
|
targetData = active->data;
|
||||||
|
} else {
|
||||||
|
targetData = _glGetMipmapLocation(active, level);
|
||||||
|
}
|
||||||
|
|
||||||
assert(targetData);
|
assert(targetData);
|
||||||
|
|
||||||
if(!data) {
|
if(!needsConversion) {
|
||||||
/* No data? Do nothing! */
|
|
||||||
return;
|
|
||||||
} else if(!needsConversion) {
|
|
||||||
assert(targetData);
|
assert(targetData);
|
||||||
assert(data);
|
assert(data);
|
||||||
assert(bytes);
|
assert(bytes);
|
||||||
|
@ -1082,7 +1121,11 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* No conversion? Just copy the data, and the pvr_format is correct */
|
/* No conversion? Just copy the data, and the pvr_format is correct */
|
||||||
|
if(bytes % 32 == 0){
|
||||||
sq_cpy(targetData, data, bytes);
|
sq_cpy(targetData, data, bytes);
|
||||||
|
} else {
|
||||||
|
memcpy(targetData, data, bytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -13,7 +13,8 @@ OBJS += containers/stack.o containers/named_array.o containers/aligned_vector.o
|
||||||
|
|
||||||
SUBDIRS =
|
SUBDIRS =
|
||||||
|
|
||||||
KOS_CFLAGS += -ffast-math -O2 -funroll-loops -fsingle-precision-constant -Iinclude -funsafe-math-optimizations -DBUILD_LIBGL -Wall -Wextra
|
EXTRA_CFLAGS= -Wall -Wextra -Wstrict-aliasing=0
|
||||||
|
KOS_CFLAGS += -ffast-math -O2 -funroll-loops -fsingle-precision-constant -Iinclude -funsafe-math-optimizations -DBUILD_LIBGL
|
||||||
#KOS_CFLAGS += -O1 -mlra -Iinclude -DBUILD_LIBGL -Wall -Wextra
|
#KOS_CFLAGS += -O1 -mlra -Iinclude -DBUILD_LIBGL -Wall -Wextra
|
||||||
#GCC5_FLAGS = -mfsca -mfsrra -mlra
|
#GCC5_FLAGS = -mfsca -mfsrra -mlra
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user