Browse Source

pandify some more

David Rose 20 years ago
parent
commit
fc716f0d49

+ 108 - 108
panda/src/dxgsg8/dxGraphicsStateGuardian8.I

@@ -17,7 +17,13 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 
 
-INLINE DWORD
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::Colorf_to_D3DCOLOR
+//       Access: Public, Static
+//  Description: Converts Panda's floating-point Colorf structure to
+//               DirectX's D3DCOLOR packed structure.
+////////////////////////////////////////////////////////////////////
+INLINE DWORD DXGraphicsStateGuardian8::
 Colorf_to_D3DCOLOR(const Colorf &cColorf) {
 Colorf_to_D3DCOLOR(const Colorf &cColorf) {
 // MS VC defines _M_IX86 for x86.  gcc should define _X86_
 // MS VC defines _M_IX86 for x86.  gcc should define _X86_
 #if defined(_M_IX86) || defined(_X86_)
 #if defined(_M_IX86) || defined(_X86_)
@@ -71,62 +77,46 @@ Colorf_to_D3DCOLOR(const Colorf &cColorf) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_line_smooth
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_line_smooth(bool val) {
-  if(_line_smooth_enabled != val) {
-    _line_smooth_enabled = val;
-
-    _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, (DWORD)val);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_dither
-//       Access:
+//     Function: DXGraphicsStateGuardian8::enable_color_material
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
-enable_dither(bool val) {
-  if (_dither_enabled != val) {
-    _dither_enabled = val;
-
-    _pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, (DWORD)val);
+enable_color_material(bool val) {
+  if (_color_material_enabled != val) {
+    _color_material_enabled = val;
   }
   }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_color_material
-//       Access:
+//     Function: DXGraphicsStateGuardian8::enable_fog
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
-enable_color_material(bool val) {
-  if (_color_material_enabled != val) {
-    _color_material_enabled = val;
+enable_fog(bool val) {
+  if ((_fog_enabled != val) && (_doFogType!=None)) {
+    _fog_enabled = val;
+    _pD3DDevice->SetRenderState(D3DRS_FOGENABLE, (DWORD)val);
   }
   }
 }
 }
 
 
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_blend
-//       Access:
+//     Function: DXGraphicsStateGuardian8::enable_zwritemask
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
-enable_blend(bool val) {
-  if (_blend_enabled != val) {
-    _blend_enabled = val;
-    _pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, (DWORD)val);
+enable_zwritemask(bool val) {
+  if (_depth_write_enabled != val) {
+    _depth_write_enabled = val;
+    _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, val);
   }
   }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::set_color_writemask
 //     Function: DXGraphicsStateGuardian8::set_color_writemask
-//       Access:
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
@@ -144,22 +134,9 @@ set_color_writemask(UINT color_writemask) {
   }
   }
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_fog
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian8::
-enable_fog(bool val) {
-  if ((_fog_enabled != val) && (_doFogType!=None)) {
-    _fog_enabled = val;
-    _pD3DDevice->SetRenderState(D3DRS_FOGENABLE, (DWORD)val);
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::set_vertex_format
 //     Function: DXGraphicsStateGuardian8::set_vertex_format
-//       Access:
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
@@ -177,9 +154,62 @@ set_vertex_format(DWORD NewFvfType) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::get_texture_wrap_mode
+//       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) {
+  switch (wm) {
+  case Texture::WM_clamp:
+    return D3DTADDRESS_CLAMP;
+  case Texture::WM_repeat:
+    return D3DTADDRESS_WRAP;
+  case Texture::WM_mirror:
+    return D3DTADDRESS_MIRROR;
+  case Texture::WM_mirror_once:
+    return D3DTADDRESS_MIRRORONCE;
+  case Texture::WM_border_color:
+    return D3DTADDRESS_BORDER;
+  }
+  dxgsg8_cat.error() << "Invalid Texture::Mode value" << endl;
+  return D3DTADDRESS_WRAP;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::get_fog_mode_type
+//       Access: Protected, Static
+//  Description: Maps from the fog types to gl version
+////////////////////////////////////////////////////////////////////
+INLINE D3DFOGMODE DXGraphicsStateGuardian8::
+get_fog_mode_type(Fog::Mode m) {
+  switch (m) {
+  case Fog::M_linear:
+    return D3DFOG_LINEAR;
+  case Fog::M_exponential:
+    return D3DFOG_EXP;
+  case Fog::M_exponential_squared:
+    return D3DFOG_EXP2;
+  }
+  dxgsg8_cat.error() << "Invalid Fog::Mode value" << endl;
+  return D3DFOG_EXP;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::get_tex_mat_sym
+//       Access: Protected, Static
+//  Description: Returns the nth D3DTS_TEXTURE(n) constant.
+////////////////////////////////////////////////////////////////////
+INLINE D3DTRANSFORMSTATETYPE DXGraphicsStateGuardian8::
+get_tex_mat_sym(int stage_index) {
+  return (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + stage_index);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::enable_alpha_test
 //     Function: DXGraphicsStateGuardian8::enable_alpha_test
-//       Access:
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
@@ -190,9 +220,22 @@ enable_alpha_test(bool val) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::enable_blend
+//       Access: Protected
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void DXGraphicsStateGuardian8::
+enable_blend(bool val) {
+  if (_blend_enabled != val) {
+    _blend_enabled = val;
+    _pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, (DWORD)val);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::call_dxLightModelAmbient
 //     Function: DXGraphicsStateGuardian8::call_dxLightModelAmbient
-//       Access:
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
@@ -204,10 +247,9 @@ call_dxLightModelAmbient(const Colorf &color) {
   }
   }
 }
 }
 
 
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::call_dxAlphaFunc
 //     Function: DXGraphicsStateGuardian8::call_dxAlphaFunc
-//       Access:
+//       Access: Protected
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
@@ -223,7 +265,11 @@ call_dxAlphaFunc(D3DCMPFUNC func, float reference_alpha) {
   }
   }
 }
 }
 
 
-
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::call_dxBlendFunc
+//       Access: Protected
+//  Description:
+////////////////////////////////////////////////////////////////////
 INLINE void DXGraphicsStateGuardian8::
 INLINE void DXGraphicsStateGuardian8::
 call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc) {
 call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc) {
   if (_blend_source_func != sfunc) {
   if (_blend_source_func != sfunc) {
@@ -236,63 +282,17 @@ call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc) {
   }
   }
 }
 }
 
 
