Cg:访问OpenGL的状态
From http://stackoverflow.com/questions/14358/accessing-opengl-state-variables-in-cg
If you are on any fairly recent Cg profile (arbvp1 and later), your Cg shader programs can in fact access the OpenGL state (MVP matrices, material and light settings) directly. This makes writing those programs less painful.
Here are some of the state variables which can be accessed:
MVP matrices of all types:
state.matrix.mvp   
state.matrix.inverse.mvp    
state.matrix.modelview    
state.matrix.inverse.modelview    
state.matrix.modelview.invtrans    
state.matrix.projection    
state.matrix.inverse.projection    
Light and material properties: 
state.material.ambient   
state.material.diffuse    
state.material.specular    
state.light[0].ambient    
For the full list of state variables, refer to the section Accessing OpenGL State, OpenGL ARB Vertex Program Profile (arbvp1) in the Cg Users Manual[P.256 Accessing OpenGL State]. 
Note:
All the OpenGL state variables are of uniform type when accessed in Cg.   
For light variables, the index is mandatory. (Eg: 1 in state.light[1].ambient)    
Lighting or light(s) need not be enabled to use those corresponding light values inside Cg. But, they need to be set using glLight() functions.
From http://developer.nvidia.com/forums/index.php?showtopic=2146&hl=ModelViewProjection
Wow, what a waste of time on my part.   
ModelViewProjection really isn't a semantic, it's an alias! How damn sneaky!    
I found out that in the C++ code, they do a lookup for ModelViewProjection and set the model view projection manually, just like a regular uniform. To get what I actually wanted, I had to use the "state.matrix.mvp" semantic.    
Why this was so hard to figure out, I'll never know. Maybe bad documentation.
From http://www.gamedev.net/community/forums/topic.asp?topic_id=480004
These params always should be uniform:   
uniform float4x4 ModelViewProj : state.matrix.mvp    
You don't need to use cgGLSetStateMatrixParameter if you use ARB-based profile (arbvp1, vp40, etc.)
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号