I’m having some a rather major problem I can’t figure out, trying to get mipmapping working on 3D textures. I use a 3D texture for the terrain in a game I’m working on, sampled by a simple shader. When I don’t use mipmapping it all renders correctly. However, when I do, it seems like the mipmap data is all garbage (only things sampled from the non-mip layers look right), such as this:
Here’s the basics of how I’m creating and then later loading the textures:
---- for creation ----
GLuint texHand=0;
glGenTextures(1,&texHand);
GLenum texTar=(depth==1?GL_TEXTURE_2D:GL_TEXTURE_3D);
glBindTexture(texTar,texHand);
glTexParameteri(texTar, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
if (texTar==GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D,0,intFormat, width,height,0, srcFormat,GL_UNSIGNED_BYTE, 0);
else
glTexImage3DEXT(GL_TEXTURE_3D,0,intFormat, width,height,depth,0, srcFormat,GL_UNSIGNED_BYTE, 0);
glTexParameteri(texTar,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(texTar,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(texTar,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(texTar,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
---- loading it later ----
glBindTexture(texTar,texHand);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
if (texTar==GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D,0,intFormat, width,height, 0,srcFormat,GL_UNSIGNED_BYTE, pixels);
else
glTexImage3DEXT(GL_TEXTURE_3D,0,intFormat, width,height,depth, 0,srcFormat,GL_UNSIGNED_BYTE, pixels);
----
in this case:
intFormat is GL_RGBA
srcFormat is GL_BGRA_EXT