Graou
Graou

Reputation: 140

OpenGl transform feedback with GL_SEPARATE_ATTRIBS buffer mode

I use OpenGl's transform feedback (version 3 to remain compatible with macos) to generate vertices from other vertices. In this scenario for example, the generated vertices are at least twice as numerous as the source vertices. Vertices also have colors but I would like the vertices coordinates and their associated colors to be in two separate VBOs.

Before trying to implement colors in the shader calculation looked like this:

#version 330 core

in vec3 vertex;

out vec3 v0;
out vec3 v1;

void main()
{
    vec4 var0;
    vec4 var1;

    //Implementation of calculation

    ...

    v0 = vec3(var0.x, var0.y, var0.z);
    v1 = vec3(var1.x, var1.y, var1.z);
}

And in the OpenGl implementation (Java code):

glTransformFeedbackVaryings(programId, new String[] {"v0","v1"}, GL_INTERLEAVED_ATTRIBS);

...

glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo1);

And it works very well.

But to implement color, I haven't found anything that can explain how to configure the links between output variables and their associated VBOs. so I tried passing the output variables via interface block but it does not pass to the shader compilation and gives this error message ("Could not find transform feedback binding for 'coords_out.'" and "Could not find transform feedback binding for 'colors_out.'"):

#version 330 core

in vec3 vertex;
in int color;

out COORDS_OUT
{
    vec3 v0;
    vec3 v1;
} coords_out;

out COLORS_OUT
{
    int c0;
    int c1;
} colors_out;

void main()
{
    vec4 var0;
    vec4 var1;

    //Implementation of calculation

    ...

    coords_out.v0 = vec3(var0.x, var0.y, var0.z);
    coords_out.v1 = vec3(var1.x, var1.y, var1.z);
    
    colors_out.c0 = color;
    colors_out.c1 = color;
}

And in the OpenGl implementation (Java code):

glTransformFeedbackVaryings(programId, new String[] {"coords_out","colors_out"}, GL_SEPARATE_ATTRIBS);

...

glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo1);        
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, tbo2);    

I start to believe that what I'm trying to do isn't possible while hoping I'm wrong.

Upvotes: 0

Views: 84

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473174

You're using OpenGL 3.x. Unextended transform feedback has exactly two ways to output variables to buffers: either all of them go into the same buffer (interleaved) or all of them go into different buffers (separate).

Anything else requires higher GL versions/extensions.

Putting output variables in interface blocks has no effect on how transform feedback operates. glTransformFeedbackVaryings takes the name of the output variables, and coords_out does not name a variable. It names an interface block. coords_out.c0 names an output variable.

Upvotes: 2

Related Questions