12. Effect
Following code clip demostrates the use of effect.
- In the shader class declares an effect variable effect
variable effect
In InitDeviceObjects method of the shader class inserts lines
set effect [$app effect $filename $userid]
You may set fixed file name string without using the open file dialog box. The $app graph command creates a graph object gh with filename and userid. The userid is a 32-bit integer.
In the RestoreDeviceObjects method inserts below line to restore the effect.
$effect restore
In the InvalidateDeviceObjects method inserts below line to invalidate the effect.
$effect invalidate
In the DeleteDeviceObjects method inserts below line to delete the effect.
$effect release
In the Render method the regular use of effect looks like
$effect setMatrix "matView" $mView
$vb stream 0 0 [$vertice size]
$ib indices 0
set uPass [$effect begin 0]
for {set i 0} {i < uPass} {incr i} {
$effect pass $i
$app drawIndexedPrimitive trianglelist 0 \
0 $nNumVertices 0 $nNumFaces
}
$effect end
The $effect setMatrix sets a matrix used in the effect. $effect begin id starts the effect. In the for loop $effect pass $i enables the i-th pass in the effect. After showing all the effect, $effect end closes the rendering.
|