Cinder icon indicating copy to clipboard operation
Cinder copied to clipboard

Selective mipmap fbo behavior

Open fschliem opened this issue 8 years ago • 0 comments

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.

fschliem avatar Feb 23 '17 23:02 fschliem