21.06.2014 Views

GLSL 3.30 - OpenGL

GLSL 3.30 - OpenGL

GLSL 3.30 - 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 />

It is a compile-time error if a layout declaration's array size (from table above) does not match any array<br />

size specified in declarations of an input variable in the same shader. The following are all examples of<br />

compile time errors:<br />

// code sequence within one shader...<br />

in vec4 Color1[]; // size unknown<br />

...Color1.length()...// illegal, length() unknown<br />

in vec4 Color2[2]; // size is 2<br />

...Color1.length()...// illegal, Color1 still has no size<br />

in vec4 Color3[3]; // illegal, input sizes are inconsistent<br />

layout(lines) in; // legal, input size is 2, matching<br />

in vec4 Color4[3]; // illegal, contradicts layout<br />

...Color1.length()...// legal, length() is 2, Color1 sized by layout()<br />

layout(lines) in; // legal, matches other layout() declaration<br />

layout(triangles) in;// illegal, does not match earlier layout() declaration<br />

It is a link-time error if not all provided sizes (sized input arrays and layout size) match across all<br />

geometry shaders in the program.<br />

Fragment shaders can have an input layout only for redeclaring the built-in variable gl_FragCoord (see<br />

section 7.2 “Fragment Shader Special Variables”). The layout qualifier identifiers for gl_FragCoord are<br />

layout-qualifier-id<br />

origin_upper_left<br />

pixel_center_integer<br />

By default, gl_FragCoord assumes a lower-left origin for window coordinates and assumes pixel centers<br />

are located at half-pixel coordinates. For example, the (x, y) location (0.5, 0.5) is returned for the lowerleft-most<br />

pixel in a window. The origin can be changed by redeclaring gl_FragCoord with the<br />

origin_upper_left identifier, moving the origin of gl_FragCoord to the upper left of the window, with y<br />

increasing in value toward the bottom of the window. The values returned can also be shifted by half a<br />

pixel in both x and y by pixel_center_integer so it appears the pixels are centered at whole number pixel<br />

offsets. This moves the (x, y) value returned by gl_FragCoord of (0.5, 0.5) by default, to (0.0, 0.0) with<br />

pixel_center_integer. Redeclarations are done as follows<br />

in vec4 gl_FragCoord;<br />

// redeclaration that changes nothing is allowed<br />

// All the following are allowed redeclaration that change behavior<br />

layout(origin_upper_left) in vec4 gl_FragCoord;<br />

layout(pixel_center_integer) in vec4 gl_FragCoord;<br />

layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;<br />

If gl_FragCoord is redeclared in any fragment shader in a program, it must be redeclared in all the<br />

fragment shaders in that program that have a static use gl_FragCoord. All redeclarations of<br />

gl_FragCoord in all fragment shaders in a single program must have the same set of qualifiers. Within<br />

any shader, the first redeclarations of gl_FragCoord must appear before any use of gl_FragCoord. The<br />

built-in gl_FragCoord is only predeclared in fragment shaders, so redeclaring it in any other shader<br />

language will be illegal.<br />

37

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

Saved successfully!

Ooh no, something went wrong!