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

Author Topic: How do you bind multiple textures to the same shader?  (Read 3700 times)

0 Members and 1 Guest are viewing this topic.

Powereleven

  • Newbie
  • *
  • Posts: 36
    • View Profile
How do you bind multiple textures to the same shader?
« on: May 24, 2018, 01:03:44 am »
I am aware of
sf::Texture::bind(&texture_here);
but what if my shader requires more than 1 texture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Powereleven

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: How do you bind multiple textures to the same shader?
« Reply #2 on: May 24, 2018, 03:10:35 pm »
I was aware of that setUniform stuff too. I used them before entering my game loop to set the sampler2Ds.
But when mixing with my custom OpenGL code, the doc says:
sf::Texture t1, t2;
...
sf::Texture::bind(&t1);
// draw OpenGL stuff that use t1...
sf::Texture::bind(&t2);
// draw OpenGL stuff that use t2...
sf::Texture::bind(NULL);
// draw OpenGL stuff that use no texture...
 But what if my OpenGL stuff uses t1 and t2? It seems that t1 is unbinded if I bind t2.
« Last Edit: May 24, 2018, 03:18:29 pm by Powereleven »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How do you bind multiple textures to the same shader?
« Reply #3 on: May 24, 2018, 03:27:23 pm »
Texture::bind cannot make use of multiple texture units, so yes, each call replaces the previous texture. But depending on what your OpenGL code does, this may not be a problem.
Laurent Gomila - SFML developer

Powereleven

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: How do you bind multiple textures to the same shader?
« Reply #4 on: May 24, 2018, 03:40:03 pm »
For example, I have 2 sampler2D and mix() them in the shader. How do I solve this? ( in sfml standard functions obviously )
« Last Edit: May 24, 2018, 03:41:39 pm by Powereleven »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How do you bind multiple textures to the same shader?
« Reply #5 on: May 25, 2018, 09:20:29 am »
As I said, if it's in a sf::Shader, you can use Shader::setUniform, it will correctly handle multiple texture units.
Laurent Gomila - SFML developer

 

anything