Shader Subroutine

From OpenGL Wiki
Revision as of 03:35, 29 August 2013 by Alfonse (talk | contribs) (General outline and categorization.)
Jump to navigation Jump to search
Shader Subroutine
Core in version 4.6
Core since version 4.0
Core ARB extension ARB_shader_subroutine

Shader Subroutines are special GLSL functions which can have variations. The specific variation that will be called is selected by the OpenGL code.

The general idea is as follows. The shader defines some number of special functions, each of which uses the same function signature. Each such function is called a "subroutine". Each subroutine is associated with one or more "subroutine types". The type represents a specific aggregation of subroutines that could be called, a specific list of variations.

Once a subroutine type is defined, the shader can declare one or more global "variables" of that type. Each variable represents . Because these are set from OpenGL code before rendering type, these are called "uniform"s (though they do not work like regular uniforms in almost any way). Each variable represents a specific, user-defined selection from among the possible subroutines in a subroutine type. The shader code can call these subroutine uniforms as though they were functions.

The user can query indices and locations for subroutines, types, and subroutine uniforms. These queries allow the user to specify which subroutines are used in which subroutine uniforms.

Note: This specification must happen every time the current program or program pipeline object binding is changed. This is not program object state, and the context will destroy this state after each new binding.

Definition

Subroutine uniforms

Calling

Runtime selection

Limitations