From f8824e1fb2798e2e763a8936805ac65615eda7f9 Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Thu, 17 Nov 2016 23:47:45 +0700 Subject: [PATCH] Reimplement drawing of the mesh wireframe. OpenGL 2 and newer do not have the glPolygonMode(..., GL_LINES) API, so produce the wireframe on our side. It's somewhat slow, and draws every line three times, but it is cached when the OpenGL 2 renderer is used, and this should do for a debugging feature. --- src/export.cpp | 3 +-- src/groupmesh.cpp | 21 ++++++++++++++------- src/render/render.cpp | 2 +- src/render/render.h | 7 +++---- src/render/render2d.cpp | 15 ++------------- src/render/rendergl1.cpp | 23 ++--------------------- 6 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/export.cpp b/src/export.cpp index 5d63c325..12da831a 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -149,8 +149,7 @@ public: void DrawPolygon(const SPolygon &p, hFill hcf) override { ssassert(false, "Not implemented"); } - void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}, - hStroke hcsTriangles = {}) override { + void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}) override { ssassert(false, "Not implemented"); } void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override { diff --git a/src/groupmesh.cpp b/src/groupmesh.cpp index dac5869e..420478af 100644 --- a/src/groupmesh.cpp +++ b/src/groupmesh.cpp @@ -478,20 +478,27 @@ void Group::DrawMesh(DrawMeshAs how, Canvas *canvas) { hcfBack = canvas->GetFill(fillBack); } + // Draw the shaded solid into the depth buffer for hidden line removal, + // and if we're actually going to display it, to the color buffer too. + canvas->DrawMesh(displayMesh, hcfFront, hcfBack); + // Draw mesh edges, for debugging. - Canvas::hStroke hcsTriangle = {}; if(SS.GW.showMesh) { Canvas::Stroke strokeTriangle = {}; strokeTriangle.zIndex = 1; strokeTriangle.color = RgbaColor::FromFloat(0.0f, 1.0f, 0.0f); strokeTriangle.width = 1; - strokeTriangle.unit = Canvas::Unit::PX; - hcsTriangle = canvas->GetStroke(strokeTriangle); + strokeTriangle.unit = Canvas::Unit::PX; + Canvas::hStroke hcsTriangle = canvas->GetStroke(strokeTriangle); + SEdgeList edges = {}; + for(const STriangle &t : displayMesh.l) { + edges.AddEdge(t.a, t.b); + edges.AddEdge(t.b, t.c); + edges.AddEdge(t.c, t.a); + } + canvas->DrawEdges(edges, hcsTriangle); + edges.Clear(); } - - // Draw the shaded solid into the depth buffer for hidden line removal, - // and if we're actually going to display it, to the color buffer too. - canvas->DrawMesh(displayMesh, hcfFront, hcfBack, hcsTriangle); break; } diff --git a/src/render/render.cpp b/src/render/render.cpp index 94f00408..e82aa5ff 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -405,7 +405,7 @@ void ObjectPicker::DrawPolygon(const SPolygon &p, hFill hcf) { ssassert(false, "Not implemented"); } -void ObjectPicker::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) { +void ObjectPicker::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) { ssassert(false, "Not implemented"); } diff --git a/src/render/render.h b/src/render/render.h index d8a4af9e..4f8fcf9a 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -154,8 +154,7 @@ public: hFill hcf) = 0; virtual void DrawPoint(const Vector &o, hStroke hcs) = 0; virtual void DrawPolygon(const SPolygon &p, hFill hcf) = 0; - virtual void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}, - hStroke hcsTriangles = {}) = 0; + virtual void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}) = 0; virtual void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) = 0; virtual void DrawPixmap(std::shared_ptr pm, @@ -221,7 +220,7 @@ public: hFill hcf) override; void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; - void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; + void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; void DrawPixmap(std::shared_ptr pm, @@ -269,7 +268,7 @@ public: hFill hcf) override; void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; - void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; + void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; void DrawPixmap(std::shared_ptr pm, diff --git a/src/render/render2d.cpp b/src/render/render2d.cpp index 729f8eb9..efee571a 100644 --- a/src/render/render2d.cpp +++ b/src/render/render2d.cpp @@ -122,12 +122,12 @@ void SurfaceRenderer::DrawPoint(const Vector &o, Canvas::hStroke hcs) { void SurfaceRenderer::DrawPolygon(const SPolygon &p, hFill hcf) { SMesh m = {}; p.TriangulateInto(&m); - DrawMesh(m, hcf, {}, {}); + DrawMesh(m, hcf, {}); m.Clear(); } void SurfaceRenderer::DrawMesh(const SMesh &m, - hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) { + hFill hcfFront, hFill hcfBack) { Fill *fill = fills.FindById(hcfFront); ssassert(fill->layer == Layer::NORMAL || fill->layer == Layer::DEPTH_ONLY, "Unexpected mesh layer"); @@ -160,17 +160,6 @@ void SurfaceRenderer::DrawMesh(const SMesh &m, } mesh.AddTriangle(&tr); } - - if(hcsTriangles.v != 0) { - for(const STriangle &tr : m.l) { - edges[hcsTriangles].AddEdge(ProjectPoint3RH(camera, tr.a), - ProjectPoint3RH(camera, tr.b)); - edges[hcsTriangles].AddEdge(ProjectPoint3RH(camera, tr.b), - ProjectPoint3RH(camera, tr.c)); - edges[hcsTriangles].AddEdge(ProjectPoint3RH(camera, tr.c), - ProjectPoint3RH(camera, tr.a)); - } - } } void SurfaceRenderer::DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) { diff --git a/src/render/rendergl1.cpp b/src/render/rendergl1.cpp index 29c55722..a868c324 100644 --- a/src/render/rendergl1.cpp +++ b/src/render/rendergl1.cpp @@ -198,7 +198,7 @@ public: hFill hcf) override; void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; - void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; + void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; void DrawPixmap(std::shared_ptr pm, const Vector &o, const Vector &u, const Vector &v, @@ -597,8 +597,7 @@ void OpenGl1Renderer::DrawPolygon(const SPolygon &p, hFill hcf) { gluDeleteTess(gt); } -void OpenGl1Renderer::DrawMesh(const SMesh &m, - hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) { +void OpenGl1Renderer::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) { UnSelectPrimitive(); Fill *frontFill = SelectFill(hcfFront); @@ -646,24 +645,6 @@ void OpenGl1Renderer::DrawMesh(const SMesh &m, } glEnd(); glDisable(GL_LIGHTING); - - if(hcsTriangles.v != 0) { - Stroke *triangleStroke = SelectStroke(hcsTriangles); - ssassert(triangleStroke->width == 1 && - triangleStroke->stipplePattern == StipplePattern::CONTINUOUS && - triangleStroke->stippleScale == 0.0, - "Triangle stroke must match predefined OpenGL parameters"); - - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glBegin(GL_TRIANGLES); - for(const STriangle &tr : m.l) { - ssglVertex3v(tr.a); - ssglVertex3v(tr.b); - ssglVertex3v(tr.c); - } - glEnd(); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } } void OpenGl1Renderer::DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) {