Mesa Subset Specification

Tungsten Graphics, Inc.

February 26, 2003

Copyright © 2002-2003 by Tungsten Graphics, Inc., Cedar Park, Texas. All Rights Reserved.

Permission is granted to make and distribute verbatim copies of this document provided the copyright notice and this permission notice are preserved on all copies.

OpenGL is a trademark of Silicon Graphics, Inc..

1. Introduction

This document describes a subset of the Mesa implemented by Tungsten Graphics, Inc. for embedded devices.  Prior to reading this document the reader should be familiar with the OpenGL 1.2.1 specification dated April 1, 1999 (available from http://www.opengl.org/developers/documentation/specs.html.)  Experience with OpenGL programming is highly advisable.

Tungsten Graphics, Inc. is working with industry standards organizations +in an attempt to standardize this Mesa subset and any other possible subsets +as a result of this work.

Appendix A contains a list of issues of which some may not be resolved.

To summarize, the following major features of Mesa are omitted from the subset:

Further reductions are made at a lower level of detail.

Mesa function names are printed in bold face.  Function parameters are printed in italics.

The Tungsten Graphics, Inc. Mesa subset library is hereafter referred to as the subset.

2. Primitive Specification

2.1 glBegin, glEnd and glVertex Commands

The basic rendering primitives are points, lines and triangles.  Quadrilaterals and polygons are composed of triangles.  Primitives are drawn with the glBegin and glEnd commands and a subset of the glVertex commands:

void glBegin(GLenummode)
void glEnd(void)

void glVertex2f(GLfloat x, GLfloat y)
void glVertex2fv(const GLfloat *v)
void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
void glVertex3fv(const GLfloat *v)

The mode parameter to glBegin may be one of the following

GL_POINTS - a series of individual points
GL_LINES - a series of disjoint line segments
GL_LINE_STRIP - series of connected line segments
GL_LINE_LOOP - a closed loop of line segments
GL_TRIANGLES - a series of individual triangles
GL_TRIANGLE_STRIP - a connected strip of triangles
GL_TRIANGLE_FAN - a sequence of triangles all sharing a common vertex
GL_QUADS - a sequence of individual quadrilaterals
GL_QUAD_STRIP - a connected strip of quadrilaterals
GL_POLYGON - a closed, convex polygon


The glVertex commands take two or three floating point coordinates, or a pointer to an array of two or three floating point coordinates.  Vertices are actually 4-element homogeneous coordinates.  The fourth component, unspecified by the subset's glVertex commands, is one.

2.2 Other Per-vertex Commands

The glColor and glTexCoord commands may be used to specify colors and texture coordinates for each vertex:

void glColor3f(GLfloatred, GLfloat green, GLfloat blue)
void glColor3fv(const GLfloat *rgb)
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
void glColor4fv(const GLfloat *rgba)
void glTexCoord2f(GLfloat s, GLfloat t)
void glTexCoord2fv(const GLfloat *c)

The glColor commands specify the color and optionally, the alpha value, for subsequent vertices.  For the glColor3 commands, alpha is set to one.

The glTexCoord2 commands specify the texture coordinate for subsequent vertices.  Texture coordinates are actually four-component coordinates: (s, t, r, q).  The glTexCoord2 commands set s and t explicitly.  The r and q components are zero and one, respectively.

Only glVertex, glColor and glTexCoord commands are allowed between glBegin and glEnd.  Calling any other command between glBegin and glEnd will result in the error GL_INVALID_OPERATION.

2.3 Unsupported Commands

None of the following commands related to primitive specification are supported by the subset:

Per-Vertex commands:
glVertex2d, glVertex2i, glVertex2s, glVertex3d, glVertex3i, glVertex3s, glVertex4d, glVertex4i, glVertex4s, glVertex2dv, glVertex2iv, glVertex2sv, glVertex3dv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4iv, glVertex4sv,
glNormal3b, glNormal3d, glNormal3f, glNormal3i, glNormal3s,
glNormal3bv, glNormal3dv, glNormal3fv, glNormal3iv, glNormal3sv,
glIndexd, glIndexf, glIndexi, glIndexs, glIndexub, glIndexdv, glIndexfv, glIndexiv, glIndexsv, glIndexubv,
glColor3b, glColor3d, glColor3i, glColor3s, glColor3ub, glColor3ui, glColor3us,
glColor3bv, glColor3dv, glColor3iv, glColor3sv, glColor3ubv, glColor3uiv, glColor3usv, lColor4b, glColor4d, glColor4i, glColor4s, glColor4ub, glColor4ui, glColor4us, glColor4bv, glColor4dv, glColor4iv, glColor4sv, glColor4ubv, glColor4uiv, glColor4usv,
glTexCoord1d, glTexCoord1f, glTexCoord1i, glTexCoord1s, glTexCoord2d, glTexCoord2i, glTexCoord2s, glTexCoord3d, glTexCoord3f, glTexCoord3i, glTexCoord3s, glTexCoord4d, glTexCoord4f, glTexCoord4i, glTexCoord4s, glTexCoord1dv, glTexCoord1fv, glTexCoord1iv, glTexCoord1sv, glTexCoord2dv, glTexCoord2iv, glTexCoord2sv, glTexCoord3dv, glTexCoord3fv, glTexCoord3iv, glTexCoord3sv, glTexCoord4dv, glTexCoord4fv, glTexCoord4iv, glTexCoord4sv,
glEdgeFlag, glEdgeFlagv


Vertex array commands:
glVertexPointer, glColorPointer, glIndexPointer, glTexCoordPointer, glEdgeFlagPointer, glNormalPointer, glInterleavedArrays, glArrayElement, glDrawArrays, glDrawElements, glDrawRangeElements, glEnableClientState, glDisableClientState

Rectangle commands:
glRects, glRecti, glRectf, glRectd, glRectsv, glRectiv, glRectfv, glRectdv,

Lighting commands:
glMaterialf, glMateriali, glMaterialfv, glMaterialiv

Evaluator commands:
glEvalCoord1d, glEvalCoord1f, glEvalCoord1dv, glEvalCoord1fv, glEvalCoord2d, glEvalCoord2f, glEvalCoord2dv, glEvalCoord2fv,
glEvalPoint1, glEvalPoint2

3. Coordinate Transformation

3.1 Vertex Transformation

Vertex coordinates are transformed by the current modelview and projection matrices then mapped to window coordinates as specified by the viewport.  The following coordinate transformation commands are supported by the subset

glMatrixMode(GLenum mode)
glLoadIdentity(void)
glPushMatrix(void)
glPopMatrix(void)
glLoadMatrixf(const GLfloat *m)
glMultMatrixf(const GLfloat *m)
glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
glTranslatef(GLfloat x, GLfloat y, GLfloat z)
glScalef(GLfloat x, GLfloat y, GLfloat z)
glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)

glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
glViewport(GLint x, GLint y, GLsize width, GLsizei height)

The glMatrixMode command specifies the current matrix.  The mode parameter may be GL_MODELVIEW or GL_PROJECTION to specify the modelview matrix or projection matrix.  Subsequent matrix commands will effect the current matrix.  Also associated with the modelview and projection matrices are a modelview matrix stack and projection matrix stack.

The glLoadIdentity command replaces the current matrix with the identity matrix.  The matrix elements are specified in column-major order.

The glPushMatrix command pushes a copy of the current matrix onto either the modelview matrix stack or the projection matrix stack.  The glPopMatrix command replaces the current matrix with a copy of the top matrix off the modelview matrix stack or projection matrix stack, the pops the stack.  Matrix stacks are useful for traversing and rendering hierarchical models.

The glMultMatrixf command post-multiplies the current matrix by the specified matrix.  The matrix elements are specified in column-major order.

The glRotatef command post-multiplies the current matrix by a rotation matrix defined by the angle and rotation axis defined by x, y and z.

The glTranslatef command post-multiplies the current matrix by a translation matrix defined by the x, y and z translation parameters.

The glScalef command post-multiplies the current matrix by a scaling matrix defined by the x, y and z scale factors.

The glFrustum command post-multiplies the current matrix by a perspective projection matrix.  The near and far values specify the position of the hither and yon Z-axis clipping planes.  The left, right, bottom and top parameters are the X and Y extents at the near clipping plane.  glFrustum is normally used to modify the projection matrix.

