Results 1 to 6 of 6

Thread: Writing to a pbuffer

  1. #1

    Writing to a pbuffer

    I need to create a texture bindable pbuffer. Then bind it and upload the texture data.

    Im sort of stuck.

    Here's how we create the pbuffers(all this code courtesy a reply from Xmas in these forums):

    EGLSurface pbuffer[NUM_PBUFFERS];
    for (int i = 0; i < NUM_PBUFFERS; ++i)
    pbuffer[i] = eglCreatePbufferSurface(eglDisplay, eglConfig, attribs);
    And this is what I need to do while rendering(it should be equivalent to glTexSubImage2D+glDrawArrays+glSwapBuffers when using textures alone)
    void renderScene()
    {
    eglMakeCurrent(eglDisplay, pbuffer[writeBuffer], pbuffer[readBuffer], eglContext);
    <<<<DRAW to the writepbuffer>>>>
    }
    Is there anything wrong with the contents of renderScene?
    How do I do the <<<<DRAW to the writepbuffer>>>> part?
    Is it placed correctly in the function?
    And should'nt there be an eglSwapBuffers someplace?

    Thanks for your help.

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353
    The idea was to use the pbuffer as a texture, not as a render target. So you don't need the eglMakeCurrent call.

    Code :
    // create pbuffer
    EGLint attribs[] = {
      EGL_WIDTH, width,
      EGL_HEIGHT, height,
      EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
      EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
      EGL_NONE
    };
    pbuffer = eglCreatePbufferSurface(eglDisplay, eglConfig, attribs);
     
    // upload data to pbuffer
    glBindTexture(GL_TEXTURE_2D, 0);
    eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);
    glTexImage2D(...); 
     
    // render using pbuffer as texture
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Posts
    28
    Code :
    // upload data to pbuffer 
    glBindTexture(GL_TEXTURE_2D, 0); 
    eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER); 
    glTexImage2D(...);

    If I want to draw some rendering scene to PBuffer,
    And I use this PBuffer scene as a texture.

    How can I move PBuffer Scene to glTexImage2D(...)?

    For drawing some rendering scene to PBuffer,
    I guess eglMakeCurrent() be requested.. right??

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353
    Quote Originally Posted by danielkim
    For drawing some rendering scene to PBuffer,
    I guess eglMakeCurrent() be requested.. right??
    Yes, if you want to render to a pbuffer, you need to make it the current draw surface.

    However, akhil is looking for a solution to another problem (see other treads in this forum) where using a pbuffer solely as a texture without ever rendering to it could help.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  5. #5
    // create pbuffer
    ...
    // upload data to pbuffer
    ...
    glTexImage2D(...);
    // render using pbuffer as texture
    Just to make sure I am clear as to whats going on here...

    A pbuffer resides in video memory like a texture, the difference being pbuffer is expected to be dynamic, whereas texture, static.

    So I initialize the pbuffer like so:

    Code :
    pbuffer = eglCreatePbufferSurface(...)
    glBindTexture(GL_TEXTURE_2D, 0); // why 0?
    eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER); 
    glTexImage2D(...,0);

    In my "regular update" function, which keeps drawing the scren quad to screen I do this(??):
    Code :
    glBindTexture(GL_TEXTURE_2D, 0); //does this automatically link to the pbuffer or something?
    glTexSubImage2D(....,screenbuffer)
    glDrawArrays(...);//to draw a quad
    eglSwapBuffers(...);
    Here is how my app is structured:
    in loop:
    • (1) Draw modified objects(not textures) to ScreenBuffer(memcpy's)
      (2) Draw opengles texture objects to screen (glDrawarrays for different textures)
      (3) RegularUpdate: Draw the ScreenBuffer (prepared in (1) ) to screen (A glDrawArrays to draw the screenbuffer quad(until know, via a texture, but hopefully soon, using a pbuffer), followed by an eglSwapBuffers)
      Then back to (1)

  6. #6
    Senior Member
    Join Date
    May 2006
    Posts
    353
    First you want to create a pbuffer, bind it to a texture name and set the filter and wrap modes. You only do this once:
    Code :
    pbuffer = eglCreatePbufferSurface(...);
    GLuint pbufferTex;
    glGenTextures(1, &pbufferTex);
    glBindTexture(GL_TEXTURE_2D, pbufferTex);
    eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);
     
    // set filter and wrap modes
    glTexParameter(...);
    ...
    Note that you need a new/unused texture name because eglBindTexImage deletes the contents of the currently bound texture. I used 0 above simply because it's the name of the default texture, which is rarely used.

    Whenever you want to update the pbuffer, use this:
    Code :
    glBindTexture(GL_TEXTURE_2D, pbufferTex);
    glTexSubImage2D(...);
    Note that you must use glTexSubImage2D, otherwise the pbuffer binding would be released. So the example in my post above is wrong.
    Of course you only need to call glBindTexture if the texture isn't bound already.

    And when you want to render something with that texture:
    Code :
    glBindTexture(GL_TEXTURE_2D, pbufferTex);
    // set up render states, texenv, vertex arrays, etc.
    glEnable(GL_TEXTURE_2D);
    ...
     
    glDrawArrays(...);

    If you want to clean up nicely:
    Code :
    eglReleaseTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);
    eglDestroySurface(eglDisplay, pbuffer);
    glDeleteTextures(1, &pbufferTex);
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

Similar Threads

  1. About writing to Global Memory
    By lava in forum OpenCL
    Replies: 5
    Last Post: 07-22-2010, 12:58 AM
  2. Acces violation writing
    By Lyven in forum OpenCL
    Replies: 0
    Last Post: 04-15-2010, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •