Yes, use the function glFramebufferTexture2D
and on the last parameter specify the mipmap level.
After you attached everything you need, render the image you want to be at the specific mipmap.
Note: Don't forget to change to glViewport
so it will render to the appropriate mipmap size!
Here is a simple example:
unsigned int Texture = 0;
int MipmapLevel = 0;
glGenFramebuffers(1, &FBO);
glGenRenderbuffers(1, &RBO);
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, TextureWidth, TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
// glTexParameteri here
// Use shader and setup uniforms
glViewport(0, 0, TextureWidth, TextureHeight);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
glBindRenderbuffer(GL_RENDERBUFFER, RBO);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, TextureWidth, TextureHeight);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Texture, MipmapLevel); // Here, change the last parameter to the mipmap level you want to write to
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render to texture
// Restore all states (glViewport, Framebuffer, etc..)
EDIT:
If you want to modify a generated mipmap (generated with glGenerateMipmap
or externally), you can use the same method, use glFramebufferTexture2D
and choose the mipmap you want to modify.
After you have done all the setup stuff (like the above sample), you can either completely render a new mipmap, or you can send the original texture, and modify it in the fragment shader.