From 6073c8dee92130c8379444695a7d9f583b0a9c14 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 5 Aug 2008 17:49:35 +0000 Subject: [PATCH] RenderModeAttrib::M_filled_flat --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 1 + panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 1 + .../glstuff/glGraphicsStateGuardian_src.cxx | 1 + panda/src/pgraph/cullableObject.cxx | 8 ++++---- panda/src/pgraph/renderModeAttrib.cxx | 8 ++++++-- panda/src/pgraph/renderModeAttrib.h | 14 ++++++++++++- .../tinydisplay/tinyGraphicsStateGuardian.cxx | 20 +++++++++++++++++-- .../tinydisplay/tinyGraphicsStateGuardian.h | 1 + 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 04a1a5a51f..4e151a93d1 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2002,6 +2002,7 @@ do_issue_render_mode() { switch (mode) { case RenderModeAttrib::M_unchanged: case RenderModeAttrib::M_filled: + case RenderModeAttrib::M_filled_flat: _d3d_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); break; diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 2e850675ed..3650ebe24c 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3257,6 +3257,7 @@ do_issue_render_mode() { switch (mode) { case RenderModeAttrib::M_unchanged: case RenderModeAttrib::M_filled: + case RenderModeAttrib::M_filled_flat: set_render_state(D3DRS_FILLMODE, D3DFILL_SOLID); break; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 7260c38032..452d62c2c9 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3782,6 +3782,7 @@ do_issue_render_mode() { switch (_render_mode) { case RenderModeAttrib::M_unchanged: case RenderModeAttrib::M_filled: + case RenderModeAttrib::M_filled_flat: GLP(PolygonMode)(GL_FRONT_AND_BACK, GL_FILL); break; diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index e4fc831735..11de141864 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -258,10 +258,10 @@ munge_points_to_quads(const CullTraverser *traverser, bool force) { point_size = render_mode->get_thickness(); perspective = render_mode->get_perspective(); - if (render_mode->get_mode() != RenderModeAttrib::M_filled) { - // Be sure to turn on polygon render mode, since we're actually - // rendering polygons, not points any more. - _state = _state->add_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled)); + if (render_mode->get_mode() != RenderModeAttrib::M_filled_flat) { + // Render the new polygons with M_filled_flat, for a slight + // performance advantage when software rendering. + _state = _state->add_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled_flat)); } } diff --git a/panda/src/pgraph/renderModeAttrib.cxx b/panda/src/pgraph/renderModeAttrib.cxx index 7b493be94e..c15af4c6e1 100644 --- a/panda/src/pgraph/renderModeAttrib.cxx +++ b/panda/src/pgraph/renderModeAttrib.cxx @@ -61,11 +61,11 @@ output(ostream &out) const { out << get_type() << ":"; switch (get_mode()) { case M_unchanged: - out << "unchanged(" << get_thickness() << ")"; + out << "unchanged"; break; case M_filled: - out << "filled(" << get_thickness() << ")"; + out << "filled"; break; case M_wireframe: @@ -75,6 +75,10 @@ output(ostream &out) const { case M_point: out << "point(" << get_thickness() << ")"; break; + + case M_filled_flat: + out << "filled_flat"; + break; } if (get_perspective()) { diff --git a/panda/src/pgraph/renderModeAttrib.h b/panda/src/pgraph/renderModeAttrib.h index 3a410a9d22..d2f5c749c1 100644 --- a/panda/src/pgraph/renderModeAttrib.h +++ b/panda/src/pgraph/renderModeAttrib.h @@ -30,9 +30,21 @@ class EXPCL_PANDA_PGRAPH RenderModeAttrib : public RenderAttrib { PUBLISHED: enum Mode { M_unchanged, + + // Normal, filled polygons. M_filled, + + // Wireframe polygons, possibly with thickness. M_wireframe, - M_point + + // Points at vertices only, possibly with thickness and/or + // perspective sizing. + M_point, + + // Filled polygons, without any particular emphasis on perspective + // correctness (a particularly useful designation for software + // rendering sprites). + M_filled_flat }; private: diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx index 50d1248c0f..5664ffb9d8 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx @@ -103,6 +103,12 @@ reset() { _alpha_scale_via_texture = false; _runtime_color_scale = true; + _color_material_flags = 0; + _texturing_state = 0; + _texfilter_state = 0; + _texture_replace = false; + _filled_flat = false; + // Now that the GSG has been initialized, make it available for // optimizations. add_gsg(this); @@ -800,9 +806,11 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, int texfilter_state = 0; // tnearest if (texturing_state > 0) { texfilter_state = _texfilter_state; - if (_c->matrix_model_projection_no_w_transform) { + if (_c->matrix_model_projection_no_w_transform || + _filled_flat) { // Don't bother with the perspective-correct algorithm if we're - // under an orthonormal lens, e.g. render2d. + // under an orthonormal lens, e.g. render2d; or if + // RenderMode::M_filled_flat is in effect. texturing_state = 1; // textured (not perspective correct) } @@ -1602,6 +1610,8 @@ void TinyGraphicsStateGuardian:: do_issue_render_mode() { const RenderModeAttrib *attrib = _target._render_mode; + _filled_flat = false; + switch (attrib->get_mode()) { case RenderModeAttrib::M_unchanged: case RenderModeAttrib::M_filled: @@ -1609,6 +1619,12 @@ do_issue_render_mode() { _c->draw_triangle_back = gl_draw_triangle_fill; break; + case RenderModeAttrib::M_filled_flat: + _c->draw_triangle_front = gl_draw_triangle_fill; + _c->draw_triangle_back = gl_draw_triangle_fill; + _filled_flat = true; + break; + case RenderModeAttrib::M_wireframe: _c->draw_triangle_front = gl_draw_triangle_line; _c->draw_triangle_back = gl_draw_triangle_line; diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h index d7eb43e545..dbd0cbbd1d 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h @@ -139,6 +139,7 @@ private: int _texturing_state; int _texfilter_state; bool _texture_replace; + bool _filled_flat; SimpleLru _textures_lru;