Hi,

On 31/05/11 23:52, Kris Dale wrote:
Greetings all,

I've been learning PBOs here lately, and I can't seem to find any
tutorials about how to use OSG::PixelBufferObjects.  If anyone can
point me in the direction of one, that would be awesome, as I
wouldn't have to mix OGL and OSG code quite as much as I'm doing
now.

Right now what I'm doing is trying to copy back the frame buffer to a
PBO each frame, but I can't get glGenBuffers to return a valid buffer
ID.  I've tried passing in a single int or an array, but all I get
back are 0's.  (In a strict GLUT/GL project, I get 1,2,3..)

I've made sure (as much as I can) that I have a context..  I've
created a graphicscontext, a window exists, I've called
viewer.realize(), even tried one viewer.frame() before glGenBuffers.
All I can get back are 0's.  So naturally when I try to bindbuffer /
readpixels / mapbuffer, I just get back a null pointer because my
bufferID is zero.

Can anyone suggest a reason this might be happening?  (Even if you
can point me to a good OSG tutorial on using OSG::PixelBufferObjects,
I'd still be curious to know.)

Thanks in advance for any guidance anyone can offer..

you'll probably have to stick your code into a camera callback to make sure you have a valid context.

See the osgscreencapture example for some use of PBO. I also paste some small example below that shows some methods for reading back texture data.

HTH
jp

--8<--

struct GPURegionOfInterestCallback : public osg::Camera::DrawCallback
        {
            GPURegionOfInterestCallback(ImageFormat& imf,
                                        osg::Image *osg_im,
                                        osg::TextureRectangle *tex) :
                ImageFormat_(imf),
                osg_im_(osg_im),
                trect_(tex)
            {
                pdbo_ = new osg::PixelDataBufferObject();
                pdbo_->setDataSize(ImageFormat_.getBytesPerImage());
            }
            virtual void operator() (osg::RenderInfo& renderInfo) const
            {
                // first get the texture into the pbo
                pdbo_->bindBufferInWriteMode(*renderInfo.getState());
                renderInfo.getState()->applyTextureAttribute(0, //unit
                                                             trect_);
                glGetTexImage(trect_->getTextureTarget(),
                              0, //level
                              GL_LUMINANCE,
                              GL_UNSIGNED_BYTE,
                              NULL);

                // now copy to cpu
osg::GLBufferObject::Extensions* ext = osg::GLBufferObject::getExtensions(renderInfo.getState()->getContextID(), true); GLubyte* src = (GLubyte*)ext->glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB,

GL_READ_ONLY_ARB);
                if(src)
                {
memcpy(osg_im_->data(), src, osg_im_->getTotalSizeInBytes());
                    ext->glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
                }

                pdbo_->unbindBuffer(renderInfo.getState()->getContextID());

                /*
                // direct to image from texture
                renderInfo.getState()->applyTextureAttribute(0, //unit
                                                             trect_);
                glGetTexImage(trect_->getTextureTarget(),
                              0, //level
                              GL_LUMINANCE,
                              GL_UNSIGNED_BYTE,
                              osg_im_->data());
                */
            }

            ImageFormat ImageFormat_;
            osg::Image* osg_im_;
            osg::TextureRectangle* trect_;
            osg::ref_ptr<osg::PixelDataBufferObject> pdbo_;

        };


Kris

------------------ Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=39979#39979





_______________________________________________ osg-users mailing
list [email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to