Problem 1:
The following code causes an access violation in atioglxx.dll when it reaches the line with glGenerateMipMapEXT:
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB,512,512,0,GL_RGBA,GL_FLOAT,0);
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL, 0);
GLuint fb;
glGenFramebuffersEXT(1, &fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
// glBindTexture(GL_TEXTURE_2D, tex);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, tex, 0);
// optionally render something here
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, tex);
glGenerateMipmapEXT(GL_TEXTURE_2D);
// render here with tex
...
If you uncomment the line where GL_GENERATE_MIP is set to GL_TRUE, or the line which sets GL_TEXTURE_MAX_LEVEL to 0, glGenerateMipmapEXT does not cause an access violation any more.
But:
glGenerateMipmapEXT on this fp16 texture destroys the texture data!! I rendered a fullscreen quad using the fp16 texture 'tex' after glGenerateMipmapEXT and everything was black. Skipping the call to glGenerateMipmapEXT solved the problem.
But:
If you uncomment the line with glBindTexture(GL_TEXTURE_2D, tex). glGenerateMipmapEXT does not kill the texture data any mode !?!? Why is this? tex is already bound to GL_TEXTURE_2D!!!
Problem 2:
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,512,512,0,GL_RED,GL_INT,0);
GLuint fb;
glGenFramebuffersEXT(1, &fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, tex, 0);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// render something
...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glGenerateMipmapEXT(GL_TEXTURE_2D);
// render something using the texture 'tex'
...
The texture is created and the min and mag filter are set to nearest intentionally. GENERATE_MIPMAP is enabled so that a full set of mipmaps will be generated automatically.
After glGenerateMipmapsEXT the texture 'tex' contains artifacts in every mipmap layer. Not calling this function will leave the texture intact and without artifacts.
Uncommenting the line with glTexParameteri AFTER glFramebufferTexture2DEXT causes the texture to be black regadles of GenerateMipmapsEXT.
Setting the same texture filter before calling glFramebufferTexture2DEXT makes it work.
Even
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, tex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
makes it work! This is completely confusing!!
What does the FBO extension have to do with the GL_TEXTURE_MIN_FILTER??? Why is the value of the min filter apparently copyied into the color attachment state when glFramebufferTexture2D is called???
Conclusion:
The exhibited behavior is rather confusing. The behavior is even dependant on the texture internal format (try fp16 vs. RGBA8).
I think at least some of the exhibited behaviour is because of a bug in the drivers. With a GeForce 6600 i didn’t experience these problems.
What do you all think? Do you experience the same problems with this code?