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

What is the vertex limit number of glDrawArrays?

Started by akira32 Oct 22, 2011 at 9:42 AM 3 replies 10.8k views
Original Post
akira32
akira32
What is the vertex limit number of glDrawArrays? Should I divide two parts when I want to draw the vertices over 65535?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
L. Spiro
L. Spiro
You should be aware that that function asks you for the type of the indices.
If you specify GL_UNSIGNED_SHORT, then of course you are limit is 65,536 vertices.
However, if you specify GL_UNSIGNED_INT, your limit is 4,294,967,296 vertices, which is far more than is ever possible for you to create.

In general, people make wrappers around the OpenGL functions instead of calling them directly.
If you make a wrapper class that encapsulates an index buffer, you will be able to automatically switch between GL_UNSIGNED_SHORT and GL_UNSIGNED_INT.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
akira32
akira32
Thanks. Another problem, how do I set the vertex limit to 4,294,967,296? Use which function?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
samoth
samoth
Careful, there are two limits. The first, obvious hard limit as pointed out by YogurtEmperor.

The second is a soft limit denoted by GL_MAX_ELEMENTS_VERTICES. You can draw more than this limit, but an implementation is not required to perform at maximum possible speed (and some will not).

Note that this limit is not documented for glDrawArrays, but it is well-documented for glDrawRangeElements, which performs an almost identical operation (with indices in addition to a range). Both functions must lock a range of vertices to draw them, and the amount of vertices the driver can lock is obviously finite. It is therefore reasonable to assume that the same limit applies to both draw calls.
V-man
V-man

Careful, there are two limits. The first, obvious hard limit as pointed out by YogurtEmperor.

The second is a soft limit denoted by GL_MAX_ELEMENTS_VERTICES. You can draw more than this limit, but an implementation is not required to perform at maximum possible speed (and some will not).

Note that this limit is not documented for glDrawArrays, but it is well-documented for glDrawRangeElements, which performs an almost identical operation (with indices in addition to a range). Both functions must lock a range of vertices to draw them, and the amount of vertices the driver can lock is obviously finite. It is therefore reasonable to assume that the same limit applies to both draw calls.


The only thing that I have seen is that GL_MAX_ELEMENTS_VERTICES applies to glDrawElements and glDrawRangeElements (and perhaps glMultiDrawElements).
glDrawArrays doesn't have a limit. It is possible that the driver does some yo-yo and juggling behind the scene that causes performance loss if you send too many vertices but there is nothing in the GL specification about limits.
21st Century Moose
21st Century Moose

The only thing that I have seen is that GL_MAX_ELEMENTS_VERTICES applies to glDrawElements and glDrawRangeElements (and perhaps glMultiDrawElements).
glDrawArrays doesn't have a limit. It is possible that the driver does some yo-yo and juggling behind the scene that causes performance loss if you send too many vertices but there is nothing in the GL specification about limits.


True that OpenGL itself doesn't specify a limit, but you can bet that the hardware does. Generally, keeping under 64k seems a good idea to me (split your draw calls if you need to go over) but if you're targetting more modern hardware you should be easily able to go higher.

It's worth noting that the documentation and spec for many of these older functions was originally written in pre-hardware T&L days, and has had minimal updating since. Factors such as hardware limits on that part of the pipeline didn't even exist back then.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

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

Sign in to reply to this topic.