Let's say I have a texture that I need to mipmap but I want the mipmapping done hardware accelerated. I decided the best route to take would be something like this:
int read = glGenFramebuffers();
int draw = glGenFramebuffers();
int wh = 256;
int glObject = glGenTextures();
glBindTexture(GL_TEXTURE_2D, glObject);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, wh, wh, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
for(int i = 0; i < mipLevels; ++i) {
glBindFramebuffer(GL_FRAMEBUFFER, read);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glObject, i);
glTexImage2D(GL_TEXTURE_2D, i + 1, GL_RGBA8, wh / 2, wh / 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByeBuffer)null);
glBindFramebuffer(GL_FRAMEBUFFER, draw);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glObject, i + 1);
glBindFramebuffer(GL_READ_FRAMEBUFFER, read);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw);
glBlitFramebuffer(0, 0, wh, wh, 0, 0, wh / 2, wh / 2, GL_COLOR_BUFFER_BIT, GL_LINEAR);
wh /= 2;
}
Both framebuffers return INCOMPLETE_ATTACHMENT in this block of code when glCheckFramebufferStatus is called. What am I doing wrong? Am I allocating the blank mipmap levels correctly?
Answer: I was using glTexImage2D
to allocate blank mip levels when I should have used glTexStorage2D
to allocate the blank levels under these circumstances. Here is a link to the manual page for glTexStorage2D
for more details: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexStorage2D.xhtml