The glOrtho command post-multiplies the current matrix by an orthographic projection matrix.  The near and far values specify the position of the hither and yon Z-axis clipping planes.  The left, right, bottom and top parameters specify the X and Y-axis clipping planes.  glOrtho is normally used to modify the projection matrix.

The glViewport command specifies the mapping of coordinates from normalized device coordinates to window coordinates.  The x and y parameters specify the viewport's lower-left corner in the window and the width and height parameters specify the size of the viewport.  glViewport does not effect the current matrix.

A coordinate transformed to window coordinates is hereafter known as (xw, yw, zw).

3.2 Clipping

View-volume clipping automatically discards or trims primitives which lie completely or partially outside of the view volume specified by glFrustum and glOrtho.  Note that the glViewport command does not define a clipping region.

Clipping occurs in clip coordinate space - the coordinates produced after applying the projection matrix.

3.3 Current Raster Position

The current raster position specifies the location for drawing images with glBitmap.  The current raster position is set with the commands:

void glRasterPos2f(GLfloatx, GLfloat y)
void glRasterPos2fv(const GLfloat *v)
void glRasterPos2i(GLint x, GLint y)
void glRasterPos2iv(const GLint *v)

glRasterPos specifies a 4-component coordinate (x, y, 0, 1).  The coordinate is processed like a vertex; it is transformed by the modelview matrix, the projection matrix and mapped to the viewport.  The resulting window coordinate is stored as the current raster position.  The coordinate is clipped-tested against the frustum like a vertex.  If the coordinate is clipped, then the current raster position becomes invalid and subsequent glBitmap commands have no effect.

glRasterPos also updates the current raster color and current raster texture coordinates.  The current raster color is updated (copied) from the current color (as specified by glColor).  The current raster texture coordinate is updated (copied) from the current texture coordinate (as specified by glTexCoord).

3.4 Unsupported Commands

The following commands related to vertex transformation are not supported by the subset:

User-defined clip plane commands:
glClipPlane

Lighting and material commands:
glLightModeli, glLightModelf, glLightModeliv, glLightModelfv, glLightf, glLighti, glLightfv, glLightiv, glColorMaterial

Automatic texture coordinate generation commands:
glTexGend, glTexGenf, glTexGeni, glTexGendv, glTexGenfv, glTexGeniv,

Double-valued commands:
glLoadMatrixd, glMultMatrixd, glRotated, glTranslated, glScaled

Depth Range command:
glDepthRange (the near value is always 0.0 and the far value is always 1.0)

Extra RasterPos commands:
glRasterPos2d, glRasterPos2s, glRasterPos3d, glRasterPos3f, glRasterPos3i, glRasterPos3s, glRasterPos4d, glRasterPos4f, glRasterPos4i, glRasterPos4s, glRasterPos2dv, glRasterPos2sv, glRasterPos3dv, glRasterPos3fv, glRasterPos3iv, glRasterPos3sv, glRasterPos4dv, glRasterPos4fv, glRasterPos4iv, glRasterPos4sv


4. Rasterization

This section describes the commands and options for drawing points, lines, triangles and bitmaps.  Rasterization is the term for the process which produces fragments from the geometric description of a primitive (a point, line, polygon or bitmap).  For example, given the two coordinates for the end-points of a line segment, rasterization determines which pixels in the frame buffer are modified to draw the line.  A fragment is a tuple which consists of a window coordinate, colors and texture coordinates.  The fragments produced by rasterization are subsequently processed by the per-fragment operations described later.

4.1 Point Rasterization

Points are rendered with the command sequence glBegin(GL_POINTS), glVertex, ... glEnd.  The window coordinate (xw, yw, zw) is truncated to rasterize the point.  The truncated coordinate with its associated color and texture coordinate is sent as a single fragment to the per-fragment processing stages.

The glPointSize command is not supported; only 1-pixel points are supported.

Point smoothing (antialiasing) is also not supported.

4.2 Line Rasterization

Lines are rendered with the command sequence glBegin(mode), glVertex, glVertex, ... glEnd where mode is one of GL_LINES, GL_LINE_STRIP or GL_LINE_LOOP.  Lines are rasterized as described in the OpenGL specification.  Note that OpenGL specifies the half-open convention for drawing lines: the last fragment in a line segment is omitted so that endpoint pixels shared by two line segments will only be drawn once instead of twice.

4.2.1 Line Width

The width of lines can be controlled by

void glLineWidth(GLfloatwidth)

where width is the line width in pixels.  The width defaults to 1.0.  Attempting to set the width to a value less than or equal to zero will raise the error GL_INVALID_VALUE.

4.2.2 Line Stipple

Lines may be stippled (i.e. dashed) with the command

glLineStipple(GLintfactor, GLushort pattern)

pattern describes an on/off pattern for the fragments produced by rasterization and factor specifies how many subsequent fragments are kept or culled for each pattern bit.  Line stippling can be enabled or disabled by the commands glEnable(GL_LINE_STIPPLE) and glDisable(GL_LINE_STIPPLE).

4.2.3 Line Antialiasing

Lines may be antialiased.  For antialiased lines, each fragment produced by rasterization is assigned a coverage value which describes how much of the fragment's area is considered to be inside the line.  Later, the alpha value of each fragment is multiplied by the coverage value.  By blending the fragments into the frame buffer, the edges of lines appear smoothed.

Line antialiasing can be enabled or disabled with the commands glEnable(GL_LINE_SMOOTH) and glDisable(GL_LINE_SMOOTH).

4.3 Polygon Rasterization

Polygons, quadrilaterals and triangles share the same polygon rasterization options.

Triangles are rendered by the command sequence glBegin(mode),glVertex, glVertex, ... glEnd where mode may be one of GL_TRIANGLES, GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN.  For GL_TRIANGLES mode, the number of vertices should be a multiple of three - extra vertices will be ignored.  For GL_TRIANGLE_STRIP and GL_TRIANGLE_FAN, at least three vertices should be specified.  If less than three are specified, nothing is drawn.  

Quadrilaterals are rendered by the command sequence glBegin(mode),glVertex, glVertex, ... glEnd where mode may be one of GL_QUADS or GL_QUAD_STRIP.   For GL_QUADS, the number of vertices should be a multiple of four - extra vertices will be ignored.  For GL_QUAD_STRIP, the number of vertices should be even and at least four.  Extra vertices (one) will be ignored.

Convex polygons are rendered by the command sequence glBegin(GL_POLYGON),glVertex, glVertex, ... glEnd.  If less than three vertices are specified, nothing is drawn.

4.3.1 Polygon Orientation

The winding order of vertices (clockwise or counter-clockwise) is significant.  It is used to determine the front-facing or back-facing orientation of polygons.  By default, a front-facing polygon's vertices are in counter-clockwise order (in window coordinates).  Figures 2.4 and 2.5 of the OpenGL 1.2.1 specification illustrate the winding order for front-facing triangles and quadrilaterals, respectively.

The command

void glFrontFace(GLenum mode)

specifies whether clockwise or counter-clockwise winding indicates a front-facing polygon.  If mode is GL_CW then polygons with clockwise winding are front-facing.  If mode is GL_CCW then polygons with counter-clockwise winding are front-facing.  The default value is GL_CCW.  If mode is not GL_CCW or GL_CW then the error GL_INVALID_ENUM will be raised.

4.3.2 Polygon Culling

Polygons may be culled (discarded) depending on whether they are front-facing or back-facing.  The command

void glCullFace(GLenum mode)

specifies whether front-facing, back-facing or all polygons should be culled.  If mode is GL_FRONT then front-facing polygons will be culled.  If mode is GL_BACK then back-facing polygons will be culled. Otherwise, if mode is GL_FRONT_AND_BACK then all polygons will be culled.  Any other value for mode will raise the error GL_INVALID_ENUM.

Polygon culling is enabled and disabled with the commands glEnable(GL_CULL_FACE) and glDisable(GL_CULL_FACE), respectively.

4.3.3 Polygon Antialiasing

Polygons may be antialiased in order to smooth their edges.  Polygon antialiasing is enabled and disabled with the commands glEnable(GL_POLYGON_SMOOTH) and glDisable(GL_POLYGON_SMOOTH).

When polygon antialiasing is enabled each fragment produced by polygon, triangle and quadrilateral rasterization will be given a coverage value which indicates how much of the fragment is covered by the polygon.  Fragments completely inside the polygon have coverage 1.0.  Fragments completely outside the polygon have zero coverage (in theory).  Fragments which intersect the polygon's edge have a coverage value in the range (0, 1).

