degenerated vertices and GL_LINE_STRIP

倾然丶 夕夏残阳落幕 提交于 2020-01-04 06:33:57

问题


I'm on iOS 5.1

I was trying to display several batch of lines in the same vertex array and I wanted to separate them using degenerated vertices. But it does not seem to work. I line is drawn between each batch of vertices.

Googling the problem gave me results that degenerated vertices was not compatible with GL_LINE_STRIP but I'm not really sure about it. Can someone confirm that? And also what's the alternative ?


回答1:


As far as I know, you can only draw a continuous line using a single vertex array and GL_LINE_STRIP. The alternative is to use GL_LINES, which treats each vertex pair as an independent line segment. To get a contiguous line, duplicate the last vertex of the previous segment as the start of your next segment in your vertex array.




回答2:


One possibility that may come to your mind would be to use vertices with some strange values (like infinity, or a w of 0), but those will most probably just get rendered as normal points at some crazy distance away (and thus you get weird clipped lines). So this won't work generally.

When drawing triangle strips, you can use degenerate triangles to restart the strip. This works by duplicating a vertex (or better two consecutive ones), which then results in a triangle (or better four) that degenerates to a line and thus has zero area (and is not drawn). But lets look at a line strip. When duplicating a vertex there, you get a line that degenerates to a point (and is thus not drawn), but once when starting the next line strip, you have to get a new vertex and since two distinct vertices always make a valid line, you see that by duplicating vertices you cannot get a line strip restart.

So there is no real way to put multiple line strips into a single draw call using degenerate vertices (though modern desktop GL has other ways to do it). The best idea would probably be to just use an ordinary line set (GL_LINES), as Drewsmits suggests. Ok, you will approximately double the number of vertices (if your strips are very long), but the less driver overhead from the batching may possibly outweight the additional memory and copying overhead.




回答3:


Whereas you can't use degenerate vertices in a line strip, you can use a primitive restart index (usually the maximum index value possible for the numeric type), also called a strip-cut index in Direct3D parlance. It can be configured using glPrimitiveRestartIndex.



来源:https://stackoverflow.com/questions/9685516/degenerated-vertices-and-gl-line-strip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!