是的,使用函数glFramebufferTexture2D 并在最后一个参数上指定mipmap 级别。
在你附加了你需要的所有东西之后,在特定的 mipmap 上渲染你想要的图像。
注意:别忘了改成glViewport,这样它就会渲染成合适的mipmap大小!
这是一个简单的例子:
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..)
编辑:
如果要修改生成的mipmap(使用glGenerateMipmap或外部生成),可以使用相同的方法,使用glFramebufferTexture2D并选择要修改的mipmap。
完成所有设置后(如上面的示例),您可以完全渲染新的 mipmap,也可以发送原始纹理,并在片段着色器中对其进行修改。