Browse Source

rearranged fog stuff

cxgeorge 24 years ago
parent
commit
11917fb072

+ 3 - 0
panda/src/dxgsg/config_dxgsg.cxx

@@ -28,6 +28,9 @@ bool dx_cull_traversal = config_dxgsg.GetBool("dx-cull-traversal", true);
 bool dx_ignore_mipmaps = config_dxgsg.GetBool("dx-ignore-mipmaps", false);
 float dx_global_miplevel_bias = config_dxgsg.GetFloat("dx-global-miplevel-bias", 0.0);
 
+// if true, if card only supports per-vertex fog, it will be treated as no-HW fog capability
+bool dx_no_vertex_fog = config_dxgsg.GetBool("dx-no-vertex-fog", false);
+
 bool dx_force_16bpp_screenbuffers = config_dxgsg.GetBool("dx-force-16bpp-screenbuffers", false);
 bool dx_show_fps_meter = config_dxgsg.GetBool("show-fps-meter", false);
 float dx_fps_meter_update_interval = max(0.5,config_dxgsg.GetFloat("fps-meter-update-interval", 1.7));

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

@@ -17,6 +17,7 @@ extern bool dx_cull_traversal;
 extern bool dx_ignore_mipmaps;
 extern bool dx_force_16bpp_screenbuffers;
 extern bool dx_show_fps_meter;
+extern bool dx_no_vertex_fog;
 extern float dx_fps_meter_update_interval;
 
 #ifdef _DEBUG

+ 63 - 35
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -183,14 +183,13 @@ reset() {
 	GraphicsStateGuardian::reset();
 	_buffer_mask = 0;
 
-	// All implementations have the following buffers. (?)
+	// All implementations have the following buffers. 
 	_buffer_mask = (RenderBuffer::T_color |
 					RenderBuffer::T_depth |
-					RenderBuffer::T_stencil |
-					RenderBuffer::T_accum );
-
-	// WBD  for now, let's assume a back buffer too);
-	_buffer_mask |= RenderBuffer::T_back;
+					RenderBuffer::T_back  
+//					RenderBuffer::T_stencil |
+//					RenderBuffer::T_accum 
+					);
 
 	_current_projection_mat = LMatrix4f::ident_mat();
 	_projection_mat_stack_count = 0;
