瀏覽代碼

rearranged fog stuff

cxgeorge 24 年之前
父節點
當前提交
37b59ed463
共有 5 個文件被更改,包括 88 次插入607 次删除
  1. 30 502
      panda/src/dxgsg/dxGraphicsStateGuardian.I
  2. 11 11
      panda/src/dxgsg/dxGraphicsStateGuardian.cxx
  3. 12 46
      panda/src/gobj/fog.I
  4. 27 34
      panda/src/gobj/fog.cxx
  5. 8 14
      panda/src/gobj/fog.h

+ 30 - 502
panda/src/dxgsg/dxGraphicsStateGuardian.I

@@ -15,496 +15,8 @@
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 activate() {
-//  _win->make_current();
 }
 
-
-
-#ifdef WBD_GL_MODE
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glClearColor
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glClearColor(GLclampf red, GLclampf green, GLclampf blue,
-		  GLclampf alpha) {
-  if (red != _clear_color_red ||
-      green != _clear_color_green ||
-      blue != _clear_color_blue ||
-      alpha != _clear_color_alpha) {
-    glClearColor(red, green, blue, alpha);
-    _clear_color_red = red;
-    _clear_color_green = green;
-    _clear_color_blue = blue;
-    _clear_color_alpha = alpha;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glClearDepth
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glClearDepth(GLclampd depth) {
-  if (depth != _clear_depth) {
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug()
-      << "glClearDepth(" << (double)depth << ")" << endl;
-#endif
-    glClearDepth(depth);
-    _clear_depth = depth;
-  }
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glClearStencil
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glClearStencil(GLint s) {
-  if (s != _clear_stencil) {
-    glClearStencil(s);
-    _clear_stencil = s;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glClearAccum
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glClearAccum(GLclampf red, GLclampf green, GLclampf blue,
-		  GLclampf alpha) {
-  if (red != _clear_accum_red ||
-      green != _clear_accum_green ||
-      blue != _clear_accum_blue ||
-      alpha != _clear_accum_alpha) {
-    glClearAccum(red, green, blue, alpha);
-    _clear_accum_red = red;
-    _clear_accum_green = green;
-    _clear_accum_blue = blue;
-    _clear_accum_alpha = alpha;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glDrawBuffer
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glDrawBuffer(GLenum mode) {
-  if (mode != _draw_buffer_mode) {
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug() << "glDrawBuffer(";
-    switch (mode) {
-    case GL_FRONT:
-      dxgsg_cat.debug(false) << "GL_FRONT)"; 
-      break;
-    case GL_BACK:
-      dxgsg_cat.debug(false) << "GL_BACK)"; 
-      break;
-    case GL_RIGHT:
-      dxgsg_cat.debug(false) << "GL_RIGHT)"; 
-      break;
-    case GL_LEFT:
-      dxgsg_cat.debug(false) << "GL_LEFT)"; 
-      break;
-    case GL_FRONT_RIGHT:
-      dxgsg_cat.debug(false) << "GL_FRONT_RIGHT)"; 
-      break;
-    case GL_FRONT_LEFT:
-      dxgsg_cat.debug(false) << "GL_FRONT_LEFT)"; 
-      break;
-    case GL_BACK_RIGHT:
-      dxgsg_cat.debug(false) << "GL_BACK_RIGHT)"; 
-      break;
-    case GL_BACK_LEFT:
-      dxgsg_cat.debug(false) << "GL_BACK_LEFT)"; 
-      break;
-    case GL_FRONT_AND_BACK:
-      dxgsg_cat.debug(false) << "GL_FRONT_AND_BACK)"; 
-      break;
-    }
-    dxgsg_cat.debug(false) << endl;
-#endif
-    glDrawBuffer(mode);
-    _draw_buffer_mode = mode;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glReadBuffer
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glReadBuffer(GLenum mode) {
-  if (mode != _read_buffer_mode) {
-    glReadBuffer(mode);
-    _read_buffer_mode = mode;
-  }
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glShadeModel
-//       Access:
-//  Description: Set the shading model to be either GL_FLAT or GL_SMOOTH
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glShadeModel(GLenum mode) {
-  if (_shade_model_mode != mode) {
-    glShadeModel(mode);
-    _shade_model_mode = mode;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glViewport
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
-{
-    if ( _viewport_x != x || _viewport_y != y ||
-        _viewport_width != width || _viewport_height != height )
-    {   
-        _viewport_x = x; _viewport_y = y;
-        _viewport_width = width; _viewport_height = height;
-        glViewport( x, y, width, height );
-    }
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glStencilFunc
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glStencilFunc(GLenum func) {
-  if (_stencil_func != func) {
-    _stencil_func = func;
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug() << "glStencilFunc(";
-    switch (func) {
-    case GL_NEVER:
-      dxgsg_cat.debug(false) << "GL_NEVER, "; 
-      break;
-    case GL_LESS:
-      dxgsg_cat.debug(false) << "GL_LESS, "; 
-      break;
-    case GL_EQUAL:
-      dxgsg_cat.debug(false) << "GL_EQUAL, "; 
-      break;
-    case GL_LEQUAL:
-      dxgsg_cat.debug(false) << "GL_LEQUAL, "; 
-      break;
-    case GL_GREATER:
-      dxgsg_cat.debug(false) << "GL_GREATER, "; 
-      break;
-    case GL_NOTEQUAL:
-      dxgsg_cat.debug(false) << "GL_NOTEQUAL, "; 
-      break;
-    case GL_GEQUAL:
-      dxgsg_cat.debug(false) << "GL_GEQUAL, "; 
-      break;
-    case GL_ALWAYS:
-      dxgsg_cat.debug(false) << "GL_ALWAYS, "; 
-      break;
-    default:
-      dxgsg_cat.debug(false) << "unknown, "; 
-      break;
-    }
-    dxgsg_cat.debug(false) << "1, 1)" << endl;
-#endif
-    glStencilFunc(func, 1, 1);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glStencilOp
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glStencilOp(GLenum op) {
-  if (_stencil_op != op) {
-    _stencil_op = op;
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug() << "glStencilOp(GL_KEEP, GL_KEEP, ";
-    switch (op) {
-    case GL_KEEP:
-      dxgsg_cat.debug(false) << "GL_KEEP)"; 
-      break;
-    case GL_ZERO:
-      dxgsg_cat.debug(false) << "GL_ZERO)"; 
-      break;
-    case GL_REPLACE:
-      dxgsg_cat.debug(false) << "GL_REPLACE)"; 
-      break;
-    case GL_INCR:
-      dxgsg_cat.debug(false) << "GL_INCR)"; 
-      break;
-    case GL_DECR:
-      dxgsg_cat.debug(false) << "GL_DECR)"; 
-      break;
-    case GL_INVERT:
-      dxgsg_cat.debug(false) << "GL_INVERT)"; 
-      break;
-    default:
-      dxgsg_cat.debug(false) << "unknown)"; 
-      break;
-    }
-    dxgsg_cat.debug(false) << endl;
-#endif
-    glStencilOp(GL_KEEP, GL_KEEP, op);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glLineWidth
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glLineWidth(GLfloat width) {
-  if (_line_width != width) {
-    _line_width = width;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glLineWidth(" << width << ")" << endl;
-#endif
-    glLineWidth(width);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glPointSize
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glPointSize(GLfloat size) {
-  if (_point_size != size) {
-    _point_size = size;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glPointSize(" << size << ")" << endl;
-#endif
-    glPointSize(size);
-  }
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glFogMode
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glFogMode(GLint mode) {
-  if (_fog_mode != mode) {
-    _fog_mode = mode;
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug() << "glFog(GL_FOG_MODE, ";
-    switch(mode) {
-    case GL_LINEAR:
-      dxgsg_cat.debug(false) << "GL_LINEAR)" << endl; 
-      break;
-    case GL_EXP:
-      dxgsg_cat.debug(false) << "GL_EXP)" << endl; 
-      break;
-    case GL_EXP2:
-      dxgsg_cat.debug(false) << "GL_EXP2)" << endl; 
-      break;
-#ifdef GL_FOG_FUNC_SGIS
-    case GL_FOG_FUNC_SGIS:
-      dxgsg_cat.debug(false) << "GL_FOG_FUNC_SGIS)" << endl; 
-      break;
-#endif
-    default:
-      dxgsg_cat.debug(false) << "unknown)" << endl; 
-      break;
-    }
-#endif
-    glFogi(GL_FOG_MODE, mode);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glFogStart
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glFogStart(GLfloat start) {
-  if (_fog_start != start) {
-    _fog_start = start;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glFog(GL_FOG_START, " << start << ")" << endl;
-#endif
-    glFogf(GL_FOG_START, start);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glFogEnd
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glFogEnd(GLfloat end) {
-  if (_fog_end != end) {
-    _fog_end = end;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glFog(GL_FOG_END, " << end << ")" << endl;
-#endif
-    glFogf(GL_FOG_END, end);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glFogDensity
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glFogDensity(GLfloat density) {
-  if (_fog_density != density) {
-    _fog_density = density;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glFog(GL_FOG_DENSITY, " << density << ")" << endl;
-#endif
-    glFogf(GL_FOG_DENSITY, density);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glFogColor
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glFogColor(const Colorf &color) {
-  if (_fog_color != color) {
-    _fog_color = color;
-#ifdef GSG_VERBOSE
-  dxgsg_cat.debug()
-    << "glFog(GL_FOG_COLOR, " << color << ")" << endl;
-#endif
-    glFogfv(GL_FOG_COLOR, color.get_data());
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::call_glAlphaFunc
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-call_glAlphaFunc(GLenum func, GLclampf ref) {
-  if (_alpha_func != func || _alpha_func_ref != ref) {
-    _alpha_func = func;
-    _alpha_func_ref = ref;
-#ifdef GSG_VERBOSE
-    dxgsg_cat.debug() << "glAlphaFunc(";
-    switch (func) {
-    case GL_NEVER:
-      dxgsg_cat.debug(false) << "GL_NEVER, "; 
-      break;
-    case GL_LESS:
-      dxgsg_cat.debug(false) << "GL_LESS, "; 
-      break;
-    case GL_EQUAL:
-      dxgsg_cat.debug(false) << "GL_EQUAL, "; 
-      break;
-    case GL_LEQUAL:
-      dxgsg_cat.debug(false) << "GL_LEQUAL, "; 
-      break;
-    case GL_GREATER:
-      dxgsg_cat.debug(false) << "GL_GREATER, "; 
-      break;
-    case GL_NOTEQUAL:
-      dxgsg_cat.debug(false) << "GL_NOTEQUAL, "; 
-      break;
-    case GL_GEQUAL:
-      dxgsg_cat.debug(false) << "GL_GEQUAL, "; 
-      break;
-    case GL_ALWAYS:
-      dxgsg_cat.debug(false) << "GL_ALWAYS, "; 
-      break;
-    }
-    dxgsg_cat.debug() << ref << ")" << endl;
-#endif
-    glAlphaFunc(func, ref); 
-  }
-}
-
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::get_light_id
-//       Access: Public
-//  Description: Convert index to gl light id
-////////////////////////////////////////////////////////////////////
-INLINE GLenum DXGraphicsStateGuardian::get_light_id(int index) const
-{
-    switch( index )
-    {   
-        case 0: return GL_LIGHT0;
-        case 1: return GL_LIGHT1;
-        case 2: return GL_LIGHT2;
-        case 3: return GL_LIGHT3;
-        case 4: return GL_LIGHT4;
-        case 5: return GL_LIGHT5;
-        case 6: return GL_LIGHT6;
-        case 7: return GL_LIGHT7;
-        default:
-            dxgsg_cat.error()
-	      << "get_light_id() - we don't currently support ids "
-	      << "> 8" << endl;
-            break;
-    }
-    return GL_LIGHT0;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::get_clip_plane_id
-//       Access: Public
-//  Description: Convert index to gl clip plane id
-////////////////////////////////////////////////////////////////////
-INLINE GLenum DXGraphicsStateGuardian::
-get_clip_plane_id(int index) const {
-  switch(index) {
-    case 0: return GL_CLIP_PLANE0;
-    case 1: return GL_CLIP_PLANE1;
-    case 2: return GL_CLIP_PLANE2;
-    case 3: return GL_CLIP_PLANE3;
-    case 4: return GL_CLIP_PLANE4;
-    case 5: return GL_CLIP_PLANE5;
-    default:
-      dxgsg_cat.error()
-	<< "get_clip_plane_id() - we don't currently support ids "
-	<< "> 5" << endl;
-      break;
-  }
-  return GL_CLIP_PLANE0;
-}
-
-
-#endif		// WBD_GL_MODE
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::set_pack_alignment
 //       Access:
@@ -512,7 +24,9 @@ get_clip_plane_id(int index) const {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 set_pack_alignment(int alignment) {
-    dxgsg_cat.error() << "set_pack_alignment() unimplemented, has no meaning in DX\n";
+  #ifdef NDEBUG
+	dxgsg_cat.error() << "set_pack_alignment() unimplemented, has no meaning in DX\n";
+  #endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -522,7 +36,9 @@ set_pack_alignment(int alignment) {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 set_unpack_alignment(int alignment) {
-   dxgsg_cat.error() << "set_unpack_alignment() unimplemented, has no meaning in DX\n";
+  #ifdef NDEBUG
+    dxgsg_cat.error() << "set_unpack_alignment() unimplemented, has no meaning in DX\n";
+  #endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -532,9 +48,10 @@ set_unpack_alignment(int alignment) {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 enable_multisample(bool val) {
-  if (_multisample_enabled != val) {   
-    _multisample_enabled = val;
-  }
+  _multisample_enabled = val;
+  #ifdef NDEBUG
+    dxgsg_cat.error() << "dx multisample unimplemented!!\n";
+  #endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -544,8 +61,15 @@ enable_multisample(bool val) {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 enable_line_smooth(bool val) {
-  if (_line_smooth_enabled != val) {   
+  if(_line_smooth_enabled != val) {   
     _line_smooth_enabled = val;
+  #ifdef NDEBUG
+	{
+    	if(val && (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES)) 
+           dxgsg_cat.error() << "no HW support for line smoothing!!\n";
+	}
+  #endif
+  
  	_d3dDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, (DWORD)val);
   }
 }
@@ -557,9 +81,10 @@ enable_line_smooth(bool val) {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian::
 enable_point_smooth(bool val) {
-  if (_point_smooth_enabled != val) {   
-    _point_smooth_enabled = val;
-  }
+  _point_smooth_enabled = val;
+  #ifdef NDEBUG
+    dxgsg_cat.error() << "dx point smoothing unimplemented!!\n";
+  #endif
 }
 
 
@@ -585,6 +110,14 @@ INLINE void DXGraphicsStateGuardian::
 enable_dither(bool val) {
   if (_dither_enabled != val) {
     _dither_enabled = val;
+
+  #ifdef NDEBUG
+	{
+    	if(val && (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)) 
+           dxgsg_cat.error() << "no HW support for color dithering!!\n";
+	}
+  #endif
+    
 	_d3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, (DWORD)val);
   }
 }
@@ -700,9 +233,6 @@ enable_fog(bool val) {
   }
 }
 
-
-
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::enable_alpha_test
 //       Access:
@@ -717,8 +247,6 @@ enable_alpha_test(bool val )
   }
 }
 
-
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::call_dxLightModelAmbient
 //       Access:

+ 11 - 11
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -395,7 +395,7 @@ init_dx(  LPDIRECTDRAW7     context,
 
 	// Antialiasing.
 	enable_line_smooth(false);
-	enable_multisample(true);
+//	enable_multisample(true);
 
 	// technically DX7's front-end has no limit on the number of lights, but it's simpler for
 	// this implementation to set a small GL-like limit to make the light array traversals short
@@ -4742,8 +4742,8 @@ issue_transparency(const TransparencyAttribute *attrib ) {
 
 	switch (mode) {
 		case TransparencyProperty::M_none:
-			enable_multisample_alpha_one(false);
-			enable_multisample_alpha_mask(false);
+//			enable_multisample_alpha_one(false);
+//			enable_multisample_alpha_mask(false);
 			enable_blend(false);
 			enable_alpha_test(false);
 			break;
@@ -4756,27 +4756,27 @@ issue_transparency(const TransparencyAttribute *attrib ) {
 			// implicitly requires a bit more logic here and in the state
 			// management; for now we require the user to explicitly turn off
 			// the depth write.
-			enable_multisample_alpha_one(false);
-			enable_multisample_alpha_mask(false);
+//			enable_multisample_alpha_one(false);
+//			enable_multisample_alpha_mask(false);
 			enable_blend(true);
 			enable_alpha_test(false);
 			call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
 			break;
 		case TransparencyProperty::M_multisample:
-			enable_multisample_alpha_one(true);
-			enable_multisample_alpha_mask(true);
+//			enable_multisample_alpha_one(true);
+//			enable_multisample_alpha_mask(true);
 			enable_blend(false);
 			enable_alpha_test(false);
 			break;
 		case TransparencyProperty::M_multisample_mask:
-			enable_multisample_alpha_one(false);
-			enable_multisample_alpha_mask(true);
+//			enable_multisample_alpha_one(false);
+//			enable_multisample_alpha_mask(true);
 			enable_blend(false);
 			enable_alpha_test(false);
 			break;
 		case TransparencyProperty::M_binary:
-			enable_multisample_alpha_one(false);
-			enable_multisample_alpha_mask(false);
+//			enable_multisample_alpha_one(false);
+//			enable_multisample_alpha_mask(false);
 			enable_blend(false);
 			enable_alpha_test(true);
 			call_dxAlphaFunc(D3DCMP_EQUAL, 1);

+ 12 - 46
panda/src/gobj/fog.I

@@ -1,5 +1,5 @@
 // Filename: fog.I
-// Created by:  mike (05Feb99)
+// Created by: krisg (05Feb01)
 // 
 ////////////////////////////////////////////////////////////////////
 
@@ -20,7 +20,7 @@ INLINE Fog::Mode Fog::get_mode(void) const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Fog::set_mode(Mode mode) {
   _mode = mode;
-  compute_density();
+//  compute_density();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -47,8 +47,8 @@ INLINE void Fog::set_color(const Colorf &color) {
 //  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void Fog::get_range(float &onset, float &opaque) const {
-  onset = _onset;
-  opaque = _opaque;
+  onset = _onset_distance;
+  opaque = _opaque_distance;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -57,48 +57,9 @@ INLINE void Fog::get_range(float &onset, float &opaque) const {
 //  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void Fog::set_range(float onset, float opaque) {
-  _onset = onset;
-  _opaque = opaque;
-  compute_density();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Fog::get_offsets
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void Fog::get_offsets(float &onset, float &opaque) const {
-  onset = _onset_offset;
-  opaque = _opaque_offset;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Fog::set_offsets
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void Fog::set_offsets(float onset, float opaque) {
-  _onset_offset = onset;
-  _opaque_offset = opaque;
-  compute_density();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Fog::get_start
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE float Fog::get_start(void) const {
-  return _onset + _onset_offset;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Fog::get_end
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE float Fog::get_end(void) const {
-  return _opaque + _opaque_offset;
+  _onset_distance = onset;
+  _opaque_distance = opaque;
+//  compute_density();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -110,6 +71,11 @@ INLINE float Fog::get_density(void) const {
   return _density;
 }
 
+INLINE void Fog::set_density(float fDensity) {
+  assert((fDensity >= 0.0) && (fDensity <= 1.0));
+  _density = fDensity;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Fog::apply
 //       Access: Public

+ 27 - 34
panda/src/gobj/fog.cxx

@@ -11,7 +11,6 @@
 #include "fog.h"
 
 #include <mathNumbers.h>
-
 #include <stddef.h>
 
 ////////////////////////////////////////////////////////////////////
@@ -28,11 +27,8 @@ operator << (ostream &out, Fog::Mode mode) {
   case Fog::M_exponential:
     return out << "exponential";
 
-  case Fog::M_super_exponential:
-    return out << "super_exponential";
-
-  case Fog::M_spline:
-    return out << "spline";
+  case Fog::M_exponential_squared:
+    return out << "exponential-squared";
   }
 
   return out << "**invalid**(" << (int)mode << ")";
@@ -43,25 +39,25 @@ operator << (ostream &out, Fog::Mode mode) {
 //       Access:
 //  Description:
 ////////////////////////////////////////////////////////////////////
-Fog::Fog(Mode mode, int hardware_bits) {
-  _hardware_bits = hardware_bits;
+Fog::Fog(Mode mode, int bits_per_color_channel) {
+  _bits_per_color_channel = bits_per_color_channel;
   set_mode(mode);
-  set_color(Colorf(1.0, 1.0, 1.0, 1.0));
+  set_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
   set_range(0.0f, 100.0f);
-  set_offsets(0.0f, 0.0f);
-  compute_density();
+  
+  _density = 0.5f;
+//  compute_density();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: Fog::Destructor 
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-Fog::~Fog(void) {
-}
+#if 0
+// this fn tries to 'match' exponential to linear fog by computing a exponential density
+// factor such that exponential fog matches linear fog at the linear fog's 'fog-end' distance.
+// usefulness of this is debatable since the exponential fog that matches will be very very
+// close to observer, and it's harder to guess a good end fog distance than it is to manipulate
+// the [0.0,1.0] density range directly, so taking this out
 
 ////////////////////////////////////////////////////////////////////
-//     Function: Fog::set_mode
+//     Function: Fog::compute_density
 //       Access:
 //  Description:
 ////////////////////////////////////////////////////////////////////
@@ -73,21 +69,20 @@ void Fog::compute_density(void) {
     break;
   case M_exponential:
     // Multiplier = ln(2^bits)
-    opaque_multiplier = MathNumbers::ln2 * _hardware_bits;
-    _density = opaque_multiplier / (_opaque + _opaque_offset);
+	// attempt to compute density based on full
+    opaque_multiplier = MathNumbers::ln2 * _bits_per_color_channel;
+    _density = opaque_multiplier / _opaque_distance;
     break;
-  case M_super_exponential:
-    // Multiplier = ln(squrt(2^bits))
-    opaque_multiplier = 0.5f * MathNumbers::ln2 * _hardware_bits;
+  case M_exponential_squared:
+    // Multiplier = ln(sqrt(2^bits))
+    opaque_multiplier = 0.5f * MathNumbers::ln2 * _bits_per_color_channel;
     opaque_multiplier *= opaque_multiplier;
-    _density = opaque_multiplier / (_opaque + _opaque_offset);
-    break;
-  case M_spline:
-    // *** What's this?
+    _density = opaque_multiplier / _opaque_distance;
     break;
   }
 }
 
+#endif
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Fog::output
@@ -98,14 +93,12 @@ void Fog::
 output(ostream &out) const {
   out << "fog:" << _mode;
   switch (_mode) {
-  case M_linear: 
+	  case M_linear: 
     break;
   case M_exponential:
-  case M_super_exponential:
-    out << "(" << _hardware_bits << "," << _density
-	<< "," << _opaque << "," << _opaque_offset << ")";
-    break;
-  case M_spline:
+  case M_exponential_squared:
+    out << "(" << _bits_per_color_channel << "," << _density
+	<< "," << _opaque_distance << ")";
     break;
   };
 }

+ 8 - 14
panda/src/gobj/fog.h

@@ -29,12 +29,12 @@ PUBLISHED:
   enum Mode {
     M_linear,                   // f = (end - z) / (end - start)
     M_exponential,              // f = e^(-density * z)
-    M_super_exponential,        // f = e^(-density * z)^2
-    M_spline,                   // Not implemented yet
+    M_exponential_squared       // f = e^((-density * z)^2)
   };
 
-  Fog(Mode mode = M_linear, int hardware_bits = 8);
-  ~Fog();
+  Fog(Mode mode = M_linear, int bits_per_color_channel = 8);
+
+  INLINE ~Fog(void) {};
 
   INLINE Mode get_mode(void) const;
   INLINE void set_mode(Mode mode);
@@ -44,13 +44,9 @@ PUBLISHED:
 
   INLINE void get_range(float &onset, float &opaque) const;
   INLINE void set_range(float onset, float opaque);
- 
-  INLINE void get_offsets(float &onset, float &opaque) const;
-  INLINE void set_offsets(float onset, float opaque);
 
-  INLINE float get_start(void) const;
-  INLINE float get_end(void) const;
   INLINE float get_density(void) const;
+  INLINE void set_density(float fDensity);
 
   void output(ostream &out) const;
 
@@ -62,12 +58,10 @@ protected:
 
 protected:
   Mode			_mode;
-  int			_hardware_bits;
+  int			_bits_per_color_channel;
   Colorf		_color;
-  float			_onset;
-  float			_opaque;
-  float			_onset_offset;
-  float			_opaque_offset;
+  float			_onset_distance;
+  float			_opaque_distance;
   float 		_density;
 
 public: