OpenGL ES 2.0 and Double Buffering

2,522 views
Skip to first unread message

David Liebman

unread,
May 22, 2012, 12:20:28 PM5/22/12
to andro...@googlegroups.com
Basically the thing is that I cannot figure out how to do double buffering. I've google'd a lot, and come up with some sources, but none that really let me know what to do. Can anyone point me in the right direction? I can't use 'glDrawBuffer(GL_BACK)' in my android ndk setup. I get an error that the method is undefined. I've tried using 'glBindFramebuffer(GL_FRAMEBUFFER, fbo);' in my code. Sometimes it throws an error when executing of GL_INVALID_FRAMEBUFFER_OPERATION. What I'd like to do is below:

static GLint _frameBuffer[2];
GLint screencounter;

void init() {
    glGenFramebuffers(2, _frameBuffer);// make two frame buffers here.
    //other stuff
}

void draw() {
    //construct my texture here and use "glTexImage2D" on it.
    //use "glDrawElements"
    //other stuff
   
    screencounter ++;
   
    GLint local_index = screencounter %2;
    glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer[local_index]);
}

Here is one of the articles I was looking at:

http://zach.in.tu-clausthal.de/teaching/cg_literatur/frame_buffer_objects.html

Any help would be apretiated.

Louise Cypher

unread,
May 22, 2012, 12:56:55 PM5/22/12
to andro...@googlegroups.com
you are already double buffered (the primary framebuffer created with
your GLES context is already double or triple buffered buffered)

until you have more than one gpu in your system there is a little
sense in double buffering 'user' FBOs - what are you trying to do ?
> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/Oy8NL9H_T4kJ.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.



--
--
Code it black!

David Liebman

unread,
May 22, 2012, 2:31:10 PM5/22/12
to andro...@googlegroups.com
I have a game which has an array of pixels, 256x256 that jni writes to. On a regular basis I use 'glTexImage2D' to display this array to the screen as a texture. Sometimes the texture briefly displays areas of black where the jni is writing to the array but has not completed its job while the GLES code is displaying the texture. I want to double buffer so that I can show a buffer while the jni writes my game info to another buffer, and then displays it when it is done. I thought this was fairly common, but I'm finding it hard to do on android with OpenGL ES 2. Your saying that it's already being done some how?
> android-ndk+unsubscribe@googlegroups.com.

Louise Cypher

unread,
May 23, 2012, 8:53:35 AM5/23/12
to andro...@googlegroups.com
so just double buffer texture

GLuint tids[2];

glGenTextures(2, tids);

glBindTexture(GL_TEXTURE_2D, tids[0]);
glTexImage2D(GL_TEXTURE_2D, 0, FinFormat, Width, Height, 0, FinFormat,
ComponentType, NULL); // preallocate GPU ram for first texture
glBindTexture(GL_TEXTURE_2D, tids[1]);
glTexImage2D(GL_TEXTURE_2D, 0, FinFormat, Width, Height, 0, FinFormat,
ComponentType, NULL); // preallocate GPU ram for second texture

int counter = 0;

your game loop:

glBindTexture(GL_TEXTURE_2D, tids[counter]);
glTexSubImage2D(...) // upload portion of texture ... or just the
whole one ... BUT ALWAYS USE glTexSubImage2D even if you uploading
whole texture - this way driver will not reallocate it all over again

DrawQuad(tids[counter]);

counter = (counter+1)&1;



this way you will allow gpu to be lagging one frame behind cpu before
the cpu will be forced to wait for gpu - hope that helps
>> > android-ndk...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/android-ndk?hl=en.
>>
>>
>>
>> --
>> --
>> Code it black!
>
> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/AldDq8TG0oMJ.
>
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.

David Liebman

unread,
May 23, 2012, 5:12:43 PM5/23/12
to andro...@googlegroups.com
thanks. thanks for the code. I will try this. I'm sketchy about some of the details, but I'll give it a try.
>> > android-ndk+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/android-ndk?hl=en.
>>
>>
>>
>> --
>> --
>> Code it black!
>
> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/AldDq8TG0oMJ.
>
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages