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.)

原文链接: https://www.cnblogs.com/lilei9110/archive/2010/11/26/1888558.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Cg:访问OpenGL的状态

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/17914

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月7日 下午6:37
下一篇 2023年2月7日 下午6:37

相关推荐