SFML community forums

General => General discussions => Topic started by: JoshuaT on June 20, 2011, 10:30:56 pm

Title: Shader::SetCurrentTexture member shadowing?
Post by: JoshuaT 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.
Title: Shader::SetCurrentTexture member shadowing?
Post by: Laurent on June 20, 2011, 10:40:13 pm
That's definitely a huge error :)

Thanks!
Title: Shader::SetCurrentTexture member shadowing?
Post by: JoshuaT 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...