The fragment's alpha value is multiplied by the coverage value.  By enabling the appropriate blending mode, polygon edges will appear smoothed.

4.4 Shading

The command

void glShadeModel(GLenummode)

determines whether colors are interpolated between vertices during rasterization.  If mode is GL_FLAT then vertex colors are not interpolated.  The color used for drawing lines, triangles and quadrilaterals is that of the last vertex used to specify each primitive.  For polygons, the color of the first vertex specifies the color for the entire polygon.  If mode is GL_SMOOTH then vertex colors are linearly interpolated to produce the fragment colors.

4.5 Bitmap Rasterization

A bitmap is a monochromatic, binary image in which each image element (or pixel) is represented by one bit.  Fragments are only generated for the bits (pixels) which are set.  Bitmaps are commonly used to draw text (glyphs) and markers.

A bitmap is drawn with the command

void glBitmap(GLsizeiwidth, GLsizei height, GLfloat xOrig, GLfloat yOrig, GLfloat xMove, GLfloat yMove, const  GLubyte *image)

width and height specify the image size in pixels.  xOrig and yOrig specify the bitmap origin.  xMove and yMove are added to the current raster position after the bitmap is rasterized.  image is a pointer to the bitmap data.

If the current raster position is not valid, glBitmap has no effect.

4.5.1 Bitmap Unpacking

The first step in bitmap rendering is unpacking.  Unpacking is the process of extracting image data from client memory subject to byte swapping, non-default row strides, etc.  The unpacking parameters are specified with the command

void glPixelStorei(GLenum pname, GLint value)

The following unpacking parameters may be set:

Parameter (pname)
Value (value)
Default
GL_UNPACK_ROW_LENGTH
Width of the image in memory, in pixels.
0
GL_UNPACK_LSB_FIRST
GL_FALSE indicates that the most significant bit is unpacked first from each byte.  GL_TRUE indicates that the least significant bit is unpacked first from each byte.
GL_FALSE


The GL_UNPACK_ROW_LENGTH specifies the stride (in pixels) for advancing from one row of the image to the next.  If it's zero, the width parameter to glBitmap specifies the width of the image in memory.

GL_UNPACK_LSB_FIRST determines whether the least significant or most significant bit in each byte is unpacked first.  Unpacking occurs in left to right order (in image space).

The value of bit (i, j) of the image (where i is the image row and j is the image column) is found as follows:

rowLength = (GL_UNPACK_ROW_LENGTH != 0) ? GL_UNPACK_ROW_LENGTH : width;

byte = image[((rowLength + 7) / 8) * i + j / 8];

if (GL_UNPACK_LSB_FIRST != 0)
    bitMask = 1 << (j % 8);
else
    bitMask = 128 >> (j % 8);

if (byte & bitMask)
    bit = 1;
else
    bit = 0;

4.5.2 Rasterization

If the current raster position is (xrp, yrp, zrp, wrp), then the bitmap is rasterized according to the following algorithm:

for (j = 0; j < height; j++) {
    for (i = 0; i < width; i++) {
        if (bit(i,j)) {
            fragment.x = floor(xrp - xOrig) + i;
            fragment.y = floor(yrp - yOrig) + j;
            fragment.color = GL_CURRENT_RASTER_COLOR;
            fragment.texture = GL_CURRENT_RASTER_TEXTURE_COORDS;
            ProcessFragment(fragment)
         }
    }
}

After the bitmap has been rendered the current raster position is updated as follows:

xrp = xrp + xMove
yrp = yrp + yMove

4.5.3 Per-fragment Operations

XXX supported?  See issue in appendix A.

4.6 Unsupported Commands

The following commands related to rasterization are not supported by the subset.

Point commands:
glPointSize

Polygon commands:
glPolygonStipple
glPolygonOffset
glPolygonMode

Pixel storage commands:
glPixelStoref


5. Texture Mapping

There are four elements to texture mapping: texture coordinate specification, texture image specification, texture sampling and texture application.

Texture mapping is enabled and disabled with the commands glEnable(GL_TEXTURE_2D) and glDisable(GL_TEXTURE_2D).

5.1 Texture Image Specification

A texture image is specified with the command:

void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )

target must be GL_TEXTURE_2D.  level indicates the mipmap level for mipmap textures.  internalFormat is a hint to indicate the preferred internal storage format for the texture.  width and height indicate the image size in pixels (or texels).  border must be zero.  format and type describe the pixel format and data type for the incoming image.  pixels points to the incoming texture image.  These parameters are described in more detail below.

5.1.1 Texture Image Size and Mipmaps

Texture images must have dimensions (width and height) that are powers of two. For example: 256 x 256, 32 x 1024, 1 x 8, etc.  That is, it must be the case that width = 2n and height = 2m for some positive integers n and m.

Mipmapping is a method of antialiasing or filtering textures to improve their appearance.  A mipmap is a set of images consisting of a base image and a set of filtered, reduced-resolution images.  If the base image (level=0) is of width 2n and height 2m then the level 1 image must be of width 2n-1 and height 2m-1.  Each mipmap level is half the width and height of the previous level, or at least one.  The last mipmap level has a width and height of one.

The following is an example of a mipmap's image levels:

mipmap level
width
height
0
256
64
1
128
32
2
64
16
3
32
8
4
16
4
5
8
2
6
4
1
7
2
1
8
1
1

If the width or height parameters are not powers of two, the error GL_INVALID_VALUE is raised.  If the image levels in a mipmap do not satisfy the restrictions listed above the texture is considered to be inconsistent and the system will behave as if the texturing is disabled.

5.1.2 Texture Image Formats and Unpacking

The glTexImage2D command's format and type parameters describe the format of the incoming texture image.  Accepted values for format are GL_INTENSITY, GL_RGB and GL_RGBA.  The type parameter must be GL_UNSIGNED_BYTE.  Pixel component values are thus in the range 0 through 255.

If format is GL_INTENSITY then the image has one byte per pixel which specifies the pixel's red, green, blue and alpha values.

If format is GL_RGB then the image has three bytes per pixel which specify the pixel's red, green and blue values (in that order).  The alpha value defaults to 255.

If format is GL_RGBA then the image has four bytes per pixel which specify the pixel's red, green, blue and alpha values (in that order).

The command

void glPixelStorei(GLenum pname, GLint value)

controls the unpacking of texture image data from client memory.  pname may be GL_UNPACK_ROW_LENGTH to indicate the stride, in pixels, between subsequent rows of the image in client memory.  If GL_UNPACK_ROW_LENGTH is zero (the default) then the width parameter to glTexImage2D determines the stride.

5.1.3 Internal Texture Format

glTexImage2D converts the incoming texture image to one of the supported internal texture formats.

The internalFormat parameter indicates the desired internal format for the texture and may be either GL_INTENSITY8, GL_RGB5 or GL_RGBA8.

If internalFormat is GL_INTENSITY8 then the texture has one byte per texel (texture element) which indicates the texel's intensity (or brightness).  The intensity is obtained from the incoming image's red channel.

If internalFormat is GL_RGB5 then the texture is stored with two bytes per texel:  5 bits per red value, 5 bits per green value and 5 bits per blue value.

If internalFormat is GL_RGBA8 then the texture is stored with four bytes per texel:  8 bits for each of the red, green,  blue and alpha values.

The internal format is also significant to texture application (see section 5.4).

5.2 Texture Coordinates

Texture coordinates control the mapping from local polygon space to texture image space.  Texture coordinates are set for each vertex with the glTexCoord commands.  During line and polygon rasterization the vertex's texture coordinates are interpolated across the primitive to produce a texture coordinate for each fragment.  The fragment texture coordinates are used to sample the current texture image.

Texture coordinates are normally in the range [0, 1].  Values outside that range are processed according to the texture wrap mode.  The texture wrap mode is set with the command

void glTexParameteri(GLenum target, GLenum pname, GLint value)

target must be GL_TEXTURE_2D.  If pname is GL_TEXTURE_WRAP_S or GL_TEXTURE_WRAP_T then value must be either GL_CLAMP_TO_EDGE or GL_REPEAT.

For GL_CLAMP_TO_EDGE, texture coordinates are effectively clamped to the interval [0, 1].

For GL_REPEAT, the integer part of texture coordinates is ignored; only the fractional part of the texture coordinates is used.  This allows texture images to repeated or tiled across an object.

5.3 Texture Sampling

