GlGenerateMipmap fails if not followed by glGetError ... wait what?

I am having a very strange problem generating textures for a project. The first mipmapped texture works flawlessly, but the next ones only paint the first level. While debugging, I suddenly came across a hack that fixed it:

glGenTextures(1, &texture->textureID);
glBindTexture(GL_TEXTURE_2D, texture->textureID);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexStorage2D(GL_TEXTURE_2D, 10, GL_RGBA8, width, height);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glGenerateMipmap(GL_TEXTURE_2D);
assert(glGetError() == GL_NO_ERROR);    // Mipmapping fails if glGetError is not here

glBindTexture(GL_TEXTURE_2D, 0);

      

Why does this only work when glGetError (which, as you can see with this statement, ALWAYS returns GL_NO_ERROR) is called after glGenerateMimap? Why does this have to do with this?

I am currently using a GeForce GTX 670 with the latest GeForce 340.52 driver.

Edit: a few images might help

With glGetError ():

enter image description here

Without glGetError ():

enter image description here

+3


source to share


1 answer


Referring to Is iOS glGenerateMipmap synchronous, or possibly asynchronous? it looks like glGenerateMipmaps is working asynchronously. My project uses shared contexts to create shaders, textures and meshes (sorry if I didn't mention this, I didn't think it mattered).

The thing is, whenever the texture finishes, the flag generated by the textures was raised and the general context would be destroyed, it seems that the last glGenerateMipmap is therefore not flushed down the pipeline. The glGetError call should clear the operations from the pipeline to see if there is any error to report, which is why it makes everything work flawlessly.



So, in other words, if you are doing something in a separate general context, you need to call glFinish explicitly before killing this thread, or some operations will be canceled.

+2


source







All Articles