Procházet zdrojové kódy

individual control of channels in ColorWriteAttrib

David Rose před 20 roky
rodič
revize
fd71491bc6

+ 1 - 1
panda/src/display/graphicsStateGuardian.cxx

@@ -865,7 +865,7 @@ begin_decal_base_second() {
   static CPT(RenderState) decal_base_second;
   static CPT(RenderState) decal_base_second;
   if (decal_base_second == (const RenderState *)NULL) {
   if (decal_base_second == (const RenderState *)NULL) {
     decal_base_second = RenderState::make
     decal_base_second = RenderState::make
-      (ColorWriteAttrib::make(ColorWriteAttrib::M_off),
+      (ColorWriteAttrib::make(ColorWriteAttrib::C_off),
        // On reflection, we need to leave texturing on so the alpha
        // On reflection, we need to leave texturing on so the alpha
        // test mechanism can work (if it is enabled, e.g. we are
        // test mechanism can work (if it is enabled, e.g. we are
        // rendering an object with M_dual transparency).
        // rendering an object with M_dual transparency).

+ 6 - 2
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -2663,7 +2663,11 @@ bind_clip_plane(const NodePath &plane, int plane_id) {
 void DXGraphicsStateGuardian8::
 void DXGraphicsStateGuardian8::
 do_issue_blending() {
 do_issue_blending() {
 
 
-  if (_target._color_write->get_mode() == ColorWriteAttrib::M_off) {
+  // Handle the color_write attrib.  If color_write is off, then
+  // all the other blending-related stuff doesn't matter.  If the
+  // device doesn't support color-write, we use blending tricks
+  // to effectively disable color write.
+  if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) {
     if (_target._color_write != _state._color_write) {
     if (_target._color_write != _state._color_write) {
       if (_screen->_can_direct_disable_color_writes) {
       if (_screen->_can_direct_disable_color_writes) {
         enable_blend(false);
         enable_blend(false);
@@ -2677,7 +2681,7 @@ do_issue_blending() {
   } else {
   } else {
     if (_target._color_write != _state._color_write) {
     if (_target._color_write != _state._color_write) {
       if (_screen->_can_direct_disable_color_writes) {
       if (_screen->_can_direct_disable_color_writes) {
-        _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)0xFFFFFFFF);
+        _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, _target._color_write->get_channels());
       }
       }
     }
     }
   }
   }

+ 6 - 2
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -3069,7 +3069,7 @@ do_issue_blending() {
   // all the other blending-related stuff doesn't matter.  If the
   // all the other blending-related stuff doesn't matter.  If the
   // device doesn't support color-write, we use blending tricks
   // device doesn't support color-write, we use blending tricks
   // to effectively disable color write.
   // to effectively disable color write.
-  if (_target._color_write->get_mode() == ColorWriteAttrib::M_off) {
+  if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) {
     if (_target._color_write != _state._color_write) {
     if (_target._color_write != _state._color_write) {
       enable_multisample_alpha_one(false);
       enable_multisample_alpha_one(false);
       enable_multisample_alpha_mask(false);
       enable_multisample_alpha_mask(false);
@@ -3086,7 +3086,11 @@ do_issue_blending() {
   } else {
   } else {
     if (_target._color_write != _state._color_write) {
     if (_target._color_write != _state._color_write) {
       if (CLP(color_mask)) {
       if (CLP(color_mask)) {
-        GLP(ColorMask)(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+	unsigned int channels = _target._color_write->get_channels();
+        GLP(ColorMask)(channels & ColorWriteAttrib::C_red,
+		       channels & ColorWriteAttrib::C_green,
+		       channels & ColorWriteAttrib::C_blue,
+		       channels & ColorWriteAttrib::C_alpha);
       }
       }
     }
     }
   }
   }

+ 1 - 1
panda/src/pgraph/attribSlots.cxx

@@ -38,7 +38,7 @@ initialize_defvals() {
   _defvals._color          = DCAST(ColorAttrib,ColorAttrib::make_off());
   _defvals._color          = DCAST(ColorAttrib,ColorAttrib::make_off());
   _defvals._color_blend    = DCAST(ColorBlendAttrib,ColorBlendAttrib::make_off());
   _defvals._color_blend    = DCAST(ColorBlendAttrib,ColorBlendAttrib::make_off());
   _defvals._color_scale    = DCAST(ColorScaleAttrib,ColorScaleAttrib::make_off());
   _defvals._color_scale    = DCAST(ColorScaleAttrib,ColorScaleAttrib::make_off());
-  _defvals._color_write    = DCAST(ColorWriteAttrib,ColorWriteAttrib::make(ColorWriteAttrib::M_on));
+  _defvals._color_write    = DCAST(ColorWriteAttrib,ColorWriteAttrib::make(ColorWriteAttrib::C_all));
   _defvals._cull_bin       = DCAST(CullBinAttrib,CullBinAttrib::make("",0));
   _defvals._cull_bin       = DCAST(CullBinAttrib,CullBinAttrib::make("",0));
   _defvals._cull_face      = DCAST(CullFaceAttrib,CullFaceAttrib::make(CullFaceAttrib::M_cull_counter_clockwise));
   _defvals._cull_face      = DCAST(CullFaceAttrib,CullFaceAttrib::make(CullFaceAttrib::M_cull_counter_clockwise));
   _defvals._depth_offset   = DCAST(DepthOffsetAttrib,DepthOffsetAttrib::make(0));
   _defvals._depth_offset   = DCAST(DepthOffsetAttrib,DepthOffsetAttrib::make(0));

+ 8 - 7
panda/src/pgraph/colorWriteAttrib.I

@@ -24,17 +24,18 @@
 //               ColorWriteAttrib object.
 //               ColorWriteAttrib object.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE ColorWriteAttrib::
 INLINE ColorWriteAttrib::
-ColorWriteAttrib(ColorWriteAttrib::Mode mode) :
-  _mode(mode)
+ColorWriteAttrib(unsigned int channels) :
+  _channels(channels)
 {
 {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: ColorWriteAttrib::get_mode
+//     Function: ColorWriteAttrib::get_channels
 //       Access: Published
 //       Access: Published
-//  Description: Returns the color write mode.
+//  Description: Returns the mask of color channels that are enabled
+//               by this attrib.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE ColorWriteAttrib::Mode ColorWriteAttrib::
-get_mode() const {
-  return _mode;
+INLINE unsigned int ColorWriteAttrib::
+get_channels() const {
+  return _channels;
 }
 }

+ 19 - 11
panda/src/pgraph/colorWriteAttrib.cxx

@@ -33,8 +33,8 @@ TypeHandle ColorWriteAttrib::_type_handle;
 //  Description: Constructs a new ColorWriteAttrib object.
 //  Description: Constructs a new ColorWriteAttrib object.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 CPT(RenderAttrib) ColorWriteAttrib::
 CPT(RenderAttrib) ColorWriteAttrib::
-make(ColorWriteAttrib::Mode mode) {
-  ColorWriteAttrib *attrib = new ColorWriteAttrib(mode);
+make(unsigned int channels) {
+  ColorWriteAttrib *attrib = new ColorWriteAttrib(channels);
   return return_new(attrib);
   return return_new(attrib);
 }
 }
 
 
@@ -46,13 +46,21 @@ make(ColorWriteAttrib::Mode mode) {
 void ColorWriteAttrib::
 void ColorWriteAttrib::
 output(ostream &out) const {
 output(ostream &out) const {
   out << get_type() << ":";
   out << get_type() << ":";
-  switch (get_mode()) {
-  case M_off:
+  if (_channels == 0) {
     out << "off";
     out << "off";
-    break;
-  case M_on:
-    out << "on";
-    break;
+  } else {
+    if ((_channels & C_red) != 0) {
+      out << "r";
+    }
+    if ((_channels & C_green) != 0) {
+      out << "g";
+    }
+    if ((_channels & C_blue) != 0) {
+      out << "b";
+    }
+    if ((_channels & C_alpha) != 0) {
+      out << "a";
+    }
   }
   }
 }
 }
 
 
@@ -75,7 +83,7 @@ int ColorWriteAttrib::
 compare_to_impl(const RenderAttrib *other) const {
 compare_to_impl(const RenderAttrib *other) const {
   const ColorWriteAttrib *ta;
   const ColorWriteAttrib *ta;
   DCAST_INTO_R(ta, other, 0);
   DCAST_INTO_R(ta, other, 0);
-  return (int)_mode - (int)ta->_mode;
+  return (int)_channels - (int)ta->_channels;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -126,7 +134,7 @@ void ColorWriteAttrib::
 write_datagram(BamWriter *manager, Datagram &dg) {
 write_datagram(BamWriter *manager, Datagram &dg) {
   RenderAttrib::write_datagram(manager, dg);
   RenderAttrib::write_datagram(manager, dg);
 
 
-  dg.add_int8(_mode);
+  dg.add_uint8(_channels);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -160,5 +168,5 @@ void ColorWriteAttrib::
 fillin(DatagramIterator &scan, BamReader *manager) {
 fillin(DatagramIterator &scan, BamReader *manager) {
   RenderAttrib::fillin(scan, manager);
   RenderAttrib::fillin(scan, manager);
 
 
-  _mode = (Mode)scan.get_int8();
+  _channels = scan.get_uint8();
 }
 }

+ 13 - 7
panda/src/pgraph/colorWriteAttrib.h

@@ -34,18 +34,24 @@ class FactoryParams;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA ColorWriteAttrib : public RenderAttrib {
 class EXPCL_PANDA ColorWriteAttrib : public RenderAttrib {
 PUBLISHED:
 PUBLISHED:
-  enum Mode {
-    M_off,
-    M_on
+  enum Channels {
+    // By coincidence, these bits are the same as those for
+    // D3DCOLORWRITEENABLE_RED, _GREEN, _BLUE, and _ALPHA.
+    C_off    = 0x000,
+    C_red    = 0x001,
+    C_green  = 0x002,
+    C_blue   = 0x004,
+    C_alpha  = 0x008,
+    C_all    = 0x00f,
   };
   };
 
 
 private:
 private:
-  INLINE ColorWriteAttrib(Mode mode = M_on);
+  INLINE ColorWriteAttrib(unsigned int channels = C_all);
 
 
 PUBLISHED:
 PUBLISHED:
-  static CPT(RenderAttrib) make(Mode mode);
+  static CPT(RenderAttrib) make(unsigned int channels);
 
 
-  INLINE Mode get_mode() const;
+  INLINE unsigned int get_channels() const;
 
 
 public:
 public:
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
@@ -56,7 +62,7 @@ protected:
   virtual RenderAttrib *make_default_impl() const;
   virtual RenderAttrib *make_default_impl() const;
 
 
 private:
 private:
-  Mode _mode;
+  int _channels;
 
 
 public:
 public:
   static void register_with_read_factory();
   static void register_with_read_factory();