You can save and restore the values of a collection of state variables on an attribute stack with the commands glPushAttrib() and glPopAttrib(). The attribute stack has a depth of at least 16, and the actual depth can be obtained using GL_MAX_ATTRIB_STACK_DEPTH with glGetIntegerv(). Pushing a full stack or popping an empty one generates an error.
In general, it's faster to use glPushAttrib() and glPopAttrib() than to get and restore the values yourself. Some values might be pushed and popped in the hardware, and saving and restoring 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's saved and restored. However, your OpenGL implementation keeps the attribute stack on the server, avoiding unnecessary network delays. void glPushAttrib(GLbitfield mask);
Saves all the attributes indicated by bits in mask by pushing them onto the attribute stack. Table B-2 lists the possible mask bits that can be logically ORed together to save any combination of attributes. Each bit corresponds to a collection of individual state variables. For example, GL_LIGHTING_BIT refers to all the state variables related to lighting, which include the current material color, the ambient, diffuse, specular, and emitted light, a list of the lights that are enabled, and the directions of the spotlights. When glPopAttrib() is called, all those variables are restored. To find out exactly which attributes are saved for particular mask values, see the tables in "OpenGL State Variables."
| 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 glPopAttrib(void);
Restores the values of those state variables that were saved with the last glPushAttrib().
OpenGL Programming Guide