KTX compression pipeline fixes and sanity-check asserts

--HG--
branch : nfb
This commit is contained in:
2014-03-01 21:48:46 -08:00
parent 22747d507d
commit 094a89a379
2 changed files with 26 additions and 9 deletions

View File

@@ -171,7 +171,7 @@ KRTexture *KRTextureManager::getTexture(const std::string &name) {
return pTexture; return pTexture;
} else { } else {
// Not found // Not found
//fprintf(stderr, "ERROR: Texture not found: %s\n", szName); // fprintf(stderr, "ERROR: Texture not found: %s\n", name.c_str());
return NULL; return NULL;
} }
} else { } else {
@@ -400,6 +400,8 @@ void KRTextureManager::compress(bool premultiply_alpha)
if(compressed_texture) { if(compressed_texture) {
textures_to_remove.push_back(texture); textures_to_remove.push_back(texture);
textures_to_add.push_back(compressed_texture); textures_to_add.push_back(compressed_texture);
} else {
assert(false);
} }
} }

View File

@@ -119,8 +119,10 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int &current_lo
*pDest++ = 0xff; *pDest++ = 0xff;
pSource += 3; pSource += 3;
} }
assert(pSource <= m_pData->getEnd());
//#endif //#endif
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image)); GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
GLDEBUG(glFinish());
free(converted_image); free(converted_image);
current_lod_max_dim = m_max_lod_max_dim; current_lod_max_dim = m_max_lod_max_dim;
@@ -141,11 +143,14 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int &current_lo
*pDest++ = pSource[3]; *pDest++ = pSource[3];
pSource += 4; pSource += 4;
} }
assert(pSource <= m_pData->getEnd());
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image)); GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
GLDEBUG(glFinish());
free(converted_image); free(converted_image);
} else { } else {
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pData)); GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pData));
GLDEBUG(glFinish());
} }
current_lod_max_dim = m_max_lod_max_dim; current_lod_max_dim = m_max_lod_max_dim;
@@ -189,6 +194,8 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int &current_lo
} }
} }
} }
assert(pSource <= m_pData->getEnd());
assert(pDest == pEnd);
} else { } else {
while(pDest < pEnd) { while(pDest < pEnd) {
int count = (*pSource & 0x7f) + 1; int count = (*pSource & 0x7f) + 1;
@@ -214,8 +221,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int &current_lo
} }
} }
} }
assert(pSource <= m_pData->getEnd());
assert(pDest == pEnd);
} }
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image)); GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
GLDEBUG(glFinish());
free(converted_image); free(converted_image);
current_lod_max_dim = m_max_lod_max_dim; current_lod_max_dim = m_max_lod_max_dim;
} }
@@ -250,7 +260,10 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int &current_lo
} }
} }
} }
assert(pSource <= m_pData->getEnd());
assert(pDest == pEnd);
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image)); GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
GLDEBUG(glFinish());
free(converted_image); free(converted_image);
current_lod_max_dim = m_max_lod_max_dim; current_lod_max_dim = m_max_lod_max_dim;
} }
@@ -297,6 +310,12 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha)
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height));
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format));
/*
int texture_base_level = 0;
int texture_max_level = 0;
GLDEBUG(glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, &texture_base_level));
GLDEBUG(glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, &texture_max_level));
*/
switch(internal_format) switch(internal_format)
{ {
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
@@ -312,8 +331,9 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha)
GLuint lod_level = 0; GLuint lod_level = 0;
GLint compressed_size = 0; GLint compressed_size = 0;
GLenum err = GL_NO_ERROR; int lod_width = width;
while(err == GL_NO_ERROR) { while(lod_width > 1) {
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_WIDTH, &lod_width));
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size));
KRDataBlock *new_block = new KRDataBlock(); KRDataBlock *new_block = new KRDataBlock();
new_block->expand(compressed_size); new_block->expand(compressed_size);
@@ -324,10 +344,7 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha)
lod_level++; lod_level++;
} }
if(err != GL_INVALID_VALUE) { assert(lod_width == 1);
// err will equal GL_INVALID_VALUE when
// assert(false); // Unexpected error
}
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0)); GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
getContext().getTextureManager()->selectTexture(0, NULL); getContext().getTextureManager()->selectTexture(0, NULL);
@@ -335,8 +352,6 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha)
KRTextureKTX *new_texture = new KRTextureKTX(getContext(), getName(), internal_format, base_internal_format, width, height, blocks); KRTextureKTX *new_texture = new KRTextureKTX(getContext(), getName(), internal_format, base_internal_format, width, height, blocks);
KRResource *test_resource = new_texture;
m_pData->unlock(); m_pData->unlock();
for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) { for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {