OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition
by Dave Shreiner, Graham Sellers, John M. Kessenich, Bill M. Licea-Kane
GLSL Subroutine Setup
When you want to use subroutine selection inside of a shader, there are three steps required to set up the pool of subroutines:
1. Define the subroutine type using the subroutine keyword
subroutine returnType subroutineType(type param, ...);
where returnType is any valid type that a function can return, and subroutineType is any valid name. As with function prototypes, only the parameter types are required; the parameter names are optional. (Hint: Think of this like a typedef in C, with subroutineType as the newly defined type.)
2. Using the subroutineType you just defined, define the set of subroutines that you would like to dynamically select from using the subroutine keyword. The prototype for a subroutine function looks ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access