Browse Source

new clip plane interface

David Rose 23 years ago
parent
commit
591e054123

+ 0 - 21
panda/src/dxgsg/dxGraphicsStateGuardian.I

@@ -86,27 +86,6 @@ enable_color_material(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::enable_clip_plane
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-enable_clip_plane(int clip_plane, bool val)
-{
-  if (_clip_plane_enabled[clip_plane] != val)
-    {
-    _clip_plane_enabled[clip_plane] = val;
-    DWORD  ClipPlaneBits;
-    scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , &ClipPlaneBits);
-    if (val)
-        ClipPlaneBits |= 1 << clip_plane;
-    else
-        ClipPlaneBits &= ~(1 << clip_plane);
-    scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , ClipPlaneBits);
-    }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::enable_blend
 //       Access:

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

@@ -485,6 +485,8 @@ dx_init( void) {
 
     ZeroMemory(&_lmodel_ambient,sizeof(Colorf));
     scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0);
+
+    _clip_plane_bits = 0;
     scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0);
 
     scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true);
@@ -525,7 +527,6 @@ dx_init( void) {
     _fog_enabled = false;
     scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, _fog_enabled);
 
-    _decal_level = 0;
     _current_projection_mat = LMatrix4f::ident_mat();
     _projection_mat_stack_count = 0;
     _has_scene_graph_color = false;
