
However, unwritten outputs will have undefined values. Output variables from the fragment shader do not have to be written. The value in the array at that index refers to a specific image in the current drawing framebuffer. The indices in the array passed to this function correspond to an output variable's assigned index. Like vertex shader inputs, fragment shader outputs are assigned indices, either explicitly by the user or implicitly by the system.Įach fragment shader output's index corresponds to a draw buffer, as defined by the current draw framebuffer's draw-buffer setting, set with the glDrawBuffers command. They must be vectors or scalars of single-precision floating-point or integer types. There are some special cases with input and output variables for different stages.įragment shader outputs cannot be matrices or boolean types. The interfaces between two shader stages must match, though not necessarily exactly. The input and output-qualified variables define an interface between this shader and the previous/next part of the pipeline. There are usually very strict limits on the number of user-defined input and output values available to each shader stage. Input/output variables can be aggregated into interface blocks. They cannot be of struct types, but they can be arrays. Variables qualified with these can be of any non- opaque basic type (though some stages have more restrictive limitations on types. And on Function Parameters, they take on an entirely different meaning. These qualifiers can not be used on local variables. This includes writes to fragment shader outputs which are masked off.

The shader must set all output variables at some point in its execution there are only two exceptions to this: These values are passed to the next stage of the pipeline (possibly via interpolation of values output from multiple shader executions). Global variables declared with the out qualifier are shader stage output variables. These variables are not constant (in the sense of const), but they cannot be changed by user code.

These variables are given values by the previous stage (possibly via interpolation of values output from multiple shader executions). Global variables declared with the in qualifier are shader stage input variables. 4.20 permits such variables to be initialized with non-constant expressions, but the variable in that case will not be a constant expression. GLSL versions before 4.20 required that all non-parameter const-qualified variables be initialized with Constant Expressions. This also means that the variable declaration must initialize the variable.įor variables that are not function parameters, const-qualified variables which are initialized by Constant Expressions are themselves constant expressions. This means that the variable's value cannot be changed after it is initialized. Global and local variables, as well as input function parameters, can be declared with the const qualifier. Local variables are scoped as with C/C++: the local scope in which they are declared. If no storage qualifier is specified for a local variable, then the variable is a local variable that can be modified. So invocations cannot communicate between each other through default-qualified global variables that would require the shared qualifier. So if you have two vertex shader objects that define int someValue, when you link them into a program, they will both be referring to the same value.Įach separate invocation of the same shader stage will refer to different versions of the same global variable. All global variables have a scope of the particular shader stage. If no storage qualifier is specified when declaring a global variable, then the variable is just a normal global variable. Storage qualifiers define where a variable's storage comes from. 1.3.3 Tessellation evaluation shader inputs.1.3.2 Tessellation control shader outputs.
