glDrawArrays

Started by
5 comments, last by quasar3d 20 years, 4 months ago
to glDrawArrays you have to pass the start index and the count, but what exactly are they? is index a byte index, or vertex index, or primitive index? And what about count, is it the vertex count, or primitive count? Every page on the internet just says it''s the starting index, and the number of indices to render (It isn''t indixed, right?) My Site
Advertisement
The vertex index and vertex count.
-Ostsol
thanks,

But if I have my vbo filled with different types of vertices, and I want to render a set of vertices, that''s preceded with vertices of a different size? Then my index can''t be correct any more, How should I do that? or shouldn''t I use different vertex formats in one vbo?

My Site
The size of a vertex is defined by the stride parameter in the gl*Pointer functions. As such, the location of each index will be based on that stride. The starting index (element zero) of the array will be wherever you set it to be via the last parameter in the gl*Pointer functions and further vertices will be at location (start + stride * index).

Since you're using VBO, though, I really suggest you use multiple buffers rather than just one. That way you don't have to worry about setting the correct offset for a certain group of vertices in your array. You can just render from the start of each buffer. I suppose the advantage of using a single buffer in the past was that one could lock the entire thing in server-side memory via compiled vertex arrays, but with VBOs that's no longer necessary. For my own implementation, I have a separate buffer for each unique mesh I create.

[edited by - Ostsol on November 30, 2003 2:23:30 PM]
-Ostsol
Ok, I will use a single buffer for each vertex type then.

It''s not totally clear though. With that gl*Pointer functions you can set a system memory pointer (which you got with new or so), and you can also set a null based pointer, which then will be an index in the currently binded vbo, right? How does ogl know which one I mean, how does it know if it''s an offset in the vbo, or if it''s a memory pointer? I guess I''ve to set some states, but I don''t see one in the examples I''ve seen.

Also, if I use those gl*Pointer functions, are they then saved for that vbo? so if I bind that vbo again, do I have to set all those pointers again?

My Site
With VBOs you set the data using glBufferDataARB (after having generated a buffer via glGenBuffersARB). After that you can even delete the original source data, if you want, as it will be stored in server-side memory (either video memory or AGP memory) until you destroy that buffer object.

With standard OpenGL vertex arrays, the last parameter in the gl*Pointer functions is the location of the first element of the array in system memory. With VBOs, it is the offset from zero to the first element in the array.

OpenGL can tell if you are using the gl*Pointer functions for VBOs or not by checking to see if you''ve bound a vertex buffer or not. If you haven''t, or if buffer number zero is bound, it''ll assuming that you''re using standard vertex arrays and that last parameter is a location is system memory.

Have you taken a look at the VBO spec? At the end, it has some nice examples on its basic use with comparisons to standard vertex arrays.

http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_buffer_object.txt

NVidia has also posted a document on VBOs on their website. I haven''t taken a look at it myself, but I heard that it''s very helpful.

http://developer.nvidia.com/object/using_VBOs.html
-Ostsol
thanks a lot. That nvidia paper is exactly what I need!

My Site

This topic is closed to new replies.

Advertisement