Graphics Reference
In-Depth Information
There are no char , char * , or string data types, and GLSL has no string-
manipulation functions.
There is no sizeof( ) operator, because there is no need to deal with data
in various sizes. There are standard constructors for arrays and matrices
of all needed sizes.
No implicit type conversions are allowed in GLSL. Conversions are sup-
ported by explicit type constructors.
Instead of implicit conversions, or type casts, there are three explicit con-
structors for simple types, as follows:
int(arg): converts the argument to an int; the argument may be a float
or a bool.
float(arg): converts the argument to a float; the argument may be an
int or a bool.
bool(arg): converts the argument to a boolean; the argument may be a
float or an int.
The usual conversion operations are used: conversions from float to int
simply drop the fractional part, nonzero floats or ints convert to the Boolean
true , etc. This is a different syntax from the familiar cast operations, but it gives
you the same functionality if you need it.
New Matrix and Vector Types
GLSL supports a number of predefined data types for vectors and matri-
ces. Vectors may have a real, integer, or Boolean base type, but matrices
must be real. Many familiar vector and matrix operations and functions can
be applied to variables of these types, and a number of useful new func-
tions are also provided. These are discussed in several sections later in this
chapter.
GLSL's built-in floating-point scalar and vector types are loat , vec2 ,
vec3 , and vec4 . The storage for a variable of type vecN is simply that of a tra-
ditional array, but you want to use the built-in type rather than the traditional
array type. Using the vecN types explicitly makes a much larger number of
operations available for the data, and these operations can then take advan-
tage of graphics card parallelism to work at a much higher speed.
GLSL's built-in integer, scalar, and vector types are int , ivec2 , ivec3 , and
ivec4 . Again, the storage for an ivec variable is the same as that for a tradi-
tional array, but the explicit ivec type can take a much larger set of operations.
Search WWH ::




Custom Search