From d57e76859490d82f28f3e55399ef8927089ebf13 Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Wed, 24 May 2006 00:13:04 +0000 Subject: [PATCH] Initial working stencil. --- panda/src/pgraph/stencilAttrib.I | 25 ++++---- panda/src/pgraph/stencilAttrib.cxx | 92 ++++++++++++++++++++++++------ panda/src/pgraph/stencilAttrib.h | 21 ++++--- 3 files changed, 101 insertions(+), 37 deletions(-) diff --git a/panda/src/pgraph/stencilAttrib.I b/panda/src/pgraph/stencilAttrib.I index 746fa9303f..1bcdd08e35 100644 --- a/panda/src/pgraph/stencilAttrib.I +++ b/panda/src/pgraph/stencilAttrib.I @@ -26,26 +26,24 @@ INLINE StencilAttrib:: StencilAttrib() { - _stencil_render_states [SRS_clear_value] = 0; - - _stencil_render_states [SRS_reference] = 0; - - _stencil_render_states [SRS_read_mask] = ~0; - _stencil_render_states [SRS_write_mask] = ~0; - _stencil_render_states [SRS_front_enable] = 0; + _stencil_render_states [SRS_back_enable] = 0; + _stencil_render_states [SRS_front_comparison_function] = SCF_always; _stencil_render_states [SRS_front_stencil_fail_operation] = SO_keep; _stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = SO_keep; _stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = SO_keep; - _stencil_render_states [SRS_back_enable] = 0; + _stencil_render_states [SRS_reference] = 0; + _stencil_render_states [SRS_read_mask] = ~0; + _stencil_render_states [SRS_write_mask] = ~0; + _stencil_render_states [SRS_back_comparison_function] = SCF_always; _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; - _default = true; + _pre = false; } //////////////////////////////////////////////////////////////////// @@ -55,8 +53,13 @@ StencilAttrib() { //////////////////////////////////////////////////////////////////// INLINE void StencilAttrib:: set_render_state(unsigned int render_state_identifier, unsigned int render_state) { - _stencil_render_states [render_state_identifier] = render_state; - _default = false; + if (_pre) { + _stencil_render_states [render_state_identifier] = render_state; + } + else { + // ERROR: set_render_state can only be called with a pre_make StencilAttrib + printf ("ERROR: set_render_state can only be called with a StencilAttrib.make_begin\n"); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/stencilAttrib.cxx b/panda/src/pgraph/stencilAttrib.cxx index ba8df25a29..1b8f8e5a28 100644 --- a/panda/src/pgraph/stencilAttrib.cxx +++ b/panda/src/pgraph/stencilAttrib.cxx @@ -27,10 +27,49 @@ TypeHandle StencilAttrib::_type_handle; +char *StencilAttrib:: +stencil_render_state_name_array [StencilAttrib::SRS_total] = +{ + "SRS_front_enable", + "SRS_back_enable", + + "SRS_front_comparison_function", + "SRS_front_stencil_fail_operation", + "SRS_front_stencil_pass_z_fail_operation", + "SRS_front_stencil_pass_z_pass_operation", + + "SRS_reference", + "SRS_read_mask", + "SRS_write_mask", + + "SRS_back_comparison_function", + "SRS_back_stencil_fail_operation", + "SRS_back_stencil_pass_z_fail_operation", + "SRS_back_stencil_pass_z_pass_operation", +}; + +//////////////////////////////////////////////////////////////////// +// Function: StencilAttrib::make_begin +// Access: Published, Static +// Description: Constructs a new default and writable StencilAttrib. +// set_render_state can be called. +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) StencilAttrib:: +make_begin() { + StencilAttrib *attrib = new StencilAttrib; + attrib -> _pre = true; + + CPT(RenderAttrib) pt_attrib = attrib; + + return pt_attrib; +} + //////////////////////////////////////////////////////////////////// // Function: StencilAttrib::make // Access: Published, Static -// Description: Constructs a new StencilAttrib object. +// Description: Constructs a new default read-only StencilAttrib. +// set_render_state can not be called on the created +// object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) StencilAttrib:: make() { @@ -38,6 +77,29 @@ make() { return return_new(attrib); } +//////////////////////////////////////////////////////////////////// +// Function: StencilAttrib::make_end +// Access: Published +// Description: Constructs a final read-only StencilAttrib object +// from an existing StencilAttrib. +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) StencilAttrib:: +make_end() { + + StencilAttrib *attrib = new StencilAttrib; + StencilAttrib *original_attrib; + + original_attrib = this; + + int index; + for (index = 0; index < SRS_total; index++) { + attrib -> _stencil_render_states [index] = + original_attrib -> _stencil_render_states [index]; + } + + return return_new(attrib); +} + //////////////////////////////////////////////////////////////////// // Function: StencilAttrib::output // Access: Public, Virtual @@ -45,9 +107,12 @@ make() { //////////////////////////////////////////////////////////////////// void StencilAttrib:: output(ostream &out) const { + int index; for (index = 0; index < SRS_total; index++) { - out << "(" << index << "," << _stencil_render_states [index] << ")"; + out + << "(" << stencil_render_state_name_array [index] + << ", " << _stencil_render_states [index] << ")"; } } @@ -71,22 +136,16 @@ compare_to_impl(const RenderAttrib *other) const { const StencilAttrib *sa; DCAST_INTO_R(sa, other, 0); + int a; + int b; + int index; int compare_result = 0; - // quick test to see if both are default states - // which should be the most common case - if (_default && (_default == sa -> _default)) { - - } - else { - int index; - for (index = 0; index < SRS_total; index++) { - if (_stencil_render_states [index] - sa -> _stencil_render_states [index]) { - - // ????? - compare_result = -(index + 1); - break; - } + for (index = 0; index < SRS_total; index++) { + a = (int) sa -> _stencil_render_states [index]; + b = (int) _stencil_render_states [index]; + if (compare_result = (a - b)) { + break; } } @@ -182,5 +241,4 @@ fillin(DatagramIterator &scan, BamReader *manager) { for (index = 0; index < SRS_total; index++) { _stencil_render_states [index] = scan.get_int32(); } - _default = false; } diff --git a/panda/src/pgraph/stencilAttrib.h b/panda/src/pgraph/stencilAttrib.h index ad41cd853e..c0aaf3d927 100644 --- a/panda/src/pgraph/stencilAttrib.h +++ b/panda/src/pgraph/stencilAttrib.h @@ -38,20 +38,18 @@ PUBLISHED: // enums are duplicated here from class StencilRenderStates for use in Python enum StencilRenderState { - SRS_clear_value, - - SRS_reference, - - SRS_read_mask, - SRS_write_mask, - SRS_front_enable, + SRS_back_enable, + SRS_front_comparison_function, SRS_front_stencil_fail_operation, SRS_front_stencil_pass_z_fail_operation, SRS_front_stencil_pass_z_pass_operation, - SRS_back_enable, + SRS_reference, + SRS_read_mask, + SRS_write_mask, + SRS_back_comparison_function, SRS_back_stencil_fail_operation, SRS_back_stencil_pass_z_fail_operation, @@ -86,11 +84,15 @@ PUBLISHED: SO_decrement_saturate, }; + static CPT(RenderAttrib) make_begin(); static CPT(RenderAttrib) make(); + CPT(RenderAttrib) make_end(); INLINE void set_render_state (unsigned int render_state_identifier, unsigned int render_state); 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; @@ -100,7 +102,8 @@ protected: private: unsigned int _stencil_render_states [SRS_total]; - bool _default; +public: + bool _pre; public: static void register_with_read_factory();