bobobobo
bobobobo

Reputation: 67346

Can you pass a matrix by reference in a GLSL shader?

How do you pass by reference in a GLSL shader?

Upvotes: 16

Views: 12186

Answers (2)

bobobobo
bobobobo

Reputation: 67346

Edit: This answer IS COMPLETELY WRONG as noted by @AnOccasionalCashew below

leaving it here to not break the thread


You can mark an attribute as inout in the function signature, and that will make the attribute effectively "pass by reference"

For example,

void doSomething( vec3 trans, inout mat4 mat )

Here mat is "passed by reference", trans is passed by value.

mat must be writeable (ie not a uniform attribute)

Upvotes: 13

Jolly Roger
Jolly Roger

Reputation: 1134

All parameters are “pass by value” by default. You can change this behavior using these “parameter qualifiers”:

in: “pass by value”; if the parameter’s value is changed in the function, the actual parameter from the calling statement is unchanged.

out: “pass by reference”; the parameter is not initialized when the function is called; any changes in the parameter’s value changes the actual parameter from the calling statement.

inout: the parameter’s value is initialized by the calling statement and any changes made by the function change the actual parameter from the calling statement.

So if you don't want to make a copy, you should use out

Upvotes: 2

Related Questions