SFML community forums

General => Feature requests => Topic started by: Ant on July 08, 2016, 10:12:45 am

Title: Check if Shader Parameter Exists
Post by: Ant on July 08, 2016, 10:12:45 am
I think having the capability to check which uniform(s) exists on a Shader may help reduce the amount of micromanagement.  For example, I can create a wrapper of sf::Shader, and that wrapper can check for specific uniform names and act accordingly.  If the uniform named 'GlobalTime' or 'DeltaTime' exists on shader, I can have the shader wrapper automatically update those variables every frame.  It gets trickier when I need to associate a texture mask that's based on the current animation frame.  Having this functionality implemented in a wrapper class may reduce the need of external objects updating every shader they instanced.

I'm requesting for a bool CheckParamExists function defined in the sf::Shader class.
Title: Re: Check if Shader Parameter Exists
Post by: Mr_Blame on July 08, 2016, 10:56:37 am
What do you mean under micromanagement?
Title: Re: Check if Shader Parameter Exists
Post by: Laurent on July 08, 2016, 11:09:43 am
There's a possible implementation of this that could bring another useful feature to sf::Shader: resolving uniform locations in advance rather than on first call to setUniform.

Here is a draft to show the idea:

struct UniformLocation
{
    UniformLocation(std::string name);

    std::string name;
    int index;
    bool resolved;
};

UniformLocation Shader::getUniformLocation(std::string name)
{
    // glUniformLocation
}

Shader::setUniform(UniformLocation location, xxx value)
{
    // use location.index if already resolved,
    // or resolve location.name otherwise (old behaviour)
}

Thanks to the implicit constructor of UniformLocation, we don't break the previous API (ie. we can still call shader.setUniform("name", value)).

Note that we can still use the internal cache, or remove it since now user has explicit control on uniform location resolution.
Title: Re: Check if Shader Parameter Exists
Post by: fallahn on July 08, 2016, 08:34:39 pm
I strongly second this, as it would more easily enable me to map uniform locations to other values, and save on having to do frequent string lookups.