0
votes

From some examples of using OpenGL transform feedback I see that the glTransformFeedbackVaryings​ are mapped after program compilation and before it is linking.Is this way enforced for all OpenGL versions?Can't layout qualifier be used to set the indices just like for vertex arrays?I am asking because in my code shader programs creation process is abstracted from other routines and before splitting it to controllable compile/link methods I would like to know if there's a way around.

Update:

How is it done when using separable shader objects?There is no explicit linkage step.

UPDATE:

It is still not clear to me how to set glTransformFeedbackVaryings when using separate shader objects.

This explantion is completely unclear to me:

If separable program objects are in use, the set of attributes captured is taken from the program object active on the last shader stage processing the primitives captured by transform feedback. The set of attributes to capture in transform feedback mode for any other program active on a previous shader stage is ignored.

I actually thought I could activate a pipeline object and do the query.But it seem to have no effect.My transform feedback writes nothing.Then I found this discussion in Transform Feedback docs:

Can you output varyings from a seperate shader program created with glCreateShaderProgramEXT?

    RESOLVED:  No.

    glTransformFeedbackVaryings requires a re-link to take effect on a
    program.  glCreateShaderProgramEXT detaches and deletes the shader
    object use to create the program so a glLinkProgram will fail.

    You can still create a vertex or geometry shader program
    with the standard GLSL creation process where you could use
    glTransformFeedbackVaryings and glLinkProgram.

This is unclear too.Does the answer mean that to set transform feedback varyings one should use the regular shader programs only?I don't get it.

1
What version of OpenGL are you targeting? EXT extensions are notoriously out-of-synch with core OpenGL. The usual process before adopting these things into core is EXT/vendor -> ARB -> core. If you are targeting a version of OpenGL where transform feedback is core, you should stay away from the EXT extension documentation. The same way you should avoid EXT FBO in OpenGL 3.0. - Andon M. Coleman
I use GL4.2 compatible mode. - Michael IV

1 Answers

1
votes

What you are asking is possible using 4.4.2.1 Transform Feedback Layout Qualifiers, unfortunately it is an OpenGL 4.4 feature. It is available in extension form through GL_ARB_enhanced_layouts, but this is a relatively new extension and adoption is sparse at the moment.

It is considerably more complicated than any of the more traditional layout qualifiers in GLSL, so your best bet for the foreseeable future is to manage the varyings from the GL API instead of in your shader.


As far as varyings in SSO (separable shader object) programs, the OpenGL specification states the following:

OpenGL 4.4 (Core Profile) - 13.2 Transform Feedback - pp. 392

If separable program objects are in use, the set of attributes captured is taken from the program object active on the last shader stage processing the primitives captured by transform feedback. The set of attributes to capture in transform feedback mode for any other program active on a previous shader stage is ignored.

Ordinarily linking identifies varyings (denoted in/out in modern GLSL) that are actually used between stages and establishes the set of "active" uniforms for a GLSL program. Linking trims the dead weight that is not shared across multiple stages and performs static interface validation between stages and it is also when binding locations for any remaining varyings or uniforms are set. Since each program object can be a single stage when using SSOs, the linker is not going to reduce the number of inputs/outputs (varyings) and you can ignore a lot of language in the specification that says it must occur before or after linking.

Since linking is not a step in creating a program object for use with separate shader objects, your transform feedback has to be relative to a single stage (which can mean a different program object depending on which stage you select). OpenGL uses the program associated with the final vertex processing stage enabled in your pipeline for this purpose; this could be a vertex shader, tessellation evaluation shader, or geometry shader (in that order). Whichever program provides the final vertex processing stage for your pipeline is the program object that transform feedback varyings are relative to.