Skip to main content
GameDev.net gamedev.net
🔒 Locked

Generating mipmaps manually in GLSL

Started by Equilibrix Nov 19, 2009 at 12:37 PM 1 replies 5.2k views
Original Post
Equilibrix
Equilibrix
Hello, I need to generate a set of mipmaps for my texture using a custom algorithm - I need to store min values instead of average values in every subsequent level. I don't think OpenGL can do it for me automatically, so could someone please provide me with a workflow on how to do it using a shader? I can imagine it would involve some framebuffer object for binding the empty mipmapped texture and rendering into it but I don't know how to do it.. Since now I always generated mipmaps using glGenerateMipmapEXT and just accessed it in the fragment shader but have no idea how to create my own mipmaps. Thank you very much! Equilibrix
V-man
V-man
You would need to bind the FBO (glBindFramebufferEXT) and then bind the mipmap (glFramebufferTexture2DEXT) and the last parameter of glFramebufferTexture2DEXT is the mipmap level.
Don't forget to check the status with glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)
Equilibrix
Equilibrix
Thank you!

For those who are interested I have finally figured it out thanks to the Usage examples in OpenGL specs (example 5 for custom mipmap generation):
http://www.opengl.org/registry/specs/ARB/framebuffer_object.txt

Be warned though that the implementation used there is quite slow as attaching textures of different sizes (mipmap levels) to the FBO is very slow. I have implemented it using a FBO for every mipmap level and it works cca twenty times faster!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.