GLSL - program link error: Slot 0 unavailable from layout location request

GLSL - program link error: Slot 0 unavailable from layout location request

我正在尝试从教程中复制一些代码来绘制带纹理的四边形,但我担心着色器存在问题。

顶点着色器和片段着色器编译都可以,但是在链接程序时出现错误:

ERROR: Active attribute aliasing. Slot 0 unavailable for 'vertex' from layout location request.

第二个向量的位置不应该是(location = 1)吗?

我使用 SDL2 window - OpengGL 上下文:OpenGL 版本:4.1 INTEL-10.6.20 (MAC OSX)

这些是着色器文件:

vertex.glsl

#version 330 core

layout(location = 0) in vec3 vertex;
layout(location = 0) in vec2 uv;

// will be used in fragment shader
out vec2 uv_frag;

void main(){
    uv_frag = uv;
    gl_Position = vec4(vertex, 1.0);
}

fragment.glsl

#version 330 core

// has to have same name as vertex shader
in vec2 uv_frag;

// our texture
uniform sampler2D tex;

// actual output
// gl_FragColor is deprecated
out vec4 frag_color;

void main(){
    frag_color = texture(tex, uv_frag);
}

嗯,情况很清楚了。你自己已经给出了答案。

Shouldn't the location of the second vector be (location = 1)?

是的。或者更不具体:它应该不是 0。出于显而易见的原因,属性位置在单个程序中必须是唯一的。您从任何地方复制的代码都是无效的。