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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值