Skip to main content
GameDev.net gamedev.net
🔒 Locked

[OpenGL ES] Using glDrawElements with Integer index data

Started by regnar Dec 20, 2010 at 2:00 AM 5 replies 8.8k views
Original Post
regnar
regnar
Hello!
I was happily using glDrawElements with GL_UNSIGNED_SHORT index data for my index buffer rendering until I had to index terrain mesh larger than 256*256 vertices.
But it turned out that OpenGL ES doesn't support GL_UNSIGNED_INT index data. How do I solve this problem now?
Say, I want to index a mesh with 1024*1024 vertices. If I sub-divide this into smaller index buffers (like 256*256), it means I will have to create 16(!) index buffers just for that one mesh. Sounds really bad to me.
lancemao
lancemao
Sorry I` m not an expert.
How about use glDrawArrays ?
regnar
regnar
Could be an option, but you can not pass index data to glDrawArrays, only vertex data.

In case anyone else has this problem, I've searched the web and found that usually it is recommended to create multiple vertex buffers with no more than 65 536 vertices per buffer.
Other option could be to use one large vertex buffer, but to separate data into multiple index buffers, where you index no more than 65 536 vertices per buffer. And then, when rendering, just use different parts of that vertexbuffer by shifting pointer to "first" vertex (using glVertexPointer). For example:

vertex buffer: [v1,v2,v3,v4,v5,v6,..v131071]
index buffer 1: [0,1,2,...65535]
index buffer 2: [0,1,2,...65535]

Render all vertices:
glVertexPointer(3, GL_FLOAT, sizeof(myVertexStruct),0);
glDrawElements(index buffer 1);

glVertexPointer(3, GL_FLOAT, sizeof(myVertexStruct),sizeof(myVertexStruct) * 65536);
glDrawElements(index buffer 2);
21st Century Moose
21st Century Moose
You can use a single index buffer as well; it's perfectly possible to create a GL_UNSIGNED_SHORT buffer with more than 65536 elements in it and pass different buffer offsets to your glDrawElements call.

You'll probably want to switch from glDrawElements to glDrawRangeElements (if it's supported by your implementation).
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
regnar
regnar
Quote:
Original post by mhagain
it's perfectly possible to create a GL_UNSIGNED_SHORT buffer with more than 65536 elements


No, no, the problem was that you can only index vertices from 0-65535, because of unsigned short data type limit. And glDrawRangeElements unfortunately is not supported.
21st Century Moose
21st Century Moose
Quote:
Original post by regnar
Quote:
Original post by mhagain
it's perfectly possible to create a GL_UNSIGNED_SHORT buffer with more than 65536 elements


No, no, the problem was that you can only index vertices from 0-65535, because of unsigned short data type limit. And glDrawRangeElements unfortunately is not supported.


unsigned short *data;data = (unsigned short *) glMapBuffer (GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);data[262144] = 27;glUnmapBuffer (GL_ELEMENT_ARRAY_BUFFER);glDrawElements (GL_TRIANGLES, 127, GL_UNSIGNED_SHORT, (void *) (262143 * sizeof (unsigned short)));

Easy as pie. ;)
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Brother Bob
Brother Bob
Quote:
Original post by mhagain
Quote:
Original post by regnar
Quote:
Original post by mhagain
it's perfectly possible to create a GL_UNSIGNED_SHORT buffer with more than 65536 elements


No, no, the problem was that you can only index vertices from 0-65535, because of unsigned short data type limit. And glDrawRangeElements unfortunately is not supported.


*** Source Snippet Removed ***
Easy as pie. ;)

His problem is not to create an index array with more than 64k indices; it is to create an array whose indices are larger than 64k so he can reference vertices beyond his 256x256 patch.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.