Browse Source

fix assertion failure

David Rose 19 years ago
parent
commit
57e22c3279

+ 7 - 7
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -1721,6 +1721,8 @@ reset() {
     _max_cube_map_dimension = _max_texture_dimension;
     _max_cube_map_dimension = _max_texture_dimension;
   }
   }
 
 
+  _num_active_texture_stages = 0;
+
   _max_lights = (int)d3d_caps.MaxActiveLights;
   _max_lights = (int)d3d_caps.MaxActiveLights;
   _max_clip_planes = (int)d3d_caps.MaxUserClipPlanes;
   _max_clip_planes = (int)d3d_caps.MaxUserClipPlanes;
   _max_vertex_transforms = d3d_caps.MaxVertexBlendMatrices;
   _max_vertex_transforms = d3d_caps.MaxVertexBlendMatrices;
@@ -2513,13 +2515,8 @@ do_issue_texture() {
   DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
   DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
 
 
   int num_stages = _effective_texture->get_num_on_stages();
   int num_stages = _effective_texture->get_num_on_stages();
-  int num_old_stages = _max_texture_stages;
-  if (_state._texture != (TextureAttrib *)NULL) {
-    num_old_stages = _state._texture->get_num_on_stages();
-  }
-
   nassertv(num_stages <= _max_texture_stages &&
   nassertv(num_stages <= _max_texture_stages &&
-           num_old_stages <= _max_texture_stages);
+           _num_active_texture_stages <= _max_texture_stages);
 
 
   _texture_involves_color_scale = false;
   _texture_involves_color_scale = false;
 
 
@@ -2715,9 +2712,12 @@ do_issue_texture() {
   }
   }
 
 
   // Disable the texture stages that are no longer used.
   // Disable the texture stages that are no longer used.
-  for (i = num_stages; i < num_old_stages; i++) {
+  for (i = num_stages; i < _num_active_texture_stages; i++) {
     _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
     _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
   }
   }
+
+  // Save the count of texture stages for next time.
+  _num_active_texture_stages = num_stages;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 2 - 0
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -235,6 +235,8 @@ protected:
   const DXVertexBufferContext8 *_active_vbuffer;
   const DXVertexBufferContext8 *_active_vbuffer;
   const DXIndexBufferContext8 *_active_ibuffer;
   const DXIndexBufferContext8 *_active_ibuffer;
 
 
+  int _num_active_texture_stages;
+
   bool _overlay_windows_supported;
   bool _overlay_windows_supported;
   bool _tex_stats_retrieval_impossible;
   bool _tex_stats_retrieval_impossible;
 
 

+ 9 - 8
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -2349,6 +2349,7 @@ void DXGraphicsStateGuardian9::reset_render_states (void)
     texture_render_states -> state_array [D3DSAMP_MINFILTER] = D3DTEXF_POINT;
     texture_render_states -> state_array [D3DSAMP_MINFILTER] = D3DTEXF_POINT;
     texture_render_states -> state_array [D3DSAMP_MAXANISOTROPY] = 1;
     texture_render_states -> state_array [D3DSAMP_MAXANISOTROPY] = 1;
   }
   }
+  _num_active_texture_stages = 0;
 
 
   set_render_state(D3DRS_NORMALIZENORMALS, false);
   set_render_state(D3DRS_NORMALIZENORMALS, false);
 
 
@@ -3595,13 +3596,8 @@ do_issue_texture() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 void CLP(GraphicsStateGuardian)::
 disable_standard_texture_bindings() {
 disable_standard_texture_bindings() {
-  int num_old_stages = _max_texture_stages;
-  if (_state._texture != (TextureAttrib *)NULL) {
-    num_old_stages = _state._texture->get_num_on_stages();
-  }
-
   // Disable the texture stages that are no longer used.
   // Disable the texture stages that are no longer used.
-  for (int i = 0; i < num_old_stages; i++) {
+  for (int i = 0; i < _num_active_texture_stages; i++) {
     HRESULT hr;
     HRESULT hr;
 
 
     hr = _d3d_device -> SetTexture (i, NULL);
     hr = _d3d_device -> SetTexture (i, NULL);
@@ -3613,6 +3609,8 @@ disable_standard_texture_bindings() {
         << D3DERRORSTRING(hr);
         << D3DERRORSTRING(hr);
     }
     }
   }
   }
+
+  _num_active_texture_stages = 0;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -3631,7 +3629,7 @@ update_standard_texture_bindings() {
   }
   }
 
 
   nassertv(num_stages <= _max_texture_stages &&
   nassertv(num_stages <= _max_texture_stages &&
-           num_old_stages <= _max_texture_stages);
+           _num_active_texture_stages <= _max_texture_stages);
 
 
   _texture_involves_color_scale = false;
   _texture_involves_color_scale = false;
 
 
@@ -3827,10 +3825,13 @@ update_standard_texture_bindings() {
   }
   }
 
 
   // Disable the texture stages that are no longer used.
   // Disable the texture stages that are no longer used.
-  for (i = num_stages; i < num_old_stages; i++) {
+  for (i = num_stages; i < _num_active_texture_stages; i++) {
     set_texture_stage_state(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
     set_texture_stage_state(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
     _d3d_device->SetTexture(i, NULL);
     _d3d_device->SetTexture(i, NULL);
   }
   }
+
+  // Save the count of texture stages for next time.
+  _num_active_texture_stages = num_stages;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

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

@@ -345,6 +345,8 @@ protected:
   TextureStageStates _texture_stage_states_array [D3D_MAXTEXTURESTAGES];
   TextureStageStates _texture_stage_states_array [D3D_MAXTEXTURESTAGES];
   TextureRenderStates _texture_render_states_array [MAXIMUM_TEXTURES];
   TextureRenderStates _texture_render_states_array [MAXIMUM_TEXTURES];
 
 
+  int _num_active_texture_stages;
+
   int _vertex_shader_version_major;
   int _vertex_shader_version_major;
   int _vertex_shader_version_minor;
   int _vertex_shader_version_minor;
   int _pixel_shader_version_major;
   int _pixel_shader_version_major;