@@ -4832,6 +4833,68 @@ enable_light(int light_id, bool enable) {
 #endif
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::slot_new_clip_plane
+//       Access: Protected, Virtual
+//  Description: This will be called by the base class before a
+//               particular clip plane id will be used for the first
+//               time.  It is intended to allow the derived class to
+//               reserve any additional resources, if required, for
+//               the new clip plane; and also to indicate whether the
+//               hardware supports this many simultaneous clipping
+//               planes.
+//
+//               The return value should be true if the additional
+//               plane is supported, or false if it is not.
+////////////////////////////////////////////////////////////////////
+bool DXGraphicsStateGuardian::
+slot_new_clip_plane(int plane_id) {
+  return (plane_id < D3DMAXUSERCLIPPLANES);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::enable_clip_plane
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable the indicated clip_plane id.  A specific
+//               PlaneNode will already have been bound to this id via
+//               bind_clip_plane().
+////////////////////////////////////////////////////////////////////
+INLINE void DXGraphicsStateGuardian::
+enable_clip_plane(int plane_id, bool enable) {
+  assert(plane_id < D3DMAXUSERCLIPPLANES);
+
+  DWORD bitflag = ((DWORD)1 << plane_id);
+  if (enable) {
+    _clip_plane_bits |= bitflag;
+  } else {
+    _clip_plane_bits &= ~bitflag;
+  }
+
+  scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE, _clip_plane_bits);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::bind_clip_plane
+//       Access: Protected, Virtual
+//  Description: Called the first time a particular clip_plane has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware clip_plane with the clip_plane's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian::
+bind_clip_plane(PlaneNode *plane, int plane_id) {
+  // Get the plane in "world coordinates".  This means the plane in
+  // the coordinate space of the camera, converted to DX's coordinate
+  // system.
+  NodePath plane_np(plane);
+  const LMatrix4f &plane_mat = plane_np.get_mat(_scene_setup->get_camera_path());
+  LMatrix4f rel_mat = plane_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default);
+  Planef world_plane = plane->get_plane() * rel_mat;
+
+  scrn.pD3DDevice->SetClipPlane(plane_id, (float *)world_plane.get_data());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::set_blend_mode
 //       Access: Protected, Virtual

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

@@ -152,6 +152,10 @@ protected:
   virtual void set_ambient_light(const Colorf &color);
   virtual void enable_light(int light_id, bool enable);
 
+  virtual bool slot_new_clip_plane(int plane_id);
+  virtual void enable_clip_plane(int plane_id, bool enable);
+  virtual void bind_clip_plane(PlaneNode *plane, int plane_id);
+
   virtual void set_blend_mode(ColorWriteAttrib::Mode color_write_mode,
                               ColorBlendAttrib::Mode color_blend_mode,
                               TransparencyAttrib::Mode transparency_mode);
@@ -199,7 +203,6 @@ protected:
 */  
 
   INLINE void enable_color_material(bool val);
-  INLINE void enable_clip_plane(int clip_plane, bool val);
   INLINE void enable_fog(bool val);
   INLINE void enable_zwritemask(bool val);
   INLINE void set_shademode(D3DSHADEMODE val);
@@ -286,15 +289,14 @@ protected:
   bool* _light_enabled;      // bool[_max_lights]
   bool _color_material_enabled;
   bool _texturing_enabled;
-  bool  _clipping_enabled;
+  bool _clipping_enabled;
   bool _dither_enabled;
   bool _stencil_test_enabled;
-  bool* _clip_plane_enabled;      // bool[_max_clip_planes]
   bool _blend_enabled;
   bool _depth_test_enabled;
   bool _depth_write_enabled;
   bool _alpha_test_enabled;
-  int _decal_level;
+  DWORD _clip_plane_bits;
 
   RenderModeAttrib::Mode _current_fill_mode;  //poinr/wireframe/solid
   GraphicsChannel *_panda_gfx_channel;  // cache the 1 channel dx supports

+ 0 - 48
panda/src/dxgsg8/dxGraphicsStateGuardian8.I

@@ -87,54 +87,6 @@ enable_color_material(bool val) {
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::enable_clip_plane
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-enable_clip_plane(int clip_plane_id, bool val)
-{
-  assert(clip_plane_id < D3DMAXUSERCLIPPLANES);
-
-  if (_clip_plane_enabled[clip_plane_id] != val) {
-    DWORD bitflag = 1 << clip_plane_id;
-
-    _clip_plane_enabled[clip_plane_id] = val;
-    DWORD  ClipPlaneBits;
-    scrn.pD3DDevice->GetRenderState(D3DRS_CLIPPLANEENABLE , &ClipPlaneBits);
-    if (val)
-        ClipPlaneBits |= bitflag;
-    else
-        ClipPlaneBits &= ~bitflag;
-    scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE , ClipPlaneBits);
-  }
-}
-
-#if 0
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::enable_clip_plane
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-enable_clip_plane(int clip_plane_id, bool val)
-{
-  assert(clip_plane_id < D3DMAXUSERCLIPPLANES);
-
-  // clip plane stuff needs total rewriting to get rid of these arrays
-//  if (((_clip_planes_enabled & bitflag)!=0) != val) 
-  if (_clip_plane_enabled[clip_plane_id] != val) {
-    _clip_plane_enabled[clip_plane_id] = val;
-    if(val)
-      _clip_plane_enabled |= bitflag;
-     else _clip_plane_enabled &= ~bitflag;
-
-    scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE , _clip_planes_enabled);
-  }
-}
-#endif
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::enable_blend
 //       Access:

+ 63 - 1
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -570,6 +570,7 @@ dx_init(HCURSOR hMouseCursor) {
 
     _pCurFvfBufPtr = NULL;
 
+    _clip_plane_bits = 0;
     scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE , 0x0);
 
     scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPING, true);