Texture sampling is the process of using texture coordinates to extract a color from the texture image.  Multiple, weighted samples may be taken from the texture and combined during the filtering step.

During texture coordinate interpolation a level of detail value (lambda) is computed for each fragment.  For a mipmapped texture, lambda determines which level (or levels) of the mipmap will be sampled to obtain the texture color.

If lambda indicates that multiple texels map to a single screen pixel, then the texture minification filter will be used.  Otherwise, if lambda indicates that a single texel maps to multiple screen pixels, then the texture magnification filter will be used.

5.3.1 Texture Minification

The texture minification filter is set with the glTexParameteri command by setting target to GL_TEXTURE_2D, setting pname to GL_TEXTURE_MIN_FILTER and setting value to GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,  GL_NEAREST_MIPMAP_LINEAR,   GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR.

GL_NEAREST samples the texel nearest the texture coordinate in the level 0 texture image.

GL_LINEAR samples the four texels around the texture coordinate in the level 0 texture image.  The four texels are linearly weighted to compute the final texel value.

GL_NEAREST_MIPMAP_NEAREST samples the texel nearest the texture coordinate in the level N texture image.  N is the level of detail and is computed by the partial derivatives of the texture coordinates with respect to the window coordinates.

GL_NEAREST_MIPMAP_LINEAR samples two texels nearest the texture coordinates in the level N and N+1 texture images.  The two texels are linearly weighted to compute the final texel value.  N is the level of detail and is computed by the partial derivatives of the texture coordinates with respect to the window coordinates.

GL_LINEAR_MIPMAP_NEAREST samples four texels around the texture coordinate in the level N texture image.  The four texels are linearly weighted to compute the final texel value.  N is the level of detail and is computed by the partial derivatives of the texture coordinates with respect to the window coordinates.

GL_LINEAR_MIPMAP_LINEAR samples four texels around the texture coordinate in the level N texture image and four texels around the texture coordinate in the level N+1 texture image.  The eight texels are linearly weighted to compute the final texel value.  N is the level of detail and is computed by the partial derivatives of the texture coordinates with respect to the window coordinates.

Filter modes other than GL_LINEAR and GL_NEAREST requires that the texture have a complete set of mipmaps.  If the mipmap is incomplete, it is as if texturing is disabled.
 

5.3.2 Texture Magnification

The texture magnification filter is set with the glTexParameteri command by setting target to GL_TEXTURE_2D, setting pname to GL_TEXTURE_MAG_FILTER and setting value to GL_NEAREST or GL_LINEAR.

GL_NEAREST samples the texel nearest the texture coordinate in the level 0 texture image.

GL_LINEAR samples the four texels around the texture coordinate in the level 0 texture image.  The four texels are linearly weighted to compute the final texel value.

5.4 Texture Application

The sampled texture value is combined with the incoming fragment color to produce a new fragment color.  The fragment and texture colors are combined according to the texture environment mode and the current texture's base internal format.  The texture environment mode is set with the command

void glTexEnvi(GLenum target, GLenum pname, GLint value)

target must be GL_TEXTURE_ENV.  If pname is GL_TEXTURE_ENV_MODE then value must be one of GL_REPLACE, GL_MODULATE, GL_DECAL, or GL_BLEND.

There is also a texture environment color that can factor into texture application.  The texture environment color can be set with the command

void glTexEnvfv(GLenum target, GLenum pname, const GLfloat *value)

target must be GL_TEXTURE_ENV.  If pname is GL_TEXTURE_ENV_COLOR then value must point to an array of four values which specify the red, green, blue, and alpha values of the texture environment color.  The values are clamped to the range [0, 1].  The default color is (0, 0, 0, 0).

The following table describes the arithmetic used for each combination of environment mode and base internal format.  (Rf, Gf, Bf, Af) is the incoming fragment color.  (Rt, Gt, Bt, At) is the sampled texture color.  Lt is the sampled texture luminance.  'It' is the sampled texture intensity.  (Rc, Gc, Bc, Ac) is the texture environment color.  (Rv, Gv, Bv, Av) is the resulting value.


Base Internal Format
GL_REPLACE
GL_MODULATE
GL_DECAL
GL_BLEND
GL_INTENSITY
Rv = It
Gv = It
Bv = It
Bf = It
Rv = Rf * It
Gv = Gf * It
Bv = Bf * It
Av = Af * It
undefined
Rv = Rf*(1-It) + Rc*It
Gv = Gf*(1-It) + Gc*It
Bv = Bf*(1-It) + Bc*It
Av = Af*(1-It) + Ac*It
GL_RGB
Rv = Rt
Gv = Gt
Bv = Bt
Av = Af
Rv = Rf * Rt
Gv = Gf * Gt
Bv = Bf * Bt
Av = Af
Rv = Rt
Gv = Gt
Bv = Bt
Av = Af
Rv = Rf*(1-Rt) + Rc*Rt
Gv = Gf*(1-Gt) + Gc*Gt
Bv = Bf*(1-Bt) + Bc*Bt
Av = Af
GL_RGBA
Rv = Rt
Gv = Gt
Bv = Bt
Av = At
Rv = Rf * Rt
Gv = Gf * Gt
Bv = Bf * Bt
Av = Af * At
Rv = Rf*(1-At) + Rt*At
Gv = Gf*(1-At) + Gt*At
Bv = Bf*(1-At) + Bt*At
Av = Af
Rv = Rf*(1-Rt) + Rc*Rt
Gv = Gf*(1-Gt) + Gc*Gt
Bv = Bf*(1-Bt) + Bc*Bt
Av = Af*At



5.5 Texture Objects

Texture objects encapsulate a set of texture images (mipmap) and related state into a named object.  This facilitates use of multiple textures in an application.  Texture objects are named with GLuints (unsigned integers).  There is a default texture object with the name/identifier zero which can never be deleted.

5.5.1 Creating Texture Objects

A texture object is created by binding a new GLuint identifier to the GL_TEXTURE_2D target with the command:

void glBindTexture(GLenum target, GLuint textureID)

target must be GL_TEXTURE_2D.  textureID may be any unsigned integer.  If textureID does not name an existing texture object, a new texture object with that ID will be created, initialized to the default state.  Whether the ID is new or existed previously, that named texture object is bound as the current texture object.  Subsequent glTexParameter andglTexImage2D calls will effect the current texture object.

5.5.2 Deleting Texture Objects

One or more texture objects may be deleted with the command:

void glDeleteTextures(GLsizein, const GLuint *textureIDs)

textureIDs is an array of n texture IDs.  The named texture objects will be deleted.  If the current texture object is deleted the default texture object (number 0) will be bound as the current texture object.

5.5.3 Allocating Texture Object Identifiers

A list of new, unused texture IDs can be obtained by calling the command

void glGenTextures(GLsizei n, GLuint *textureIDs)

An array of n unused texture IDs will be returned in the textureIDs array.


6. Per-fragment Operations

The fragments produced by rasterization are subjected to a number of operations which either modify the fragment or test the fragment (discarding the fragment if the test fails.)  This chapter describes the per-fragment operations.  They are presented in the order in which they're performed.  If a fragment fails a test it is discarded and not subjected to subsequent tests or modifications.

6.1 Scissor Test

The scissor test limits rendering to a 2-D rectangular region of the framebuffer.  The command

void glScissor(GLintx, GLint y, GLsizei width, GLsizei height)

defines a clipping region with the lower-left corner at (x, y) and the given width and height.  The scissor test is enabled and disabled with the command glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).

If the incoming fragment's position is (xf, yf) then the fragment will pass the test if x <= xf < x + width and y <= yf < y + height.  Otherwise, the fragment is discarded.

If width or height is less than zero the error GL_INVALID_VALUE is raised.  The default scissor rectangle bounds are (0, 0, w, h) where w is the initial window width and h is the initial window height.  The scissor test is disabled by default.

6.2 Alpha Test

The alpha test compares the fragment's alpha value against a reference value and discards the fragment if the comparison fails.  The test is specified by the command

void glAlphaFunc(GLenummode, GLclampf reference)

mode specifies an inequality and reference specifies a value to compare against.  The following table lists all possible modes and the corresponding test:

Comparison mode
The test passes if
GL_LESS
alpha < reference
GL_LEQUAL
alpha <= reference
GL_GREATER
alpha > reference
GL_GEQUAL
alpha >= reference
GL_EQUAL
alpha == reference
GL_NOTEQUAL
alpha != reference
GL_NEVER
never pass
GL_ALWAYS
always passes