-INLINE void DXGraphicsStateGuardian8::
-enable_zwritemask(bool val) {
-  if (_depth_write_enabled != val) {
-    _depth_write_enabled = val;
-    _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, val);
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_texture_wrap_mode
-//       Access: Protected, Static
-//  Description: Maps from the Texture's internal wrap mode symbols to
-//               GL's.
+//     Function: DXGraphicsStateGuardian8::enable_dither
+//       Access: Protected
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian8::
-get_texture_wrap_mode(Texture::WrapMode wm) {
-  switch (wm) {
-  case Texture::WM_clamp:
-    return D3DTADDRESS_CLAMP;
-  case Texture::WM_repeat:
-    return D3DTADDRESS_WRAP;
-  case Texture::WM_mirror:
-    return D3DTADDRESS_MIRROR;
-  case Texture::WM_mirror_once:
-    return D3DTADDRESS_MIRRORONCE;
-  case Texture::WM_border_color:
-    return D3DTADDRESS_BORDER;
-  }
-  dxgsg8_cat.error() << "Invalid Texture::Mode value" << endl;
-  return D3DTADDRESS_WRAP;
-}
+INLINE void DXGraphicsStateGuardian8::
+enable_dither(bool val) {
+  if (_dither_enabled != val) {
+    _dither_enabled = val;
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_fog_mode_type
-//       Access: Protected, Static
-//  Description: Maps from the fog types to gl version
-////////////////////////////////////////////////////////////////////
-INLINE D3DFOGMODE DXGraphicsStateGuardian8::
-get_fog_mode_type(Fog::Mode m) {
-  switch (m) {
-  case Fog::M_linear:
-    return D3DFOG_LINEAR;
-  case Fog::M_exponential:
-    return D3DFOG_EXP;
-  case Fog::M_exponential_squared:
-    return D3DFOG_EXP2;
+    _pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, (DWORD)val);
   }
   }
-  dxgsg8_cat.error() << "Invalid Fog::Mode value" << endl;
-  return D3DFOG_EXP;
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_tex_mat_sym
-//       Access: Protected, Static
-//  Description: Returns the nth D3DTS_TEXTURE(n) constant.
-////////////////////////////////////////////////////////////////////
-INLINE D3DTRANSFORMSTATETYPE DXGraphicsStateGuardian8::
-get_tex_mat_sym(int stage_index) {
-  return (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + stage_index);
-}

+ 5 - 5
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -1443,7 +1443,7 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
     return false;
     return false;
   }
   }
 
 
-  d3d_surface_to_texture(SrcCopyRect, pD3DSurf, tex);
+  DXTextureContext8::d3d_surface_to_texture(SrcCopyRect, pD3DSurf, tex);
 
 
   RELEASE(pD3DSurf, dxgsg8, "pD3DSurf", RELEASE_ONCE);
   RELEASE(pD3DSurf, dxgsg8, "pD3DSurf", RELEASE_ONCE);
 
 
@@ -1528,7 +1528,6 @@ reset() {
   _depth_test_enabled = true;
   _depth_test_enabled = true;
   _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, _depth_test_enabled);
   _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, _depth_test_enabled);
 
 
-  _line_smooth_enabled = false;
   _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, false);
   _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, false);
 
 
   _color_material_enabled = false;
   _color_material_enabled = false;
@@ -1610,13 +1609,14 @@ reset() {
   _pD3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
   _pD3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
 
 
   // Antialiasing.
   // Antialiasing.
-  enable_line_smooth(false);
+  _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);
 
 
   _current_fill_mode = RenderModeAttrib::M_filled;
   _current_fill_mode = RenderModeAttrib::M_filled;
   _pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
   _pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
 
 
-  // must do SetTSS here because redundant states are filtered out by our code based on current values above, so
-  // initial conditions must be correct
+  // must do SetTSS here because redundant states are filtered out by
+  // our code based on current values above, so initial conditions
+  // must be correct
   _texturing_enabled = false;
   _texturing_enabled = false;
   _pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);  // disables texturing
   _pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);  // disables texturing
 
 

+ 1 - 3
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -116,6 +116,7 @@ public:
                           int light_id);
                           int light_id);
 
 
   static D3DFORMAT get_index_type(qpGeom::NumericType numeric_type);
   static D3DFORMAT get_index_type(qpGeom::NumericType numeric_type);
+  INLINE static DWORD Colorf_to_D3DCOLOR(const Colorf &cColorf);
 
 
 protected:
 protected:
   virtual void do_issue_material();
   virtual void do_issue_material();
@@ -156,9 +157,7 @@ protected:
   INLINE static D3DTRANSFORMSTATETYPE get_tex_mat_sym(int stage_index);
   INLINE static D3DTRANSFORMSTATETYPE get_tex_mat_sym(int stage_index);
 
 
   INLINE void enable_alpha_test(bool val);
   INLINE void enable_alpha_test(bool val);
-  INLINE void enable_line_smooth(bool val);
   INLINE void enable_blend(bool val);
   INLINE void enable_blend(bool val);
-  INLINE void enable_point_smooth(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_dxAlphaFunc(D3DCMPFUNC func, float refval);
   INLINE void call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc);
   INLINE void call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc);
@@ -230,7 +229,6 @@ protected:
   unsigned int _max_lights;
   unsigned int _max_lights;
   unsigned int _max_clip_planes;
   unsigned int _max_clip_planes;
 
 
-  bool _line_smooth_enabled;
   bool _color_material_enabled;
   bool _color_material_enabled;
   bool _texturing_enabled;
   bool _texturing_enabled;
   bool _dither_enabled;
   bool _dither_enabled;

+ 410 - 390
panda/src/dxgsg8/dxTextureContext8.cxx

@@ -29,288 +29,49 @@ TypeHandle DXTextureContext8::_type_handle;
 static const DWORD g_LowByteMask = 0x000000FF;
 static const DWORD g_LowByteMask = 0x000000FF;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::get_bits_per_pixel
