Anyway, because I happened to make this change already locally, I will post a patch to allow for it. It will not cover the needed utility functions for dynamic stuff because they're not that well thought out. But I cannot see how this could otherwise be thought out any better, other than by caching more of the texture data.
The patch includes the change also for texture cubes. I haven't tested them. I also haven't tested LUMINANCE_ALPHA, but I imagine if any other alpha case works, it should too.
Code:
Index: egRendererBase.cpp
===================================================================
--- egRendererBase.cpp (revision 38)
+++ egRendererBase.cpp (working copy)
@@ -189,7 +189,23 @@
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering ? GL_LINEAR : GL_NEAREST );
}
- int format = (comps == 4) ? GL_RGBA : GL_RGB;
+ int format=0;
+ switch (comps)
+ {
+ case 1:
+ format=GL_LUMINANCE;
+ break;
+ case 2:
+ format=GL_LUMINANCE_ALPHA;
+ break;
+ case 3:
+ format=GL_RGB;
+ break;
+ case 4:
+ format=GL_RGBA;
+ break;
+ }
+
int type = hdr ? GL_FLOAT : GL_UNSIGNED_BYTE;
int internalFormat;
if( Modules::config().texCompression && allowCompression )
@@ -218,7 +234,22 @@
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering ? GL_LINEAR : GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );
- int format = (comps == 4) ? GL_BGRA : GL_BGR;
+ int format=0;
+ switch (comps)
+ {
+ case 1:
+ format=GL_LUMINANCE;
+ break;
+ case 2:
+ format=GL_LUMINANCE_ALPHA;
+ break;
+ case 3:
+ format=GL_BGR; // This is reversed because it's native graphics hardware format.
+ break;
+ case 4:
+ format=GL_BGRA; // This is reversed because it's native graphics hardware format.
+ break;
+ }
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, pixels );
}
@@ -249,7 +280,23 @@
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, filtering ? GL_LINEAR : GL_NEAREST );
}
- int format = (comps == 4) ? GL_RGBA : GL_RGB;
+ int format=0;
+ switch (comps)
+ {
+ case 1:
+ format=GL_LUMINANCE;
+ break;
+ case 2:
+ format=GL_LUMINANCE_ALPHA;
+ break;
+ case 3:
+ format=GL_RGB;
+ break;
+ case 4:
+ format=GL_RGBA;
+ break;
+ }
+
int type = hdr ? GL_FLOAT : GL_UNSIGNED_BYTE;
int internalFormat;
if( Modules::config().texCompression && allowCompression )
Index: egTextures.cpp
===================================================================
--- egTextures.cpp (revision 38)
+++ egTextures.cpp (working copy)
@@ -249,7 +275,7 @@
Modules::log().writeWarning( "Texture2D resource '%s': Texture size was changed to match POT", _name.c_str() );
// Check color depth
- if( _comps != 3 && _comps != 4 )
+ if( _comps < 1 || _comps > 4 )
return raiseError( "Invalid color depth" );
// Upload texture
@@ -394,7 +420,7 @@
return raiseError( "Invalid image format (" + ImageLoader::getErrorString() + ")" );
// Check color depth
- if( _comps != 3 && _comps != 4 )
+ if( _comps < 1 || _comps > 4 )
return raiseError( "Invalid color depth" );
// Check image size