<?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="glUniform">
    <refmeta>
	<refentrytitle>glUniform</refentrytitle>
	<manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
	<refdescriptor>glUniform</refdescriptor>
	<refname>glUniform1f</refname>
	<refname>glUniform2f</refname>
	<refname>glUniform3f</refname>
	<refname>glUniform4f</refname>
	<refname>glUniform1i</refname>
	<refname>glUniform2i</refname>
	<refname>glUniform3i</refname>
	<refname>glUniform4i</refname>
	<refname>glUniform1fv</refname>
	<refname>glUniform2fv</refname>
	<refname>glUniform3fv</refname>
	<refname>glUniform4fv</refname>
	<refname>glUniform1iv</refname>
	<refname>glUniform2iv</refname>
	<refname>glUniform3iv</refname>
	<refname>glUniform4iv</refname>
	<refname>glUniformMatrix2fv</refname>
	<refname>glUniformMatrix3fv</refname>
	<refname>glUniformMatrix4fv</refname>
	<refname>glUniformMatrix2x3fv</refname>
	<refname>glUniformMatrix3x2fv</refname>
	<refname>glUniformMatrix2x4fv</refname>
	<refname>glUniformMatrix4x2fv</refname>
	<refname>glUniformMatrix3x4fv</refname>
	<refname>glUniformMatrix4x3fv</refname>
	<refpurpose>Specify the value of a uniform variable for the current program object</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
	<funcsynopsis>
	    <funcprototype>
		<funcdef>void <function>glUniform1f</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLfloat <parameter>v0</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform2f</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLfloat <parameter>v0</parameter></paramdef>
		<paramdef>GLfloat <parameter>v1</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform3f</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLfloat <parameter>v0</parameter></paramdef>
		<paramdef>GLfloat <parameter>v1</parameter></paramdef>
		<paramdef>GLfloat <parameter>v2</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform4f</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLfloat <parameter>v0</parameter></paramdef>
		<paramdef>GLfloat <parameter>v1</parameter></paramdef>
		<paramdef>GLfloat <parameter>v2</parameter></paramdef>
		<paramdef>GLfloat <parameter>v3</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform1i</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLint <parameter>v0</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform2i</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLint <parameter>v0</parameter></paramdef>
		<paramdef>GLint <parameter>v1</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform3i</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLint <parameter>v0</parameter></paramdef>
		<paramdef>GLint <parameter>v1</parameter></paramdef>
		<paramdef>GLint <parameter>v2</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform4i</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLint <parameter>v0</parameter></paramdef>
		<paramdef>GLint <parameter>v1</parameter></paramdef>
		<paramdef>GLint <parameter>v2</parameter></paramdef>
		<paramdef>GLint <parameter>v3</parameter></paramdef>
	    </funcprototype>
	</funcsynopsis>
    </refsynopsisdiv>
    <refsect1 id="parameters"><title>Parameters</title>
	<variablelist>
	    <varlistentry>
		<term><parameter>location</parameter></term>
		<listitem>
		    <para>Specifies the location of the uniform variable
		    to be modified.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term>
		    <parameter>v0</parameter>,
		    <parameter>v1</parameter>,
		    <parameter>v2</parameter>,
		    <parameter>v3</parameter>
		</term>
		<listitem>
		    <para>Specifies the new values to be used for the
		    specified uniform variable.</para>
		</listitem>
	    </varlistentry>
	</variablelist>
    </refsect1>
    <refsynopsisdiv><title>C Specification</title>
	<funcsynopsis>
	    <funcprototype>
		<funcdef>void <function>glUniform1fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform2fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform3fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform4fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform1iv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLint *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform2iv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLint *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform3iv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLint *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniform4iv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>const GLint *<parameter>value</parameter></paramdef>
	    </funcprototype>
	</funcsynopsis>
    </refsynopsisdiv>
    <refsect1 id="parameters2"><title>Parameters</title>
	<variablelist>
	    <varlistentry>
		<term><parameter>location</parameter></term>
		<listitem>
		    <para>Specifies the location of the uniform value to
		    be modified.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term><parameter>count</parameter></term>
		<listitem>
		    <para>Specifies the number of elements that are to
		    be modified. This should be 1 if the targeted
		    uniform variable is not an array, and 1 or more if it is
		    an array.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term><parameter>value</parameter></term>
		<listitem>
		    <para>Specifies a pointer to an array of
		    <parameter>count</parameter> values that will be
		    used to update the specified uniform
		    variable.</para>
		</listitem>
	    </varlistentry>
	</variablelist>
    </refsect1>
    <refsynopsisdiv><title>C Specification</title>
	<funcsynopsis>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix2fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix3fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix4fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix2x3fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix3x2fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix2x4fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix4x2fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix3x4fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	    <funcprototype>
		<funcdef>void <function>glUniformMatrix4x3fv</function></funcdef>
		<paramdef>GLint <parameter>location</parameter></paramdef>
		<paramdef>GLsizei <parameter>count</parameter></paramdef>
		<paramdef>GLboolean <parameter>transpose</parameter></paramdef>
		<paramdef>const GLfloat *<parameter>value</parameter></paramdef>
	    </funcprototype>
	</funcsynopsis>
    </refsynopsisdiv>
    <refsect1 id="parameters3"><title>Parameters</title>
	<variablelist>
	    <varlistentry>
		<term><parameter>location</parameter></term>
		<listitem>
		    <para>Specifies the location of the uniform value to
		    be modified.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term><parameter>count</parameter></term>
		<listitem>
		    <para>Specifies the number of matrices that are to
		    be modified. This should be 1 if the targeted
		    uniform variable is not an array of matrices, and 1 or more if it is
		    an array of matrices.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term><parameter>transpose</parameter></term>
		<listitem>
		    <para>Specifies whether to transpose the matrix as
		    the values are loaded into the uniform
		    variable.</para>
		</listitem>
	    </varlistentry>
	    <varlistentry>
		<term><parameter>value</parameter></term>
		<listitem>
		    <para>Specifies a pointer to an array of
		    <parameter>count</parameter> values that will be
		    used to update the specified uniform
		    variable.</para>
		</listitem>
	    </varlistentry>
	</variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
	<para><function>glUniform</function> modifies the value of a
	uniform variable or a uniform variable array. The location of
	the uniform variable to be modified is specified by
	<parameter>location</parameter>, which should be a value
	returned by
	<citerefentry><refentrytitle>glGetUniformLocation</refentrytitle></citerefentry>.
	<function>glUniform</function> operates on the program object
	that was made part of current state by calling
	<citerefentry><refentrytitle>glUseProgram</refentrytitle></citerefentry>.</para>

	<para>The commands <function>glUniform{1|2|3|4}{f|i}</function>
	are used to change the value of the uniform variable specified
	by <parameter>location</parameter> using the values passed as
	arguments. The number specified in the command should match the
	number of components in the data type of the specified uniform
	variable (e.g., <function>1</function> for float, int, bool;
	<function>2</function> for vec2, ivec2, bvec2, etc.). The suffix
	<function>f</function> indicates that floating-point values are
	being passed; the suffix <function>i</function> indicates that
	integer values are being passed, and this type should also match
	the data type of the specified uniform variable. The
	<function>i</function> variants of this function should be used
	to provide values for uniform variables defined as int, ivec2,
	ivec3, ivec4, or arrays of these. The <function>f</function>
	variants should be used to provide values for uniform variables
	of type float, vec2, vec3, vec4, or arrays of these. Either the
	<function>i</function> or the <function>f</function> variants
	may be used to provide values for uniform variables of type
	bool, bvec2, bvec3, bvec4, or arrays of these. The uniform
	variable will be set to false if the input value is 0 or 0.0f,
	and it will be set to true otherwise.</para>

	<para>All active uniform variables defined in a program object
	are initialized to 0 when the program object is linked
	successfully. They retain the values assigned to them by a call
	to <function>glUniform </function> until the next successful
	link operation occurs on the program object, when they are once
	again initialized to 0.</para>

	<para>The commands <function>glUniform{1|2|3|4}{f|i}v</function>
	can be used to modify a single uniform variable or a uniform
	variable array. These commands pass a count and a pointer to the
	values to be loaded into a uniform variable or a uniform
	variable array. A count of 1 should be used if modifying the
	value of a single uniform variable, and a count of 1 or greater
	can be used to modify an entire array or part of an array. When
	loading <emphasis>n</emphasis> elements starting at an arbitrary
	position <emphasis>m</emphasis> in a uniform variable array,
	elements <emphasis>m</emphasis> + <emphasis>n</emphasis> - 1 in
	the array will be replaced with the new values. If
	<parameter>m</parameter> + <parameter>n</parameter> - 1 is
	larger than the size of the uniform variable array, values for
	all array elements beyond the end of the array will be ignored.
	The number specified in the name of the command indicates the
	number of components for each element in
	<parameter>value</parameter>, and it should match the number of
	components in the data type of the specified uniform variable
	(e.g., <function>1</function> for float, int, bool;
	<function>2</function> for vec2, ivec2, bvec2, etc.). The data
	type specified in the name of the command must match the data
	type for the specified uniform variable as described previously
	for <function>glUniform{1|2|3|4}{f|i}</function>.</para>

	<para>For uniform variable arrays, each element of the array is
	considered to be of the type indicated in the name of the
	command (e.g., <function>glUniform3f</function> or
	<function>glUniform3fv</function> can be used to load a uniform
	variable array of type vec3). The number of elements of the
	uniform variable array to be modified is specified by
	<parameter>count</parameter></para>

	<para>The commands
	<function>glUniformMatrix{2|3|4|2x3|3x2|2x4|4x2|3x4|4x3}fv</function> 
        are used to modify a matrix or an array of matrices. The numbers in the
	command name are interpreted as the dimensionality of the matrix.
	The number <function>2</function> indicates a 2 &#215; 2 matrix
	(i.e., 4 values), the number <function>3</function> indicates a
	3 &#215; 3 matrix (i.e., 9 values), and the number
	<function>4</function> indicates a 4 &#215; 4 matrix (i.e., 16
	values). Non-square matrix dimensionality is explicit, with the first
        number representing the number of columns and the second number
        representing the number of rows.  For example, 
        <function>2x4</function> indicates a 2 &#215; 4 matrix with 2 columns
        and 4 rows (i.e., 8 values).
        If <parameter>transpose</parameter> is
	<constant>GL_FALSE</constant>, each matrix is assumed to be
	supplied in column major order. If
	<parameter>transpose</parameter> is
	<constant>GL_TRUE</constant>, each matrix is assumed to be
	supplied in row major order. The <parameter>count</parameter>
	argument indicates the number of matrices to be passed. A count
	of 1 should be used if modifying the value of a single matrix,
	and a count greater than 1 can be used to modify an array of
	matrices.</para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
	<para><function>glUniform</function> is available only if the GL
	version is 2.0 or greater.</para>

	<para><function>glUniformMatrix{2x3|3x2|2x4|4x2|3x4|4x3}fv</function> 
        is available only if the GL version is 2.1 or greater.</para>

	<para><function>glUniform1i</function> and
	<function>glUniform1iv</function> are the only two functions
	that may be used to load uniform variables defined as sampler
	types. Loading samplers with any other function will result in a
	<constant>GL_INVALID_OPERATION</constant> error.</para>

	<para>If <parameter>count</parameter> is greater than 1 and the
	indicated uniform variable is not an array, a
	<constant>GL_INVALID_OPERATION</constant> error is generated and the
	specified uniform variable will remain unchanged.</para>

	<para>Other than the preceding exceptions, if the type and size
	of the uniform variable as defined in the shader do not match
	the type and size specified in the name of the command used to
	load its value, a <constant>GL_INVALID_OPERATION</constant> error will
	be generated and the specified uniform variable will remain
	unchanged.</para>

	<para>If <parameter>location</parameter> is a value other than
	-1 and it does not represent a valid uniform variable location
	in the current program object, an error will be generated, and
	no changes will be made to the uniform variable storage of the
	current program object. If <parameter>location</parameter> is
	equal to -1, the data passed in will be silently ignored and the
	specified uniform variable will not be changed.</para>
    </refsect1>
    <refsect1 id="errors"><title>Errors</title>
	<para><constant>GL_INVALID_OPERATION</constant> is generated if there
	is no current program object.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if the
	size of the uniform variable declared in the shader does not
	match the size indicated by the <function>glUniform</function>
	command.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if one of
	the integer variants of this function is used to load a uniform
	variable of type float, vec2, vec3, vec4, or an array of these,
	or if one of the floating-point variants of this function is
	used to load a uniform variable of type int, ivec2, ivec3, or
	ivec4, or an array of these.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if
	<parameter>location</parameter> is an invalid uniform location
	for the current program object and
	<parameter>location</parameter> is not equal to -1.</para>

	<para><constant>GL_INVALID_VALUE</constant> is generated if
	<parameter>count</parameter> is less than 0.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if
	<parameter>count</parameter> is greater than 1 and the indicated
	uniform variable is not an array variable.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if a
	sampler is loaded using a command other than
	<function>glUniform1i</function> and
	<function>glUniform1iv</function>.</para>

	<para><constant>GL_INVALID_OPERATION</constant> is generated if
	<function>glUniform</function> 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="associatedgets"><title>Associated Gets</title>
	<para><citerefentry><refentrytitle>glGet</refentrytitle></citerefentry>
	with the argument <constant>GL_CURRENT_PROGRAM</constant></para>

	<para><citerefentry><refentrytitle>glGetActiveUniform</refentrytitle></citerefentry>
	with the handle of a program object and the index of an active uniform variable</para>

	<para><citerefentry><refentrytitle>glGetUniform</refentrytitle></citerefentry>
	with the handle of a program object and the location of a
	uniform variable</para>

	<para><citerefentry><refentrytitle>glGetUniformLocation</refentrytitle></citerefentry>
	with the handle of a program object and the name of a uniform
	variable</para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
	<para><citerefentry><refentrytitle>glLinkProgram</refentrytitle></citerefentry>,
	<citerefentry><refentrytitle>glUseProgram</refentrytitle></citerefentry></para>
    </refsect1>
    <refsect1 id="Copyright"><title>Copyright</title>
        <para>
            Copyright <trademark class="copyright"></trademark> 2003-2005 3Dlabs Inc. Ltd. 
            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>