-//       Access: Protected
-//  Description: Maps from the Texture's Format symbols
-//               to bpp.  returns # of alpha bits
-//               Note: Texture's format indicates REQUESTED final format,
-//                     not the stored format, which is indicated by pixelbuffer type
+//     Function: DXTextureContext8::Constructor
+//       Access: Public
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-unsigned int DXTextureContext8::
-get_bits_per_pixel(Texture::Format format, int *alphbits) {
-  *alphbits = 0;      // assume no alpha bits
-  switch(format) {
-  case Texture::F_alpha:
-    *alphbits = 8;
-  case Texture::F_color_index:
-  case Texture::F_red:
-  case Texture::F_green:
-  case Texture::F_blue:
-  case Texture::F_rgb332:
-    return 8;
-  case Texture::F_luminance_alphamask:
-    *alphbits = 1;
-    return 16;
-  case Texture::F_luminance_alpha:
-    *alphbits = 8;
-    return 16;
-  case Texture::F_luminance:
-    return 8;
-  case Texture::F_rgba4:
-    *alphbits = 4;
-    return 16;
-  case Texture::F_rgba5:
-    *alphbits = 1;
-    return 16;
-  case Texture::F_depth_component:
-  case Texture::F_rgb5:
-    return 16;
-  case Texture::F_rgb8:
-  case Texture::F_rgb:
-    return 24;
-  case Texture::F_rgba8:
-  case Texture::F_rgba:
-  case Texture::F_rgbm:
-    if (format == Texture::F_rgbm)   // does this make any sense?
-      *alphbits = 1;
-    else *alphbits = 8;
-    return 32;
-  case Texture::F_rgb12:
-    return 36;
-  case Texture::F_rgba12:
-    *alphbits = 12;
-    return 48;
-  }
-  return 8;
-}
-
-// still need custom conversion since d3d/d3dx has no way to convert arbitrary fmt to ARGB in-memory user buffer
-HRESULT
-d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface, Texture *result) {
-  // copies source_rect in pD3DSurf to upper left of texture
-  HRESULT hr;
-  DWORD dwNumComponents = result->get_num_components();
-
-  nassertr(result->get_component_width() == sizeof(BYTE), E_FAIL);   // cant handle anything else now
-  nassertr(result->get_component_type() == Texture::T_unsigned_byte, E_FAIL);   // cant handle anything else now
-  nassertr((dwNumComponents == 3) || (dwNumComponents == 4), E_FAIL);  // cant handle anything else now
-  nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
-
-  BYTE *pbuf = result->modify_ram_image().p();
-
-  if (IsBadWritePtr(d3d_surface, sizeof(DWORD))) {
-    dxgsg8_cat.error() << "d3d_surface_to_texture failed: bad pD3DSurf ptr value (" << ((void*)d3d_surface) << ")\n";
-    exit(1);
-  }
-
-  DWORD dwXWindowOffset, dwYWindowOffset;
-  DWORD dwCopyWidth, dwCopyHeight;
-
-  D3DLOCKED_RECT LockedRect;
-  D3DSURFACE_DESC SurfDesc;
-
-  hr = d3d_surface->GetDesc(&SurfDesc);
-
-  dwXWindowOffset = source_rect.left, dwYWindowOffset = source_rect.top;
-  dwCopyWidth = RECT_XSIZE(source_rect);
-  dwCopyHeight = RECT_YSIZE(source_rect);
-
-  //make sure there's enough space in the texture, its size must match (especially xsize)
-  // or scanlines will be too long
-
-  if (!((dwCopyWidth == result->get_x_size()) && (dwCopyHeight <= (DWORD)result->get_y_size()))) {
-    dxgsg8_cat.error() << "d3d_surface_to_texture, Texture size too small to hold display surface!\n";
-    nassertr(false, E_FAIL);
-    return E_FAIL;
-  }
-
-  hr = d3d_surface->LockRect(&LockedRect, (CONST RECT*)NULL, (D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE /* | D3DLOCK_NOSYSLOCK */));
-  if (FAILED(hr)) {
-    dxgsg8_cat.error() << "d3d_surface_to_texture LockRect() failed!" << D3DERRORSTRING(hr);
-    return hr;
-  }
-
-  // ones not listed not handled yet
-  nassertr((SurfDesc.Format == D3DFMT_A8R8G8B8) ||
-           (SurfDesc.Format == D3DFMT_X8R8G8B8) ||
-           (SurfDesc.Format == D3DFMT_R8G8B8) ||
-           (SurfDesc.Format == D3DFMT_R5G6B5) ||
-           (SurfDesc.Format == D3DFMT_X1R5G5B5) ||
-           (SurfDesc.Format == D3DFMT_A1R5G5B5) ||
-           (SurfDesc.Format == D3DFMT_A4R4G4B4), E_FAIL);
-
-  //pbuf contains raw ARGB in Texture byteorder
-
-  DWORD BytePitch = LockedRect.Pitch;
-  BYTE* pSurfBytes = (BYTE*)LockedRect.pBits;
-
-  // writes out last line in DDSurf first in PixelBuf, so Y line order precedes inversely
-
-  if (dxgsg8_cat.is_debug()) {
-    dxgsg8_cat.debug()
-      << "d3d_surface_to_texture converting " << D3DFormatStr(SurfDesc.Format) << "bpp DDSurf to "
-      <<  dwNumComponents << "-channel panda Texture\n";
-  }
-
-  DWORD *pDstWord = (DWORD *) pbuf;
-  BYTE *pDstByte = (BYTE *) pbuf;
-
-  switch(SurfDesc.Format) {
-  case D3DFMT_A8R8G8B8:
-  case D3DFMT_X8R8G8B8: {
-    if (dwNumComponents == 4) {
-      DWORD *pSrcWord;
-      BYTE *pDstLine = (BYTE*)pDstWord;
-
-      pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcWord = ((DWORD*)pSurfBytes)+dwXWindowOffset;
-        memcpy(pDstLine, pSrcWord, BytePitch);
-        pDstLine += BytePitch;
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      DWORD *pSrcWord;
-      pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcWord = ((DWORD*)pSurfBytes)+dwXWindowOffset;
-
-        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++) {
-          BYTE r, g, b;
-          DWORD dwPixel = *pSrcWord;
-
-          r = (BYTE)((dwPixel>>16) & g_LowByteMask);
-          g = (BYTE)((dwPixel>> 8) & g_LowByteMask);
-          b = (BYTE)((dwPixel    ) & g_LowByteMask);
-
-          *pDstByte += b;
-          *pDstByte += g;
-          *pDstByte += r;
-        }
-      }
-    }
-    break;
-  }
-
-  case D3DFMT_R8G8B8: {
-    BYTE *pSrcByte;
-    pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
-
-    if (dwNumComponents == 4) {
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
-        for(DWORD x = 0; x<dwCopyWidth; x++, pDstWord++) {
-          DWORD r, g, b;
-
-          b = *pSrcByte++;
-          g = *pSrcByte++;
-          r = *pSrcByte++;
+DXTextureContext8::
+DXTextureContext8(Texture *tex) :
+  TextureContext(tex) {
 
 
-          *pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b;
-        }
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
-        memcpy(pDstByte, pSrcByte, BytePitch);
-        pDstByte += BytePitch;
-      }
-    }
-    break;
+  if (dxgsg8_cat.is_spam()) {
+    dxgsg8_cat.spam() 
+      << "Creating DX texture [" << tex->get_name() << "], minfilter(" << tex->get_minfilter() << "), magfilter(" << tex->get_magfilter() << "), anisodeg(" << tex->get_anisotropic_degree() << ")\n";
   }
   }
 
 
-  case D3DFMT_R5G6B5:
-  case D3DFMT_X1R5G5B5:
-  case D3DFMT_A1R5G5B5:
-  case D3DFMT_A4R4G4B4: {
-    WORD  *pSrcWord;
-    // handle 0555, 1555, 0565, 4444 in same loop
-
-    BYTE redshift, greenshift, blueshift;
-    DWORD redmask, greenmask, bluemask;
-
-    if (SurfDesc.Format == D3DFMT_R5G6B5) {
-      redshift = (11-3);
-      redmask = 0xF800;
-      greenmask = 0x07E0;
-      greenshift = (5-2);
-      bluemask = 0x001F;
-      blueshift = 3;
-    } else if (SurfDesc.Format == D3DFMT_A4R4G4B4) {
-      redmask = 0x0F00;
-      redshift = 4;
-      greenmask = 0x00F0;
-      greenshift = 0;
-      bluemask = 0x000F;
-      blueshift = 4;
-    } else {  // 1555 or x555
-      redmask = 0x7C00;
-      redshift = (10-3);
-      greenmask = 0x03E0;
-      greenshift = (5-3);
-      bluemask = 0x001F;
-      blueshift = 3;
-    }
-
-    pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
-    if (dwNumComponents == 4) {
-      // Note: these 16bpp loops ignore input alpha completely (alpha
-      // is set to fully opaque in texture!)
-
-      // if we need to capture alpha, probably need to make separate
-      // loops for diff 16bpp fmts for best speed
-
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
-        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++, pDstWord++) {
-          WORD dwPixel = *pSrcWord;
-          BYTE r, g, b;
-
-          b = (dwPixel & bluemask) << blueshift;
-          g = (dwPixel & greenmask) >> greenshift;
-          r = (dwPixel & redmask) >> redshift;
-
-          // alpha is just set to 0xFF
-
-          *pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b;
-        }
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
-        pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
-        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++) {
-          WORD dwPixel = *pSrcWord;
-          BYTE r, g, b;
-
-          b = (dwPixel & bluemask) << blueshift;
-          g = (dwPixel & greenmask) >> greenshift;
-          r = (dwPixel & redmask) >> redshift;
-
-          *pDstByte += b;
-          *pDstByte += g;
-          *pDstByte += r;
-        }
-      }
-    }
-    break;
-  }
+  _d3d_texture = NULL;
+  _has_mipmaps = false;
+  _tex = tex;
+}
 
 
-  default:
-    dxgsg8_cat.error() << "d3d_surface_to_texture: unsupported D3DFORMAT!\n";
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::Destructor
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+DXTextureContext8::
+~DXTextureContext8() {
+  if (dxgsg8_cat.is_spam()) {
+    dxgsg8_cat.spam()
+      << "Deleting texture context for " << _tex->get_name() << "\n";
   }
   }
