MENU
Data Types
Basic Types | |
void | no function return value or empty parameter list |
bool | Boolean |
int | signed integer |
float | floating scalar |
vec2, vec3, vec4 | float vector |
bvec2, bvec3, bvec4 | boolean vector |
ivec2, ivec3, ivec4 | signed integer vector |
mat2, mat3, mat4 | float matrix |
sampler2D | 2D texture access |
samplerCube | cube-mapped texture access |
Examples | |
bool b1=true; | |
int i1=3; | |
float f1=5; //error | |
float f2=5.0; | |
float f3=float(5); | |
float f4=float(i1); | |
bool b2=bool(5.0); | |
int i2=int(true)+3,i3,i4=5; | |
vec3 va=5.0; //error | |
vec3 vb=vec3(1.0,2.0,3.0); | |
vec2 vc=vec2(vb); //sets to (1.0,2.0); | |
vec4 vd=vec4(5.0); //sets to (5.0,5.0,5.0,5.0); | |
vec4 ve=vec4(vc,vd); //sets to (1.0,2.0,5.0,5.0); | |
mat3 ma=mat3(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0); |
|
mat2 mb=mat2(ve); | |
mat3 mc=mat3(vb,vb,vb); | |
mat2 md=mat2(1.0,2.0,vc); | |
mat4 me=mat4(1.0); // identity matrix | |
float f5=vb.x; // the first to fourth components of a vector can be accessed via // (x,y,z,w), (r,g,b,a), or (s,t,p,q), // where v.x, v.r, and v.s are the same, and so on. |
|
vec2 vf=vb.zx; // sets to (3.0,1.0) | |
vec3 vg=vb.rgr; // sets to (1.0,2.0,1.0) | |
vg.sp=vec2(5.0,6.0); // vg becomes (5.0,2.0,6.0) | |
vg=vb.xrs; // error: components not of the same set | |
vec3 vh=ma[1]; //sets to (4.0,5.0,6.0) | |
float f6=ma[2][0]; //sets to 7.0 | |
float f7=ma[1].y; //sets to 5.0 | |
const int ind=0; vec3 vi=ma[ind+1]; // in the [] operator, there can only be an integral // literal, a const variable, a loop index, or an // expression composed from any of the preceding. |
|
Arrays | |
Only 1-dimensional arrays are supported. Arrays cannot be initialized during declaration. Arrays cannot also be qualified as const. The index of an array must be an integral literal, a const variable, or an expression composed from any of the preceding. | |
Examples | |
float floatArray[3]; | |
vec4 vec4Array[5]; |
Structures |
Unlike C, the 'typedef' keyword is not necessary when defining a new aggregate structure type. |
Examples |
struct light { vec4 color; vec3 position; }; light l1,l2; l1=light(vec4(0.0,1.0,0.0,1.0), vec3(8.0,3.0,8.0)); |
struct light { vec4 color[3]; vec3 position;}l3[5]; // an array of structures vec3 p=l3[2].position; |