Sign in to follow this  

Compile time shader variable name resolution?

This topic is 3292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In an OpenGL program I'd like to have uniform and attribute handles that I access by name; most implementations I've seen use a hash to map a name string to the handle. I don't want to do this since it makes no sense when the information is there at compile time. Is there some template metaprogramming trick or something with enums I can do to have named uniform/attribute handles?

Share this post


Link to post
Share on other sites
You'd have to write a scanner/parser for whatever shading language you're using, then enumerate the atrributes/uniforms as they appear in the shader. However, this is a nontrivial task if you are not familiar with parsing and context-free grammars.

Additionally, usually a detail such as how uniform and attribute handles are enumerated is going to be an implementation detail, not guaranteed to be consistent across platforms. Thus, you run the risk of compatibility problems if you attempt to do the graphics' driver's job for it.

I highly doubt that the time investment needed to do this/risks involved are attractive to most programmers and so most just opt for the easy and natural solution you already mentioned.

Share this post


Link to post
Share on other sites
I don't mean to automatically retrieve them from the shader source, but simply to be able to refer to them by names (manually entered) in the C++ program, as opposed to say indexing into a vector<GLuint> member of my shader class.

Share this post


Link to post
Share on other sites

This topic is 3292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this