HHHH
HHHH

Reputation: 49

How many indexes can I give the GLES20.glDrawElements function?

I want to draw an more complex object with opengl in android Studio. I have a mesh. All vertices normals and indexes are correct.

But when I come to this function GLES20.glDrawElements(mode, count, type, indices) I have the problem that when count is for example 1661 or higher the app breaks. But when count is 1381 of lower it works fine (exept for the fact that my object looks wrong).

I thought that there could be two possible reasons for that. First the number is just to high and the method has a limit on how many objects it can draw .(But I haven´t found anything aubout it and I don´t think that 1700 is such a high number of indexes!)

An other possibility is that somehow I defined the frame or space wrong in which openGl draws. I am working with Vuforia and am using the Vuforia sample project. When I put in a small count number and opengl actually draws something, it is all in a small area of the image target. But since I use the sample I have no idea where you would define something like that.

If anyone has an idea I would really appriciate!

EDIT: This is what happens in the Logcat:

D/libEGL﹕ glDrawElements(GL_TRIANGLES, 1661, GL_UNSIGNED_SHORT, (const void *) 0x899e56d0);

A/libc﹕ Fatal signal 11 (SIGSEGV), code 2, fault addr 0xe34s5654 in tid 65432 (GLThread 8537)

E/BufferQueueProducer﹕ [unnamed-] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=7 undequeued=1)

And than the last report is repeated a couple times...

Upvotes: 0

Views: 1191

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54592

There is no defined limit for the number of indices you can pass to glDrawElements(), aside from the inherent limits of the data types.

ES 2.0 supports two index types:

  • GL_UNSIGNED_BYTE, with a maximum value of 255.
  • GL_UNSIGNED_SHORT, with a maximum value of 65,535.

To be precise: The above are limits on the maximum index value, not the number of indices you can pass to glDrawElements(). So if indices are used multiple times, the number of indices could actually be higher than this limit. Still, this is what typically limits how much geometry you can draw with a single call.

If you're using GL_UNSIGNED_SHORT for the indices, you should definitely be able to use a couple of thousand indices.

The only legitimate explanation I can think of is that the device runs out of memory if the vertex data gets too large. You could try calling glGetError(), and see if you get any GL_OUT_OF_MEMORY errors. Even though, those errors tend to not be reported reliably.

Other than that, there are two possible explanations:

  1. Your code is broken.
  2. The OpenGL implementation on the device is broken.

It's impossible to tell which of the two it is without seeing the critical parts of your code.

Upvotes: 2

Related Questions