@@ -610,7 +611,6 @@ dx_init(HCURSOR hMouseCursor) {
     _fog_enabled = false;
     scrn.pD3DDevice->SetRenderState(D3DRS_FOGENABLE, _fog_enabled);
 
-    _decal_level = 0;
     _current_projection_mat = LMatrix4f::ident_mat();
     _projection_mat_stack_count = 0;
     _has_scene_graph_color = false;
@@ -4344,6 +4344,68 @@ enable_light(int light_id, bool enable) {
 #endif
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::slot_new_clip_plane
+//       Access: Protected, Virtual
+//  Description: This will be called by the base class before a
+//               particular clip plane id will be used for the first
+//               time.  It is intended to allow the derived class to
+//               reserve any additional resources, if required, for
+//               the new clip plane; and also to indicate whether the
+//               hardware supports this many simultaneous clipping
+//               planes.
+//
+//               The return value should be true if the additional
+//               plane is supported, or false if it is not.
+////////////////////////////////////////////////////////////////////
+bool DXGraphicsStateGuardian::
+slot_new_clip_plane(int plane_id) {
+  return (plane_id < D3DMAXUSERCLIPPLANES);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::enable_clip_plane
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable the indicated clip_plane id.  A specific
+//               PlaneNode will already have been bound to this id via
+//               bind_clip_plane().
+////////////////////////////////////////////////////////////////////
+INLINE void DXGraphicsStateGuardian::
+enable_clip_plane(int plane_id, bool enable) {
+  assert(plane_id < D3DMAXUSERCLIPPLANES);
+
+  DWORD bitflag = ((DWORD)1 << plane_id);
+  if (enable) {
+    _clip_plane_bits |= bitflag;
+  } else {
+    _clip_plane_bits &= ~bitflag;
+  }
+
+  scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, _clip_plane_bits);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::bind_clip_plane
+//       Access: Protected, Virtual
+//  Description: Called the first time a particular clip_plane has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware clip_plane with the clip_plane's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian::
+bind_clip_plane(PlaneNode *plane, int plane_id) {
+  // Get the plane in "world coordinates".  This means the plane in
+  // the coordinate space of the camera, converted to DX's coordinate
+  // system.
+  NodePath plane_np(plane);
+  const LMatrix4f &plane_mat = plane_np.get_mat(_scene_setup->get_camera_path());
+  LMatrix4f rel_mat = plane_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default);
+  Planef world_plane = plane->get_plane() * rel_mat;
+
+  scrn.pD3DDevice->SetClipPlane(plane_id, world_plane.get_data());
+}
+
 void DXGraphicsStateGuardian::
 issue_color_write(const ColorWriteAttrib *attrib) {
   _color_write_mode = attrib->get_mode();

+ 6 - 4
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -155,6 +155,10 @@ protected:
   virtual void set_ambient_light(const Colorf &color);
   virtual void enable_light(int light_id, bool enable);
 
+  virtual bool slot_new_clip_plane(int plane_id);
+  virtual void enable_clip_plane(int plane_id, bool enable);
+  virtual void bind_clip_plane(PlaneNode *plane, int plane_id);
+
   virtual void set_blend_mode(ColorWriteAttrib::Mode color_write_mode,
                               ColorBlendAttrib::Mode color_blend_mode,
                               TransparencyAttrib::Mode transparency_mode);
@@ -196,7 +200,6 @@ protected:
 */  
 
   INLINE void enable_color_material(bool val);
-  INLINE void enable_clip_plane(int clip_plane_id, bool val);
   INLINE void enable_fog(bool val);
   INLINE void enable_zwritemask(bool val);
   INLINE void set_color_writemask(UINT color_writemask);
@@ -289,15 +292,14 @@ protected:
   bool _line_smooth_enabled;
   bool _color_material_enabled;
   bool _texturing_enabled;
-  bool  _clipping_enabled;
+  bool _clipping_enabled;
   bool _dither_enabled;
   bool _stencil_test_enabled;
-  bool* _clip_plane_enabled;      // bool[_max_clip_planes]
   bool _blend_enabled;
   bool _depth_test_enabled;
   bool _depth_write_enabled;
   bool _alpha_test_enabled;
-  int _decal_level;
+  DWORD _clip_plane_bits;
 
   RenderModeAttrib::Mode _current_fill_mode;  //poinr/wireframe/solid
   GraphicsChannel *_panda_gfx_channel;  // cache the 1 channel dx supports