shade
學習筆記(
3
)-
cg openGL runtime
library
-
當
uniform
參數設置到
openGL
以后是保存在
CG
openGL runtime
里邊或者
cg core runtime
里邊,而
d
3d
是直接保存到
GPU
的
constant memory
里邊。
-
openGL
在使用
CG
的時候必須首先使用wglCreateContext()
or glXCreateContext()來創建
openGL Context
。
-
設置
Uniform參數:
-
cgGLSetParameter,兩種類型
float
(f),double(d).
-
cgGLSetMatrixParameterfr
,
cgGLSetMatrixParameter
dc,
四種,
c
表示列向量為主,
r
表示
row
向量為主。
-
cgGLSetStateMatrixParameter()可以用來設置狀態矩陣,包括
ModelView
矩陣,
Projection
矩陣,紋理矩陣。
-
cgGLSetParameterArray()用來設置
Uniform
的數組參數;cgGLSetMatrixParameterArrayfr用來設置矩陣數組
??? 設置變量參數:
- 因為FP的變量參數是按照光柵化插值后的結果來設置的,所以只有VS程序有變量參數。
- 設置變量參數兩步:
- cgGLSetParameterPointer():設置變量數組,我理解就是頂點數組
- void
cgGLEnableClientState(CGparameter parameter);和void
cgGLDisableClientState(CGparameter parameter);使得該參數有效。
- 注意:cgGLSetParameter也可以用來設置變量參數,這時采用的是openGL立即模式,也就相當于glVertex,glNormal,glColor這樣的做法吧,但是我想這顯然是一種效率不高的做法。且cgGLGetParameter不能用來取變量參數。
??? 設置Sampler參數:Sampler和紋理是一一對應的,所以實際就是對一段頂點繪制指定一個紋理。- cgGLSetTextureParameter(CGparameter
parameter,GLuint textureName);來指定一個紋理給CGParameter。
- void
cgGLEnableTextureParameter(CGparameter parameter);來使紋理生效。void
cgGLDisableTextureParameter(CGparameter parameter);使其失效,相當于glBindTexture命令。
void
cgGLSetOptimalOptions(CGprofile profile);來使用最優的Profile。而CGbool
cgGLIsProfileSupported(CGprofile profile);可以用來判斷硬件是否支持該Profile。
經過這幾天的學習,終于大概明白了shader是怎么work的了,但是對于用programmable pipeline替換掉fixed function還是一頭霧水。
?