# Manual MipMap Generation

## Recommended Posts

Funkymunky    1413

I am trying to manually render my own Mip Map chain using a framebuffer object.  It works on the first pass (for the first level of mipmaps), but doesn't output anything on subsequent passes.  I set it up like:

	glBindFramebuffer(GL_FRAMEBUFFER, fboID);
glUseProgram(programID);
glBindTexture(GL_TEXTURE_2D, texID);

for(unsigned int i = 1; i < 10; i++)
{
unsigned int Dim = (512 >> i);
glViewport(0, 0, Dim, Dim);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texID, i);

}



So when I look at my texture, Level 0 is the source texture I expect, and level 1 has the correct 1st mipmap rendered... but every level from 2 on up is blank.  It's as if the render never happened and the program never ran.  If I modify the loop to start at 2, or 3, etc., then I see that mipmap level rendered correctly.  What gives?

##### Share on other sites
L. Spiro    25638

Bind (or unbind and rebind) the framebuffer each time you modify it.

Set the viewport after the binding.

Also, not sure what your purposes are, but you will not be satisfied with the quality of the mipmaps you get using this approach.  At the very least you need to always sample the next mipmap up with this approach, although even that will not give you satisfactory results.

L. Spiro

Edited by L. Spiro

##### Share on other sites
Funkymunky    1413

I tried that, along with setting everything during each iteration of the loop.  It still gives me the same result, level 1 works and the rest don't even seem to run.  And I'm not even sampling the source texture at this point; I'm setting the output to red, and I still only see it on level 1.  It's like it refuses to run/render on anything but the first iteration of the loop.

Edited by Funkymunky

##### Share on other sites
Funkymunky    1413

Ah!  I had created this texture with a depth buffer.  I needed to call glClear(GL_DEPTH_BUFFER_BIT) after attaching each texture, or really glDisable(GL_DEPTH_TEST) before the loop.

Edited by Funkymunky