Game Development Reference
In-Depth Information
MyStruct s; // instantiate
s.f = 5.0f; // member access
16.3.6 The typedef Keyword
The HLSL typedef keyword functions exactly the same as it does in
C++. For example, we can give the name point to the type vec-
tor<float, 3> using the following syntax:
typedef vector<float, 3> point;
Then instead of writing:
vector<float, 3> myPoint;
...we can just write:
point myPoint;
Here are two more examples that show how to use the typedef key-
word with a constant type and an array:
typedef const float CFLOAT;
typedef float point2[2];
16.3.7 Variable Prefixes
The following keywords can prefix a variable declaration:
static —If a global variable is prefixed with the static keyword,
it means that it is not to be exposed outside the shader. In other
words, it is local to the shader. If a local variable is prefixed with the
static keyword, it has the same behavior as a static local vari-
able in C++. That is, it is initialized once when the function is first
executed, and it maintains its value throughout all calls of the func-
tion. If the variable is not initialized, it is automatically initialized to
0.
static intx=5;
uniform —If a variable is prefixed with the uniform keyword, it
means the variable is initialized outside the shader, by the C++
application for instance, and input into the shader.
extern —If a variable is prefixed with the extern keyword it
means the variable can be accessed outside the shader, by the
C++ application for instance. Only global variables can be prefixed
with the extern keyword. Non-static global variables are extern
by default.
shared —If a variable is prefixed with the shared keyword, it
hints to the effects framework (see Chapter 19) that the variable
Team-Fly ®
Search WWH ::




Custom Search