Hi John,

I cannot say, what the problem is,

but the possible solution is to use pbo with glReadPixels so that you read
previous frame - and all reading is async - not slowing app at all

here is a code for you
//somewhere after rendering

glReadBuffer(GL_FRONT);
// get next buffer's index
 unsigned int iNextBuffer = (_iCurrentBuffer + 1) % N_MAX_BUFFERS;
 // kick of readback of current front-buffer
 // into the next buffer
    glBindBuffer(GL_PIXEL_PACK_BUFFER, _aPixelBuffer[iNextBuffer]);//bind
pbo1
    glReadPixels(0, 0, m_width, m_height, GL_BGRA,
                 GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));//readback
                                // map the current buffer containing the
                                // image read back the previous time around
    glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT,
_aPixelBuffer[_iCurrentBuffer]);//bind pbo2
   _pPixels = static_cast<unsigned char *>(glMapBuffer(GL_PIXEL_PACK_BUFFER,
GL_READ_ONLY));

if(_pPixels)
{

//something like:
 memcpy(image,_pPixels,m_width*m_height*4);
// unmap the buffer
     if (!glUnmapBuffer(GL_PIXEL_PACK_BUFFER))
    {
        std::cerr << "Couldn't unmap pixel buffer. Exiting\n";
        assert(false);
    }
}


 // unbind readback buffer to not interfere with
 // any other (traditional) readbacks.
    glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
 // make next-buffer the current buffer
    _iCurrentBuffer = iNextBuffer;
glReadBuffer(GL_BACK);


make sure you have inited buffers

glGenBuffers(N_MAX_BUFFERS, _aPixelBuffer);
for (unsigned int iBuffer = 0; iBuffer < N_MAX_BUFFERS; ++iBuffer)
    {
        glBindBuffer(GL_PIXEL_PACK_BUFFER, _aPixelBuffer[iBuffer]);
        glBufferData(GL_PIXEL_PACK_BUFFER, m_width*m_height*4, NULL,
GL_STATIC_READ);
errorcode = glGetError();
    }
  glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

and that you delete them after use

glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
glDeleteBuffersARB(N_MAX_BUFFERS, _aPixelBuffer);


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

Reply via email to