
<refentry id="glXSwapBuffers">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>1991-2006</year>
                <holder>Silicon Graphics, Inc.</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>glXSwapBuffers</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>glXSwapBuffers</refname>
        <refpurpose>exchange front and back buffers</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>glXSwapBuffers</function></funcdef>
                <paramdef>Display * <parameter>dpy</parameter></paramdef>
                <paramdef>GLXDrawable <parameter>drawable</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>dpy</parameter></term>
            <listitem>
                <para>
                    Specifies the connection to the X server.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>drawable</parameter></term>
            <listitem>
                <para>
                    Specifies the drawable whose buffers are to be swapped.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            <function>glXSwapBuffers</function> promotes the contents of the back buffer of <parameter>drawable</parameter> to become
            the contents of the front buffer of <parameter>drawable</parameter>.
            The contents of the back buffer then become undefined.
            The update typically takes place during the vertical retrace of
            the monitor,
            rather than immediately after <function>glXSwapBuffers</function> is called.
        </para>
        <para>
            <function>glXSwapBuffers</function> performs an implicit <citerefentry><refentrytitle>glFlush</refentrytitle></citerefentry> before it returns.
            Subsequent OpenGL commands may be issued immediately after calling <function>glXSwapBuffers</function>,
            but are not executed until the buffer exchange is completed.
        </para>
        <para>
            If <parameter>drawable</parameter> was not created with respect to a double-buffered visual,
            <function>glXSwapBuffers</function> has no effect,
            and no error is generated.
        </para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
        <para>
            The contents of the back buffer become undefined after
            a swap. Note that this applies to pixel buffers as well as windows.
        </para>
        <para>
            All GLX rendering contexts share the same notion of which are front buffers
            and which are back buffers.
            One consequence is that when multiple clients are rendering to the same
            double-buffered window,
            all of them should finish rendering before one of them issues the command
            to swap buffers.
            The clients are responsible for implementing this synchronization.
            Typically this is accomplished by executing <citerefentry><refentrytitle>glFinish</refentrytitle></citerefentry> and then
            using a semaphore in shared memory to rendezvous before swapping.
        </para>
    </refsect1>
    <refsect1 id="errors"><title>Errors</title>
        <para>
            <constant>GLXBadDrawable</constant> is generated if <parameter>drawable</parameter> is not a valid GLX drawable.
        </para>
        <para>
            <constant>GLXBadCurrentWindow</constant> is generated if <parameter>dpy</parameter> and <parameter>drawable</parameter> are
            respectively the display and drawable associated with the current
            context of the calling thread, and <parameter>drawable</parameter> identifies a window that
            is no longer valid.
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>glFlush</refentrytitle></citerefentry>
        </para>
    </refsect1>
    <refsect1 id="Copyright"><title>Copyright</title>
        <para>
            Copyright <trademark class="copyright"></trademark> 1991-2006
            Silicon Graphics, Inc. This document is licensed under the SGI
            Free Software B License. For details, see
            <ulink url="http://oss.sgi.com/projects/FreeB/">http://oss.sgi.com/projects/FreeB/</ulink>.
        </para>
    </refsect1>
</refentry>