-
-  d3d_surface->UnlockRect();
-  return S_OK;
+  delete_texture();
+  TextureContext::~TextureContext();
+  _tex = NULL;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-// Name: create_texture()
-// Desc: Use panda texture's pixelbuffer to create a texture for the specified device.
-//       This code gets the attributes of the texture from the bitmap, creates the
-//       texture, and then copies the bitmap into the texture.
-//-----------------------------------------------------------------------------
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::create_texture
+//       Access: Public
+//  Description: Use panda texture's pixelbuffer to create a texture
+//               for the specified device.  This code gets the
+//               attributes of the texture from the bitmap, creates
+//               the texture, and then copies the bitmap into the
+//               texture.
+////////////////////////////////////////////////////////////////////
 IDirect3DTexture8 *DXTextureContext8::
 IDirect3DTexture8 *DXTextureContext8::
 create_texture(DXScreenData &scrn) {
 create_texture(DXScreenData &scrn) {
   HRESULT hr;
   HRESULT hr;
@@ -723,94 +484,346 @@ create_texture(DXScreenData &scrn) {
     }
     }
     break;
     break;
 
 
-  case Texture::FT_nearest_mipmap_linear:
-    // if we dont have bilinear, do nearest_nearest
-    if (!((scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFPOINT) &&
-          (scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR))) {
-      ft = Texture::FT_nearest_mipmap_nearest;
-    }
-    break;
+  case Texture::FT_nearest_mipmap_linear:
+    // if we dont have bilinear, do nearest_nearest
+    if (!((scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFPOINT) &&
+          (scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR))) {
+      ft = Texture::FT_nearest_mipmap_nearest;
+    }
+    break;
+
+  case Texture::FT_linear_mipmap_nearest:
+    // if we dont have mip linear, do nearest_nearest
+    if (!(scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)) {
+      ft = Texture::FT_nearest_mipmap_nearest;
+    }
+    break;
+
+  case Texture::FT_linear:
+    if (!(scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)) {
+      ft = Texture::FT_nearest;
+    }
+    break;
+  }
+
+  _tex->set_minfilter(ft);
+
+  uint aniso_degree;
+
+  aniso_degree = 1;
+  if (scrn.d3dcaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
+    aniso_degree = _tex->get_anisotropic_degree();
+    if ((aniso_degree>scrn.d3dcaps.MaxAnisotropy) || 
+        dx_force_anisotropic_filtering) {
+      aniso_degree = scrn.d3dcaps.MaxAnisotropy;
+    }
+  }
+  _tex->set_anisotropic_degree(aniso_degree);
+
+#ifdef _DEBUG
+  dxgsg8_cat.spam()
+    << "create_texture: setting aniso degree for " << _tex->get_name()
+    << " to: " << aniso_degree << endl;
+#endif
+
+  UINT cMipLevelCount;
+
+  if (_has_mipmaps) {
+    // tell CreateTex to alloc space for all mip levels down to 1x1
+    cMipLevelCount = 0;
+
+    if (dxgsg8_cat.is_debug()) {
+      dxgsg8_cat.debug()
+        << "create_texture: generating mipmaps for " << _tex->get_name()
+        << endl;
+    }
+  } else {
+    cMipLevelCount = 1;
+  }
+
+  hr = scrn.pD3DDevice->CreateTexture(TargetWidth, TargetHeight, cMipLevelCount, 0x0,
+                                      TargetPixFmt, D3DPOOL_MANAGED, &_d3d_texture);
+  if (FAILED(hr)) {
+    dxgsg8_cat.error()
+      << "D3D create_texture failed!" << D3DERRORSTRING(hr);
+    goto error_exit;
+  }
+
+  if (dxgsg8_cat.is_debug()) {
+    dxgsg8_cat.debug()
+      << "create_texture: " << _tex->get_name()
+      << " converting panda equivalent of " << D3DFormatStr(_d3d_format)
+      << " => " << D3DFormatStr(TargetPixFmt) << endl;
+  }
+
+  hr = fill_d3d_texture_pixels();
+  if (FAILED(hr)) {
+    goto error_exit;
+  }
+
+  // PRINT_REFCNT(dxgsg8, scrn.pD3D8);
+
+  // Return the newly created texture
+  return _d3d_texture;
+
+ error_exit:
+
+  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
+  return NULL;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::delete_texture
+//       Access: Public
+//  Description: Release the surface used to store the texture
+////////////////////////////////////////////////////////////////////
+void DXTextureContext8::
+delete_texture() {
+  if (_d3d_texture == NULL) {
+    // dont bother printing the msg below, since we already released it.
+    return;
+  }
+
+  if (dxgsg8_cat.is_spam()) {
+    dxgsg8_cat.spam() << "Deleting DX texture for " << _tex->get_name() << "\n";
+  }
+
+  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::d3d_surface_to_texture
+//       Access: Public, Static
+//  Description: copies source_rect in pD3DSurf to upper left of
+//               texture
+////////////////////////////////////////////////////////////////////
+HRESULT DXTextureContext8::
+d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface, Texture *result) {
+  // still need custom conversion since d3d/d3dx has no way to convert
+  // arbitrary fmt to ARGB in-memory user buffer
+
+  HRESULT hr;
+  DWORD dwNumComponents = result->get_num_components();
+
+  nassertr(result->get_component_width() == sizeof(BYTE), E_FAIL);   // cant handle anything else now
+  nassertr(result->get_component_type() == Texture::T_unsigned_byte, E_FAIL);   // cant handle anything else now
+  nassertr((dwNumComponents == 3) || (dwNumComponents == 4), E_FAIL);  // cant handle anything else now
+  nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
+
+  BYTE *pbuf = result->modify_ram_image().p();
+
+  if (IsBadWritePtr(d3d_surface, sizeof(DWORD))) {
+    dxgsg8_cat.error() << "d3d_surface_to_texture failed: bad pD3DSurf ptr value (" << ((void*)d3d_surface) << ")\n";
+    exit(1);
+  }
+
+  DWORD dwXWindowOffset, dwYWindowOffset;
+  DWORD dwCopyWidth, dwCopyHeight;
+
+  D3DLOCKED_RECT LockedRect;
+  D3DSURFACE_DESC SurfDesc;
+
+  hr = d3d_surface->GetDesc(&SurfDesc);
+
+  dwXWindowOffset = source_rect.left, dwYWindowOffset = source_rect.top;
+  dwCopyWidth = RECT_XSIZE(source_rect);
+  dwCopyHeight = RECT_YSIZE(source_rect);
+
+  //make sure there's enough space in the texture, its size must match (especially xsize)
+  // or scanlines will be too long
+
+  if (!((dwCopyWidth == result->get_x_size()) && (dwCopyHeight <= (DWORD)result->get_y_size()))) {
+    dxgsg8_cat.error() << "d3d_surface_to_texture, Texture size too small to hold display surface!\n";
+    nassertr(false, E_FAIL);
+    return E_FAIL;
+  }
+
+  hr = d3d_surface->LockRect(&LockedRect, (CONST RECT*)NULL, (D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE /* | D3DLOCK_NOSYSLOCK */));
+  if (FAILED(hr)) {
+    dxgsg8_cat.error() << "d3d_surface_to_texture LockRect() failed!" << D3DERRORSTRING(hr);
+    return hr;
+  }
+
+  // ones not listed not handled yet
+  nassertr((SurfDesc.Format == D3DFMT_A8R8G8B8) ||
+           (SurfDesc.Format == D3DFMT_X8R8G8B8) ||
+           (SurfDesc.Format == D3DFMT_R8G8B8) ||
+           (SurfDesc.Format == D3DFMT_R5G6B5) ||
+           (SurfDesc.Format == D3DFMT_X1R5G5B5) ||
+           (SurfDesc.Format == D3DFMT_A1R5G5B5) ||
+           (SurfDesc.Format == D3DFMT_A4R4G4B4), E_FAIL);
+
+  //pbuf contains raw ARGB in Texture byteorder
+
+  DWORD BytePitch = LockedRect.Pitch;
+  BYTE* pSurfBytes = (BYTE*)LockedRect.pBits;
+
+  // writes out last line in DDSurf first in PixelBuf, so Y line order precedes inversely
+
+  if (dxgsg8_cat.is_debug()) {
+    dxgsg8_cat.debug()
+      << "d3d_surface_to_texture converting " << D3DFormatStr(SurfDesc.Format) << "bpp DDSurf to "
+      <<  dwNumComponents << "-channel panda Texture\n";
+  }
+
+  DWORD *pDstWord = (DWORD *) pbuf;
+  BYTE *pDstByte = (BYTE *) pbuf;
+
+  switch(SurfDesc.Format) {
+  case D3DFMT_A8R8G8B8:
+  case D3DFMT_X8R8G8B8: {
+    if (dwNumComponents == 4) {
+      DWORD *pSrcWord;
+      BYTE *pDstLine = (BYTE*)pDstWord;
+
+      pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcWord = ((DWORD*)pSurfBytes)+dwXWindowOffset;
+        memcpy(pDstLine, pSrcWord, BytePitch);
+        pDstLine += BytePitch;
+      }
+    } else {
+      // 24bpp texture case (numComponents == 3)
+      DWORD *pSrcWord;
+      pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcWord = ((DWORD*)pSurfBytes)+dwXWindowOffset;
+
+        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++) {
+          BYTE r, g, b;
+          DWORD dwPixel = *pSrcWord;
+
+          r = (BYTE)((dwPixel>>16) & g_LowByteMask);
+          g = (BYTE)((dwPixel>> 8) & g_LowByteMask);
+          b = (BYTE)((dwPixel    ) & g_LowByteMask);
+
+          *pDstByte += b;
+          *pDstByte += g;
+          *pDstByte += r;
+        }
+      }
+    }
+    break;
+  }
+
+  case D3DFMT_R8G8B8: {
+    BYTE *pSrcByte;
+    pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
 
 
-  case Texture::FT_linear_mipmap_nearest:
-    // if we dont have mip linear, do nearest_nearest
-    if (!(scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)) {
-      ft = Texture::FT_nearest_mipmap_nearest;
-    }
-    break;
+    if (dwNumComponents == 4) {
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
+        for(DWORD x = 0; x<dwCopyWidth; x++, pDstWord++) {
+          DWORD r, g, b;
 
 
-  case Texture::FT_linear:
-    if (!(scrn.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)) {
-      ft = Texture::FT_nearest;
+          b = *pSrcByte++;
+          g = *pSrcByte++;
+          r = *pSrcByte++;
+
+          *pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b;
+        }
+      }
+    } else {
+      // 24bpp texture case (numComponents == 3)
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
+        memcpy(pDstByte, pSrcByte, BytePitch);
+        pDstByte += BytePitch;
+      }
     }
     }
     break;
     break;
   }
   }
 
 
