Pārlūkot izejas kodu

simply & pandify dx8gsg some; rework gsg's external_transform and internal_transform

David Rose 20 gadi atpakaļ
vecāks
revīzija
296721f061
46 mainītis faili ar 1775 papildinājumiem un 4117 dzēšanām
  1. 2 2
      panda/src/collide/collisionNode.cxx
  2. 2 3
      panda/src/collide/collisionVisualizer.cxx
  3. 0 6
      panda/src/display/graphicsEngine.cxx
  4. 20 3
      panda/src/display/graphicsStateGuardian.I
  5. 85 1
      panda/src/display/graphicsStateGuardian.cxx
  6. 16 1
      panda/src/display/graphicsStateGuardian.h
  7. 2 23
      panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx
  8. 0 1
      panda/src/dxgsg7/dxGraphicsStateGuardian7.h
  9. 6 12
      panda/src/dxgsg8/Sources.pp
  10. 0 935
      panda/src/dxgsg8/d3dfont8.cxx
  11. 0 112
      panda/src/dxgsg8/d3dfont8.h
  12. 53 340
      panda/src/dxgsg8/dxGraphicsStateGuardian8.I
  13. 386 497
      panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx
  14. 97 211
      panda/src/dxgsg8/dxGraphicsStateGuardian8.h
  15. 40 0
      panda/src/dxgsg8/dxTextureContext8.I
  16. 619 769
      panda/src/dxgsg8/dxTextureContext8.cxx
  17. 16 17
      panda/src/dxgsg8/dxTextureContext8.h
  18. 0 1
      panda/src/dxgsg8/dxgsg8_composite1.cxx
  19. 2 1
      panda/src/dxgsg8/dxgsg8base.h
  20. 148 228
      panda/src/dxgsg8/wdxGraphicsPipe8.cxx
  21. 11 22
      panda/src/dxgsg8/wdxGraphicsPipe8.h
  22. 125 658
      panda/src/dxgsg8/wdxGraphicsWindow8.cxx
  23. 15 23
      panda/src/dxgsg8/wdxGraphicsWindow8.h
  24. 0 19
      panda/src/dxgsg9/dxGraphicsStateGuardian9.I
  25. 2 4
      panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx
  26. 0 1
      panda/src/dxgsg9/dxGraphicsStateGuardian9.h
  27. 41 90
      panda/src/glstuff/glGraphicsStateGuardian_src.cxx
  28. 0 12
      panda/src/glstuff/glGraphicsStateGuardian_src.h
  29. 13 0
      panda/src/gobj/preparedGraphicsObjects.I
  30. 2 0
      panda/src/gobj/preparedGraphicsObjects.h
  31. 6 0
      panda/src/gobj/qpgeomPrimitive.I
  32. 2 0
      panda/src/gobj/qpgeomPrimitive.h
  33. 10 14
      panda/src/gsgbase/graphicsStateGuardianBase.h
  34. 8 8
      panda/src/parametrics/ropeNode.cxx
  35. 2 2
      panda/src/parametrics/sheetNode.cxx
  36. 9 11
      panda/src/pgraph/cullTraverser.I
  37. 6 8
      panda/src/pgraph/cullTraverser.cxx
  38. 1 1
      panda/src/pgraph/cullTraverser.h
  39. 0 5
      panda/src/pgraph/cullTraverserData.I
  40. 0 1
      panda/src/pgraph/cullTraverserData.cxx
  41. 0 2
      panda/src/pgraph/cullTraverserData.h
  42. 1 1
      panda/src/pgraph/cullableObject.I
  43. 24 11
      panda/src/pgraph/cullableObject.cxx
  44. 1 1
      panda/src/pgraph/portalNode.cxx
  45. 2 53
      panda/src/pgraph/sceneSetup.I
  46. 0 7
      panda/src/pgraph/sceneSetup.h

+ 2 - 2
panda/src/collide/collisionNode.cxx

@@ -250,8 +250,8 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
       if (node != (PandaNode *)NULL) {
         CullTraverserData next_data(data, node);
 
-        next_data._render_transform = 
-          next_data._render_transform->compose(transform);
+        next_data._net_transform = 
+          next_data._net_transform->compose(transform);
         next_data._state = get_last_pos_state();
         trav->traverse(next_data);
       }

+ 2 - 3
panda/src/collide/collisionVisualizer.cxx

@@ -130,7 +130,6 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
     // always renders its objects according to their appropriate net
     // transform.
     xform_data._net_transform = TransformState::make_identity();
-    xform_data._render_transform = trav->get_render_transform();
     xform_data.apply_transform_and_state(trav, net_transform, 
                                          RenderState::make_empty(),
                                          RenderEffects::make_empty());
@@ -189,7 +188,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
           }
             
           CullableObject *object = 
-            new CullableObject(sphere, empty_state, xform_data._render_transform);
+            new CullableObject(sphere, empty_state, xform_data._net_transform);
           
           trav->get_cull_handler()->record_object(object, trav);
         }
@@ -207,7 +206,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
           line->set_num_prims(1);
           
           CullableObject *object = 
-            new CullableObject(line, empty_state, xform_data._render_transform);
+            new CullableObject(line, empty_state, xform_data._net_transform);
           
           trav->get_cull_handler()->record_object(object, trav);
         }

+ 0 - 6
panda/src/display/graphicsEngine.cxx

