In GLSL, is it legal for a function to read from an out
argument, after it has already written to it?
For example
void f(out float x) {
x = ...
x = sqrt(x);
}
Or is it needed to write it as
void f(out float output_x) {
float x = ...
output_x = sqrt(x);
}
It seems to work correctly when testing, but the specification seems to say nothing specifically about this. (only "Evaluation of an out parameter results in an l-value that is used to copy out a value when the function returns.")
the specification seems to say nothing specifically about this. (only "Evaluation of an out parameter results in an l-value that is used to copy out a value when the function returns.")
That's really all it needs to say.
in
/out
/inout
are all about how the parameters get initialized when the function is called and are used when the function concludes. What happens in the middle doesn't care about these qualifiers.
An in
or inout
parameter gets a copy of a value from the argument at the time of the function call. An out
or inout
parameter has its value copied to the argument when the function returns. The value of out
qualified parameters is undefined at the start of the function. That's it; those are the only things these qualifiers do. The variable can otherwise be used as you like.