diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 99c6b5d3cf..7e12cbf300 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -865,7 +865,7 @@ begin_decal_base_second() { static CPT(RenderState) decal_base_second; if (decal_base_second == (const RenderState *)NULL) { 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 // test mechanism can work (if it is enabled, e.g. we are // rendering an object with M_dual transparency). diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 1ed6ea6614..2a0438cd96 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2663,7 +2663,11 @@ bind_clip_plane(const NodePath &plane, int plane_id) { void DXGraphicsStateGuardian8:: 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 (_screen->_can_direct_disable_color_writes) { enable_blend(false); @@ -2677,7 +2681,7 @@ do_issue_blending() { } else { if (_target._color_write != _state._color_write) { if (_screen->_can_direct_disable_color_writes) { - _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)0xFFFFFFFF); + _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, _target._color_write->get_channels()); } } } diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 5a07516657..a8812aa546 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3069,7 +3069,7 @@ do_issue_blending() { // 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_mode() == ColorWriteAttrib::M_off) { + if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) { if (_target._color_write != _state._color_write) { enable_multisample_alpha_one(false); enable_multisample_alpha_mask(false); @@ -3086,7 +3086,11 @@ do_issue_blending() { } else { if (_target._color_write != _state._color_write) { 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); } } } diff --git a/panda/src/pgraph/attribSlots.cxx b/panda/src/pgraph/attribSlots.cxx index 5db1fa5114..0bba977bad 100644 --- a/panda/src/pgraph/attribSlots.cxx +++ b/panda/src/pgraph/attribSlots.cxx @@ -38,7 +38,7 @@ initialize_defvals() { _defvals._color = DCAST(ColorAttrib,ColorAttrib::make_off()); _defvals._color_blend = DCAST(ColorBlendAttrib,ColorBlendAttrib::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_face = DCAST(CullFaceAttrib,CullFaceAttrib::make(CullFaceAttrib::M_cull_counter_clockwise)); _defvals._depth_offset = DCAST(DepthOffsetAttrib,DepthOffsetAttrib::make(0)); diff --git a/panda/src/pgraph/colorWriteAttrib.I b/panda/src/pgraph/colorWriteAttrib.I index 635382182f..1258d33450 100644 --- a/panda/src/pgraph/colorWriteAttrib.I +++ b/panda/src/pgraph/colorWriteAttrib.I @@ -24,17 +24,18 @@ // ColorWriteAttrib object. //////////////////////////////////////////////////////////////////// INLINE ColorWriteAttrib:: -ColorWriteAttrib(ColorWriteAttrib::Mode mode) : - _mode(mode) +ColorWriteAttrib(unsigned int channels) : + _channels(channels) { } //////////////////////////////////////////////////////////////////// -// Function: ColorWriteAttrib::get_mode +// Function: ColorWriteAttrib::get_channels // 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; } diff --git a/panda/src/pgraph/colorWriteAttrib.cxx b/panda/src/pgraph/colorWriteAttrib.cxx index 469d672898..e12d445f7b 100644 --- a/panda/src/pgraph/colorWriteAttrib.cxx +++ b/panda/src/pgraph/colorWriteAttrib.cxx @@ -33,8 +33,8 @@ TypeHandle ColorWriteAttrib::_type_handle; // Description: Constructs a new ColorWriteAttrib object. //////////////////////////////////////////////////////////////////// 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); } @@ -46,13 +46,21 @@ make(ColorWriteAttrib::Mode mode) { void ColorWriteAttrib:: output(ostream &out) const { out << get_type() << ":"; - switch (get_mode()) { - case M_off: + if (_channels == 0) { 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 { const ColorWriteAttrib *ta; 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) { RenderAttrib::write_datagram(manager, dg); - dg.add_int8(_mode); + dg.add_uint8(_channels); } //////////////////////////////////////////////////////////////////// @@ -160,5 +168,5 @@ void ColorWriteAttrib:: fillin(DatagramIterator &scan, BamReader *manager) { RenderAttrib::fillin(scan, manager); - _mode = (Mode)scan.get_int8(); + _channels = scan.get_uint8(); } diff --git a/panda/src/pgraph/colorWriteAttrib.h b/panda/src/pgraph/colorWriteAttrib.h index a86a54815f..57312a851a 100644 --- a/panda/src/pgraph/colorWriteAttrib.h +++ b/panda/src/pgraph/colorWriteAttrib.h @@ -34,18 +34,24 @@ class FactoryParams; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA ColorWriteAttrib : public RenderAttrib { 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: - INLINE ColorWriteAttrib(Mode mode = M_on); + INLINE ColorWriteAttrib(unsigned int channels = C_all); 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: virtual void output(ostream &out) const; @@ -56,7 +62,7 @@ protected: virtual RenderAttrib *make_default_impl() const; private: - Mode _mode; + int _channels; public: static void register_with_read_factory();