Laurent Crivello
Laurent Crivello

Reputation: 3931

Vertices limitation in OpenGL

I have an OpenGL scene with thousands of vertices and would like to pass them as VBOs/IBOs. Executing the glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices) command reveals a limitation of 2048 max amount of vertices, despite the fact I have a recent video card. In addition to that, an array in C is limited to an int, hence 32k vertices max.

How can I work around these limitations to anyway display all my objects ?

Upvotes: 3

Views: 5970

Answers (3)

Christian Rau
Christian Rau

Reputation: 45948

The GL_MAX_ELEMENTS_VERTICES constant only applies to the glDrawRangeElements call and even then values larger than that will surely not make glDrawRangeElements slower than glDrawElements. It is not a good idea to manually split your batches into smaller parts, as batches should be as large as possible and draw calls as few as possible. Just forget about this value, it has no real meaning anymore.

And by the way, I'm quite sure your int can hold values much larger than 32k, as on modern platforms (at least those with a graphics device that supports VBOs) an int should be at least 32bits wide (and therefore be able to hold values like 2G/4G). Although on an embedded device (using OpenGL ES) you might still be limited to 16bit vertex indices.

Upvotes: 5

Louis Ricci
Louis Ricci

Reputation: 21086

Divide your total number of vertices by 2048 and create than many VBOs

void glGenBuffersARB(GLsizei n, GLuint* ids)

So n would be (total / 2048)+1 and ids would be a GLuint array containing (total / 2048)+1

Upvotes: 1

Rupert Swarbrick
Rupert Swarbrick

Reputation: 2803

Doesn't GL_MAX_ELEMENTS_VERTICES just tell you the most vertices that can be passed to a single call of glDrawRangeElements? Is there a reason you can't split your scene into bits and render the bits one by one?

Upvotes: 2

Related Questions