The reference parameter is clamped to the range [0, 1].

The alpha test is enabled and disabled with the commands glEnable(GL_ALPHA_TEST) and glDisable(GL_ALPHA_TEST).

The default mode is GL_ALWAYS and the default reference value is 0.

6.3 Stencil Test

The stencil buffer stores an N-bit integer value for each pixel in the frame buffer.  The stencil test compares the stencil buffer value at the fragment's position to a reference value and possibly discards the fragment based on the outcome.  Furthermore, the stencil buffer value may be updated or modified depending on the outcome.  If there is no stencil buffer the stencil test is bypassed.

Stenciling is controlled by the commands

void glStencilFunc(GLenumfunc, GLint ref, GLuint mask)
void glStencilOp(GLenum stencilFail, GLenum depthTestFail, GLenum depthTestPass)

The glStencilFunc command controls the stencil test while glStencilOp command controls the how the stencil buffer is updated/modified after the test.

ref is clamped to the range [0, 2N-1] where N is the number of bits per stencil value in the stencil buffer.

The following table lists all possible values for the func parameter and when the stencil test will pass.  Both the stencil buffer value and the stencil reference value are bit-wise ANDed with the mask parameter before the test.

Stencil func value
Stencil test passes if
GL_LESS
(ref&mask) < (stencil buffer value & mask)
GL_LEQUAL
(ref & mask) <= (stencil buffer value & mask)
GL_GREATER
(ref & mask) > (stencil buffer value & mask)
GL_GEQUAL
(ref & mask) >= (stencil buffer value & mask)
GL_EQUAL
(ref & mask) == (stencil buffer value & mask)
GL_NOTEQUAL
(ref & mask) != (stencil buffer value & mask)
GL_NEVER
never passes
GL_ALWAYS
always passes


If the stencil test passes, the fragment is passed to the next per-fragment operation.  Otherwise, if the stencil test fails, the value in the stencil buffer is updated according to the value of the stencilFail parameter to glStencilOp.

stencilFail value
New stencil buffer value
GL_KEEP
originalValue
GL_ZERO
0
GL_INVERT
BitWiseInvert(originalValue) i.e. ~originalValue
GL_REPLACE
ref
GL_INCR
originalValue + 1, clamped to [0, 2N-1]
GL_DECR
originalValue - 1, clamped to [0, 2N-1]


The depthTestFail and depthTestPass parameters to glStencilOp are ignored.  Values for func and stencilFail other than those listed in the table will cause the error GL_INVALID_ENUM to be raised.

The stencil test is enabled and disabled with the commands glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).

The default stencil function is GL_ALWAYS.  The default stencil reference value is 0.  The default stencil mask is ~0.  The default stencil fail operation is GL_KEEP.

Values written into the stencil buffer are masked with the command

void glStencilMask(GLuintmask)

Only the bits which are set in mask will be modified in the stencil buffer when written to.  If each stencil buffer value has N bits, only the least significant N bits of mask are relevant.  The default stencil mask is ~0.

6.4 Blending and Logicop

Blending or a logic operation combines the incoming fragment color with the destination frame buffer color according to a blending equation or bit-wise Boolean logical operation.

Blending is enabled and disabled with the commands glEnable(GL_BLEND) and glDisable(GL_BLEND).

The logic operation is enabled and disabled with the commands glEnable(GL_LOGIC_OP) and glDisable(GL_LOGIC_OP).

If both blending and the logic operation are enabled, the logic operation has higher priority; blending is bypassed.

6.4.1 Logic Op

The command

void glLogicop(GLenummode)

Specifies the Boolean logic operation for combining the incoming fragment color with the destination frame buffer color.  Both the incoming fragment color and destination frame buffer colors are interpreted as four-tuples of unsigned integer color components in the range [0, 2N-1] where N is the number of bits per color channel.  N may not be the same for all color channels.

The following table lists all values for mode and the boolean arithmetic used to combine the incoming fragment color value (src) with the destination framebuffer color value (dst).  Standard ANSI C operators used.

LogicOp mode
Resulting channel value
GL_CLEAR
0
GL_SET
~0
GL_COPY
src
GL_COPY_INVERTED
~s
GL_NOOP
dst
GL_INVERT
~dst
GL_AND
src & dst
GL_NAND
~(src & dst)
GL_AND_REVERSE
src & ~dst
GL_AND_INVERTED
~src & dst
GL_OR
src | dst
GL_NOR
~(src | dst)
GL_OR_REVERSE
src | ~dst
GL_OR_INVERTED
~src | dst
GL_XOR
src ^ dst
GL_EQUIV
~(src ^ dst)

The fragment's color is replaced by the result of the logic operation.

Specifying any value for mode other than those listed in the above table will cause the error GL_INVALID_ENUM to be raised.

The default value for mode is GL_COPY.  The logic operation is disabled by default.

6.4.2 Blending

The command

void glBlendFunc(GLenumsrcTerm, GLenum dstTerm)

specifies the terms of the blending equation.  If Cf = (Rf, Gf, Bf, Af) is the incoming fragment color and Cb = (Rb, Gb, Bb, Ab) is the frame buffer color, then the resulting color Cv = (Rv, Gv, Bv, Av) is computed by:

Cv = Cf * srcTerm + Cb * dstTerm

All possible values for srcTerm and the corresponding arithmetic term are listed in the following table:

srcTerm
srcTermArithmetic
GL_ZERO
(0, 0, 0, 0)
GL_ONE
(1, 1, 1, 1)
GL_DST_COLOR
(Rb, Gb, Bb, Ab)
GL_ONE_MINUS_DST_COLOR
(1-Rb, 1-Gb, 1-Bb, 1-Ab)
GL_SRC_ALPHA
(Af, Af, Af, AF)
GL_ONE_MINUS_SRC_ALPHA
(1-Af, 1-Af, 1-Af, 1-Af)
GL_DST_ALPHA
(Ab, Ab, Ab, Ab)
GL_ONE_MINUS_DST_ALPHA
(1-Ab, 1-Ab, 1-Ab, 1-Ab)
GL_SRC_ALPHA_SATURATE
(m, m, m, 1) where m = MIN(Af, 1-Ab)

All possible values for srcTerm and the corresponding arithmetic term are listed in the following table:

dstTerm
dstTermArithmetic
GL_ZERO
(0, 0, 0, 0)
GL_ONE
(1, 1, 1, 1)
GL_SRC_COLOR
(Rf, Gf, Bf, Af)
GL_ONE_MINUS_SRC_COLOR
(1-Rf, 1-Gf, 1-Bf, 1-Af)
GL_SRC_ALPHA
(Af, Af, Af, AF)
GL_ONE_MINUS_SRC_ALPHA
(1-Af, 1-Af, 1-Af, 1-Af)
GL_DST_ALPHA
(Ab, Ab, Ab, Ab)
GL_ONE_MINUS_DST_ALPHA
(1-Ab, 1-Ab, 1-Ab, 1-Ab)

The fragment's color is replaced by the result of the blending equation.

Values for srcTerm and dstTerm other than those listed in the table will cause the error GL_INVALID_ENUM to be raised.

The default value for srcTerm is GL_ONE.  The default value for dstTerm is GL_ZERO.  Blending is disabled by default.

6.5 Color Mask

The final fragment color is written into the current color buffer at the end of the per-fragment operations.  Normally, all color channels in the frame buffer are replaced with the final fragment color.  However, the command

void glColorMask(GLbooleanredMask, GLboolean greenMask, GLboolean blueMask, GLboolean alphaMask)

allows selective writing to individual color channels.  If redMask is GL_TRUE then writing to the red color channel is enabled, otherwise it's disabled.  Similarly, the green, blue and alpha channels can also be masked.

Initially all four mask values are GL_TRUE.

Color masking is not enabled/disabled with the glEnable/glDisable commands.

7. Frame Buffer Operations

The frame buffer is considered to be a two-dimensional array of pixels.  The frame buffer is also organized into layers or logical buffers.  There may be a front color buffer, back color buffer and stencil buffer.  A double-buffered frame buffer has both a front color buffer and back color buffer.  A single-buffered framebuffer only has a front color buffer.  Each pixel in a color buffer has a red, green and blue value and an optional alpha value.

7.1 Clearing Buffers

Buffers are cleared (set to uniform values) with the command

void glClear(GLbitfieldbuffers)

