LDraw.org Discussion Forums

Full Version: Drawing conditional lines
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm using OpenGL for LDForge's renderer and I'm about stumped on to decide when to draw conditional lines. Actually rendering the part is no problem but how does a GL renderer take the control points into account?

For compiling objects glGenLists/glNewList/... is used and glCallList for drawing them. While it's not the most optimized approach, it works for something as simple as a single part.. at least for the simple ones. I've been considering using VBOs though.
LDView computes which conditional lines to draw completely on the CPU. (It does so in background threads on computers with more than 1 CPU core.) Once it has calculated the indices of the "active" conditionals for a given frame, it draws them with glDrawElements(). You definitely don't want to use display lists for the conditional lines.
This issue (including its friend at POVray) makes me chuckle. I find it quite funny that it's easier to make a 'true 3D' render on a GPU than a classic wireframe.

Tim
Ah, bah... guess I'll have to keep drawing them as dashed lines for a while. GL is too headache-inducing to go after this.

Thanks anyway.
It's worth mentioning that there are algorithms out there for GPU-accelerated outlining. These would probably work fine with LDraw parts (although they might require BFC in order to work right). However, I believe they would involve ignoring the conditional lines in the file, and using various tricks in the GPU to come up with the outline, so I'm not sure they would work with multi-colored edge lines.
The main, perhaps only, reason for actually drawing conditional lines in LDForge is quickly previewing them so that the author could confirm that the conditional lines would behave properly, thus they'd have to be drawn exactly like the LDraw spec says.
If LDForge only deals with parts, then calculating the conditionals every frame on the CPU isn't ever going cause a performance problem (even if you don't bother to try to optimize with multi-threading). Even with the 48x48 baseplate, LDView gets 480FPS with conditional lines enabled on my computer (and around 2000 with them disabled).

Mind you, calculating which ones to draw is a pain. However, because of this, the code inside LDView that calculates whether a particular conditional should be drawn is well-commented. You're welcome to copy it if you want. Take a look at TREShapeGroup:ConfusedhouldDrawConditional() here:

http://ldview.cvs.sourceforge.net/viewvc...iew=markup

Note: I think Don Heyse gave me the initial code that the LDView code is based on.
It's pretty trivial to do with a vertex-shader (or geometry-shader on newer OpenGLs). All calculations are handed off to the GPU, and are done on-the-fly at render-time, which means you can stick all the optional-lines in display-lists or VBOs without having to worry about which ones will eventually be visible.
Hi Alex, Long time no read Smile

@Santeri

I use Alex' excellent approach in my LDCad, you can see the shader code in the resources folder of it's installation.

The geometry shader approach is the most efficient on paper but on older cards/drivers it's actually slower then the vs one.

The vs approach works on almost any gl platform, but it takes a whopping 5 attributes (incl pos) per vertex, and as a result wastes quite some memory and completely messes up your index re usage, But the performance you get is all all worth it Smile
Interesting - I'll have to give that a shot. Thanks for the suggestions.

On the subject of GL stuff, I've had some problems with alpha rendering as well, stuff seems to get rendered in the wrong order. I have no clue why it is doing this, maybe some of you have encountered this before?
[Image: alpharender.png]
Pages: 1 2