i’m trying to make a little application with transform feedback, i want to capture all (transformed) vertex attributes and want to reuse them the next frame (double-buffered)
capturing variables already works, but i assume the problem is the glsl compiler that “optimizes” the vertex shader and discarts unused variables
#version 450 core
in vec3 position;
in vec4 color;
out layout (location = 0) vec4 out_color;
void main ()
{
out_color = color + vec4(position, 0);
}
as you can see, the fragment shader does some “weird” stuff, i just added a position to “persuay” the compiler to not discard the variable, but that’s just for testing purposes
of course i want to have this: fragment shader:
#version 450 core
in vec4 color;
out layout (location = 0) vec4 out_color;
void main ()
{
out_color = color;
}
but when i do that, the application definitely wont capture the “position” attribute anymore
(i retrieved all transform feedback varyings and the captured data to test this)
as you can see, the fragment shader does some “weird” stuff, i just added a position to “[persuade]” the compiler to not discard the variable, but that’s just for testing purposes[/QUOTE]
Hmm, ok. Since you’re doing transform feedback, why do you even have a fragment shader? I’d get rid of that (that is, only link a vertex shader into your shader program). See if the linker removes position then.
If so, you might consider using glTransformFeedbackVaryings to set the TF outputs instead of the layout qualifiers. Just be sure to call this “before” you link your program. See this: Transform Feedback (OpenGL Wiki)
i tried that –> it works!
but the thing is i want to do a kind of “buffer pingponging”
that means WHILE rendering a triangle, i want to capture the transformed vertex in buffer 2
when done, i use buffer 2 as GL_ARRAY_BUFFER and feed the vertices into the same program again, capturing every thing into buffer 1 (ping-pong)
so the point is i need the fragmentshader (beside 2 VAO, 2 VBO, 2 Xfer feedback objects)
glTransformFeedbackVaryings(…) is exactly what i want to avoid
(used it before, works perfectly)
Ok. Well as far as I know what you’re doing is fine. What GPU/driver/OS is this?
I’d suggest that you double-check the spec just to verify that your/my understanding that this is valid is correct. And assuming so, file a bug report with the company/organization that maintains the drivers you’re using.
For now I guess you can continue to use a work-around similar to what you are using, but just change the expression so it can have no real effect on the resulting color, and yet won’t allow the compiler to optimize it away.
a usual desktop pc:
– windows 10 home (x64)
– NVIDIA GeForce GT 640
– driver 369.09 (outdated)
– driver 376.19
OpenGL 4.5 core profile and GLSL 450 core
my driver 369.09 was outdated, but that doesnt matter, my example doesnt work neither with 369.09, nor with 376.19
(i’ve just installed 376.19)
triple-checked it … i dont violate any GLSL 450 core rule
i played around, used interface blocks, etc … nothing worked
(until i pass the “position” attribute to the fragmentshader and use it there anyhow)