游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2602|回复: 3

glpushattrib里面的状态组是互相独立的还是有交叉?

[复制链接]

21

主题

230

帖子

230

积分

中级会员

Rank: 3Rank: 3

积分
230
发表于 2006-11-15 09:09:00 | 显示全部楼层 |阅读模式
"

                        The symbolic mask constants and their associated GL state are as follows (the second column lists which attributes are
                        saved):
               
GL_ACCUM_BUFFER_BIT        Accumulation buffer clear value
         
GL_COLOR_BUFFER_BIT        GL_ALPHA_TEST enable bit
        Alpha test function and reference value
        GL_BLEND enable bit
        Blending source and destination functions
        Constant blend color
        Blending equation
        GL_DITHER enable bit
        GL_DRAW_BUFFER setting
        GL_COLOR_LOGIC_OP enable bit
        GL_INDEX_LOGIC_OP enable 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_VALID flag
        RGBA color associated with current raster position
        Color index associated with current raster position
        Texture coordinates associated with current raster position
        GL_EDGE_FLAG flag
         
GL_DEPTH_BUFFER_BIT        GL_DEPTH_TEST enable bit
        Depth buffer test function
        Depth buffer clear value
        GL_DEPTH_WRITEMASK enable bit
         
GL_ENABLE_BIT        GL_ALPHA_TEST flag
        GL_AUTO_NORMAL flag
        GL_BLEND flag
        Enable bits for the user-definable clipping planes
        GL_COLOR_MATERIAL
        GL_CULL_FACE flag
        GL_DEPTH_TEST flag
        GL_DITHER flag
        GL_FOG flag
        GL_LIGHTi where 0<=
                                                i<GL_MAX_LIGHTS
        GL_LIGHTING flag
        GL_LINE_SMOOTH flag
        GL_LINE_STIPPLE flag
        GL_COLOR_LOGIC_OP flag
        GL_INDEX_LOGIC_OP flag
        GL_MAP1_x where x is a map
                                                type
        GL_MAP2_x where x is a map
                                                type
        GL_NORMALIZE flag
        GL_POINT_SMOOTH flag
        GL_POLYGON_OFFSET_LINE flag
        GL_POLYGON_OFFSET_FILL flag
        GL_POLYGON_OFFSET_POINT flag
        GL_POLYGON_SMOOTH flag
        GL_POLYGON_STIPPLE flag
        GL_SCISSOR_TEST flag
        GL_STENCIL_TEST flag
        GL_TEXTURE_1D flag
        GL_TEXTURE_2D flag
        GL_TEXTURE_3D flag
        Flags GL_TEXTURE_GEN_x where x is
                                                S, T, R, or Q
         
GL_EVAL_BIT        GL_MAP1_x enable bits, where x is
                                                a map type
        GL_MAP2_x enable bits, where x is
                                                a map type
        1D grid endpoints and divisions
        2D grid endpoints and divisions
        GL_AUTO_NORMAL enable bit
         
GL_FOG_BIT        GL_FOG enable bit
        Fog color
        Fog density
        Linear fog start
        Linear fog end
        Fog index
        GL_FOG_MODE value
         
GL_HINT_BIT        GL_PERSPECTIVE_CORRECTION_HINT setting
        GL_POINT_SMOOTH_HINT setting
        GL_LINE_SMOOTH_HINT setting
        GL_POLYGON_SMOOTH_HINT setting
        GL_FOG_HINT setting
         
GL_LIGHTING_BIT        GL_COLOR_MATERIAL enable bit
        GL_COLOR_MATERIAL_FACE value
        Color material parameters that are tracking the current color
        Ambient scene color
        GL_LIGHT_MODEL_LOCAL_VIEWER value
        GL_LIGHT_MODEL_TWO_SIDE setting
        GL_LIGHTING enable 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_MODEL setting
         
GL_LINE_BIT        GL_LINE_SMOOTH flag
        GL_LINE_STIPPLE enable bit
        Line stipple pattern and repeat counter
        Line width
         
GL_LIST_BIT        GL_LIST_BASE setting
         
GL_PIXEL_MODE_BIT        GL_RED_BIAS and GL_RED_SCALE settings
        GL_GREEN_BIAS and GL_GREEN_SCALE values
        GL_BLUE_BIAS and GL_BLUE_SCALE
        GL_ALPHA_BIAS and GL_ALPHA_SCALE
        GL_DEPTH_BIAS and GL_DEPTH_SCALE
        GL_INDEX_OFFSET and GL_INDEX_SHIFT values
        GL_MAP_COLOR and GL_MAP_STENCIL flags
        GL_ZOOM_X and GL_ZOOM_Y factors
        GL_READ_BUFFER setting
         
GL_POINT_BIT        GL_POINT_SMOOTH flag
        Point size
         
