Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use glDrawElements with GL_UNSIGNED_INT for the indices?

I'm trying to draw 3d objects that have more than 65536 vertices on the iPad, but can't figure out what I'm doing wrong. My original model that used GL_UNSIGNED_SHORT worked just fine, but now with GL_UNSIGNED_INT, I can't get anything to show up using the glDrawElements command. It's like the renderer is ignoring my glDrawElements line completely. The portion of my rendering loop that I'm referencing is below:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(assemblyObj->vertices[0])*6, &assemblyObj->vertices[0]);
glNormalPointer(GL_FLOAT, sizeof(assemblyObj->vertices[0])*6, &assemblyObj->vertices[0]);

for (int i = 0; i < assemblyObj->numObjects; i++)
{
     glDrawElements(GL_TRIANGLES, assemblyObj->partList[i].faceArray.size(), GL_UNSIGNED_INT, &assemblyObj->partList[i].faceArray[0]);
}

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

vertices is defined as:

vector<float> vertices;

and each faceArray is defined as:

vector<UInt32> faceArray;

Any suggestions on what I'm doing wrong that is preventing my geometry from drawing?

like image 206
Davido Avatar asked Dec 10 '10 22:12

Davido


People also ask

How does glDrawElements work?

When glDrawElements is called, it uses count sequential elements from an enabled array, starting at indices to construct a sequence of geometric primitives. mode specifies what kind of primitives are constructed and how the array elements construct these primitives. If more than one array is enabled, each is used.

What is the difference between glDrawArrays and glDrawElements?

With glDrawArrays, OpenGL pulls data from the enabled arrays in order, vertex 0, then vertex 1, then vertex 2, and so on. With glDrawElements, you provide a list of vertex numbers. OpenGL will go through the list of vertex numbers, pulling data for the specified vertices from the arrays.


1 Answers

Stock OpenGL ES does not support GL_UNSIGNED_INT for indices.

From the GLES glDrawElements man page:

GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.

This restriction is relaxed when GL_OES_element_index_uint is supported.

If you don't have support on the target platform, your best bet is to munge your mesh in multiple sub-meshes with < 64K indices for each.

As to ipad specifically, as far as I know, iOS does not support this extension (See Supported extensions), but you can verify the extension list on the actual device if you want to make sure.

like image 155
Bahbar Avatar answered Sep 22 '22 21:09

Bahbar