PDA

View Full Version : Reduce code, use of glTexImage3D ... ?



Groovounet
11-27-2008, 04:59 AM
Basically, I had this awful felling in my texture loading code: It's so complicated, so full of cases, let's makes everything easier and "bug proof" (lol).

I didn't used to use so much glTexImage3D but now with texture array or texture 3d used like texture array, it becomes quite useful.

And I felt: "Why using glTexImage1D and glTexImage2D when glTexImage3D and glCompressedTexImage3D could do the job in any case?!" With few wrapping around in the code it could be like just a single function to load any texture ...

The warpper:


void TexImage(
GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLsizei texelSize, //Basically, used from compressed data size
const GLvoid * data);


Any reason not to do that? Is glTexImage2D and glTexImage1D would provide significant better performance for texture uploading? I don't any specific reason but maybe...

Groovounet
11-27-2008, 05:06 AM
I forgot it say that specification say that target should be just GL_TEXTURE_3D or GL_TEXTURE_2D_ARRAY but it works fine with GL_TEXTURE_2D on nVidia GF8 and 180 drivers XD. Anyway it should be a problem to bind a texture at loading to GL_TEXTURE_3D or GL_TEXTURE_2D_ARRAY and to GL_TEXTURE_2D at draw ... (haven't tried yet)

Komat
11-27-2008, 01:07 PM
I forgot it say that specification say that target should be just GL_TEXTURE_3D or GL_TEXTURE_2D_ARRAY but it works fine with GL_TEXTURE_2D on nVidia GF8 and 180 drivers XD.


If specification says that only some values are allowed and your card does not export additional extension which extends that list, you should never pass value other than those listed even if it might appear to work. Otherwise you are very clearly asking for troubles with future drivers or hw from another vendor.

If you wish to reduce code, then simply hide all the switching based on target type inside your TexImage wrapper.

Groovounet
11-28-2008, 02:58 AM
And texture object can't be binded to different targets ... won't work :p