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.
single-window
EvilSpirit 2016-11-17 23:47:45 +07:00 committed by whitequark
parent e56630e71d
commit f8824e1fb2
6 changed files with 23 additions and 48 deletions

View File

@ -149,8 +149,7 @@ public:
void DrawPolygon(const SPolygon &p, hFill hcf) override { void DrawPolygon(const SPolygon &p, hFill hcf) override {
ssassert(false, "Not implemented"); ssassert(false, "Not implemented");
} }
void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}, void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}) override {
hStroke hcsTriangles = {}) override {
ssassert(false, "Not implemented"); ssassert(false, "Not implemented");
} }
void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override { void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override {

View File

@ -478,20 +478,27 @@ void Group::DrawMesh(DrawMeshAs how, Canvas *canvas) {
hcfBack = canvas->GetFill(fillBack); 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. // Draw mesh edges, for debugging.
Canvas::hStroke hcsTriangle = {};
if(SS.GW.showMesh) { if(SS.GW.showMesh) {
Canvas::Stroke strokeTriangle = {}; Canvas::Stroke strokeTriangle = {};
strokeTriangle.zIndex = 1; strokeTriangle.zIndex = 1;
strokeTriangle.color = RgbaColor::FromFloat(0.0f, 1.0f, 0.0f); strokeTriangle.color = RgbaColor::FromFloat(0.0f, 1.0f, 0.0f);
strokeTriangle.width = 1; strokeTriangle.width = 1;
strokeTriangle.unit = Canvas::Unit::PX; strokeTriangle.unit = Canvas::Unit::PX;
hcsTriangle = canvas->GetStroke(strokeTriangle); 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; break;
} }

View File

@ -405,7 +405,7 @@ void ObjectPicker::DrawPolygon(const SPolygon &p, hFill hcf) {
ssassert(false, "Not implemented"); 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"); ssassert(false, "Not implemented");
} }

View File

@ -154,8 +154,7 @@ public:
hFill hcf) = 0; hFill hcf) = 0;
virtual void DrawPoint(const Vector &o, hStroke hcs) = 0; virtual void DrawPoint(const Vector &o, hStroke hcs) = 0;
virtual void DrawPolygon(const SPolygon &p, hFill hcf) = 0; virtual void DrawPolygon(const SPolygon &p, hFill hcf) = 0;
virtual void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}, virtual void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}) = 0;
hStroke hcsTriangles = {}) = 0;
virtual void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) = 0; virtual void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) = 0;
virtual void DrawPixmap(std::shared_ptr<const Pixmap> pm, virtual void DrawPixmap(std::shared_ptr<const Pixmap> pm,
@ -221,7 +220,7 @@ public:
hFill hcf) override; hFill hcf) override;
void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPoint(const Vector &o, hStroke hcs) override;
void DrawPolygon(const SPolygon &p, hFill hcf) 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<uint32_t> &faces, hFill hcf) override; void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override;
void DrawPixmap(std::shared_ptr<const Pixmap> pm, void DrawPixmap(std::shared_ptr<const Pixmap> pm,
@ -269,7 +268,7 @@ public:
hFill hcf) override; hFill hcf) override;
void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPoint(const Vector &o, hStroke hcs) override;
void DrawPolygon(const SPolygon &p, hFill hcf) 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<uint32_t> &faces, hFill hcf) override; void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override;
void DrawPixmap(std::shared_ptr<const Pixmap> pm, void DrawPixmap(std::shared_ptr<const Pixmap> pm,

View File

@ -122,12 +122,12 @@ void SurfaceRenderer::DrawPoint(const Vector &o, Canvas::hStroke hcs) {
void SurfaceRenderer::DrawPolygon(const SPolygon &p, hFill hcf) { void SurfaceRenderer::DrawPolygon(const SPolygon &p, hFill hcf) {
SMesh m = {}; SMesh m = {};
p.TriangulateInto(&m); p.TriangulateInto(&m);
DrawMesh(m, hcf, {}, {}); DrawMesh(m, hcf, {});
m.Clear(); m.Clear();
} }
void SurfaceRenderer::DrawMesh(const SMesh &m, void SurfaceRenderer::DrawMesh(const SMesh &m,
hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) { hFill hcfFront, hFill hcfBack) {
Fill *fill = fills.FindById(hcfFront); Fill *fill = fills.FindById(hcfFront);
ssassert(fill->layer == Layer::NORMAL || ssassert(fill->layer == Layer::NORMAL ||
fill->layer == Layer::DEPTH_ONLY, "Unexpected mesh layer"); fill->layer == Layer::DEPTH_ONLY, "Unexpected mesh layer");
@ -160,17 +160,6 @@ void SurfaceRenderer::DrawMesh(const SMesh &m,
} }
mesh.AddTriangle(&tr); 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<uint32_t> &faces, hFill hcf) { void SurfaceRenderer::DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) {

View File

@ -198,7 +198,7 @@ public:
hFill hcf) override; hFill hcf) override;
void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPoint(const Vector &o, hStroke hcs) override;
void DrawPolygon(const SPolygon &p, hFill hcf) 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<uint32_t> &faces, hFill hcf) override; void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override;
void DrawPixmap(std::shared_ptr<const Pixmap> pm, void DrawPixmap(std::shared_ptr<const Pixmap> pm,
const Vector &o, const Vector &u, const Vector &v, const Vector &o, const Vector &u, const Vector &v,
@ -597,8 +597,7 @@ void OpenGl1Renderer::DrawPolygon(const SPolygon &p, hFill hcf) {
gluDeleteTess(gt); gluDeleteTess(gt);
} }
void OpenGl1Renderer::DrawMesh(const SMesh &m, void OpenGl1Renderer::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) {
hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) {
UnSelectPrimitive(); UnSelectPrimitive();
Fill *frontFill = SelectFill(hcfFront); Fill *frontFill = SelectFill(hcfFront);
@ -646,24 +645,6 @@ void OpenGl1Renderer::DrawMesh(const SMesh &m,
} }
glEnd(); glEnd();
glDisable(GL_LIGHTING); 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<uint32_t> &faces, hFill hcf) { void OpenGl1Renderer::DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) {