PDA

View Full Version : Problem of maximum vertices with glDrawelements



Paras_wolf
04-01-2011, 03:25 AM
Hi, I am working on water surface simulation and I am using glDrawELements() for laying my triangular mesh.

The problem is, maximum vertices the code works is 62500(i.e when I lay a 250x250 grid). If I increase the grid size above this for eg 260x260 or 300x300 the grid gets stripped for right side and only 62500 vertices are drawn. Also the grid appears not laid properly.

link for 250x250 grid simulation image:
http://www.flickr.com/photos/37679557@N03/5579269742/

link for 350x350 grid simulation image:
http://www.flickr.com/photos/37679557@N03/5579270484/

I am using GL_TRIANGLES for putting the triangles. I have used the query command
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);

which gives the output 1048576, and the max i can use is 62500 so I can still increase lot of vertices.

I had googled about this problem but all I found was to use GL_MAX_ELEMENTS_VERTICES and act accordingly. following is part of my code:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glNormalPointer(GL_FLOAT, 0, normals);
glTexCoordPointer(2,GL_FLOAT,0,tex);
glVertexPointer(3,GL_FLOAT,0,vertices);
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);

glDrawElements(GL_TRIANGLES,6*(n-1)*(n-1),GL_UNSIGNED_SHORT,indices);

glDisableClientState(GL_VERTEX_ARRAY);


where 'n' is the height or width of square grid.

Thanks in advance.

tksuoran
04-01-2011, 03:30 AM
With GL_UNSIGNED_SHORT you are limited to 16 bit indices, so your indices are probably wrapping around after 65535. I suggest you try GL_UNSIGNED_INT and prepare your indices accordingly.

Alfonse Reinheart
04-01-2011, 03:32 AM
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);

These are constants. They don't change. Also, they mean absolutely nothing for what you're doing. They are for glDrawRangeElements, which is not a function you are using.


glDrawElements(GL_TRIANGLES,6*(n-1)*(n-1),GL_UNSIGNED_SHORT,indices);

Your indices are shorts. Shorts take up only 16-bits. They can only represent numbers from 0 to 65535. If you have more than 256x256 vertices, then you will need more than 65536 indices. You must store integers in your index array, not shorts.

Paras_wolf
04-01-2011, 04:00 AM
That solves the problem, thanks a lot.