title: Using EGL Pixel Buffer
body: <p>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.</p>
  
  <p>This is in Init function</p>
  
  <pre><code>// 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, &amp;iMajorVersion, &amp;iMinorVersion);
      eglChooseConfig(eglDisplay, attribListWindow,
                      &amp;eglConfigWindow, 1, &amp;iConfigs);
      eglContext = eglCreateContext(eglDisplay,
                                    eglConfigWindow, NULL, NULL);
      eglSurfaceWindow = eglGetCurrentSurface(EGL_DRAW);
      eglSurfacePbuffer = eglCreatePbufferSurface(eglDisplay,
                          eglConfigPbuffer,srfPbufferAttr);
  
      eglMakeCurrent(eglDisplay, eglSurfacePbuffer, eglSurfacePbuffer, eglContext);
  
      glGenTextures(1, &amp;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);
  </code></pre>
  
  <p>In Drawing:</p>
  
  <pre><code>  UserData *userData = (UserData*)esContext-&gt;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-&gt;width, esContext-&gt;height );
      // Clear the color buffer
      glClear ( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
       // Use the program object
      glUseProgram ( userData-&gt;programObject );
  
      // Load the vertex position
      glVertexAttribPointer ( userData-&gt;positionLoc, 3, GL_FLOAT,
                              GL_FALSE, 5 * sizeof(GLfloat), vVertices );
      // Load the texture coordinate
      glVertexAttribPointer ( userData-&gt;texCoordLoc, 2, GL_FLOAT,
                              GL_FALSE, 5 * sizeof(GLfloat), &amp;vVertices[3] );
  
      glEnableVertexAttribArray ( userData-&gt;positionLoc );
      glEnableVertexAttribArray ( userData-&gt;texCoordLoc );
  
      // Bind the base map
      glUniform1i ( userData-&gt;baseMapLoc, 0 );
      glActiveTexture ( GL_TEXTURE0 );
      glBindTexture ( GL_TEXTURE_2D, userData-&gt;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 );
  </code></pre>