PDA

View Full Version : Cube texture fixed set of mipmaps problem



maxest
06-18-2011, 08:40 AM
Hey,

I generate a cube map texture, assign it 3 mipmaps (although the texture can hold up to 9, it's 256x256) and try to render a mesh with that texture. Unfortunately, I see black triangles.

However, when I use GL_TEXTURE_2D with 3 mipmaps it's all okay.

I don't use automatic texture generation, I want manually load the mipmaps and render mesh with them.

Here's my code from glIntercept log for cube map texture creation:


glGenTextures(1,0xe9fbe8)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_GENERATE_MI PMAP,GL_ZERO)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_R GBA8,256,256,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,1,GL_R GBA8,128,128,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,2,GL_R GBA8,64,64,0,GL_BGRA,GL_UNSIGNED_BYTE,0x0000)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x5f8c738)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x5fcc750)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x5fdc768)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x6010048)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x5fe0b98)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x5ff0bb0)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x6051260)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x5ff4fe8)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x6005000)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x60928e8)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x60d2900)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x6009018)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x60e3fa8)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x6123fc0)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x6133fd8)
glActiveTexture(GL_TEXTURE31)
glBindTexture(GL_TEXTURE_CUBE_MAP,3)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,0 ,0,256,256,GL_BGRA,GL_UNSIGNED_BYTE,0x6137ff0)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,1,0 ,0,128,128,GL_BGRA,GL_UNSIGNED_BYTE,0x6178008)
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,2,0 ,0,64,64,GL_BGRA,GL_UNSIGNED_BYTE,0x6188020)

_arts_
06-18-2011, 10:00 AM
You need to provide full mimpap, so from 256*256 to 1*1.

See here for more details:

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

maxest
06-18-2011, 11:06 AM
1. I don't see anything regarding mip-mapping or cube maps.
2. Why with texture2D I don't need provide a full mipmap chain, and with cube textures I need?

Alfonse Reinheart
06-18-2011, 11:10 AM
You need to tell OpenGL how many mipmaps it can use. This is done by setting the glTexParameter's GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL (http://www.opengl.org/wiki/Texture#Mipmap_range).


Why with texture2D I don't need provide a full mipmap chain, and with cube textures I need?

Sounds like a driver bug that allowed you to get away with improper behavior with 2D textures.

maxest
06-18-2011, 11:14 AM
Why would that be improper? With D3D9 it works this way. Imho OGL should set base level "under the hood" and expected it to have done so with Texture2D. So actually I though it's a driver bug with Cube. But if you say the opposite...

Alfonse Reinheart
06-18-2011, 11:53 AM
Why would that be improper?

Because OpenGL says so. And because it allows you to use fewer mipmap levels than you have actually uploaded if you so desire.


Imho OGL should set base level "under the hood" and expected it to have done so with Texture2D.

It doesn't matter what your opinion is. That's not what the specification says.

maxest
06-18-2011, 12:23 PM
This "imho" was dictated by the way D3D9 works. I just like when it's possible to expect the same behavior from OGL and D3D9.
But ok, if it's what the spec says I'm not gonna argue :).
Thanks for pointing this out.