When drawing instanced in OpenGL, attribute divisor can be set only to 255 as maximum value, so to combine big mesh I have to separate into several instances. I need to understand more about divisor in OpenGL, does maximum limit depend on driver/GPU or it's always 255 on every devices ?
-
The spec doesn't mention a maximum, so I guess that every value that fits in a `GLuint` is valid. It's either a bug in the drivers or in your code. Please show the code. – Yakov Galka Feb 26 '17 at 08:44
-
I know about instancing and how divisor will help me to traverse data on vertex_buffer_object. It works fine when I want a transform be passed to each n instance (n from 1 to 255), but when I want a transform be passed to more, 256 instances, then it renders like a noise fan in screen. – Manh Feb 26 '17 at 09:37
-
It sounds like a bug in your code, as if you used a wrong datatype somewhere. – Yakov Galka Feb 26 '17 at 09:55
-
thanks I defined divisor as unsigned char, now it works flawlessly. – Manh Feb 26 '17 at 10:33
-
@Manh: Why would you want multiple instances to be given the same per-instance data? That seems... counter-productive. – Nicol Bolas Feb 26 '17 at 15:27
-
@NicolBolas I want to reduce number of draw calls to gpu as low as possible. my VAO is built from 1 vertex_buffer with 3 floats to index vertex (gl_VertexID does not work for me on some device), 1 vertex_buffer for transform (divisor = 320), 3 vertex_buffer for position(divisor = 1), 3 vertex_buffer for normal(divisor = 1), 1 vertex_buffer for color(divisor = 1). This mean 1 transform matrix will be passed to 320 triangles which I can manage position, normal, colors. – Manh Feb 26 '17 at 19:30
-
I'm not sure if it's not good approach but with 1 draw call I can msaa >50k triangles with 60fps on iphone. – Manh Feb 26 '17 at 19:37
-
@Manh: As I suspected, you have misunderstood how instancing works. See my answer. – Nicol Bolas Feb 26 '17 at 20:01
1 Answers
You misunderstand how the divisor and instance arrays works.
Instancing means rendering the same mesh multiple times, providing different per-instance data like transformations and so forth. Instance arrays are one way to provide per-instance data.
The divisor is not a divisor of the vertex count. It's a divisor of the instance count. And thus, it only actually does something useful if you use instanced rendering.
If the divisor is zero, then no instancing happens for that attribute. If the divisor is 1, then the attribute will be the same for all vertices within an instance, but the next instance will get the next value. If the divisor is 2, then the first two instances will get the same value, but the next two will get a different one. And so on.
Unless you're doing something very special with instancing, then your divisor should be either 0 or 1. It should never be based on the vertex count.

- 449,505
- 63
- 781
- 982
-
with 320 triangles and I can combine a lot different models in the same VAO, the good thing I see is I can manage vertex, normal, color of these models, which mean with many instances I can reach a complex dynamic scene with one or several draw call and low overhead of transferring data to gpu. – Manh Feb 26 '17 at 20:09
-
@Manh: I cannot decipher what you're saying. You sound like you're rendering multiple *different* models through a single instanced draw call, rather than the same model in different places. But that is *impossible*. So either you're not correctly explaining what you're doing, or you're not doing what you think you're doing. – Nicol Bolas Feb 26 '17 at 20:22
-
I made it possible. what I do is see the model with 80 triangles is the same as the models with 100 or 120 triangles ... – Manh Feb 26 '17 at 20:27