From 6ec87e25062a513818de726c92d744ae9c44045c Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Wed, 13 Dec 2006 19:27:51 +0000 Subject: [PATCH] Add stencil buffer clear. --- panda/src/display/stencilRenderStates.h | 3 + panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 4 + panda/src/pgraph/stencilAttrib.cxx | 97 +++++++++++++++++++ panda/src/pgraph/stencilAttrib.h | 35 ++++++- 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/panda/src/display/stencilRenderStates.h b/panda/src/display/stencilRenderStates.h index 4e2a7d2e7a..8817783320 100644 --- a/panda/src/display/stencilRenderStates.h +++ b/panda/src/display/stencilRenderStates.h @@ -53,6 +53,9 @@ PUBLISHED: SRS_back_stencil_pass_z_fail_operation, SRS_back_stencil_pass_z_pass_operation, + SRS_clear, + SRS_clear_value, + SRS_total, SRS_first = 0, diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index c270d0456a..1e14f9e712 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -5336,6 +5336,10 @@ do_issue_stencil() { stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_read_mask, stencil -> get_render_state (StencilAttrib::SRS_read_mask)); stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_write_mask, stencil -> get_render_state (StencilAttrib::SRS_write_mask)); } + + if (stencil -> get_render_state (StencilAttrib::SRS_clear)) { + _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, 0, 0.0f, stencil -> get_render_state (StencilAttrib::SRS_clear_value)); + } } else { diff --git a/panda/src/pgraph/stencilAttrib.cxx b/panda/src/pgraph/stencilAttrib.cxx index 79ae5266b4..4d5becb9fd 100644 --- a/panda/src/pgraph/stencilAttrib.cxx +++ b/panda/src/pgraph/stencilAttrib.cxx @@ -46,6 +46,9 @@ stencil_render_state_name_array [StencilAttrib::SRS_total] = "SRS_back_stencil_fail_operation", "SRS_back_stencil_pass_z_fail_operation", "SRS_back_stencil_pass_z_pass_operation", + + "SRS_clear", + "SRS_clear_value", }; //////////////////////////////////////////////////////////////////// @@ -73,6 +76,9 @@ StencilAttrib() { _stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep; _stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep; _stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep; + + _stencil_render_states [SRS_clear] = 0; + _stencil_render_states [SRS_clear_value] = 0; } //////////////////////////////////////////////////////////////////// @@ -170,6 +176,97 @@ make_2_sided( return return_new(attrib); } +//////////////////////////////////////////////////////////////////// +// Function: StencilAttrib::make +// Access: Published, Static +// Description: Constructs a front face StencilAttrib. +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) StencilAttrib:: +make_with_clear( + unsigned int front_enable, + unsigned int front_comparison_function, + unsigned int stencil_fail_operation, + unsigned int stencil_pass_z_fail_operation, + unsigned int front_stencil_pass_z_pass_operation, + unsigned int reference, + unsigned int read_mask, + unsigned int write_mask, + unsigned int clear, + unsigned int clear_value) +{ + StencilAttrib *attrib = new StencilAttrib; + + attrib->_stencil_render_states [SRS_front_enable] = front_enable; + attrib->_stencil_render_states [SRS_back_enable] = 0; + + attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; + attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; + attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation; + attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation; + + attrib->_stencil_render_states [SRS_reference] = reference; + attrib->_stencil_render_states [SRS_read_mask] = read_mask; + attrib->_stencil_render_states [SRS_write_mask] = write_mask; + + attrib->_stencil_render_states [SRS_back_comparison_function] = SCF_always; + attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep; + attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep; + attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep; + + attrib->_stencil_render_states [SRS_clear] = clear; + attrib->_stencil_render_states [SRS_clear_value] = clear_value; + + return return_new(attrib); +} + +//////////////////////////////////////////////////////////////////// +// Function: StencilAttrib::make_2_sided +// Access: Published, Static +// Description: Constructs a two-sided StencilAttrib. +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) StencilAttrib:: +make_2_sided_with_clear( + unsigned int front_enable, + unsigned int back_enable, + unsigned int front_comparison_function, + unsigned int stencil_fail_operation, + unsigned int stencil_pass_z_fail_operation, + unsigned int front_stencil_pass_z_pass_operation, + unsigned int reference, + unsigned int read_mask, + unsigned int write_mask, + unsigned int back_comparison_function, + unsigned int back_stencil_fail_operation, + unsigned int back_stencil_pass_z_fail_operation, + unsigned int back_stencil_pass_z_pass_operation, + unsigned int clear, + unsigned int clear_value) +{ + StencilAttrib *attrib = new StencilAttrib; + + attrib->_stencil_render_states [SRS_front_enable] = front_enable; + attrib->_stencil_render_states [SRS_back_enable] = back_enable; + + attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; + attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; + attrib->_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = stencil_pass_z_fail_operation; + attrib->_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = front_stencil_pass_z_pass_operation; + + attrib->_stencil_render_states [SRS_reference] = reference; + attrib->_stencil_render_states [SRS_read_mask] = read_mask; + attrib->_stencil_render_states [SRS_write_mask] = write_mask; + + attrib->_stencil_render_states [SRS_back_comparison_function] = back_comparison_function; + attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = back_stencil_fail_operation; + attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = back_stencil_pass_z_fail_operation; + attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = back_stencil_pass_z_pass_operation; + + attrib->_stencil_render_states [SRS_clear] = clear; + attrib->_stencil_render_states [SRS_clear_value] = clear_value; + + return return_new(attrib); +} + //////////////////////////////////////////////////////////////////// // Function: StencilAttrib::output // Access: Public, Virtual diff --git a/panda/src/pgraph/stencilAttrib.h b/panda/src/pgraph/stencilAttrib.h index c3b2f4660a..d68b468823 100644 --- a/panda/src/pgraph/stencilAttrib.h +++ b/panda/src/pgraph/stencilAttrib.h @@ -34,6 +34,7 @@ class FactoryParams; // get_supports_two_sided_stencil. //////////////////////////////////////////////////////////////////// class EXPCL_PANDA StencilAttrib : public RenderAttrib { + private: StencilAttrib(); @@ -59,6 +60,9 @@ PUBLISHED: SRS_back_stencil_pass_z_fail_operation, SRS_back_stencil_pass_z_pass_operation, + SRS_clear, + SRS_clear_value, + SRS_total, SRS_first = 0, @@ -120,11 +124,40 @@ PUBLISHED: unsigned int back_stencil_pass_z_fail_operation, unsigned int back_stencil_pass_z_pass_operation); + static CPT(RenderAttrib) make_with_clear( + unsigned int front_enable, + unsigned int front_comparison_function, + unsigned int stencil_fail_operation, + unsigned int stencil_pass_z_fail_operation, + unsigned int front_stencil_pass_z_pass_operation, + unsigned int reference, + unsigned int read_mask, + unsigned int write_mask, + unsigned int clear, + unsigned int clear_value); + + static CPT(RenderAttrib) make_2_sided_with_clear( + unsigned int front_enable, + unsigned int back_enable, + unsigned int front_comparison_function, + unsigned int stencil_fail_operation, + unsigned int stencil_pass_z_fail_operation, + unsigned int front_stencil_pass_z_pass_operation, + unsigned int reference, + unsigned int read_mask, + unsigned int write_mask, + unsigned int back_comparison_function, + unsigned int back_stencil_fail_operation, + unsigned int back_stencil_pass_z_fail_operation, + unsigned int back_stencil_pass_z_pass_operation, + unsigned int clear, + unsigned int clear_value); + INLINE unsigned int get_render_state (unsigned int render_state_identifier) const; public: static char *stencil_render_state_name_array [SRS_total]; - + virtual void output(ostream &out) const; virtual void store_into_slot(AttribSlots *slots) const;