I am attempting to call one of many functions based on the value of a variable. The variable is set during runtime, so code on the CPU will not work. Using an if/switch statement will be slow due to the large number of possibilities.[probably incorrect]
I am looking for a way to store the functions in an array, either by using function pointers, or by storing the actual equations (e.g. texcoord.x*2) in an array.
Example psuedo-code:
in vec2 texcoord;
out vec4 color;
int number; //Assigned a number between 0 and 300 during runtime
float func1(void) {
return texcoord.x + texcoord.y;
}
float func2(void) {
return texcoord.x*2;
}
...
float func299(void) {
return texcoord.y - 7;
}
void main(void) {
number = <something calculated during runtime>;
float output = func<number>(); // <--------------
color = vec4(output, output, output, 1);
}