OpenGL glGeneratemipmap and Framebuffers

I am wrapping around creating mipmaps on the fly and reading this bit using this code: http://www.g-truc.net/post-0256.html

//Create the mipmapped texture
glGenTextures(1, &ColorbufferName);
glBindTexture(ColorbufferName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_UNSIGNED_BYTE, NULL);
glGenerateMipmap(GL_TEXTURE_2D); // /!\ Allocate the mipmaps /!\
...
//Create the framebuffer object and attach the mipmapped texture
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColorbufferName, 0);
...
//Commands to actually draw something
render();
...
//Generate the mipmaps of ColorbufferName
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ColorbufferName);
glGenerateMipmap(GL_TEXTURE_2D);

My questions:

  • Why do I glGenerateMipmapneed to call twice in case of rendering a texture?
  • Should it be called every frame?

If, for example, I import a diffuse 2d texture, I need to call it once after loading in OpenGL as follows:

    GLCALL(glGenTextures(1, &mTexture));
    GLCALL(glBindTexture(GL_TEXTURE_2D, mTexture));

    GLint format = (colorFormat == ColorFormat::COLOR_FORMAT_RGB ? GL_RGB : colorFormat == ColorFormat::COLOR_FORMAT_RGBA ? GL_RGBA : GL_RED);
    GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, format, textureWidth, textureHeight, 0, format, GL_UNSIGNED_BYTE, &textureData[0]));

    GLCALL(glGenerateMipmap(GL_TEXTURE_2D));
    GLCALL(glBindTexture(GL_TEXTURE_2D, 0));

I suspect that this is because the textures are redrawn every frame, and the mipmap generation uses its contents in this process, but I want to confirm this.

3 - Also, if I pass in my gbuffer and then immediately send glBlitFramebufferit to FBO by default, I need to bind and glGenerateMipmaphow is it?

GLCALL(glBindTexture(GL_TEXTURE_2D, mGBufferTextures[GBuffer::GBUFFER_TEXTURE_DIFFUSE]));
GLCALL(glGenerateMipmap(GL_TEXTURE_2D));
GLCALL(glReadBuffer(GL_COLOR_ATTACHMENT0 + GBuffer::GBUFFER_TEXTURE_DIFFUSE));
GLCALL(glBlitFramebuffer(0, 0, mWindowWidth, mWindowHeight, 0, 0, mWindowWidth, mWindowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR));
+4
1
  • , , "[ glGenerateMipmap] , : mipmaps mipmaps."

    , , glGenerateMipmap, glTexImage2D NULL. . , , .

    , , glGenerateMipmap, .

  • , glGenerateMipmap , , , ( ). , - ( ​​, mipmap, ).

  • . Mipmaps , , mipmaps. , mipmaps. , , renderbuffer .

+7

All Articles