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
1 : Yes, and yes, but at least when the compiler complains that it can't choose between float and double overloads, you can force him very simply, ie setUniform<float>(blah)
instead of setUniform(blah)
2 : This time overloading is a simpler solution :)
3 : What is the question ?
The question is, why would you want to do such a thing ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With