niamh
niamh

Reputation: 33

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:

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?

Upvotes: 3

Views: 350

Answers (1)

Vivien
Vivien

Reputation: 787

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

Upvotes: 1

Related Questions