Wrapping OpenGL: Is there a more general glUniform function?

I'm trying to create a Python API that wraps OpenGL in some fairly convenient ways. For example:

Code :

program.uniforms["world"] = transform.gl_matrix

Converting from Python to the appropriate C pointer is relatively easy, but the fact that there's a different glUniform* function for each and every GLSL type ... that's somewhat troublesome, because (unless there's a better way) I'll have to wrap each and every glUniform* function.

Now, I can write a script to auto-generate that wrapping, but I would really prefer something like this:

Code :

void glUniform(GLint loc, GLsizei size, GLvoid* data)

Basically, a function that would just take the data, and stuff it into the uniform (if the sizes match); something that doesn't require calling a completely different function for what is essentially a float*.

Does something like that exist, or is there some other way to do this?

Don't you have to examine the declared type of the uniform (using e.g. glGetProgramResource) and the type of the data passed in already, so that you can check if the user passed in integers or floats for vec{2,3,4}, ivec{2,3,4}, uvec{2,3,4} uniforms respectively and perform a conversion in case of mismatch? Otherwise the interface is not only convenient, but also easy to accidentally misuse

I don't mind misuse, as long as I get to cut down on the wrapper code (which is my goal in this case).

Maybe you should pay more attention to misuse. People will use your code more often than you will write it. Making an interface that is more error prone just because it's easier to write is a bad idea. You're basically trading your implementation time for the time of anyone who must debug applications written against your API.

I can virtually guarantee that no one will use my code; This is just a small hobby project, started for educational purposes. In the unlikely event that it becomes something more than that, I will endeavor to think carefully about safety issues, but for now, I just want to write a very simple implementation.

Actually, in this case, while I'm willing to sacrifice safety, I'm not actively trying to avoid it - I just don't want to have wrappers for so many different functions (all of which basically do the same thing).

I can virtually guarantee that no one will use my code; This is just a small hobby project, started for educational purposes. In the unlikely event that it becomes something more than that, I will endeavor to think carefully about safety issues, but for now, I just want to write a very simple implementation.

Basically, a function that would just take the data, and stuff it into the uniform (if the sizes match); something that doesn't require calling a completely different function for what is essentially a float*.

Does something like that exist, or is there some other way to do this?

I was looking for a function that would make those lookup tables unnecessary, but I guess it doesn't exist.

Even with explicit uniform locations there needs to be a mapping to ensure a stable interface between the application and your shader program(s). So, you'd still have a mapping which doesn't involve a name, but the semantics of the uniform, e.g. "loc_0 -> shadow map" or "loc_1 -> current time". I've only skimmed some of the above answers, but handling type mismatches becomes easier with explicit uniform locations since you know the type of the uniform you assign a location to. So you could expand the location->semantics mapping to location->(semantics, type).

Of course, these semantics may vary from program to program and IMHO, it's not that easy to establish a stable, explicit uniform interface as it is with explicit attributes.