-  _tex->set_minfilter(ft);
+  case D3DFMT_R5G6B5:
+  case D3DFMT_X1R5G5B5:
+  case D3DFMT_A1R5G5B5:
+  case D3DFMT_A4R4G4B4: {
+    WORD  *pSrcWord;
+    // handle 0555, 1555, 0565, 4444 in same loop
 
 
-  uint aniso_degree;
+    BYTE redshift, greenshift, blueshift;
+    DWORD redmask, greenmask, bluemask;
 
 
-  aniso_degree = 1;
-  if (scrn.d3dcaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
-    aniso_degree = _tex->get_anisotropic_degree();
-    if ((aniso_degree>scrn.d3dcaps.MaxAnisotropy) || 
-        dx_force_anisotropic_filtering) {
-      aniso_degree = scrn.d3dcaps.MaxAnisotropy;
+    if (SurfDesc.Format == D3DFMT_R5G6B5) {
+      redshift = (11-3);
+      redmask = 0xF800;
+      greenmask = 0x07E0;
+      greenshift = (5-2);
+      bluemask = 0x001F;
+      blueshift = 3;
+    } else if (SurfDesc.Format == D3DFMT_A4R4G4B4) {
+      redmask = 0x0F00;
+      redshift = 4;
+      greenmask = 0x00F0;
+      greenshift = 0;
+      bluemask = 0x000F;
+      blueshift = 4;
+    } else {  // 1555 or x555
+      redmask = 0x7C00;
+      redshift = (10-3);
+      greenmask = 0x03E0;
+      greenshift = (5-3);
+      bluemask = 0x001F;
+      blueshift = 3;
     }
     }
-  }
-  _tex->set_anisotropic_degree(aniso_degree);
-
-#ifdef _DEBUG
-  dxgsg8_cat.spam()
-    << "create_texture: setting aniso degree for " << _tex->get_name()
-    << " to: " << aniso_degree << endl;
-#endif
 
 
-  UINT cMipLevelCount;
+    pSurfBytes += BytePitch*(dwYWindowOffset+dwCopyHeight-1);
+    if (dwNumComponents == 4) {
+      // Note: these 16bpp loops ignore input alpha completely (alpha
+      // is set to fully opaque in texture!)
 
 
-  if (_has_mipmaps) {
-    // tell CreateTex to alloc space for all mip levels down to 1x1
-    cMipLevelCount = 0;
+      // if we need to capture alpha, probably need to make separate
+      // loops for diff 16bpp fmts for best speed
 
 
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "create_texture: generating mipmaps for " << _tex->get_name()
-        << endl;
-    }
-  } else {
-    cMipLevelCount = 1;
-  }
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
+        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++, pDstWord++) {
+          WORD dwPixel = *pSrcWord;
+          BYTE r, g, b;
 
 
-  hr = scrn.pD3DDevice->CreateTexture(TargetWidth, TargetHeight, cMipLevelCount, 0x0,
-                                      TargetPixFmt, D3DPOOL_MANAGED, &_d3d_texture);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "D3D create_texture failed!" << D3DERRORSTRING(hr);
-    goto error_exit;
-  }
+          b = (dwPixel & bluemask) << blueshift;
+          g = (dwPixel & greenmask) >> greenshift;
+          r = (dwPixel & redmask) >> redshift;
 
 
-  if (dxgsg8_cat.is_debug()) {
-    dxgsg8_cat.debug()
-      << "create_texture: " << _tex->get_name()
-      << " converting panda equivalent of " << D3DFormatStr(_d3d_format)
-      << " => " << D3DFormatStr(TargetPixFmt) << endl;
-  }
+          // alpha is just set to 0xFF
 
 
-  hr = fill_d3d_texture_pixels();
-  if (FAILED(hr)) {
-    goto error_exit;
-  }
+          *pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b;
+        }
+      }
+    } else {
+      // 24bpp texture case (numComponents == 3)
+      for(DWORD y = 0; y<dwCopyHeight; y++, pSurfBytes -= BytePitch) {
+        pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
+        for(DWORD x = 0; x<dwCopyWidth; x++, pSrcWord++) {
+          WORD dwPixel = *pSrcWord;
+          BYTE r, g, b;
 
 
-  // PRINT_REFCNT(dxgsg8, scrn.pD3D8);
+          b = (dwPixel & bluemask) << blueshift;
+          g = (dwPixel & greenmask) >> greenshift;
+          r = (dwPixel & redmask) >> redshift;
 
 
-  // Return the newly created texture
-  return _d3d_texture;
+          *pDstByte += b;
+          *pDstByte += g;
+          *pDstByte += r;
+        }
+      }
+    }
+    break;
+  }
 
 
- error_exit:
+  default:
+    dxgsg8_cat.error() << "d3d_surface_to_texture: unsupported D3DFORMAT!\n";
+  }
 
 
-  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
-  return NULL;
+  d3d_surface->UnlockRect();
+  return S_OK;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::fill_d3d_texture_pixels
+//       Access: Private
+//  Description: 
+////////////////////////////////////////////////////////////////////
 HRESULT DXTextureContext8::
 HRESULT DXTextureContext8::
 fill_d3d_texture_pixels() {
 fill_d3d_texture_pixels() {
   HRESULT hr = E_FAIL;
   HRESULT hr = E_FAIL;
@@ -945,55 +958,6 @@ fill_d3d_texture_pixels() {
   return hr;
   return hr;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-// Name: delete_texture()
-// Desc: Release the surface used to store the texture
-//-----------------------------------------------------------------------------
-void DXTextureContext8::
-delete_texture( ) {
-  if (_d3d_texture == NULL) {
-    // dont bother printing the msg below, since we already released it.
-    return;
-  }
-
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam() << "Deleting DX texture for " << _tex->get_name() << "\n";
-  }
-
-  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXTextureContext8::
-DXTextureContext8(Texture *tex) :
-  TextureContext(tex) {
-
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam() 
-      << "Creating DX texture [" << tex->get_name() << "], minfilter(" << tex->get_minfilter() << "), magfilter(" << tex->get_magfilter() << "), anisodeg(" << tex->get_anisotropic_degree() << ")\n";
-  }
-
-  _d3d_texture = NULL;
-  _has_mipmaps = false;
-  _tex = tex;
-}
-
-DXTextureContext8::
-~DXTextureContext8() {
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam()
-      << "Deleting DX8 TexContext for " << _tex->get_name() << "\n";
-  }
-  delete_texture();
-  TextureContext::~TextureContext();
-  _tex = NULL;
-}
-
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXTextureContext8::down_to_power_2
 //     Function: DXTextureContext8::down_to_power_2
@@ -1009,3 +973,59 @@ down_to_power_2(int value) {
   }
   }
   return x;
   return x;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXTextureContext8::get_bits_per_pixel
