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

Author Topic: Shader::SetCurrentTexture member shadowing?  (Read 2289 times)

0 Members and 1 Guest are viewing this topic.

JoshuaT

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shader::SetCurrentTexture member shadowing?
« on: June 20, 2011, 10:30:56 pm »
Been doing a little source diving of the latest snapshot, preparatory to tackling a new project using shaders, and in Graphics/Shader.cpp I found the function SetCurrentTexture:

Code: [Select]

void Shader::SetCurrentTexture(const std::string& name)
{
    if (myShaderProgram)
    {
        EnsureGlContext();

        // Find the location of the variable in the shader
        int myCurrentTexture = glGetUniformLocationARB(myShaderProgram, name.c_str());
        if (myCurrentTexture == -1)
            Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
    }
}


This seems a little weird to me, since the declaration int myCurrentTexture appears to shadow the member myCurrentTexture declared as part of Shader class. Thus, the result of the glGetUniformLocationARB call is discarded at the end of the scope, rather than being assigned to the member. Is this intentional? If so, it still seems weird, since no other method in the Shader class assigns to Shader::myCurrentTexture except the constructor, which inits it to -1. Yet the Shader::Bind method checks the value of Shader::myCurrentTexture before calling glUniform1iARB.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Shader::SetCurrentTexture member shadowing?
« Reply #1 on: June 20, 2011, 10:40:13 pm »
That's definitely a huge error :)

Thanks!
Laurent Gomila - SFML developer

JoshuaT

  • Newbie
  • *
  • Posts: 5
    • View Profile
Shader::SetCurrentTexture member shadowing?
« Reply #2 on: June 20, 2011, 10:46:33 pm »
Well, maybe not huge, so much as potentially annoying to find down the road. :D If I had $1 for every time I've done that...