buffers is a bitmask for which the value may be the bitwise-OR of the values GL_COLOR_BUFFER_BIT and GL_STENCIL_BUFFER_BIT.  If the GL_COLOR_BUFFER_BIT bit is specified, the current color buffer will be cleared.  If the GL_STENCIL_BUFFER_BIT bit is specified, the stencil buffer will be cleared.

The current color buffer is specified with the command

void glDrawBuffer(GLenum buffer)

buffer may be either GL_FRONT, GL_BACK or GL_NONE.  GL_FRONT indicates that the front color buffer will be modified by glClear and any drawing command.  GL_BACK indicates that the back color buffer will be modified by glClear and any drawing command.  GL_NONE indicates that neither color buffer will be modified by glClear or any drawing command.  GL_BACK is only valid for double-buffered frame buffers.

The current scissor rectangle, set by the glScissor command, effects glClear, limiting the clear to the scissor rectangle, if it's enabled.  Furthermore, only the color channels enabled by glColorMask will be effected by glClear(GL_COLOR_BUFFER_BIT).  Likewise, only the stencil bits enabled by glStencilMask will be effected by glClear(GL_STENCIL_BUFFER_BIT).

The current clear color is set with the command

void glClearColor(GLclampfred, GLclampf green, GLclampf blue, GLclampf alpha)

Subsequent calls to glClear will use the color (red, green, blue, alpha) to clear the front or back color buffers.

The current stencil clear value is set with the command

void glClearStencil(GLintclearValue)

If the stencil buffer is N bits deep, the least significant N bits of clearValue will be used to clear the stencil buffer.


8. Other Features

8.1 Frame Buffer Readback

A rectangular region of pixels can be read from the frame buffer and placed in client memory with the command

void glReadPixels(GLintx, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *data)

x and y specify the coordinate of the lower-left corner of the region to read and width and height specify the size of the rectangular region to read.  format specifies the format of image data and must be either GL_RGB or GL_RGBA.  type specify the data type of the image data and must be either GL_UNSIGNED_BYTE or GL_FLOAT.  Other values for format or type will cause the error GL_INVALID_ENUM to be raised.

The framebuffer may contain 3-component colors (red, green, blue) or 4-component colors (red, green, blue, alpha).  If an alpha channel is not present, alpha values default to 1.0.

The frame buffer color components (red, green, blue, alpha) are either converted to 8-bit unsigned integers in the range[0, 255] if type is GL_UNSIGNED_BYTE or converted to floating point values in the range [0, 1] if type is GL_FLOAT.  The (red, green, blue, alpha) tuples are then stored as GL_RGB triplets (by dropping the alpha component) or GL_RGBA quadruples in client memory.

Image data is packed into client memory according to the pixel packing parameters which are set by the command

void glPixelStorei(GLenum pname, GLint value)

pname must be GL_PACK_ROW_LENGTH.  value indicates the stride (in pixels) between subsequent rows in the destination image.  If GL_PACK_ROW_LENGTH is zero (the default) then the width parameter to glReadPixels indicates the row stride.

Pixel readback takes place as follows:

if (GL_PACK_ROW_LENGTH == 0)
    rowLength = width;
else
    rowLength = GL_PACK_ROW_LENGTH

if (format == GL_RGB) {
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
            k = (i * rowLength + j) * 3;
            data[k+0] = FrameBuffer(x + j, y + i).red;
            data[k+1] = FrameBuffer(x + j, y + i).green;
            data[k+2] = FrameBuffer(x + j, y + i).blue;
        }
    }
}
else {
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
            k = (i * rowLength + j) * 4;
            data[k+0] = FrameBuffer(x + j, y + i).red;
            data[k+1] = FrameBuffer(x + j, y + i).green;
            data[k+2] = FrameBuffer(x + j, y + i).blue;
            data[k+3] = FrameBuffer(x + j, y + i).alpha;
        }
    }
}

The function FrameBuffer(c, r) returns the pixel in the frame buffer at column c of row r.  data is considered to be either a GLubyte pointer or a GLfloat pointer, depending on the type parameter.  Similarly, the FrameBuffer function returns either GLubyte values in the range [0, 255] or GLfloat values in the range [0,1], depending on the type parameter.

Pixels may be read from either the front or back color buffer.  The command

void glReadBuffer(GLenumbuffer)

specifies the source for reading images with glReadPixels.  If buffer is GL_FRONT then front color buffer is the source.  If buffer is GL_BACK then the back color buffer is the source.  It is illegal to specify GL_BACK when the color buffer is not double buffered.  Any invalid value for buffer will raise the error GL_INVALID_ENUM.

The default read source is GL_BACK if the frame buffer is double buffered.  Otherwise, the default read source is GL_FRONT.

8.2 Selection Mode

Selection mode is typically used to implement picking: determining which primitive(s) are present at particular window positions.  The command

GLint glRenderMode(GLenummode)

is used to enable selection mode.  If mode is GL_SELECTION the graphics library is put into selection mode.  If mode is GL_RENDER the graphic library is put into normal rendering mode.  Any other value for mode will raise the error GL_INVALID_ENUM.

When in selection mode rendering commands will not effect the framebuffer.  Instead, a record of the primitives that would have been drawn is placed in the selection buffer.  The selection buffer is specified with the command

void glSelectionBuffer(GLsizein, GLuint *buffer)

buffer
is an array of n unsigned integers.  No more than n values will be placed in the buffer.

The name stack is a stack (LIFO) of unsigned integer names.  The following commands manipulate the name stack:

void glInitNames(void)
void glPushName(GLuint name)
void glPopName(void)
void glLoadName(GLuint name)

glInitNames resets the name stack to an empty state.  glPushName pushes the given name value onto the stack.  glPopName pops the top name from the stack.  glLoadName replaces the top value on the stack with the specified name.  Stack underflow and overflow conditions cause the errors GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW to be raised.

While in selection mode, primitives (points, lines, polygons) are transformed and clip-tested normally.  Primitives which aren't discarded by clipping cause the hit data to be updated.  The hit data consists of three pieces of information: a hit flag, a minimum Z value and a maximum Z value.  First, the hit flag is set.  Then, for each of the primitive's vertices, the vertex Z value is compared to the minimum and maximum Z values.  The minimum Z value is updated if the vertex's Z value is less than the minimum Z value.  The maximum Z value is updated if the vertex's Z value is greater than the maximum Z value.

When any of glInitNames, glPushName, glPopName, glLoadName or glRenderMode are called and the hit flag is set, a hit record is written to the selection buffer.

A hit record consists of a sequence of unsigned integers.  The first value is the size of the name stack.  The second value is the minimum Z value multiplied by 232-1.  The third value is the maximum Z value multiplied by 232-1.  The remaining values are the values in the name stack, in bottom to top order.  The hit flag is cleared after a hit record is written to the selection buffer.  Hit records are places sequentially into the selection buffer until it is full or selection mode is terminated.

Selection mode is terminated by calling glRenderMode(GL_RENDER).   The return value of glRenderMode will be -1 if the selection buffer overflowed.  Otherwise, the return value will indicate the number of values written into the selection buffer.

8.3 Synchronization

The command

void glFlush(void)

makes the graphics library to flush all pending graphics commands.  The command

void glFinish(void)

makes the graphics library flush the command queue and wait until those commands are completed.  glFlush will not return until all previous graphics commands have been fully completed.

These commands are typically used to force completion of rendering to the front color buffer.  Otherwise, rendering to the front color buffer may not appear.  The swapbuffers command (part of the window system binding library) does an implicit flush before swapping the front and back color buffers.  The glReadPixels command also does an implicit flush before reading pixel data from the frame buffer.

9. State Queries

The current value of nearly all library state variables can be queried.  This chapter describes the commands used for querying the value of state variables.

9.1 General State Queries

The command

void glGetFloatv(GLenumpname, GLfloat *values)

returns the value(s) of the state variable specified by pname.  The following table lists all accepted values for pname and a description of the value(s).  Specifying any other value for pname causes the error GL_INVALID_ENUM to be raised.

