Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL - Equivalent Of "layout (location = 1)" In #version 130

I am reading a tutorial about openGL 3.3 (where naturally GLSL 330 is in use). Unfortunately my hardware is limited to openGL 3.0 (where GLSL 130 is the newest format). In GLSL 130 the syntax

layout (location = 1) in vec4 position;

produces an error. Most importantly a code where several instances of "layout" are applied to different variables does not work. I even tried

#extension ARB_explicit_attrib_location : require

which is also not supported. Is there a way to rewrite these statements from 330 in 130 equivalently?

like image 606
Fejwin Avatar asked Oct 05 '11 22:10

Fejwin


People also ask

What is GLSL layout?

layout(location = output index) out vec4 outColor; As with vertex shader inputs, this allows the user to forgo the use of glBindFragDataLocation. Similarly, the values in the shader override the values provided by this function.

Is gl_FragColor deprecated?

Yes, gl_FragColor is deprecated. You should use the following syntax: layout(location = 0) out vec4 diffuseColor; It is included in the GLSL 4.60 spec under the section 7.1.

What is a uniform in GLSL?

A uniform is a global Shader variable declared with the "uniform" storage qualifier. These act as parameters that the user of a shader program can pass to that program. Their values are stored in a program object.

What is Std140?

Std140 is a standardized memory layout for GLSL shader interface blocks (e.g. uniform blocks). An interface block is a group op typed GLSL variables. For details on the layout rules for std140, please refer to the section 2.12. 6.4 “Standard Uniform Block Layout” of the OpenGL ES 3.0 Specification.


1 Answers

If your implementation does not support ARB_explicit_attrib_location (either as an extension or as version 330 or later), then you cannot use explicit attribute locations. You must specify them before the linking phase with glBindAttribLocation.

And technically, your "hardware" could do this just fine. NVIDIA and ATI support this extension in all hardware that they still support in drivers. This is an API convenience. I'm guessing you're on some from of Intel hardware. If so, you have my sympathy.

BTW, is that my code, by chance?

like image 117
Nicol Bolas Avatar answered Oct 10 '22 14:10

Nicol Bolas