I want to i to implement offescreen render in my project with FBO;It works on Other manufacturers‘ GPU,but get glReadPixels error 502 on Mali-T628.I am very confused. Then I try to directly glReadPixels without FBO,no error happened,but i get a white screen.Could any one know this problem?
here is my code to readpixel
getbuffer(uint8_t *dst_buf)
{
int framesize=g_width * g_height * 4;
glBindFramebuffer( GL_FRAMEBUFFER, g_framebuffer );
checkGlError( "glBindFramebuffer" );
GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
checkGlError( "glCheckFramebufferStatus" );
switch( status ){
case GL_FRAMEBUFFER_COMPLETE:
log_debug("FBO good %d",status);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
log_debug("FBO wrong %d",status);
default:
}
glReadBuffer(GL_COLOR_ATTACHMENT0);
if( g_asyncReadingIndex == 0 ){
g_asyncReadingIndex = 1;
g_asyncCopyingIndex = 0;
else{
g_asyncReadingIndex = 0;
g_asyncCopyingIndex = 1;
glBindBuffer( GL_PIXEL_PACK_BUFFER, g_pboID[g_asyncReadingIndex] );
checkGlError( "glBindBuffer" );
glFinish();
checkGlError( "glFinish" );
pj_get_timestamp(&ts_begin);
glReadPixels( 0, 0,g_width,g_height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
checkGlError( "glReadPixels" );
glBindBuffer( GL_PIXEL_PACK_BUFFER, g_pboID[g_asyncCopyingIndex] );
GLubyte* bufferData = NULL;
bufferData = (GLubyte*)glMapBufferRange( GL_PIXEL_PACK_BUFFER,0,
framesize, GL_MAP_READ_BIT );
checkGlError( "glMapBufferRange" );
if( bufferData != NULL ){
memcpy(dst_buf, bufferData, framesize);
glUnmapBuffer( GL_PIXEL_PACK_BUFFER );
checkGlError( "glUnmapBuffer" );
glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
checkGlError( "glBindFramebuffer");
Hi zhengyi112233,
Looking at the code I can see some issues. The first one is that you call glReadBuffer to setup the color attachment but there is no call to glBindFramebuffer(GL_READ_FRAMEBUFFER, "framebuffer used to render to texture"). Without that ReadPixels doesn't know which framebuffer to read from.
The other issue I see is that you setup "glBindBuffer( GL_PIXEL_PACK_BUFFER, g_pboID[g_asyncReadingIndex] );". This will set g_pboID[g_asyncReadingIndex] as destination of your glReadPixels operation but then you map g_pboID[g_asyncCopyingIndex] and return it's data.
To make the code work you should map the pbo with index g_asyncReadingIndex and return that data instead.
Hope it helps,
Daniele