Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Using EGL Pixel Buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 AhmedCoeia   Members   -  Reputation: 510

Like
0Likes
Like

Posted 26 February 2013 - 06:08 PM

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 );
 

 



Sponsor:

#2 blueshogun96   Crossbones+   -  Reputation: 1755

Like
0Likes
Like

Posted 27 February 2013 - 03:32 AM

Can you share a screenshot of the corrupted image?  That may help a bit.

 

Shogun.


Follow Shogun3D on the official website: http://shogun3d.net

Posted Image Posted Image Posted Image Posted Image

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS