March 2013
Intermediate to advanced
984 pages
26h 18m
English
While GLSL allows you to define functions in shaders, the call flow of those functions was always static. To dynamically select between multiple functions, you either created two distinct shaders, or used an if-statement to make a run-time selection, like demonstrated in Example 2.5.
Example 2.5. Static Shader Control Flow
#version 330 corevoid func_1() { ... }void func_2() { ... }uniform int func;void main(){ if (func == 1) func_1(); else func_2();}
Shader subroutines are conceptually similar to function pointers in C for implementing dynamic subroutine selection. In your shader, you specify a subroutine type and use that type when declaring the set of subroutines eligible for dynamic use. Then, you choose ...