GLPUSHATTRIB(3G)
π NAME π
glPushAttrib, glPopAttrib β push and pop the server attribute stack π
β¨ C SPECIFICATION β¨
void glPushAttrib( GLbitfield mask )
πΈ PARAMETERS πΈ
maskβ bestie this is the mask that says which attributes we're saving. All the valid values formaskare listed down below, keep scrolling π
β¨ C SPECIFICATION (again, because there's two of them) β¨
void glPopAttrib( void )
π DESCRIPTION π
glPushAttrib takes exactly one argument, a mask that tells GL which groups of state variables to save onto the attribute stack. You build the mask out of symbolic constants β one bit per constant β and the usual move is to OR a bunch of them together. And if you're feeling β¨generousβ¨, the special mask GL_ALL_ATTRIB_BITS saves literally all the stackable states. Iconic.
So here's the whole menu of symbolic mask constants and the GL state they carry (second column = what actually gets saved, no cap):
GL_ACCUM_BUFFER_BIT- Accumulation buffer clear value
GL_COLOR_BUFFER_BITGL_ALPHA_TESTenable bit- Alpha test function and reference value
GL_BLENDenable bit- Blending source and destination functions
- Constant blend color
- Blending equation
GL_DITHERenable bitGL_DRAW_BUFFERsettingGL_COLOR_LOGIC_OPenable bitGL_INDEX_LOGIC_OPenable bit- Logic op function
- Color mode and index mode clear values
- Color mode and index mode writemasks
GL_CURRENT_BIT- Current RGBA color
- Current color index
- Current normal vector
- Current texture coordinates
- Current raster position
GL_CURRENT_RASTER_POSITION_VALIDflag- RGBA color associated with current raster position
- Color index associated with current raster position
- Texture coordinates associated with current raster position
GL_EDGE_FLAGflag
GL_DEPTH_BUFFER_BITGL_DEPTH_TESTenable bit- Depth buffer test function
- Depth buffer clear value
GL_DEPTH_WRITEMASKenable bit
GL_ENABLE_BITGL_ALPHA_TESTflagGL_AUTO_NORMALflagGL_BLENDflag- Enable bits for the user-definable clipping planes
GL_COLOR_MATERIALGL_CULL_FACEflagGL_DEPTH_TESTflagGL_DITHERflagGL_FOGflagGL_LIGHTiwhere0 <= i<GL_MAX_LIGHTSGL_LIGHTINGflagGL_LINE_SMOOTHflagGL_LINE_STIPPLEflagGL_COLOR_LOGIC_OPflagGL_INDEX_LOGIC_OPflagGL_MAP1_xwhere x is a map typeGL_MAP2_xwhere x is a map typeGL_NORMALIZEflagGL_POINT_SMOOTHflagGL_POLYGON_OFFSET_LINEflagGL_POLYGON_OFFSET_FILLflagGL_POLYGON_OFFSET_POINTflagGL_POLYGON_SMOOTHflagGL_POLYGON_STIPPLEflagGL_SCISSOR_TESTflagGL_STENCIL_TESTflagGL_TEXTURE_1DflagGL_TEXTURE_2DflagGL_TEXTURE_3Dflag- Flags
GL_TEXTURE_GEN_xwhere x isS,T,R, orQ
GL_EVAL_BITGL_MAP1_xenable bits, where x is a map typeGL_MAP2_xenable bits, where x is a map type- 1D grid endpoints and divisions
- 2D grid endpoints and divisions
GL_AUTO_NORMALenable bit
GL_FOG_BITGL_FOGenable bit- Fog color
- Fog density
- Linear fog start
- Linear fog end
- Fog index
GL_FOG_MODEvalue
GL_HINT_BITGL_PERSPECTIVE_CORRECTION_HINTsettingGL_POINT_SMOOTH_HINTsettingGL_LINE_SMOOTH_HINTsettingGL_POLYGON_SMOOTH_HINTsettingGL_FOG_HINTsetting
GL_LIGHTING_BITGL_COLOR_MATERIALenable bitGL_COLOR_MATERIAL_FACEvalue- Color material parameters that are tracking the current color
- Ambient scene color
GL_LIGHT_MODEL_LOCAL_VIEWERvalueGL_LIGHT_MODEL_TWO_SIDEsettingGL_LIGHTINGenable bit- Enable bit for each light
- Ambient, diffuse, and specular intensity for each light
- Direction, position, exponent, and cutoff angle for each light
- Constant, linear, and quadratic attenuation factors for each light
- Ambient, diffuse, specular, and emissive color for each material
- Ambient, diffuse, and specular color indices for each material
- Specular exponent for each material
GL_SHADE_MODELsetting
GL_LINE_BITGL_LINE_SMOOTHflagGL_LINE_STIPPLEenable bit- Line stipple pattern and repeat counter
- Line width
GL_LIST_BITGL_LIST_BASEsetting
GL_PIXEL_MODE_BITGL_RED_BIASandGL_RED_SCALEsettingsGL_GREEN_BIASandGL_GREEN_SCALEvaluesGL_BLUE_BIASandGL_BLUE_SCALEGL_ALPHA_BIASandGL_ALPHA_SCALEGL_DEPTH_BIASandGL_DEPTH_SCALEGL_INDEX_OFFSETandGL_INDEX_SHIFTvaluesGL_MAP_COLORandGL_MAP_STENCILflagsGL_ZOOM_XandGL_ZOOM_YfactorsGL_READ_BUFFERsetting
GL_POINT_BITGL_POINT_SMOOTHflag- Point size
GL_POLYGON_BITGL_CULL_FACEenable bitGL_CULL_FACE_MODEvalueGL_FRONT_FACEindicatorGL_POLYGON_MODEsettingGL_POLYGON_SMOOTHflagGL_POLYGON_STIPPLEenable bitGL_POLYGON_OFFSET_FILLflagGL_POLYGON_OFFSET_LINEflagGL_POLYGON_OFFSET_POINTflagGL_POLYGON_OFFSET_FACTORGL_POLYGON_OFFSET_UNITS
GL_POLYGON_STIPPLE_BIT- Polygon stipple image
GL_SCISSOR_BITGL_SCISSOR_TESTflag- Scissor box
GL_STENCIL_BUFFER_BITGL_STENCIL_TESTenable bit- Stencil function and reference value
- Stencil value mask
- Stencil fail, pass, and depth buffer pass actions
- Stencil buffer clear value
- Stencil buffer writemask
GL_TEXTURE_BIT- Enable bits for the four texture coordinates
- Border color for each texture image
- Minification function for each texture image
- Magnification function for each texture image
- Texture coordinates and wrap mode for each texture image
- Color and mode for each texture environment
- Enable bits
GL_TEXTURE_GEN_x, x isS,T,R, andQ GL_TEXTURE_GEN_MODEsetting forS,T,R, andQglTexGenplane equations forS,T,R, andQ- Current texture bindings (for example,
GL_TEXTURE_BINDING_2D)
GL_TRANSFORM_BIT- Coefficients of the six clipping planes
- Enable bits for the user-definable clipping planes
GL_MATRIX_MODEvalueGL_NORMALIZEflagGL_RESCALE_NORMALflag
GL_VIEWPORT_BIT- Depth range (near and far)
- Viewport origin and extent
Now for the other half of the duo: glPopAttrib restores the values of the state variables that were saved with the last glPushAttrib command. Anything that wasn't saved? Left completely unchanged. She minds her own business. π
It's an error to push attributes onto a full stack, or to pop attributes off an empty stack. In either case, the error flag gets set and nothing else in GL state changes. So like, no half-applied chaos. Good.
And heads up: initially, the attribute stack is empty. π«
π NOTES π
Not every single value of GL state can be saved on the attribute stack, bestie. For example: render mode state, and select and feedback state β cannot be saved. Client state has to be saved with glPushClientAttrib instead, that's a whole different stack.
The depth of the attribute stack depends on the implementation, but it must be at least 16. That's the floor, not a suggestion.
When the GL_ARB_multitexture extension is supported, pushing and popping texture state apples to all supported texture units. (Yes it says apples. We are simply quoting the ancestors. π)
π ERRORS π
GL_STACK_OVERFLOWis generated ifglPushAttribis called while the attribute stack is full.GL_STACK_UNDERFLOWis generated ifglPopAttribis called while the attribute stack is empty.GL_INVALID_OPERATIONis generated ifglPushAttriborglPopAttribis executed between the execution ofglBeginand the corresponding execution ofglEnd.
π¨ Not me pushing onto a full stackβ¦ that'sGL_STACK_OVERFLOWand GL will absolutely clock it. Don't do it betweenglBeginandglEndeither. That'sGL_INVALID_OPERATIONterritory, and it's giving chaos.
π ASSOCIATED GETS π
glGetwith argumentGL_ATTRIB_STACK_DEPTHglGetwith argumentGL_MAX_ATTRIB_STACK_DEPTH
π¦ SEE ALSO π¦
glGet(3G), glGetClipPlane(3G), glGetError(3G), glGetLight(3G), glGetMap(3G), glGetMaterial(3G), glGetPixelMap(3G), glGetPolygonStipple(3G), glGetString(3G), glGetTexEnv(3G), glGetTexGen(3G), glGetTexImage(3G), glGetTexLevelParameter(3G), glGetTexParameter(3G), glIsEnabled(3G), glPushClientAttrib(3G)
okay that's the whole page, bestie π«Ά This was GLPUSHATTRIB(3G) from the 3G manual pages β header said GLPUSHATTRIB(3G), footer said GLPUSHATTRIB(3G), and the date slot was lowkey empty, so consider this your timestamp: whenever you needed it. Push responsibly, pop responsibly, and remember the stack starts empty. mwah πβ¨
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- fedora 43: gl-manpages 1.1-34.20190306.fc43 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- fedora 44: gl-manpages 1.1-35.20190306.fc44 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms