21.06.2014 Views

GLSLANG Spec 4.0 - OpenGL

GLSLANG Spec 4.0 - OpenGL

GLSLANG Spec 4.0 - OpenGL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4 Variables and Types<br />

If an instance name (instance-name) is not used, the names declared inside the block are scoped at the<br />

global level and accessed as if they were declared outside the block. If an instance name (instance-name)<br />

is used, then it puts all the members inside a scope within its own name space, accessed with the field<br />

selector ( . ) operator (analogously to structures). For example,<br />

in Light {<br />

vec4 LightPos;<br />

vec3 LightColor;<br />

};<br />

in ColoredTexture {<br />

vec4 Color;<br />

vec2 TexCoord;<br />

} Material; // instance name<br />

vec3 Color;<br />

// different Color than Material.Color<br />

vec4 LightPos;<br />

// illegal, already defined<br />

...<br />

... = LightPos; // accessing LightPos<br />

... = Material.Color; // accessing Color in ColoredTexture block<br />

Outside the shading language (i.e., in the API), members are similarly identified except the block name is<br />

always used in place of the instance name (API accesses are to interfaces, not to shaders). If there is no<br />

instance name, then the API does not use the block name to access a member, just the member name.<br />

out Vertex {<br />

vec4 Position; // API transform/feedback will use “Vertex.Position”<br />

vec2 Texture;<br />

} Coords; // shader will use “Coords.Position”<br />

out Vertex2 {<br />

vec4 Color;<br />

};<br />

// API will use “Color”<br />

For blocks declared as arrays, the array index must also be included when accessing members, as in this<br />

example<br />

uniform Transform { // API uses “Transform[2]” to refer to instance 2<br />

mat4<br />

ModelViewMatrix;<br />

mat4<br />

ModelViewProjectionMatrix;<br />

float<br />

Deformation;<br />

} transforms[4];<br />

...<br />

... = transforms[2].ModelViewMatrix; // shader access of instance 2<br />

// API uses “Transform.ModelViewMatrix” to query an offset or other query<br />

For uniform blocks declared as an array, each individual array element corresponds to a separate buffer<br />

object backing one instance of the block. As the array size indicates the number of buffer objects needed,<br />

uniform block array declarations must specify an array size. Any integral expression can be used to index<br />

a uniform block array, as per section 4.1.9 "Arrays".<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!