Is it possible to read back content of VBO in OpenGL ES 2.0 ?
I have tried glMapBufferOES
, but there is no READ flag.
I dont want any answers, like "you shouldnt do it" or "keep copy of geometry in ram".
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI have used glMapBufferRange
EXT (on iOS it should be supported on all types of devices), instead of glMapBufferOES
/ glUnMapBufferOES
with READ flag, and its working correctly
glBindBuffer( GL_ARRAY_BUFFER, buffer );
void * data = glMapBufferRange(GL_ARRAY_BUFFER, 0, vboSize, GL_MAP_READ_BIT);
//do someething with data
glBindBuffer( GL_ARRAY_BUFFER, 0 );
Regarding OpenGL ES glMapBufferOES
is not part of the standard OpenGL ES but is actually an extension, regardless, it seems you can't use GL_READ_ONLY_OES the only defined tokens according to the extension registry are
/* GL_OES_mapbuffer */
#ifndef GL_OES_mapbuffer
#define GL_WRITE_ONLY_OES 0x88B9
#define GL_BUFFER_ACCESS_OES 0x88BB
#define GL_BUFFER_MAPPED_OES 0x88BC
#define GL_BUFFER_MAP_POINTER_OES 0x88BD
#endif
It seems you can only use GL_WRITE_ONLY_OES, I suspect that you can memcpy returned pointer (since naturally speaking writing on a memory location require reading it first from a computer architecture point of view). This is only a speculation I didn't test it nor I guarantee it to work. for example in semi-pseudo code:
GLvoid* vbo = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
for (int i = 0; i < count; i++) {
memcpy( yourBuffer, vbo, 4*sizeof(GLfloat));
}
glMapBufferOES(GL_ARRAY_BUFFER, GL_READ_ONLY)
can not be done, because GL_READ_ONLY
does not exest
\$\endgroup\$
Nov 3, 2013 at 10:30
I dont want any answers, like "you shouldnt do it" or "keep copy of geometry in ram".
You're going to be disappointed then because the GL ES specification and documentation don't define any way of reading back: http://www.khronos.org/opengles/sdk/docs/man/
At this stage you need to consider why you want to do such a readback; reading back from GPU memory is a slow operation, and if you really must do it, you may be better off just not using buffer objects at all (which is allowed by ES2).