PDA

View Full Version : Double buffer



learnwebgl
11-07-2009, 10:02 AM
How do you do double buffer on WebGL?

Thanks in advance for your help.

Coolcat
11-07-2009, 10:32 AM
Because I don't see any useful application for single buffering I would claim that double buffering is always enabled.

However, there might be some effects that require read access to the front buffer. I would recommend to use FrameBufferObjects (FBO) for these special effects.

learnwebgl
11-07-2009, 11:17 AM
What does it mean that "double buffering is always enabled." ? How does it know when to swap?

My understanding is that OpenGL does not have swap buffer command. I am looking for the equivalent of glutSwapBuffers() function where it explicitly asks to swap the buffer.

Coolcat
11-07-2009, 05:26 PM
As far as I understand it, WebGL does swap automatically when the browser does stop processing your script. Normally your applications does look like this:


window.setInterval("mainloop()", 33);

function mainloop() {
/* update */
...

/* draw scene */
...
}

The browser does swap buffers, when it does leave the mainloop function.

However, there are commands finish() and flush(), but for normal applications there is no need to call them.

learnwebgl
11-08-2009, 10:05 AM
Thanks for the clarification coolcat.

But your (pseudo-code) example seems to be still a single buffer rendering.

Below is the code snippet from http://www.opengl-redbook.com/.

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); // Request double buffer
...
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();

glutSwapBuffers(); // Explicitly request the swap buffer
}

X Windows provides glXSwapBuffers() and Windows provides wglSwapLayerBuffers()

That's a typical OpenGL double buffer rendering.

Coolcat
11-08-2009, 11:09 AM
Once again...the browser does swap buffers, when it does leave the mainloop() function. After that your interval timer does call mainloop() again. Double buffering is used automatically.