Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBO worse then GL_TRIANGLE_STRIP?

Tags:

c++

opengl

for learning purposes I decide to draw a sphere using 3 methods

  1. Display List
  2. Voa Vbo (GL_TRIANGLE_STRIPE)
  3. Vao Vbo and Ibo (GL_TRIANGLES)

I read that using ibo makes program runs faster, but is this really true? For a sphere of 100 slices and 100 stacks 2nd method produces 40400 vertices while 3rd "only" 19802.By doing that I save 20598vertices each 32bytes = 659136 bytes.

  1. verticesSize=(slices*4)*(stacks+1);

  2. IBO verticesSize=(slices*2)*(stacks-1)+2;

However I need to make array of indices which in this case is a size of 118800(number of indexes needed to create all faces)*4(size of unsigned int)=475200 bytes! While 2nd methods renders 1000 spheres with 15fps ,the 3rd renders 1000 with barely 6pfs

  1. Does converting indices array from GL_TRIANGLES to GL_TRIANGLE_STRIP will provide more efficiently method then 2nd method?
  2. Does rendering sphere using ibo is bad idea?
  3. Why it is slower?Does the order in indices array have any matter?

Or maybe I wrote my code completely wrong and that why it struggles so much :( If someone is interested ,here is my code http://pastebin.com/raw.php?i=74jLKV5M

like image 281
user1075940 Avatar asked Sep 19 '12 12:09

user1075940


1 Answers

The glDrawElements call is wrong. The count parameter should be the number of indices, not the number times 4. Try changing that.

Using indices instead of triangle strips should almost always be faster. In fact I wouldn't be surprised if the driver was using indices behind the scenes to render triangle strips as well.

Also as I mentioned in the comments, the order in which you have your indices can impact the performance. However for your sphere, the indexing pattern you are using is probably the most optimal, and even so, the difference it makes is small.

like image 140
Hannesh Avatar answered Sep 24 '22 16:09

Hannesh