- when loading textures, if compressed texture call fails, try to revert to uncompressed before throwing an error

This commit is contained in:
Mark Vejvoda
2011-03-30 19:23:27 +00:00
parent 2f250846b1
commit 55f2bdc2d5
2 changed files with 115 additions and 12 deletions

View File

@@ -696,6 +696,18 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy) {
//wrap params
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, wrap);
//maxAnisotropy
if(isGlExtensionSupported("GL_EXT_texture_filter_anisotropic")){
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
}
if(mipmap) {
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
//build mipmaps
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, glFilter);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
int error= gluBuild1DMipmaps(
GL_TEXTURE_1D, glCompressionFormat, pixmap.getW(),
@@ -713,7 +725,22 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy) {
}
//
if(error != 0) {
if(error != 0) {
//throw runtime_error("Error building texture 1D mipmaps");
char szBuf[1024]="";
sprintf(szBuf,"Error building texture 1D mipmaps, returned: %d [%s] w = %d, glCompressionFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),glCompressionFormat);
throw runtime_error(szBuf);
}
}
else {
//build single texture
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage1D(
GL_TEXTURE_1D, 0, glCompressionFormat, pixmap.getW(),
0, glFormat, GL_UNSIGNED_BYTE, pixels);
GLint error= glGetError();
// Now try without compression if we tried compression
@@ -800,7 +827,22 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
//build mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps(
GL_TEXTURE_2D, glCompressionFormat,
pixmap.getW(), pixmap.getH(),
glFormat, GL_UNSIGNED_BYTE, pixels);
*/
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, glCompressionFormat,
pixmap.getW(), pixmap.getH(), 0,
glFormat, GL_UNSIGNED_BYTE, pixels);
GLint error= glGetError();
// Now try without compression if we tried compression
@@ -817,6 +859,20 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
}
//
if(error != GL_NO_ERROR) {
//throw runtime_error("Error building texture 2D mipmaps");
char szBuf[1024]="";
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH(),glCompressionFormat);
throw runtime_error(szBuf);
}
}
else {
//build single texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, glCompressionFormat,pixmap.getW(),
pixmap.getH(),0, glFormat, GL_UNSIGNED_BYTE, pixels);
GLint error= glGetError();
@@ -894,6 +950,22 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy) {
//gen texture
glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_3D, handle);
//wrap params
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap);
//build single texture
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage3D(
GL_TEXTURE_3D, 0, glCompressionFormat,
pixmap.getW(), pixmap.getH(), pixmap.getD(),
0, glFormat, GL_UNSIGNED_BYTE, pixels);
GLint error= glGetError();
// Now try without compression if we tried compression
@@ -988,7 +1060,22 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
if(mipmap) {
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps(
target, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(),
glFormat, GL_UNSIGNED_BYTE, pixels);
*/
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(target, 0, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(), 0,
glFormat, GL_UNSIGNED_BYTE, pixels);
int error = glGetError();
// Now try without compression if we tried compression
@@ -1001,14 +1088,30 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
if(error2 == GL_NO_ERROR) {
error = GL_NO_ERROR;
currentPixmap->getW(), currentPixmap->getH(), 0,
}
int error = glGetError();
if(error != 0) {
//throw runtime_error("Error building texture cube mipmaps");
char szBuf[1024]="";
sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat);
}
//
if(error != GL_NO_ERROR) {
//throw runtime_error("Error building texture cube mipmaps");
char szBuf[1024]="";
sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat);
throw runtime_error(szBuf);
}
}
else {
glTexImage2D(
target, 0, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(),
0, glFormat, GL_UNSIGNED_BYTE, pixels);
int error = glGetError();
// Now try without compression if we tried compression
if(error != GL_NO_ERROR && glCompressionFormat != glInternalFormat) {
glTexImage2D(
target, 0, glInternalFormat,
currentPixmap->getW(), currentPixmap->getH(),
0, glFormat, GL_UNSIGNED_BYTE, pixels);