﻿<?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="glTexImage2D">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>1991-2006</year>
                <holder>Silicon Graphics, Inc.</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>glTexImage2D</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>glTexImage2D</refname>
        <refpurpose>specify a two-dimensional texture image</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>glTexImage2D</function></funcdef>
                <paramdef>GLenum <parameter>target</parameter></paramdef>
                <paramdef>GLint <parameter>level</parameter></paramdef>
                <paramdef>GLint <parameter>internalformat</parameter></paramdef>
                <paramdef>GLsizei <parameter>width</parameter></paramdef>
                <paramdef>GLsizei <parameter>height</parameter></paramdef>
                <paramdef>GLint <parameter>border</parameter></paramdef>
                <paramdef>GLenum <parameter>format</parameter></paramdef>
                <paramdef>GLenum <parameter>type</parameter></paramdef>
                <paramdef>const GLvoid * <parameter>data</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <para>
    </para>
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>target</parameter></term>
            <listitem>
                <para>
                    Specifies the target texture of the active texture unit.
                    Must be <constant>GL_TEXTURE_2D</constant>,
                    <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_X</constant>,
                    <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_X</constant>,
                    <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_Y</constant>,
                    <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_Y</constant>,
                    <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_Z</constant>, or
                    <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_Z</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>level</parameter></term>
            <listitem>
                <para>
                    Specifies the level-of-detail number.
                    Level 0 is the base image level.
                    Level <emphasis>n</emphasis> is the <emphasis>n</emphasis>th mipmap reduction image.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>internalformat</parameter></term>
            <listitem>
                <para>
                    Specifies the internal format of the texture.
                    Must be one of the following symbolic constants:
                    <constant>GL_ALPHA</constant>,
                    <constant>GL_LUMINANCE</constant>,
                    <constant>GL_LUMINANCE_ALPHA</constant>,
                    <constant>GL_RGB</constant>,
                    <constant>GL_RGBA</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>width</parameter></term>
            <listitem>
                <para>
                    Specifies the width of the texture image.
                    All implementations support 2D texture images that are at least 64 texels
                    wide and cube-mapped texture images that are at least 16 texels wide.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>height</parameter></term>
            <listitem>
                <para>
                    Specifies the height of the texture image
                    All implementations support 2D texture images that are at least 64 texels
                    high and cube-mapped texture images that are at least 16 texels high.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>border</parameter></term>
            <listitem>
                <para>
                    Specifies the width of the border.
                    Must be 0.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>format</parameter></term>
            <listitem>
                <para>
                    Specifies the format of the texel data.  Must match <parameter>internalformat</parameter>.
                    The following symbolic values are accepted:
                    <constant>GL_ALPHA</constant>,
                    <constant>GL_RGB</constant>,
                    <constant>GL_RGBA</constant>,
                    <constant>GL_LUMINANCE</constant>, and
                    <constant>GL_LUMINANCE_ALPHA</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>type</parameter></term>
            <listitem>
                <para>
                    Specifies the data type of the texel data.
                    The following symbolic values are accepted:
                    <constant>GL_UNSIGNED_BYTE</constant>,
                    <constant>GL_UNSIGNED_SHORT_5_6_5</constant>,
                    <constant>GL_UNSIGNED_SHORT_4_4_4_4</constant>, and
                    <constant>GL_UNSIGNED_SHORT_5_5_5_1</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>data</parameter></term>
            <listitem>
                <para>
                    Specifies a pointer to the image data in memory.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            Texturing maps a portion of a specified texture image 
            onto each graphical primitive for which texturing is
            active.  Texturing is active when the current fragment shader or
            vertex shader makes use of built-in texture lookup 
            functions.
        </para>
        <para>
            To define texture images, call <function>glTexImage2D</function>.
            The arguments describe the parameters of the texture image,
            such as height,
            width,
            level-of-detail number
            (see <citerefentry><refentrytitle>glTexParameter</refentrytitle></citerefentry>),
            and format.
            The last three arguments describe how the image is represented in memory.
        </para>
        <para>
            Data is read from <parameter>data</parameter> as a sequence of unsigned bytes or shorts,
            depending on <parameter>type</parameter>.
            When <parameter>type</parameter> is <constant>GL_UNSIGNED_BYTE</constant>, 
            each of the bytes is interpreted as one color component.
            When <parameter>type</parameter> is one of 
            <constant>GL_UNSIGNED_SHORT_5_6_5</constant>, <constant>GL_UNSIGNED_SHORT_4_4_4_4</constant>, or
            <constant>GL_UNSIGNED_SHORT_5_5_5_1</constant>, each unsigned short value is interpreted as
            containing all the components for a single texel, with the color
            components arranged according to <parameter>format</parameter>.
            Color components are treated as groups of one, two, three, or four
            values, again based on <parameter>format</parameter>. Groups of
            components are referred to as texels.
        </para>
        <para>
            <inlineequation><mml:math>
                <!-- eqn: width  times  height:-->
                <mml:mrow>
                    <mml:mi mathvariant="italic">width</mml:mi>
                    <mml:mo>&times;</mml:mo>
                    <mml:mi mathvariant="italic">height</mml:mi>
                </mml:mrow>
            </mml:math></inlineequation>
            texels are read from memory,
            starting at location <parameter>data</parameter>.
            By default, these texels are taken from adjacent memory locations,
            except that after all <parameter>width</parameter> texels are read,
            the read pointer is advanced to the next four-byte boundary.
            The four-byte row alignment is specified by <citerefentry><refentrytitle>glPixelStorei</refentrytitle></citerefentry> with
            argument <constant>GL_UNPACK_ALIGNMENT</constant>,
            and it can be set to one, two, four, or eight bytes.
        </para>
        <para>
            The first element corresponds to the lower left corner of the texture
            image.
            Subsequent elements progress left-to-right through the remaining texels
            in the lowest row of the texture image, and then in successively higher
            rows of the texture image.
            The final element corresponds to the upper right corner of the texture
            image.
        </para>
        <para>
            <parameter>format</parameter> determines the composition of each element in <parameter>data</parameter>.
            It can assume one of these symbolic values:
        </para>
        <variablelist>
            <varlistentry>
                <term><constant>GL_ALPHA</constant></term>
                <listitem>
                    <para>
                        Each element is a single alpha component.
                        The GL converts it to floating point and assembles it into an RGBA element
                        by attaching 0 for red, green, and blue.
                        Each component is then clamped to the range [0,1].
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_RGB</constant></term>
                <listitem>
                    <para>
                        Each element is an RGB triple.
                        The GL converts it to floating point and assembles it into an RGBA element
                        by attaching 1 for alpha.
                        Each component is then clamped to the range [0,1].
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_RGBA</constant></term>
                <listitem>
                    <para>
                        Each element contains all four components.  The GL converts it to floating point, then
                        each component is clamped to the range [0,1].
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_LUMINANCE</constant></term>
                <listitem>
                    <para>
                        Each element is a single luminance value.
                        The GL converts it to floating point,
                        then assembles it into an RGBA element by replicating the luminance value
                        three times for red, green, and blue and attaching 1 for alpha.
                        Each component is then clamped to the range [0,1].
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_LUMINANCE_ALPHA</constant></term>
                <listitem>
                    <para>
                        Each element is a luminance/alpha pair.
                        The GL converts it to floating point,
                        then assembles it into an RGBA element by replicating the luminance value
                        three times for red, green, and blue.
                        Each component is then clamped to the range [0,1].
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
        <para>
            Color components are converted to floating point based on the <parameter>type</parameter>.
            When <parameter>type</parameter> is <constant>GL_UNSIGNED_BYTE</constant>,
            each component is divided by
            <inlineequation><mml:math>
                <!-- eqn: 2 sup 8 - 1:-->
                <mml:mrow>
                    <mml:msup><mml:mn>2</mml:mn>
                    <mml:mn>8</mml:mn>
                    </mml:msup>
                    <mml:mo>-</mml:mo>
                    <mml:mn>1</mml:mn>
                </mml:mrow>
            </mml:math></inlineequation>.
            When <parameter>type</parameter> is <constant>GL_UNSIGNED_SHORT_5_6_5</constant>,
            <constant>GL_UNSIGNED_SHORT_4_4_4_4</constant>, or <constant>GL_UNSIGNED_SHORT_5_5_5_1</constant>,
            each component is divided by
            <inlineequation><mml:math>
                <!-- eqn: 2 sup N - 1:-->
                <mml:mrow>
                    <mml:msup><mml:mn>2</mml:mn>
                    <mml:mi>N</mml:mi>
                    </mml:msup>
                    <mml:mo>-</mml:mo>
                    <mml:mn>1</mml:mn>
                </mml:mrow>
            </mml:math></inlineequation>,
            where <inlineequation><mml:math><mml:mi mathvariant="italic">N</mml:mi></mml:math></inlineequation> 
            is the number of bits in the bitfield.
        </para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
        <para>
            <parameter>internalformat</parameter> must match <parameter>format</parameter>.
            No conversion between formats is supported during texture image processing.
            <parameter>type</parameter> may be used as a hint to specify how much
            precision is desired, but a GL implementation may choose to store the texture
            array at any internal resolution it chooses.
        </para>
        <para>
            <parameter>data</parameter> may be a null pointer.
            In this case, texture memory is
            allocated to accommodate a texture of width <parameter>width</parameter> and height <parameter>height</parameter>.
            You can then download subtextures to initialize this
            texture memory.
            The image is undefined if the user tries to apply
            an uninitialized portion of the texture image to a primitive.
        </para>
        <para>
            <function>glTexImage2D</function>
            specifies a two-dimensional or cube-map texture for the current texture unit,
            specified with <citerefentry><refentrytitle>glActiveTexture</refentrytitle></citerefentry>.
        </para>
    </refsect1>
    <refsect1 id="errors"><title>Errors</title>
        <para>
            <constant>GL_INVALID_ENUM</constant> is generated if <parameter>target</parameter> is not <constant>GL_TEXTURE_2D</constant>,
            <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_X</constant>,
            <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_X</constant>,
            <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_Y</constant>,
            <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_Y</constant>,
            <constant>GL_TEXTURE_CUBE_MAP_POSITIVE_Z</constant>, or 
            <constant>GL_TEXTURE_CUBE_MAP_NEGATIVE_Z</constant>.
        </para>
        <para>
            <constant>GL_INVALID_ENUM</constant> is generated if <parameter>format</parameter> 
            or <parameter>type</parameter> is not an accepted value.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> is generated if <parameter>target</parameter> is one of the six cube map 2D image targets and the width and height parameters are not equal.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> is generated if <parameter>level</parameter> is less than 0.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> may be generated if <parameter>level</parameter> is greater than 
            <inlineequation><mml:math>
                <!-- eqn: log sub 2 (max):-->
                <mml:mrow>
                    <mml:msub><mml:mi mathvariant="italic">log</mml:mi>
                    <mml:mn>2</mml:mn>
                    </mml:msub>
                    <mml:mo>&af;</mml:mo>
                    <mml:mfenced open="(" close=")">
                        <mml:mi mathvariant="italic">max</mml:mi>
                    </mml:mfenced>
                </mml:mrow>
            </mml:math></inlineequation>,
            where <emphasis>max</emphasis> is the returned value of 
            <constant>GL_MAX_TEXTURE_SIZE</constant> when <parameter>target</parameter>
            is <constant>GL_TEXTURE_2D</constant> or <constant>GL_MAX_CUBE_MAP_TEXTURE_SIZE</constant> when
            <parameter>target</parameter> is not <constant>GL_TEXTURE_2D</constant>.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> is generated if <parameter>internalformat</parameter> is not an
            accepted format.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> is generated if <parameter>width</parameter> or <parameter>height</parameter> is less than 0
            or greater than <constant>GL_MAX_TEXTURE_SIZE</constant> when <parameter>target</parameter>
            is <constant>GL_TEXTURE_2D</constant> or <constant>GL_MAX_CUBE_MAP_TEXTURE_SIZE</constant> when
            <parameter>target</parameter> is not <constant>GL_TEXTURE_2D</constant>.
        </para>
        <para>
            <constant>GL_INVALID_VALUE</constant> is generated if <parameter>border</parameter> is not 0.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <parameter>format</parameter> does
            not match <parameter>internalformat</parameter>.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <parameter>type</parameter> is
            <constant>GL_UNSIGNED_SHORT_5_6_5</constant>
            and <parameter>format</parameter> is not <constant>GL_RGB</constant>.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <parameter>type</parameter> is
            <constant>GL_UNSIGNED_SHORT_4_4_4_4</constant> or
            <constant>GL_UNSIGNED_SHORT_5_5_5_1</constant>
            and <parameter>format</parameter> is not <constant>GL_RGBA</constant>.
        </para>
    </refsect1>
    <refsect1 id="associatedgets"><title>Associated Gets</title>
        <para>
            <citerefentry><refentrytitle>glGet</refentrytitle></citerefentry>
            with argument <constant>GL_MAX_TEXTURE_SIZE</constant> or
            <constant>GL_MAX_CUBE_MAP_TEXTURE_SIZE</constant>
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>glActiveTexture</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glCompressedTexImage2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glCompressedTexSubImage2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glCopyTexImage2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glCopyTexSubImage2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glPixelStorei</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glTexSubImage2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glTexParameter</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>
