glDrawTransformFeedbackStream, what the stream refers to?

328 Views Asked by At

I ported this sample to to jogl from g-truc and it works, everything fine everything nice.

But now I am trying to understand exactly what the stream of glDrawTransformFeedbackStream refers to.

Basically a vec4 position input gets transformed to

        String[] strings = {"gl_Position", "Block.color"};
        gl4.glTransformFeedbackVaryings(transformProgramName, 2, strings, GL_INTERLEAVED_ATTRIBS);

as following:

void main()
{   
    gl_Position = mvp * position;
    outBlock.color = vec4(clamp(vec2(position), 0.0, 1.0), 0.0, 1.0);
}

transform-stream.vert, transform-stream.geom

And then I simply render the transformed objects with glDrawTransformFeedbackStream

feedback-stream.vert, feedback-stream.frag

Now, based on the docs they say:

Specifies the index of the transform feedback stream from which to retrieve a primitive count.

Cool, so if I bind my feedbackArrayBufferName to 0 here

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName[0]);
    gl4.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, feedbackArrayBufferName[0]);
    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

I guess it should be that.

Also the geometry shader outputs (only) the color to index 0. What about the positions? Are they assumed to be already on stream 0? How? From glTransformFeedbackVaryings?

Therefore, I tried to switch all the references to this stream to 1 to check if they are all consistent and then if they do refer to the same index.

So I modified

    gl4.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, feedbackArrayBufferName[0]);

and

    gl4.glDrawTransformFeedbackStream(GL_TRIANGLES, feedbackName[0], 1);

and also inside the geometry shader

out Block
{
    layout(stream = 1) vec4 color;
} outBlock;

But if I run, I get:

Program link failed: 1
    Link info
---------
error: Transform feedback can't capture varyings belonging to different vertex streams in a single buffer.

OpenGL Error(GL_INVALID_OPERATION): initProgram
GlDebugOutput.messageSent(): GLDebugEvent[ id 0x502
    type Error
    severity High: dangerous undefined behavior
    source GL API
    msg GL_INVALID_OPERATION error generated. <program> object is not successfully linked, or is not a program object.
    when 1455183474230
    source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31, ES32], FBO, hardware) - 4.5.0 NVIDIA 361.43 - hash 0x225c78a9]
GlDebugOutput.messageSent(): GLDebugEvent[ id 0x502
    type Error
    severity High: dangerous undefined behavior
    source GL API
    msg GL_INVALID_OPERATION error generated. <program> has not been linked, or is not a program object.
    when 1455183474232
    source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31, ES32], FBO, hardware) - 4.5.0 NVIDIA 361.43 - hash 0x225c78a9]

Trying to know what'g going on, I found this here

Output variables in the Geometry Shader can be declared to go to a particular stream. This is controlled via an in-shader specification, but there are certain limitations that affect advanced component interleaving.

No two outputs that go to different streams can be captured by the same buffer. Attempting to do so will result in a linker error. So using multiple streams with interleaved writing requires using advanced interleaving to route attributes to different buffers. 

Is it what happens to me? position going to index 0 and color to index 1?

I'd simply like to know if my hypotesis are correct. And if yes, I want to prove it by changing the stream index. Therefore I'd also like to know how I can set the position on stream 1 together with color after my changes.. shall I modify the output of the geometry shader in this way layout(triangle_strip, max_vertices = 3, xfb_buffer = 1) out;?

Because it complains

Shader status invalid: 0(11) : error C7548: 'layout(xfb_buffer)' requires "#extension GL_ARB_enhanced_layouts : enable" before use

Then I add it and I get

error: Transform feedback can't capture varyings belonging to different vertex streams in a single buffer.

But now they should be both on stream 1, what I am missing?

Moreover, what is the definition of a stream?

0

There are 0 best solutions below