Sign in to follow this  

Using EGL Pixel Buffer

This topic is 1785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm on embedded platform Mali400GPU, Ubuntu. I'm trying to use EGL
Pixel Buffer, to copy a texture that is rendered using fragment shader
to a pixel buffer so that I can do some processing on that buffer on
CPU. I have done the following code but when trying use the buffer
object and draw it on a quad, the quad has a distored texture, i don't
know why.

The main problem is I want to use EGL Pixel Buffer with glreadpixels in asynchronous manner to speed up reading from gpu to cpu

// EGL variables
EGLDisplay eglDisplay = 0;
EGLConfig eglConfigWindow = 0;
EGLConfig eglConfigPbuffer = 0;
EGLSurface eglSurfaceWindow = 0;
EGLSurface eglSurfacePbuffer = 0;
EGLContext eglContext = 0;


const EGLint attribListWindow[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_NONE
};
const EGLint attribListPbuffer[] =
{
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_NONE
};
const EGLint srfPbufferAttr[] =
{
EGL_WIDTH, 1024,
EGL_HEIGHT, 1024,
EGL_COLORSPACE, GL_RGB,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_LARGEST_PBUFFER, EGL_TRUE,
EGL_NONE
};

EGLint iMajorVersion, iMinorVersion;
int iConfigs;
eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion);
eglChooseConfig(eglDisplay, attribListWindow,
&eglConfigWindow, 1, &iConfigs);
eglContext = eglCreateContext(eglDisplay,
eglConfigWindow, NULL, NULL);
eglSurfaceWindow = eglGetCurrentSurface(EGL_DRAW);
eglSurfacePbuffer = eglCreatePbufferSurface(eglDisplay,
eglConfigPbuffer,srfPbufferAttr);

eglMakeCurrent(eglDisplay, eglSurfacePbuffer, eglSurfacePbuffer, eglContext);

glGenTextures(1, &theSource);
glBindTexture(GL_TEXTURE_2D, theSource);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024,
1024, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 

 

 

In Drawing:

UserData *userData = (UserData*)esContext->userData;
GLfloat vVertices[] = { -1.0f, -1.0f, 0.0f, // Position 0
0.0f, 0.0f, // TexCoord 0
-1.0f, 1.0f, 0.0f, // Position 1
0.0f, 1.0f, // TexCoord 1
1.0f, 1.0f, 0.0f, // Position 2
1.0f, 1.0f, // TexCoord 2
1.0f, -1.0f, 0.0f, // Position 3
1.0f, 0.0f // TexCoord 3
};
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };

// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
// Use the program object
glUseProgram ( userData->programObject );

// Load the vertex position
glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
GL_FALSE, 5 * sizeof(GLfloat), vVertices );
// Load the texture coordinate
glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );

glEnableVertexAttribArray ( userData->positionLoc );
glEnableVertexAttribArray ( userData->texCoordLoc );

// Bind the base map
glUniform1i ( userData->baseMapLoc, 0 );
glActiveTexture ( GL_TEXTURE0 );
glBindTexture ( GL_TEXTURE_2D, userData->baseMapTexId );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
//glCopyTexImage2D(GL_TEXTURE_2D,0,0,0,0,0, 1024, 1024);
glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );

eglMakeCurrent(eglDisplay, eglSurfacePbuffer, eglSurfacePbuffer, eglContext);

eglBindTexImage(eglDisplay, eglSurfacePbuffer, EGL_BACK_BUFFER);

glBindTexture(GL_TEXTURE_2D, theSource);

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1024, 1024, 0);
glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
 

 

Share this post


Link to post
Share on other sites
Sign in to follow this