@@ -1041,11 +1041,6 @@ setup_scene(GraphicsStateGuardian *gsg, DisplayRegion *dr) {
   CPT(TransformState) camera_transform = camera.get_transform(scene_parent);
   CPT(TransformState) world_transform = scene_parent.get_transform(camera);
 
-  // The render transform is the same as the world transform, except
-  // it is converted into the GSG's internal coordinate system.  This
-  // is the transform that the GSG will apply to all of its vertices.
-  CPT(TransformState) cs_transform = gsg->get_cs_transform();
-
   CPT(RenderState) initial_state = camera_node->get_initial_state();
 
   if (window->get_inverted()) {
@@ -1068,7 +1063,6 @@ setup_scene(GraphicsStateGuardian *gsg, DisplayRegion *dr) {
   scene_setup->set_initial_state(initial_state);
   scene_setup->set_camera_transform(camera_transform);
   scene_setup->set_world_transform(world_transform);
-  scene_setup->set_cs_transform(cs_transform);
 
   return scene_setup;
 }

+ 20 - 3
panda/src/display/graphicsStateGuardian.I

@@ -40,6 +40,16 @@ ClipPlaneInfo() {
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::release_all
+//       Access: Public
+//  Description: Releases all prepared objects.
+////////////////////////////////////////////////////////////////////
+INLINE void GraphicsStateGuardian::
+release_all() {
+  return _prepared_objects->release_all();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::release_all_textures
 //       Access: Public
@@ -483,13 +493,20 @@ set_state(const RenderState *state) {
 //               subsequent geometry.  This is normally called only
 //               during the draw process, immediately before issuing
 //               geometry commands.
+//
+//               This transform specified is the "external" net
+//               transform, expressed in the external coordinate
+//               space; internally, it will be pretransformed by
+//               get_cs_transform() to express it in the GSG's
+//               internal coordinate space.
 ////////////////////////////////////////////////////////////////////
 INLINE void GraphicsStateGuardian::
 set_transform(const TransformState *transform) {
-  if (transform != _transform) {
+  if (transform != _external_transform) {
     _state_pcollector.add_level(1);
-    _transform = transform;
-    issue_transform(transform);
+    _external_transform = transform;
+    _internal_transform = _cs_transform->compose(transform);
+    issue_transform(_internal_transform);
   }
 }
 

+ 85 - 1
panda/src/display/graphicsStateGuardian.cxx

@@ -97,6 +97,8 @@ GraphicsStateGuardian(const FrameBufferProperties &properties,
   _properties(properties)
 {
   _coordinate_system = CS_invalid;
+  _external_transform = TransformState::make_identity();
+  _internal_transform = TransformState::make_identity();
   set_coordinate_system(get_default_coordinate_system());
 
   _current_display_region = (DisplayRegion*)0L;
@@ -203,7 +205,8 @@ reset() {
   _lens_stack_level = 0;
 
   _state = RenderState::make_empty();
-  _transform = TransformState::make_identity();
+  _external_transform = TransformState::make_identity();
+  _internal_transform = _cs_transform;
 
   _buffer_mask = 0;
   _color_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f);
@@ -242,6 +245,14 @@ reset() {
   _has_material_force_color = false;
   _material_force_color.set(1.0f, 1.0f, 1.0f, 1.0f);
   _light_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f);
+
+  _current_texture = DCAST(TextureAttrib, TextureAttrib::make_all_off());
+  _current_tex_mat = DCAST(TexMatrixAttrib, TexMatrixAttrib::make());
+  _needs_tex_mat = false;
+  _current_tex_gen = DCAST(TexGenAttrib, TexGenAttrib::make());
+  _needs_tex_gen = false;
+  _tex_gen_modifies_mat = false;
+  _last_max_stage_index = 0;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -429,6 +440,12 @@ make_geom_munger(const RenderState *state) {
 //       Access: Public, Virtual
 //  Description: Simultaneously resets the render state and the
 //               transform state.
+//
+//               This transform specified is the "external" net
+//               transform, expressed in the external coordinate
+//               space; internally, it will be pretransformed by
+//               get_cs_transform() to express it in the GSG's
+//               internal coordinate space.
 ////////////////////////////////////////////////////////////////////
 void GraphicsStateGuardian::
 set_state_and_transform(const RenderState *state,
@@ -437,6 +454,37 @@ set_state_and_transform(const RenderState *state,
   set_state(state);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::compute_distance_to
+//       Access: Public, Virtual
+//  Description: This function may only be called during a render
+//               traversal; it will compute the distance to the
+//               indicated point, assumed to be in eye coordinates,
+//               from the camera plane.
+////////////////////////////////////////////////////////////////////
+float GraphicsStateGuardian::
+compute_distance_to(const LPoint3f &point) const {
+  switch (_coordinate_system) {
+  case CS_zup_right:
+    return point[1];
+
+  case CS_yup_right:
+    return -point[2];
+
+  case CS_zup_left:
+    return -point[1];
+
+  case CS_yup_left:
+    return point[2];
+
+  default:
+    gsg_cat.error()
+      << "Invalid coordinate system in compute_distance_to: "
+      << (int)_coordinate_system << "\n";
+    return 0.0f;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::set_color_clear_value
 //       Access: Public
@@ -900,6 +948,7 @@ set_coordinate_system(CoordinateSystem cs) {
       (LMatrix4f::convert_mat(_coordinate_system,
                               _internal_coordinate_system));
   }
+  _internal_transform = _cs_transform->compose(_external_transform);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -925,6 +974,9 @@ get_internal_coordinate_system() const {
 //       Access: Public, Virtual
 //  Description: Sends the indicated transform matrix to the graphics
 //               API to be applied to future vertices.
+//
+//               This transform is the internal_transform, already
+//               converted into the GSG's internal coordinate system.
 ////////////////////////////////////////////////////////////////////
 void GraphicsStateGuardian::
 issue_transform(const TransformState *) {
@@ -1006,6 +1058,22 @@ issue_color(const ColorAttrib *attrib) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::issue_tex_matrix
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+issue_tex_matrix(const TexMatrixAttrib *attrib) {
+  // We don't apply the texture matrix right away, since we might yet
+  // get a TextureAttrib that changes the set of TextureStages we have
+  // active.  Instead, we simply set a flag that indicates we need to
+  // re-issue the texture matrix after all of the other attribs are
+  // done being issued.
+  _current_tex_mat = attrib;
+  _needs_tex_mat = true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::issue_light
 //       Access: Public, Virtual
@@ -1067,6 +1135,22 @@ issue_color_blend(const ColorBlendAttrib *attrib) {
   _blend_mode_stale = true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::issue_tex_gen
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+issue_tex_gen(const TexGenAttrib *attrib) {
+  // We don't apply the texture coordinate generation commands right
+  // away, since we might yet get a TextureAttrib that changes the set
+  // of TextureStages we have active.  Instead, we simply set a flag
+  // that indicates we need to re-issue the TexGenAttrib after all of
+  // the other attribs are done being issued.
+  _current_tex_gen = attrib;
+  _needs_tex_gen = true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::issue_texture
 //       Access: Public, Virtual

+ 16 - 1
panda/src/display/graphicsStateGuardian.h

@@ -74,6 +74,7 @@ public:
   virtual ~GraphicsStateGuardian();
 
 PUBLISHED:
+  INLINE void release_all();
   INLINE int release_all_textures();
   INLINE int release_all_geoms();
   INLINE int release_all_vertex_buffers();
@@ -128,6 +129,8 @@ public:
   virtual void set_state_and_transform(const RenderState *state,
                                        const TransformState *transform);
 
+  virtual float compute_distance_to(const LPoint3f &point) const;
+
   virtual void set_color_clear_value(const Colorf &value);
   virtual void set_depth_clear_value(const float value);
   virtual void do_clear(const RenderBuffer &buffer)=0;
@@ -197,11 +200,13 @@ public:
   virtual void issue_transform(const TransformState *transform);
   virtual void issue_color_scale(const ColorScaleAttrib *attrib);
   virtual void issue_color(const ColorAttrib *attrib);
+  virtual void issue_tex_matrix(const TexMatrixAttrib *attrib);
   virtual void issue_light(const LightAttrib *attrib);
   virtual void issue_material(const MaterialAttrib *attrib);
   virtual void issue_color_write(const ColorWriteAttrib *attrib);
   virtual void issue_transparency(const TransparencyAttrib *attrib);
   virtual void issue_color_blend(const ColorBlendAttrib *attrib);
+  virtual void issue_tex_gen(const TexGenAttrib *attrib);
   virtual void issue_texture(const TextureAttrib *attrib);
   virtual void issue_clip_plane(const ClipPlaneAttrib *attrib);
 
@@ -279,7 +284,8 @@ protected:
   PT(SceneSetup) _scene_setup;
 
   CPT(RenderState) _state;
-  CPT(TransformState) _transform;
+  CPT(TransformState) _external_transform;
+  CPT(TransformState) _internal_transform;
   CPT(qpGeomMunger) _munger;
   CPT(qpGeomVertexData) _vertex_data;
 
@@ -334,6 +340,15 @@ protected:
   Colorf _material_force_color;
   LVecBase4f _light_color_scale;
 
+  CPT(TextureAttrib) _current_texture;
+  CPT(TexMatrixAttrib) _current_tex_mat;
+  bool _needs_tex_mat;
+  CPT(TexGenAttrib) _current_tex_gen;
+  bool _needs_tex_gen;
+  bool _tex_gen_modifies_mat;
+  bool _tex_gen_point_sprite;
+  int _last_max_stage_index;
+
   bool _needs_reset;
   bool _closing_gsg;
   bool _active;

+ 2 - 23
panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx

@@ -1755,7 +1755,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) {
     }
 
     // save the modelview matrix
-    const LMatrix4f &modelview_mat = _transform->get_mat();
+    const LMatrix4f &modelview_mat = _internal_transform->get_mat();
 
     // We don't need to mess with the aspect ratio, since we are now
     // using the default projection matrix, which has the right aspect
@@ -3703,7 +3703,6 @@ issue_transform(const TransformState *transform) {
   _pScrn->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,
                                 (LPD3DMATRIX)transform->get_mat().get_data());
  
-  _transform = transform;
   if (_auto_rescale_normal) {
     do_auto_rescale_normal();
   }
@@ -4255,25 +4254,6 @@ wants_texcoords() const {
     return _texturing_enabled;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian7::compute_distance_to
-//       Access: Public, Virtual
-//  Description: This function may only be called during a render
-//               traversal; it will compute the distance to the
-//               indicated point, assumed to be in modelview
-//               coordinates, from the camera plane.
-////////////////////////////////////////////////////////////////////
-INLINE float DXGraphicsStateGuardian7::
-compute_distance_to(const LPoint3f &point) const {
-    // In the case of a DXGraphicsStateGuardian7, we know that the
-    // modelview matrix already includes the relative transform from the
-    // camera, as well as a to-y-up conversion.  Thus, the distance to
-    // the camera plane is simply the +z distance.  (negative of gl compute_distance_to,
-    // since d3d uses left-hand coords)
-
-    return point[2];
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian7::set_draw_buffer
 //       Access: Protected
@@ -4393,8 +4373,7 @@ get_fog_mode_type(Fog::Mode m) const {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian7::
 do_auto_rescale_normal() {
-  if (_transform->has_uniform_scale() &&
-      IS_NEARLY_EQUAL(_transform->get_uniform_scale(), 1.0f)) {
+  if (_external_transform->has_identity_scale()) {
     // If there's no scale, don't normalize anything.
     _pD3DDevice->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, false);
 

+ 0 - 1
panda/src/dxgsg7/dxGraphicsStateGuardian7.h

@@ -126,7 +126,6 @@ public:
 
   virtual bool wants_texcoords(void) const;
 
-  INLINE float compute_distance_to(const LPoint3f &point) const;
   virtual void set_color_clear_value(const Colorf& value);
 
 public:

+ 6 - 12
panda/src/dxgsg8/Sources.pp

@@ -17,16 +17,6 @@
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx     
 
-  // need to install these due to external projects that link directly with libpandadx (bartop)  
-  #define INSTALL_HEADERS \
-    dxgsg8base.h config_dxgsg8.h dxGraphicsStateGuardian8.I dxGraphicsStateGuardian8.h \
-    dxVertexBufferContext8.h \
-    dxIndexBufferContext8.h \
-    dxTextureContext8.h \
-    dxGeomMunger8.h \
-    d3dfont8.h \
-    dxGraphicsDevice8.h
-
   // build dxGraphicsStateGuardian separately since its so big
   
   #define SOURCES \
@@ -34,7 +24,12 @@
     dxGraphicsDevice8.h \
     wdxGraphicsPipe8.I wdxGraphicsPipe8.h \
     wdxGraphicsWindow8.I wdxGraphicsWindow8.h \
-    $[INSTALL_HEADERS]
+    dxgsg8base.h config_dxgsg8.h dxGraphicsStateGuardian8.I dxGraphicsStateGuardian8.h \
+    dxVertexBufferContext8.h dxVertexbufferContext8.I \
+    dxIndexBufferContext8.h dxIndexBufferContext8.I \
+    dxTextureContext8.h dxTextureContext8.I \
+    dxGeomMunger8.h dxGeomMunger8.I \
+    dxGraphicsDevice8.h
     
   #define INCLUDED_SOURCES \
     config_dxgsg8.cxx \
@@ -42,7 +37,6 @@
     dxIndexBufferContext8.cxx \
     dxTextureContext8.cxx \
     dxGeomMunger8.cxx \
-    d3dfont8.cxx \
     dxGraphicsDevice8.cxx \
     wdxGraphicsPipe8.cxx wdxGraphicsWindow8.cxx
 

+ 0 - 935
panda/src/dxgsg8/d3dfont8.cxx

@@ -1,935 +0,0 @@
-//-----------------------------------------------------------------------------
-// File: D3DFont.cpp
-//
-// Desc: Texture-based font class
-//       modified from a modified version of DXSDK CD3DFont from http://www.lafaqmfc.com/directx.htm
-//       Note that this is faster than ID3DXFont, which calls GDI in Draw()
-//-----------------------------------------------------------------------------
-#ifndef STRICT
-#define STRICT
-#endif
-
-#include "dxgsg8base.h"
-#include <stdio.h>
-#include <tchar.h>
-#include <d3dx8.h>
-#include "d3dfont8.h"
-
-//-----------------------------------------------------------------------------
-// Custom vertex types for rendering text
-//-----------------------------------------------------------------------------
-
-struct FONT2DVERTEX {
-    D3DXVECTOR4 p;   DWORD color;     FLOAT tu, tv;
-};
-struct FONT3DVERTEX {
-    D3DXVECTOR3 p;   D3DXVECTOR3 n;   FLOAT tu, tv;
-};
-
-inline FONT2DVERTEX InitFont2DVertex( const D3DXVECTOR4& p, D3DCOLOR color,
-                                      FLOAT tu, FLOAT tv ) {
-    FONT2DVERTEX v;   v.p = p;   v.color = color;   v.tu = tu;   v.tv = tv;
-    return v;
-}
-
-inline FONT3DVERTEX InitFont3DVertex( const D3DXVECTOR3& p, const D3DXVECTOR3& n,
-                                      FLOAT tu, FLOAT tv ) {
-    FONT3DVERTEX v;   v.p = p;   v.n = n;   v.tu = tu;   v.tv = tv;
-    return v;
-}
-
-//-----------------------------------------------------------------------------
-// Name: CD3DFont()
-// Desc: Font class constructor
-//-----------------------------------------------------------------------------
-CD3DFont::CD3DFont( TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags ) {
-    _tcscpy( m_strFontName, strFontName );
-    m_dwFontHeight         = dwHeight;
-    m_dwFontFlags          = dwFlags;
-
-    m_pd3dDevice           = NULL;
-    m_pTexture             = NULL;
-    m_pVB                  = NULL;
-
-    m_dwSavedStateBlock    = NULL;
-    m_dwDrawTextStateBlock = NULL;
-
-    ClearBeginEndData ( ) ; 
-    m_bBeginText = false ; 
-}
-
-//-----------------------------------------------------------------------------
-// Name: ~CD3DFont()
-// Desc: Font class destructor
-//-----------------------------------------------------------------------------
-CD3DFont::~CD3DFont() {
-    DeleteDeviceObjects();
-}
-
-//-----------------------------------------------------------------------------
-// Name: InitDeviceObjects()
-// Desc: Initializes device-dependent objects, including the vertex buffer used
-//       for rendering text and the texture map which stores the font image.
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE8 pd3dDevice ) {
-    HRESULT hr;
-
-    // Keep a local copy of the device
-    m_pd3dDevice = pd3dDevice;
-
-    // Establish the font and texture size
-    m_fTextScale  = 1.0f; // Draw fonts into texture without scaling
-
-    // Large fonts need larger textures 
-    // We can be generous at this step, this is an estimate
-    if(m_dwFontHeight > 40)
-        m_dwTexWidth = m_dwTexHeight = 2048;
-    else if(m_dwFontHeight > 32)
-        m_dwTexWidth = m_dwTexHeight = 1024;
-    else if(m_dwFontHeight > 16)
-        m_dwTexWidth = m_dwTexHeight = 512;
-    else
-        m_dwTexWidth = m_dwTexHeight = 256;
-
-    // Prepare to create a bitmap
-    DWORD*      pBitmapBits;
-    BITMAPINFO bmi;
-    ZeroMemory( &bmi.bmiHeader,  sizeof(BITMAPINFOHEADER) );
-    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
-    bmi.bmiHeader.biWidth       =  (int)m_dwTexWidth;
-    bmi.bmiHeader.biHeight      = -(int)m_dwTexHeight;
-    bmi.bmiHeader.biPlanes      = 1;
-    bmi.bmiHeader.biCompression = BI_RGB;
-    bmi.bmiHeader.biBitCount    = 32;
-
-    // Create a DC and a bitmap for the font
-    HDC     hDC       = CreateCompatibleDC( NULL );
-    HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
-                                          (VOID**)&pBitmapBits, NULL, 0 );
-    SetMapMode( hDC, MM_TEXT );
-
-    // Create a font.  By specifying ANTIALIASED_QUALITY, we might get an
-    // antialiased font, but this is not guaranteed.
-    INT nHeight    = -MulDiv( m_dwFontHeight, 
-                              (INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
-    DWORD dwBold   = (m_dwFontFlags&D3DFONT_BOLD)   ? FW_BOLD : FW_NORMAL;
-    DWORD dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE    : FALSE;
-    HFONT hFont    = CreateFont( nHeight, 0, 0, 0, dwBold, 
-
-                                 FALSE ,   // dwItalic, // NO! We should not do that...
-                                    // See below comment about GetTextExtentPoint32
-
-                                 FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
-                                 CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
-                                 VARIABLE_PITCH, m_strFontName );
-    if(NULL==hFont) {
-        dxgsg8_cat.error() << "CD3DFont InitDeviceObjects(): initial CreateFont failed!  GetLastError=" << GetLastError() << endl;
-        return E_FAIL;
-    }
-
-    HBITMAP hbmOld = ( HBITMAP ) SelectObject ( hDC, hbmBitmap );
-    HFONT   hfOld  = ( HFONT ) SelectObject ( hDC, hFont );
-
-    // Set text properties
-    SetTextColor( hDC, RGB(255,255,255) );
-    SetBkColor(   hDC, 0x00000000 );
-    SetTextAlign( hDC, TA_TOP );
-
-    // First Loop through all printable characters 
-    // in order to determine the smallest necessary texture
-    DWORD x = 0;
-    DWORD y = 0;
-    TCHAR str[2] = _T("x");
-    SIZE size;
-    SIZE sizes [ 127 - 32 ] ;
-
-    TCHAR c;
-    for(c=32; c<127; c++) {
-        str[0] = c;
-        // GetTextExtentPoint32 does not care that the font is Italic or not, it will 
-        // return the same value. However, if we specify an Italic font, the output 
-        // on the bitmap will use more pixels. 
-        // If the font is Italic we have to output the standard character 
-        // and bend our vertices.
-        GetTextExtentPoint32 ( hDC, str, 1, & sizes [ c - 32 ] );
-    } ; 
-
-    static DWORD TexturesSizes [ 5 ] = { 128 , 256 , 512 , 1024 , 2048} ; 
-    DWORD dwTexSize = 0 ;  
-    for(DWORD iTex = 0 ; iTex < 5 ; ++ iTex) {
-        // fake the tex coord loop calculation 
-        x = 0 ; 
-        y = 0 ; 
-        for(TCHAR c=32; c<127; c++) {
-            if((DWORD)( x + sizes[ c - 32 ].cx+1) > TexturesSizes [ iTex ]) {
-                x  = 0;
-                y += sizes[ c - 32 ].cy+1;
-                // new y size 
-                if((DWORD) ( y + sizes[ 0 ].cy + 1 ) >= TexturesSizes [ iTex ]) {
-                    // does not fit, let's try a larger one 
-                    break ; 
-                }; 
-            }; 
-            x += sizes[ c - 32 ].cx + 2 ;
-        } ; 
-
-        if((DWORD) ( y + sizes[ 0 ].cy + 1 ) < TexturesSizes [ iTex ]) {
-            // Yahoo! it fits! 
-            dwTexSize = TexturesSizes [ iTex ] ; 
-            break ; 
-        }; 
-    } ; 
-
-    m_dwTexWidth = m_dwTexHeight = dwTexSize ;
-
-    // Select old objects ( added ) 
-    // Is this needed for compatible DCs? 
-    // The old handles are not not NULL, so it is done "by the book"
-    SelectObject ( hDC, hbmOld );
-    SelectObject ( hDC, hfOld );
-
-    // delete our gdi objects
-    DeleteObject( hbmBitmap );
-    DeleteObject( hFont );
-    DeleteDC( hDC );
-
-    // moved here to allow deletion of GDI objects 
-    if(dwTexSize == 0) {
-        dxgsg8_cat.error() << "CD3DFont InitDeviceObjects() error: Texture didnt fit, creation failed!\n";
-        return E_FAIL;
-    }
-
-    // Re-Create new GDI stuff with the optimal size 
-    // 
-    // Prepare to create a bitmap
-    ZeroMemory( &bmi.bmiHeader,  sizeof(BITMAPINFOHEADER) );
-    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
-    bmi.bmiHeader.biWidth       =  (int)m_dwTexWidth;
-    bmi.bmiHeader.biHeight      = -(int)m_dwTexHeight;
-    bmi.bmiHeader.biPlanes      = 1;
-    bmi.bmiHeader.biCompression = BI_RGB;
-    bmi.bmiHeader.biBitCount    = 32;
-
-    // Create a DC and a bitmap for the font
-    hDC       = CreateCompatibleDC( NULL );
-    hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
-                                  (VOID**)&pBitmapBits, NULL, 0 );
-    SetMapMode( hDC, MM_TEXT );
-
-    // Create a font.  By specifying ANTIALIASED_QUALITY, we might get an
-    // antialiased font, but this is not guaranteed.
-    nHeight  = -MulDiv( m_dwFontHeight, 
-                        (INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
-    dwBold   = (m_dwFontFlags&D3DFONT_BOLD)   ? FW_BOLD : FW_NORMAL;
-    dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE    : FALSE;
-    hFont    = CreateFont( nHeight, 0, 0, 0, dwBold, 
-                           FALSE , // was dwItalic, // see above 
-                           FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
-                           CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
-                           VARIABLE_PITCH, m_strFontName );
-
-    if(NULL==hFont) {
-        dxgsg8_cat.error() << "CD3DFont InitDeviceObjects(): optimal CreateFont failed!  GetLastError=" << GetLastError() << endl;
-        return E_FAIL;
-    }
-
-    hbmOld = ( HBITMAP ) SelectObject ( hDC, hbmBitmap );
-    hfOld  = ( HFONT ) SelectObject ( hDC, hFont );
-
-    // Set text properties
-    SetTextColor( hDC, RGB(255,255,255) );
-    SetBkColor(   hDC, 0x00000000 );
-    SetTextAlign( hDC, TA_TOP );
-
-    // If requested texture is too big, use a smaller texture and smaller font,
-    // and scale up when rendering.
-    D3DCAPS8 d3dCaps;
-    m_pd3dDevice->GetDeviceCaps( &d3dCaps );
-
-    if(m_dwTexWidth > d3dCaps.MaxTextureWidth) {
-        m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
-        m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
-    }; 
-
-    // Create a new texture for the font
-    hr = m_pd3dDevice->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1,
-                                      0, D3DFMT_A4R4G4B4,
-                                      D3DPOOL_MANAGED, &m_pTexture );
-
-    if(FAILED(hr)) {
-        SelectObject ( hDC, hbmOld );
-        SelectObject ( hDC, hfOld );
-
-        DeleteObject( hbmBitmap );
-        DeleteObject( hFont );
-        DeleteDC( hDC );
-
-        dxgsg8_cat.error() << "CD3DFont InitDeviceObjs CreateTexture failed!" << D3DERRORSTRING(hr);
-        return hr;
-    }; 
-
-    // Loop through all printable character and output them to the bitmap..
-    // Meanwhile, keep track of the corresponding tex coords for each character.
-    x = 0 ; 
-    y = 0 ; 
-
-    for(c=32; c<127; c++) {
-        str[0] = c;
-        GetTextExtentPoint32( hDC, str, 1, &size );
-        if((DWORD)(x+size.cx+1) > m_dwTexWidth) {
-            x  = 0;
-            y += size.cy+1;
-        }
-
-        // We need one pixel on both sides 
-
-        // plus one here for one pixel on the left
-        ExtTextOut( hDC, x + 1, y, ETO_OPAQUE, NULL, str, 1, NULL );
-
-        m_fTexCoords[c-32][0] = ( (FLOAT) x + 0.5f ) / m_dwTexWidth ;
-        m_fTexCoords[c-32][1] = ( (FLOAT) y + 0.5f ) / m_dwTexHeight ;
-        m_fTexCoords[c-32][2] = ( (FLOAT) x + 0.5f + size.cx ) / m_dwTexWidth;
-        m_fTexCoords[c-32][3] = ( (FLOAT) y + 0.5f + size.cy ) / m_dwTexHeight;
-
-        // plus two here because we also need one more pixel on the right side
-        x += size.cx + 2 ;
-    }
-
-    // Lock the surface and write the alpha values for the set pixels
-    D3DLOCKED_RECT d3dlr;
-    m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
-    BYTE* pDstRow = (BYTE*)d3dlr.pBits;
-    WORD* pDst16;
-    BYTE bAlpha; // 4-bit measure of pixel intensity
-
-    for(y=0; y < m_dwTexHeight; y++) {
-        pDst16 = (WORD*)pDstRow;
-        for(x=0; x < m_dwTexWidth; x++) {
-            bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
-            if(bAlpha > 0) {
-                *pDst16++ = (bAlpha << 12) | 0x0fff;
-            } else {
-                *pDst16++ = 0x0000;
-            }
-        }
-        pDstRow += d3dlr.Pitch;
-    }
-
-    // Done updating texture, so clean up used objects
-    m_pTexture->UnlockRect(0);
-
-    SelectObject ( hDC, hbmOld );
-    SelectObject ( hDC, hfOld );
-
-    DeleteObject( hbmBitmap );
-    DeleteObject( hFont );
-    DeleteDC( hDC );
-
-    return RestoreDeviceObjects();
-}
-
-//-----------------------------------------------------------------------------
-// Name: RestoreDeviceObjects()
-// Desc:
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::RestoreDeviceObjects() {
-    HRESULT hr;
-
-    // Create vertex buffer for the letters
-    if(FAILED( hr = m_pd3dDevice->CreateVertexBuffer(
-            // can be rendered 3d 
-                                                    MAX_NUM_VERTICES*sizeof(FONT3DVERTEX /*FONT2DVERTEX */ ),
-                                                    D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
-                                                    D3DPOOL_DEFAULT,  // D3DUSAGE_DYNAMIC makes D3DPOOL_MANAGED impossible
-                                                    &m_pVB ) )) {
-        dxgsg8_cat.error() << "CD3DFont CreateVB failed!" << D3DERRORSTRING(hr);
-        return hr;
-    }
-
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    // Create the state blocks for rendering text
-    for(UINT which=0; which<2; which++) {
-        m_pd3dDevice->BeginStateBlock();
-        m_pd3dDevice->SetTexture( 0, m_pTexture );
-
-        if(D3DFONT_ZENABLE & m_dwFontFlags)
-            m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
-        else
-            m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
-
-        m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
-        m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND,   D3DBLEND_SRCALPHA );
-        m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND,  D3DBLEND_INVSRCALPHA );
-        m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,  TRUE );
-        m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF,         0x08 );
-        m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC,  D3DCMP_GREATEREQUAL );
-        m_pd3dDevice->SetRenderState( D3DRS_FILLMODE,   D3DFILL_SOLID );
-        m_pd3dDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CCW );
-        m_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE,    FALSE );
-        m_pd3dDevice->SetRenderState( D3DRS_CLIPPING,         TRUE );
-        m_pd3dDevice->SetRenderState( D3DRS_EDGEANTIALIAS,    FALSE );
-        m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE,  FALSE );
-        m_pd3dDevice->SetRenderState( D3DRS_VERTEXBLEND,      FALSE );
-        m_pd3dDevice->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE );
-        m_pd3dDevice->SetRenderState( D3DRS_FOGENABLE,        FALSE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_POINT );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_POINT );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_NONE );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
-        m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
-        m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
-
-        if(which==0)
-            m_pd3dDevice->EndStateBlock( &m_dwSavedStateBlock );
-        else
-            m_pd3dDevice->EndStateBlock( &m_dwDrawTextStateBlock );
-    }
-
-    return S_OK;
-}
-
-
-//-----------------------------------------------------------------------------
-// Name: InvalidateDeviceObjects()
-// Desc: Destroys all device-dependent objects
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::InvalidateDeviceObjects() {
-    HRESULT hr;
-
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    if(IS_VALID_PTR(m_pd3dDevice)) {
-        // undo SetStreamSource before releasing VB
-
-        IDirect3DVertexBuffer8 *pStreamData=NULL;
-        UINT StreamStride;
-        hr = m_pd3dDevice->GetStreamSource(0,&pStreamData,&StreamStride);
-        SAFE_RELEASE(pStreamData);  // undo GetStreamSource AddRef
-        if(pStreamData==m_pVB)
-            hr = m_pd3dDevice->SetStreamSource(0,NULL,0);
-    }
-
-    PRINT_REFCNT(dxgsg8,m_pVB);
-
-    RELEASE(m_pVB,dxgsg8,"d3dfont VB",RELEASE_ONCE);
-
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    // Delete the state blocks
-    if(m_pd3dDevice) {
-        assert(IS_VALID_PTR(m_pd3dDevice));
-        if(m_dwSavedStateBlock)
-            m_pd3dDevice->DeleteStateBlock( m_dwSavedStateBlock );
-        if(m_dwDrawTextStateBlock)
-            m_pd3dDevice->DeleteStateBlock( m_dwDrawTextStateBlock );
-    }
-
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    m_dwSavedStateBlock    = NULL;
-    m_dwDrawTextStateBlock = NULL;
-
-    return S_OK;
-}
-
-
-//-----------------------------------------------------------------------------
-// Name: DeleteDeviceObjects()
-// Desc: Destroys all device-dependent objects
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::DeleteDeviceObjects() {
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    InvalidateDeviceObjects();
-
-    SAFE_RELEASE( m_pTexture );
-
-    PRINT_REFCNT(dxgsg8,m_pd3dDevice);
-
-    m_pd3dDevice = NULL;
-
-    return S_OK;
-}
-
-
-//-----------------------------------------------------------------------------
-// Name: GetTextExtent()
-// Desc: Get the dimensions of a text string
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::GetTextExtent( TCHAR* strText, SIZE* pSize ) {
-    if(NULL==strText || NULL==pSize)
-        return E_FAIL;
-
-    FLOAT fRowWidth  = 0.0f;
-    FLOAT fRowHeight = (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
-    FLOAT fWidth     = 0.0f;
-    FLOAT fHeight    = fRowHeight;
-
-    while(*strText) {
-        TCHAR c = *strText++;
-
-        if(c == _T('\n')) {
-            fRowWidth = 0.0f;
-            fHeight  += fRowHeight;
-        }
-        if(c < _T(' '))
-            continue;
-
-        FLOAT tx1 = m_fTexCoords[c-32][0];
-        FLOAT tx2 = m_fTexCoords[c-32][2];
-
-        fRowWidth += (tx2-tx1)*m_dwTexWidth;
-
-        if(fRowWidth > fWidth)
-            fWidth = fRowWidth;
-    }
-
-    pSize->cx = (int)fWidth;
-    pSize->cy = (int)fHeight;
-
-    return S_OK;
-}
-
-//-----------------------------------------------------------------------------
-// Name: DrawTextScaled()
-// Desc: Draws scaled 2D text.  Note that x and y are in viewport coordinates
-//       (ranging from -1 to +1).  fXScale and fYScale are the size fraction 
-//       relative to the entire viewport.  For example, a fXScale of 0.25 is
-//       1/8th of the screen width.  This allows you to output text at a fixed
-//       fraction of the viewport, even if the screen or window size changes.
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
-                                  FLOAT fXScale, FLOAT fYScale, DWORD dwColor,
-                                  TCHAR* strText, DWORD dwFlags ) {
-    if(m_pd3dDevice == NULL)
-        return E_FAIL;
-
-    HRESULT hr ; 
-    if(m_bBeginText) {
-        hr = DeferedDrawTextScaled ( x, y, z, fXScale, fYScale, dwColor, strText, dwFlags ) ; 
-    } else {
-        BeginText ( ) ; 
-        hr = DeferedDrawTextScaled ( x, y, z, fXScale, fYScale, dwColor, strText, dwFlags ) ; 
-        if(! FAILED ( hr ))
-            EndText ( ) ;
-    } ; 
-
-    return hr ;
-}
-
-//-----------------------------------------------------------------------------
-// Name: DrawText()
-// Desc: Draws 2D text
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
-                            TCHAR* strText, DWORD dwFlags ) {
-    if(m_pd3dDevice == NULL)
-        return E_FAIL;
-
-    HRESULT hr ; 
-    if(m_bBeginText) {
-        hr = DeferedDrawText ( sx, sy, dwColor, strText, dwFlags ) ; 
-    } else {
-        BeginText(); 
-        hr = DeferedDrawText ( sx, sy, dwColor, strText, dwFlags ) ; 
-        if(! FAILED ( hr ))
-            EndText ( ) ;
-    } ; 
-
-    return hr ;
-}
-
-
-void CD3DFont::ClearBeginEndData ( void ) {
-    m_nDeferedCalls = 0 ; 
-    m_TextBuffer [ 0 ] = 0 ; 
-    m_pTextBuffer = & m_TextBuffer [ 0 ] ; 
-} 
-
-HRESULT CD3DFont::BeginText ( void ) {
-    m_bBeginText = true ; 
-    ClearBeginEndData() ; 
-
-    return S_OK ; 
-} 
-
-HRESULT CD3DFont::DeferedDrawTextScaled
-( FLOAT x, FLOAT y, FLOAT z, 
-  FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
-  TCHAR* strText, DWORD dwFlags ) {
-    return 
-    DeferedDraw ( true , x, y, z, fXScale, fYScale, dwColor, strText, dwFlags ) ; 
-} 
-
-HRESULT CD3DFont::DeferedDrawText
-( FLOAT x, FLOAT y, DWORD dwColor, 
-  TCHAR* strText, DWORD dwFlags ) {
-    return 
-    DeferedDraw ( false , x, y, 0.0f , 0.0f , 0.0f , dwColor, strText, dwFlags ) ; 
-} 
-
-HRESULT CD3DFont::DeferedDraw
-( bool bScaled , 
-  FLOAT x, FLOAT y, FLOAT z, 
-  FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
-  TCHAR* strText, DWORD dwFlags ) {
-    if(m_nDeferedCalls >= MaxCalls) {
-        dxgsg8_cat.error() << "CD3DFont DeferedDraw() error, MaxCalls exceeded!\n";
-        return E_FAIL ;
-    }
-
-    // we need to make a deep copy of the string 
-    // the user object might have fallen out of scope
-    // when it will be time to render 
-    int nStrLen = strlen ( strText ) + 1 ; 
-    int nUsed = m_pTextBuffer - & m_pTextBuffer [ 0 ] ; 
-    if(nUsed + nStrLen > TextBufferLength) {
-        dxgsg8_cat.error() << "CD3DFont DeferedDraw() error, TextBufferLength exceeded!\n";
-        return E_FAIL ;
-    }
-
-    strcpy ( m_pTextBuffer , strText ) ; 
-    m_DTArgs [ m_nDeferedCalls ].m_strText = m_pTextBuffer ; 
-    m_pTextBuffer += nStrLen ; 
-
-    m_DTArgs [ m_nDeferedCalls ].m_bScaled = bScaled ; 
-    m_DTArgs [ m_nDeferedCalls ].m_x = x ; 
-    m_DTArgs [ m_nDeferedCalls ].m_y = y ; 
-    m_DTArgs [ m_nDeferedCalls ].m_z = z ; 
-    m_DTArgs [ m_nDeferedCalls ].m_fXScale = fXScale ; 
-    m_DTArgs [ m_nDeferedCalls ].m_fYScale = fYScale ; 
-    m_DTArgs [ m_nDeferedCalls ].m_dwColor = dwColor ; 
-    m_DTArgs [ m_nDeferedCalls ].m_dwFlags = dwFlags ; 
-
-    m_nDeferedCalls ++ ; 
-
-    return S_OK ; 
-} 
-
-HRESULT CD3DFont::EndText ( void ) {
-    if(m_pd3dDevice == NULL)
-        return E_FAIL;
-    HRESULT hr;
-
-    assert(IS_VALID_PTR(m_pVB));
-
-    DWORD hSavedVertexShader,hSavedPixelShader;
-    UINT SavedStreamStride;
-    IDirect3DVertexBuffer8 *pSavedStreamData=NULL;
-
-    hr = m_pd3dDevice->GetVertexShader(&hSavedVertexShader);
-    hr = m_pd3dDevice->GetPixelShader(&hSavedPixelShader);
-
-    // Set up renderstate
-    hr = m_pd3dDevice->CaptureStateBlock( m_dwSavedStateBlock );
-    hr = m_pd3dDevice->ApplyStateBlock( m_dwDrawTextStateBlock );
-    if(hSavedVertexShader!=D3DFVF_FONT2DVERTEX)
-        hr = m_pd3dDevice->SetVertexShader(D3DFVF_FONT2DVERTEX);
-    if(hSavedPixelShader!=NULL)
-        hr = m_pd3dDevice->SetPixelShader(NULL);
-
-    hr = m_pd3dDevice->GetStreamSource(0,&pSavedStreamData,&SavedStreamStride);
-    if(FAILED(hr)) {
-        dxgsg8_cat.error() << "CD3DFont EndText GetStreamSource() failed!" << D3DERRORSTRING(hr);
-        return E_FAIL;
-    }
-
-    // undo GetStreamSource AddRef
-    SAFE_RELEASE(pSavedStreamData);
-
-    if((pSavedStreamData!=m_pVB)||(SavedStreamStride!=sizeof(FONT2DVERTEX))) {
-        hr = m_pd3dDevice->SetStreamSource(0,m_pVB,sizeof(FONT2DVERTEX));
-        if(FAILED(hr)) {
-            dxgsg8_cat.error() << "CD3DFont EndText initial SetStreamSource() failed!" << D3DERRORSTRING(hr);
-            return E_FAIL;
-        }
-    }
-
-    // Set filter states
-    //
-    // filter if any in our list is specified filtered 
-    //
-    // This functionality is different from the original D3DFont 
-    // but is a significant speed increase
-    //
-    // User will make another batch if necessary
-    //  
-    bool bFiltered = false ; 
-    UINT i;
-    for(i = 0 ; i < m_nDeferedCalls ; ++ i) {
-        DWORD   dwFlags = m_DTArgs [ i ].m_dwFlags ; 
-        if(dwFlags & D3DFONT_FILTERED) {
-            bFiltered = true ; 
-            break ; 
-        }
-    } ; 
-    if(bFiltered) {
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
-    }; 
-
-    // useless if nothing is scaled but should be fast enough 
-    D3DVIEWPORT8 vp;
-    m_pd3dDevice->GetViewport( &vp );
-    FLOAT fLineHeight = ( m_fTexCoords[0][3] - m_fTexCoords[0][1] ) * m_dwTexHeight;
-
-    // Fill vertex buffer
-    FONT2DVERTEX* pVertices;
-    DWORD         dwNumTriangles = 0L;
-    m_pVB->Lock( 0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD );
-
-    bool bItalic = 0 != ( m_dwFontFlags & D3DFONT_ITALIC ) ; 
-    // loop on our batched sets of arguments 
-    for(i = 0 ; i < m_nDeferedCalls ; ++ i) {
-        bool    bScaled = m_DTArgs [ i ].m_bScaled ; 
-        FLOAT   x       = m_DTArgs [ i ].m_x       ; 
-        FLOAT   y       = m_DTArgs [ i ].m_y       ; 
-        FLOAT   z       = m_DTArgs [ i ].m_z       ; 
-        FLOAT   fXScale = m_DTArgs [ i ].m_fXScale ; 
-        FLOAT   fYScale = m_DTArgs [ i ].m_fYScale ; 
-        DWORD   dwColor = m_DTArgs [ i ].m_dwColor ; 
-        TCHAR * strText = m_DTArgs [ i ].m_strText ; 
-
-        if(bScaled) {
-
-            FLOAT sx  = (x+1.0f)*vp.Width/2;
-            FLOAT sy  = (y-1.0f)*vp.Height/2;
-            FLOAT sz  = z;
-            FLOAT rhw = 1.0f;
-            FLOAT fStartX = sx;
-
-            FLOAT fBend = 0.0f ; 
-            if(bItalic)
-                fBend = fYScale*vp.Height / 4.0f ;
-
-            while(*strText) {
-                TCHAR c = *strText++;
-
-                if(c == _T('\n')) {
-                    sx  = fStartX;
-                    sy += fYScale*vp.Height;
-                }
-                if(c < _T(' '))
-                    continue;
-
-                FLOAT tx1 = m_fTexCoords[c-32][0];
-                FLOAT ty1 = m_fTexCoords[c-32][1];
-                FLOAT tx2 = m_fTexCoords[c-32][2];
-                FLOAT ty2 = m_fTexCoords[c-32][3];
-
-                FLOAT w = (tx2-tx1)*m_dwTexWidth;
-                FLOAT h = (ty2-ty1)*m_dwTexHeight;
-
-                w *= (fXScale*vp.Height)/fLineHeight;
-                h *= (fYScale*vp.Height)/fLineHeight;
-
-                if(c != _T(' ')) {
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,sz,rhw), dwColor, tx1, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f + fBend,sy+0-0.5f,sz,rhw), dwColor, tx1, ty1 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,sz,rhw), dwColor, tx2, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f + fBend,sy+0-0.5f,sz,rhw), dwColor, tx2, ty1 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,sz,rhw), dwColor, tx2, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f + fBend,sy+0-0.5f,sz,rhw), dwColor, tx1, ty1 );
-                    dwNumTriangles += 2;
-
-                    if(dwNumTriangles*3 > (MAX_NUM_VERTICES-6)) {
-                        // Unlock, render, and relock the vertex buffer
-                        m_pVB->Unlock();
-                        m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
-                        m_pVB->Lock( 0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD );
-                        dwNumTriangles = 0L;
-                    }
-                }
-
-                sx += w;
-            } ; 
-        } else {  // not scaled 
-            FLOAT fBend = 0.0f ; 
-            if(bItalic)
-                fBend = fLineHeight / 4.0f ;
-
-            // Lazy guy...
-            FLOAT sx = x ; 
-            FLOAT sy = y ; 
-
-            FLOAT fStartX = sx;
-            while(*strText) {
-                TCHAR c = *strText++;
-
-                if(c == _T('\n')) {
-                    sx = fStartX ;
-                    sy += fLineHeight ;
-                }
-                if(c < _T(' '))
-                    continue;
-
-                FLOAT tx1 = m_fTexCoords[c-32][0];
-                FLOAT ty1 = m_fTexCoords[c-32][1];
-                FLOAT tx2 = m_fTexCoords[c-32][2];
-                FLOAT ty2 = m_fTexCoords[c-32][3];
-
-                FLOAT w = (tx2-tx1) *  m_dwTexWidth / m_fTextScale;
-                FLOAT h = (ty2-ty1) * m_dwTexHeight / m_fTextScale;
-
-                if(c != _T(' ')) {
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx1, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f + fBend,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f + fBend,sy+0-0.5f,0.9f,1.0f), dwColor, tx2, ty1 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
-                    *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f + fBend,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
-                    dwNumTriangles += 2;
-
-                    if(dwNumTriangles*3 > (MAX_NUM_VERTICES-6)) {
-                        // Unlock, render, and relock the vertex buffer
-                        m_pVB->Unlock();
-                        m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
-                        pVertices = NULL;
-                        m_pVB->Lock( 0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD );
-                        dwNumTriangles = 0L;
-                    }
-                };  // endif not blank 
-
-                sx += w;
-            } ; // end while 
-
-        } ; // end if else scaled 
-
-    } ; // end for 
-
-    m_bBeginText = false ; 
-    ClearBeginEndData ( ) ; 
-
-    // Unlock and render the vertex buffer
-    m_pVB->Unlock();
-    if(dwNumTriangles > 0)
-        m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
-
-    // Restore the modified renderstates
-    m_pd3dDevice->ApplyStateBlock( m_dwSavedStateBlock );
-    if((hSavedVertexShader!=NULL) && (hSavedVertexShader!=D3DFVF_FONT2DVERTEX))
-        m_pd3dDevice->SetVertexShader(hSavedVertexShader);
-    if(hSavedPixelShader!=NULL)
-        m_pd3dDevice->SetPixelShader(hSavedPixelShader);
-
-    if(IS_VALID_PTR(pSavedStreamData) && ((pSavedStreamData!=m_pVB)||(SavedStreamStride!=sizeof(FONT2DVERTEX)))) {
-        hr = m_pd3dDevice->SetStreamSource(0,pSavedStreamData,SavedStreamStride);
-        if(FAILED(hr)) {
-            dxgsg8_cat.error() << "CD3DFont EndText restore SetStreamSource() failed!" << D3DERRORSTRING(hr);
-            return E_FAIL;
-        }
-        pSavedStreamData->Release();
-    }
-
-    return S_OK;
-} 
-
-#if 0
-// dont need this now
-//-----------------------------------------------------------------------------
-// Name: Render3DText()
-// Desc: Renders 3D text
-//-----------------------------------------------------------------------------
-HRESULT CD3DFont::Render3DText( TCHAR* strText, DWORD dwFlags ) {
-    if(m_pd3dDevice == NULL)
-        return E_FAIL;
-
-    // Setup renderstate
-    m_pd3dDevice->CaptureStateBlock( m_dwSavedStateBlock );
-    m_pd3dDevice->ApplyStateBlock( m_dwDrawTextStateBlock );
-    m_pd3dDevice->SetVertexShader( D3DFVF_FONT3DVERTEX );
-    m_pd3dDevice->SetPixelShader( NULL );
-    m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(FONT3DVERTEX) );
-
-    // Set filter states
-    if(dwFlags & D3DFONT_FILTERED) {
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
-        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
-    }
-
-    // Position for each text element
-    FLOAT x = 0.0f;
-    FLOAT y = 0.0f;
-
-    // Center the text block at the origin
-    if(dwFlags & D3DFONT_CENTERED) {
-        SIZE sz;
-        GetTextExtent( strText, &sz );
-        x = -(((FLOAT)sz.cx)/10.0f)/2.0f;
-        y = -(((FLOAT)sz.cy)/10.0f)/2.0f;
-    }
-
-    // Turn off culling for two-sided text
-    if(dwFlags & D3DFONT_TWOSIDED)
-        m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
-
-    FLOAT fStartX = x;
-    TCHAR c;
-
-    // Fill vertex buffer
-    FONT3DVERTEX* pVertices;
-    // DWORD         dwVertex       = 0L; // not ref'ed
-    DWORD         dwNumTriangles = 0L;
-    m_pVB->Lock( 0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD );
-
-    bool bItalic = 0 != ( m_dwFontFlags & D3DFONT_ITALIC ) ; 
-    FLOAT fBend = 0.0f ; 
-    if(bItalic)
-        fBend = ( ( m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight/10.0f ) / 4.0f ;
-
-    while(c = *strText++) {
-        if(c == '\n') {
-            x = fStartX;
-            y -= (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight/10.0f;
-        }
-        if(c < 32)
-            continue;
-
-        FLOAT tx1 = m_fTexCoords[c-32][0];
-        FLOAT ty1 = m_fTexCoords[c-32][1];
-        FLOAT tx2 = m_fTexCoords[c-32][2];
-        FLOAT ty2 = m_fTexCoords[c-32][3];
-
-        FLOAT w = (tx2-tx1) * m_dwTexWidth  / ( 10.0f * m_fTextScale );
-        FLOAT h = (ty2-ty1) * m_dwTexHeight / ( 10.0f * m_fTextScale );
-
-        if(c != _T(' ')) {
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0,y+0,0), D3DXVECTOR3(0,0,-1), tx1, ty2 );
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0 + fBend ,y+h,0), D3DXVECTOR3(0,0,-1), tx1, ty1 );
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+w,y+0,0), D3DXVECTOR3(0,0,-1), tx2, ty2 );
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+w + fBend ,y+h,0), D3DXVECTOR3(0,0,-1), tx2, ty1 );
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+w,y+0,0), D3DXVECTOR3(0,0,-1), tx2, ty2 );
-            *pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0 + fBend ,y+h,0), D3DXVECTOR3(0,0,-1), tx1, ty1 );
-            dwNumTriangles += 2;
-
-            if(dwNumTriangles*3 > (MAX_NUM_VERTICES-6)) {
-                // Unlock, render, and relock the vertex buffer
-                m_pVB->Unlock();
-                m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
-                m_pVB->Lock( 0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD );
-                dwNumTriangles = 0L;
-            }
-        }
-
-        x += w;
-    }
-
-    // Unlock and render the vertex buffer
-    m_pVB->Unlock();
-    if(dwNumTriangles > 0)
-        m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
-
-    // Restore the modified renderstates
-    m_pd3dDevice->ApplyStateBlock( m_dwSavedStateBlock );
-
-    return S_OK;
-}
-#endif

