Browse Source

fix lighting opt

cxgeorge 24 năm trước cách đây
mục cha
commit
3a886fda0f

+ 2 - 1
panda/src/dxgsg/dxGraphicsStateGuardian.I

@@ -96,8 +96,9 @@ enable_point_smooth(bool val) {
 INLINE void DXGraphicsStateGuardian::
 enable_lighting(bool val) {
   if (_lighting_enabled != val) {   
-    _lighting_enabled = val;
  	_d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)val);
+	if(_lighting_enabled = val)
+      _lighting_enabled_this_frame = true;
   }
 }
 

+ 3 - 1
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -647,6 +647,8 @@ void DXGraphicsStateGuardian::
 render_frame(const AllAttributesWrapper &initial_state) {
 	if (!_dx_ready)	return;
 
+    _lighting_enabled_this_frame = false;
+
 	_win->begin_frame();
 	_d3dDevice->BeginScene();
 
@@ -700,7 +702,7 @@ render_frame(const AllAttributesWrapper &initial_state) {
 
 	_d3dDevice->EndScene();  // FPS meter drawing MUST occur after EndScene, since it uses GDI
 
-	if(_lighting_enabled) { 
+	if (_lighting_enabled_this_frame) {
 		// Let's turn off all the lights we had on, and clear the light
 		// cache--to force the lights to be reissued next frame, in case
 		// their parameters or positions have changed between frames.

+ 1 - 0
panda/src/dxgsg/dxGraphicsStateGuardian.h

@@ -323,6 +323,7 @@ protected:
   bool* _light_enabled;      // bool[_max_lights]
   bool _color_material_enabled;
   bool _lighting_enabled;
+  bool _lighting_enabled_this_frame;
   bool _texturing_enabled;
   bool _dither_enabled;
   bool _stencil_test_enabled;