简体   繁体   中英

OpenGL change varying location in separable shader program

i am trying to mix/match shaders with OpenGL's shader program pipelines. With separable programs (and thus, pipelines), varyings are matched by location rather than by name. The 'clean' solution would be to set locations from C code but i couldn't find anyway yo do that. glGetProgramResource... allow to get program output locations, but i didn't find how to set them. Is there a way to do that in core ? and if not why is it impossible ?

(Note: I haven't actually used separateable shaders; this is based off of my reading of the ARB_separate_shader_objects spec .)

ARB_separate_shader_objects requires the ARB_explicit_attrib_location extension, which adds the layout(location=N) syntax for specifying the location of vertex shader inputs and fragment shader outputs in the shader itself, which before were done with glBindAttribLocation and glBindFragDataLocation respectively. ARB_separate_shader_objects extends this to all inputs/outputs.

I didn't see a C function for setting locations (other than glBindAttribLocation and glBindFragDataLocation ), so you'll have to use layout qualifiers. Make sure you set the appropriate GLSL version/extension, and that you are using the in / out keywords and not attribute / varying .

With separable programs (and thus, pipelines), varyings are matched by location rather than by name.

This is not true.

Interface variables (what you call "varyings") may or may not be matched based on location in separate programs .

Interface variables in separate programs that have a layout(location) specified in GLSL will be matched by that location. Interface variables that do not have a location will be matched by name.

The principle difference is what happens on a mismatch. If a name doesn't have a match on the other side, this results in undefined behavior. But this results in undefined behavior for all named interface variables, not just the mismatched ones.

However, if a location doesn't match on the other side, then the location input has an undefined value, or the location output is dropped.

So you can use named matches with separate programs if you like. You just need to make sure that the match is exact . Location-based matching is for non-exact matching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM