PDA

View Full Version : Mipmap generation fails second time



SasMaster
03-24-2014, 09:55 AM
I have the following situation: I have a material with a texture which I load from file.In some cases I just load the image, create OpenGL texture and generate mipmaps.Then just render it.Works fine when minimized.In other cases,I do some processing on that texture after the initial mipmaps generation.And because I do the processing only on the level zero I regenerate the mipmaps before returning to the renderer.The issue is that after second generation of mipmaps they don't exist.The texture looks as if it has GL_NEAREST mag and min.I can't understand why it doesn't work second time.Here is my code to generate mipmaps:

glBindTexture(GL_TEXTURE_2D,_id);
glTexParameteri ( _target, GL_TEXTURE_BASE_LEVEL, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);


My hardware is NVidia QUADRO K4000 ,OpenGL 4.2
One more thing.In OpenGL debug output I am getting the following warning:


State usage warning: Texture 2 is base level inconsistent.Check texture size.Severity:low ,ID131204

rextimmy
04-15-2014, 11:00 PM
How are you updating the texture data?

tdname
04-16-2014, 05:12 AM
Texture data should be "allocated" with glTexImage2D() at least one time (with right parameters) and already updated (using sync or async methods) on GPU before call glGenerateMipmap().

So (sync upload method):


glGenTextures(1, _id);
glBindTexture(GL_TEXTURE_2D,_id);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, DEFAULT_RGBA_INTERNAL_FORMAT, pixelsData);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);