views:

46

answers:

1

When the texture is switched, why is the speed slow?


Code - 1

 glBindTexture(GL_TEXTURE_2D,texId01);

 glDrawArray(glDrawArrays(GL_TRIANGLES, 0, 4);

 glBindTexture(GL_TEXTURE_2D,texId02);

 glDrawArray(glDrawArrays(GL_TRIANGLES, 0, 4);


Code - 2

 glBindTexture(GL_TEXTURE_2D,texId01);

 glDrawArray(GL_TRIANGLES, 0, 4);

 glDrawArray(GL_TRIANGLES, 0, 4);


Why are these speeds different?

+3  A: 

Because the driver must do some internal validations, to check that everything is as expected, so binding a texture is a expensive operation.

With that in mind, you should minimize texture binding operations. A common way of doing it is sort primitives by texture (and shader also, if GL ES 2.0) when drawing.

Matias Valdenegro
Oh, I see.I was switching many times.I take care next time.Thanks!
Shiva