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

Author Topic: shader keep being bound after call to draw ?  (Read 1318 times)

0 Members and 1 Guest are viewing this topic.

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
shader keep being bound after call to draw ?
« 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?
« Last Edit: May 28, 2014, 11:54:09 pm by lezebulon »

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: shader keep being bound after call to draw ?
« Reply #1 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

 

anything