Variable (pname)
Number of values
Value(s) Description
GL_ALPHA_BITS
1
Number of bits per alpha value in the frame buffer.
GL_ALPHA_TEST
1
Zero if the alpha test is disabled.
One if the alpha test is enabled.
GL_ALPHA_TEST_FUNC
1
The alpha test function.
GL_BLEND
1
Zero if blending is disabled.
One if blending is enabled.
GL_BLEND_DST
1
Blend destination function/term.
GL_BLEND_SRC
1
Blend source function/term.
GL_BLUE_BITS
1
Number of bits per blue value in the frame buffer.
GL_COLOR_CLEAR_VALUE
4
Clear color (red, green, blue, alpha).
GL_COLOR_WRITE_MASK
4
Color buffer writemask (red, green, blue, alpha).
Zero if writing is disabled.
One if writing is enabled.
GL_CULL_FACE
1
Zero if polygon culling is disabled.
One if polygon culling is enabled.
GL_CULL_FACE_MODE
1
Polygon cull mode: GL_FRONT, GL_BACK or GL_FRONT_AND_BACK.
GL_CURRENT_COLOR
4
Current color (red, green, blue, alpha).
GL_CURRENT_RASTER_COLOR
4
Current raster position color (red, green, blue, alpha).
GL_CURRENT_RASTER_TEXTURE_COORDS
4
Current raster position texture coordinates (s, t, r, q).
GL_CURRENT_RASTER_POSITION
4
Current raster position (x, y, z, w).
GL_CURRENT_POSITION_VALID
1
Zero if current raster position is invalid.
One if current raster position is valid.
GL_CURRENT_TEXTURE_COORDS
4
Current texture coordinates (s, t, r, q)
GL_DOUBLEBUFFER
1
Zero if color buffer is single-buffered.
One if color buffer is double-buffered.
GL_DRAW_BUFFER
1
Current color draw buffer: GL_FRONT or GL_BACK.
GL_FRONT_FACE 1
Polygon front-face winding: GL_CW or GL_CCW.
GL_GREEN_BITS
1
Number of bits per green value in the frame buffer.
GL_LINE_SMOOTH
1
Zero if line smoothing is disabled.
One if line smoothing is enabled.
GL_LINE_STIPPLE
1
Zero if line stippling is disabled.
One if line stippling is enabled.
GL_LINE_STIPPLE_PATTERN
1
Line stipple pattern.
GL_LINE_STIPPLE_REPEAT
1
Line stipple repeat factor.
GL_LINE_WIDTH
1
Line width in pixels.
GL_LINE_WIDTH_GRANULARITY
1
Aliased line width granularity.
GL_LINE_WIDTH_RANGE
2
Minimum and maximum aliased line widths.
GL_ALIASED_LINE_WIDTH_RANGE
2
Minimum and maximum antialiased line widths.
GL_COLOR_LOGIC_OP
1
Zero if logicop is disabled.
One if logicop is enabled.
GL_LOGIC_OP_MODE
1
Logicop function.
GL_MATRIX_MODE
1
Matrix mode: GL_MODELVIEW or GL_PROJECTION.
GL_MAX_MODELVIEW_STACK_DEPTH
1
Maximum size of the modelview matrix stack.
GL_MAX_NAME_STACK_DEPTH
1
Maximum size of the selection name stack.
GL_MAX_PROJECTION_STACK_DEPTH
1
Maximum size of the projection matrix stack.
GL_MAX_TEXTURE_SIZE
1
Maximum 2D texture image width and height.
GL_MAX_VIEWPORT_DIMS
2 Maximum viewport width and height in pixels.
GL_MODELVIEW_MATRIX
16
Current/top modelview matrix values.
GL_MODELVIEW_MATRIX_STACK_DEPTH
1
Current size of the modelview matrix stack.
GL_NAME_STACK_DEPTH
1
Current size of the selection name stack.
GL_PACK_ROW_LENGTH
1
Pixel packing row length.
GL_POLYGON_SMOOTH
1
Zero if polygon smoothing is disabled.
One if polygon smoothing is enabled.
GL_PROJECTION_MATRIX
16
Current/top projection matrix values.
GL_PROJECTION_STACK_DEPTH
1
Current size of projection matrix stack.
GL_READ_BUFFER
1
Current read buffer: GL_FRONT or GL_BACK.
GL_RED_BITS
1
Number of bits per red value in the frame buffer.
GL_RENDER_MODE
1
Current rendering mode: GL_RENDER or GL_SELECTION.
GL_RGBA_MODE
1
Always one.
GL_SCISSOR_BOX
4
Scissor box (x, y, width, height).
GL_SCISSOR_TEST
1
Zero if scissor test is disabled.
One if scissor test is enabled.
GL_SELECTION_BUFFER_SIZE
1
Size of selection buffer.
GL_SHADE_MODEL
1
Shade model: GL_FLAT or GL_SMOOTH.
GL_STENCIL_BITS
1
Number of bits per stencil value in the frame buffer.
GL_STENCIL_CLEAR_VALUE
1
Stencil buffer clear value.
GL_STENCIL_FAIL
1
Stencil fail operation.
GL_STENCIL_FUNC
1
Stencil function.
GL_STENCIL_REF
1
Stencil reference value.
GL_STENCIL_TEST
1
Zero if stencil test is disabled.
One if stencil test is enabled.
GL_STENCIL_VALUE_MASK
1
Stencil mask value.
GL_STENCIL_WRITE_MASK
1
Stencil buffer write mask.
GL_TEXTURE_2D
1
Zero if 2D texture mapping is disabled.
One if 2D texture mapping is enabled.
GL_TEXTURE_BINDING_2D 1
Name of currently bound 2D texture object.
GL_TEXTURE_ENV_COLOR
4
Texture environment color (red, green, blue, alpha).
GL_TEXTURE_ENV_MODE
1
Texture environment mode.
GL_UNPACK_ROW_LENGTH
1
Pixel unpacking row length.
GL_UNPACK_LSB_FIRST
1
Zero if most significant bit is unpacked first for bitmaps.
One if least significant bit is unpacked first for bitmaps.
GL_VIEWPORT
4
Current viewport (x, y, width, height).


9.2 String Queries

The command

const GLubyte *glGetString(GLenum name)

is used to query string-valued values.  The legal values for name are described in the following table:

name
Return value
GL_VERSION
The library version, such as "1.2".
GL_RENDERER
The renderer, such as "Mesa DRI Radeon".
GL_VENDOR
The vendor of this implementation, such as "Tungsten Graphics, Inc."
GL_EXTENSIONS
A white-space separated list of the supported extensions.

9.3 Error Queries

The command

GLenum glGetError(void)

returns the current error code.  The current error code will be set by a GL command when an error condition has been detected.  If the current error code is already set, subsequent errors will not be recorded.  The error code is reset/cleared to GL_NO_ERROR when glGetError returns.  The following error codes are possible:

Error code
Meaning
GL_NO_ERROR
No error has been recorded.
GL_INVALID_ENUM
An enum parameter had an invalid value.
GL_INVALID_VALUE
A numeric parameter had an invalid value.
GL_INVALID_OPERATION
A function was called when not legal to do so.
GL_STACK_OVERFLOW
The current transformation matrix stack is full.
GL_STACK_UNDERFLOW
The current transformation matrix stack is empty.
GL_OUT_OF_MEMORY
The system ran out of dynamic memory.


10. Unsupported Features

This section lists other features and functions which are not supported and not previously discussed.

10.1 Feedback Mode

Feedback mode and the following related functions are not supported.

glFeedbackBuffer
glPassThrough

10.2 1D and 3D Textures

Only 2D texture images are supported.  The following functions used to specify 1D and 3D texture images are not supported:

glTexImage1D
glTexImage3D
glTexSubImage1D
glTexSubImage3D
glCopyTexImage1D
glCopyTexSubImage1D
glCopyTexSubImage3D

10.3 Alternate Texture Image Commands

Texture images may only be specified with glTexImage2D.  The following alternate texture image commands are not supported:

glTexSubImage2D
glCopyTexImage2D
glCopyTexSubImage2D

10.4 Proxy Textures

Proxy textures are not supported and the GL_PROXY_TEXTURE_2D token is not supported by any function.


10.5 Other Texture Commands

The following commands related to texture mapping are not supported by the subset:

glPrioritizeTextures
glAreTexturesResident
glIsTexture
glTexEnviv
glTexEnvf
glTexParameterf
glTexParameteriv
glTexParameterfv


10.6 Copy and Draw Pixels

The following commands are not supported:

glDrawPixels
glCopyPixels
glPixelZoom

10.7 Color Index Mode

Color index mode and the following related commands are not supported:

glIndexub
glIndexi
glIndexs
glIndexf
glIndexd
glIndexubv
glIndexiv
glIndexsv
glIndexfv
glIndexdv

