Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Check if Shader Parameter Exists  (Read 3973 times)

0 Members and 1 Guest are viewing this topic.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Check if Shader Parameter Exists
« 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Check if Shader Parameter Exists
« Reply #1 on: July 08, 2016, 10:56:37 am »
What do you mean under micromanagement?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Check if Shader Parameter Exists
« Reply #2 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.
« Last Edit: July 08, 2016, 11:13:36 am by Laurent »
Laurent Gomila - SFML developer

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Check if Shader Parameter Exists
« Reply #3 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.

 

anything