开发者

About the texture switch in OpenGLES

开发者 https://www.devze.com 2023-01-06 18:55 出处:网络
When the texture is switched, why is the speed slow? Code - 1  glBindTexture(GL_TEXTURE_2D,texId01);  glDrawArray(glDrawArrays(GL_TRIANGLES, 0, 4);

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);

 glDrawArra开发者_开发技巧y(GL_TRIANGLES, 0, 4);

 glDrawArray(GL_TRIANGLES, 0, 4);


Why are these speeds different?


The upvoted answer is wrong for OpenGLES on PowerVR hardware, apparanty, and perhaps others. I came across this "texture binding is slow" myth on a few occasions already, but none of the performance docs (Apple's or Imagination Technologies) mention anything about this.

So I checked this with Imagination Technologies directly, and their answer is:

Using glBindTexture shouldn't make any difference in performance besides what we've mentioned in our documentation, there is a small overhead but not a huge one. Some information out there seems to mention texture switching when using glTexture2D to reload textures which IS a slow call and should only be done when first initialising the app


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.


Shiva, bhai sun .. I know you are upto some game in gles

why you have to ask such questions,... will you be able to optimize anyhow if it is really slow , like slow because of driver etc ..?

try using single large texture use seperate buffer objects to store the coordinates of each image you want to use in this texture, that is it... even if texture switch is slow, you are still ahead because you are using single texture and the fact that you used buffers...

0

精彩评论

暂无评论...
验证码 换一张
取 消