Преглед на файлове

Initial working stencil.

aignacio_sf преди 19 години
родител
ревизия
d57e768594
променени са 3 файла, в които са добавени 101 реда и са изтрити 37 реда
  1. 14 11
      panda/src/pgraph/stencilAttrib.I
  2. 75 17
      panda/src/pgraph/stencilAttrib.cxx
  3. 12 9
      panda/src/pgraph/stencilAttrib.h

+ 14 - 11
panda/src/pgraph/stencilAttrib.I

@@ -26,26 +26,24 @@
 INLINE StencilAttrib::
 INLINE StencilAttrib::
 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_front_enable] = 0;
+  _stencil_render_states [SRS_back_enable] = 0;
+
   _stencil_render_states [SRS_front_comparison_function] = SCF_always;
   _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_fail_operation] = SO_keep;
   _stencil_render_states [SRS_front_stencil_pass_z_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_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_comparison_function] = SCF_always;
   _stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
   _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_fail_operation] = SO_keep;
   _stencil_render_states [SRS_back_stencil_pass_z_pass_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::
 INLINE void StencilAttrib::
 set_render_state(unsigned int render_state_identifier, unsigned int render_state) {
 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");
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 75 - 17
panda/src/pgraph/stencilAttrib.cxx

@@ -27,10 +27,49 @@
 
 
 TypeHandle StencilAttrib::_type_handle;
 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
 //     Function: StencilAttrib::make
 //       Access: Published, Static
 //       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::
 CPT(RenderAttrib) StencilAttrib::
 make() {
 make() {
@@ -38,6 +77,29 @@ make() {
   return return_new(attrib);
   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
 //     Function: StencilAttrib::output
 //       Access: Public, Virtual
 //       Access: Public, Virtual
@@ -45,9 +107,12 @@ make() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void StencilAttrib::
 void StencilAttrib::
 output(ostream &out) const {
 output(ostream &out) const {
+
   int index;
   int index;
   for (index = 0; index < SRS_total; 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;
   const StencilAttrib *sa;
   DCAST_INTO_R(sa, other, 0);
   DCAST_INTO_R(sa, other, 0);
 
 
+  int a;
+  int b;
+  int index;
   int compare_result = 0;
   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++) {
   for (index = 0; index < SRS_total; index++) {
     _stencil_render_states [index] = scan.get_int32();
     _stencil_render_states [index] = scan.get_int32();
   }
   }
-  _default = false;
 }
 }

+ 12 - 9
panda/src/pgraph/stencilAttrib.h

@@ -38,20 +38,18 @@ PUBLISHED:
   // enums are duplicated here from class StencilRenderStates for use in Python
   // enums are duplicated here from class StencilRenderStates for use in Python
   enum StencilRenderState
   enum StencilRenderState
   {
   {
-    SRS_clear_value,
-
-    SRS_reference,
-
-    SRS_read_mask,
-    SRS_write_mask,
-
     SRS_front_enable,
     SRS_front_enable,
+    SRS_back_enable,
+
     SRS_front_comparison_function,
     SRS_front_comparison_function,
     SRS_front_stencil_fail_operation,
     SRS_front_stencil_fail_operation,
     SRS_front_stencil_pass_z_fail_operation,
     SRS_front_stencil_pass_z_fail_operation,
     SRS_front_stencil_pass_z_pass_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_comparison_function,
     SRS_back_stencil_fail_operation,
     SRS_back_stencil_fail_operation,
     SRS_back_stencil_pass_z_fail_operation,
     SRS_back_stencil_pass_z_fail_operation,
@@ -86,11 +84,15 @@ PUBLISHED:
     SO_decrement_saturate,
     SO_decrement_saturate,
   };
   };
 
 
+  static CPT(RenderAttrib) make_begin();
   static CPT(RenderAttrib) make();
   static CPT(RenderAttrib) make();
+  CPT(RenderAttrib) make_end();
   INLINE void set_render_state (unsigned int render_state_identifier, unsigned int render_state);
   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;
   INLINE unsigned int get_render_state (unsigned int render_state_identifier) const;
 
 
 public:
 public:
+  static char *stencil_render_state_name_array [SRS_total];
+
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
   virtual void store_into_slot(AttribSlots *slots) const;
   virtual void store_into_slot(AttribSlots *slots) const;
 
 
@@ -100,7 +102,8 @@ protected:
 
 
 private:
 private:
   unsigned int _stencil_render_states [SRS_total];
   unsigned int _stencil_render_states [SRS_total];
-  bool _default;
+public:
+  bool _pre;
 
 
 public:
 public:
   static void register_with_read_factory();
   static void register_with_read_factory();