I’m using drawArrays(), with mode LINE_STRIP to draw a polyline. So far, so good - everything works.
I actually have a number of polylines that I want to render in batch.
However, it’s not clear to me what data I should be binding for the drawElements call.
I assume that, at least, I need to have a bound buffer containing the concatenated coordinates of all the polylines I’m drawing.
However, what should the element array buffer contain? Subsequent pairs of start/end indices? Is bulk/batched polyline drawing even supported at all?
I managed to solve this one myself.
Populate the vertex buffer with all the points from all the polylines.
Then populate the index buffer with pairs of indices (single lines), each connecting a pair of points.
It seems not very elegant, but I guess it beats having to make thousands of separate draw calls.
Actually that is a very good approach. In OpenGL 3, there is a feature called primitive restart, which allows you to assign an index value that terminates a primitive and starts a new one. This allows you to draw disconnected polylines using LINE_STRIP, so it saves some index data and is, arguably, cleaner. We may or may not see this feature make its way into OpenGL ES / WebGL.
Hi…is there any function like primitive restart for webgl.i need because it may not be very elegant to use index buffer instead of line_strip for drawing polylines