+//       Access: Private
+//  Description: Maps from the Texture's Format symbols to bpp.
+//               Returns # of alpha bits.  Note: Texture's format
+//               indicates REQUESTED final format, not the stored
+//               format, which is indicated by pixelbuffer type
+////////////////////////////////////////////////////////////////////
+unsigned int DXTextureContext8::
+get_bits_per_pixel(Texture::Format format, int *alphbits) {
+  *alphbits = 0;      // assume no alpha bits
+  switch(format) {
+  case Texture::F_alpha:
+    *alphbits = 8;
+  case Texture::F_color_index:
+  case Texture::F_red:
+  case Texture::F_green:
+  case Texture::F_blue:
+  case Texture::F_rgb332:
+    return 8;
+  case Texture::F_luminance_alphamask:
+    *alphbits = 1;
+    return 16;
+  case Texture::F_luminance_alpha:
+    *alphbits = 8;
+    return 16;
+  case Texture::F_luminance:
+    return 8;
+  case Texture::F_rgba4:
+    *alphbits = 4;
+    return 16;
+  case Texture::F_rgba5:
+    *alphbits = 1;
+    return 16;
+  case Texture::F_depth_component:
+  case Texture::F_rgb5:
+    return 16;
+  case Texture::F_rgb8:
+  case Texture::F_rgb:
+    return 24;
+  case Texture::F_rgba8:
+  case Texture::F_rgba:
+  case Texture::F_rgbm:
+    if (format == Texture::F_rgbm)   // does this make any sense?
+      *alphbits = 1;
+    else *alphbits = 8;
+    return 32;
+  case Texture::F_rgb12:
+    return 36;
+  case Texture::F_rgba12:
+    *alphbits = 12;
+    return 48;
+  }
+  return 8;
+}

+ 5 - 9
panda/src/dxgsg8/dxTextureContext8.h

@@ -24,13 +24,13 @@
 #include "textureContext.h"
 #include "textureContext.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//   Class : DXTextureContext8
+//       Class : DXTextureContext8
 // Description :
 // Description :
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDADX DXTextureContext8 : public TextureContext {
 class EXPCL_PANDADX DXTextureContext8 : public TextureContext {
 public:
 public:
   DXTextureContext8(Texture *tex);
   DXTextureContext8(Texture *tex);
-  ~DXTextureContext8();
+  virtual ~DXTextureContext8();
 
 
   IDirect3DTexture8 *create_texture(DXScreenData &scrn);
   IDirect3DTexture8 *create_texture(DXScreenData &scrn);
   void delete_texture();
   void delete_texture();
@@ -38,9 +38,12 @@ public:
   INLINE bool has_mipmaps() const;
   INLINE bool has_mipmaps() const;
   INLINE IDirect3DTexture8 *get_d3d_texture() const;
   INLINE IDirect3DTexture8 *get_d3d_texture() const;
 
 
+  static HRESULT d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface, Texture *result);
+
 private:
 private:
   HRESULT fill_d3d_texture_pixels();
   HRESULT fill_d3d_texture_pixels();
   static int down_to_power_2(int value);
   static int down_to_power_2(int value);
+  unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
 
 
 private:
 private:
   Texture *_tex;            // ptr to parent, primarily for access to namestr
   Texture *_tex;            // ptr to parent, primarily for access to namestr
@@ -49,9 +52,6 @@ private:
 
 
   bool _has_mipmaps;
   bool _has_mipmaps;
 
 
-protected:
-  unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
-
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
     return _type_handle;
     return _type_handle;
@@ -70,10 +70,6 @@ private:
   static TypeHandle _type_handle;
   static TypeHandle _type_handle;
 };
 };
 
 
-HRESULT 
-d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface, 
-                       Texture *result);
-
 #include "dxTextureContext8.I"
 #include "dxTextureContext8.I"
 
 
 #endif
 #endif

+ 156 - 154
panda/src/dxgsg8/wdxGraphicsWindow8.cxx

@@ -33,9 +33,6 @@
 
 
 TypeHandle wdxGraphicsWindow8::_type_handle;
 TypeHandle wdxGraphicsWindow8::_type_handle;
 
 
-#define JOYSTICK_POLL_TIMER_ID 8
-#define DX_IS_READY ((_dxgsg != NULL)&&(_dxgsg->GetDXReady()))
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::Constructor
 //     Function: wdxGraphicsWindow8::Constructor
 //       Access: Public
 //       Access: Public
