我正在尝试将使用变换反馈的 GLSL 程序与顶点着色器 + 几何着色器链接起来。该程序给出了一个链接错误,因为它找不到这里指定的变量之一:
ConstStr captureVars[] = {"tf.pos", "tf.speed", "tf.timeLived"};
glTransformFeedbackVaryings(prog, tl::size(captureVars), captureVars, GL_INTERLEAVED_ATTRIBS);
这些变量位于几何着色器的输出接口块内。
out TransformFeedback {
vec3 pos;
vec3 speed;
float timeLived;
} tf;
这是我得到的错误消息:
Geometry info
-------------
0(16) : warning C7050: "tf.speed" might be used before being initialized
Link info
---------
error: Varying (named tf.pos) specified but not present in the program object.
Vertex Shader:
0| #version 330
1|
2| layout(location = 0) in vec3 a_pos;
3| layout(location = 1) in vec3 a_speed;
4| layout(location = 2) in float a_timeLived;
5|
6| out VertexData {
7| vec3 pos;
8| vec3 speed;
9| float timeLived;
10| } output;
11|
12| void main()
13| {
14| output.pos = a_pos;
15| output.speed = a_speed;
16| output.timeLived = a_timeLived;
17| }
18|
Geometry Shader:
0| #version 330
1|
2| layout (points) in;
3| layout (points, max_vertices = 1) out;
4|
5| in VertexData {
6| vec3 pos;
7| vec3 speed;
8| float timeLived;
9| } input[];
10|
11| out TransformFeedback {
12| vec3 pos;
13| vec3 speed;
14| float timeLived;
15| } tf;
16|
17| uniform float u_dt;
18| uniform float u_damping;
19| uniform float u_gravity;
20| uniform float u_lifeTime;
21|
22| void main()
23| {
24| tf.timeLived = input[0].timeLived + u_dt;
25| if(tf.timeLived < u_lifeTime) {
26| tf.pos = input[0].pos + tf.speed * u_dt;
27| tf.speed = input[0].speed + u_gravity * u_dt;
28| tf.speed *= 1.0 - u_damping * u_dt;
29| EmitVertex();
30| EndPrimitive();
31| }
32| }
33|
如您所见,几何着色器编译时带有警告(这对我来说没有意义)。然后程序无法链接。
我试过不使用接口块,而是使用带有“tf_”的变量,它就是这样工作的。因此,它必须与必须指定接口块变量的方式有关。