Browse Source

use D3DTA_CONSTANT

David Rose 20 years ago
parent
commit
742c4173b8

+ 22 - 16
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -2021,8 +2021,15 @@ reset() {
 
 
   _supports_texture_combine = ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0);
   _supports_texture_combine = ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0);
   _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
   _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
+  _supports_texture_constant_color = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT) != 0);
   _supports_texture_dot3 = true;
   _supports_texture_dot3 = true;
 
 
+  if (_supports_texture_constant_color) {
+    _constant_color_operand = D3DTA_CONSTANT;
+  } else {
+    _constant_color_operand = D3DTA_TFACTOR;
+  }
+
   _screen->_supports_dynamic_textures = ((d3d_caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) != 0);
   _screen->_supports_dynamic_textures = ((d3d_caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) != 0);
 
 
   _screen->_managed_textures = _gsg_managed_textures;
   _screen->_managed_textures = _gsg_managed_textures;
@@ -3682,7 +3689,7 @@ set_texture_blend_mode(int i, const TextureStage *stage) {
       _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_LERP);
       _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_LERP);
       _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG0, D3DTA_TEXTURE);
       _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG0, D3DTA_TEXTURE);
       _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
       _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
-      _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TFACTOR);
+      _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, _constant_color_operand);
 
 
       _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
       _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
       _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
       _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
@@ -3771,15 +3778,7 @@ set_texture_blend_mode(int i, const TextureStage *stage) {
   if (stage->uses_color()) {
   if (stage->uses_color()) {
     // Set up the constant color for this stage.
     // Set up the constant color for this stage.
 
 
-    // Actually, DX8 doesn't support a per-stage constant color, but
-    // it does support one TEXTUREFACTOR color for the whole pipeline.
-    // This does mean you can't have two different blends in effect
-    // with different colors on the same object.  However, DX9 does
-    // support a per-stage constant color with the D3DTA_CONSTANT
-    // argument--so we should implement that when this code gets
-    // ported to DX9.
-
-    D3DCOLOR texture_factor;
+    D3DCOLOR constant_color;
     if (stage->involves_color_scale() && _color_scale_enabled) {
     if (stage->involves_color_scale() && _color_scale_enabled) {
       Colorf color = stage->get_color();
       Colorf color = stage->get_color();
       color.set(color[0] * _current_color_scale[0],
       color.set(color[0] * _current_color_scale[0],
@@ -3787,11 +3786,18 @@ set_texture_blend_mode(int i, const TextureStage *stage) {
                 color[2] * _current_color_scale[2],
                 color[2] * _current_color_scale[2],
                 color[3] * _current_color_scale[3]);
                 color[3] * _current_color_scale[3]);
       _texture_involves_color_scale = true;
       _texture_involves_color_scale = true;
-      texture_factor = Colorf_to_D3DCOLOR(color);
+      constant_color = Colorf_to_D3DCOLOR(color);
     } else {
     } else {
-      texture_factor = Colorf_to_D3DCOLOR(stage->get_color());
+      constant_color = Colorf_to_D3DCOLOR(stage->get_color());
+    }
+    if (_supports_texture_constant_color) {
+      _d3d_device->SetTextureStageState(i, D3DTSS_CONSTANT, constant_color);
+    } else {
+      // This device doesn't supoprt a per-stage constant color, so we
+      // have to fall back to a single constant color for the overall
+      // texture pipeline.
+      _d3d_device->SetRenderState(D3DRS_TEXTUREFACTOR, constant_color);
     }
     }
-    _d3d_device->SetRenderState(D3DRS_TEXTUREFACTOR, texture_factor);
   }
   }
 }
 }
 
 
@@ -4172,14 +4178,14 @@ get_texture_operation(TextureStage::CombineMode mode, int scale) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian9::get_texture_argument
 //     Function: DXGraphicsStateGuardian9::get_texture_argument
-//       Access: Protected, Static
+//       Access: Protected
 //  Description: Returns the D3DTA value corresponding to the
 //  Description: Returns the D3DTA value corresponding to the
 //               indicated TextureStage::CombineSource and
 //               indicated TextureStage::CombineSource and
 //               TextureStage::CombineOperand enumerated types.
 //               TextureStage::CombineOperand enumerated types.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 DWORD DXGraphicsStateGuardian9::
 DWORD DXGraphicsStateGuardian9::
 get_texture_argument(TextureStage::CombineSource source,
 get_texture_argument(TextureStage::CombineSource source,
-                     TextureStage::CombineOperand operand) {
+                     TextureStage::CombineOperand operand) const {
   switch (source) {
   switch (source) {
   case TextureStage::CS_undefined:
   case TextureStage::CS_undefined:
   case TextureStage::CS_texture:
   case TextureStage::CS_texture:
@@ -4187,7 +4193,7 @@ get_texture_argument(TextureStage::CombineSource source,
 
 
   case TextureStage::CS_constant:
   case TextureStage::CS_constant:
   case TextureStage::CS_constant_color_scale:
   case TextureStage::CS_constant_color_scale:
-    return D3DTA_TFACTOR | get_texture_argument_modifier(operand);
+    return _constant_color_operand | get_texture_argument_modifier(operand);
 
 
   case TextureStage::CS_primary_color:
   case TextureStage::CS_primary_color:
     return D3DTA_DIFFUSE | get_texture_argument_modifier(operand);
     return D3DTA_DIFFUSE | get_texture_argument_modifier(operand);

+ 4 - 2
panda/src/dxgsg9/dxGraphicsStateGuardian9.h

@@ -181,8 +181,8 @@ protected:
   static D3DTEXTUREFILTERTYPE get_d3d_min_type(Texture::FilterType filter_type);
   static D3DTEXTUREFILTERTYPE get_d3d_min_type(Texture::FilterType filter_type);
   static D3DTEXTUREFILTERTYPE get_d3d_mip_type(Texture::FilterType filter_type);
   static D3DTEXTUREFILTERTYPE get_d3d_mip_type(Texture::FilterType filter_type);
   static D3DTEXTUREOP get_texture_operation(TextureStage::CombineMode mode, int scale);
   static D3DTEXTUREOP get_texture_operation(TextureStage::CombineMode mode, int scale);
-  static DWORD get_texture_argument(TextureStage::CombineSource source,
-                                    TextureStage::CombineOperand operand);
+  DWORD get_texture_argument(TextureStage::CombineSource source,
+			     TextureStage::CombineOperand operand) const;
   static DWORD get_texture_argument_modifier(TextureStage::CombineOperand operand);
   static DWORD get_texture_argument_modifier(TextureStage::CombineOperand operand);
 
 
   void draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
   void draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
@@ -242,6 +242,8 @@ protected:
 
 
   bool _overlay_windows_supported;
   bool _overlay_windows_supported;
   bool _tex_stats_retrieval_impossible;
   bool _tex_stats_retrieval_impossible;
+  bool _supports_texture_constant_color;
+  DWORD _constant_color_operand;
 
 
   static D3DMATRIX _d3d_ident_mat;
   static D3DMATRIX _d3d_ident_mat;