solvespace / solvespace

Parametric 2d/3d CAD
http://solvespace.com/
GNU General Public License v3.0
3.2k stars 483 forks source link

All solid edges shown as occluded #378

Open ghost opened 5 years ago

ghost commented 5 years ago

System information

SolveSpace version: 3.0~10123738

Operating system: Debian 9.x Stretch

Expected behavior

Only really occluded edges should be shown as hidden

Actual behavior

All solid edges shown as occluded

Additional information

pic.1

pic.2

pic.3

Evil-Spirit commented 5 years ago

@whitequark probably here is the problem caused by https://github.com/solvespace/solvespace/commit/e383b7fba8fbad23ac370ea5731a87b7eacdf6c8

whitequark commented 5 years ago

@Evil-Spirit No, it was a problem as far as I can remember, I just never paid attention to it. It renders the same way if I revert e383b7f.

phkahler commented 4 years ago

On my system it looks like the occluded lines are drawn by drawing all lines (in whichever style) without Z-buffer, and then drawing all of them again in normal style with the Z-buffer enabled. It looks like some kind of fighting between the two line styles rather than only using the right one for each edge. Is that what's happening? @Evil-Spirit ?

EDIT: This look a lot like it's not applying the depth test correctly for occluded lines. Meaning this:

strokeHidden.layer  = Canvas::Layer::OCCLUDED;

Probably isn't correctly affecting this:

        case Canvas::Layer::OCCLUDED:
            glDepthFunc(GL_GREATER);
            glDepthMask(GL_FALSE);
            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
            break;

It's actually saying to draw the one line style only for things hidden by the Z-buffer, but that's not working.

Evil-Spirit commented 4 years ago

Probably, I can blame glDepthRangef following after this. I suppose for hidden lines it should be performed in a different way.

Evil-Spirit commented 4 years ago

Also, depth write probably should be switched off (glDepthMask(GL_FALSE)) for non-occluded edges.

phkahler commented 4 years ago

@Evil-Spirit its behaving like depth testing is turned off for occluded edges. And yes, depth write should probably be off for all edges.

phkahler commented 4 years ago

The problem has to be that there are multiple areas in the code affecting this. I can go in Group::Draw(Canvas *canvas) and comment out the entire section enclosed by if(SS.GW.showEdges) { .... } and I'm still able to use the toggle buttons to produce most of the options including showing the occluded lines. The bug is because a lot of this section of code is redundant in some way - I just haven't figured out what's stepping on it.

phkahler commented 4 years ago

OK, commenting out everyting but:

    GenerateDisplayItems();
    DrawMesh(DrawMeshAs::DEFAULT, canvas);

It's still drawing almost all edges (no silhouettes) and allowing 3 options for them with zero calls to DrawOutlines. This is also enabled/disabled via the "show all / hide all" links in the text window. I thought those were only supposed to toggle entities and the toolbar buttons determined which edges are visible and what style.

EDIT: no, It's just drawing the entities in 3 styles. It correctly draws the hidden ones when that option is enabled. So fixing this I should probably test with all entities turned off until the actual edges behave better.