GL_POLYGON_BIT        GL_CULL_FACE enable bit
        GL_CULL_FACE_MODE value
        GL_FRONT_FACE indicator
        GL_POLYGON_MODE setting
        GL_POLYGON_SMOOTH flag
        GL_POLYGON_STIPPLE enable bit
        GL_POLYGON_OFFSET_FILL flag
        GL_POLYGON_OFFSET_LINE flag
        GL_POLYGON_OFFSET_POINT flag
        GL_POLYGON_OFFSET_FACTOR
        GL_POLYGON_OFFSET_UNITS
         
GL_POLYGON_STIPPLE_BIT        Polygon stipple image
         
GL_SCISSOR_BIT        GL_SCISSOR_TEST flag
        Scissor box
         
GL_STENCIL_BUFFER_BIT        GL_STENCIL_TEST enable 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
                                                is S, T, R, and Q
        GL_TEXTURE_GEN_MODE setting for S, T, R, and Q
        glTexGen plane equations for S, T, R, and Q
        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_MODE value
        GL_NORMALIZE flag
        GL_RESCALE_NORMAL flag
         
GL_VIEWPORT_BIT        Depth range (near and far)
        Viewport origin and extent


                        glPopAttrib restores the values of the state variables saved with the last
               


                        glPushAttrib command. Those not saved are left unchanged.
               


                        It is an error to push attributes onto a full stack, or to pop attributes off an empty stack. In either case, the error
                        flag is set and no other change is made to GL state.
               


                        Initially, the attribute stack is empty.
               
Notes


                        Not all values for GL state can be saved on the attribute stack. For example, render mode state, and select and
                        feedback state cannot be saved. Client state must be saved with glPushClientAttrib.
"

21

主题

230

帖子

230

积分

中级会员

Rank: 3Rank: 3

积分
230
 楼主| 发表于 2006-11-15 09:12:00 | 显示全部楼层

Re:glpushattrib里面的状态组是互相独立的还是有交叉?

主要是 GL_ENABLE_BIT和其他好像有交叉。
比如他有        GL_DEPTH_TEST flag
然后在GL_DEPTH_BUFFER_BIT也有        GL_DEPTH_TEST enable bit

1

主题

28

帖子

28

积分

注册会员

Rank: 2

积分
28
QQ
发表于 2006-11-15 15:53:00 | 显示全部楼层

Re:glpushattrib里面的状态组是互相独立的还是有交叉?

好东西,请问楼主,这个函数效率怎么样啊?

21

主题

230

帖子

230

积分

中级会员

Rank: 3Rank: 3

积分
230
 楼主| 发表于 2006-11-15 16:48:00 | 显示全部楼层

Re:glpushattrib里面的状态组是互相独立的还是有交叉?

是有交叉的。比如GL_DEPTH_BUFFER_BIT和GL_ENABLE_BIT那些状态是有重复的。我测试了一下,glenablebit里面包含了ztest,gl_depth_buffer也包含。
glpushattrib速度好像慢。但是好像不能说效率不高。

OpenGL Performance Optimization ,SIGGRAPH '97里面说
"
Avoid glPushAttrib
    If only a few pieces of state need to be saved and restored it's often faster to maintain the information in the client program. glPushAttrib( GL_ALL_ATTRIB_BITS ) in particular can be very expensive on hardware systems. This call may be faster in software implementations than in hardware. [H,L]"

但是
msdn里面说
"
Use glPushAttrib and glPopAttrib to save and restore state values. Use query functions only when your application requires the state values for its own computations. "
来自:OpenGL Performance Tips msdn

更详细的
Avoiding 16 Common OpenGL Pitfalls  里说
"
This is however almost certainly a bad approach. OpenGL is designed for fast rendering and setting state; retrieving OpenGL state is often considerably slower than simply setting the state the way you require. As a rule, glGetIntegerv and related state retrieval routines should only be used for debugging or retrieving OpenGL implementation limits. They should never be used in performance critical code. On faster OpenGL implementations where much of OpenGL's state is maintained within the graphics hardware, the relative cost of state retrieval commands is considerably higher than in largely software-based OpenGL implementations. This is because state retrieval calls must stall the graphics hardware to return the requested state. When users run OpenGL programs on high-performance expensive graphics hardware and do not see the performance gains they expect, in many cases the reason is invocations of state retrieval commands that end up stalling the hardware to retrieve OpenGL state.

In cases where you do need to make sure that you restore the previous matrix mode after changing it, try using glPushAttrib with the GL_TRANSFORM_BIT bit set and then use glPopAttrib to restore the matrix mode as needed. Pushing and popping attributes on the attribute stack can be more efficient than reading back the state and later restoring it. This is because manipulating the attribute stack can completely avoid stalling the hardware if the attribute stack exists within the hardware. Still the attribute stack is not particularly efficient since all the OpenGL transform state (including clipping planes and the normalize flag) must also be pushed and popped.
"

我是用来做pass直接的状态保存。每个PASS之间状态切换比较多,所以我用这个。而且我自己要跟踪每个状态也麻烦。200多个状态吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-25 20:48

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表