@@ -885,6 +884,22 @@ render_subgraph(RenderTraverser *traverser,
 	_current_projection_mat = projection_mat;
 	_projection_mat_stack_count++;
 
+#ifdef _DEBUG 
+   {
+   	  static bool bPrintedMsg=false;
+
+	  if((!bPrintedMsg) && !IS_NEARLY_EQUAL(projection_mat(2,3),1.0f)) {
+	     bPrintedMsg=true;
+   	     dxgsg_cat.info() << "non w-compliant render_subgraph projection matrix [2][3]: " << projection_mat(2,3) << endl;
+  	     dxgsg_cat.info() << "cur projection matrix: " << projection_mat << endl;
+	  }
+
+	  // note: a projection matrix that does not have a [3][4] value of 1.0 is
+	  //       not w-compliant and could cause problems with fog
+
+	}
+#endif
+
 	// We load the projection matrix directly.
 	HRESULT res = 
 	_d3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
@@ -917,9 +932,7 @@ render_subgraph(RenderTraverser *traverser,
 
 
 	// We must now restore the projection matrix from before.  We could
-	// do a push/pop matrix, but OpenGL doesn't promise more than 2
-	// levels in the projection matrix stack, so we'd better do it in
-	// the CPU.
+	// do a push/pop matrix if we were using D3DX
 	if (_projection_mat_stack_count > 0)
 		_d3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
 								 (LPD3DMATRIX) _current_projection_mat.get_data());
@@ -3259,16 +3272,10 @@ apply_texture(TextureContext *tc) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 release_texture(TextureContext *tc) {
-	activate();
 	DXTextureContext *gtc = DCAST(DXTextureContext, tc);
 	Texture *tex = tc->_texture;
 
-#ifdef WBD_GL_MODE
-	glDeleteTextures(1, &gtc->_index);
-	gtc->_index = 0;
-#else
 	gtc->DeleteTexture();
-#endif              // WBD_GL_MODE
 	bool erased = unmark_prepared_texture(gtc);
 
 	// If this assertion fails, a texture was released that hadn't been
@@ -3280,6 +3287,14 @@ release_texture(TextureContext *tc) {
 	delete gtc;
 }
 
+#if 1
+
+void DXGraphicsStateGuardian::
+copy_texture(TextureContext *tc, const DisplayRegion *dr) {
+	dxgsg_cat.fatal() << "DX copy_texture unimplemented!!!";
+}
+
+#else
 static int logs[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
 	4096, 0};
 
@@ -3301,10 +3316,7 @@ static int binary_log_cap(const int x) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 copy_texture(TextureContext *tc, const DisplayRegion *dr) {
-	dxgsg_cat.fatal() << "DX copy_texture unimplemented!!!";
-	return;
 
-#if 0
 	nassertv(tc != NULL && dr != NULL);
 	activate();
 
@@ -3331,14 +3343,13 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr) {
 	pb->set_ysize(h);
 
 
-//#ifdef WBD_GL_MODE
 	bind_texture(tc);
 	glCopyTexImage2D( GL_TEXTURE_2D, tex->get_level(), 
 					  get_internal_image_format(pb->get_format()),
 					  pb->get_xorg(), pb->get_yorg(),
 					  pb->get_xsize(), pb->get_ysize(), pb->get_border() );
-#endif              // WBD_GL_MODE
 }
+#endif
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::copy_texture
@@ -3722,22 +3733,30 @@ void DXGraphicsStateGuardian::apply_material( const Material* material ) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 apply_fog(Fog *fog) {
-      // need to re-examine this fog stuff
 
 	Fog::Mode panda_fogmode = fog->get_mode();
 	D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode);
 
 	if(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE ) {
   	   _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, d3dfogmode);
-	} else if(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX ) {
-	  _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, d3dfogmode);
+	} else {
+
+	  // vtx fog looks crappy if you have large polygons in the foreground
+	  if(dx_no_vertex_fog)
+		  return;
+
+		//if(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX )
+		// every card is going to have vertex fog, since it's implemented in d3d runtime
+
+      _d3dDevice->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, d3dfogmode);
 	}
 
 	switch (panda_fogmode) {
 		case Fog::M_linear:
 			{
-				float fog_start = fog->get_start();   
-				float fog_end = fog->get_end();   
+				float fog_start,fog_end;
+				fog->get_range(fog_start,fog_end);
+
 				_d3dDevice->SetRenderState( D3DRENDERSTATE_FOGSTART, 
 							*((LPDWORD) (&fog_start)) );
 				_d3dDevice->SetRenderState( D3DRENDERSTATE_FOGEND, 
@@ -3745,15 +3764,13 @@ apply_fog(Fog *fog) {
 			}
 			break;
 		case Fog::M_exponential:
-		case Fog::M_super_exponential:
+		case Fog::M_exponential_squared:
 			{
 				float fog_density = fog->get_density();   
 				_d3dDevice->SetRenderState( D3DRENDERSTATE_FOGDENSITY, 
 							*((LPDWORD) (&fog_density)) );
 			}
 			break;
-		case Fog::M_spline:
-			break;
 	}
 
 	Colorf  fog_colr = fog->get_color();
@@ -4561,7 +4578,6 @@ issue_depth_test(const DepthTestAttribute *attrib) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 issue_depth_write(const DepthWriteAttribute *attrib) {
-	activate();
 	_d3dDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, attrib->is_on());
 }
 
@@ -4572,9 +4588,18 @@ issue_depth_write(const DepthWriteAttribute *attrib) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 issue_stencil(const StencilAttribute *attrib) {
-	activate();
+  
+  StencilProperty::Mode mode = attrib->get_mode();
+
+#if 1
+  if (mode != StencilProperty::M_none) {
+	dxgsg_cat.error() << "stencil buffering unimplemented for DX GSG renderer!!!\n";    
+	// to implement stenciling, need to change wdxGraphicsWindow to create a stencil 
+	// z-buffer or maybe do a SetRenderTarget on a new zbuffer
+  }
+	
+#else
 
-	StencilProperty::Mode mode = attrib->get_mode();
 	if (mode == StencilProperty::M_none) {
 		enable_stencil_test(false);
 
@@ -4585,6 +4610,7 @@ issue_stencil(const StencilAttribute *attrib) {
 		_d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILFAIL, get_stencil_action_type(attrib->get_action()));
 		_d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILZFAIL, get_stencil_action_type(attrib->get_action()));
 	}
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -4769,7 +4795,6 @@ issue_transparency(const TransparencyAttribute *attrib ) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 issue_linesmooth(const LinesmoothAttribute *attrib) {
-	activate();
 	enable_line_smooth(attrib->is_on());
 }
 
@@ -5049,7 +5074,7 @@ set_read_buffer(const RenderBuffer &rb) {
 //               GL's.
 ////////////////////////////////////////////////////////////////////
 INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian::
-get_texture_wrap_mode(Texture::WrapMode wm) {
+get_texture_wrap_mode(Texture::WrapMode wm) const {
 
 	if (wm == Texture::WM_clamp)
 		return D3DTADDRESS_CLAMP;
@@ -5084,6 +5109,9 @@ get_depth_func_type(DepthTestProperty::Mode m) const {
 	return D3DCMP_LESS;
 }
 
+#if 0
+// ifdef out until stencil zbuf creation works in wdxGraphicsWindow.c
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::get_stencil_func_type
 //       Access: Protected
@@ -5127,6 +5155,7 @@ get_stencil_action_type(StencilProperty::Action a) const {
 	return D3DSTENCILOP_KEEP;
 }
 
+#endif
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::get_fog_mode_type
@@ -5138,13 +5167,12 @@ get_fog_mode_type(Fog::Mode m) const {
 	switch (m) {
 		case Fog::M_linear: return D3DFOG_LINEAR;
 		case Fog::M_exponential: return D3DFOG_EXP;
-		case Fog::M_super_exponential: return D3DFOG_EXP2;
+		case Fog::M_exponential_squared: return D3DFOG_EXP2;
 	}
 	dxgsg_cat.error() << "Invalid Fog::Mode value" << endl;
 	return D3DFOG_EXP;
 }
 
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::free_pointers
 //       Access: Public

+ 9 - 6
panda/src/dxgsg/dxGraphicsStateGuardian.h

@@ -230,6 +230,15 @@ protected:
   INLINE void enable_fog(bool val);
   INLINE void set_shademode(D3DSHADEMODE val);
 
+  INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm) const;
+  INLINE D3DCMPFUNC get_depth_func_type(DepthTestProperty::Mode m) const;
+  INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const;
+
+  #if 0
+    INLINE D3DCMPFUNC get_stencil_func_type(StencilProperty::Mode m) const;
+    INLINE D3DSTENCILOP get_stencil_action_type(StencilProperty::Action a) const;
+  #endif
+
 /*  INLINE void enable_multisample_alpha_one(bool val);
   INLINE void enable_multisample_alpha_mask(bool val);
   INLINE void enable_multisample(bool val, LPDIRECT3DDEVICE7 d3dDevice);
@@ -247,12 +256,6 @@ protected:
   INLINE void enable_stencil_test(bool val);
   bool enable_light(int light, bool val);
 
-  INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm);
-  INLINE D3DCMPFUNC get_depth_func_type(DepthTestProperty::Mode m) const;
-  INLINE D3DCMPFUNC get_stencil_func_type(StencilProperty::Mode m) const;
-  INLINE D3DSTENCILOP get_stencil_action_type(StencilProperty::Action a) const;
-  INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const;
-
   void draw_prim_inner_loop(int nVerts, const Geom *geom, DWORD perFlags);
   size_t draw_prim_setup(const Geom *geom) ;
   void draw_multitri(const Geom *geom, D3DPRIMITIVETYPE tri_id);

+ 12 - 8
panda/src/glgsg/glGraphicsStateGuardian.cxx

@@ -329,6 +329,9 @@ reset() {
       << "Setting glHint() for fastest textures.\n";
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
   }
+
+  // use per-vertex fog if per-pixel fog requires SW renderer
+  glHint(GL_FOG_HINT,GL_DONT_CARE);  
 }
 
 
@@ -2222,18 +2225,19 @@ void GLGraphicsStateGuardian::apply_material(const Material *material) {
 ////////////////////////////////////////////////////////////////////
 void GLGraphicsStateGuardian::
 apply_fog(Fog *fog) {
-  call_glFogMode(get_fog_mode_type(fog->get_mode()));
-  switch(fog->get_mode()) {
+  Fog::Mode fmode=fog->get_mode();
+  call_glFogMode(get_fog_mode_type(fmode));
+  switch(fmode) {
     case Fog::M_linear:
-      call_glFogStart(fog->get_start());
-      call_glFogEnd(fog->get_end());
+		float fog_start,fog_end;
+		fog->get_range(fog_start,fog_end);
+		call_glFogStart(fog_start);
+		call_glFogEnd(fog_end);
       break;
     case Fog::M_exponential:
-    case Fog::M_super_exponential:
+    case Fog::M_exponential_squared:
       call_glFogDensity(fog->get_density());
       break;
-    case Fog::M_spline:
-      break;
   }
   call_glFogColor(fog->get_color());
   report_errors();
@@ -3856,7 +3860,7 @@ get_fog_mode_type(Fog::Mode m) const {
   switch(m) {
     case Fog::M_linear: return GL_LINEAR;
     case Fog::M_exponential: return GL_EXP;
-    case Fog::M_super_exponential: return GL_EXP2;
+    case Fog::M_exponential_squared: return GL_EXP2;
 #ifdef GL_FOG_FUNC_SGIS
     case Fog::M_spline: return GL_FOG_FUNC_SGIS;
 #endif