Home > Articles > Programming > Graphic Programming

  • Print
  • + Share This
This chapter is from the book

Attribute Groups

In “Basic State Management” you saw how to set or query an individual state or state variable. 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. (See “Antialiasing” in Chapter 6.) With the commands glPushAttrib() and glPopAttrib(), you can save and restore all five state variables at once.

Some state variables are in more than one attribute group. For example, the state variable GL_CULL_FACE is part of both the polygon and the enable attribute groups.

In OpenGL Version 1.1, there are now two different attribute stacks. In addition to the original attribute stack (which saves the values of server state variables), there is also a client attribute stack, accessible by the commands glPushClientAttrib() and glPopClientAttrib().

In general, it’s 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. Also, if you’re operating on a remote client, all the attribute data has to be transferred across the network connection and back as it is obtained, saved, and restored. However, your OpenGL implementation keeps the attribute stack on the server, avoiding unnecessary network delays.

There are about 20 different attribute groups, which can be saved and restored by glPushAttrib() and glPopAttrib(). There are two client attribute groups, which can be saved and restored by glPushClientAttrib() and glPopClientAttrib(). For both server and client, the attributes are stored on a stack, which has a depth of at least 16 saved attribute groups. (The actual stack depths for your implementation can be obtained using GL_MAX_ATTRIB_STACK_DEPTH and GL_MAX_CLIENT_ATTRIB_STACK_DEPTH with glGetIntegerv().) Pushing a full stack or popping an empty one generates an error.

(See the tables in Appendix B to find out exactly which attributes are saved for particular mask values—that is, which attributes are in a particular attribute group.)

Table 2-8. 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_MULTISAMPLE_BIT

multisample

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

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

  • + Share This
  • 🔖 Save To Your Account