Contents / Previous / Next


Attribute Groups

Similar to matrix stacks, you can also save and restore the values of a collection of related state variables with a single command.

OpenGL groups related state variables into an attribute group. For example, the GL_LINE_BIT attribute consists of five state variables: the line width, the GL_LINE_STIPPLE enable status, the line stipple pattern, the line stipple repeat counter, and the GL_LINE_SMOOTH enable status.

With the commands glPushAttrib() and glPopAttrib(), you can save and restore all five state variables, all at once:

      gl.glPushAttrib( GL.GL_LINE_BIT ); {
      
            gl.glLineStipple( 1, stripple );
	    gl.glEnable( GL.GL_LINE_STIPPLE );

	    ...
      
      } gl.glPopAttrib(); 

void glPushAttrib(GLbitfield mask);
saves all the attributes indicated by bits in
mask by pushing them onto the attribute stack.

void glPopAttrib(void);
restores the values of those state variables that were saved with the last glPushAttrib().

In general, it is faster to use these commands than to get, save, and restore the values yourself. Some values might be maintained in the hardware, and getting them might be expensive.

The special mask, GL_ALL_ATTRIB_BITS, is used to save and restore all the state variables in all the attribute groups.

Attribute Groups

Mask Bit

Attribute Group

GL_ACCUM_BUFFER_BIT

accum-buffer

GL_ALL_ATTRIB_BITS

--

GL_COLOR_BUFFER_BIT

color-buffer

GL_CURRENT_BIT

current

GL_DEPTH_BUFFER_BIT

depth-buffer

GL_ENABLE_BIT

enable

GL_EVAL_BIT

eval

GL_FOG_BIT

fog

GL_HINT_BIT

hint

GL_LIGHTING_BIT

lighting

GL_LINE_BIT

line

GL_LIST_BIT

list

GL_PIXEL_MODE_BIT

pixel

GL_POINT_BIT

point

GL_POLYGON_BIT

polygon

GL_POLYGON_STIPPLE_BIT

polygon-stipple

GL_SCISSOR_BIT

scissor

GL_STENCIL_BUFFER_BIT

stencil-buffer

GL_TEXTURE_BIT

texture

GL_TRANSFORM_BIT

transform

GL_VIEWPORT_BIT

viewport


 

void glPushClientAttrib(GLbitfield mask);
void glPopClientAttrib(void); glPushClientAttrib() saves all the attributes indicated by bits in
mask by pushing them onto the client attribute stack. glPopClientAttrib() restores the values of those state variables that were saved with the last glPushClientAttrib(). Table 2-7 lists the possible mask bits that can be logically ORed (OR operation) together to save any combination of client attributes.
There are two client attribute groups, feedback and select, that cannot be saved or restored with the stack mechanism.
Client Attribute Groups

Mask Bit

Attribute Group

GL_CLIENT_PIXEL_STORE_BIT

pixel-store

GL_CLIENT_VERTEX_ARRAY_BIT

vertex-array

GL_ALL_CLIENT_ATTRIB_BITS

--

can't be pushed or popped

feedback

can't be pushed or popped

select