+ 0 - 112
panda/src/dxgsg8/d3dfont8.h

@@ -1,112 +0,0 @@
-//--------------------------------------------------------------------------------------------
-// File: D3DFont.h
-//
-// Desc: Texture-based font class
-//       based on a modified version of DXSDK CD3DFont from http://www.lafaqmfc.com/directx.htm
-//       Note that this is faster than ID3DXFont, which calls GDI in Draw()
-//---------------------------------------------------------------------------------------------
-#ifndef D3DFONT_H
-#define D3DFONT_H
-#include <tchar.h>
-#include <d3d8.h>
-
-// Font creation flags
-#define D3DFONT_BOLD        0x0001
-#define D3DFONT_ITALIC      0x0002
-#define D3DFONT_ZENABLE     0x0004
-
-// Font rendering flags
-#define D3DFONT_CENTERED    0x0001
-#define D3DFONT_TWOSIDED    0x0002
-#define D3DFONT_FILTERED    0x0004
-
-//-----------------------------------------------------------------------------
-// Name: class CD3DFont
-// Desc: Texture-based font class for doing text in a 3D scene.
-//-----------------------------------------------------------------------------
-class CD3DFont
-{
-    enum 
-    { 
-        D3DFVF_FONT2DVERTEX = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1) , 
-        D3DFVF_FONT3DVERTEX = (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1) , 
-        TextBufferLength = 1024 , 
-        MAX_NUM_VERTICES = TextBufferLength * 6 , 
-        MaxCalls = 30 
-    } ; 
-
-    TCHAR   m_strFontName[80];            // Font properties
-    DWORD   m_dwFontHeight;
-    DWORD   m_dwFontFlags;
-
-    LPDIRECT3DDEVICE8       m_pd3dDevice; // A D3DDevice used for rendering
-    LPDIRECT3DTEXTURE8      m_pTexture;   // The d3d texture for this font
-    LPDIRECT3DVERTEXBUFFER8 m_pVB;        // VertexBuffer for rendering text
-    DWORD   m_dwTexWidth;                 // Texture dimensions
-    DWORD   m_dwTexHeight;
-    FLOAT   m_fTextScale;
-    FLOAT   m_fTexCoords[128-32][4];
-
-    // Stateblocks for setting and restoring render states
-    DWORD   m_dwSavedStateBlock;
-    DWORD   m_dwDrawTextStateBlock;
-
-    struct DrawTextArgs 
-    {
-        bool  m_bScaled ; 
-        FLOAT m_x ;  FLOAT m_y ;  FLOAT m_z ; 
-        FLOAT m_fXScale ; FLOAT m_fYScale ; 
-        DWORD m_dwColor ;  
-        TCHAR *m_strText ; 
-        DWORD m_dwFlags ; 
-    } ; 
-
-    DrawTextArgs m_DTArgs [ MaxCalls ] ; 
-    char    m_TextBuffer  [ TextBufferLength ] ; 
-    char   *m_pTextBuffer ; 
-    UINT    m_nDeferedCalls ;
-    bool    m_bBeginText ; 
-    inline  HRESULT DeferedDrawText( FLOAT x, FLOAT y, DWORD dwColor, 
-                      TCHAR* strText, DWORD dwFlags=0L );
-    inline  HRESULT DeferedDrawTextScaled ( FLOAT x, FLOAT y, FLOAT z, 
-                            FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
-                            TCHAR* strText, DWORD dwFlags=0L ) ; 
-    inline  HRESULT DeferedDraw
-            ( bool bScaled , 
-              FLOAT x, FLOAT y, FLOAT z, 
-              FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
-              TCHAR* strText, DWORD dwFlags ) ; 
-
-    inline  void ClearBeginEndData (void ) ; 
-
-
-public:
-    // 2D and 3D text drawing functions
-    HRESULT BeginText ( void ) ;
-    HRESULT EndText ( void ) ;
-
-    HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor, 
-                      TCHAR* strText, DWORD dwFlags=0L );
-    HRESULT DrawTextScaled ( FLOAT x, FLOAT y, FLOAT z, 
-                            FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
-                            TCHAR* strText, DWORD dwFlags=0L ) ; 
-
-   // HRESULT Render3DText( TCHAR* strText, DWORD dwFlags=0L );
-    
-    // Function to get extent of text
-    HRESULT GetTextExtent( TCHAR* strText, SIZE* pSize );
-
-    // Initializing and destroying device-dependent objects
-    HRESULT InitDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice);
-    HRESULT RestoreDeviceObjects(void);
-    HRESULT InvalidateDeviceObjects(void);
-    HRESULT DeleteDeviceObjects(void);
-
-    // Constructor / destructor
-    CD3DFont( TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
-    ~CD3DFont();
-};
-
-#endif
-
-

+ 53 - 340
panda/src/dxgsg8/dxGraphicsStateGuardian8.I

@@ -21,52 +21,52 @@ INLINE DWORD
 Colorf_to_D3DCOLOR(const Colorf &cColorf) {
 // MS VC defines _M_IX86 for x86.  gcc should define _X86_
 #if defined(_M_IX86) || defined(_X86_)
-    DWORD d3dcolor,tempcolorval=255;
+  DWORD d3dcolor, tempcolorval=255;
 
-    // note the default FPU rounding mode will give 255*0.5f=0x80, not 0x7F as VC would force it to by resetting rounding mode
-    // dont think this makes much difference
-
-    __asm {
+  // note the default FPU rounding mode will give 255*0.5f=0x80, not 0x7F as VC would force it to by resetting rounding mode
+  // dont think this makes much difference
+  
+  __asm {
         push ebx   ; want to save this in case this fn is inlined
         push ecx
         mov ecx, cColorf
         fild tempcolorval
         fld DWORD PTR [ecx]
-        fmul ST(0),ST(1)
+        fmul ST(0), ST(1)
         fistp tempcolorval  ; no way to store directly to int register
         mov eax, tempcolorval
         shl eax, 16
 
         fld DWORD PTR [ecx+4]  ;grn
-        fmul ST(0),ST(1)
+        fmul ST(0), ST(1)
         fistp tempcolorval
-        mov ebx,tempcolorval
+        mov ebx, tempcolorval
         shl ebx, 8
-        or eax,ebx
+        or eax, ebx
 
         fld DWORD PTR [ecx+8]  ;blue
-        fmul ST(0),ST(1)
+        fmul ST(0), ST(1)
         fistp tempcolorval
-        or eax,tempcolorval
+        or eax, tempcolorval
 
         fld DWORD PTR [ecx+12] ;alpha
-        fmul ST(0),ST(1)
+        fmul ST(0), ST(1)
         fistp tempcolorval
         ; simulate pop 255.0 off FP stack w/o store, mark top as empty and increment stk ptr
         ffree ST(0)
         fincstp
-        mov ebx,tempcolorval
+        mov ebx, tempcolorval
         shl ebx, 24
-        or eax,ebx
-        mov d3dcolor,eax
+        or eax, ebx
+        mov d3dcolor, eax
         pop ecx
         pop ebx
-    }
+  }
 
-   //   dxgsg8_cat.debug() << (void*)d3dcolor << endl;
-   return d3dcolor;
+  //   dxgsg8_cat.debug() << (void*)d3dcolor << endl;
+  return d3dcolor;
 #else //!_X86_
-   return MY_D3DRGBA(cColorf[0], cColorf[1], cColorf[2], cColorf[3]);
+  return MY_D3DRGBA(cColorf[0], cColorf[1], cColorf[2], cColorf[3]);
 #endif //!_X86_
 }
 
@@ -79,12 +79,6 @@ INLINE void DXGraphicsStateGuardian8::
 enable_line_smooth(bool val) {
   if(_line_smooth_enabled != val) {
     _line_smooth_enabled = val;
-  #ifndef NDEBUG
-    {
-        if(val && (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES))
-           dxgsg8_cat.error() << "no HW support for line smoothing!!\n";
-    }
-  #endif
 
     _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, (DWORD)val);
   }
