Forums - Unable to update Graphicbuffer bound to texture

2 posts / 0 new
Last post
Unable to update Graphicbuffer bound to texture
emilwestergren
Join Date: 4 Jul 14
Posts: 6
Posted: Thu, 2014-11-13 00:45

I am trying to implement a faster way of dynamically uploading textures to the GPU by using the EGLImage extension.

I first create a GraphicBuffer and bind it to an OpenGL texture:

buffers[index] = new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, GraphicBuffer::USAGE_SW_WRITE_OFTEN | GraphicBuffer::USAGE_HW_TEXTURE);
EGLint eglImageAttributes[] = {EGL_IMAGE_PRESERVED_KHR, EGL_FALSE, EGL_NONE};
EGLClientBuffer nativeBuffer = buffers[index]->getNativeBuffer();
eglImages[index] = _eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, nativeBuffer, eglImageAttributes);
_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImages[index]);

I lock the buffer and copy pixels to it:

buffers[index]->lock(GraphicBuffer::USAGE_SW_READ_OFTEN, &pixels);
/* Copy pixels to buffer... */
buffers[index]->unlock();

 

This works the first frame but after I have drawn the texture in OpenGL I am unable to modify the data in the GraphicBuffer (so the same texture is always drawn). How can I modify the OpenGL texture by simply modifying the GraphicBuffer? I am not sure if I am simply doing this wrong or if there is some kind of lock on the buffer after OpenGL has used it.

  • Up0
  • Down0
mhfeldma Moderator
Join Date: 29 Nov 12
Posts: 310
Posted: Fri, 2014-11-14 12:48

Hi..  It should be possible to use GraphicBuffer to continually update a texture.  Just a few ideas...

1) Try using these flags when creating the GraphicBuffer:

android::GraphicBuffer::USAGE_HW_TEXTURE

android::GraphicBuffer::USAGE_HW_2D

GRALLOC_USAGE_SW_READ_OFTEN

GRALLOC_USAGE_SW_WRITE_OFTEN);

 

2) Try setting the EGL_IMAGE_PRESERVED_KHR attribute to true

 

3) After updating the texture, make sure you set the active texture, and bind..

glActiveTexture(GL_TEXTURE0));
glEnable(GL_TEXTURE_2D));

glBindTexture(GL_TEXTURE_2D, texID);

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.