Android : How does CVPixelBuffers work?

on Monday, September 8, 2014


Several SO answers suggest using the platform-specific iOS CVPixelBuffers as a faster alternative to the portable OpenGL ES 2.0 glReadPixels().


IIUC, the CVPixelBuffers can be bound as "regular" OpenGL textures and rendered to. Later they can be locked, and their memory buffer can be directly accessed by the CPU (quoting from here).



CVPixelBufferLockBaseAddress(renderTarget, 0);
_rawBytesForImage = (GLubyte *)CVPixelBufferGetBaseAddress(renderTarget);
// Do something with the bytes
CVPixelBufferUnlockBaseAddress(renderTarget, 0);


So, where does the memory for CVPixelBuffers reside:



  1. In CPU memory

  2. In GPU memory

  3. In parts of the GPU memory directly accessible to the CPU

  4. Data is copied automatically by the OS

  5. Other?


Can this effect be achieved in a more portable way such as extensions, FBO, PBO etc.?


This post seems to show how to do something similar on Android via an EGL extension.



uint8_t *ptr;
glBindTexture(GL_TEXTURE_2D, texture_id);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
window->lock(GraphicBuffer::USAGE_SW_READ_OFTEN, &ptr);
memcpy(pixels, ptr, width * height * 4);
window->unlock();


Is there a difference?


0 comments:

Post a Comment