Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OGL_ES 2.0: Using multiple texture units vs rebinding textures for separate shaders

In the game that I am currently producing, I have two shaders:

  • one for sprites on a texture atlas and
  • one particle shaped texture which is loaded separately. (I decided to keep this texture out of the atlas as the particles in my generator are GL_POINTS).

Currently, I bind each one of these to a separate Texture unit and then set the uniform of each shader to the respective texture units. I find that binding the textures just once in this way is clean but was wondering if there is any reason why this is a bad method to employ.

I have searched extensively for any discussions on this method but it seems that not many people are doing this, creating doubt in my own mind as to its safety.

Has anyone used this method themselves or know of any reason why it might not be a good idea?

like image 779
niamh Avatar asked Jan 16 '26 20:01

niamh


1 Answers

Indirectly, yes, i use this method and it's safe. But it's a side effect of an optimisation at the rendering engine level.

You can (maybe) get some performance if you avoid to bind the same texture many times. In my engine, before rendering something, i bind material's textures only if it's not already bound. (efficient after sorting entities by material & texture)

Because multiple textures-unit can be used at the same time, the test is performed at texture unit level.

This optimisation worth it's cost for big scenes. (hundreds of draw calls with at least thirty textures).

In your case, because there is only two textures and two shaders, why do you try to remove some textures bindings ? Can you measure how much performance you won ? Did you sacrifice flexibility for that ?

Vivien

like image 109
Vivien Avatar answered Jan 19 '26 18:01

Vivien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!