Hi again and welcome to another 'wouldn't it be great if we'd combine two things that i really don't understand anything about'-question ;)
This Episode: OpenGL Uniforms and c++ Templates
The Idea: Wouldn't it be great if you could write a single template function to set uniforms in an OpenGL shader?
The Problem: Uniforms in shaders are set using a number of glUniform* functions. These differ in:
Type: there are several types a uniform can take. This results in different function names in OpenGL looking like: glUniform1f, glUniform1i, glUniform1fv, etc.
These could easily be 'unified' using overloading of functions. But this results in a huge amount of similiar functions.
First question: is it possible to use templates in this place? As far as i understand templates you would have to specialize for every new function. And in the end you'd have the same amount of functions like with simple overloading.
Parameter Count: The number in glUniform functions referes to the number the given parameters. There are one to 4 parameters which relates to simple values up to vectors with 4 elements.
Second question: is it possible to implement a 'dynamic' parameter count with templates?
Matrices: To make things complicated there is another class of uniform functions which send matrices but as I am not really using these I am not really interested in them.
Possibly there is no real way to simplify uniform methods ... but maybe someone can come up with a great solution using mighty templates?
Kind regards, Florian