Hi,

  this little hack makes this approach work:

  Change to Image (header): Added bool allocateIfRequired to ReadPixels.
Controls if Image is free or not to allocate the desired memory buffer, or
app want to take care of it (true means Image has control). App must
guarantee _data is initialized and have the proper format (and size) or a
memory problem could happen.

void readPixels(int x,int y,int width,int height,
GLenum pixelFormat,GLenum type, bool allocateIfRequired = true);


  Change to Image.cpp: Make call to allocateImage dependant of flag state.

void Image::readPixels(int x,int y,int width,int height,
GLenum format,GLenum type, bool allocateIfRequired)
{
if (allocateIfRequired)
        allocateImage(width,height,1,format,type);

glPixelStorei(GL_PACK_ALIGNMENT,_packing);
glReadPixels(x,y,width,height,format,type,_data);
}

Change to RenderStage.cpp (drawInner): Added false to the call of
readPixels. Means app have control (and responsability) of memory.

itr->second._image->readPixels(static_cast<int>(_viewport->x()),
                                               static_cast<int>(_viewport->y()),

static_cast<int>(_viewport->width()),

static_cast<int>(_viewport->height()),
                                               pixelFormat, dataType,
false);

   Now, simply setting the image to the desired FBO size, the viewport of
the camera controls which region is transfered.

   I know this is not the right place to comment that, but so this thread is
now complete for everyone who read it.

  Summary for the future readers: The main topic was 'How to use FBO with
resizing requisites and readback render results to main memory (for new
users like me).'

  Problem: RenderStage is not sensitive to changes in the FBO or its
attachment (w.r.t. size at least) ) once it is created in runCameraSetUp.

  Alternative 1: Resize the FBO and have it always of the desired size
(first workaround in this thread).
  Alternative 2: Set a FBO larger than the maximum size possible and let the
camera viewport control which region is desired. (need hack in this message)
  Alternative 3: (Not yet implemented). Change RenderStage and implement the
desired behaviour (if image attached to an FBO chages size, let leave FBO
refresh its attachments).

  None is perfect, 1 and 2 have pros and cons. Best seems 3, but requires
more knowlegde of OSG that i don't yet have.

Thanks for the wise replies.
Himar.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to