Cinder
Cinder copied to clipboard
Selective mipmap fbo behavior
I ran into https://github.com/cinder/Cinder/issues/1320 and independently had a simple fix for it.
The problem is that the code assumes that any mipmap beyond the top one will be auto-generated and so when the texture is requested its whole mimap chain gets regenerated on the fly if they top level changed.
This is great default behavior, but in some cases you may want to write to the specific levels - for that you would now have the option of calling:
// loop over all LOD levels
for (int l = 0; l <= maxLOD; l++) {
// loop over all 6 cubemap faces
for (uint8_t dir = 0; dir < 6; ++dir) {
...
// bind to ALL mipmap levels
fbo->bindFramebufferFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X + dir, l);
...
// draw fragment for each face/level
batch->draw();
}
}
// at this point, we've rendered to all mipmap levels, so do NOT re-generate them from level 0
fbo->getTextureCubeMap(GL_COLOR_ATTACHMENT0, false /* keep those mipmaps as they are! */ );
The mipmap chain is generated by default on FBO construction.