Double buffer

How do you do double buffer on WebGL?

Thanks in advance for your help.

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.

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.

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.

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.

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.