[osg-users] How to resize when using PIXEL_BUFFER?

Robert Osfield robert.osfield at gmail.com
Fri Feb 12 02:48:24 PST 2016


Hi Greg,

It's hard to know specifically what is wrong as I don't have any of
your code to test first hand.  If you are re-creating the PixelBuffer
on each resize then I'd guess that there is an issue with the graphics
object handles being invalidated in some way.  There are mechanisms in
the OSG for release graphics objects but perhaps you are bypassing
these or using an older version of the OSG that doesn't manage this
correctly.

In my previous email I suggested that the best approach is to using a
single PixelBuffer and then using a FrameBufferObject within this to
do the rendering to and copying from rather than the using the
PixelBuffer's frame buffer - this approach would allow you to avoid
the need to release and then recreating GL objects on each resize, the
only resource that would need to be reallocated with the FBO.

Robert.

On 11 February 2016 at 22:58, Greg Danaha <osgforum at tevs.eu> wrote:
> Hi,
>
> Here's a follow-up.  I have it about 95% working (finally!).
>
> Here's my code to resize the pixel-buffer models.
>
>
> Code:
>
>
> osg::Camera * camera = m_nhiViewer->getCamera();
> if (camera != nullptr)
> {
>    osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
>    if (gc != nullptr)
>    {
>       if (gc->releaseContext())
>       {
>          gc->close(); // will release PixelBufferWin32 and resources
>
>          // create new graphics context
>          osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
>          traits->x = 0;
>          traits->y = 0;
>          traits->width = m_width;
>          traits->height = m_height;
>          traits->red = 8;
>          traits->green = 8;
>          traits->blue = 8;
>          traits->depth = 24;
>          traits->pbuffer = true;
>          traits->doubleBuffer = true;
>          traits->readDISPLAY();
>          traits->supportsResize = true;
>
>          gc = osg::GraphicsContext::createGraphicsContext(traits.get());
>          if (gc != nullptr)
>          {
>             gc->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
>             gc->setClearColor(m_background);
>
>             camera->setGraphicsContext(gc.get());
>
>             osg::ref_ptr<osg::Image> image = nullptr;
>             std::map<osg::Camera::BufferComponent, osg::Camera::Attachment> bam = camera->getBufferAttachmentMap();
>             if (!bam.empty())
>             {
>                osg::Camera::BufferAttachmentMap::iterator iter = bam.find(osg::Camera::COLOR_BUFFER);
>                if (iter != bam.end())
>                   image = iter->second._image;
>             }
>
>             if (image != nullptr)
>             {
>                image->allocateImage(m_width, m_height, image->r(),                                              image->getPixelFormat(), image->getDataType(),
>                image->getPacking());
>             }
>
>             m_nhiViewer->realize();
>
>             double widthChangeRatio = double(m_width) / double(m_lastWidth);
>             double heightChangeRatio = double(m_height) / double(m_lastHeight);
>             double aspectRatioChange = widthChangeRatio / heightChangeRatio;
>
>             if (aspectRatioChange != 1.0)
>             {
>                switch (camera->getProjectionResizePolicy())
>                {
>                   case(osg::Camera::HORIZONTAL) :
>                      camera->getProjectionMatrix() *= osg::Matrix::scale(1.0 / aspectRatioChange, 1.0, 1.0);
>                      break;
>                   case(osg::Camera::VERTICAL) :
>                      camera->getProjectionMatrix() *= osg::Matrix::scale(1.0, aspectRatioChange, 1.0);
>                      break;
>
>                   default:
>                      break;
>                }
>             }
>
>             camera->setViewport(0, 0, m_width, m_height);
>
>             double eventTime = m_nhiViewer->getEventQueue()->getTime();
>             m_nhiViewer->getEventQueue()->windowResize(0, 0, m_width, m_height, eventTime);
>          }
>       }
>    }
> }
>
>
>
>
>
> But the real problem was that when I set up the rendering when the model loaded, I specified
>
> camera->setRenderTargetImplementation(osg::Camera::PIXEL_BUFFER);
>
> That seemed to throw everything off.  Now it is defaulting to FRAME_BUFFER and using traits->pbuffer = true; to set up the pixel buffering.
>
> I still have one problem though.  It works great with models (e.g. .flt) but when I resize an earth file it doesn't render properly.  I also get an error 'invalid enumerant' after RenderBin::draw() in osgUtil RenderBin.cpp.  The error value is 1280.  The earth image looks as below after I resize it (or it comes up black).  If I resize it again the globe is black.
>
> Any additional help would be greatly appreciated.
>
> ...
>
> Thank you!
>
> Cheers,
> Greg[/code]
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=66275#66275
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list