ERROR: 0:3: 错误(#279) 无效的布局限定符 ‘location’

huangapple go评论120阅读模式
英文:

ERROR: 0:3: error(#279) Invalid layout qualifier 'location'

问题

我试图按照教程操作,但在尝试编译他制作的顶点着色器时,我得到以下输出:

  1. 顶点着色器编译失败,出现以下错误:
  2. 错误:0:3:错误(#279) 无效的布局限定符 'location'
  3. 错误:错误(#273) 1 个编译错误。没有生成代码

我使用的是 GLSL 3.2.9232,我的代码:

  1. #version 150
  2. layout (location = 0) in vec3 position;
  3. void main()
  4. {
  5. gl_Position = vec4(0.25 * position, 1.0);
  6. }
英文:

i am trying to follow a tutorial and when i try to compile the vertex shader he made i get this output:

  1. Vertex shader failed to compile with the following errors:
  2. ERROR: 0:3: error(#279) Invalid layout qualifier 'location'
  3. ERROR: error(#273) 1 compilation errors. No code generated

I use GLSL 3.2.9232 and my code :

  1. #version 150
  2. layout (location = 0) in vec3 position;
  3. void main()
  4. {
  5. gl_Position = vec4(0.25 * position, 1.0);
  6. }

答案1

得分: 1

  1. 输入布局位置限定符(参见[顶点着色器属性索引](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Vertex_shader_attribute_index))在GLSL 3.30中引入,在GLSL 1.50中不可用。请对比[OpenGL Shading Language 3.30规范](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.3.30.pdf)和[OpenGL Shading Language 1.50规范](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.50.pdf)。
  2. 切换到GLSL 3.30
  3. #version 150
  4. ```glsl
  5. #version 330

如果你的系统不支持GLSL 3.30,你必须移除布局限定符:

layout (location = 0) in vec3 position;

  1. in vec3 position;

你可以在程序链接之前使用glBindAttribLocation指定属性位置:

  1. glBindAttribLocation(program, 0, "position"); // 必须在glLinkProgram之前完成
  2. glLinkProgram(program)
  1. <details>
  2. <summary>英文:</summary>
  3. Input layout locations qualifiers (see [Vertex shader attribute index](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Vertex_shader_attribute_index)) are introduced in in GLSL 3.30 and cannot be used in GLSL 1.50. Compare [OpenGL Shading Language 3.30 Specification](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.3.30.pdf) and [OpenGL Shading Language 1.50 Specification](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.50.pdf).
  4. Switch to glsl 3.30:
  5. &lt;s&gt;`#version 150`&lt;/s&gt;
  6. ```glsl
  7. #version 330

If your system doesn't support GLSL 3.30, you have to remove the layout qualifier

<s>layout (location = 0) in vec3 position;</s>

  1. in vec3 position;

You can specify the attribute location with glBindAttribLocation before the program is linked:

  1. glBindAttribLocation(program, 0, &quot;position&quot;); // has to be done before glLinkProgram
  2. glLinkProgram(program)

huangapple
  • 本文由 发表于 2020年10月16日 00:29:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/64375952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定