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?