glIndexMask
glClearIndex
glIndexPointer


10.8 Pixel Transfer Operations

The pixel transfer operations (scale, bias, look-up table, etc) are not supported and the following commands are omitted:

glPixelTransferf
glPixelTransferi
glPixelMapfv
glPixelMapuiv
glPixelMapusv
glGetPixelMapfv
glGetPixelMapuiv
glGetPixelMapusv

10.9 Hints

Hints and the following related command is not supported:

glHint

10.10 State Query Commands

The following state query commands are not supported:

glGetBooleanv
glGetIntegerv
glGetDoublev
glGetPointerv
glGetTexEnvi
glGetTexEnvf
glGetTexParameteriv
glGetTexParameterfv
glGetTexLevelParameteriv
glGetTexLevelParameterfv
glGetTexImage
glGetClipPlane

10.11 Attribute Stacks

State attribute stacks and the following related commands are not supported:

glPushAttrib
glPopAtttrib

10.12 Double-Valued Functions

All functions which take double-precision floating point values, but for which there is an equivalent single-precision valued function, are omitted.  This includes, but is not limited to:

glVertex2d
glVertex2dv
glVertex3d
glVertex3dv
glVertex4d
glVertex4dv
glColor3d
glColor3dv
glColor4d
glColor4dv
glTexCoord1d
glTexCoord1dv
glTexCoord2d
glTexCoord2dv
glTexCoord3d
glTexCoord3dv
glTexCoord4d
glTexCoord4dv
glRasterPos2d
glRasterPos2dv
glRasterPos3d
glRasterPos3dv
glRasterPos4d
glRasterPos4dv
glLoadMatrixd
glMultMatrixd
glScaled
glRotated
glTranslated
glRectd
glRectdv

10.13 Evaluators

Evaluators and the following related commands are not supported:

glMap1f
glMap2d
glMap2f
glGetMapdv
glGetMapfv
glGetMapiv
glEvalCoord1d
glEvalCoord1f
glEvalCoord1dv
glEvalCoord1fv
glEvalCoord2d
glEvalCoord2f
glEvalCoord2dv
glEvalCoord2fv
glMapGrid1d
glMapGrid1f
glMapGrid2d
glMapGrid2f
glEvalPoint1
glEvalPoint2
glEvalMesh1
glEvalMesh2

10.14 Display Lists

Display lists and the following related commands are not supported:

glIsList
glDeleteLists
glGenLists
glNewList
glEndList
glCallList
glCallLists
glListBase

10.15 Accumulation Buffer

The accumulation buffer and the following related commands are not supported:

glAccum
glClearAccum

10.16 Fog

Fog and the following related commands are not supported:

glFogi
glFogf
glFogiv
glFogfv

10.17 Depth Test

Depth testing and the following related commands are not supported:

glDepthFunc
glDepthMask
glDepthRange
glClearDepth

10.18 Imaging Subset

The OpenGL imaging subset (which implements features such as convolution, histogram, min/max recording, color matrix and color tables) is not supported.


Appendix A: Issues

This appendix lists documentation and subset issues with their current status.  For items which are still open, the documentation (above) follows the recommended solution.

A.1 Vertex Arrays

Should vertex arrays be supported?  Is there a performance advantage?

RESOLUTION: No, there isn't enough of a performance advantage to justify them.

A.2 Polygon Antialiasing and Edge Flags

Should edge flags be supported for antialiasing?

Edge flags don't effect antialiasing, at least not normally.  A number of approaches to antialiasing have been summarized in email.

RECOMMENDATION: don't support edge flags.  They don't effect polygon antialiasing.

RESOLUTION: closed, as of 26 Feb 2003.

A.3 glRasterPos vs. glWindowPos

Should glRasterPos and/or glWindowPos commands be supported?

RESOLUTION: Closed: implement glRasterPos commands, but not glWindowPos commands.

A.4 GL_IBM_rasterpos_clip extension

Should the GL_IBM_rasterpos_clip extension be implemented?

RESOLUTION:  No.  It's not required.

A.5 Image Formats and Types

Which image formats and types should be supported for glTexImage2D and glReadPixels?

OpenGL specifies a large variety of image formats and data types.  Only a few are commonly used.

RECOMMENDATION:  we propose a subset:

For glTexImage2D only allow type=GL_UNSIGNED_BYTE and format=GL_RGBA, GL_RGB, GL_INTENSITY.   Only allow internalFormat to be GL_RGBA, GL_RGB or GL_INTENSITY as well.  Basically, only support image formats/types that are directly supported by the Radeon hardware.  This will allow glTexImage2D to basically just use memcpy to copy texture images.

For glReadPixels, only allow type = GL_UNSIGNED_BYTE or GL_FLOAT.  Only allow format = GL_RGB or GL_RGBA.  This is just enough to support the OpenGL conformance tests.

RESOLUTION: open

A.6 Texture Environment Modes

Which texture environment modes should be supported?  OpenGL 1.2 has GL_REPLACE, GL_MODULATE, GL_DECAL and GL_BLEND.  GL_DECAL isn't defined for all base internal texture formats.  GL_ADD is another useful mode.  Perhaps drop GL_DECAL mode and add GL_ADD mode.

RECOMMENDATION: implement the standard modes GL_REPLACE, GL_MODULATE, GL_DECAL and GL_BLEND.

RESOLUTION: open

A.7 Truncated Mipmaps and LOD Control

Should we support the GL_TEXTURE_BASE_LEVEL, GL_TEXTURE_MAX_LEVEL, GL_TEXTURE_MIN_LOD and GL_TEXTURE_MAX_LOD texture parameters?

RECOMMENDATION:  We propose omitting these features at this time, in the interest of simplifying the driver.

RESOLUTION: open

A.8 Texture Priorities and Residency

Should the subset support texture priorities via glPrioritizeTextures and the glAreTexturesResident command?

RECOMMENDATION:  Few applications use these features and functions.  We propose omitting them to simplify the driver.

RESOLUTION: open

A.9 Pixel Pack/Unpack Alignment Control

Should we support the GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT options?

These are used to align pixel data addresses to 1, 2 and 4-byte multiples for glBitmap, glTexImage2D and glReadPixels.  These aren't strictly needed since the user can provide a 1, 2 or 4-byte aligned address and appropriate GL_PACK_ROW_LENGTH or GL_UNPACK_ROW_LENGTH values instead.

RECOMMENDATION:  We recommend omitting them to simplify the driver.

RESOLUTION: open

A.10 Pixel Pack/Unpack Skip Rows/Pixels Control

Should we support the GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, GL_PACK_SKIP_PIXELS and GL_PACK_SKIP_ROWS options for pixel unpacking/packing?

These options aren't really needed since the user can adjust the start address and GL_PACK/UNPACK_ROW_LENGTH parameters to achieve the same effect.

RECOMMENDATION:  omit these parameters.

RESOLUTION: open

A.11 Texture State Queries

Should we support the command glGetTexEnvi/fv, glGetTexParameteri/fv and glGetTexLevelParameteri/fv?

RECOMMENDATION:  No. They're seldom needed and their implementation is several hundred lines of code in length.

RESOLUTION:  open

A.12 glGetIntegerv, glGetBooleanv and glGetDoublev

Should we support the commands glGetIntegerv, glGetBooleanv and glGetDoublev in addition to glGetFloatv?

RECOMMENDATION:  Omit the boolean, integer and double-valued functions. All state values which can be queried by these commands can be expressed as floating point values and queried with glGetFloatv.  The implementation of the other three commands involves many lines of code.

RESOLUTION:  open

A.13 glBitmap and Per-Fragment Operations

Should bitmaps rendered with glBitmap be subjected to the per-fragment operations?

If bitmaps are implemented with points it will be easy to implement the per-fragment operations.  Otherwise, it could be difficult.

RECOMMENDATION:  Implement glBitmap by drawing points/pixels with the hardware.  This will make supporting the per-fragments trivially easy.  Also, it makes portrait-mode display relatively easy.

RESOLUTION:  open

A.14 Reduced gl.h Header File

Should we produce a reduced gl.h header file which only defines the tokens and functions which are implemented by the subset?

RECOMMENDATION: yes.  It would be a useful reference to programmers to quickly determine which functions and tokens are supported.

RESOLUTION: open

A.15 glPolygonMode

Is glPolygonMode needed?

RECOMMENDATION: No.  Omit it.

RESOLUTION: closed, as of 26 Feb 2003