@@ -100,30 +94,10 @@ enable_dither(bool val) {
   if (_dither_enabled != val) {
     _dither_enabled = val;
 
-  #ifndef NDEBUG
-    {
-        if(val && !(_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_DITHER))
-           dxgsg8_cat.error() << "no HW support for color dithering!!\n";
-    }
-  #endif
-
     _pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, (DWORD)val);
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_stencil_test
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_stencil_test(bool val) {
-  if (_stencil_test_enabled != val) {
-    _stencil_test_enabled = val;
-    _pD3DDevice->SetRenderState(D3DRS_STENCILENABLE, (DWORD)val);
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::enable_color_material
 //       Access:
@@ -150,24 +124,6 @@ enable_blend(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_texturing
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_texturing(bool val) {
-  _texturing_enabled = val;
-  
-  if (!val) {
-    _pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE);
-
-  } else {
-    nassertv(_pCurTexContext!=NULL);
-    SetTextureBlendMode(_CurTexBlendMode,true);
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::set_color_writemask
 //       Access:
@@ -178,12 +134,12 @@ set_color_writemask(UINT color_writemask) {
   if (_color_writemask != color_writemask) {
     _color_writemask = color_writemask;
     if(_pScrn->bCanDirectDisableColorWrites) {
-        // only newer HW supports this rstate
-        _pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)color_writemask);
+      // only newer HW supports this rstate
+      _pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)color_writemask);
     } else {
-        // blending can only handle on/off
-        assert((color_writemask==0x0)||(color_writemask==0xFFFFFFFF));
-        set_blend_mode();
+      // blending can only handle on/off
+      assert((color_writemask==0x0)||(color_writemask==0xFFFFFFFF));
+      set_blend_mode();
     }
   }
 }
@@ -201,17 +157,6 @@ enable_fog(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::add_to_FVFBuf
-//       Access: Private
-//  Description: This adds data to the flexible vertex format
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-add_to_FVFBuf(void *data,  size_t bytes) {
-    memcpy(_pCurFvfBufPtr, data, bytes);
-    _pCurFvfBufPtr += bytes;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::set_vertex_format
 //       Access:
@@ -219,33 +164,16 @@ add_to_FVFBuf(void *data,  size_t bytes) {
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 set_vertex_format(DWORD NewFvfType) {
-#ifdef USE_VERTEX_SHADERS
-  if(_CurVertexShader!=NULL) {
-    // this needs optimization
-    HRESULT hr = _pD3DDevice->SetVertexShader(_CurVertexShader);
-    #ifndef NDEBUG
-    if(FAILED(hr)) {
-           dxgsg8_cat.error() << "SetVertexShader for custom vtx shader failed" << D3DERRORSTRING(hr);
-           exit(1);
-    }
-    #endif
-    _CurFVFType = NewFvfType;    
-    return;
-  }
-#endif
-
   if (_CurFVFType != NewFvfType) {
     _CurFVFType = NewFvfType;
 
-    //    dxgsg8_cat.info() << "current fvf " << _CurFVFType << endl;
-
     HRESULT hr = _pD3DDevice->SetVertexShader(NewFvfType);
- #ifndef NDEBUG
+#ifndef NDEBUG
     if(FAILED(hr)) {
-           dxgsg8_cat.error() << "SetVertexShader(0x" << (void*)NewFvfType<<") failed" << D3DERRORSTRING(hr);
-           exit(1);
+      dxgsg8_cat.error() << "SetVertexShader(0x" << (void*)NewFvfType<<") failed" << D3DERRORSTRING(hr);
+      exit(1);
     }
- #endif
+#endif
   }
 }
 
@@ -255,8 +183,7 @@ set_vertex_format(DWORD NewFvfType) {
 //  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
-enable_alpha_test(bool val )
-{
+enable_alpha_test(bool val) {
   if (_alpha_test_enabled != val) {
     _alpha_test_enabled = val;
     _pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, (DWORD)val);
@@ -269,15 +196,11 @@ enable_alpha_test(bool val )
 //  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
-call_dxLightModelAmbient( const Colorf& color)
-{
+call_dxLightModelAmbient(const Colorf &color) {
   if (_lmodel_ambient != color) {
     _lmodel_ambient = color;
-#ifdef GSG_VERBOSE
-    dxgsg8_cat.debug() << "dxLightModel(LIGHT_MODEL_AMBIENT, " << color << ")" << endl;
-#endif
-    _pD3DDevice->SetRenderState( D3DRS_AMBIENT,
-                D3DCOLOR_COLORVALUE(color[0], color[1], color[2], color[3]));
+    _pD3DDevice->SetRenderState(D3DRS_AMBIENT, 
+                                 D3DCOLOR_COLORVALUE(color[0], color[1], color[2], color[3]));
   }
 }
 
@@ -291,209 +214,44 @@ INLINE void DXGraphicsStateGuardian8::
 call_dxAlphaFunc(D3DCMPFUNC func, float reference_alpha) {
   if (_alpha_func != func) {
     _alpha_func = func;
-#ifdef GSG_VERBOSE
-    dxgsg8_cat.debug() << "dxAlphaFunc(";
-    switch (func) {
-    case D3DCMP_NEVER:
-      dxgsg8_cat.debug(false) << "D3DCMP_NEVER";
-      break;
-    case D3DCMP_LESS:
-      dxgsg8_cat.debug(false) << "D3DCMP_LESS";
-      break;
-    case D3DCMP_EQUAL:
-      dxgsg8_cat.debug(false) << "D3DCMP_EQUAL";
-      break;
-#ifdef D3DCMP_LEQUAL
-    case D3DCMP_LEQUAL:
-      dxgsg8_cat.debug(false) << "D3DCMP_LEQUAL";
-      break;
-#endif
-    case D3DCMP_GREATER:
-      dxgsg8_cat.debug(false) << "D3DCMP_GREATER";
-      break;
-    case D3DCMP_NOTEQUAL:
-      dxgsg8_cat.debug(false) << "D3DCMP_NOTEQUAL";
-      break;
-#ifdef D3DCMP_GEQUAL
-    case D3DCMP_GEQUAL:
-      dxgsg8_cat.debug(false) << "D3DCMP_GEQUAL";
-      break;
-#endif
-    case D3DCMP_ALWAYS:
-      dxgsg8_cat.debug(false) << "D3DCMP_ALWAYS";
-      break;
-    }
-    dxgsg8_cat.debug() << " , " << reference_alpha << ")" << endl;
-#endif
     _pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, func);
   }
 
   if(_alpha_func_refval != reference_alpha) {
-      _alpha_func_refval = reference_alpha;
-      _pD3DDevice->SetRenderState(D3DRS_ALPHAREF, (UINT) (reference_alpha*255.0f));  //d3d uses 0x0-0xFF, not a float
+    _alpha_func_refval = reference_alpha;
+    _pD3DDevice->SetRenderState(D3DRS_ALPHAREF, (UINT) (reference_alpha*255.0f));  //d3d uses 0x0-0xFF, not a float
   }
 }
 
 
 INLINE void DXGraphicsStateGuardian8::
-call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc )
-{
-  if (_blend_source_func != sfunc)
-    {
+call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc) {
+  if (_blend_source_func != sfunc) {
     _blend_source_func = sfunc;
     _pD3DDevice->SetRenderState(D3DRS_SRCBLEND, sfunc);
-#ifdef GSG_VERBOSE
-    dxgsg8_cat.debug() << "dxSrcBlendFunc(";
-    switch (sfunc)
-        {
-        case D3DBLEND_ZERO:
-          dxgsg8_cat.debug(false) << "ZERO, ";
-          break;
-        case D3DBLEND_ONE:
-          dxgsg8_cat.debug(false) << "ONE, ";
-          break;
-        case D3DBLEND_DESTCOLOR:
-          dxgsg8_cat.debug(false) << "DESTCOLOR, ";
-          break;
-        case D3DBLEND_INVDESTCOLOR:
-          dxgsg8_cat.debug(false) << "INVDESTCOLOR, ";
-          break;
-        case D3DBLEND_SRCALPHA:
-          dxgsg8_cat.debug(false) << "SRCALPHA, ";
-          break;
-        case D3DBLEND_INVSRCALPHA:
-          dxgsg8_cat.debug(false) << "INVSRCALPHA, ";
-          break;
-        case D3DBLEND_DESTALPHA:
-          dxgsg8_cat.debug(false) << "DESTALPHA, ";
-          break;
-        case D3DBLEND_INVDESTALPHA:
-          dxgsg8_cat.debug(false) << "INVDESTALPHA, ";
-          break;
-        case D3DBLEND_SRCALPHASAT:
-          dxgsg8_cat.debug(false) << "SRCALPHASAT, ";
-          break;
-        default:
-          dxgsg8_cat.debug(false) << "unknown, ";
-          break;
-        }
-    dxgsg8_cat.debug(false) << endl;
-#endif
-    }
-  if ( _blend_dest_func != dfunc)
-    {
+  }
+  if (_blend_dest_func != dfunc) {
     _blend_dest_func = dfunc;
     _pD3DDevice->SetRenderState(D3DRS_DESTBLEND, dfunc);
-#ifdef GSG_VERBOSE
-    dxgsg8_cat.debug() << "dxDstBlendFunc(";
-    switch (dfunc)
-        {
-        case D3DBLEND_ZERO:
-          dxgsg8_cat.debug(false) << "ZERO, ";
-          break;
-        case D3DBLEND_ONE:
-          dxgsg8_cat.debug(false) << "ONE, ";
-          break;
-        case D3DBLEND_DESTCOLOR:
-          dxgsg8_cat.debug(false) << "DESTCOLOR, ";
-          break;
-        case D3DBLEND_INVDESTCOLOR:
-          dxgsg8_cat.debug(false) << "INVDESTCOLOR, ";
-          break;
-        case D3DBLEND_SRCALPHA:
-          dxgsg8_cat.debug(false) << "SRCALPHA, ";
-          break;
-        case D3DBLEND_INVSRCALPHA:
-          dxgsg8_cat.debug(false) << "INVSRCALPHA, ";
-          break;
-        case D3DBLEND_DESTALPHA:
-          dxgsg8_cat.debug(false) << "DESTALPHA, ";
-          break;
-        case D3DBLEND_INVDESTALPHA:
-          dxgsg8_cat.debug(false) << "INVDESTALPHA, ";
-          break;
-        case D3DBLEND_SRCALPHASAT:
-          dxgsg8_cat.debug(false) << "SRCALPHASAT, ";
-          break;
-        }
-    dxgsg8_cat.debug(false) << endl;
-#endif
-    }
+  }
 }
 
 INLINE void DXGraphicsStateGuardian8::
 enable_zwritemask(bool val) {
-    if (_depth_write_enabled != val) {
-        _depth_write_enabled = val;
-        _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, val);
-    }
-}
-
-INLINE void DXGraphicsStateGuardian8::
-transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) {
-  Colorf transformed
-    (InColor[0] * _current_color_scale[0],
-     InColor[1] * _current_color_scale[1],
-     InColor[2] * _current_color_scale[2],
-     InColor[3] * _current_color_scale[3]);
-  OutRGBAColor = Colorf_to_D3DCOLOR(transformed);
-}
-
-/*
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::wants_normals
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE bool DXGraphicsStateGuardian8::
-wants_normals() const {
-    return (_lighting_enabled || _normals_enabled);
-}
-*/
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::wants_texcoords
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE bool DXGraphicsStateGuardian8::
-wants_texcoords() const {
-    return _texturing_enabled;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::compute_distance_to
-//       Access: Public, Virtual
-//  Description: This function may only be called during a render
-//               traversal; it will compute the distance to the
-//               indicated point, assumed to be in eye coordinates,
-//               from the camera plane.
-////////////////////////////////////////////////////////////////////
-INLINE float DXGraphicsStateGuardian8::
-compute_distance_to(const LPoint3f &point) const {
-    // In the case of a DXGraphicsStateGuardian8, we know that the
-    // modelview matrix already includes the relative transform from the
-    // camera, as well as a to-y-up conversion.  Thus, the distance to
-    // the camera plane is simply the +z distance.  (negative of gl compute_distance_to,
-    // since d3d uses left-hand coords)
-
-    return point[2];
+  if (_depth_write_enabled != val) {
+    _depth_write_enabled = val;
+    _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, val);
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::get_texture_wrap_mode
-//       Access: Protected
+//       Access: Protected, Static
 //  Description: Maps from the Texture's internal wrap mode symbols to
 //               GL's.
 ////////////////////////////////////////////////////////////////////
 INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian8::
-get_texture_wrap_mode(Texture::WrapMode wm) const {
-#if 0
-  static D3DTEXTUREADDRESS PandaTexWrapMode_to_D3DTexWrapMode[Texture::WM_invalid] = {
-    D3DTADDRESS_CLAMP,D3DTADDRESS_WRAP,D3DTADDRESS_MIRROR,D3DTADDRESS_MIRRORONCE,D3DTADDRESS_BORDER};
-
-    return PandaTexWrapMode_to_D3DTexWrapMode[wm];
-#endif
+get_texture_wrap_mode(Texture::WrapMode wm) {
   switch (wm) {
   case Texture::WM_clamp:
     return D3DTADDRESS_CLAMP;
@@ -512,11 +270,11 @@ get_texture_wrap_mode(Texture::WrapMode wm) const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::get_fog_mode_type
-//       Access: Protected
+//       Access: Protected, Static
 //  Description: Maps from the fog types to gl version
 ////////////////////////////////////////////////////////////////////
 INLINE D3DFOGMODE DXGraphicsStateGuardian8::
-get_fog_mode_type(Fog::Mode m) const {
+get_fog_mode_type(Fog::Mode m) {
   switch (m) {
   case Fog::M_linear:
     return D3DFOG_LINEAR;
@@ -529,57 +287,12 @@ get_fog_mode_type(Fog::Mode m) const {
   return D3DFOG_EXP;
 }
 
-/**  unimplemented
-
 ////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_multisample
-//       Access:
-//  Description:
+//     Function: DXGraphicsStateGuardian8::get_tex_mat_sym
+//       Access: Protected, Static
+//  Description: Returns the nth D3DTS_TEXTURE(n) constant.
 ////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_multisample(bool val) {
-  _multisample_enabled = val;
-  #ifdef NDEBUG
-    dxgsg8_cat.error() << "dx multisample unimplemented!!\n";
-  #endif
+INLINE D3DTRANSFORMSTATETYPE DXGraphicsStateGuardian8::
+get_tex_mat_sym(int stage_index) {
+  return (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + stage_index);
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_multisample_alpha_one
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_multisample_alpha_one(bool val) {
-  if (_multisample_alpha_one_enabled != val) {
-    _multisample_alpha_one_enabled = val;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_multisample_alpha_mask
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_multisample_alpha_mask(bool val) {
-  if (_multisample_alpha_mask_enabled != val) {
-    _multisample_alpha_mask_enabled = val;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_point_smooth
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_point_smooth(bool val) {
-  // _point_smooth_enabled = val;
-
-  #ifdef NDEBUG
-    dxgsg8_cat.error() << "dx point smoothing unimplemented!!\n";
-  #endif
-}
-*/
-

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 386 - 497
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx


+ 97 - 211
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -1,4 +1,4 @@
-// Filename: dxGraphicsStateGuardian.h
+// Filename: dxGraphicsStateGuardian8.h
 // Created by:  mike (02Feb99)
 //
 ////////////////////////////////////////////////////////////////////
@@ -16,14 +16,11 @@
 //
 ////////////////////////////////////////////////////////////////////
 
-#ifndef DXGRAPHICSSTATEGUARDIAN_H
-#define DXGRAPHICSSTATEGUARDIAN_H
-
-//#define GSG_VERBOSE 1
+#ifndef DXGRAPHICSSTATEGUARDIAN8_H
+#define DXGRAPHICSSTATEGUARDIAN8_H
 
 #include "dxgsg8base.h"
 #include "dxTextureContext8.h"
-#include "d3dfont8.h"
 #include "config_dxgsg8.h"
 
 #include "graphicsStateGuardian.h"
@@ -39,58 +36,44 @@
 
 class Light;
 
-//#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS)
-//#ifdef _DEBUG
-// is there something in DX8 to replace this?
-#if 0
-// This function now serves both to print a debug message to the
-// console, as well as to notify PStats about the change in texture
-// memory.  Thus, we compile it in if we are building with support for
-// either notify debug messages or PStats; otherwise, we compile it
-// out.
-extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *pMsg);
-#define PRINTVIDMEM(pDD,pCaps,pMsg) dbgPrintVidMem(pDD,pCaps,pMsg)
-#else
-#define PRINTVIDMEM(pDD,pCaps,pMsg)
-#endif
-
 class DXVertexBufferContext8;
 class DXIndexBufferContext8;
 
 ////////////////////////////////////////////////////////////////////
-//   Class : DXGraphicsStateGuardian8
-// Description : A GraphicsStateGuardian specialized for rendering
-//               into DX.  There should be no DX calls
-//               outside of this object.
+//       Class : DXGraphicsStateGuardian8
+// Description : A GraphicsStateGuardian for rendering into DirectX8
+//               contexts.
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDADX DXGraphicsStateGuardian8 : public GraphicsStateGuardian {
-  friend class wdxGraphicsWindow8;
-  friend class wdxGraphicsPipe8;
-  friend class wdxGraphicsWindowGroup8;
-  friend class DXTextureContext8;
-
 public:
   DXGraphicsStateGuardian8(const FrameBufferProperties &properties);
   ~DXGraphicsStateGuardian8();
 
-  virtual void reset();
+  virtual TextureContext *prepare_texture(Texture *tex);
+  void apply_texture(int i, TextureContext *tc);
+  virtual void release_texture(TextureContext *tc);
+
+  virtual VertexBufferContext *prepare_vertex_buffer(qpGeomVertexArrayData *data);
+  void apply_vertex_buffer(VertexBufferContext *vbc);
+  virtual void release_vertex_buffer(VertexBufferContext *vbc);
+
+  virtual IndexBufferContext *prepare_index_buffer(qpGeomPrimitive *data);
+  void apply_index_buffer(IndexBufferContext *ibc);
+  virtual void release_index_buffer(IndexBufferContext *ibc);
+
+  virtual PT(qpGeomMunger) make_geom_munger(const RenderState *state);
+
+  virtual void set_color_clear_value(const Colorf &value);
 
   virtual void do_clear(const RenderBuffer &buffer);
 
   virtual void prepare_display_region();
   virtual bool prepare_lens();
 
-  virtual void draw_point(GeomPoint *geom, GeomContext *gc);
-  virtual void draw_line(GeomLine *geom, GeomContext *gc);
-  virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc);
-  void draw_linestrip_base(Geom *geom, GeomContext *gc, bool bConnectEnds);
-  virtual void draw_sprite(GeomSprite *geom, GeomContext *gc);
-  virtual void draw_polygon(GeomPolygon *geom, GeomContext *gc);
-  virtual void draw_quad(GeomQuad *geom, GeomContext *gc);
-  virtual void draw_tri(GeomTri *geom, GeomContext *gc);
-  virtual void draw_tristrip(GeomTristrip *geom, GeomContext *gc);
-  virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc);
-  virtual void draw_sphere(GeomSphere *geom, GeomContext *gc);
+  virtual bool begin_frame();
+  virtual bool begin_scene();
+  virtual void end_scene();
+  virtual void end_frame();
 
   virtual bool begin_draw_primitives(const qpGeom *geom, 
                                      const qpGeomMunger *munger,
@@ -103,35 +86,22 @@ public:
   virtual void draw_points(const qpGeomPoints *primitive);
   virtual void end_draw_primitives();
 
-  virtual TextureContext *prepare_texture(Texture *tex);
-  void apply_texture(TextureContext *tc);
-  virtual void release_texture(TextureContext *tc);
-
-  virtual VertexBufferContext *prepare_vertex_buffer(qpGeomVertexArrayData *data);
-  void apply_vertex_buffer(VertexBufferContext *vbc);
-  virtual void release_vertex_buffer(VertexBufferContext *vbc);
-
-  virtual IndexBufferContext *prepare_index_buffer(qpGeomPrimitive *data);
-  void apply_index_buffer(IndexBufferContext *ibc);
-  virtual void release_index_buffer(IndexBufferContext *ibc);
-
-  virtual PT(qpGeomMunger) make_geom_munger(const RenderState *state);
-
   virtual void framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr,
                                            const RenderBuffer &rb);
   virtual bool framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr,
                                        const RenderBuffer &rb);
 
+  virtual void reset();
+
   virtual void apply_fog(Fog *fog);
 
   virtual void issue_transform(const TransformState *transform);
-  virtual void issue_tex_matrix(const TexMatrixAttrib *attrib);
+  virtual void issue_alpha_test(const AlphaTestAttrib *attrib);
   virtual void issue_render_mode(const RenderModeAttrib *attrib);
   virtual void issue_rescale_normal(const RescaleNormalAttrib *attrib);
-  virtual void issue_alpha_test(const AlphaTestAttrib *attrib);
+  virtual void issue_color_write(const ColorWriteAttrib *attrib);
   virtual void issue_depth_test(const DepthTestAttrib *attrib);
   virtual void issue_depth_write(const DepthWriteAttrib *attrib);
-  virtual void issue_color_write(const ColorWriteAttrib *attrib);
   virtual void issue_cull_face(const CullFaceAttrib *attrib);
   virtual void issue_fog(const FogAttrib *attrib);
   virtual void issue_depth_offset(const DepthOffsetAttrib *attrib);
@@ -145,29 +115,11 @@ public:
   virtual void bind_light(Spotlight *light_obj, const NodePath &light, 
                           int light_id);
 
-  virtual bool begin_frame();
-  virtual bool begin_scene();
-  virtual void end_scene();
-  virtual void end_frame();
-
-  virtual bool wants_texcoords(void) const;
-
-  INLINE float compute_distance_to(const LPoint3f &point) const;
-  virtual void set_color_clear_value(const Colorf& value);
-
   static D3DFORMAT get_index_type(qpGeom::NumericType numeric_type);
 
-  const D3DCOLORVALUE &get_light_color(Light *light) const;
-
-public:
-  // recreate_tex_callback needs these to be public
-  DXScreenData *_pScrn;
-  LPDIRECT3DDEVICE8 _pD3DDevice;  // same as pScrn->_pD3DDevice, cached for spd
-  IDirect3DSwapChain8 *_pSwapChain;
-  D3DPRESENT_PARAMETERS _PresReset;  // This is built during reset device
-
 protected:
   virtual void do_issue_material();
+  virtual void do_issue_texture();
 
   virtual bool slot_new_light(int light_id);
   virtual void enable_lighting(bool enable);
@@ -186,103 +138,73 @@ protected:
   void set_draw_buffer(const RenderBuffer &rb);
   void set_read_buffer(const RenderBuffer &rb);
 
-  INLINE void add_to_FVFBuf(void *data,  size_t bytes) ;
-
   static CPT(RenderState) get_smooth_state();
   static CPT(RenderState) get_flat_state();
 
   void do_auto_rescale_normal();
-  virtual void do_issue_texture();
-
-  bool                  _bDXisReady;
-  HRESULT               _last_testcooplevel_result;
-  DXTextureContext8  *_pCurTexContext;
-
-  bool _transform_stale;
-  bool _vertex_blending_enabled;
-
-  RenderBuffer::Type _cur_read_pixel_buffer;  // source for copy_pixel_buffer operation
-  bool _auto_rescale_normal;
-
-  void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize,
-                      void *pIndexSpace,DWORD dwIndexSpaceByteSize,
-                      D3DXVECTOR3 *pCenter, float fRadius,
-                      DWORD wNumRings, DWORD wNumSections, float sx, float sy, float sz,
-                      DWORD *pNumVertices,DWORD *pNumTris,DWORD fvfFlags,DWORD dwVertSize);
-  HRESULT ReleaseAllDeviceObjects(void);
-  HRESULT RecreateAllDeviceObjects(void);
-  HRESULT DeleteAllDeviceObjects(void);
-
-/*
-  INLINE void enable_multisample_alpha_one(bool val);
-  INLINE void enable_multisample_alpha_mask(bool val);
-  INLINE void enable_multisample(bool val);
-*/
 
+protected:
   INLINE void enable_color_material(bool val);
   INLINE void enable_fog(bool val);
   INLINE void enable_zwritemask(bool val);
   INLINE void set_color_writemask(UINT color_writemask);
-  void enable_gouraud_shading(bool val);
   INLINE void set_vertex_format(DWORD NewFvfType);
 
-  INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm) const;
-  INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const;
+  INLINE static D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm);
+  INLINE static D3DFOGMODE get_fog_mode_type(Fog::Mode m);
+  const D3DCOLORVALUE &get_light_color(Light *light) const;
+  INLINE static D3DTRANSFORMSTATETYPE get_tex_mat_sym(int stage_index);
 
   INLINE void enable_alpha_test(bool val);
   INLINE void enable_line_smooth(bool val);
   INLINE void enable_blend(bool val);
   INLINE void enable_point_smooth(bool val);
-  INLINE void enable_texturing(bool val);
-  INLINE void call_dxLightModelAmbient(const Colorf& color);
+  INLINE void call_dxLightModelAmbient(const Colorf &color);
   INLINE void call_dxAlphaFunc(D3DCMPFUNC func, float refval);
   INLINE void call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc);
   static D3DBLEND get_blend_func(ColorBlendAttrib::Operand operand);
   INLINE void enable_dither(bool val);
-  INLINE void enable_stencil_test(bool val);
   void report_texmgr_stats();
-  void draw_multitri(Geom *geom, D3DPRIMITIVETYPE tri_id);
-
-  void draw_prim_inner_loop(int nVerts, const Geom *geom, ushort perFlags);
-  void draw_prim_inner_loop_coordtexonly(int nVerts, const Geom *geom);
-  size_t draw_prim_setup(const Geom *geom) ;
-
-  //   for drawing primitives
-  Normalf   p_normal;  // still used to hold G_OVERALL, G_PER_PRIM values
-  TexCoordf p_texcoord;
-  D3DCOLOR  _curD3Dcolor;
-  DWORD     _perPrim,_perVertex,_perComp;   //  these hold DrawLoopFlags bitmask values
-  DWORD     _CurFVFType;
-  // for storage of the flexible vertex format
-  BYTE *_pCurFvfBufPtr,*_pFvfBufBasePtr;
-  WORD *_index_buf;  // base of malloced array
-
-  D3DCOLOR _scene_graph_color_D3DCOLOR;
-  D3DCOLOR _d3dcolor_clear_value;
-//  D3DSHADEMODE _CurShadeMode;
-  bool _bGouraudShadingOn;
-  UINT _color_writemask;
-  bool _bDrawPrimDoSetupVertexBuffer;       // if true, draw methods just copy vertex data into pCurrentGeomContext
 
-  // iterators for primitives
-  Geom::VertexIterator vi;
-  Geom::NormalIterator ni;
-  Geom::TexCoordIterator ti;
-  Geom::ColorIterator ci;
+  void set_context(DXScreenData *new_context);
+  void set_render_target();
+
+  void set_texture_blend_mode(int i, const TextureStage *stage);
+
+  void dx_cleanup();
+  HRESULT reset_d3d_device(D3DPRESENT_PARAMETERS *pPresParams, DXScreenData **pScrn=NULL);
+
+  bool check_cooperative_level();
 
-  // these are used for fastpaths that bypass the iterators above
-  // pointers to arrays in current geom, used to traverse indexed and non-indexed arrays
-  Vertexf *_coord_array,*_pCurCoord;
-  ushort *_coordindex_array,*_pCurCoordIndex;
+  void show_frame();
 
-  TexCoordf *_texcoord_array,*_pCurTexCoord;
-  ushort *_texcoordindex_array,*_pCurTexCoordIndex;
+  bool create_swap_chain (DXScreenData *new_context);
+  bool release_swap_chain (DXScreenData *new_context);
+  void copy_pres_reset(DXScreenData *new_context);
+
+  static D3DTEXTUREFILTERTYPE get_d3d_min_type(Texture::FilterType filter_type);
+  static D3DTEXTUREFILTERTYPE get_d3d_mip_type(Texture::FilterType filter_type);
+  static D3DTEXTUREOP get_tex_color_op1(TextureStage::Mode mode);
+
+protected:
+  DXScreenData *_pScrn;
+  LPDIRECT3DDEVICE8 _pD3DDevice;  // same as pScrn->_pD3DDevice, cached for spd
+  IDirect3DSwapChain8 *_pSwapChain;
+  D3DPRESENT_PARAMETERS _PresReset;  // This is built during reset device
 
-/*
-  PTA_Normalf _norms;
-  PTA_Colorf _colors;
-  PTA_ushort _cindexes,_nindexes;
-*/
+  bool _bDXisReady;
+  HRESULT _last_testcooplevel_result;
+
+  bool _transform_stale;
+  bool _vertex_blending_enabled;
+
+  RenderBuffer::Type _cur_read_pixel_buffer;  // source for copy_pixel_buffer operation
+  bool _auto_rescale_normal;
+
+  DWORD _CurFVFType;
+
+  D3DCOLOR _d3dcolor_clear_value;
+  UINT _color_writemask;
 
   Colorf _lmodel_ambient;
   float _material_ambient;
@@ -291,18 +213,15 @@ protected:
   float _material_shininess;
   float _material_emission;
 
-  typedef enum {None,
-                PerVertexFog=D3DRS_FOGVERTEXMODE,
-                PerPixelFog=D3DRS_FOGTABLEMODE
-               } DxgsgFogType;
+  enum DxgsgFogType {
+    None,
+    PerVertexFog=D3DRS_FOGVERTEXMODE,
+    PerPixelFog=D3DRS_FOGTABLEMODE
+  };
   DxgsgFogType _doFogType;
   bool _fog_enabled;
-/*
-  TODO: cache fog state
-  float _fog_start,_fog_end,_fog_density,float _fog_color;
-*/
 
-  float      _alpha_func_refval;  // d3d stores UINT, panda stores this as float.  we store float
+  float _alpha_func_refval;  // d3d stores UINT, panda stores this as float.  we store float
   D3DCMPFUNC _alpha_func;
 
   D3DBLEND _blend_source_func;
@@ -315,24 +234,13 @@ protected:
   bool _color_material_enabled;
   bool _texturing_enabled;
   bool _dither_enabled;
-  bool _stencil_test_enabled;
   bool _blend_enabled;
   bool _depth_test_enabled;
   bool _depth_write_enabled;
   bool _alpha_test_enabled;
   DWORD _clip_plane_bits;
   CullFaceAttrib::Mode _cull_face_mode;
-
-  RenderModeAttrib::Mode _current_fill_mode;  //poinr/wireframe/solid
-
-  // unused right now
-  //GraphicsChannel *_panda_gfx_channel;  // cache the 1 channel dx supports
-
-  // Cur Texture State
-  TextureStage::Mode _CurTexBlendMode;
-  D3DTEXTUREFILTERTYPE _CurTexMagFilter,_CurTexMinFilter,_CurTexMipFilter;
-  DWORD _CurTexAnisoDegree;
-  Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
+  RenderModeAttrib::Mode _current_fill_mode;  //point/wireframe/solid
 
   LMatrix4f _projection_mat;
 
@@ -340,57 +248,35 @@ protected:
   const DXVertexBufferContext8 *_active_vbuffer;
   const DXIndexBufferContext8 *_active_ibuffer;
 
-  // Color/Alpha Matrix Transition stuff
-  INLINE void transform_color(Colorf &InColor,D3DCOLOR &OutColor);
-
   bool _overlay_windows_supported;
 
-#if 0
-  // This is here just as a temporary hack so this file will still
-  // compile.  However, it is never initialized and will certainly
-  // cause the code to crash when it is referenced.  (This used to be
-  // inherited from the base class, but the new design requires that a
-  // GSG may be used for multiple windows, so it doesn't make sense to
-  // store a single window pointer any more.)
-  GraphicsWindow *_win;
-#endif
-
 public:
-  static GraphicsStateGuardian*
-  make_DXGraphicsStateGuardian8(const FactoryParams &params);
-  void set_context(DXScreenData *pNewContextData);
-  void set_render_target();
-
-  static TypeHandle get_class_type(void);
-  static void init_type(void);
-  virtual TypeHandle get_type(void) const;
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-  INLINE void SetDXReady(bool status)  { _bDXisReady = status; }
-  INLINE bool GetDXReady(void)  { return _bDXisReady;}
-  void DXGraphicsStateGuardian8::SetTextureBlendMode(TextureStage::Mode TexBlendMode,bool bJustEnable);
-
-  void  dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled);
-  void reset_panda_gsg(void);
-  HRESULT reset_d3d_device(D3DPRESENT_PARAMETERS *pPresParams, DXScreenData **pScrn=NULL);
-
-  #define DO_REACTIVATE_WINDOW true
-  bool CheckCooperativeLevel(bool bDoReactivateWindow = false);
 
-  void show_frame(bool bNoNewFrameDrawn = false);
-  void dx_init(void);
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
 
-  void support_overlay_window(bool flag);
-
-  bool create_swap_chain (DXScreenData *pNewContextData);
-  bool release_swap_chain (DXScreenData *pNewContextData);
-  void copy_pres_reset(DXScreenData *pNewContextData);
+public:
+  static void init_type() {
+    GraphicsStateGuardian::init_type();
+    register_type(_type_handle, "DXGraphicsStateGuardian8",
+                  GraphicsStateGuardian::get_class_type());
+  }
 
 private:
   static TypeHandle _type_handle;
+
+  friend class wdxGraphicsWindow8;
+  friend class wdxGraphicsPipe8;
+  friend class wdxGraphicsWindowGroup8;
+  friend class DXTextureContext8;
 };
 
-HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddWatermark);
+#include "dxGraphicsStateGuardian8.I"
 
-#include "DXGraphicsStateGuardian8.I"
 #endif
 

+ 40 - 0
panda/src/dxgsg8/dxTextureContext8.I

@@ -0,0 +1,40 @@
+// Filename: dxTextureContext8.I
+// Created by:  drose (23May05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::has_mipmaps
+//       Access: Public
+//  Description: Returns true if the texture was created with mipmaps,
+//               false otherwise.
+////////////////////////////////////////////////////////////////////
+INLINE bool DXTextureContext8::
+has_mipmaps() const {
+  return _has_mipmaps;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::get_d3d_texture
+//       Access: Public
+//  Description: Returns the Direct3D object that represents the
+//               texture.
+////////////////////////////////////////////////////////////////////
+INLINE IDirect3DTexture8 *DXTextureContext8::
+get_d3d_texture() const {
+  return _d3d_texture;
+}

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 619 - 769
panda/src/dxgsg8/dxTextureContext8.cxx


+ 16 - 17
panda/src/dxgsg8/dxTextureContext8.h

@@ -23,38 +23,33 @@
 #include "texture.h"
 #include "textureContext.h"
 
-//#define DO_CUSTOM_CONVERSIONS
-
 ////////////////////////////////////////////////////////////////////
 //   Class : DXTextureContext8
 // Description :
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDADX DXTextureContext8 : public TextureContext {
-  friend class DXGraphicsStateGuardian;
-  friend class wdxGraphicsWindow;
-
 public:
   DXTextureContext8(Texture *tex);
   ~DXTextureContext8();
 
-  IDirect3DTexture8  *_pD3DTexture8;
-  Texture *_tex;            // ptr to parent, primarily for access to namestr
   IDirect3DTexture8 *CreateTexture(DXScreenData &scrn);
+  void DeleteTexture();
 
-  D3DFORMAT _PixBufD3DFmt;    // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
+  INLINE bool has_mipmaps() const;
+  INLINE IDirect3DTexture8 *get_d3d_texture() const;
 
-  bool _bHasMipMaps;
+private:
+  HRESULT FillDDSurfTexturePixels();
 
-#ifdef DO_CUSTOM_CONVERSIONS
-  DWORD _PixBufConversionType;  // enum ConversionType
-#endif
+private:
+  Texture *_tex;            // ptr to parent, primarily for access to namestr
+  D3DFORMAT _d3d_format;    // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
+  IDirect3DTexture8  *_d3d_texture;
 
-  // must be public since called from global callback fns
-  void DeleteTexture(void);
-  HRESULT FillDDSurfTexturePixels(void);
+  bool _has_mipmaps;
 
 protected:
-    unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
+  unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
 
 public:
   static TypeHandle get_class_type() {
@@ -74,7 +69,11 @@ private:
   static TypeHandle _type_handle;
 };
 
-extern HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,Texture *pixbuf);
+HRESULT 
+d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface, 
+                       Texture *result);
+
+#include "dxTextureContext8.I"
 
 #endif
 

+ 0 - 1
panda/src/dxgsg8/dxgsg8_composite1.cxx

@@ -4,7 +4,6 @@
 #include "dxVertexBufferContext8.cxx"
 #include "dxIndexBufferContext8.cxx"
 #include "dxGeomMunger8.cxx"
-#include "d3dfont8.cxx"
 #include "wdxGraphicsPipe8.cxx"
 #include "wdxGraphicsWindow8.cxx"
 #include "dxGraphicsDevice8.cxx"

+ 2 - 1
panda/src/dxgsg8/dxgsg8base.h

@@ -21,6 +21,7 @@
 
 #include "pandabase.h"
 #include "graphicsWindow.h"
+#include "pmap.h"
 
 #define WIN32_LEAN_AND_MEAN   // get rid of mfc win32 hdr stuff
 #ifndef STRICT
@@ -209,7 +210,7 @@ typedef struct {
 
 
 //utility stuff
-extern map<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
+extern pmap<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
 extern void Init_D3DFORMAT_map(void);
 extern const char *D3DFormatStr(D3DFORMAT fmt);
 

+ 148 - 228
panda/src/dxgsg8/wdxGraphicsPipe8.cxx

@@ -23,7 +23,6 @@
 
 TypeHandle wdxGraphicsPipe8::_type_handle;
 
-// #define LOWVIDMEMTHRESHOLD 3500000
 #define LOWVIDMEMTHRESHOLD 5700000  // 4MB cards should fall below this
 #define CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD 1000000  // if # is > 1MB, card is lying and I cant tell what it is
 #define UNKNOWN_VIDMEM_SIZE 0xFFFFFFFF
@@ -31,7 +30,7 @@ TypeHandle wdxGraphicsPipe8::_type_handle;
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsPipe8::Constructor
 //       Access: Public
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 wdxGraphicsPipe8::
 wdxGraphicsPipe8() {
@@ -44,12 +43,11 @@ wdxGraphicsPipe8() {
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsPipe8::Destructor
 //       Access: Public, Virtual
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 wdxGraphicsPipe8::
 ~wdxGraphicsPipe8() {
-
-  RELEASE(_pD3D8,wdxdisplay8,"ID3D8",RELEASE_DOWN_TO_ZERO);
+  RELEASE(_pD3D8, wdxdisplay8, "ID3D8", RELEASE_DOWN_TO_ZERO);
   SAFE_FREELIB(_hD3D8_DLL);
   SAFE_FREELIB(_hDDrawDLL);
 }
@@ -92,8 +90,10 @@ make_window(GraphicsStateGuardian *gsg, const string &name) {
     return NULL;
   }
 
-  // thanks to the dumb threading requirements this constructor actually does nothing but create an empty c++ object
-  // no windows are really opened until wdxGraphicsWindow8->open_window() is called
+  // thanks to the dumb threading requirements this constructor
+  // actually does nothing but create an empty c++ object. no windows
+  // are really opened until wdxGraphicsWindow8->open_window() is
+  // called
   return new wdxGraphicsWindow8(this, gsg, name);
 }
 
@@ -108,42 +108,31 @@ make_window(GraphicsStateGuardian *gsg, const string &name) {
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsPipe8::
 init() {
-  if(!MyLoadLib(_hDDrawDLL,"ddraw.dll")) {
-      goto error;
+  if (!MyLoadLib(_hDDrawDLL, "ddraw.dll")) {
+    goto error;
   }
 
-  if(!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawCreateEx, "DirectDrawCreateEx")) {
-      goto error;
+  if (!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawCreateEx, "DirectDrawCreateEx")) {
+    goto error;
   }
 
-  if(!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawEnumerateExA, "DirectDrawEnumerateExA")) {
-      goto error;
+  if (!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawEnumerateExA, "DirectDrawEnumerateExA")) {
+    goto error;
   }
 
-  if(!MyLoadLib(_hD3D8_DLL,"d3d8.dll")) {
-      goto error;
+  if (!MyLoadLib(_hD3D8_DLL, "d3d8.dll")) {
+    goto error;
   }
 
-  if(!MyGetProcAddr(_hD3D8_DLL, (FARPROC*)&_Direct3DCreate8, "Direct3DCreate8")) {
-      goto error;
+  if (!MyGetProcAddr(_hD3D8_DLL, (FARPROC*)&_Direct3DCreate8, "Direct3DCreate8")) {
+    goto error;
   }
-/*
-  wdxGraphicsPipe8 *dxpipe;
-  DCAST_INTO_V(dxpipe, _pipe);
-
-  nassertv(_gsg == (GraphicsStateGuardian *)NULL);
-  _dxgsg = new DXGraphicsStateGuardian8(this);
-  _gsg = _dxgsg;
-
-  // Tell the associated dxGSG about the window handle.
-  _dxgsg->scrn.hWnd = _hWnd;
- */
 
   // Create a Direct3D object.
 
   // these were taken from the 8.0 and 8.1 d3d8.h SDK headers
-  #define D3D_SDK_VERSION_8_0  120
-  #define D3D_SDK_VERSION_8_1  220
+#define D3D_SDK_VERSION_8_0  120
+#define D3D_SDK_VERSION_8_1  220
 
   // are we using 8.0 or 8.1?
   WIN32_FIND_DATA TempFindData;
@@ -162,7 +151,7 @@ init() {
   }
 
   if (_pD3D8 == NULL) {
-    wdxdisplay8_cat.error() << "Direct3DCreate8(8." << (_bIsDX81 ? "1" : "0") << ") failed!, error=" << GetLastError() << endl;
+    wdxdisplay8_cat.error() << "Direct3DCreate8(8." << (_bIsDX81 ? "1" : "0") << ") failed!, error = " << GetLastError() << endl;
     //release_gsg();
     goto error;
   }
@@ -171,9 +160,8 @@ init() {
 
   return find_all_card_memavails();
 
-  error:
-    // wdxdisplay8_cat.error() << ", error=" << GetLastError << endl;
-    return false;
+ error:
+  return false;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -187,7 +175,7 @@ bool wdxGraphicsPipe8::
 find_all_card_memavails() {
   HRESULT hr;
 
-  hr = (*_DirectDrawEnumerateExA)(dx7_driver_enum_callback, this, 
+  hr = (*_DirectDrawEnumerateExA)(dx7_driver_enum_callback, this,
                                   DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES);
   if (FAILED(hr)) {
     wdxdisplay8_cat.fatal()
@@ -211,18 +199,18 @@ find_all_card_memavails() {
     _card_ids.erase(_card_ids.begin());
   }
 
-  for (UINT i=0; i < _card_ids.size(); i++) {
+  for (UINT i = 0; i < _card_ids.size(); i++) {
     LPDIRECTDRAW7 pDD;
     BYTE ddd_space[sizeof(DDDEVICEIDENTIFIER2)+4];  //bug in DX7 requires 4 extra bytes for GetDeviceID
-    DDDEVICEIDENTIFIER2 *pDX7DeviceID=(DDDEVICEIDENTIFIER2 *)&ddd_space[0];
-    GUID *pGUID= &(_card_ids[i].DX7_DeviceGUID);
+    DDDEVICEIDENTIFIER2 *pDX7DeviceID = (DDDEVICEIDENTIFIER2 *)&ddd_space[0];
+    GUID *pGUID = &(_card_ids[i].DX7_DeviceGUID);
 
     if (IsEqualGUID(*pGUID, ZeroGUID)) {
-      pGUID=NULL;
+      pGUID = NULL;
     }
 
     // Create the Direct Draw Object
-    hr = (*_DirectDrawCreateEx)(pGUID,(void **)&pDD, IID_IDirectDraw7, NULL);
+    hr = (*_DirectDrawCreateEx)(pGUID, (void **)&pDD, IID_IDirectDraw7, NULL);
     if (FAILED(hr)) {
       wdxdisplay8_cat.error()
         << "DirectDrawCreateEx failed for device (" << i
@@ -235,7 +223,7 @@ find_all_card_memavails() {
     hr = pDD->GetDeviceIdentifier(pDX7DeviceID, 0x0);
     if (FAILED(hr)) {
       wdxdisplay8_cat.error()
-        << "GetDeviceID failed for device ("<< i << ")" << D3DERRORSTRING(hr);
+        << "GetDeviceID failed for device (" << i << ")" << D3DERRORSTRING(hr);
       continue;
     }
 
@@ -248,8 +236,8 @@ find_all_card_memavails() {
     // fullscreen more than once due to the annoying monitor flicker,
     // so try to figure out optimal mode using this estimate
     DDSCAPS2 ddsGAVMCaps;
-    DWORD dwVidMemTotal,dwVidMemFree;
-    dwVidMemTotal=dwVidMemFree=0;
+    DWORD dwVidMemTotal, dwVidMemFree;
+    dwVidMemTotal = dwVidMemFree = 0;
     {
       // print out total INCLUDING AGP just for information purposes
       // and future use.  The real value I'm interested in for
@@ -261,7 +249,7 @@ find_all_card_memavails() {
       hr = pDD->GetAvailableVidMem(&ddsGAVMCaps, &dwVidMemTotal, &dwVidMemFree);
       if (FAILED(hr)) {
         wdxdisplay8_cat.error()
-          << "GetAvailableVidMem failed for device #" << i 
+          << "GetAvailableVidMem failed for device #" << i
           << D3DERRORSTRING(hr);
         //goto skip_device;
         //exit(1);  // probably want to exit, since it may be my fault
@@ -280,17 +268,17 @@ find_all_card_memavails() {
 
     hr = pDD->GetAvailableVidMem(&ddsGAVMCaps, &dwVidMemTotal, &dwVidMemFree);
     if (FAILED(hr)) {
-      wdxdisplay8_cat.error() << "GetAvailableVidMem failed for device #"<< i<< D3DERRORSTRING(hr);
-      // sometimes GetAvailableVidMem fails with hr=DDERR_NODIRECTDRAWHW for some unknown reason (bad drivers?)
-      // see bugs: 15327,18122, others.  is it because D3D8 object has already been created?
-      if(hr==DDERR_NODIRECTDRAWHW)
-          continue;
+      wdxdisplay8_cat.error() << "GetAvailableVidMem failed for device #" << i<< D3DERRORSTRING(hr);
+      // sometimes GetAvailableVidMem fails with hr = DDERR_NODIRECTDRAWHW for some unknown reason (bad drivers?)
+      // see bugs: 15327, 18122, others.  is it because D3D8 object has already been created?
+      if (hr == DDERR_NODIRECTDRAWHW)
+        continue;
       exit(1);  // probably want to exit, since it may be my fault
     }
 
     wdxdisplay8_cat.info()
       << "GetAvailableVidMem (no AGP) returns Total: " << dwVidMemTotal
-      << ", Free: " << dwVidMemFree << " for device #"<< i<< endl;
+      << ", Free: " << dwVidMemFree << " for device #" << i<< endl;
 
     pDD->Release();  // release DD obj, since this is all we needed it for
 
@@ -307,7 +295,7 @@ find_all_card_memavails() {
       if (!ISPOW2(dwVidMemTotal)) {
         // assume they wont return a proper max value, so
         // round up to next pow of 2
-        UINT count=0;
+        UINT count = 0;
         while ((dwVidMemTotal >> count) != 0x0) {
           count++;
         }
@@ -329,12 +317,12 @@ find_all_card_memavails() {
 
     // assume buggy drivers (this means you, FireGL2) may return zero
     // (or small amts) for dwVidMemTotal, so ignore value if its < CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD
-    bool bLowVidMemFlag = 
-      ((dwVidMemTotal > CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD) && 
+    bool bLowVidMemFlag =
+      ((dwVidMemTotal > CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD) &&
        (dwVidMemTotal< LOWVIDMEMTHRESHOLD));
 
     _card_ids[i].bIsLowVidMemCard = bLowVidMemFlag;
-    wdxdisplay8_cat.info() 
+    wdxdisplay8_cat.info()
       << "SetLowVidMem flag to " << bLowVidMemFlag
       << " based on adjusted VidMemTotal: " << dwVidMemTotal << endl;
   }
@@ -344,20 +332,18 @@ find_all_card_memavails() {
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsPipe8::dx7_driver_enum_callback
 //       Access: Private, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 BOOL WINAPI wdxGraphicsPipe8::
 dx7_driver_enum_callback(GUID *pGUID, TCHAR *strDesc, TCHAR *strName,
                          VOID *argptr, HMONITOR hm) {
-  //    #define PRNT(XX) ((XX!=NULL) ? XX : "NULL")
-  //    cout << "strDesc: "<< PRNT(strDesc) << "  strName: "<< PRNT(strName)<<endl;
   wdxGraphicsPipe8 *self = (wdxGraphicsPipe8 *)argptr;
 
   CardID card_id;
   ZeroMemory(&card_id, sizeof(CardID));
 
   if (hm == NULL) {
-    card_id.hMon = MonitorFromWindow(GetDesktopWindow(), 
+    card_id.hMon = MonitorFromWindow(GetDesktopWindow(),
                                      MONITOR_DEFAULTTOPRIMARY);
   } else {
     card_id.hMon = hm;
@@ -377,7 +363,7 @@ dx7_driver_enum_callback(GUID *pGUID, TCHAR *strDesc, TCHAR *strName,
 //////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::find_best_depth_format
 //       Access: Private
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsPipe8::
 find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
@@ -385,14 +371,11 @@ find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
                        bool bForce16bpp, bool bVerboseMode) const {
   // list fmts in order of preference
 #define NUM_TEST_ZFMTS 3
-  static D3DFORMAT NoStencilPrefList[NUM_TEST_ZFMTS]={D3DFMT_D32,D3DFMT_D24X8,D3DFMT_D16};
-  static D3DFORMAT StencilPrefList[NUM_TEST_ZFMTS]={D3DFMT_D24S8,D3DFMT_D24X4S4,D3DFMT_D15S1};
+  static D3DFORMAT NoStencilPrefList[NUM_TEST_ZFMTS] = {D3DFMT_D32, D3DFMT_D24X8, D3DFMT_D16};
+  static D3DFORMAT StencilPrefList[NUM_TEST_ZFMTS] = {D3DFMT_D24S8, D3DFMT_D24X4S4, D3DFMT_D15S1};
 
   // do not use Display.DisplayMode since that is probably not set yet, use TestDisplayMode instead
 
-  // int want_color_bits = _props._want_color_bits;
-  // int want_depth_bits = _props._want_depth_bits;  should we pay attn to these so panda user can select bitdepth?
-
   *pBestFmt = D3DFMT_UNKNOWN;
   HRESULT hr;
 
@@ -405,8 +388,8 @@ find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
       << "FindBestDepthFmt: bSelectOnly16bpp: " << bOnlySelect16bpp << endl;
   }
 
-  for (int i=0; i < NUM_TEST_ZFMTS; i++) {
-    D3DFORMAT TestDepthFmt = 
+  for (int i = 0; i < NUM_TEST_ZFMTS; i++) {
+    D3DFORMAT TestDepthFmt =
       (bWantStencil ? StencilPrefList[i] : NoStencilPrefList[i]);
 
     if (bOnlySelect16bpp && !IS_16BPP_ZBUFFER(TestDepthFmt)) {
@@ -417,19 +400,19 @@ find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
                                           D3DDEVTYPE_HAL,
                                           TestDisplayMode.Format,
                                           D3DUSAGE_DEPTHSTENCIL,
-                                          D3DRTYPE_SURFACE,TestDepthFmt);
+                                          D3DRTYPE_SURFACE, TestDepthFmt);
 
     if (FAILED(hr)) {
       if (hr == D3DERR_NOTAVAILABLE) {
         if (bVerboseMode)
-          wdxdisplay8_cat.info() 
-            << "FindBestDepthFmt: ChkDevFmt returns NotAvail for " 
+          wdxdisplay8_cat.info()
+            << "FindBestDepthFmt: ChkDevFmt returns NotAvail for "
             << D3DFormatStr(TestDepthFmt) << endl;
         continue;
       }
 
       wdxdisplay8_cat.error()
-        << "unexpected CheckDeviceFormat failure" << D3DERRORSTRING(hr) 
+        << "unexpected CheckDeviceFormat failure" << D3DERRORSTRING(hr)
         << endl;
       exit(1);
     }
@@ -443,17 +426,17 @@ find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
       *pBestFmt = TestDepthFmt;
       break;
     } else {
-      if (hr==D3DERR_NOTAVAILABLE) {
+      if (hr == D3DERR_NOTAVAILABLE) {
         if (bVerboseMode) {
           wdxdisplay8_cat.info()
             << "FindBestDepthFmt: ChkDepMatch returns NotAvail for "
-            << D3DFormatStr(TestDisplayMode.Format) << ", " 
+            << D3DFormatStr(TestDisplayMode.Format) << ", "
             << D3DFormatStr(TestDepthFmt) << endl;
         }
       } else {
         wdxdisplay8_cat.error()
           << "unexpected CheckDepthStencilMatch failure for "
-          << D3DFormatStr(TestDisplayMode.Format) << ", " 
+          << D3DFormatStr(TestDisplayMode.Format) << ", "
           << D3DFormatStr(TestDepthFmt) << endl;
         exit(1);
       }
@@ -476,28 +459,22 @@ find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
 //               cases
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsPipe8::
-special_check_fullscreen_resolution(DXScreenData &scrn,UINT x_size,UINT y_size) {
+special_check_fullscreen_resolution(DXScreenData &scrn, UINT x_size, UINT y_size) {
   DWORD VendorId = scrn.DXDeviceID.VendorId;
   DWORD DeviceId = scrn.DXDeviceID.DeviceId;
 
   switch (VendorId) {
-      case 0x8086:  // Intel
-        /*for now, just validate all the intel cards at these resolutions.
-          I dont have a complete list of intel deviceIDs (missing 82830, 845, etc)
-          // Intel i810,i815,82810
-          if ((DeviceId==0x7121)||(DeviceId==0x7123)||(DeviceId==0x7125)||
-          (DeviceId==0x1132))
-        */
-        if ((x_size == 640) && (y_size == 480)) {
-          return true;
-        }
-        if ((x_size == 800) && (y_size == 600)) {
-          return true;
-        }
-        if ((x_size == 1024) && (y_size == 768)) {
-          return true;
-        }
-        break;
+  case 0x8086:  // Intel
+    if ((x_size == 640) && (y_size == 480)) {
+      return true;
+    }
+    if ((x_size == 800) && (y_size == 600)) {
+      return true;
+    }
+    if ((x_size == 1024) && (y_size == 768)) {
+      return true;
+    }
+    break;
   }
 
   return false;
@@ -522,42 +499,37 @@ search_for_valid_displaymode(DXScreenData &scrn,
   assert(IS_VALID_PTR(scrn.pD3D8));
   HRESULT hr;
 
-#ifndef NDEBUG
-  //   no longer true, due to special_check_fullscreen_res, where lowvidmem cards are allowed higher resolutions
-  //    if (_dxgsg->scrn.bIsLowVidMemCard)
-  //        nassertv((RequestedX_Size==640)&&(RequestedY_Size==480));
-#endif
   *pSuggestedPixFmt = D3DFMT_UNKNOWN;
   *pSupportedScreenDepthsMask = 0x0;
   *pCouldntFindAnyValidZBuf = false;
 
   int cNumModes = scrn.pD3D8->GetAdapterModeCount(scrn.CardIDNum);
   D3DDISPLAYMODE BestDispMode;
-  ZeroMemory(&BestDispMode,sizeof(BestDispMode));
+  ZeroMemory(&BestDispMode, sizeof(BestDispMode));
 
   if (bVerboseMode) {
     wdxdisplay8_cat.info()
       << "searching for valid display modes at res: ("
-      << RequestedX_Size << "," << RequestedY_Size
+      << RequestedX_Size << ", " << RequestedY_Size
       << "), TotalModes: " << cNumModes << endl;
   }
 
   // ignore memory based checks for min res 640x480.  some cards just
   // dont give accurate memavails.  (should I do the check anyway for
   // 640x480 32bpp?)
-  bool bDoMemBasedChecks = 
-    ((!((RequestedX_Size==640)&&(RequestedY_Size==480))) &&
-     (scrn.MaxAvailVidMem!=UNKNOWN_VIDMEM_SIZE) &&
-     (!special_check_fullscreen_resolution(scrn,RequestedX_Size,RequestedY_Size)));
+  bool bDoMemBasedChecks =
+    ((!((RequestedX_Size == 640)&&(RequestedY_Size == 480))) &&
+     (scrn.MaxAvailVidMem != UNKNOWN_VIDMEM_SIZE) &&
+     (!special_check_fullscreen_resolution(scrn, RequestedX_Size, RequestedY_Size)));
 
   if (bVerboseMode || wdxdisplay8_cat.is_spam()) {
     wdxdisplay8_cat.info()
       << "DoMemBasedChecks = " << bDoMemBasedChecks << endl;
   }
 
-  for (int i=0; i < cNumModes; i++) {
+  for (int i = 0; i < cNumModes; i++) {
     D3DDISPLAYMODE dispmode;
-    hr = scrn.pD3D8->EnumAdapterModes(scrn.CardIDNum,i,&dispmode);
+    hr = scrn.pD3D8->EnumAdapterModes(scrn.CardIDNum, i, &dispmode);
     if (FAILED(hr)) {
       wdxdisplay8_cat.error()
         << "EnumAdapterDisplayMode failed for device #"
@@ -565,8 +537,8 @@ search_for_valid_displaymode(DXScreenData &scrn,
       continue;
     }
 
-    if ((dispmode.Width!=RequestedX_Size) ||
-        (dispmode.Height!=RequestedY_Size)) {
+    if ((dispmode.Width != RequestedX_Size) ||
+        (dispmode.Height != RequestedY_Size)) {
       if (bVerboseMode) {
         wdxdisplay8_cat.info()
           << "Mode dimension " << dispmode.Width << "x" << dispmode.Height
@@ -578,10 +550,10 @@ search_for_valid_displaymode(DXScreenData &scrn,
 
     if ((dispmode.RefreshRate<60) && (dispmode.RefreshRate>1)) {
       // dont want refresh rates under 60Hz, but 0 or 1 might indicate
-      // a default refresh rate, which is usually >=60
+      // a default refresh rate, which is usually > = 60
       if (bVerboseMode) {
         wdxdisplay8_cat.info()
-          << "skipping mode[" << i << "], bad refresh rate: " 
+          << "skipping mode[" << i << "], bad refresh rate: "
           << dispmode.RefreshRate << endl;
       }
       continue;
@@ -592,20 +564,20 @@ search_for_valid_displaymode(DXScreenData &scrn,
     // an out-of-video-mem error
 
     hr = scrn.pD3D8->CheckDeviceFormat(scrn.CardIDNum, D3DDEVTYPE_HAL, dispmode.Format,
-                                               D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE,
-                                               dispmode.Format);
+                                       D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE,
+                                       dispmode.Format);
     if (FAILED(hr)) {
-      if (hr==D3DERR_NOTAVAILABLE) {
+      if (hr == D3DERR_NOTAVAILABLE) {
         if (bVerboseMode) {
           wdxdisplay8_cat.info()
-            << "skipping mode[" << i 
+            << "skipping mode[" << i
             << "], CheckDevFmt returns NotAvail for fmt: "
             << D3DFormatStr(dispmode.Format) << endl;
         }
         continue;
       } else {
         wdxdisplay8_cat.error()
-          << "CheckDeviceFormat failed for device #" 
+          << "CheckDeviceFormat failed for device #"
           << scrn.CardIDNum << D3DERRORSTRING(hr);
         continue;
       }
@@ -627,29 +599,26 @@ search_for_valid_displaymode(DXScreenData &scrn,
 #define REQD_TEXMEM 1800000
 
       float bytes_per_pixel = (bIs16bppRenderTgt ? 2 : 4);
-      
-//    cant do this check yet since gsg doesnt exist!
-//    assert((_gsg->get_properties().get_frame_buffer_mode() & FrameBufferProperties::FM_double_buffer) != 0);
 
       // *2 for double buffer
 
-      RendTgtMinMemReqmt = 
-        ((float)RequestedX_Size) * ((float)RequestedY_Size) * 
+      RendTgtMinMemReqmt =
+        ((float)RequestedX_Size) * ((float)RequestedY_Size) *
         bytes_per_pixel * 2 + REQD_TEXMEM;
 
       if (bVerboseMode || wdxdisplay8_cat.is_spam())
         wdxdisplay8_cat.info()
-          << "Testing Mode (" <<RequestedX_Size<<"x" << RequestedY_Size 
-          << "," << D3DFormatStr(dispmode.Format) << ")\nReqdVidMem: "
-          << (int)RendTgtMinMemReqmt << " AvailVidMem: " 
+          << "Testing Mode (" <<RequestedX_Size<<"x" << RequestedY_Size
+          << ", " << D3DFormatStr(dispmode.Format) << ")\nReqdVidMem: "
+          << (int)RendTgtMinMemReqmt << " AvailVidMem: "
           << scrn.MaxAvailVidMem << endl;
 
       if (RendTgtMinMemReqmt > scrn.MaxAvailVidMem) {
         if (bVerboseMode || wdxdisplay8_cat.is_debug())
           wdxdisplay8_cat.info()
             << "not enough VidMem for render tgt, skipping display fmt "
-            << D3DFormatStr(dispmode.Format) << " (" 
-            << (int)RendTgtMinMemReqmt << " > " 
+            << D3DFormatStr(dispmode.Format) << " ("
+            << (int)RendTgtMinMemReqmt << " > "
             << scrn.MaxAvailVidMem << ")\n";
         continue;
       }
@@ -657,9 +626,9 @@ search_for_valid_displaymode(DXScreenData &scrn,
 
     if (bWantZBuffer) {
       D3DFORMAT zformat;
-      if (!find_best_depth_format(scrn,dispmode, &zformat,
+      if (!find_best_depth_format(scrn, dispmode, &zformat,
                                   bWantStencil, bForce16bppZBuffer)) {
-        *pCouldntFindAnyValidZBuf=true;
+        *pCouldntFindAnyValidZBuf = true;
         continue;
       }
 
@@ -673,8 +642,8 @@ search_for_valid_displaymode(DXScreenData &scrn,
         if (bVerboseMode || wdxdisplay8_cat.is_spam())
           wdxdisplay8_cat.info()
             << "Testing Mode w/Z (" << RequestedX_Size << "x"
-            << RequestedY_Size << "," << D3DFormatStr(dispmode.Format)
-            << ")\nReqdVidMem: "<< (int)MinMemReqmt << " AvailVidMem: " 
+            << RequestedY_Size << ", " << D3DFormatStr(dispmode.Format)
+            << ")\nReqdVidMem: " << (int)MinMemReqmt << " AvailVidMem: "
             << scrn.MaxAvailVidMem << endl;
 
         if (MinMemReqmt > scrn.MaxAvailVidMem) {
@@ -691,20 +660,20 @@ search_for_valid_displaymode(DXScreenData &scrn,
         if (!IS_16BPP_ZBUFFER(zformat)) {
           // see if things fit with a 16bpp zbuffer
 
-          if (!find_best_depth_format(scrn, dispmode, &zformat, 
+          if (!find_best_depth_format(scrn, dispmode, &zformat,
                                       bWantStencil, true, bVerboseMode)) {
             if (bVerboseMode)
               wdxdisplay8_cat.info()
-                << "FindBestDepthFmt rejected Mode[" << i << "] (" 
-                << RequestedX_Size << "x" << RequestedY_Size 
-                << "," << D3DFormatStr(dispmode.Format) << endl;
-            *pCouldntFindAnyValidZBuf=true;
+                << "FindBestDepthFmt rejected Mode[" << i << "] ("
+                << RequestedX_Size << "x" << RequestedY_Size
+                << ", " << D3DFormatStr(dispmode.Format) << endl;
+            *pCouldntFindAnyValidZBuf = true;
             continue;
           }
-          
+
           // right now I'm not going to use these flags, just let the
           // create fail out-of-mem and retry at 16bpp
-          *pSupportedScreenDepthsMask |= 
+          *pSupportedScreenDepthsMask |=
             (IS_16BPP_DISPLAY_FORMAT(dispmode.Format) ? DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG : DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG);
         }
       }
@@ -712,13 +681,13 @@ search_for_valid_displaymode(DXScreenData &scrn,
 
     if (bVerboseMode || wdxdisplay8_cat.is_spam())
       wdxdisplay8_cat.info()
-        << "Validated Mode (" << RequestedX_Size << "x" 
-        << RequestedY_Size << "," << D3DFormatStr(dispmode.Format) << endl;
+        << "Validated Mode (" << RequestedX_Size << "x"
+        << RequestedY_Size << ", " << D3DFormatStr(dispmode.Format) << endl;
 
-  /*
+    /*
     // dx8 valid display modes for render targets.
     D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8, and D3DFMT_A8R8G8B8
-  */
+    */
 
     switch (dispmode.Format) {
     case D3DFMT_X1R5G5B5:
@@ -737,7 +706,7 @@ search_for_valid_displaymode(DXScreenData &scrn,
       // Render target formats should be only D3DFMT_X1R5G5B5,
       // D3DFMT_R5G6B5, D3DFMT_X8R8G8B8 and D3DFMT_A8R8G8B8
       wdxdisplay8_cat.error()
-        << "unrecognized supported fmt "<< D3DFormatStr(dispmode.Format)
+        << "unrecognized supported fmt " << D3DFormatStr(dispmode.Format)
         << " returned by EnumAdapterDisplayModes!\n";
     }
   }
@@ -755,7 +724,7 @@ search_for_valid_displaymode(DXScreenData &scrn,
   }
 
   if (bVerboseMode || wdxdisplay8_cat.is_spam()) {
-    wdxdisplay8_cat.info() 
+    wdxdisplay8_cat.info()
       << "search_for_valid_device returns fmt: "
       << D3DFormatStr(*pSuggestedPixFmt) << endl;
   }
@@ -777,32 +746,8 @@ make_device(void *scrn) {
   wdxdisplay8_cat.info() << "walla: device" << device << "\n";
 
   return device.p();
-
-/*
-  nassertv(_gsg == (GraphicsStateGuardian *)NULL);
-  _dxgsg = new DXGraphicsStateGuardian8(this);
-  _gsg = _dxgsg;
-
-  // Tell the associated dxGSG about the window handle.
-  _dxgsg->scrn.hWnd = _hWnd;
-
-  if (pD3D8 == NULL) {
-    wdxdisplay8_cat.error()
-      << "Direct3DCreate8 failed!\n";
-    release_gsg();
-    return;
-  }
-
-  if (!choose_adapter(pD3D8)) {
-    wdxdisplay8_cat.error()
-      << "Unable to find suitable rendering device.\n";
-    release_gsg();
-    return;
-  }
-
-  create_screen_buffers_and_device(_dxgsg->scrn, dx_force_16bpp_zbuffer);
-  */
 }
+
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsPipew8::make_gsg
 //       Access: Public, Virtual
@@ -811,7 +756,7 @@ make_device(void *scrn) {
 ////////////////////////////////////////////////////////////////////
 
 PT(GraphicsStateGuardian) wdxGraphicsPipe8::
-make_gsg(const FrameBufferProperties &properties, 
+make_gsg(const FrameBufferProperties &properties,
          GraphicsStateGuardian *share_with) {
   if (share_with != (GraphicsStateGuardian *)NULL) {
     wdxdisplay8_cat.error()
@@ -823,80 +768,55 @@ make_gsg(const FrameBufferProperties &properties,
   // put here because of GLX multithreading requirement
   PT(DXGraphicsStateGuardian8) gsg = new DXGraphicsStateGuardian8(properties);
   return gsg.p();
-
-/*
-  nassertv(_gsg == (GraphicsStateGuardian *)NULL);
-  _dxgsg = new DXGraphicsStateGuardian8(this);
-  _gsg = _dxgsg;
-
-  // Tell the associated dxGSG about the window handle.
-  _dxgsg->scrn.hWnd = _hWnd;
-
-  if (pD3D8 == NULL) {
-    wdxdisplay8_cat.error()
-      << "Direct3DCreate8 failed!\n";
-    release_gsg();
-    return;
-  }
-
-  if (!choose_adapter(pD3D8)) {
-    wdxdisplay8_cat.error()
-      << "Unable to find suitable rendering device.\n";
-    release_gsg();
-    return;
-  }
-
-  create_screen_buffers_and_device(_dxgsg->scrn, dx_force_16bpp_zbuffer);
-  */
 }
 
-map<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
+pmap<D3DFORMAT_FLAG, D3DFORMAT> g_D3DFORMATmap;
 
 void Init_D3DFORMAT_map(void) {
-  if(g_D3DFORMATmap.size()!=0)
+  if (g_D3DFORMATmap.size() != 0)
     return;
 
-    #define INSERT_ELEM(XX)  g_D3DFORMATmap[XX##_FLAG] = D3DFMT_##XX;
-
-    INSERT_ELEM(R8G8B8);
-    INSERT_ELEM(A8R8G8B8);
-    INSERT_ELEM(X8R8G8B8);
-    INSERT_ELEM(R5G6B5);
-    INSERT_ELEM(X1R5G5B5);
-    INSERT_ELEM(A1R5G5B5);
-    INSERT_ELEM(A4R4G4B4);
-    INSERT_ELEM(R3G3B2);
-    INSERT_ELEM(A8);
-    INSERT_ELEM(A8R3G3B2);
-    INSERT_ELEM(X4R4G4B4);
-    INSERT_ELEM(A2B10G10R10);
-    INSERT_ELEM(G16R16);
-    INSERT_ELEM(A8P8);
-    INSERT_ELEM(P8);
-    INSERT_ELEM(L8);
-    INSERT_ELEM(A8L8);
-    INSERT_ELEM(A4L4);
-    INSERT_ELEM(V8U8);
-    INSERT_ELEM(L6V5U5);
-    INSERT_ELEM(X8L8V8U8);
-    INSERT_ELEM(Q8W8V8U8);
-    INSERT_ELEM(V16U16);
-    INSERT_ELEM(W11V11U10);
-    INSERT_ELEM(A2W10V10U10);
-    INSERT_ELEM(UYVY);
-    INSERT_ELEM(YUY2);
-    INSERT_ELEM(DXT1);
-    INSERT_ELEM(DXT2);
-    INSERT_ELEM(DXT3);
-    INSERT_ELEM(DXT4);
-    INSERT_ELEM(DXT5);
+#define INSERT_ELEM(XX)  g_D3DFORMATmap[XX##_FLAG] = D3DFMT_##XX;
+
+  INSERT_ELEM(R8G8B8);
+  INSERT_ELEM(A8R8G8B8);
+  INSERT_ELEM(X8R8G8B8);
+  INSERT_ELEM(R5G6B5);
+  INSERT_ELEM(X1R5G5B5);
+  INSERT_ELEM(A1R5G5B5);
+  INSERT_ELEM(A4R4G4B4);
+  INSERT_ELEM(R3G3B2);
+  INSERT_ELEM(A8);
+  INSERT_ELEM(A8R3G3B2);
+  INSERT_ELEM(X4R4G4B4);
+  INSERT_ELEM(A2B10G10R10);
+  INSERT_ELEM(G16R16);
+  INSERT_ELEM(A8P8);
+  INSERT_ELEM(P8);
+  INSERT_ELEM(L8);
+  INSERT_ELEM(A8L8);
+  INSERT_ELEM(A4L4);
+  INSERT_ELEM(V8U8);
+  INSERT_ELEM(L6V5U5);
+  INSERT_ELEM(X8L8V8U8);
+  INSERT_ELEM(Q8W8V8U8);
+  INSERT_ELEM(V16U16);
+  INSERT_ELEM(W11V11U10);
+  INSERT_ELEM(A2W10V10U10);
+  INSERT_ELEM(UYVY);
+  INSERT_ELEM(YUY2);
+  INSERT_ELEM(DXT1);
+  INSERT_ELEM(DXT2);
+  INSERT_ELEM(DXT3);
+  INSERT_ELEM(DXT4);
+  INSERT_ELEM(DXT5);
 }
 
 
+
 const char *D3DFormatStr(D3DFORMAT fmt) {
 
 #define CASESTR(XX) case XX: return #XX;
-
   switch(fmt) {
     CASESTR(D3DFMT_UNKNOWN);
     CASESTR(D3DFMT_R8G8B8);

+ 11 - 22
panda/src/dxgsg8/wdxGraphicsPipe8.h

@@ -25,20 +25,10 @@
 #include "dxgsg8base.h"
 #include <ddraw.h>
 
-typedef struct {
-   UINT    cardID;
-   char    szDriver[MAX_DEVICE_IDENTIFIER_STRING];
-   char    szDescription[MAX_DEVICE_IDENTIFIER_STRING];
-   GUID    guidDeviceIdentifier;
-   DWORD   VendorID, DeviceID;
-   HMONITOR hMon;
-} DXDeviceInfo;
-typedef pvector<DXDeviceInfo> DXDeviceInfoVec;
-
 ////////////////////////////////////////////////////////////////////
 //       Class : wdxGraphicsPipe8
 // Description : This graphics pipe represents the interface for
-//               creating DirectX graphics windows.
+//               creating DirectX8 graphics windows.
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDADX wdxGraphicsPipe8 : public WinGraphicsPipe {
 public:
@@ -53,18 +43,18 @@ public:
   virtual PT(GraphicsDevice) make_device(void *scrn);
 
   bool find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
-                       D3DFORMAT *pBestFmt, bool bWantStencil,
-                       bool bForce16bpp, bool bVerboseMode = false) const;
+                              D3DFORMAT *pBestFmt, bool bWantStencil,
+                              bool bForce16bpp, bool bVerboseMode = false) const;
 
   void search_for_valid_displaymode(DXScreenData &scrn,
-                             UINT RequestedX_Size, UINT RequestedY_Size,
-                             bool bWantZBuffer, bool bWantStencil,
-                             UINT *pSupportedScreenDepthsMask,
-                             bool *pCouldntFindAnyValidZBuf,
-                             D3DFORMAT *pSuggestedPixFmt,
-                             bool bForce16bppZBuffer,
-                             bool bVerboseMode = false);
-
+                                    UINT RequestedX_Size, UINT RequestedY_Size,
+                                    bool bWantZBuffer, bool bWantStencil,
+                                    UINT *pSupportedScreenDepthsMask,
+                                    bool *pCouldntFindAnyValidZBuf,
+                                    D3DFORMAT *pSuggestedPixFmt,
+                                    bool bForce16bppZBuffer,
+                                    bool bVerboseMode = false);
+  
    bool special_check_fullscreen_resolution(DXScreenData &scrn, UINT x_size,UINT y_size);
 
 protected:
@@ -99,7 +89,6 @@ private:
     bool  bIsLowVidMemCard;
     GUID  DX7_DeviceGUID;
     DWORD VendorID, DeviceID;
-    //   char  szDriver[MAX_DEVICE_IDENTIFIER_STRING];
   };
   
   typedef pvector<CardID> CardIDs;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 125 - 658
panda/src/dxgsg8/wdxGraphicsWindow8.cxx


+ 15 - 23
panda/src/dxgsg8/wdxGraphicsWindow8.h

@@ -27,11 +27,6 @@
 
 class wdxGraphicsPipe8;
 
-static const int WDXWIN_CONFIGURE = 4;
-static const int WDXWIN_EVENT = 8;
-
-//#define FIND_CARD_MEMAVAILS
-
 ////////////////////////////////////////////////////////////////////
 //       Class : wdxGraphicsWindow8
 // Description : A single graphics window for rendering DirectX under
@@ -42,48 +37,47 @@ public:
   wdxGraphicsWindow8(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
                      const string &name);
   virtual ~wdxGraphicsWindow8();
-  virtual bool open_window(void);
-  virtual void close_window(void);
+  virtual bool open_window();
+  virtual void close_window();
   virtual void reset_window(bool swapchain);
 
   virtual int verify_window_sizes(int numsizes, int *dimen);
 
   virtual bool begin_frame();
   virtual void end_flip();
-  virtual LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  virtual bool handle_mouse_motion(int x, int y);
 
 protected:
   virtual void fullscreen_restored(WindowProperties &properties);
   virtual void handle_reshape();
   virtual bool do_fullscreen_resize(int x_size, int y_size);
-  virtual void support_overlay_window(bool flag);
 
 private:
-  //  bool set_to_temp_rendertarget();
+  struct DXDeviceInfo {
+    UINT cardID;
+    char szDriver[MAX_DEVICE_IDENTIFIER_STRING];
+    char szDescription[MAX_DEVICE_IDENTIFIER_STRING];
+    GUID guidDeviceIdentifier;
+    DWORD VendorID, DeviceID;
+    HMONITOR hMon;
+  };
+  typedef pvector<DXDeviceInfo> DXDeviceInfoVec;
+
   bool create_screen_buffers_and_device(DXScreenData &Display,
                                         bool force_16bpp_zbuffer);
 
-  bool choose_device(void);
+  bool choose_device();
   bool search_for_device(wdxGraphicsPipe8 *dxpipe, DXDeviceInfo *device_info);
 
-  //  void set_coop_levels_and_display_modes();
-/*
-  void search_for_valid_displaymode(UINT RequestedX_Size, UINT RequestedY_Size,
-                                    bool bWantZBuffer, bool bWantStencil,
-                                    UINT *pSupportedScreenDepthsMask,
-                                    bool *pCouldntFindAnyValidZBuf,
-                                    D3DFORMAT *pSuggestedPixFmt,
-                                    bool bVerboseMode = false);
-*/
   bool reset_device_resize_window(UINT new_xsize, UINT new_ysize);
   void init_resized_window();
   static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
   static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
+  virtual void make_current();
 
   DXGraphicsStateGuardian8 *_dxgsg;
   DXScreenData _wcontext;
 
+  int _buffer_mask;
   int _depth_buffer_bpp;
   bool _awaiting_restore;
 
@@ -100,14 +94,12 @@ public:
     return get_class_type();
   }
   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-  virtual void make_current(void);
 
 private:
   static TypeHandle _type_handle;
   friend class wdxGraphicsPipe8;
 };
 
-//extern bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
 
 #include "wdxGraphicsWindow8.I"
 

+ 0 - 19
panda/src/dxgsg9/dxGraphicsStateGuardian9.I

@@ -470,25 +470,6 @@ wants_texcoords() const {
     return _texturing_enabled;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian9::compute_distance_to
-//       Access: Public, Virtual
-//  Description: This function may only be called during a render
-//               traversal; it will compute the distance to the
-//               indicated point, assumed to be in modelview
-//               coordinates, from the camera plane.
-////////////////////////////////////////////////////////////////////
-INLINE float DXGraphicsStateGuardian9::
-compute_distance_to(const LPoint3f &point) const {
-    // In the case of a DXGraphicsStateGuardian9, we know that the
-    // modelview matrix already includes the relative transform from the
-    // camera, as well as a to-y-up conversion.  Thus, the distance to
-    // the camera plane is simply the +z distance.  (negative of gl compute_distance_to,
-    // since d3d uses left-hand coords)
-
-    return point[2];
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian9::get_texture_wrap_mode
 //       Access: Protected

+ 2 - 4
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -1533,7 +1533,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) {
     }
 
     // save the modelview matrix
-    const LMatrix4f &modelview_mat = _transform->get_mat();
+    const LMatrix4f &modelview_mat = _internal_transform->get_mat();
 
     // We don't need to mess with the aspect ratio, since we are now
     // using the default projection matrix, which has the right aspect
@@ -3089,7 +3089,6 @@ issue_transform(const TransformState *transform) {
   D3DMATRIX *pMat = (D3DMATRIX*)transform->get_mat().get_data();
   _pD3DDevice->SetTransform(D3DTS_WORLD,pMat);
 
-  _transform = transform;
   if (_auto_rescale_normal) {
     do_auto_rescale_normal();
   }
@@ -3757,8 +3756,7 @@ set_read_buffer(const RenderBuffer &rb) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian9::
 do_auto_rescale_normal() {
-  if (_transform->has_uniform_scale() &&
-      IS_NEARLY_EQUAL(_transform->get_uniform_scale(), 1.0f)) {
+  if (_external_transform->has_identity_scale()) {
     // If there's no scale, don't normalize anything.
     _pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, false);
 

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

@@ -130,7 +130,6 @@ public:
 
   virtual bool wants_texcoords(void) const;
 
-  INLINE float compute_distance_to(const LPoint3f &point) const;
   virtual void set_color_clear_value(const Colorf& value);
 
 public:

+ 41 - 90
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -830,13 +830,6 @@ reset() {
         << "max texture stages = " << _max_texture_stages << "\n";
     }
   }
-  _current_texture = DCAST(TextureAttrib, TextureAttrib::make_all_off());
-  _current_tex_mat = DCAST(TexMatrixAttrib, TexMatrixAttrib::make());
-  _needs_tex_mat = false;
-  _current_tex_gen = DCAST(TexGenAttrib, TexGenAttrib::make());
-  _needs_tex_gen = false;
-  _tex_gen_modifies_mat = false;
-  _last_max_stage_index = 0;
   _current_vbuffer_index = 0;
   _current_ibuffer_index = 0;
   _auto_antialias_mode = false;
@@ -1444,7 +1437,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) {
   }
 
   // save the modelview matrix
-  const LMatrix4f &modelview_mat = _transform->get_mat();
+  const LMatrix4f &modelview_mat = _internal_transform->get_mat();
 
   // We don't need to mess with the aspect ratio, since we are now
   // using the default projection matrix, which has the right aspect
@@ -2246,7 +2239,7 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger,
 
         for (int i = 0; i < table->get_num_transforms(); ++i) {
           LMatrix4f mat;
-          table->get_transform(i)->mult_matrix(mat, _transform->get_mat());
+          table->get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
           _glCurrentPaletteMatrixARB(i);
           GLP(LoadMatrixf)(mat.get_data());
         }
@@ -2266,21 +2259,21 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger,
         int i = 0;
         if (i < table->get_num_transforms()) {
           LMatrix4f mat;
-          table->get_transform(i)->mult_matrix(mat, _transform->get_mat());
+          table->get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
           GLP(MatrixMode)(GL_MODELVIEW0_ARB);
           GLP(LoadMatrixf)(mat.get_data());
           ++i;
         }
         if (i < table->get_num_transforms()) {
           LMatrix4f mat;
-          table->get_transform(i)->mult_matrix(mat, _transform->get_mat());
+          table->get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
           GLP(MatrixMode)(GL_MODELVIEW1_ARB);
           GLP(LoadMatrixf)(mat.get_data());
           ++i;
         }
         while (i < table->get_num_transforms()) {
           LMatrix4f mat;
-          table->get_transform(i)->mult_matrix(mat, _transform->get_mat());
+          table->get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
           GLP(MatrixMode)(GL_MODELVIEW2_ARB + i - 2);
           GLP(LoadMatrixf)(mat.get_data());
           ++i;
@@ -2305,7 +2298,7 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger,
 
     if (_transform_stale) {
       GLP(MatrixMode)(GL_MODELVIEW);
-      GLP(LoadMatrixf)(_transform->get_mat().get_data());
+      GLP(LoadMatrixf)(_internal_transform->get_mat().get_data());
     }
   }
 
@@ -2745,7 +2738,7 @@ end_draw_primitives() {
   
   if (_transform_stale) {
     GLP(MatrixMode)(GL_MODELVIEW);
-    GLP(LoadMatrixf)(_transform->get_mat().get_data());
+    GLP(LoadMatrixf)(_internal_transform->get_mat().get_data());
   }
 
   if (_vertex_data->is_vertex_transformed()) {
@@ -3442,6 +3435,9 @@ apply_fog(Fog *fog) {
 //       Access: Public, Virtual
 //  Description: Sends the indicated transform matrix to the graphics
 //               API to be applied to future vertices.
+//
+//               This transform is the internal_transform, already
+//               converted into the GSG's internal coordinate system.
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 issue_transform(const TransformState *transform) {
@@ -3454,7 +3450,6 @@ issue_transform(const TransformState *transform) {
   GLP(LoadMatrixf)(transform->get_mat().get_data());
   _transform_stale = false;
 
-  _transform = transform;
   if (_auto_rescale_normal) {
     do_auto_rescale_normal();
   }
@@ -3462,38 +3457,6 @@ issue_transform(const TransformState *transform) {
   report_my_gl_errors();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::issue_tex_matrix
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void CLP(GraphicsStateGuardian)::
-issue_tex_matrix(const TexMatrixAttrib *attrib) {
-  // We don't apply the texture matrix right away, since we might yet
-  // get a TextureAttrib that changes the set of TextureStages we have
-  // active.  Instead, we simply set a flag that indicates we need to
-  // re-issue the texture matrix after all of the other attribs are
-  // done being issued.
-  _current_tex_mat = attrib;
-  _needs_tex_mat = true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::issue_tex_gen
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void CLP(GraphicsStateGuardian)::
-issue_tex_gen(const TexGenAttrib *attrib) {
-  // We don't apply the texture coordinate generation commands right
-  // away, since we might yet get a TextureAttrib that changes the set
-  // of TextureStages we have active.  Instead, we simply set a flag
-  // that indicates we need to re-issue the TexGenAttrib after all of
-  // the other attribs are done being issued.
-  _current_tex_gen = attrib;
-  _needs_tex_gen = true;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::issue_shade_model
 //       Access: Public, Virtual
@@ -4051,24 +4014,6 @@ wants_texcoords() const {
   return true;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::compute_distance_to
-//       Access: Public, Virtual
-//  Description: This function may only be called during a render
-//               traversal; it will compute the distance to the
-//               indicated point, assumed to be in eye coordinates,
-//               from the camera plane.
-////////////////////////////////////////////////////////////////////
-float CLP(GraphicsStateGuardian)::
-compute_distance_to(const LPoint3f &point) const {
-  // In the case of a CLP(GraphicsStateGuardian), we know that the
-  // modelview matrix already includes the relative transform from the
-  // camera, as well as a to-y-up conversion.  Thus, the distance to
-  // the camera plane is simply the -z distance.
-
-  return -point[2];
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: report_errors_loop
 //       Access: Protected, Static
@@ -5107,11 +5052,14 @@ begin_bind_lights() {
   // root.  (Alternatively, we could leave the current transform where
   // it is and compute the light position relative to that transform
   // instead of relative to the root, by composing with the matrix
-  // computed by _transform->invert_compose(render_transform).  But I
-  // think loading a completely new matrix is simpler.)
+  // computed by _internal_transform->invert_compose(render_transform).  
+  // But I think loading a completely new matrix is simpler.)
+  CPT(TransformState) render_transform = 
+    _cs_transform->compose(_scene_setup->get_world_transform());
+
   GLP(MatrixMode)(GL_MODELVIEW);
   GLP(PushMatrix)();
-  GLP(LoadMatrixf)(_scene_setup->get_render_transform()->get_mat().get_data());
+  GLP(LoadMatrixf)(render_transform->get_mat().get_data());
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -5184,11 +5132,14 @@ begin_bind_clip_planes() {
   // root.  (Alternatively, we could leave the current transform where
   // it is and compute the clip_plane position relative to that transform
   // instead of relative to the root, by composing with the matrix
-  // computed by _transform->invert_compose(render_transform).  But I
-  // think loading a completely new matrix is simpler.)
+  // computed by _internal_transform->invert_compose(render_transform).
+  // But I think loading a completely new matrix is simpler.)
+  CPT(TransformState) render_transform = 
+    _cs_transform->compose(_scene_setup->get_world_transform());
+
   GLP(MatrixMode)(GL_MODELVIEW);
   GLP(PushMatrix)();
-  GLP(LoadMatrixf)(_scene_setup->get_render_transform()->get_mat().get_data());
+  GLP(LoadMatrixf)(render_transform->get_mat().get_data());
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -5439,7 +5390,8 @@ finish_modify_state() {
             // tempting to try, we can't safely convert to object
             // space, since this method doesn't get called with each
             // different object.
-            CPT(TransformState) transform = _scene_setup->get_render_transform();
+            CPT(TransformState) transform = 
+              _cs_transform->compose(_scene_setup->get_world_transform());
             transform = transform->invert_compose(TransformState::make_identity());
             LMatrix4f mat = transform->get_mat();
             mat.set_row(3, LVecBase3f(0.0f, 0.0f, 0.0f));
@@ -5471,7 +5423,8 @@ finish_modify_state() {
             // tempting to try, we can't safely convert to object
             // space, since this method doesn't get called with each
             // different object.
-            CPT(TransformState) transform = _scene_setup->get_render_transform();
+            CPT(TransformState) transform = 
+              _cs_transform->compose(_scene_setup->get_world_transform());
             transform = transform->invert_compose(TransformState::make_identity());
             LMatrix4f mat = transform->get_mat();
             mat.set_row(3, LVecBase3f(0.0f, 0.0f, 0.0f));
@@ -5515,7 +5468,7 @@ finish_modify_state() {
         // load the coordinate-system transform.
         GLP(MatrixMode)(GL_MODELVIEW);
         GLP(PushMatrix)();
-        GLP(LoadMatrixf)(_scene_setup->get_cs_transform()->get_mat().get_data());
+        GLP(LoadMatrixf)(_cs_transform->get_mat().get_data());
 
         GLP(TexGeni)(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
         GLP(TexGeni)(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
@@ -5543,7 +5496,7 @@ finish_modify_state() {
         {
           GLP(MatrixMode)(GL_MODELVIEW);
           GLP(PushMatrix)();
-          CPT(TransformState) root_transform = _scene_setup->get_render_transform();
+          CPT(TransformState) root_transform = _cs_transform->compose(_scene_setup->get_world_transform());
           GLP(LoadMatrixf)(root_transform->get_mat().get_data());
           GLP(TexGeni)(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
           GLP(TexGeni)(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
@@ -5661,24 +5614,22 @@ get_flat_state() {
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 do_auto_rescale_normal() {
-  if (_transform->has_uniform_scale()) {
-    if (IS_NEARLY_EQUAL(_transform->get_uniform_scale(), 1.0f)) {
-      // If there's no scale at all, don't do anything.
+  if (_external_transform->has_identity_scale()) {
+    // If there's no scale at all, don't do anything.
+    GLP(Disable)(GL_NORMALIZE);
+    if (_supports_rescale_normal && support_rescale_normal) {
+      GLP(Disable)(GL_RESCALE_NORMAL);
+    }
+    
+  } else if (_external_transform->has_uniform_scale()) {
+    // There's a uniform scale; use the rescale feature if available.
+    if (_supports_rescale_normal && support_rescale_normal) {
+      GLP(Enable)(GL_RESCALE_NORMAL);
       GLP(Disable)(GL_NORMALIZE);
-      if (_supports_rescale_normal && support_rescale_normal) {
-        GLP(Disable)(GL_RESCALE_NORMAL);
-      }
-      
     } else {
-      // There's a uniform scale; use the rescale feature if available.
-      if (_supports_rescale_normal && support_rescale_normal) {
-        GLP(Enable)(GL_RESCALE_NORMAL);
-        GLP(Disable)(GL_NORMALIZE);
-      } else {
-        GLP(Enable)(GL_NORMALIZE);
-      }
+      GLP(Enable)(GL_NORMALIZE);
     }
-
+  
   } else {
     // If there's a non-uniform scale, normalize everything.
     GLP(Enable)(GL_NORMALIZE);

+ 0 - 12
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -133,7 +133,6 @@ public:
   void apply_fog(Fog *fog);
 
   virtual void issue_transform(const TransformState *transform);
-  virtual void issue_tex_matrix(const TexMatrixAttrib *attrib);
   virtual void issue_render_mode(const RenderModeAttrib *attrib);
   virtual void issue_antialias(const AntialiasAttrib *);
   virtual void issue_rescale_normal(const RescaleNormalAttrib *attrib);
@@ -144,7 +143,6 @@ public:
   virtual void issue_cull_face(const CullFaceAttrib *attrib);
   virtual void issue_fog(const FogAttrib *attrib);
   virtual void issue_depth_offset(const DepthOffsetAttrib *attrib);
-  virtual void issue_tex_gen(const TexGenAttrib *attrib);
   virtual void issue_shade_model(const ShadeModelAttrib *attrib);
 #ifdef HAVE_CGGL
   virtual void issue_cg_shader_bind(const CgShaderAttrib *attrib);
@@ -161,8 +159,6 @@ public:
 
   virtual bool wants_texcoords(void) const;
 
-  virtual float compute_distance_to(const LPoint3f &point) const;
-
   void print_gfx_visual();
 
   //For those interested in what the guardian thinks is the current
@@ -310,13 +306,6 @@ protected:
   LMatrix4f _projection_mat;
   int _viewport_width;
   int _viewport_height;
-  CPT(TextureAttrib) _current_texture;
-  CPT(TexMatrixAttrib) _current_tex_mat;
-  bool _needs_tex_mat;
-  CPT(TexGenAttrib) _current_tex_gen;
-  bool _needs_tex_gen;
-  bool _tex_gen_modifies_mat;
-  bool _tex_gen_point_sprite;
   bool _auto_antialias_mode;
   RenderModeAttrib::Mode _render_mode;
   float _point_size;
@@ -335,7 +324,6 @@ protected:
   int _pass_number;
   bool _auto_rescale_normal;
   GLuint _geom_display_list;
-  int _last_max_stage_index;
   GLuint _current_vbuffer_index;
   GLuint _current_ibuffer_index;
   

+ 13 - 0
panda/src/gobj/preparedGraphicsObjects.I

@@ -16,3 +16,16 @@
 //
 ////////////////////////////////////////////////////////////////////
 
+
+////////////////////////////////////////////////////////////////////
+//     Function: PreparedGraphicsObjects::release_all
+//       Access: Public
+//  Description: Releases all prepared objects of all kinds at once.
+////////////////////////////////////////////////////////////////////
+INLINE void PreparedGraphicsObjects::
+release_all() {
+  release_all_textures();
+  release_all_geoms();
+  release_all_vertex_buffers();
+  release_all_index_buffers();
+}

+ 2 - 0
panda/src/gobj/preparedGraphicsObjects.h

@@ -60,6 +60,8 @@ public:
   PreparedGraphicsObjects();
   ~PreparedGraphicsObjects();
 
+  INLINE void release_all();
+
   void enqueue_texture(Texture *tex);
   bool dequeue_texture(Texture *tex);
   void release_texture(TextureContext *tc);

+ 6 - 0
panda/src/gobj/qpgeomPrimitive.I

@@ -393,3 +393,9 @@ CData(const qpGeomPrimitive::CData &copy) :
   _max_vertex(copy._max_vertex)
 {
 }
+
+INLINE ostream &
+operator << (ostream &out, const qpGeomPrimitive &obj) {
+  obj.output(out);
+  return out;
+}

+ 2 - 0
panda/src/gobj/qpgeomPrimitive.h

@@ -267,6 +267,8 @@ private:
   friend class PreparedGraphicsObjects;
 };
 
+INLINE ostream &operator << (ostream &out, const qpGeomPrimitive &obj);
+
 #include "qpgeomPrimitive.I"
 
 #endif

+ 10 - 14
panda/src/gsgbase/graphicsStateGuardianBase.h

@@ -83,13 +83,10 @@ class DepthWriteAttrib;
 class TexGenAttrib;
 class CgShaderAttrib;
 class CullFaceAttrib;
-class StencilAttrib;
 class ClipPlaneAttrib;
 class ShadeModelAttrib;
 class TransparencyAttrib;
 class FogAttrib;
-class LinesmoothAttrib;
-class PointShapeAttrib;
 class DepthOffsetAttrib;
 
 class PointLight;
@@ -175,16 +172,16 @@ public:
   // inconvenient to declare each of those types to be friends of this
   // class.
 
-  virtual void draw_point(GeomPoint *geom, GeomContext *gc)=0;
-  virtual void draw_line(GeomLine *geom, GeomContext *gc)=0;
-  virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc)=0;
-  virtual void draw_sprite(GeomSprite *geom, GeomContext *gc)=0;
-  virtual void draw_polygon(GeomPolygon *geom, GeomContext *gc)=0;
-  virtual void draw_quad(GeomQuad *geom, GeomContext *gc)=0;
-  virtual void draw_tri(GeomTri *geom, GeomContext *gc)=0;
-  virtual void draw_tristrip(GeomTristrip *geom, GeomContext *gc)=0;
-  virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc)=0;
-  virtual void draw_sphere(GeomSphere *geom, GeomContext *gc)=0;
+  virtual void draw_point(GeomPoint *geom, GeomContext *gc) { }
+  virtual void draw_line(GeomLine *geom, GeomContext *gc) { }
+  virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc) { }
+  virtual void draw_sprite(GeomSprite *geom, GeomContext *gc) { }
+  virtual void draw_polygon(GeomPolygon *geom, GeomContext *gc) { }
+  virtual void draw_quad(GeomQuad *geom, GeomContext *gc) { }
+  virtual void draw_tri(GeomTri *geom, GeomContext *gc) { }
+  virtual void draw_tristrip(GeomTristrip *geom, GeomContext *gc) { }
+  virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc) { }
+  virtual void draw_sphere(GeomSphere *geom, GeomContext *gc) { }
 
   virtual bool begin_draw_primitives(const qpGeom *geom, 
                                      const qpGeomMunger *munger,
@@ -228,7 +225,6 @@ public:
   virtual void issue_color_blend(const ColorBlendAttrib *) { }
   virtual void issue_tex_gen(const TexGenAttrib *) { }
   virtual void issue_cg_shader_bind(const CgShaderAttrib *){}
-  virtual void issue_stencil(const StencilAttrib *) { }
   virtual void issue_clip_plane(const ClipPlaneAttrib *) { }
   virtual void issue_shade_model(const ShadeModelAttrib *) { }
 

+ 8 - 8
panda/src/parametrics/ropeNode.cxx

@@ -361,7 +361,7 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
     CPT(RenderState) state = data._state->add_attrib(thick);
     
     CullableObject *object = new CullableObject(geom, state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
 
   } else {
@@ -406,7 +406,7 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
     CPT(RenderState) state = data._state->add_attrib(thick);
     
     CullableObject *object = new CullableObject(geom, state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
   }
 }
@@ -451,7 +451,7 @@ render_tape(CullTraverser *trav, CullTraverserData &data,
     geom->add_primitive(strip);
 
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
 
   } else {
@@ -497,7 +497,7 @@ render_tape(CullTraverser *trav, CullTraverserData &data,
     geom->set_lengths(lengths);
     
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
   }
 }
@@ -549,7 +549,7 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
     geom->add_primitive(strip);
 
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
 
   } else {
@@ -595,7 +595,7 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
     geom->set_lengths(lengths);
     
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
   }
 }
@@ -654,7 +654,7 @@ render_tube(CullTraverser *trav, CullTraverserData &data,
     geom->add_primitive(strip);
 
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
 
   } else {
@@ -713,7 +713,7 @@ render_tube(CullTraverser *trav, CullTraverserData &data,
     geom->set_lengths(lengths);
     
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
   }
 }

+ 2 - 2
panda/src/parametrics/sheetNode.cxx

@@ -333,7 +333,7 @@ render_sheet(CullTraverser *trav, CullTraverserData &data,
     geom->add_primitive(strip);
 
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
 
   } else {
@@ -403,7 +403,7 @@ render_sheet(CullTraverser *trav, CullTraverserData &data,
     geom->set_lengths(lengths);
   
     CullableObject *object = new CullableObject(geom, data._state,
-                                                data._render_transform);
+                                                data._net_transform);
     trav->get_cull_handler()->record_object(object, trav);
   }
 }

+ 9 - 11
panda/src/pgraph/cullTraverser.I

@@ -81,9 +81,7 @@ get_tag_state_key() const {
 //     Function: CullTraverser::get_camera_transform
 //       Access: Public
 //  Description: Returns the position of the camera relative to the
-//               starting node, without any compensating
-//               coordinate-system transforms that might have been
-//               introduced for the purposes of rendering.
+//               starting node.
 ////////////////////////////////////////////////////////////////////
 INLINE const TransformState *CullTraverser::
 get_camera_transform() const {
@@ -91,21 +89,21 @@ get_camera_transform() const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: CullTraverser::get_render_transform
+//     Function: CullTraverser::get_world_transform
 //       Access: Public
 //  Description: Returns the position of the starting node relative
-//               to the camera, pretransformed as appropriate for
-//               rendering.
+//               to the camera.  This is the inverse of the camera
+//               transform.
 //
 //               Note that this value is always the position of the
 //               starting node, not the current node, even if it is
-//               sampled during a traversal.  To get the render
-//               transform of the current node check in the current
-//               CullTraverserData.
+//               sampled during a traversal.  To get the world
+//               transform of the current node use
+//               CullTraverserData::_net_transform.
 ////////////////////////////////////////////////////////////////////
 INLINE const TransformState *CullTraverser::
-get_render_transform() const {
-  return _scene_setup->get_render_transform();
+get_world_transform() const {
+  return _scene_setup->get_world_transform();
 }
 
 ////////////////////////////////////////////////////////////////////

+ 6 - 8
panda/src/pgraph/cullTraverser.cxx

@@ -111,8 +111,7 @@ traverse(const NodePath &root, bool python_cull_control) {
     // store this pointer in this
     set_portal_clipper(&portal_viewer);
 
-    CullTraverserData data(root, get_render_transform(),
-                           TransformState::make_identity(),
+    CullTraverserData data(root, get_world_transform(),
                            _initial_state, _view_frustum, 
                            _guard_band);
     
@@ -126,12 +125,11 @@ traverse(const NodePath &root, bool python_cull_control) {
     CPT(TransformState) transform = cull_center.get_transform(root);
     
     CullTraverserData my_data(data, portal_viewer._previous);
-    my_data._render_transform = my_data._render_transform->compose(transform);
+    my_data._net_transform = my_data._net_transform->compose(transform);
     traverse(my_data);
 
   } else {
-    CullTraverserData data(root, get_render_transform(),
-                           TransformState::make_identity(),
+    CullTraverserData data(root, get_world_transform(),
                            _initial_state, _view_frustum, 
                            _guard_band);
     
@@ -275,7 +273,7 @@ show_bounds(CullTraverserData &data, bool tight) {
       _geoms_pcollector.add_level(1);
       CullableObject *outer_viz = 
         new CullableObject(bounds_viz, get_bounds_outer_viz_state(), 
-                           data._render_transform);
+                           data._net_transform);
       _cull_handler->record_object(outer_viz, this);
     }
     
@@ -286,12 +284,12 @@ show_bounds(CullTraverserData &data, bool tight) {
       _geoms_pcollector.add_level(2);
       CullableObject *outer_viz = 
         new CullableObject(bounds_viz, get_bounds_outer_viz_state(), 
-                           data._render_transform);
+                           data._net_transform);
       _cull_handler->record_object(outer_viz, this);
       
       CullableObject *inner_viz = 
         new CullableObject(bounds_viz, get_bounds_inner_viz_state(), 
-                           data._render_transform);
+                           data._net_transform);
       _cull_handler->record_object(inner_viz, this);
     }
   }

+ 1 - 1
panda/src/pgraph/cullTraverser.h

@@ -64,7 +64,7 @@ public:
   INLINE const DrawMask &get_camera_mask() const;
 
   INLINE const TransformState *get_camera_transform() const;
-  INLINE const TransformState *get_render_transform() const;
+  INLINE const TransformState *get_world_transform() const;
 
   INLINE void set_initial_state(const RenderState *initial_state);
   INLINE const RenderState *get_initial_state() const;

+ 0 - 5
panda/src/pgraph/cullTraverserData.I

@@ -23,13 +23,11 @@
 ////////////////////////////////////////////////////////////////////
 INLINE CullTraverserData::
 CullTraverserData(const NodePath &start,
-                  const TransformState *render_transform,
                   const TransformState *net_transform,
                   const RenderState *state,
                   GeometricBoundingVolume *view_frustum,
                   GeometricBoundingVolume *guard_band) :
   _node_path(start),
-  _render_transform(render_transform),
   _net_transform(net_transform),
   _state(state),
   _view_frustum(view_frustum),
@@ -45,7 +43,6 @@ CullTraverserData(const NodePath &start,
 INLINE CullTraverserData::
 CullTraverserData(const CullTraverserData &copy) :
   _node_path(copy._node_path),
-  _render_transform(copy._render_transform),
   _net_transform(copy._net_transform),
   _state(copy._state),
   _view_frustum(copy._view_frustum),
@@ -61,7 +58,6 @@ CullTraverserData(const CullTraverserData &copy) :
 INLINE void CullTraverserData::
 operator = (const CullTraverserData &copy) {
   _node_path = copy._node_path;
-  _render_transform = copy._render_transform;
   _net_transform = copy._net_transform;
   _state = copy._state;
   _view_frustum = copy._view_frustum;
@@ -77,7 +73,6 @@ operator = (const CullTraverserData &copy) {
 INLINE CullTraverserData::
 CullTraverserData(const CullTraverserData &parent, PandaNode *child) :
   _node_path(parent._node_path, child),
-  _render_transform(parent._render_transform),
   _net_transform(parent._net_transform),
   _state(parent._state),
   _view_frustum(parent._view_frustum),

+ 0 - 1
panda/src/pgraph/cullTraverserData.cxx

@@ -72,7 +72,6 @@ apply_transform_and_state(CullTraverser *trav,
 
   if (!node_transform->is_identity()) {
     _net_transform = _net_transform->compose(node_transform);
-    _render_transform = _render_transform->compose(node_transform);
 
     if ((_view_frustum != (GeometricBoundingVolume *)NULL) ||
         (_guard_band != (GeometricBoundingVolume *)NULL)) {

+ 0 - 2
panda/src/pgraph/cullTraverserData.h

@@ -48,7 +48,6 @@ class CullTraverser;
 class EXPCL_PANDA CullTraverserData {
 public:
   INLINE CullTraverserData(const NodePath &start,
-                           const TransformState *render_transform,
                            const TransformState *net_transform,
                            const RenderState *state,
                            GeometricBoundingVolume *view_frustum,
@@ -69,7 +68,6 @@ public:
                                  CPT(RenderEffects) node_effects);
 
   WorkingNodePath _node_path;
-  CPT(TransformState) _render_transform;
   CPT(TransformState) _net_transform;
   CPT(RenderState) _state;
   PT(GeometricBoundingVolume) _view_frustum;

+ 1 - 1
panda/src/pgraph/cullableObject.I

@@ -41,7 +41,7 @@ CullableObject(const CullTraverserData &data,
                CullableObject *next) :
   _geom(geom_node->get_geom(i)),
   _state(data._state->compose(geom_node->get_geom_state(i))),
-  _transform(data._render_transform),
+  _transform(data._net_transform),
   _next(next)
 {
 }

+ 24 - 11
panda/src/pgraph/cullableObject.cxx

@@ -70,6 +70,12 @@ munge_geom(GraphicsStateGuardianBase *gsg,
         // directly; we have to render them in software instead.
         // Munge them into quads.  This will replace the _geom and
         // _munged_data, and might also replace _state.
+        if (pgraph_cat.is_spam()) {
+          pgraph_cat.spam()
+            << "munge_points_to_quads() for geometry with bits: " 
+            << hex << geom_rendering << ", unsupported: "
+            << (unsupported_bits & qpGeom::GR_point_bits) << dec << "\n";
+        }
         munge_points_to_quads(traverser);
         qpgeom = DCAST(qpGeom, _geom);
       }
@@ -233,16 +239,7 @@ munge_points_to_quads(const CullTraverser *traverser) {
 
   SceneSetup *scene = traverser->get_scene();
   const Lens *lens = scene->get_lens();
-  const LMatrix4f &lens_mat = lens->get_projection_mat();
-  LMatrix4f projection =
-    LMatrix4f::convert_mat(gsg->get_internal_coordinate_system(), 
-                           lens->get_coordinate_system()) *
-    lens_mat;
-
-  LMatrix4f render_transform;
-  if (has_normal) {
-    render_transform = modelview * projection;
-  }
+  const LMatrix4f &projection = lens->get_projection_mat();
 
   int viewport_width = scene->get_viewport_width();
   int viewport_height = scene->get_viewport_height();
@@ -261,6 +258,22 @@ munge_points_to_quads(const CullTraverser *traverser) {
     }
   }
 
+  // We need a standard projection matrix, in a known coordinate
+  // system, to compute the perspective height.
+  LMatrix4f height_projection;
+  if (perspective) {
+    height_projection =
+      LMatrix4f::convert_mat(CS_yup_right, lens->get_coordinate_system()) *
+      projection;
+  }
+
+  // We will need the composite render transform to compute the
+  // lighting normal.
+  LMatrix4f render_transform;
+  if (has_normal) {
+    render_transform = modelview * projection;
+  }
+
   // Replace each primitive in the Geom (it's presumably a GeomPoints
   // primitive, although it might be some other kind of primitive if
   // we got here because RenderModeAttrib::M_point is enabled) with a
@@ -339,7 +352,7 @@ munge_points_to_quads(const CullTraverser *traverser) {
         // viewport and projection matrix.
         float scale = _transform->get_scale()[1];
         LVector3f height(0.0f, point_size * scale, scale);
-        height = height * projection;
+        height = height * height_projection;
         scale_y = height[1] * viewport_height;
 
         // We should then divide the radius by the distance from the

+ 1 - 1
panda/src/pgraph/portalNode.cxx

@@ -231,7 +231,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
       // Get the net trasform of the _cell_out
       CPT(TransformState) cell_transform = _cell_out.get_net_transform();
       
-      CullTraverserData next_data(_cell_out, trav->get_render_transform()->compose(cell_transform),
+      CullTraverserData next_data(_cell_out, 
                                   cell_transform,
                                   trav->get_initial_state(), vf, 
                                   trav->get_guard_band());

+ 2 - 53
panda/src/pgraph/sceneSetup.I

@@ -31,7 +31,6 @@ SceneSetup() {
   _initial_state = RenderState::make_empty();
   _camera_transform = TransformState::make_identity();
   _world_transform = TransformState::make_identity();
-  _cs_transform = TransformState::make_identity();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -238,9 +237,7 @@ get_initial_state() const {
 //     Function: SceneSetup::set_camera_transform
 //       Access: Public
 //  Description: Specifies the position of the camera relative to the
-//               starting node, without any compensating
-//               coordinate-system transforms that might have been
-//               introduced for the purposes of rendering.
+//               starting node.
 ////////////////////////////////////////////////////////////////////
 INLINE void SceneSetup::
 set_camera_transform(const TransformState *camera_transform) {
@@ -251,9 +248,7 @@ set_camera_transform(const TransformState *camera_transform) {
 //     Function: SceneSetup::get_camera_transform
 //       Access: Public
 //  Description: Returns the position of the camera relative to the
-//               starting node, without any compensating
-//               coordinate-system transforms that might have been
-//               introduced for the purposes of rendering.
+//               starting node.
 ////////////////////////////////////////////////////////////////////
 INLINE const TransformState *SceneSetup::
 get_camera_transform() const {
@@ -270,7 +265,6 @@ get_camera_transform() const {
 INLINE void SceneSetup::
 set_world_transform(const TransformState *world_transform) {
   _world_transform = world_transform;
-  _render_transform = _cs_transform->compose(_world_transform);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -284,48 +278,3 @@ INLINE const TransformState *SceneSetup::
 get_world_transform() const {
   return _world_transform;
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: SceneSetup::set_cs_transform
-//       Access: Public
-//  Description: Specifies the pretransformation to apply to the world
-//               transform to produce the appropriate transformation
-//               for rendering.  This is usually the appropriate
-//               coordinate-system conversion for the current GSG.
-////////////////////////////////////////////////////////////////////
-INLINE void SceneSetup::
-set_cs_transform(const TransformState *cs_transform) {
-  _cs_transform = cs_transform;
-  _render_transform = _cs_transform->compose(_world_transform);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: SceneSetup::get_cs_transform
-//       Access: Public
-//  Description: Returns the pretransformation to apply to the world
-//               transform to produce the appropriate transformation
-//               for rendering.
-////////////////////////////////////////////////////////////////////
-INLINE const TransformState *SceneSetup::
-get_cs_transform() const {
-  return _cs_transform;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: SceneSetup::get_render_transform
-//       Access: Public
-//  Description: Returns the position of the starting node relative
-//               to the camera, pretransformed as appropriate for
-//               rendering.  This is the same as the world transform,
-//               with a possible coordinate-system conversion applied.
-//
-//               Note that this value is always the position of the
-//               starting node, not the current node, even if it is
-//               sampled during a traversal.  To get the render
-//               transform of the current node check in the current
-//               CullTraverserData.
-////////////////////////////////////////////////////////////////////
-INLINE const TransformState *SceneSetup::
-get_render_transform() const {
-  return _render_transform;
-}

+ 0 - 7
panda/src/pgraph/sceneSetup.h

@@ -71,11 +71,6 @@ public:
   INLINE void set_world_transform(const TransformState *world_transform);
   INLINE const TransformState *get_world_transform() const;
 
-  INLINE void set_cs_transform(const TransformState *cs_transform);
-  INLINE const TransformState *get_cs_transform() const;
-
-  INLINE const TransformState *get_render_transform() const;
-
 private:
   DisplayRegion *_display_region;
   int _viewport_width;
@@ -88,8 +83,6 @@ private:
   CPT(RenderState) _initial_state;
   CPT(TransformState) _camera_transform;
   CPT(TransformState) _world_transform;
-  CPT(TransformState) _cs_transform;
-  CPT(TransformState) _render_transform;
 };
 
 #include "sceneSetup.I"

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels