SFML community forums

Help => Graphics => Topic started by: lezebulon on May 28, 2014, 11:19:10 pm

Title: shader keep being bound after call to draw ?
Post by: lezebulon on May 28, 2014, 11:19:10 pm
Hi
I'm trying to understand code from a library
here Sprite3d is a class derived from sf::Sprite:
 
void Sprite3d::draw(sf::RenderTarget& target, ShaderPack& shaderPack)
{
   //a texture was already set for "this"
    screen.draw(*this, &shader1);

    sf::Sprite sprite(*this);
    sprite.setTexture(heightmap);
    heightmapScreen.draw(sprite, &shader2);
}

this produces an unexpected result (for me!) where it seems that the shader1 is being called twice, the second time being during the second draw call, after shader2 is called. Is this normal?
For reference, if I do this instead:
 
void Sprite3d::draw(sf::RenderTarget& target, ShaderPack& shaderPack)
{
   //a texture was already set for "this"
    screen.draw(*this, &shader1);

    sf::Sprite sprite;
    sprite.setTexture(heightmap);
    heightmapScreen.draw(sprite, &shader2);
}
it produces a different result, and seems to call each shader 1 time, which is what I expect would have happened in the first example.

What am I missing here ? The code I'm looking at seems to be actually relying on the behavior from the 1st sample, so it's probably not a bug. I'm smelling that something is very fishy in the copy constructor of sf::Sprite but I'm unable to understand what exactly goes on... any idea?
Title: Re: shader keep being bound after call to draw ?
Post by: lezebulon on May 29, 2014, 12:11:57 am
nevermind, I figured it out and it had nothing to do with what I explain in that post.... I can't delete the topic though