@@ -66,6 +63,11 @@ wdxGraphicsWindow8::
 ~wdxGraphicsWindow8() {
 ~wdxGraphicsWindow8() {
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow8::make_current
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
 void wdxGraphicsWindow8::
 void wdxGraphicsWindow8::
 make_current() {
 make_current() {
   PStatTimer timer(_make_current_pcollector);
   PStatTimer timer(_make_current_pcollector);
@@ -87,6 +89,52 @@ make_current() {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow8::begin_frame
+//       Access: Public, Virtual
+//  Description: This function will be called within the draw thread
+//               before beginning rendering for a given frame.  It
+//               should do whatever setup is required, and return true
+//               if the frame should be rendered, or false if it
+//               should be skipped.
+////////////////////////////////////////////////////////////////////
+bool wdxGraphicsWindow8::
+begin_frame() {
+  if (_awaiting_restore) {
+    // The fullscreen window was recently restored; we can't continue
+    // until the GSG says we can.
+    if (!_dxgsg->check_cooperative_level()) {
+      // Keep waiting.
+      return false;
+    }
+    _awaiting_restore = false;
+
+    init_resized_window();
+  }
+
+  bool return_val = WinGraphicsWindow::begin_frame();
+  _dxgsg->set_render_target();
+  return return_val;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow8::end_flip
+//       Access: Public, Virtual
+//  Description: This function will be called within the draw thread
+//               after begin_flip() has been called on all windows, to
+//               finish the exchange of the front and back buffers.
+//
+//               This should cause the window to wait for the flip, if
+//               necessary.
+////////////////////////////////////////////////////////////////////
+void wdxGraphicsWindow8::
+end_flip() {
+  if (_dxgsg != (DXGraphicsStateGuardian8 *)NULL && is_active()) {
+    _dxgsg->show_frame();
+  }
+  GraphicsWindow::end_flip();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::verify_window_sizes
 //     Function: wdxGraphicsWindow8::verify_window_sizes
 //       Access: Public, Virtual
 //       Access: Public, Virtual
@@ -159,50 +207,123 @@ verify_window_sizes(int numsizes, int *dimen) {
   return num_valid_modes;
   return num_valid_modes;
 }
 }
 
 
+//////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow::close_window
+//       Access: Public
+//  Description: Some cleanup is necessary for directx closeup of window.
+//               Handle close window events for this particular
+//               window.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::begin_frame
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               before beginning rendering for a given frame.  It
-//               should do whatever setup is required, and return true
-//               if the frame should be rendered, or false if it
-//               should be skipped.
+void wdxGraphicsWindow8::
+close_window() {
+  wdxdisplay8_cat.debug() << "wdx closed window\n";
+  _dxgsg->release_swap_chain(&_wcontext);
+  WinGraphicsWindow::close_window();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow8::open_window
+//       Access: Protected, Virtual
+//  Description: Opens the window right now.  Called from the window
+//               thread.  Returns true if the window is successfully
+//               opened, or false if there was a problem.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsWindow8::
 bool wdxGraphicsWindow8::
-begin_frame() {
-  if (_awaiting_restore) {
-    // The fullscreen window was recently restored; we can't continue
-    // until the GSG says we can.
-    if (!_dxgsg->check_cooperative_level()) {
-      // Keep waiting.
-      return false;
-    }
-    _awaiting_restore = false;
+open_window() {
+  PT(DXGraphicsDevice8) dxdev;
+  DXGraphicsStateGuardian8 *dxgsg;
+  DCAST_INTO_R(dxgsg, _gsg, false);
+  WindowProperties props;
+  bool discard_device = false;
 
 
-    init_resized_window();
+  if (!choose_device()) {
+    return false;
   }
   }
 
 
-  bool return_val = WinGraphicsWindow::begin_frame();
-  _dxgsg->set_render_target();
-  return return_val;
+  wdxdisplay8_cat.debug() << "_wcontext.hWnd is " << _wcontext.hWnd << "\n";
+  if (!WinGraphicsWindow::open_window()) {
+    return false;
+  }
+  _wcontext.hWnd = _hWnd;
+
+  wdxdisplay8_cat.debug() << "_wcontext.hWnd is " << _wcontext.hWnd << "\n";
+
+  // Here check if a device already exists. If so, then this open_window
+  // call may be an extension to create multiple windows on same device
+  // In that case just create an additional swapchain for this window
+
+  while (true) {
+    if (dxgsg->get_pipe()->get_device() == NULL || discard_device) {
+      wdxdisplay8_cat.debug() << "device is null or fullscreen\n";
+
+      // If device exists, free it
+      if (dxgsg->get_pipe()->get_device()) {
+        dxgsg->dx_cleanup();
+      }
+
+      wdxdisplay8_cat.debug() << "device width " << _wcontext.DisplayMode.Width << "\n";
+      if (!create_screen_buffers_and_device(_wcontext, dx_force_16bpp_zbuffer)) {
+        // just crash here
+        wdxdisplay8_cat.error() << "fatal: must be trying to create two fullscreen windows: not supported\n";
+        return false;
+      }
+      dxgsg->get_pipe()->make_device((void*)(&_wcontext));
+      dxgsg->copy_pres_reset(&_wcontext);
+      dxgsg->create_swap_chain(&_wcontext);
+      break;
+
+    } else {
+      // fill in the DXScreenData from dxdevice here and change the
+      // reference to hWnd.
+      wdxdisplay8_cat.debug() << "device is not null\n";
+
+      dxdev = (DXGraphicsDevice8*)dxgsg->get_pipe()->get_device();
+      props = get_properties();
+      memcpy(&_wcontext, &dxdev->_Scrn, sizeof(DXScreenData));
+
+      _wcontext.PresParams.Windowed = !is_fullscreen();
+      _wcontext.PresParams.hDeviceWindow = _wcontext.hWnd = _hWnd;
+      _wcontext.PresParams.BackBufferWidth = _wcontext.DisplayMode.Width = props.get_x_size();
+      _wcontext.PresParams.BackBufferHeight = _wcontext.DisplayMode.Height = props.get_y_size();
+
+      wdxdisplay8_cat.debug() << "device width " << _wcontext.PresParams.BackBufferWidth << "\n";
+      if (!dxgsg->create_swap_chain(&_wcontext)) {
+        discard_device = true;
+        continue; // try again
+      }
+      init_resized_window();
+      break;
+    }
+  }
+  wdxdisplay8_cat.debug() << "swapchain is " << _wcontext.pSwapChain << "\n";
+  return true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::end_flip
+//     Function: wdxGraphicsWindow8::reset_window
 //       Access: Public, Virtual
 //       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               after begin_flip() has been called on all windows, to
-//               finish the exchange of the front and back buffers.
-//
-//               This should cause the window to wait for the flip, if
-//               necessary.
+//  Description: Resets the window framebuffer right now.  Called
+//               from graphicsEngine. It releases the current swap
+//               chain / creates a new one. If this is the initial
+//               window and swapchain is false, then it calls reset_
+//               main_device to Reset the device.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void wdxGraphicsWindow8::
 void wdxGraphicsWindow8::
-end_flip() {
-  if (_dxgsg != (DXGraphicsStateGuardian8 *)NULL && is_active()) {
-    _dxgsg->show_frame();
+reset_window(bool swapchain) {
+  DXGraphicsStateGuardian8 *dxgsg;
+  DCAST_INTO_V(dxgsg, _gsg);
+  if (swapchain) {
+    if (_wcontext.pSwapChain) {
+      dxgsg->create_swap_chain(&_wcontext);
+      wdxdisplay8_cat.debug() << "created swapchain " << _wcontext.pSwapChain << "\n";
+    }
+  }
+  else {
+    if (_wcontext.pSwapChain) {
+      dxgsg->release_swap_chain(&_wcontext);
+      wdxdisplay8_cat.debug() << "released swapchain " << _wcontext.pSwapChain << "\n";
+    }
   }
   }
-  GraphicsWindow::end_flip();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -335,20 +456,6 @@ do_fullscreen_resize(int x_size, int y_size) {
   return bResizeSucceeded;
   return bResizeSucceeded;
 }
 }
 
 
-//////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow::close_window
-//       Access: Public
-//  Description: Some cleanup is necessary for directx closeup of window.
-//               Handle close window events for this particular
-//               window.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-close_window() {
-  wdxdisplay8_cat.debug() << "wdx closed window\n";
-  _dxgsg->release_swap_chain(&_wcontext);
-  WinGraphicsWindow::close_window();
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::create_screen_buffers_and_device
 //     Function: wdxGraphicsWindow8::create_screen_buffers_and_device
 //       Access: Private
 //       Access: Private
@@ -1052,6 +1159,7 @@ reset_device_resize_window(UINT new_xsize, UINT new_ysize) {
   init_resized_window();
   init_resized_window();
   return bRetval;
   return bRetval;
 }
 }
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::init_resized_window
 //     Function: wdxGraphicsWindow8::init_resized_window
 //       Access: Private
 //       Access: Private
@@ -1153,109 +1261,3 @@ is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID) {
 
 
   return false;
   return false;
 }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::reset_window
-//       Access: Public, Virtual
-//  Description: Resets the window framebuffer right now.  Called
-//               from graphicsEngine. It releases the current swap
-//               chain / creates a new one. If this is the initial
-//               window and swapchain is false, then it calls reset_
-//               main_device to Reset the device.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-reset_window(bool swapchain) {
-  DXGraphicsStateGuardian8 *dxgsg;
-  DCAST_INTO_V(dxgsg, _gsg);
-  if (swapchain) {
-    if (_wcontext.pSwapChain) {
-      dxgsg->create_swap_chain(&_wcontext);
-      wdxdisplay8_cat.debug() << "created swapchain " << _wcontext.pSwapChain << "\n";
-    }
-  }
-  else {
-    if (_wcontext.pSwapChain) {
-      dxgsg->release_swap_chain(&_wcontext);
-      wdxdisplay8_cat.debug() << "released swapchain " << _wcontext.pSwapChain << "\n";
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::open_window
-//       Access: Protected, Virtual
-//  Description: Opens the window right now.  Called from the window
-//               thread.  Returns true if the window is successfully
-//               opened, or false if there was a problem.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-open_window() {
-  PT(DXGraphicsDevice8) dxdev;
-  DXGraphicsStateGuardian8 *dxgsg;
-  DCAST_INTO_R(dxgsg, _gsg, false);
-  WindowProperties props;
-  bool discard_device = false;
-
-  if (!choose_device()) {
-    return false;
-  }
-
-  wdxdisplay8_cat.debug() << "_wcontext.hWnd is " << _wcontext.hWnd << "\n";
-  if (!WinGraphicsWindow::open_window()) {
-    return false;
-  }
-  _wcontext.hWnd = _hWnd;
-
-  wdxdisplay8_cat.debug() << "_wcontext.hWnd is " << _wcontext.hWnd << "\n";
-
-  // Here check if a device already exists. If so, then this open_window
-  // call may be an extension to create multiple windows on same device
-  // In that case just create an additional swapchain for this window
-
-  while (true) {
-    if (dxgsg->get_pipe()->get_device() == NULL || discard_device) {
-      wdxdisplay8_cat.debug() << "device is null or fullscreen\n";
-
-      // If device exists, free it
-      if (dxgsg->get_pipe()->get_device()) {
-        dxgsg->dx_cleanup();
-      }
-
-      wdxdisplay8_cat.debug() << "device width " << _wcontext.DisplayMode.Width << "\n";
-      if (!create_screen_buffers_and_device(_wcontext, dx_force_16bpp_zbuffer)) {
-        // just crash here
-        wdxdisplay8_cat.error() << "fatal: must be trying to create two fullscreen windows: not supported\n";
-        return false;
-      }
-      dxgsg->get_pipe()->make_device((void*)(&_wcontext));
-      dxgsg->copy_pres_reset(&_wcontext);
-      dxgsg->create_swap_chain(&_wcontext);
-      break;
-
-    } else {
-      // fill in the DXScreenData from dxdevice here and change the
-      // reference to hWnd.
-      wdxdisplay8_cat.debug() << "device is not null\n";
-
-      dxdev = (DXGraphicsDevice8*)dxgsg->get_pipe()->get_device();
-      props = get_properties();
-      memcpy(&_wcontext, &dxdev->_Scrn, sizeof(DXScreenData));
-
-      _wcontext.PresParams.Windowed = !is_fullscreen();
-      _wcontext.PresParams.hDeviceWindow = _wcontext.hWnd = _hWnd;
-      _wcontext.PresParams.BackBufferWidth = _wcontext.DisplayMode.Width = props.get_x_size();
-      _wcontext.PresParams.BackBufferHeight = _wcontext.DisplayMode.Height = props.get_y_size();
-
-      wdxdisplay8_cat.debug() << "device width " << _wcontext.PresParams.BackBufferWidth << "\n";
-      if (!dxgsg->create_swap_chain(&_wcontext)) {
-        discard_device = true;
-        continue; // try again
-      }
-      init_resized_window();
-      break;
-    }
-  }
-  wdxdisplay8_cat.debug() << "swapchain is " << _wcontext.pSwapChain << "\n";
-  return true;
-}
-

+ 7 - 5
panda/src/dxgsg8/wdxGraphicsWindow8.h

@@ -37,16 +37,19 @@ public:
   wdxGraphicsWindow8(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
   wdxGraphicsWindow8(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
                      const string &name);
                      const string &name);
   virtual ~wdxGraphicsWindow8();
   virtual ~wdxGraphicsWindow8();
-  virtual bool open_window();
-  virtual void close_window();
-  virtual void reset_window(bool swapchain);
 
 
-  virtual int verify_window_sizes(int numsizes, int *dimen);
+  virtual void make_current();
 
 
   virtual bool begin_frame();
   virtual bool begin_frame();
   virtual void end_flip();
   virtual void end_flip();
 
 
+  virtual int verify_window_sizes(int numsizes, int *dimen);
+
 protected:
 protected:
+  virtual void close_window();
+  virtual bool open_window();
+  virtual void reset_window(bool swapchain);
+
   virtual void fullscreen_restored(WindowProperties &properties);
   virtual void fullscreen_restored(WindowProperties &properties);
   virtual void handle_reshape();
   virtual void handle_reshape();
   virtual bool do_fullscreen_resize(int x_size, int y_size);
   virtual bool do_fullscreen_resize(int x_size, int y_size);
@@ -72,7 +75,6 @@ private:
   void init_resized_window();
   void init_resized_window();
   static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
   static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
   static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
   static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
-  virtual void make_current();
 
 
   DXGraphicsStateGuardian8 *_dxgsg;
   DXGraphicsStateGuardian8 *_dxgsg;
   DXScreenData _wcontext;
   DXScreenData _wcontext;