<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
              "http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
<refentry id="glBeginQuery">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>2005</year>
                <holder>Sams Publishing</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>glBeginQuery</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>glBeginQuery</refname>
        <refpurpose>delimit the boundaries of a query object</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>glBeginQuery</function></funcdef>
                <paramdef>GLenum <parameter>target</parameter></paramdef>
                <paramdef>GLuint <parameter>id</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>target</parameter></term>
            <listitem>
                <para>
                    Specifies the target type of query object established between
                    <function>glBeginQuery</function> and the subsequent <citerefentry><refentrytitle>glEndQuery</refentrytitle></citerefentry>.
                    The symbolic constant must be <constant>GL_SAMPLES_PASSED</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>id</parameter></term>
            <listitem>
                <para>
                    Specifies the name of a query object.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>glEndQuery</function></funcdef>
                <paramdef>GLenum <parameter>target</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <refsect1 id="parameters2"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>target</parameter></term>
            <listitem>
                <para>
                    Specifies the target type of query object to be concluded.
                    The symbolic constant must be <constant>GL_SAMPLES_PASSED</constant>.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            <function>glBeginQuery</function> and <citerefentry><refentrytitle>glEndQuery</refentrytitle></citerefentry> delimit the
            boundaries of a query object.  If a query object with name <parameter>id</parameter> does not yet exist it is created.
        </para>
        <para>
            When <function>glBeginQuery</function> is executed, the query object's samples-passed counter is reset to 0.  Subsequent
            rendering will increment the counter once for every sample that passes the depth test.  When <function>glEndQuery</function>
            is executed, the samples-passed counter is assigned to the query object's result value.  This value can be queried by
            calling <citerefentry><refentrytitle>glGetQueryObject</refentrytitle></citerefentry> with <parameter>pname</parameter>
            <constant>GL_QUERY_RESULT</constant>.
        </para>
        <para>
            Querying the <constant>GL_QUERY_RESULT</constant> implicitly flushes the GL pipeline until the rendering delimited by the
            query object has completed and the result is available.  <constant>GL_QUERY_RESULT_AVAILABLE</constant> can be queried to
            determine if the result is immediately available or if the rendering is not yet complete.
        </para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
        <para>
            If the samples-passed count exceeds the maximum value representable in the number of available bits, as reported by
            <citerefentry><refentrytitle>glGetQueryiv</refentrytitle></citerefentry> with <parameter>pname</parameter>
            <constant>GL_QUERY_COUNTER_BITS</constant>, the count becomes undefined.
        </para>
        <para>
            An implementation may support 0 bits in its samples-passed counter, in which case query results are always undefined
            and essentially useless.
        </para>
        <para>
            When <constant>GL_SAMPLE_BUFFERS</constant> is 0, the samples-passed counter will increment once for each fragment that passes
            the depth test.  When <constant>GL_SAMPLE_BUFFERS</constant> is 1, an implementation may either increment the samples-passed
            counter individually for each sample of a fragment that passes the depth test, or it may choose to increment the counter for
            all samples of a fragment if any one of them passes the depth test.
        </para>
        <para>
            <function>glBeginQuery</function> and <citerefentry><refentrytitle>glEndQuery</refentrytitle></citerefentry>
            are available only if the GL version is 1.5 or greater.
        </para>
    </refsect1>
    <refsect1 id="errors"><title>Errors</title>
        <para>
            <constant>GL_INVALID_ENUM</constant> is generated if <parameter>target</parameter> is not <constant>GL_SAMPLES_PASSED</constant>.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <function>glBeginQuery</function> is executed while
            a query object of the same <parameter>target</parameter> is already active.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <citerefentry><refentrytitle>glEndQuery</refentrytitle></citerefentry>
            is executed when a query object of the same <parameter>target</parameter> is not active.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <parameter>id</parameter> is 0.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <parameter>id</parameter> is the name of an already active query object.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <function>glBeginQuery</function> or
            <citerefentry><refentrytitle>glEndQuery</refentrytitle></citerefentry> is executed between the execution of
            <citerefentry><refentrytitle>glBegin</refentrytitle></citerefentry> and the corresponding execution of
            <citerefentry><refentrytitle>glEnd</refentrytitle></citerefentry>.
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>glDeleteQueries</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glGenQueries</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glGetQueryiv</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glGetQueryObject</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glIsQuery</refentrytitle></citerefentry>
        </para>
    </refsect1>
    <refsect1 id="Copyright"><title>Copyright</title>
        <para>
            Copyright <trademark class="copyright"></trademark> 2005 Addison-Wesley. 
            This material may be distributed subject to the terms and conditions set forth in 
            the Open Publication License, v 1.0, 8 June 1999.
            <ulink url="http://opencontent.org/openpub/">http://opencontent.org/openpub/</ulink>.
        </para>
    </refsect1>
</refentry>
