Browse Source

Delete DirectX 8 support

rdb 11 years ago
parent
commit
624b3dad14
58 changed files with 77 additions and 12601 deletions
  1. 1 2
      direct/src/p3d/panda3d.pdef
  2. 2 5
      doc/Config.pp.sample
  3. 0 1
      doc/INSTALL-MK
  4. 3 8
      doc/INSTALL-PP
  5. 0 1
      dtool/Config.Android.pp
  6. 0 12
      dtool/Config.pp
  7. 0 16
      dtool/LocalSetup.pp
  8. 0 10
      dtool/Package.pp
  9. 0 14
      dtool/pptempl/Global.pp
  10. 0 1
      makepanda/config.in
  11. 0 22
      makepanda/makepanda.py
  12. 0 1
      makepanda/makepanda.vcproj
  13. 4 17
      makepanda/makepandacore.py
  14. 0 24
      panda/metalibs/pandadx8/Sources.pp
  15. 0 38
      panda/metalibs/pandadx8/pandadx8.cxx
  16. 0 14
      panda/metalibs/pandadx8/pandadx8.h
  17. 0 3
      panda/src/configfiles/panda.prc.pp
  18. 0 42
      panda/src/dxgsg8/Sources.pp
  19. 0 155
      panda/src/dxgsg8/config_dxgsg8.cxx
  20. 0 60
      panda/src/dxgsg8/config_dxgsg8.h
  21. 0 40
      panda/src/dxgsg8/dxGeomMunger8.I
  22. 0 322
      panda/src/dxgsg8/dxGeomMunger8.cxx
  23. 0 82
      panda/src/dxgsg8/dxGeomMunger8.h
  24. 0 42
      panda/src/dxgsg8/dxGraphicsDevice8.cxx
  25. 0 51
      panda/src/dxgsg8/dxGraphicsDevice8.h
  26. 0 159
      panda/src/dxgsg8/dxGraphicsStateGuardian8.I
  27. 0 4674
      panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx
  28. 0 309
      panda/src/dxgsg8/dxGraphicsStateGuardian8.h
  29. 0 14
      panda/src/dxgsg8/dxIndexBufferContext8.I
  30. 0 173
      panda/src/dxgsg8/dxIndexBufferContext8.cxx
  31. 0 62
      panda/src/dxgsg8/dxIndexBufferContext8.h
  32. 0 272
      panda/src/dxgsg8/dxInput8.cxx
  33. 0 41
      panda/src/dxgsg8/dxInput8.h
  34. 0 69
      panda/src/dxgsg8/dxTextureContext8.I
  35. 0 1853
      panda/src/dxgsg8/dxTextureContext8.cxx
  36. 0 89
      panda/src/dxgsg8/dxTextureContext8.h
  37. 0 14
      panda/src/dxgsg8/dxVertexBufferContext8.I
  38. 0 299
      panda/src/dxgsg8/dxVertexBufferContext8.cxx
  39. 0 63
      panda/src/dxgsg8/dxVertexBufferContext8.h
  40. 0 208
      panda/src/dxgsg8/dxgsg8base.h
  41. 0 10
      panda/src/dxgsg8/p3dxgsg8_composite1.cxx
  42. 0 27
      panda/src/dxgsg8/wdxGraphicsBuffer8.I
  43. 0 575
      panda/src/dxgsg8/wdxGraphicsBuffer8.cxx
  44. 0 99
      panda/src/dxgsg8/wdxGraphicsBuffer8.h
  45. 0 13
      panda/src/dxgsg8/wdxGraphicsPipe8.I
  46. 0 931
      panda/src/dxgsg8/wdxGraphicsPipe8.cxx
  47. 0 122
      panda/src/dxgsg8/wdxGraphicsPipe8.h
  48. 0 13
      panda/src/dxgsg8/wdxGraphicsWindow8.I
  49. 0 1241
      panda/src/dxgsg8/wdxGraphicsWindow8.cxx
  50. 0 108
      panda/src/dxgsg8/wdxGraphicsWindow8.h
  51. 0 2
      panda/src/framework/Sources.pp
  52. 21 24
      panda/src/framework/pandaFramework.cxx
  53. 3 3
      panda/src/windisplay/Sources.pp
  54. 29 76
      panda/src/windisplay/winDetectDx.h
  55. 0 48
      panda/src/windisplay/winDetectDx8.cxx
  56. 0 1
      panda/src/windisplay/winDetectDx9.cxx
  57. 14 25
      panda/src/windisplay/winGraphicsPipe.cxx
  58. 0 1
      pandatool/src/scripts/builder.cshrc

+ 1 - 2
direct/src/p3d/panda3d.pdef

@@ -96,7 +96,7 @@ class panda3d(package):
     # platform-specific extension for an executable.
     # platform-specific extension for an executable.
     file('libpandagl.dll', 'libp3tinydisplay.dll')
     file('libpandagl.dll', 'libp3tinydisplay.dll')
     if platform.startswith('win'):
     if platform.startswith('win'):
-        file('libpandadx8.dll', 'libpandadx9.dll')
+        file('libpandadx9.dll')
 
 
     # A basic config file is needed to lay some some fundamental runtime
     # A basic config file is needed to lay some some fundamental runtime
     # variables.
     # variables.
@@ -104,7 +104,6 @@ class panda3d(package):
         auxDisplays = """
         auxDisplays = """
 aux-display pandagl
 aux-display pandagl
 aux-display pandadx9
 aux-display pandadx9
-aux-display pandadx8
 aux-display p3tinydisplay
 aux-display p3tinydisplay
 """
 """
     else:
     else:

+ 2 - 5
doc/Config.pp.sample

@@ -32,13 +32,10 @@
 
 
 // Note the use of the Panda filename convention, with forward slashes
 // Note the use of the Panda filename convention, with forward slashes
 // instead of backslashes, and /c/ instead of c:/ .
 // instead of backslashes, and /c/ instead of c:/ .
-#define DX8_IPATH /c/DXSDK-OCT2004/include
-#define DX8_LPATH /c/DXSDK-OCT2004/lib
 #define DX9_IPATH /c/DXSDK-DEC2006/include
 #define DX9_IPATH /c/DXSDK-DEC2006/include
 #define DX9_LPATH /c/DXSDK-DEC2006/lib
 #define DX9_LPATH /c/DXSDK-DEC2006/lib
 
 
-// If for any reason you need to turn off either the DX8 or DX9 builds,
-// you can uncomment one of the following lines.  (Defining a
+// If for any reason you need to turn off the DX9 builds,
+// you can uncomment the following line.  (Defining a
 // variable to an empty string means setting it false.)
 // variable to an empty string means setting it false.)
-//#define HAVE_DX8
 //#define HAVE_DX9
 //#define HAVE_DX9

+ 0 - 1
doc/INSTALL-MK

@@ -141,7 +141,6 @@ it will show you the available command-line options:
   --use-max9        --no-max9      (enable/disable use of MAX9)
   --use-max9        --no-max9      (enable/disable use of MAX9)
   --use-max2009     --no-max2009   (enable/disable use of MAX2009)
   --use-max2009     --no-max2009   (enable/disable use of MAX2009)
   --use-max2010     --no-max2010   (enable/disable use of MAX2010)
   --use-max2010     --no-max2010   (enable/disable use of MAX2010)
-  --use-dx8         --no-dx8       (enable/disable use of DX8)
   --use-dx9         --no-dx9       (enable/disable use of DX9)
   --use-dx9         --no-dx9       (enable/disable use of DX9)
   --use-python      --no-python    (enable/disable use of PYTHON)
   --use-python      --no-python    (enable/disable use of PYTHON)
   --use-zlib        --no-zlib      (enable/disable use of ZLIB)
   --use-zlib        --no-zlib      (enable/disable use of ZLIB)

+ 3 - 8
doc/INSTALL-PP

@@ -251,13 +251,13 @@ indicate a variable is true by defining it to some nonempty string
 (e.g. "yes" or "1"), and false by defining it to nothing.  For
 (e.g. "yes" or "1"), and false by defining it to nothing.  For
 example:
 example:
 
 
-  #define HAVE_DX8 1
+  #define HAVE_DX9 1
 
 
 Indicates you have the DirectX SDK installed, while
 Indicates you have the DirectX SDK installed, while
 
 
-  #define HAVE_DX8
+  #define HAVE_DX9
 
 
-Indicates you do not.  Do not be tempted to define HAVE_DX8 to no or 0;
+Indicates you do not.  Do not be tempted to define HAVE_DX9 to no or 0;
 since these are both nonempty strings, they are considered to
 since these are both nonempty strings, they are considered to
 represent true!  Also, don't try to use a pair of quotation marks to
 represent true!  Also, don't try to use a pair of quotation marks to
 represent the empty string, since the quotation marks become part of
 represent the empty string, since the quotation marks become part of
@@ -312,11 +312,6 @@ find useful are:
     header and library files, and the name of the VRPN libraries, if
     header and library files, and the name of the VRPN libraries, if
     VRPN is installed on your system.
     VRPN is installed on your system.
 
 
-  DX8_IPATH / DX8_LPATH / DX8_LIBS - the full pathname to the
-    DirectX 8.1 SDK header and library files, if you have installed
-    this SDK. (You must currently install this SDK in order to
-    build DirectX8 support for Panda.)
-
   DX9_IPATH / DX9_LPATH / DX9_LIBS - the full pathname to the
   DX9_IPATH / DX9_LPATH / DX9_LIBS - the full pathname to the
     DirectX 9 SDK header and library files, if you have installed
     DirectX 9 SDK header and library files, if you have installed
     this SDK. (You must currently install this SDK in order to
     this SDK. (You must currently install this SDK in order to

+ 0 - 1
dtool/Config.Android.pp

@@ -45,7 +45,6 @@
 
 
 // We don't have these, of course, so let's disable
 // We don't have these, of course, so let's disable
 // them for convenience in case they were autodetected.
 // them for convenience in case they were autodetected.
-#define HAVE_DX8
 #define HAVE_DX9
 #define HAVE_DX9
 #define HAVE_CG
 #define HAVE_CG
 
 

+ 0 - 12
dtool/Config.pp

@@ -588,12 +588,6 @@
 #define CGGL_LIBS $[if $[WINDOWS_PLATFORM],cgGL.lib,CgGL]
 #define CGGL_LIBS $[if $[WINDOWS_PLATFORM],cgGL.lib,CgGL]
 #defer HAVE_CGGL $[or $[CGGL_FRAMEWORK],$[and $[HAVE_CG],$[libtest $[CGGL_LPATH],$[CGGL_LIBS]]]]
 #defer HAVE_CGGL $[or $[CGGL_FRAMEWORK],$[and $[HAVE_CG],$[libtest $[CGGL_LPATH],$[CGGL_LIBS]]]]
 
 
-// Is CgDX8 installed, and where?
-#defer CGDX8_IPATH $[CG_IPATH]
-#defer CGDX8_LPATH $[CG_LPATH]
-#define CGDX8_LIBS $[if $[WINDOWS_PLATFORM],cgD3D8.lib,CgDX8]
-#defer HAVE_CGDX8 $[and $[HAVE_CG],$[libtest $[CGDX8_LPATH],$[CGDX8_LIBS]]]
-
 // Is CgDX9 installed, and where?
 // Is CgDX9 installed, and where?
 #defer CGDX9_IPATH $[CG_IPATH]
 #defer CGDX9_IPATH $[CG_IPATH]
 #defer CGDX9_LPATH $[CG_LPATH]
 #defer CGDX9_LPATH $[CG_LPATH]
@@ -740,12 +734,6 @@
 #define HAVE_COCOA
 #define HAVE_COCOA
 #define HAVE_CARBON
 #define HAVE_CARBON
 
 
-// Is DirectX8 available, and should we try to build with it?
-#define DX8_IPATH
-#define DX8_LPATH
-#define DX8_LIBS d3d8.lib d3dx8.lib dxerr8.lib
-#defer HAVE_DX8 $[libtest $[DX8_LPATH],$[DX8_LIBS]]
-
 // Is DirectX9 available, and should we try to build with it?
 // Is DirectX9 available, and should we try to build with it?
 #define DX9_IPATH
 #define DX9_IPATH
 #define DX9_LPATH
 #define DX9_LPATH

+ 0 - 16
dtool/LocalSetup.pp

@@ -66,11 +66,6 @@
 #else
 #else
 #print - Did not find Cg OpenGL API
 #print - Did not find Cg OpenGL API
 #endif
 #endif
-#if $[HAVE_CGDX8]
-#print + Cg DX8 API
-#else
-#print - Did not find Cg DX8 API
-#endif
 #if $[HAVE_CGDX9]
 #if $[HAVE_CGDX9]
 #print + Cg DX9 API
 #print + Cg DX9 API
 #else
 #else
@@ -151,11 +146,6 @@
 #else
 #else
 #print - Did not find OpenGL ES 2
 #print - Did not find OpenGL ES 2
 #endif
 #endif
-#if $[HAVE_DX8]
-#print + DirectX8
-#else
-#print - Did not find DirectX8
-#endif
 #if $[HAVE_DX9]
 #if $[HAVE_DX9]
 #print + DirectX9
 #print + DirectX9
 #else
 #else
@@ -389,9 +379,6 @@ $[cdefine HAVE_CG]
 /* Define if we have CGGL installed.  */
 /* Define if we have CGGL installed.  */
 $[cdefine HAVE_CGGL]
 $[cdefine HAVE_CGGL]
 
 
-/* Define if we have CGDX8 installed.  */
-$[cdefine HAVE_CGDX8]
-
 /* Define if we have CGDX9 installed.  */
 /* Define if we have CGDX9 installed.  */
 $[cdefine HAVE_CGDX9]
 $[cdefine HAVE_CGDX9]
 
 
@@ -441,9 +428,6 @@ $[cdefine HAVE_EGL]
 /* Define if we have Windows-GL installed and want to build for Wgl.  */
 /* Define if we have Windows-GL installed and want to build for Wgl.  */
 $[cdefine HAVE_WGL]
 $[cdefine HAVE_WGL]
 
 
-/* Define if we have DirectX installed and want to build for DX.  */
-$[cdefine HAVE_DX8]
-
 /* Define if we have DirectX installed and want to build for DX.  */
 /* Define if we have DirectX installed and want to build for DX.  */
 $[cdefine HAVE_DX9]
 $[cdefine HAVE_DX9]
 
 

+ 0 - 10
dtool/Package.pp

@@ -191,11 +191,6 @@
 #set CGGL_LIBS $[CGGL_LIBS]
 #set CGGL_LIBS $[CGGL_LIBS]
 #set HAVE_CGGL $[HAVE_CGGL]
 #set HAVE_CGGL $[HAVE_CGGL]
 
 
-#set CGDX8_IPATH $[unixfilename $[CGDX8_IPATH]]
-#set CGDX8_LPATH $[unixfilename $[CGDX8_LPATH]]
-#set CGDX8_LIBS $[CGDX8_LIBS]
-#set HAVE_CGDX8 $[HAVE_CGDX8]
-
 #set CGDX9_IPATH $[unixfilename $[CGDX9_IPATH]]
 #set CGDX9_IPATH $[unixfilename $[CGDX9_IPATH]]
 #set CGDX9_LPATH $[unixfilename $[CGDX9_LPATH]]
 #set CGDX9_LPATH $[unixfilename $[CGDX9_LPATH]]
 #set CGDX9_LIBS $[CGDX9_LIBS]
 #set CGDX9_LIBS $[CGDX9_LIBS]
@@ -250,11 +245,6 @@
 #set HAVE_COCOA $[HAVE_COCOA]
 #set HAVE_COCOA $[HAVE_COCOA]
 #set HAVE_CARBON $[HAVE_CARBON]
 #set HAVE_CARBON $[HAVE_CARBON]
 
 
-#set DX8_IPATH $[unixfilename $[DX8_IPATH]]
-#set DX8_LPATH $[unixfilename $[DX8_LPATH]]
-#set DX8_LIBS $[DX8_LIBS]
-#set HAVE_DX8 $[HAVE_DX8]
-
 #set DX9_IPATH $[unixfilename $[DX9_IPATH]]
 #set DX9_IPATH $[unixfilename $[DX9_IPATH]]
 #set DX9_LPATH $[unixfilename $[DX9_LPATH]]
 #set DX9_LPATH $[unixfilename $[DX9_LPATH]]
 #set DX9_LIBS $[DX9_LIBS]
 #set DX9_LIBS $[DX9_LIBS]

+ 0 - 14
dtool/pptempl/Global.pp

@@ -199,13 +199,6 @@
   #define egl_libs $[EGL_LIBS]
   #define egl_libs $[EGL_LIBS]
 #endif
 #endif
 
 
-#if $[HAVE_DX8]
-  #define dx8_ipath $[wildcard $[DX8_IPATH]]
-  #define dx8_lpath $[wildcard $[DX8_LPATH]]
-  #define dx8_cflags $[DX8_CFLAGS]
-  #define dx8_libs $[DX8_LIBS]
-#endif
-
 #if $[HAVE_DX9]
 #if $[HAVE_DX9]
   #define dx9_ipath $[wildcard $[DX9_IPATH]]
   #define dx9_ipath $[wildcard $[DX9_IPATH]]
   #define dx9_lpath $[wildcard $[DX9_LPATH]]
   #define dx9_lpath $[wildcard $[DX9_LPATH]]
@@ -329,13 +322,6 @@
   #define cggl_framework $[CGGL_FRAMEWORK]
   #define cggl_framework $[CGGL_FRAMEWORK]
 #endif
 #endif
 
 
-#if $[HAVE_CGDX8]
-  #define cgdx8_ipath $[wildcard $[CGDX8_IPATH]]
-  #define cgdx8_lpath $[wildcard $[CGDX8_LPATH]]
-  #define cgdx8_cflags $[CGDX8_CFLAGS]
-  #define cgdx8_libs $[CGDX8_LIBS]
-#endif
-
 #if $[HAVE_CGDX9]
 #if $[HAVE_CGDX9]
   #define cgdx9_ipath $[wildcard $[CGDX9_IPATH]]
   #define cgdx9_ipath $[wildcard $[CGDX9_IPATH]]
   #define cgdx9_lpath $[wildcard $[CGDX9_LPATH]]
   #define cgdx9_lpath $[wildcard $[CGDX9_LPATH]]

+ 0 - 1
makepanda/config.in

@@ -14,7 +14,6 @@
 
 
 load-display pandagl
 load-display pandagl
 #load-display pandadx9
 #load-display pandadx9
-#load-display pandadx8
 #load-display pandagles
 #load-display pandagles
 #load-display p3tinydisplay
 #load-display p3tinydisplay
 
 

+ 0 - 22
makepanda/makepanda.py

@@ -1933,7 +1933,6 @@ DTOOL_CONFIG=[
     ("HAVE_GLX",                       'UNDEF',                  '1'),
     ("HAVE_GLX",                       'UNDEF',                  '1'),
     ("HAVE_EGL",                       'UNDEF',                  'UNDEF'),
     ("HAVE_EGL",                       'UNDEF',                  'UNDEF'),
     ("HAVE_WGL",                       '1',                      'UNDEF'),
     ("HAVE_WGL",                       '1',                      'UNDEF'),
-    ("HAVE_DX8",                       'UNDEF',                  'UNDEF'),
     ("HAVE_DX9",                       'UNDEF',                  'UNDEF'),
     ("HAVE_DX9",                       'UNDEF',                  'UNDEF'),
     ("HAVE_CHROMIUM",                  'UNDEF',                  'UNDEF'),
     ("HAVE_CHROMIUM",                  'UNDEF',                  'UNDEF'),
     ("HAVE_THREADS",                   '1',                      '1'),
     ("HAVE_THREADS",                   '1',                      '1'),
@@ -2491,7 +2490,6 @@ if (GetTarget() == 'windows'):
     configprc = configprc.replace("$HOME/.panda3d", "$USER_APPDATA/Panda3D-%s" % MAJOR_VERSION)
     configprc = configprc.replace("$HOME/.panda3d", "$USER_APPDATA/Panda3D-%s" % MAJOR_VERSION)
 else:
 else:
     configprc = configprc.replace("aux-display pandadx9", "")
     configprc = configprc.replace("aux-display pandadx9", "")
-    configprc = configprc.replace("aux-display pandadx8", "")
 
 
 if (GetTarget() == 'darwin'):
 if (GetTarget() == 'darwin'):
     configprc = configprc.replace(".panda3d/cache", "Library/Caches/Panda3D-%s" % MAJOR_VERSION)
     configprc = configprc.replace(".panda3d/cache", "Library/Caches/Panda3D-%s" % MAJOR_VERSION)
@@ -2663,8 +2661,6 @@ CopyAllHeaders('panda/src/audiotraits')
 CopyAllHeaders('panda/src/distort')
 CopyAllHeaders('panda/src/distort')
 CopyAllHeaders('panda/src/downloadertools')
 CopyAllHeaders('panda/src/downloadertools')
 CopyAllHeaders('panda/src/windisplay')
 CopyAllHeaders('panda/src/windisplay')
-CopyAllHeaders('panda/src/dxgsg8')
-CopyAllHeaders('panda/metalibs/pandadx8')
 CopyAllHeaders('panda/src/dxgsg9')
 CopyAllHeaders('panda/src/dxgsg9')
 CopyAllHeaders('panda/metalibs/pandadx9')
 CopyAllHeaders('panda/metalibs/pandadx9')
 CopyAllHeaders('panda/src/egg')
 CopyAllHeaders('panda/src/egg')
@@ -3922,30 +3918,12 @@ if (PkgSkip("ZLIB")==0 and not RTDIST and not RUNTIME and PkgSkip("DEPLOYTOOLS")
 if (GetTarget() == 'windows' and not RUNTIME):
 if (GetTarget() == 'windows' and not RUNTIME):
   OPTS=['DIR:panda/src/windisplay', 'BUILDING:PANDAWIN']
   OPTS=['DIR:panda/src/windisplay', 'BUILDING:PANDAWIN']
   TargetAdd('p3windisplay_composite1.obj', opts=OPTS+["BIGOBJ"], input='p3windisplay_composite1.cxx')
   TargetAdd('p3windisplay_composite1.obj', opts=OPTS+["BIGOBJ"], input='p3windisplay_composite1.cxx')
-  TargetAdd('p3windisplay_windetectdx8.obj', opts=OPTS + ["DX8"], input='winDetectDx8.cxx')
   TargetAdd('p3windisplay_windetectdx9.obj', opts=OPTS + ["DX9"], input='winDetectDx9.cxx')
   TargetAdd('p3windisplay_windetectdx9.obj', opts=OPTS + ["DX9"], input='winDetectDx9.cxx')
   TargetAdd('libp3windisplay.dll', input='p3windisplay_composite1.obj')
   TargetAdd('libp3windisplay.dll', input='p3windisplay_composite1.obj')
-  TargetAdd('libp3windisplay.dll', input='p3windisplay_windetectdx8.obj')
   TargetAdd('libp3windisplay.dll', input='p3windisplay_windetectdx9.obj')
   TargetAdd('libp3windisplay.dll', input='p3windisplay_windetectdx9.obj')
   TargetAdd('libp3windisplay.dll', input=COMMON_PANDA_LIBS)
   TargetAdd('libp3windisplay.dll', input=COMMON_PANDA_LIBS)
   TargetAdd('libp3windisplay.dll', opts=['WINIMM', 'WINGDI', 'WINKERNEL', 'WINOLDNAMES', 'WINUSER', 'WINMM',"BIGOBJ"])
   TargetAdd('libp3windisplay.dll', opts=['WINIMM', 'WINGDI', 'WINKERNEL', 'WINOLDNAMES', 'WINUSER', 'WINMM',"BIGOBJ"])
 
 
-#
-# DIRECTORY: panda/metalibs/pandadx8/
-#
-
-if PkgSkip("DX8")==0 and not RUNTIME:
-  OPTS=['DIR:panda/src/dxgsg8', 'DIR:panda/metalibs/pandadx8', 'BUILDING:PANDADX', 'DX8']
-  TargetAdd('p3dxgsg8_dxGraphicsStateGuardian8.obj', opts=OPTS, input='dxGraphicsStateGuardian8.cxx')
-  TargetAdd('p3dxgsg8_composite1.obj', opts=OPTS, input='p3dxgsg8_composite1.cxx')
-  TargetAdd('pandadx8_pandadx8.obj', opts=OPTS, input='pandadx8.cxx')
-  TargetAdd('libpandadx8.dll', input='pandadx8_pandadx8.obj')
-  TargetAdd('libpandadx8.dll', input='p3dxgsg8_dxGraphicsStateGuardian8.obj')
-  TargetAdd('libpandadx8.dll', input='p3dxgsg8_composite1.obj')
-  TargetAdd('libpandadx8.dll', input='libp3windisplay.dll')
-  TargetAdd('libpandadx8.dll', input=COMMON_PANDA_LIBS)
-  TargetAdd('libpandadx8.dll', opts=['MODULE', 'ADVAPI', 'WINGDI', 'WINKERNEL', 'WINUSER', 'WINMM', 'DX8'])
-
 #
 #
 # DIRECTORY: panda/metalibs/pandadx9/
 # DIRECTORY: panda/metalibs/pandadx9/
 #
 #

+ 0 - 1
makepanda/makepanda.vcproj

@@ -2462,7 +2462,6 @@
 				<File RelativePath="..\panda\src\windisplay\winDetectDx9.cxx"></File>
 				<File RelativePath="..\panda\src\windisplay\winDetectDx9.cxx"></File>
 				<File RelativePath="..\panda\src\windisplay\config_windisplay.cxx"></File>
 				<File RelativePath="..\panda\src\windisplay\config_windisplay.cxx"></File>
 				<File RelativePath="..\panda\src\windisplay\winGraphicsPipe.h"></File>
 				<File RelativePath="..\panda\src\windisplay\winGraphicsPipe.h"></File>
-				<File RelativePath="..\panda\src\windisplay\winDetectDx8.cxx"></File>
 				<File RelativePath="..\panda\src\windisplay\winDetectDx.h"></File>
 				<File RelativePath="..\panda\src\windisplay\winDetectDx.h"></File>
 			</Filter>
 			</Filter>
 			<Filter Name="pgraph">
 			<Filter Name="pgraph">

+ 4 - 17
makepanda/makepandacore.py

@@ -93,7 +93,7 @@ MAXVERSIONINFO = [("MAX6", "SOFTWARE\\Autodesk\\3DSMAX\\6.0", "installdir", "max
 
 
 MAYAVERSIONS = []
 MAYAVERSIONS = []
 MAXVERSIONS = []
 MAXVERSIONS = []
-DXVERSIONS = ["DX8","DX9"]
+DXVERSIONS = ["DX9"]
 
 
 for (ver,key) in MAYAVERSIONINFO:
 for (ver,key) in MAYAVERSIONINFO:
     MAYAVERSIONS.append(ver)
     MAYAVERSIONS.append(ver)
@@ -1644,7 +1644,6 @@ def GetSdkDir(sdkname, sdkkey = None):
 def SdkLocateDirectX( strMode = 'default' ):
 def SdkLocateDirectX( strMode = 'default' ):
     if (GetHost() != "windows"): return
     if (GetHost() != "windows"): return
     if strMode == 'default':
     if strMode == 'default':
-        GetSdkDir("directx8", "DX8")
         GetSdkDir("directx9", "DX9")
         GetSdkDir("directx9", "DX9")
         if ("DX9" not in SDK):
         if ("DX9" not in SDK):
             strMode = 'latest'
             strMode = 'latest'
@@ -1681,18 +1680,12 @@ def SdkLocateDirectX( strMode = 'default' ):
                 print("Using DirectX SDK March 2009")
                 print("Using DirectX SDK March 2009")
                 SDK["DX9"] = dir.replace("\\", "/").rstrip("/")
                 SDK["DX9"] = dir.replace("\\", "/").rstrip("/")
         archStr = GetTargetArch()
         archStr = GetTargetArch()
-        if ("DX9" not in SDK) or ("DX8" not in SDK):
+        if ("DX9" not in SDK):
             uninstaller = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
             uninstaller = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
             for subdir in ListRegistryKeys(uninstaller):
             for subdir in ListRegistryKeys(uninstaller):
                 if (subdir[0]=="{"):
                 if (subdir[0]=="{"):
                     dir = GetRegistryKey(uninstaller+"\\"+subdir, "InstallLocation")
                     dir = GetRegistryKey(uninstaller+"\\"+subdir, "InstallLocation")
                     if (dir != 0):
                     if (dir != 0):
-                        if (("DX8" not in SDK) and
-                            (os.path.isfile(dir+"\\Include\\d3d8.h")) and
-                            (os.path.isfile(dir+"\\Include\\d3dx8.h")) and
-                            (os.path.isfile(dir+"\\Lib\\d3d8.lib")) and
-                            (os.path.isfile(dir+"\\Lib\\d3dx8.lib"))):
-                            SDK["DX8"] = dir.replace("\\", "/").rstrip("/")
                         if (("DX9" not in SDK) and
                         if (("DX9" not in SDK) and
                             (os.path.isfile(dir+"\\Include\\d3d9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3d9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3dx9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3dx9.h")) and
@@ -1743,18 +1736,12 @@ def SdkLocateDirectX( strMode = 'default' ):
             exit("Couldn't find DirectX March 2009 SDK")
             exit("Couldn't find DirectX March 2009 SDK")
     elif strMode == 'aug2006':
     elif strMode == 'aug2006':
         archStr = GetTargetArch()
         archStr = GetTargetArch()
-        if ("DX9" not in SDK) or ("DX8" not in SDK):
+        if ("DX9" not in SDK):
             uninstaller = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
             uninstaller = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
             for subdir in ListRegistryKeys(uninstaller):
             for subdir in ListRegistryKeys(uninstaller):
                 if (subdir[0]=="{"):
                 if (subdir[0]=="{"):
                     dir = GetRegistryKey(uninstaller+"\\"+subdir, "InstallLocation")
                     dir = GetRegistryKey(uninstaller+"\\"+subdir, "InstallLocation")
                     if (dir != 0):
                     if (dir != 0):
-                        if (("DX8" not in SDK) and
-                            (os.path.isfile(dir+"\\Include\\d3d8.h")) and
-                            (os.path.isfile(dir+"\\Include\\d3dx8.h")) and
-                            (os.path.isfile(dir+"\\Lib\\d3d8.lib")) and
-                            (os.path.isfile(dir+"\\Lib\\d3dx8.lib"))):
-                            SDK["DX8"] = dir.replace("\\", "/").rstrip("/")
                         if (("DX9" not in SDK) and
                         if (("DX9" not in SDK) and
                             (os.path.isfile(dir+"\\Include\\d3d9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3d9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3dx9.h")) and
                             (os.path.isfile(dir+"\\Include\\d3dx9.h")) and
@@ -2074,7 +2061,7 @@ def SdkLocateAndroid():
 ########################################################################
 ########################################################################
 
 
 def SdkAutoDisableDirectX():
 def SdkAutoDisableDirectX():
-    for ver in ["DX8","DX9","DIRECTCAM"]:
+    for ver in ["DX9", "DIRECTCAM"]:
         if (PkgSkip(ver)==0):
         if (PkgSkip(ver)==0):
             if (ver not in SDK):
             if (ver not in SDK):
                 if (GetHost() == "windows"):
                 if (GetHost() == "windows"):

+ 0 - 24
panda/metalibs/pandadx8/Sources.pp

@@ -1,24 +0,0 @@
-#define BUILD_DIRECTORY $[HAVE_DX8]
-
-// DIR_TYPE "metalib" indicates we are building a shared library that
-// consists mostly of references to other shared libraries.  Under
-// Windows, this directly produces a DLL (as opposed to the regular
-// src libraries, which don't produce anything but a pile of OBJ files
-// under Windows).
-
-#define DIR_TYPE metalib
-#define BUILDING_DLL BUILDING_PANDADX
-
-#define COMPONENT_LIBS \
-    p3dxgsg8
-#define LOCAL_LIBS p3gsgbase p3display p3express p3gobj
-#define OTHER_LIBS p3dtoolconfig p3dtool
-
-#begin metalib_target
-  #define TARGET pandadx8
-  #define SOURCES pandadx8.cxx
-  #define WIN_SYS_LIBS \
-     ddraw.lib dxguid.lib winmm.lib \
-     kernel32.lib gdi32.lib user32.lib advapi32.lib $[WIN_SYS_LIBS]  
-#end metalib_target
-

+ 0 - 38
panda/metalibs/pandadx8/pandadx8.cxx

@@ -1,38 +0,0 @@
-// Filename: pandadx.cxx
-// Created by:  drose (15May00)
-// 
-////////////////////////////////////////////////////////////////////
-
-#include "pandadx8.h"
-
-#include "config_dxgsg8.h"
-#include "wdxGraphicsPipe8.h"
-
-// By including checkPandaVersion.h, we guarantee that runtime
-// attempts to load libpandadx8.dll will fail if they
-// inadvertently link with the wrong version of libdtool.dll.
-
-#include "checkPandaVersion.h"
-
-////////////////////////////////////////////////////////////////////
-//     Function: init_libpandadx
-//  Description: Initializes the library.  This must be called at
-//               least once before any of the functions or classes in
-//               this library can be used.  Normally it will be
-//               called by the static initializers and need not be
-//               called explicitly, but special cases exist.
-////////////////////////////////////////////////////////////////////
-void
-init_libpandadx8() {
-  init_libdxgsg8();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: get_pipe_type_pandadx8
-//  Description: Returns the TypeHandle index of the recommended
-//               graphics pipe type defined by this module.
-////////////////////////////////////////////////////////////////////
-int
-get_pipe_type_pandadx8() {
-  return wdxGraphicsPipe8::get_class_type().get_index();
-}

+ 0 - 14
panda/metalibs/pandadx8/pandadx8.h

@@ -1,14 +0,0 @@
-// Filename: pandadx.h
-// Created by:  drose (2Jan01)
-// 
-////////////////////////////////////////////////////////////////////
-
-#ifndef PANDADX8_H
-#define PANDADX8_H
-
-#include "pandabase.h"
-
-EXPCL_PANDADX void init_libpandadx8();
-extern "C" EXPCL_PANDADX int get_pipe_type_pandadx8();
-
-#endif

+ 0 - 3
panda/src/configfiles/panda.prc.pp

@@ -27,9 +27,6 @@ aux-display pandadx9
 #if $[HAVE_GL]
 #if $[HAVE_GL]
 aux-display pandagl
 aux-display pandagl
 #endif
 #endif
-#if $[HAVE_DX8]
-aux-display pandadx8
-#endif
 #if $[HAVE_TINYDISPLAY]
 #if $[HAVE_TINYDISPLAY]
 aux-display p3tinydisplay
 aux-display p3tinydisplay
 #endif
 #endif

+ 0 - 42
panda/src/dxgsg8/Sources.pp

@@ -1,42 +0,0 @@
-#define BUILD_DIRECTORY $[HAVE_DX8]
-
-#define OTHER_LIBS \
-   p3interrogatedb:c p3dconfig:c p3dtoolconfig:m \
-   p3dtoolutil:c p3dtoolbase:c p3dtool:m
-   
-#define USE_PACKAGES dx8
-
-#begin lib_target
-  #define TARGET p3dxgsg8
-  #define LOCAL_LIBS \
-    p3gsgbase p3gobj p3display p3windisplay \
-    p3putil p3linmath p3mathutil p3pnmimage p3event
-    
-  #define COMBINED_SOURCES $[TARGET]_composite1.cxx     
-
-  // build dxGraphicsStateGuardian separately since its so big
-  
-  #define SOURCES \
-    dxGraphicsStateGuardian8.cxx \
-    dxGraphicsDevice8.h \
-    wdxGraphicsPipe8.I wdxGraphicsPipe8.h \
-    wdxGraphicsWindow8.I wdxGraphicsWindow8.h \
-    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 \
-    dxVertexBufferContext8.cxx \
-    dxIndexBufferContext8.cxx \
-    dxTextureContext8.cxx \
-    dxGeomMunger8.cxx \
-    dxGraphicsDevice8.cxx \
-    wdxGraphicsPipe8.cxx \
-    wdxGraphicsWindow8.cxx \
-    wdxGraphicsBuffer8.cxx
-
-#end lib_target

+ 0 - 155
panda/src/dxgsg8/config_dxgsg8.cxx

@@ -1,155 +0,0 @@
-// Filename: config_dxgsg8.cxx
-// Created by:  drose (06Oct99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "config_dxgsg8.h"
-#include "dxGraphicsStateGuardian8.h"
-#include "dxTextureContext8.h"
-#include "dxVertexBufferContext8.h"
-#include "dxIndexBufferContext8.h"
-#include "dxGeomMunger8.h"
-#include "graphicsPipeSelection.h"
-#include "wdxGraphicsWindow8.h"
-#include "wdxGraphicsPipe8.h"
-#include "pandaSystem.h"
-
-#include "dconfig.h"
-
-Configure(config_dxgsg8);
-NotifyCategoryDef(dxgsg8, ":display:gsg");
-NotifyCategoryDef(wdxdisplay8, "display");
-
-// Configure this variable true to cause the DXGSG to show each
-// transform space it renders by drawing a little unit axis.  This
-// cannot be enabled when the player is compiled in NDEBUG mode.
-ConfigVariableBool dx_show_transforms
-("dx-show-transforms", false);
-
-// Set Level of MultiSampling to be used, if HW supports it.  Valid values are 2-16.
-ConfigVariableInt dx_multisample_antialiasing_level
-("dx-multisample-antialiasing-level", 0);
-
-// if true, if card only supports per-vertex fog, it will be treated as no-HW fog capability
-ConfigVariableBool dx_no_vertex_fog
-("dx-no-vertex-fog", false);
-
-// if true, overwrite cursor bitmap tip with "D3D" to distinguish it from GDI cursor 
-ConfigVariableBool dx_show_cursor_watermark
-("dx-show-cursor-watermark", 
-#ifdef _DEBUG
-    true
-#else
-    false
-#endif
-    );
-
-// if true, triangle filter will be used to generate mipmap levels instead of default box filter
-ConfigVariableBool dx_use_triangle_mipgen_filter
-("dx-use-triangle-mipgen-filter", false);
-
-ConfigVariableBool dx_broken_max_index
-("dx-broken-max-index", false,
- PRC_DESC("Configure this true if you have a buggy graphics driver that "
-          "doesn't correctly implement the third parameter, NumVertices, "
-          "of DrawIndexedPrimitive().  In particular, the NVIDIA Quadro "
-          "driver version 6.14.10.7184 seems to treat this as a maximum "
-          "vertex index, rather than a delta between the maximum and "
-          "minimum vertex index.  Turn this on if you are seeing stray "
-          "triangles, or you are not seeing all of your triangles.  Enabling "
-          "this should work around this bug, at the cost of some additional "
-          "rendering overhead on the GPU."));
-
-#ifndef NDEBUG
-// debugging flag
-// values are same as D3DCULL enumtype, 0 - no force, 1 - force none, 2 - force CW, 3 - force CCW
-ConfigVariableInt dx_force_backface_culling
-("dx-force-backface-culling", 0);
-#endif
-
-ConfigVariableBool dx_mipmap_everything
-("dx-mipmap-everything", false);
-ConfigVariableBool dx_ignore_mipmaps
-("dx-ignore-mipmaps", false);
-
-// if this is set, more accurate but more expensive fog computations are performed
-ConfigVariableBool dx_use_rangebased_fog
-("dx-use-rangebased-fog", false);
-ConfigVariableBool dx_no_dithering
-("dx-no-dithering", false);
-ConfigVariableBool dx_force_16bpp_zbuffer
-("dx-force-16bpp-zbuffer", false);
-ConfigVariableBool dx_do_vidmemsize_check
-("do-vidmemsize-check", true);
-// Setting this true theoretically hinders render performance, because
-// it forces the FPU to go through some extra work to clean itself up
-// after rendering a frame, but the performance cost seems to be
-// small.  On the other hand, setting it false can force the
-// application to run in single-precision arithmetic mode, even if
-// it believes it is using double-precision variables.
-ConfigVariableBool dx_preserve_fpu_state
-("dx-preserve-fpu-state", true);
-
-ConfigVariableInt dx_preferred_device_id
-("dx-preferred-device-id", -1);
-
-#ifdef _DEBUG
-ConfigVariableDouble dx_global_miplevel_bias
-("dx-global-miplevel-bias", 0.0);
-ConfigVariableBool dx_debug_view_mipmaps
-("dx-debug-view-mipmaps", false);
-#endif
-
-ConfigVariableBool dx_force_anisotropic_filtering
-("dx-force-anisotropic-filtering", false);
-
-// set 'retained-mode #t' and this to have prepare_geom concatenate all tristrips within a geom 
-// together using degenerate tris
-ConfigVariableBool link_tristrips
-("link-tristrips", false);
-
-ConfigureFn(config_dxgsg8) {
-  init_libdxgsg8();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: init_libdxgsg
-//  Description: Initializes the library.  This must be called at
-//               least once before any of the functions or classes in
-//               this library can be used.  Normally it will be
-//               called by the static initializers and need not be
-//               called explicitly, but special cases exist.
-////////////////////////////////////////////////////////////////////
-void
-init_libdxgsg8() {
-  static bool initialized = false;
-  if (initialized) {
-    return;
-  }
-  initialized = true;
-
-  DXGraphicsStateGuardian8::init_type();
-  DXTextureContext8::init_type();
-  DXVertexBufferContext8::init_type();
-  DXIndexBufferContext8::init_type();
-  DXGeomMunger8::init_type();
-
-  wdxGraphicsPipe8::init_type();
-  wdxGraphicsWindow8::init_type();
-
-  GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
-  selection->add_pipe_type(wdxGraphicsPipe8::get_class_type(),
-                           wdxGraphicsPipe8::pipe_constructor);
-
-  PandaSystem *ps = PandaSystem::get_global_ptr();
-  ps->add_system("DirectX8");
-}

+ 0 - 60
panda/src/dxgsg8/config_dxgsg8.h

@@ -1,60 +0,0 @@
-// Filename: config_dxgsg.h
-// Created by:  drose (06Oct99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef CONFIG_DXGSG8_H
-#define CONFIG_DXGSG8_H
-
-#include "pandabase.h"
-#include "notifyCategoryProxy.h"
-#include "dxgsg8base.h"
-#include "configVariableBool.h"
-#include "configVariableInt.h"
-#include "configVariableDouble.h"
-
-NotifyCategoryDecl(dxgsg8, EXPCL_PANDADX, EXPTP_PANDADX);
-NotifyCategoryDecl(wdxdisplay8, EXPCL_PANDADX, EXPTP_PANDADX);
-
-extern ConfigVariableBool dx_no_vertex_fog;
-extern ConfigVariableBool dx_show_cursor_watermark;
-extern ConfigVariableBool dx_full_screen_antialiasing;
-extern ConfigVariableBool dx_use_rangebased_fog;
-extern ConfigVariableBool link_tristrips;
-extern ConfigVariableInt dx_multisample_antialiasing_level;
-extern ConfigVariableBool dx_use_triangle_mipgen_filter;
-extern ConfigVariableBool dx_broken_max_index;
-
-
-// debug flags we might want to use in full optimized build
-extern ConfigVariableBool dx_ignore_mipmaps;
-extern ConfigVariableBool dx_mipmap_everything;
-extern ConfigVariableBool dx_show_transforms;
-extern ConfigVariableBool dx_no_dithering;
-extern ConfigVariableBool dx_force_anisotropic_filtering;
-extern ConfigVariableBool dx_force_16bpp_zbuffer;
-extern ConfigVariableBool dx_do_vidmemsize_check;
-extern ConfigVariableBool dx_preserve_fpu_state;
-extern ConfigVariableInt dx_preferred_device_id;
-
-#ifndef NDEBUG
-extern ConfigVariableInt dx_force_backface_culling;
-#endif
-
-#ifdef _DEBUG
-extern ConfigVariableDouble dx_global_miplevel_bias;
-extern ConfigVariableBool dx_debug_view_mipmaps;
-#endif
-
-extern EXPCL_PANDADX void init_libdxgsg8();
-
-#endif

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

@@ -1,40 +0,0 @@
-// Filename: dxGeomMunger8.I
-// Created by:  drose (11Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE DXGeomMunger8::
-DXGeomMunger8(GraphicsStateGuardian *gsg, const RenderState *state) :
-  StandardMunger(gsg, state, 1, NT_packed_dabc, C_color),
-  _texture(DCAST(TextureAttrib, state->get_attrib(TextureAttrib::get_class_slot()))),
-  _tex_gen(DCAST(TexGenAttrib, state->get_attrib(TexGenAttrib::get_class_slot())))
-{
-  _filtered_texture = (TextureAttrib *)NULL;
-  _reffed_filtered_texture = false;
-  if (_texture != (TextureAttrib *)NULL) {
-    _filtered_texture = _texture->filter_to_max(gsg->get_max_texture_stages());
-    if (_filtered_texture != _texture) {
-      _filtered_texture->ref();
-      _reffed_filtered_texture = true;
-    }
-  }
-  // Set a callback to unregister ourselves when either the Texture or
-  // the TexGen object gets deleted.
-  _texture.set_callback(this);
-  _tex_gen.set_callback(this);
-}

+ 0 - 322
panda/src/dxgsg8/dxGeomMunger8.cxx

@@ -1,322 +0,0 @@
-// Filename: dxGeomMunger8.cxx
-// Created by:  drose (11Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "dxGeomMunger8.h"
-#include "geomVertexReader.h"
-#include "geomVertexWriter.h"
-#include "config_dxgsg8.h"
-
-GeomMunger *DXGeomMunger8::_deleted_chain = NULL;
-TypeHandle DXGeomMunger8::_type_handle;
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::Destructor
-//       Access: Public, Virtual
-//  Description: 
-////////////////////////////////////////////////////////////////////
-DXGeomMunger8::
-~DXGeomMunger8() {
-  if (_reffed_filtered_texture) {
-    unref_delete(_filtered_texture);
-    _reffed_filtered_texture = false;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::wp_callback
-//       Access: Public, Virtual
-//  Description: This callback is set to be made whenever the
-//               associated _texture or _tex_gen attributes are
-//               destructed, in which case the GeomMunger is invalid
-//               and should no longer be used.
-////////////////////////////////////////////////////////////////////
-void DXGeomMunger8::
-wp_callback(void *) {
-  unregister_myself();
-
-  if (_reffed_filtered_texture) {
-    unref_delete(_filtered_texture);
-    _reffed_filtered_texture = false;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::munge_format_impl
-//       Access: Protected, Virtual
-//  Description: Given a source GeomVertexFormat, converts it if
-//               necessary to the appropriate format for rendering.
-////////////////////////////////////////////////////////////////////
-CPT(GeomVertexFormat) DXGeomMunger8::
-munge_format_impl(const GeomVertexFormat *orig,
-                  const GeomVertexAnimationSpec &animation) {
-  if (dxgsg8_cat.is_debug()) {
-    if (animation.get_animation_type() != AT_none) {
-      dxgsg8_cat.debug()
-        << "preparing animation type " << animation << " for " << *orig
-        << "\n";
-    }
-  }
-  // We have to build a completely new format that includes only the
-  // appropriate components, in the appropriate order, in just one
-  // array.
-  PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
-  new_format->set_animation(animation);
-  PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
-
-  const GeomVertexColumn *vertex_type = orig->get_vertex_column();
-  const GeomVertexColumn *normal_type = orig->get_normal_column(); 
-  const GeomVertexColumn *color_type = orig->get_color_column();
-
-  if (vertex_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_vertex(), 3, NT_float32,
-       vertex_type->get_contents());
-    new_format->remove_column(vertex_type->get_name());
-
-  } else {
-    // If we don't have a vertex type, not much we can do.
-    return orig;
-  }
-
-  if (animation.get_animation_type() == AT_hardware &&
-      animation.get_num_transforms() > 0) {
-    if (animation.get_num_transforms() > 1) {
-      // If we want hardware animation, we need to reserve space for the
-      // blend weights.
-      new_array_format->add_column
-        (InternalName::get_transform_weight(), animation.get_num_transforms() - 1,
-         NT_float32, C_other);
-    }
-      
-    if (animation.get_indexed_transforms()) {
-      // Also, if we'll be indexing into the transform table, reserve
-      // space for the index.
-      new_array_format->add_column
-        (InternalName::get_transform_index(), 1,
-         NT_packed_dcba, C_index);
-    }                                    
-
-    // Make sure the old weights and indices are removed, just in
-    // case.
-    new_format->remove_column(InternalName::get_transform_weight());
-    new_format->remove_column(InternalName::get_transform_index());
-
-    // And we don't need the transform_blend table any more.
-    new_format->remove_column(InternalName::get_transform_blend());
-  }
-
-  if (normal_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_normal(), 3, NT_float32, C_vector);
-    new_format->remove_column(normal_type->get_name());
-  }
-
-  if (color_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_color(), 1, NT_packed_dabc, C_color);
-    new_format->remove_column(color_type->get_name());
-  }
-
-  // To support multitexture, we will need to add all of the relevant
-  // texcoord types, and in the order specified by the TextureAttrib.
-
-  // Now set up each of the active texture coordinate stages--or at
-  // least those for which we're not generating texture coordinates
-  // automatically.
-
-  if (_filtered_texture != (TextureAttrib *)NULL) {
-    int num_stages = _filtered_texture->get_num_on_ff_stages();
-    vector_int ff_tc_index(num_stages, 0);
-
-    // Be sure we add the texture coordinates in the right order, as
-    // specified by the attrib.  To ensure this, we first walk through
-    // the stages of the attrib and get the index numbers in the
-    // appropriate order.
-    int si, tc_index;
-    int max_tc_index = -1;
-    for (si = 0; si < num_stages; ++si) {
-      int tc_index = _filtered_texture->get_ff_tc_index(si);
-      nassertr(tc_index < num_stages, orig);
-      ff_tc_index[tc_index] = si;
-      max_tc_index = max(tc_index, max_tc_index);
-    }
-
-    // Now walk through the texture coordinates in the order they will
-    // appear on the final geometry.  For each one, get the texture
-    // coordinate name from the associated stage.
-    for (tc_index = 0; tc_index <= max_tc_index; ++tc_index) {
-      si = ff_tc_index[tc_index];
-      TextureStage *stage = _filtered_texture->get_on_ff_stage(si);
-      InternalName *name = stage->get_texcoord_name();
-
-      const GeomVertexColumn *texcoord_type = orig->get_column(name);
-
-      if (texcoord_type != (const GeomVertexColumn *)NULL) {
-        new_array_format->add_column
-          (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
-      } else {
-        // We have to add something as a placeholder, even if the
-        // texture coordinates aren't defined.
-        new_array_format->add_column(name, 2, NT_float32, C_texcoord);
-      }
-      new_format->remove_column(name);
-    }
-  }
-
-  // Make sure the FVF-style array we just built up is first in the
-  // list.
-  new_format->insert_array(0, new_array_format);
-
-  return GeomVertexFormat::register_format(new_format);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::premunge_format_impl
-//       Access: Protected, Virtual
-//  Description: Given a source GeomVertexFormat, converts it if
-//               necessary to the appropriate format for rendering.
-////////////////////////////////////////////////////////////////////
-CPT(GeomVertexFormat) DXGeomMunger8::
-premunge_format_impl(const GeomVertexFormat *orig) {
-  // We have to build a completely new format that includes only the
-  // appropriate components, in the appropriate order, in just one
-  // array.
-  PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
-  PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
-
-  const GeomVertexColumn *vertex_type = orig->get_vertex_column();
-  const GeomVertexColumn *normal_type = orig->get_normal_column(); 
-  const GeomVertexColumn *color_type = orig->get_color_column();
-
-  if (vertex_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_vertex(), 3, NT_float32,
-       vertex_type->get_contents());
-    new_format->remove_column(vertex_type->get_name());
-
-  } else {
-    // If we don't have a vertex type, not much we can do.
-    return orig;
-  }
-
-  if (normal_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_normal(), 3, NT_float32, C_vector);
-    new_format->remove_column(normal_type->get_name());
-  }
-
-  if (color_type != (const GeomVertexColumn *)NULL) {
-    new_array_format->add_column
-      (InternalName::get_color(), 1, NT_packed_dabc, C_color);
-    new_format->remove_column(color_type->get_name());
-  }
-
-  // To support multitexture, we will need to add all of the relevant
-  // texcoord types, and in the order specified by the TextureAttrib.
-
-  // Now set up each of the active texture coordinate stages--or at
-  // least those for which we're not generating texture coordinates
-  // automatically.
-
-  if (_filtered_texture != (TextureAttrib *)NULL) {
-    int num_stages = _filtered_texture->get_num_on_ff_stages();
-    vector_int ff_tc_index(num_stages, 0);
-
-    // Be sure we add the texture coordinates in the right order, as
-    // specified by the attrib.  To ensure this, we first walk through
-    // the stages of the attrib and get the index numbers in the
-    // appropriate order.
-    int si, tc_index;
-    int max_tc_index = -1;
-    for (si = 0; si < num_stages; ++si) {
-      int tc_index = _filtered_texture->get_ff_tc_index(si);
-      nassertr(tc_index < num_stages, orig);
-      ff_tc_index[tc_index] = si;
-      max_tc_index = max(tc_index, max_tc_index);
-    }
-
-    // Now walk through the texture coordinates in the order they will
-    // appear on the final geometry.  For each one, get the texture
-    // coordinate name from the associated stage.
-    for (tc_index = 0; tc_index <= max_tc_index; ++tc_index) {
-      si = ff_tc_index[tc_index];
-      TextureStage *stage = _filtered_texture->get_on_ff_stage(si);
-      InternalName *name = stage->get_texcoord_name();
-
-      const GeomVertexColumn *texcoord_type = orig->get_column(name);
-
-      if (texcoord_type != (const GeomVertexColumn *)NULL) {
-        new_array_format->add_column
-          (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
-      } else {
-        // We have to add something as a placeholder, even if the
-        // texture coordinates aren't defined.
-        new_array_format->add_column(name, 2, NT_float32, C_texcoord);
-      }
-      new_format->remove_column(name);
-    }
-  }
-
-  // Make sure the FVF-style array we just built up is first in the
-  // list.
-  new_format->insert_array(0, new_array_format);
-
-  return GeomVertexFormat::register_format(new_format);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::compare_to_impl
-//       Access: Protected, Virtual
-//  Description: Called to compare two GeomMungers who are known to be
-//               of the same type, for an apples-to-apples comparison.
-//               This will never be called on two pointers of a
-//               different type.
-////////////////////////////////////////////////////////////////////
-int DXGeomMunger8::
-compare_to_impl(const GeomMunger *other) const {
-  const DXGeomMunger8 *om = DCAST(DXGeomMunger8, other);
-  if (_filtered_texture != om->_filtered_texture) {
-    return _filtered_texture < om->_filtered_texture ? -1 : 1;
-  }
-  if (_tex_gen != om->_tex_gen) {
-    return _tex_gen < om->_tex_gen ? -1 : 1;
-  }
-
-  return StandardMunger::compare_to_impl(other);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGeomMunger8::geom_compare_to_impl
-//       Access: Protected, Virtual
-//  Description: Called to compare two GeomMungers who are known to be
-//               of the same type, for an apples-to-apples comparison.
-//               This will never be called on two pointers of a
-//               different type.
-////////////////////////////////////////////////////////////////////
-int DXGeomMunger8::
-geom_compare_to_impl(const GeomMunger *other) const {
-  // Unlike GLGeomMunger, we do consider _filtered_texture and
-  // _tex_gen important for this purpose, since they control the
-  // number and order of texture coordinates we might put into the
-  // FVF.
-  const DXGeomMunger8 *om = DCAST(DXGeomMunger8, other);
-  if (_filtered_texture != om->_filtered_texture) {
-    return _filtered_texture < om->_filtered_texture ? -1 : 1;
-  }
-  if (_tex_gen != om->_tex_gen) {
-    return _tex_gen < om->_tex_gen ? -1 : 1;
-  }
-
-  return StandardMunger::geom_compare_to_impl(other);
-}

+ 0 - 82
panda/src/dxgsg8/dxGeomMunger8.h

@@ -1,82 +0,0 @@
-// Filename: dxGeomMunger8.h
-// Created by:  drose (11Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXGEOMMUNGER8_H
-#define DXGEOMMUNGER8_H
-
-#include "pandabase.h"
-#include "standardMunger.h"
-#include "graphicsStateGuardian.h"
-#include "weakPointerTo.h"
-#include "weakPointerCallback.h"
-
-////////////////////////////////////////////////////////////////////
-//       Class : DXGeomMunger8
-// Description : This specialization on GeomMunger finesses vertices
-//               for DirectX rendering.  In particular, it makes sure
-//               colors are stored in DirectX's packed_argb format,
-//               and that all relevant components are packed into a
-//               single array, in the correct order.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXGeomMunger8 : public StandardMunger, public WeakPointerCallback {
-public:
-  INLINE DXGeomMunger8(GraphicsStateGuardian *gsg, const RenderState *state);
-  virtual ~DXGeomMunger8();
-  ALLOC_DELETED_CHAIN(DXGeomMunger8);
-
-  virtual void wp_callback(void *);
-
-protected:
-  virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig,
-                                                  const GeomVertexAnimationSpec &animation);
-  virtual CPT(GeomVertexFormat) premunge_format_impl(const GeomVertexFormat *orig);
-
-  virtual int compare_to_impl(const GeomMunger *other) const;
-  virtual int geom_compare_to_impl(const GeomMunger *other) const;
-
-private:
-  WCPT(TextureAttrib) _texture;
-  WCPT(TexGenAttrib) _tex_gen;
-
-  // This pointer is derived from _texture, above.  In the case that
-  // it is a different pointer, we maintain its reference count
-  // explicitly.  If it is the same pointer, we don't reference count
-  // it at all (so we won't hold on to the reference count
-  // unnecessarily).
-  const TextureAttrib *_filtered_texture;
-  bool _reffed_filtered_texture;
-
-  static GeomMunger *_deleted_chain;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    StandardMunger::init_type();
-    register_type(_type_handle, "DXGeomMunger8",
-                  StandardMunger::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-};
-
-#include "dxGeomMunger8.I"
-
-#endif

+ 0 - 42
panda/src/dxgsg8/dxGraphicsDevice8.cxx

@@ -1,42 +0,0 @@
-// Filename: dxGraphicsDevice.cxx
-// Created by:  masad (22Jul03)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "config_dxgsg8.h"
-#include "dxGraphicsDevice8.h"
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsDevice8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXGraphicsDevice8::
-DXGraphicsDevice8(wdxGraphicsPipe8 *pipe) :
-  GraphicsDevice(pipe) {
-
-  ZeroMemory(&_Scrn,sizeof(_Scrn));
-  _d3d_device = NULL;
-  _swap_chain = NULL;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsDevice8::Destructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXGraphicsDevice8::
-~DXGraphicsDevice8() {
-
-}
-

+ 0 - 51
panda/src/dxgsg8/dxGraphicsDevice8.h

@@ -1,51 +0,0 @@
-// Filename: dxGraphicsDevice.h
-// Created by:  masad (22Jul03)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXGRAPHICSDEVICE_H
-#define DXGRAPHICSDEVICE_H
-
-//#define GSG_VERBOSE 1
-
-#include "dxgsg8base.h"
-#include "graphicsDevice.h"
-#include "wdxGraphicsPipe8.h"
-
-
-////////////////////////////////////////////////////////////////////
-//   Class : DXGraphicsDevice8
-// Description : A GraphicsDevice necessary for multi-window rendering
-//               in DX. 
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXGraphicsDevice8 : public GraphicsDevice {
-  friend class wdxGraphicsPipe8;
-
-public:
-  DXGraphicsDevice8(wdxGraphicsPipe8 *pipe);
-  ~DXGraphicsDevice8();
-
-  DXScreenData _Scrn;
-  LPDIRECT3DDEVICE8 _d3d_device;  // same as Scrn._d3d_device, cached for spd
-  IDirect3DSwapChain8 *_swap_chain;
-
-#if 0
-protected:
-  static TypeHandle get_class_type();
-  static void init_type();
-  virtual TypeHandle get_type() const;
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-#endif
-};
-
-#endif
-

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

@@ -1,159 +0,0 @@
-// Filename: dxGraphicsStateGuardian8.I
-// Created by:  mike (02Feb99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::LColor_to_D3DCOLOR
-//       Access: Public, Static
-//  Description: Converts Panda's floating-point LColor structure to
-//               DirectX's D3DCOLOR packed structure.
-////////////////////////////////////////////////////////////////////
-INLINE DWORD DXGraphicsStateGuardian8::
-LColor_to_D3DCOLOR(const LColor &cLColor) {
-// MS VC defines _M_IX86 for x86.  gcc should define _X86_
-#if (defined(_M_IX86) || defined(_X86_)) && !defined(STDFLOAT_DOUBLE)
-  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
-  // don't think this makes much difference
-  
-  __asm {
-        push ebx   ; want to save this in case this fn is inlined
-        push ecx
-        mov ecx, cLColor
-        fild tempcolorval
-        fld DWORD PTR [ecx]
-        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)
-        fistp tempcolorval
-        mov ebx, tempcolorval
-        shl ebx, 8
-        or eax, ebx
-
-        fld DWORD PTR [ecx+8]  ;blue
-        fmul ST(0), ST(1)
-        fistp tempcolorval
-        or eax, tempcolorval
-
-        fld DWORD PTR [ecx+12] ;alpha
-        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
-        shl ebx, 24
-        or eax, ebx
-        mov d3dcolor, eax
-        pop ecx
-        pop ebx
-  }
-
-  //   dxgsg8_cat.debug() << (void*)d3dcolor << endl;
-  return d3dcolor;
-#else //!_X86_
-  return MY_D3DRGBA(cLColor[0], cLColor[1], cLColor[2], cLColor[3]);
-#endif //!_X86_
-}
-
-////////////////////////////////////////////////////////////////////
-//     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(SamplerState::WrapMode wm) {
-  switch (wm) {
-  case SamplerState::WM_clamp:
-    return D3DTADDRESS_CLAMP;
-  case SamplerState::WM_repeat:
-    return D3DTADDRESS_WRAP;
-  case SamplerState::WM_mirror:
-    return D3DTADDRESS_MIRROR;
-  case SamplerState::WM_mirror_once:
-    return D3DTADDRESS_MIRRORONCE;
-  case SamplerState::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::get_safe_buffer_start
-//       Access: Protected, Static
-//  Description: Returns the address of a 64K buffer that is allocated
-//               at the beginning of a 64K block.
-////////////////////////////////////////////////////////////////////
-INLINE unsigned char *DXGraphicsStateGuardian8::
-get_safe_buffer_start() {
-  if (_temp_buffer == NULL) {
-    // Guarantee we get a buffer of size 0x10000 bytes that begins
-    // on an even multiple of 0x10000.  We do this by allocating
-    // double the required buffer, and then pointing to the first
-    // multiple of 0x10000 within that buffer.
-    _temp_buffer = new unsigned char[0x1ffff];
-    _safe_buffer_start = (unsigned char *)(((long)_temp_buffer + 0xffff) & ~0xffff);
-  }
-
-  return _safe_buffer_start;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_supports_render_texture
-//       Access: Published
-//  Description: Returns true if this particular GSG can render
-//               from a wdxGraphicsBuffer8 directly into a texture, or
-//               false if it must always copy-to-texture at the end of
-//               each frame to achieve this effect.
-////////////////////////////////////////////////////////////////////
-INLINE bool DXGraphicsStateGuardian8::
-get_supports_render_texture() const {
-  return _supports_render_texture;
-}

+ 0 - 4674
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -1,4674 +0,0 @@
-// Filename: dxGraphicsStateGuardian8.cxx
-// Created by:  mike (02Feb99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "dxGraphicsStateGuardian8.h"
-#include "config_dxgsg8.h"
-#include "displayRegion.h"
-#include "renderBuffer.h"
-#include "geom.h"
-#include "graphicsWindow.h"
-#include "graphicsEngine.h"
-#include "lens.h"
-#include "ambientLight.h"
-#include "directionalLight.h"
-#include "pointLight.h"
-#include "spotlight.h"
-#include "textureAttrib.h"
-#include "texGenAttrib.h"
-#include "shadeModelAttrib.h"
-#include "cullFaceAttrib.h"
-#include "transparencyAttrib.h"
-#include "alphaTestAttrib.h"
-#include "depthTestAttrib.h"
-#include "depthWriteAttrib.h"
-#include "colorWriteAttrib.h"
-#include "texMatrixAttrib.h"
-#include "materialAttrib.h"
-#include "renderModeAttrib.h"
-#include "rescaleNormalAttrib.h"
-#include "fogAttrib.h"
-#include "depthOffsetAttrib.h"
-#include "lightAttrib.h"
-#include "stencilAttrib.h"
-#include "scissorAttrib.h"
-#include "clipPlaneAttrib.h"
-#include "fog.h"
-#include "throw_event.h"
-#include "geomVertexFormat.h"
-#include "geomVertexData.h"
-#include "geomTriangles.h"
-#include "geomTristrips.h"
-#include "geomTrifans.h"
-#include "geomLines.h"
-#include "geomLinestrips.h"
-#include "geomPoints.h"
-#include "geomVertexReader.h"
-#include "dxGeomMunger8.h"
-#include "config_gobj.h"
-#include "dxVertexBufferContext8.h"
-#include "dxIndexBufferContext8.h"
-#include "pStatTimer.h"
-#include "pStatCollector.h"
-#include "dxgsg8base.h"
-#include "wdxGraphicsBuffer8.h"
-
-#include <mmsystem.h>
-
-TypeHandle DXGraphicsStateGuardian8::_type_handle;
-
-D3DMATRIX DXGraphicsStateGuardian8::_d3d_ident_mat;
-
-unsigned char *DXGraphicsStateGuardian8::_temp_buffer = NULL;
-unsigned char *DXGraphicsStateGuardian8::_safe_buffer_start = NULL;
-
-#define __D3DLIGHT_RANGE_MAX ((PN_stdfloat)sqrt(FLT_MAX))  //for some reason this is missing in dx8 hdrs
-
-#define MY_D3DRGBA(r, g, b, a) ((D3DCOLOR) D3DCOLOR_COLORVALUE(r, g, b, a))
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXGraphicsStateGuardian8::
-DXGraphicsStateGuardian8(GraphicsEngine *engine, GraphicsPipe *pipe) :
-  GraphicsStateGuardian(CS_yup_left, engine, pipe)
-{
-  // Assume that we will get a hardware-accelerated context, unless
-  // the window tells us otherwise.
-  _is_hardware = true;
-
-  _screen = NULL;
-  _d3d_device = NULL;
-
-  _dx_is_ready = false;
-  _vertex_blending_enabled = false;
-  _overlay_windows_supported = false;
-  _tex_stats_retrieval_impossible = false;
-  _supports_render_texture = false;
-
-  _active_vbuffer = NULL;
-  _active_ibuffer = NULL;
-
-  // This is a static member, but we initialize it here in the
-  // constructor anyway.  It won't hurt if it gets repeatedly
-  // initalized.
-  ZeroMemory(&_d3d_ident_mat, sizeof(D3DMATRIX));
-  _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f;
-
-  _cur_read_pixel_buffer = RenderBuffer::T_front;
-
-  // DirectX drivers seem to consistently invert the texture when
-  // they copy framebuffer-to-texture.  Ok.
-  _copy_texture_inverted = true;
-
-  // D3DRS_POINTSPRITEENABLE doesn't seem to support remapping the
-  // texture coordinates via a texture matrix, so we don't advertise
-  // GR_point_sprite_tex_matrix.
-  _supported_geom_rendering =
-    Geom::GR_point | Geom::GR_point_uniform_size |
-    Geom::GR_point_perspective | Geom::GR_point_sprite |
-    Geom::GR_indexed_other |
-    Geom::GR_triangle_strip | Geom::GR_triangle_fan |
-    Geom::GR_flat_first_vertex;
-
-  _scissor_mat = TransformState::make_identity();
-
-  get_gamma_table();
-  atexit (atexit_function);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::Destructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXGraphicsStateGuardian8::
-~DXGraphicsStateGuardian8() {
-  if (IS_VALID_PTR(_d3d_device)) {
-    _d3d_device->SetTexture(0, NULL);  // this frees reference to the old texture
-  }
-  free_nondx_resources();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::prepare_texture
-//       Access: Public, Virtual
-//  Description: Creates a new retained-mode representation of the
-//               given texture, and returns a newly-allocated
-//               TextureContext pointer to reference it.  It is the
-//               responsibility of the calling function to later
-//               call release_texture() with this same pointer (which
-//               will also delete the pointer).
-//
-//               This function should not be called directly to
-//               prepare a texture.  Instead, call Texture::prepare().
-////////////////////////////////////////////////////////////////////
-TextureContext *DXGraphicsStateGuardian8::
-prepare_texture(Texture *tex, int view) {
-  DXTextureContext8 *dtc = new DXTextureContext8(_prepared_objects, tex, view);
-
-  if (!get_supports_compressed_texture_format(tex->get_ram_image_compression())) {
-    dxgsg8_cat.error()
-      << *dtc->get_texture() << " is stored in an unsupported compressed format.\n";
-    return NULL;
-  }
-
-  return dtc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::apply_texture
-//       Access: Public
-//  Description: Makes the texture the currently available texture for
-//               rendering on the ith stage.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-apply_texture(int i, TextureContext *tc, const SamplerState &sampler) {
-  if (tc == (TextureContext *)NULL) {
-    // The texture wasn't bound properly or something, so ensure
-    // texturing is disabled and just return.
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
-    return;
-  }
-  if (!update_texture(tc, false)) {
-    // Couldn't get the texture image or something.
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
-    return;
-  }
-
-  tc->set_active(true);
-
-  DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
-  Texture *tex = tc->get_texture();
-
-  SamplerState::WrapMode wrap_u, wrap_v, wrap_w;
-  wrap_u = sampler.get_wrap_u();
-  wrap_v = sampler.get_wrap_v();
-  wrap_w = sampler.get_wrap_w();
-
-  _d3d_device->SetTextureStageState(i, D3DTSS_ADDRESSU, get_texture_wrap_mode(wrap_u));
-  _d3d_device->SetTextureStageState(i, D3DTSS_ADDRESSV, get_texture_wrap_mode(wrap_v));
-  _d3d_device->SetTextureStageState(i, D3DTSS_ADDRESSW, get_texture_wrap_mode(wrap_w));
-
-  _d3d_device->SetTextureStageState(i, D3DTSS_BORDERCOLOR,
-                                    LColor_to_D3DCOLOR(sampler.get_border_color()));
-
-  uint aniso_degree = sampler.get_effective_anisotropic_degree();
-  SamplerState::FilterType ft = sampler.get_effective_magfilter();
-
-  if (aniso_degree >= 1) {
-    _d3d_device->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, aniso_degree);
-  }
-
-  D3DTEXTUREFILTERTYPE new_mag_filter;
-  if (aniso_degree <= 1) {
-    new_mag_filter = ((ft != SamplerState::FT_nearest) ? D3DTEXF_LINEAR : D3DTEXF_POINT);
-  } else {
-    new_mag_filter = D3DTEXF_ANISOTROPIC;
-  }
-
-  _d3d_device->SetTextureStageState(i, D3DTSS_MAGFILTER, new_mag_filter);
-
-  // map Panda composite min+mip filter types to d3d's separate min & mip filter types
-  D3DTEXTUREFILTERTYPE new_min_filter = get_d3d_min_type(sampler.get_effective_minfilter());
-  D3DTEXTUREFILTERTYPE new_mip_filter = get_d3d_mip_type(sampler.get_effective_minfilter());
-
-  if (!tex->might_have_ram_image()) {
-    // If the texture is completely dynamic, don't try to issue
-    // mipmaps--pandadx doesn't support auto-generated mipmaps at this
-    // point.
-    new_mip_filter = D3DTEXF_NONE;
-  }
-
-  // sanity check
-  if (!dtc->has_mipmaps()) {
-    new_mip_filter = D3DTEXF_NONE;
-  }
-
-  if (aniso_degree >= 2) {
-    new_min_filter = D3DTEXF_ANISOTROPIC;
-  }
-
-  _d3d_device->SetTextureStageState(i, D3DTSS_MINFILTER, new_min_filter);
-  _d3d_device->SetTextureStageState(i, D3DTSS_MIPFILTER, new_mip_filter);
-
-  _d3d_device->SetTexture(i, dtc->get_d3d_texture());
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::update_texture
-//       Access: Public, Virtual
-//  Description: Ensures that the current Texture data is refreshed
-//               onto the GSG.  This means updating the texture
-//               properties and/or re-uploading the texture image, if
-//               necessary.  This should only be called within the
-//               draw thread.
-//
-//               If force is true, this function will not return until
-//               the texture has been fully uploaded.  If force is
-//               false, the function may choose to upload a simple
-//               version of the texture instead, if the texture is not
-//               fully resident (and if get_incomplete_render() is
-//               true).
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-update_texture(TextureContext *tc, bool force) {
-  DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
-
-  // If the texture image has changed, or if its use of mipmaps has
-  // changed, we need to re-create the image.
-
-  if (dtc->was_modified()) {
-    if (!upload_texture(dtc, force)) {
-      // Oops, we can't re-create the texture for some reason.
-      Texture *tex = tc->get_texture();
-      dxgsg8_cat.error()
-        << "Unable to re-create texture " << *tex << endl;
-      cerr << "b\n";
-      return false;
-    }
-  }
-  dtc->enqueue_lru(&_prepared_objects->_graphics_memory_lru);
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::upload_texture
-//       Access: Public
-//  Description: Creates a texture surface on the graphics card and
-//               fills it with its pixel data.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-upload_texture(DXTextureContext8 *dtc, bool force) {
-  Texture *tex = dtc->get_texture();
-  if (!get_supports_compressed_texture_format(tex->get_ram_image_compression())) {
-    dxgsg8_cat.error()
-      << *tex << " is stored in an unsupported compressed format.\n";
-    return false;
-  }
-
-  dtc->delete_texture();
-  dtc->update_data_size_bytes(0);
-  dtc->mark_unloaded();
-
-  if (_effective_incomplete_render && !force) {
-    bool has_image = _supports_compressed_texture ? tex->has_ram_image() : tex->has_uncompressed_ram_image();
-    if (!has_image && tex->might_have_ram_image() &&
-        tex->has_simple_ram_image() &&
-        !_loader.is_null()) {
-      // If we don't have the texture data right now, go get it, but in
-      // the meantime load a temporary simple image in its place.
-      async_reload_texture(dtc);
-      has_image = _supports_compressed_texture ? tex->has_ram_image() : tex->has_uncompressed_ram_image();
-      if (!has_image) {
-        if (dtc->was_simple_image_modified()) {
-          return dtc->create_simple_texture(*_screen);
-        }
-        return true;
-      }
-    }
-  }
-
-  return dtc->create_texture(*_screen);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::release_texture
-//       Access: Public, Virtual
-//  Description: Frees the GL resources previously allocated for the
-//               texture.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-release_texture(TextureContext *tc) {
-  DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
-  delete dtc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::extract_texture_data
-//       Access: Public, Virtual
-//  Description: This method should only be called by the
-//               GraphicsEngine.  Do not call it directly; call
-//               GraphicsEngine::extract_texture_data() instead.
-//
-//               This method will be called in the draw thread to
-//               download the texture memory's image into its
-//               ram_image value.  It returns true on success, false
-//               otherwise.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-extract_texture_data(Texture *tex) {
-  TextureContext *tc = tex->prepare_now(0, get_prepared_objects(), this);
-  nassertr(tc != (TextureContext *)NULL, false);
-  DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
-
-  return dtc->extract_texture_data();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::prepare_vertex_buffer
-//       Access: Public, Virtual
-//  Description: Creates a new retained-mode representation of the
-//               given data, and returns a newly-allocated
-//               VertexBufferContext pointer to reference it.  It is the
-//               responsibility of the calling function to later
-//               call release_vertex_buffer() with this same pointer (which
-//               will also delete the pointer).
-//
-//               This function should not be called directly to
-//               prepare a buffer.  Instead, call Geom::prepare().
-////////////////////////////////////////////////////////////////////
-VertexBufferContext *DXGraphicsStateGuardian8::
-prepare_vertex_buffer(GeomVertexArrayData *data) {
-  DXVertexBufferContext8 *dvbc = new DXVertexBufferContext8(_prepared_objects, data);
-  return dvbc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::apply_vertex_buffer
-//       Access: Public
-//  Description: Updates the vertex buffer with the current data, and
-//               makes it the current vertex buffer for rendering.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-apply_vertex_buffer(VertexBufferContext *vbc,
-                    const GeomVertexArrayDataHandle *reader, bool force) {
-  DXVertexBufferContext8 *dvbc = DCAST(DXVertexBufferContext8, vbc);
-
-  if (dvbc->_vbuffer == NULL) {
-    // Attempt to create a new vertex buffer.
-    if (vertex_buffers &&
-        reader->get_usage_hint() != Geom::UH_client) {
-      dvbc->create_vbuffer(*_screen, reader);
-    }
-
-    if (dvbc->_vbuffer != NULL) {
-      if (!dvbc->upload_data(reader, force)) {
-        return false;
-      }
-
-      dvbc->mark_loaded(reader);
-
-      _d3d_device->SetStreamSource
-        (0, dvbc->_vbuffer, reader->get_array_format()->get_stride());
-      _active_vbuffer = dvbc;
-      _active_ibuffer = NULL;
-      dvbc->set_active(true);
-
-    } else {
-      _active_vbuffer = NULL;
-    }
-
-  } else {
-    if (dvbc->was_modified(reader)) {
-      if (dvbc->changed_size(reader)) {
-        // We have to destroy the old vertex buffer and create a new
-        // one.
-        dvbc->create_vbuffer(*_screen, reader);
-      }
-
-      if (!dvbc->upload_data(reader, force)) {
-        return false;
-      }
-      dvbc->mark_loaded(reader);
-      _active_vbuffer = NULL;
-    }
-
-    if (_active_vbuffer != dvbc) {
-      _d3d_device->SetStreamSource
-        (0, dvbc->_vbuffer, reader->get_array_format()->get_stride());
-      _active_vbuffer = dvbc;
-      _active_ibuffer = NULL;
-      dvbc->set_active(true);
-    }
-  }
-  dvbc->enqueue_lru(&_prepared_objects->_graphics_memory_lru);
-
-  HRESULT hr = _d3d_device->SetVertexShader(dvbc->_fvf);
-#ifndef NDEBUG
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "SetVertexShader(0x" << (void*)dvbc->_fvf
-      << ") failed" << D3DERRORSTRING(hr);
-  }
-#endif
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::release_vertex_buffer
-//       Access: Public, Virtual
-//  Description: Frees the GL resources previously allocated for the
-//               data.  This function should never be called
-//               directly; instead, call Data::release() (or simply
-//               let the Data destruct).
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-release_vertex_buffer(VertexBufferContext *vbc) {
-  DXVertexBufferContext8 *dvbc = DCAST(DXVertexBufferContext8, vbc);
-  delete dvbc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::prepare_index_buffer
-//       Access: Public, Virtual
-//  Description: Creates a new retained-mode representation of the
-//               given data, and returns a newly-allocated
-//               IndexBufferContext pointer to reference it.  It is the
-//               responsibility of the calling function to later call
-//               release_index_buffer() with this same pointer (which
-//               will also delete the pointer).
-//
-//               This function should not be called directly to
-//               prepare a buffer.  Instead, call Geom::prepare().
-////////////////////////////////////////////////////////////////////
-IndexBufferContext *DXGraphicsStateGuardian8::
-prepare_index_buffer(GeomPrimitive *data) {
-  DXIndexBufferContext8 *dibc = new DXIndexBufferContext8(_prepared_objects, data);
-  return dibc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::apply_index_buffer
-//       Access: Public
-//  Description: Updates the index buffer with the current data, and
-//               makes it the current index buffer for rendering.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-apply_index_buffer(IndexBufferContext *ibc,
-                   const GeomPrimitivePipelineReader *reader, bool force) {
-  DXIndexBufferContext8 *dibc = DCAST(DXIndexBufferContext8, ibc);
-
-  if (dibc->_ibuffer == NULL) {
-    // Attempt to create a new index buffer.
-    dibc->create_ibuffer(*_screen, reader);
-
-    if (dibc->_ibuffer != NULL) {
-      if (!dibc->upload_data(reader, force)) {
-        return false;
-      }
-      dibc->mark_loaded(reader);
-
-      _d3d_device->SetIndices(dibc->_ibuffer, 0);
-      _active_ibuffer = dibc;
-      dibc->set_active(true);
-
-    } else {
-      _d3d_device->SetIndices(NULL, 0);
-      _active_ibuffer = NULL;
-    }
-
-  } else {
-    if (dibc->was_modified(reader)) {
-      if (dibc->changed_size(reader)) {
-        // We have to destroy the old index buffer and create a new
-        // one.
-        dibc->create_ibuffer(*_screen, reader);
-      }
-
-      if (!dibc->upload_data(reader, force)) {
-        return false;
-      }
-
-      dibc->mark_loaded(reader);
-      _active_ibuffer = NULL;
-    }
-
-    if (_active_ibuffer != dibc) {
-      _d3d_device->SetIndices(dibc->_ibuffer, 0);
-      _active_ibuffer = dibc;
-      dibc->set_active(true);
-    }
-  }
-  dibc->enqueue_lru(&_prepared_objects->_graphics_memory_lru);
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::release_index_buffer
-//       Access: Public, Virtual
-//  Description: Frees the GL resources previously allocated for the
-//               data.  This function should never be called
-//               directly; instead, call Data::release() (or simply
-//               let the Data destruct).
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-release_index_buffer(IndexBufferContext *ibc) {
-  DXIndexBufferContext8 *dibc = DCAST(DXIndexBufferContext8, ibc);
-  delete dibc;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::make_geom_munger
-//       Access: Public, Virtual
-//  Description: Creates a new GeomMunger object to munge vertices
-//               appropriate to this GSG for the indicated state.
-////////////////////////////////////////////////////////////////////
-PT(GeomMunger) DXGraphicsStateGuardian8::
-make_geom_munger(const RenderState *state, Thread *current_thread) {
-  PT(DXGeomMunger8) munger = new DXGeomMunger8(this, state);
-  return GeomMunger::register_munger(munger, current_thread);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_clear
-//       Access: Public, Virtual
-//  Description: Clears all of the indicated buffers to their assigned
-//               colors.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-clear(DrawableRegion *clearable) {
-
-  DWORD main_flags = 0;
-  DWORD aux_flags = 0;
-
-  D3DCOLOR color_clear_value = LColor_to_D3DCOLOR(clearable->get_clear_color());
-  PN_stdfloat depth_clear_value = clearable->get_clear_depth();
-  DWORD stencil_clear_value = (DWORD)(clearable->get_clear_stencil());
-
-  //set appropriate flags
-  if (clearable->get_clear_color_active()) {
-    main_flags |=  D3DCLEAR_TARGET;
-  }
-
-  if (clearable->get_clear_depth_active()) {
-    aux_flags |=  D3DCLEAR_ZBUFFER;
-    nassertv(_screen->_presentation_params.EnableAutoDepthStencil);
-  }
-
-  if (clearable->get_clear_stencil_active()) {
-    // clear only if there is a stencil buffer
-    if (_screen->_presentation_params.EnableAutoDepthStencil &&
-      IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) {
-      aux_flags |=  D3DCLEAR_STENCIL;
-    }
-  }
-
-  if ((main_flags | aux_flags) != 0) {
-    HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, color_clear_value,
-                                    depth_clear_value, stencil_clear_value);
-    if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) {
-      // Maybe there's a problem with the one or more of the auxiliary
-      // buffers.
-      hr = _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, color_clear_value,
-                              depth_clear_value, stencil_clear_value);
-      if (!FAILED(hr)) {
-        // Yep, it worked without them.  That's a problem.  Which buffer
-        // poses the problem?
-        if (clearable->get_clear_depth_active()) {
-          aux_flags |=  D3DCLEAR_ZBUFFER;
-          HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, color_clear_value,
-                                           depth_clear_value, stencil_clear_value);
-          if (FAILED(hr2)) {
-            dxgsg8_cat.error()
-              << "Unable to clear depth buffer; removing.\n";
-            // This is really hacky code.
-            ((FrameBufferProperties *)_current_properties)->set_depth_bits(0);
-          }
-        }
-        if (clearable->get_clear_stencil_active()) {
-          aux_flags |=  D3DCLEAR_STENCIL;
-          HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, color_clear_value,
-                                           stencil_clear_value, stencil_clear_value);
-          if (FAILED(hr2)) {
-            dxgsg8_cat.error()
-              << "Unable to clear stencil buffer; removing.\n";
-            // This is really hacky code.
-            ((FrameBufferProperties *)_current_properties)->set_stencil_bits(0);
-            _supports_stencil = false;
-          }
-        }
-      }
-    }
-
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "clear_buffer failed:  Clear returned " << D3DERRORSTRING(hr);
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::prepare_display_region
-//       Access: Public, Virtual
-//  Description: Prepare a display region for rendering (set up
-//       scissor region and viewport)
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-prepare_display_region(DisplayRegionPipelineReader *dr) {
-  nassertv(dr != (DisplayRegionPipelineReader *)NULL);
-  GraphicsStateGuardian::prepare_display_region(dr);
-
-  int l, u, w, h;
-  dr->get_region_pixels_i(l, u, w, h);
-
-  // Create the viewport
-  D3DVIEWPORT8 vp = { l, u, w, h, 0.0f, 1.0f };
-  _current_viewport = vp;
-  set_scissor(0.0f, 1.0f, 0.0f, 1.0f);
-
-  if (_screen->_can_direct_disable_color_writes) {
-    _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, _color_write_mask);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::calc_projection_mat
-//       Access: Public, Virtual
-//  Description: Given a lens, calculates the appropriate projection
-//               matrix for use with this gsg.  Note that the
-//               projection matrix depends a lot upon the coordinate
-//               system of the rendering API.
-//
-//               The return value is a TransformState if the lens is
-//               acceptable, NULL if it is not.
-////////////////////////////////////////////////////////////////////
-CPT(TransformState) DXGraphicsStateGuardian8::
-calc_projection_mat(const Lens *lens) {
-  if (lens == (Lens *)NULL) {
-    return NULL;
-  }
-
-  if (!lens->is_linear()) {
-    return NULL;
-  }
-
-  // DirectX also uses a Z range of 0 to 1, whereas the Panda
-  // convention is for the projection matrix to produce a Z range of
-  // -1 to 1.  We have to rescale to compensate.
-  static const LMatrix4 rescale_mat
-    (1, 0, 0, 0,
-     0, 1, 0, 0,
-     0, 0, 0.5, 0,
-     0, 0, 0.5, 1);
-
-  LMatrix4 result =
-    LMatrix4::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
-    lens->get_projection_mat(_current_stereo_channel) *
-    rescale_mat;
-
-  if (_scene_setup->get_inverted()) {
-    // If the scene is supposed to be inverted, then invert the
-    // projection matrix.
-    result *= LMatrix4::scale_mat(1.0f, -1.0f, 1.0f);
-  }
-
-  return TransformState::make_mat(result);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::prepare_lens
-//       Access: Public, Virtual
-//  Description: Makes the current lens (whichever lens was most
-//               recently specified with set_scene()) active, so
-//               that it will transform future rendered geometry.
-//               Normally this is only called from the draw process,
-//               and usually it is called by set_scene().
-//
-//               The return value is true if the lens is acceptable,
-//               false if it is not.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-prepare_lens() {
-  CPT(TransformState) scissor_proj_mat = _scissor_mat->compose(_projection_mat);
-  LMatrix4f mat = LCAST(float, scissor_proj_mat->get_mat());
-  HRESULT hr =
-    _d3d_device->SetTransform(D3DTS_PROJECTION,
-                              (D3DMATRIX*)mat.get_data());
-  return SUCCEEDED(hr);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::begin_frame
-//       Access: Public, Virtual
-//  Description: Called before each frame is rendered, to allow the
-//               GSG a chance to do any internal cleanup before
-//               beginning the frame.
-//
-//               The return value is true if successful (in which case
-//               the frame will be drawn and end_frame() will be
-//               called later), or false if unsuccessful (in which
-//               case nothing will be drawn and end_frame() will not
-//               be called).
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-begin_frame(Thread *current_thread) {
-  if (!GraphicsStateGuardian::begin_frame(current_thread)) {
-    return false;
-  }
-
-  if (_d3d_device == NULL) {
-    dxgsg8_cat.debug()
-      << this << "::begin_frame(): no device.\n";
-    return false;
-  }
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::begin_scene
-//       Access: Public, Virtual
-//  Description: Called between begin_frame() and end_frame() to mark
-//               the beginning of drawing commands for a "scene"
-//               (usually a particular DisplayRegion) within a frame.
-//               All 3-D drawing commands, except the clear operation,
-//               must be enclosed within begin_scene() .. end_scene().
-//
-//               The return value is true if successful (in which case
-//               the scene will be drawn and end_scene() will be
-//               called later), or false if unsuccessful (in which
-//               case nothing will be drawn and end_scene() will not
-//               be called).
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-begin_scene() {
-  if (!GraphicsStateGuardian::begin_scene()) {
-    return false;
-  }
-
-  HRESULT hr = _d3d_device->BeginScene();
-
-  if (FAILED(hr)) {
-    if (hr == D3DERR_DEVICELOST) {
-      if (dxgsg8_cat.is_debug()) {
-        dxgsg8_cat.debug()
-          << "BeginScene returns D3DERR_DEVICELOST" << endl;
-      }
-
-      check_cooperative_level();
-
-    } else {
-      dxgsg8_cat.error()
-        << "BeginScene failed, unhandled error hr == "
-        << D3DERRORSTRING(hr) << endl;
-      throw_event("panda3d-render-error");
-    }
-    return false;
-  }
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::end_scene
-//       Access: Public, Virtual
-//  Description: Called between begin_frame() and end_frame() to mark
-//               the end of drawing commands for a "scene" (usually a
-//               particular DisplayRegion) within a frame.  All 3-D
-//               drawing commands, except the clear operation, must be
-//               enclosed within begin_scene() .. end_scene().
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-end_scene() {
-  GraphicsStateGuardian::end_scene();
-  _dlights.clear();
-
-  HRESULT hr = _d3d_device->EndScene();
-
-  if (FAILED(hr)) {
-    if (hr == D3DERR_DEVICELOST) {
-      if (dxgsg8_cat.is_debug()) {
-        dxgsg8_cat.debug()
-          << "EndScene returns DeviceLost\n";
-      }
-      check_cooperative_level();
-
-    } else {
-      dxgsg8_cat.error()
-        << "EndScene failed, unhandled error hr == " << D3DERRORSTRING(hr);
-      throw_event("panda3d-render-error");
-    }
-    return;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsStateGuardian::end_frame
-//       Access: Public, Virtual
-//  Description: Called after each frame is rendered, to allow the
-//               GSG a chance to do any internal cleanup after
-//               rendering the frame, and before the window flips.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-end_frame(Thread *current_thread) {
-
-#if defined(DO_PSTATS)
-  if (_texmgrmem_total_pcollector.is_active()) {
-#define TICKS_PER_GETTEXINFO (2.5*1000)   // 2.5 second interval
-    static DWORD last_tick_count = 0;
-    DWORD cur_tick_count = GetTickCount();
-
-    if (cur_tick_count - last_tick_count > TICKS_PER_GETTEXINFO) {
-      last_tick_count = cur_tick_count;
-      report_texmgr_stats();
-    }
-  }
-#endif
-
-  // Note: regular GraphicsWindow::end_frame is being called,
-  // but we override gsg::end_frame, so need to explicitly call it here
-  // (currently it's an empty fn)
-  GraphicsStateGuardian::end_frame(current_thread);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::begin_draw_primitives
-//       Access: Public, Virtual
-//  Description: Called before a sequence of draw_primitive()
-//               functions are called, this should prepare the vertex
-//               data for rendering.  It returns true if the vertices
-//               are ok, false to abort this group of primitives.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-begin_draw_primitives(const GeomPipelineReader *geom_reader,
-                      const GeomMunger *munger,
-                      const GeomVertexDataPipelineReader *data_reader,
-                      bool force) {
-  if (!GraphicsStateGuardian::begin_draw_primitives(geom_reader, munger,
-                                                    data_reader, force)) {
-    return false;
-  }
-  nassertr(_data_reader != (GeomVertexDataPipelineReader *)NULL, false);
-
-  const GeomVertexFormat *format = _data_reader->get_format();
-
-  // The munger should have put the FVF data in the first array.
-  const GeomVertexArrayDataHandle *data = _data_reader->get_array_reader(0);
-
-  VertexBufferContext *vbc = ((GeomVertexArrayData *)(data->get_object()))->prepare_now(get_prepared_objects(), this);
-  nassertr(vbc != (VertexBufferContext *)NULL, false);
-  if (!apply_vertex_buffer(vbc, data, force)) {
-    return false;
-  }
-
-  const GeomVertexAnimationSpec &animation =
-    data_reader->get_format()->get_animation();
-  if (animation.get_animation_type() == Geom::AT_hardware) {
-    // Set up vertex blending.
-    switch (animation.get_num_transforms()) {
-    case 1:
-      // The MSDN docs suggest we should use D3DVBF_0WEIGHTS here, but
-      // that doesn't seem to work at all.  On the other hand,
-      // D3DVBF_DISABLE *does* work, because it disables special
-      // handling, meaning only the world matrix affects these
-      // vertices--and by accident or design, the first matrix,
-      // D3DTS_WORLDMATRIX(0), *is* the world matrix.
-      _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
-      break;
-    case 2:
-      _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_1WEIGHTS);
-      break;
-    case 3:
-      _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_2WEIGHTS);
-      break;
-    case 4:
-      _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_3WEIGHTS);
-      break;
-    }
-
-    if (animation.get_indexed_transforms()) {
-      // Set up indexed vertex blending.
-      _d3d_device->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, TRUE);
-    } else {
-      _d3d_device->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
-    }
-
-    const TransformTable *table = data_reader->get_transform_table();
-    if (table != (TransformTable *)NULL) {
-      for (int i = 0; i < table->get_num_transforms(); i++) {
-        LMatrix4 mat;
-        table->get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
-        LMatrix4f matf = LCAST(float, mat);
-        const D3DMATRIX *d3d_mat = (const D3DMATRIX *)matf.get_data();
-        _d3d_device->SetTransform(D3DTS_WORLDMATRIX(i), d3d_mat);
-      }
-
-      // Setting the first animation matrix steps on the world matrix,
-      // so we have to set a flag to reload the world matrix later.
-      _transform_stale = true;
-    }
-    _vertex_blending_enabled = true;
-
-  } else {
-    // We're not using vertex blending.
-    if (_vertex_blending_enabled) {
-      _d3d_device->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
-      _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
-      _vertex_blending_enabled = false;
-    }
-
-    if (_transform_stale && !_data_reader->is_vertex_transformed()) {
-      LMatrix4f mat = LCAST(float, _internal_transform->get_mat());
-      const D3DMATRIX *d3d_mat = (const D3DMATRIX *)mat.get_data();
-      _d3d_device->SetTransform(D3DTS_WORLD, d3d_mat);
-      _transform_stale = false;
-    }
-  }
-
-  if (_data_reader->is_vertex_transformed()) {
-    // If the vertex data claims to be already transformed into clip
-    // coordinates, wipe out the current projection and modelview
-    // matrix (so we don't attempt to transform it again).
-
-    // It's tempting just to use the D3DFVF_XYZRHW specification on
-    // these vertices, but that turns out to be a bigger hammer than
-    // we want: that also prevents lighting calculations and user clip
-    // planes.
-    _d3d_device->SetTransform(D3DTS_WORLD, &_d3d_ident_mat);
-    static const LMatrix4f rescale_mat
-      (1, 0, 0, 0,
-       0, 1, 0, 0,
-       0, 0, 0.5, 0,
-       0, 0, 0.5, 1);
-    _transform_stale = true;
-
-    _d3d_device->SetTransform(D3DTS_PROJECTION, (const D3DMATRIX *)rescale_mat.get_data());
-  }
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_triangles
-//       Access: Public, Virtual
-//  Description: Draws a series of disconnected triangles.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) {
-  //PStatTimer timer(_draw_primitive_pcollector);
-  _vertices_tri_pcollector.add_level(reader->get_num_vertices());
-  _primitive_batches_tri_pcollector.add_level(1);
-  if (reader->is_indexed()) {
-    int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
-    int max_vertex = reader->get_max_vertex();
-
-    if (_active_vbuffer != NULL) {
-      // Indexed, vbuffers.
-      IndexBufferContext *ibc = ((GeomPrimitive *)(reader->get_object()))->prepare_now(get_prepared_objects(), this);
-      nassertr(ibc != (IndexBufferContext *)NULL, false);
-      if (!apply_index_buffer(ibc, reader, force)) {
-        return false;
-      }
-
-      _d3d_device->DrawIndexedPrimitive
-        (D3DPT_TRIANGLELIST,
-         min_vertex, max_vertex - min_vertex + 1,
-         0, reader->get_num_primitives());
-
-    } else {
-      // Indexed, client arrays.
-      const unsigned char *index_pointer = reader->get_read_pointer(force);
-      if (index_pointer == NULL) {
-        return false;
-      }
-      D3DFORMAT index_type = get_index_type(reader->get_index_type());
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-      draw_indexed_primitive_up
-        (D3DPT_TRIANGLELIST,
-         min_vertex, max_vertex,
-         reader->get_num_primitives(),
-         index_pointer, index_type, vertex_pointer,
-         _data_reader->get_format()->get_array(0)->get_stride());
-    }
-  } else {
-    if (_active_vbuffer != NULL) {
-      // Nonindexed, vbuffers.
-      _d3d_device->DrawPrimitive
-        (D3DPT_TRIANGLELIST,
-         reader->get_first_vertex(),
-         reader->get_num_primitives());
-
-    } else {
-      // Nonindexed, client arrays.
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-      draw_primitive_up(D3DPT_TRIANGLELIST, reader->get_num_primitives(),
-                        reader->get_first_vertex(),
-                        reader->get_num_vertices(),
-                        vertex_pointer,
-                        _data_reader->get_format()->get_array(0)->get_stride());
-    }
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_tristrips
-//       Access: Public, Virtual
-//  Description: Draws a series of triangle strips.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) {
-  //PStatTimer timer(_draw_primitive_pcollector);
-  if (connect_triangle_strips && _current_fill_mode != RenderModeAttrib::M_wireframe) {
-    // One long triangle strip, connected by the degenerate vertices
-    // that have already been set up within the primitive.
-    _vertices_tristrip_pcollector.add_level(reader->get_num_vertices());
-    _primitive_batches_tristrip_pcollector.add_level(1);
-    if (reader->is_indexed()) {
-      int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
-      int max_vertex = reader->get_max_vertex();
-
-      if (_active_vbuffer != NULL) {
-        // Indexed, vbuffers, one line triangle strip.
-        IndexBufferContext *ibc = ((GeomPrimitive *)(reader->get_object()))->prepare_now(get_prepared_objects(), this);
-        nassertr(ibc != (IndexBufferContext *)NULL, false);
-        if (!apply_index_buffer(ibc, reader, force)) {
-          return false;
-        }
-
-        _d3d_device->DrawIndexedPrimitive
-          (D3DPT_TRIANGLESTRIP,
-           min_vertex, max_vertex - min_vertex + 1,
-           0, reader->get_num_vertices() - 2);
-
-      } else {
-        // Indexed, client arrays, one long triangle strip.
-        const unsigned char *index_pointer = reader->get_read_pointer(force);
-        if (index_pointer == NULL) {
-          return false;
-        }
-        D3DFORMAT index_type = get_index_type(reader->get_index_type());
-        const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-        if (vertex_pointer == NULL) {
-          return false;
-        }
-        draw_indexed_primitive_up
-          (D3DPT_TRIANGLESTRIP,
-           min_vertex, max_vertex,
-           reader->get_num_vertices() - 2,
-           index_pointer, index_type, vertex_pointer,
-           _data_reader->get_format()->get_array(0)->get_stride());
-      }
-    } else {
-      if (_active_vbuffer != NULL) {
-        // Nonindexed, vbuffers, one long triangle strip.
-        _d3d_device->DrawPrimitive
-          (D3DPT_TRIANGLESTRIP,
-           reader->get_first_vertex(),
-           reader->get_num_vertices() - 2);
-
-      } else {
-        // Indexed, client arrays, one long triangle strip.
-        const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-        if (vertex_pointer == NULL) {
-          return false;
-        }
-        draw_primitive_up(D3DPT_TRIANGLESTRIP,
-                          reader->get_num_vertices() - 2,
-                          reader->get_first_vertex(),
-                          reader->get_num_vertices(),
-                          vertex_pointer,
-                          _data_reader->get_format()->get_array(0)->get_stride());
-      }
-    }
-
-  } else {
-    // Send the individual triangle strips, stepping over the
-    // degenerate vertices.
-    CPTA_int ends = reader->get_ends();
-    _primitive_batches_tristrip_pcollector.add_level(ends.size());
-
-    if (reader->is_indexed()) {
-      CPTA_int ends = reader->get_ends();
-      int index_stride = reader->get_index_stride();
-      _primitive_batches_tristrip_pcollector.add_level(ends.size());
-
-      GeomVertexReader mins(reader->get_mins(), 0);
-      GeomVertexReader maxs(reader->get_maxs(), 0);
-      nassertr(reader->get_mins()->get_num_rows() == (int)ends.size() &&
-               reader->get_maxs()->get_num_rows() == (int)ends.size(), false);
-
-      if (_active_vbuffer != NULL) {
-        // Indexed, vbuffers, individual triangle strips.
-        IndexBufferContext *ibc = ((GeomPrimitive *)(reader->get_object()))->prepare_now(get_prepared_objects(), this);
-        nassertr(ibc != (IndexBufferContext *)NULL, false);
-        if (!apply_index_buffer(ibc, reader, force)) {
-          return false;
-        }
-
-        unsigned int start = 0;
-        for (size_t i = 0; i < ends.size(); i++) {
-          _vertices_tristrip_pcollector.add_level(ends[i] - start);
-          unsigned int min = mins.get_data1i();
-          unsigned int max = maxs.get_data1i();
-          _d3d_device->DrawIndexedPrimitive
-            (D3DPT_TRIANGLESTRIP,
-             min, max - min + 1,
-             start, ends[i] - start - 2);
-
-          start = ends[i] + 2;
-        }
-
-      } else {
-        // Indexed, client arrays, individual triangle strips.
-        int stride = _data_reader->get_format()->get_array(0)->get_stride();
-        const unsigned char *index_pointer = reader->get_read_pointer(force);
-        if (index_pointer == NULL) {
-          return false;
-        }
-        D3DFORMAT index_type = get_index_type(reader->get_index_type());
-        const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-        if (vertex_pointer == NULL) {
-          return false;
-        }
-
-        unsigned int start = 0;
-        for (size_t i = 0; i < ends.size(); i++) {
-          _vertices_tristrip_pcollector.add_level(ends[i] - start);
-          unsigned int min = mins.get_data1i();
-          unsigned int max = maxs.get_data1i();
-          draw_indexed_primitive_up
-            (D3DPT_TRIANGLESTRIP,
-             min, max,
-             ends[i] - start - 2,
-             index_pointer + start * index_stride, index_type,
-             vertex_pointer, stride);
-
-          start = ends[i] + 2;
-        }
-      }
-    } else {
-      unsigned int first_vertex = reader->get_first_vertex();
-
-      if (_active_vbuffer != NULL) {
-        // Nonindexed, vbuffers, individual triangle strips.
-        unsigned int start = 0;
-        for (size_t i = 0; i < ends.size(); i++) {
-          _vertices_tristrip_pcollector.add_level(ends[i] - start);
-          _d3d_device->DrawPrimitive
-            (D3DPT_TRIANGLESTRIP,
-             first_vertex + start, ends[i] - start - 2);
-
-          start = ends[i] + 2;
-        }
-
-      } else {
-        // Nonindexed, client arrays, individual triangle strips.
-        const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-        if (vertex_pointer == NULL) {
-          return false;
-        }
-        int stride = _data_reader->get_format()->get_array(0)->get_stride();
-
-        unsigned int start = 0;
-        for (size_t i = 0; i < ends.size(); i++) {
-          _vertices_tristrip_pcollector.add_level(ends[i] - start);
-          draw_primitive_up(D3DPT_TRIANGLESTRIP, ends[i] - start - 2,
-                            first_vertex + start,
-                            ends[i] - start,
-                            vertex_pointer, stride);
-
-          start = ends[i] + 2;
-        }
-      }
-    }
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_trifans
-//       Access: Public, Virtual
-//  Description: Draws a series of triangle fans.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_trifans(const GeomPrimitivePipelineReader *reader, bool force) {
-  //PStatTimer timer(_draw_primitive_pcollector);
-  CPTA_int ends = reader->get_ends();
-  _primitive_batches_trifan_pcollector.add_level(ends.size());
-
-  if (reader->is_indexed()) {
-    int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
-    int max_vertex = reader->get_max_vertex();
-
-    // Send the individual triangle fans.  There's no connecting fans
-    // with degenerate vertices, so no worries about that.
-    int index_stride = reader->get_index_stride();
-
-    GeomVertexReader mins(reader->get_mins(), 0);
-    GeomVertexReader maxs(reader->get_maxs(), 0);
-    nassertr(reader->get_mins()->get_num_rows() == (int)ends.size() &&
-             reader->get_maxs()->get_num_rows() == (int)ends.size(), false);
-
-    if (_active_vbuffer != NULL) {
-      // Indexed, vbuffers.
-      IndexBufferContext *ibc = ((GeomPrimitive *)(reader->get_object()))->prepare_now(get_prepared_objects(), this);
-      nassertr(ibc != (IndexBufferContext *)NULL, false);
-      if (!apply_index_buffer(ibc, reader, force)) {
-        return false;
-      }
-
-      unsigned int start = 0;
-      for (size_t i = 0; i < ends.size(); i++) {
-        _vertices_trifan_pcollector.add_level(ends[i] - start);
-        unsigned int min = mins.get_data1i();
-        unsigned int max = maxs.get_data1i();
-        _d3d_device->DrawIndexedPrimitive
-          (D3DPT_TRIANGLEFAN,
-           min, max - min + 1,
-           start, ends[i] - start - 2);
-
-        start = ends[i];
-      }
-
-    } else {
-      // Indexed, client arrays.
-      int stride = _data_reader->get_format()->get_array(0)->get_stride();
-      const unsigned char *index_pointer = reader->get_read_pointer(force);
-      if (index_pointer == NULL) {
-        return false;
-      }
-      D3DFORMAT index_type = get_index_type(reader->get_index_type());
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-
-      unsigned int start = 0;
-      for (size_t i = 0; i < ends.size(); i++) {
-        _vertices_trifan_pcollector.add_level(ends[i] - start);
-        unsigned int min = mins.get_data1i();
-        unsigned int max = maxs.get_data1i();
-        draw_indexed_primitive_up
-          (D3DPT_TRIANGLEFAN,
-           min, max,
-           ends[i] - start - 2,
-           index_pointer + start * index_stride, index_type,
-           vertex_pointer, stride);
-
-        start = ends[i];
-      }
-    }
-  } else {
-    unsigned int first_vertex = reader->get_first_vertex();
-
-    if (_active_vbuffer != NULL) {
-      // Nonindexed, vbuffers.
-      unsigned int start = 0;
-      for (size_t i = 0; i < ends.size(); i++) {
-        _vertices_trifan_pcollector.add_level(ends[i] - start);
-        _d3d_device->DrawPrimitive
-          (D3DPT_TRIANGLEFAN,
-           first_vertex + start, ends[i] - start - 2);
-
-        start = ends[i];
-      }
-
-    } else {
-      // Nonindexed, client arrays.
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-      int stride = _data_reader->get_format()->get_array(0)->get_stride();
-
-      unsigned int start = 0;
-      for (size_t i = 0; i < ends.size(); i++) {
-        _vertices_trifan_pcollector.add_level(ends[i] - start);
-        draw_primitive_up(D3DPT_TRIANGLEFAN,
-                          ends[i] - start - 2,
-                          first_vertex,
-                          ends[i] - start,
-                          vertex_pointer, stride);
-        start = ends[i];
-      }
-    }
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_lines
-//       Access: Public, Virtual
-//  Description: Draws a series of disconnected line segments.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_lines(const GeomPrimitivePipelineReader *reader, bool force) {
-  //PStatTimer timer(_draw_primitive_pcollector);
-  _vertices_other_pcollector.add_level(reader->get_num_vertices());
-  _primitive_batches_other_pcollector.add_level(1);
-
-  if (reader->is_indexed()) {
-    int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
-    int max_vertex = reader->get_max_vertex();
-
-    if (_active_vbuffer != NULL) {
-      // Indexed, vbuffers.
-      IndexBufferContext *ibc = ((GeomPrimitive *)(reader->get_object()))->prepare_now(get_prepared_objects(), this);
-      nassertr(ibc != (IndexBufferContext *)NULL, false);
-      if (!apply_index_buffer(ibc, reader, force)) {
-        return false;
-      }
-
-      _d3d_device->DrawIndexedPrimitive
-        (D3DPT_LINELIST,
-         min_vertex, max_vertex - min_vertex + 1,
-         0, reader->get_num_primitives());
-
-    } else {
-      // Indexed, client arrays.
-      const unsigned char *index_pointer = reader->get_read_pointer(force);
-      if (index_pointer == NULL) {
-        return false;
-      }
-      D3DFORMAT index_type = get_index_type(reader->get_index_type());
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-
-      draw_indexed_primitive_up
-        (D3DPT_LINELIST,
-         min_vertex, max_vertex,
-         reader->get_num_primitives(),
-         index_pointer, index_type, vertex_pointer,
-         _data_reader->get_format()->get_array(0)->get_stride());
-    }
-  } else {
-    if (_active_vbuffer != NULL) {
-      // Nonindexed, vbuffers.
-      _d3d_device->DrawPrimitive
-        (D3DPT_LINELIST,
-         reader->get_first_vertex(),
-         reader->get_num_primitives());
-
-    } else {
-      // Nonindexed, client arrays.
-      const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-      if (vertex_pointer == NULL) {
-        return false;
-      }
-      draw_primitive_up(D3DPT_LINELIST, reader->get_num_primitives(),
-                        reader->get_first_vertex(),
-                        reader->get_num_vertices(),
-                        vertex_pointer,
-                        _data_reader->get_format()->get_array(0)->get_stride());
-    }
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_linestrips
-//       Access: Public, Virtual
-//  Description: Draws a series of line strips.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) {
-  return false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_points
-//       Access: Public, Virtual
-//  Description: Draws a series of disconnected points.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-draw_points(const GeomPrimitivePipelineReader *reader, bool force) {
-  //PStatTimer timer(_draw_primitive_pcollector);
-  _vertices_other_pcollector.add_level(reader->get_num_vertices());
-  _primitive_batches_other_pcollector.add_level(1);
-
-  // The munger should have protected us from indexed points--DirectX
-  // doesn't support them.
-  nassertr(!reader->is_indexed(), false);
-
-  if (_active_vbuffer != NULL) {
-    // Nonindexed, vbuffers.
-    _d3d_device->DrawPrimitive
-      (D3DPT_POINTLIST,
-       reader->get_first_vertex(),
-       reader->get_num_primitives());
-
-  } else {
-    // Nonindexed, client arrays.
-    const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
-    if (vertex_pointer == NULL) {
-      return false;
-    }
-    draw_primitive_up(D3DPT_POINTLIST, reader->get_num_primitives(),
-                      reader->get_first_vertex(),
-                      reader->get_num_vertices(),
-                      vertex_pointer,
-                      _data_reader->get_format()->get_array(0)->get_stride());
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::end_draw_primitives()
-//       Access: Public, Virtual
-//  Description: Called after a sequence of draw_primitive()
-//               functions are called, this should do whatever cleanup
-//               is appropriate.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-end_draw_primitives() {
-  // Turn off vertex blending--it seems to cause problems if we leave
-  // it on.
-  if (_vertex_blending_enabled) {
-    _d3d_device->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
-    _d3d_device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
-    _vertex_blending_enabled = false;
-  }
-
-  if (_data_reader->is_vertex_transformed()) {
-    // Restore the projection matrix that we wiped out above.
-    LMatrix4f mat = LCAST(float, _projection_mat->get_mat());
-    _d3d_device->SetTransform(D3DTS_PROJECTION,
-                              (D3DMATRIX*)mat.get_data());
-  }
-
-  GraphicsStateGuardian::end_draw_primitives();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::framebuffer_copy_to_texture
-//       Access: Public, Virtual
-//  Description: Copy the pixels within the indicated display
-//               region from the framebuffer into texture memory.
-//
-//               If z > -1, it is the cube map index into which to
-//               copy.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-framebuffer_copy_to_texture(Texture *tex, int view, int z,
-                            const DisplayRegion *dr, const RenderBuffer &rb) {
-  set_read_buffer(rb);
-
-  int orig_x = tex->get_x_size();
-  int orig_y = tex->get_y_size();
-
-  HRESULT hr;
-  int xo, yo, w, h;
-  dr->get_region_pixels_i(xo, yo, w, h);
-  tex->set_size_padded(w, h);
-
-  TextureContext *tc = tex->prepare_now(view, get_prepared_objects(), this);
-  if (tc == (TextureContext *)NULL) {
-    return false;
-  }
-  DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
-  if (!dtc->create_texture(*_screen)) {
-    // Oops, we can't re-create the texture for some reason.
-    dxgsg8_cat.error()
-      << "Unable to re-create texture " << *dtc->get_texture() << endl;
-    return false;
-  }
-
-  if (tex->get_texture_type() != Texture::TT_2d_texture) {
-    // For a specialty texture like a cube map, go the slow route
-    // through RAM for now.
-    return do_framebuffer_copy_to_ram(tex, view, z, dr, rb, true);
-  }
-  nassertr(dtc->get_d3d_2d_texture() != NULL, false);
-
-  IDirect3DSurface8 *tex_level_0;
-  hr = dtc->get_d3d_2d_texture()->GetSurfaceLevel(0, &tex_level_0);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error() << "GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  // If the texture is the wrong size, we need to do something about it.
-  D3DSURFACE_DESC texdesc;
-  hr = tex_level_0->GetDesc(&texdesc);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error() << "GetDesc failed in copy_texture" << D3DERRORSTRING(hr);
-    SAFE_RELEASE(tex_level_0);
-    return false;
-  }
-  if ((texdesc.Width != tex->get_x_size())||(texdesc.Height != tex->get_y_size())) {
-    if ((orig_x != tex->get_x_size()) || (orig_y != tex->get_y_size())) {
-      // Texture might be wrong size because we resized it and need to recreate.
-      SAFE_RELEASE(tex_level_0);
-      if (!dtc->create_texture(*_screen)) {
-        // Oops, we can't re-create the texture for some reason.
-        dxgsg8_cat.error()
-          << "Unable to re-create texture " << *dtc->get_texture() << endl;
-        return false;
-      }
-      hr = dtc->get_d3d_2d_texture()->GetSurfaceLevel(0, &tex_level_0);
-      if (FAILED(hr)) {
-        dxgsg8_cat.error() << "GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr);
-        return false;
-      }
-      hr = tex_level_0->GetDesc(&texdesc);
-      if (FAILED(hr)) {
-        dxgsg8_cat.error() << "GetDesc 2 failed in copy_texture" << D3DERRORSTRING(hr);
-        SAFE_RELEASE(tex_level_0);
-        return false;
-      }
-    }
-    if ((texdesc.Width != tex->get_x_size())||(texdesc.Height != tex->get_y_size())) {
-      // If it's still the wrong size, it's because driver can't create size
-      // that we want.  In that case, there's no helping it, we have to give up.
-      dxgsg8_cat.error()
-        << "Unable to copy to texture, texture is wrong size: " << *dtc->get_texture() << endl;
-      SAFE_RELEASE(tex_level_0);
-      return false;
-    }
-  }
-
-  IDirect3DSurface8 *render_target;
-  hr = _d3d_device->GetRenderTarget(&render_target);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error() << "GetRenderTgt failed in copy_texture" << D3DERRORSTRING(hr);
-    SAFE_RELEASE(tex_level_0);
-    return false;
-  }
-
-  RECT src_rect;
-
-  src_rect.left = xo;
-  src_rect.right = xo+w;
-  src_rect.top = yo;
-  src_rect.bottom = yo+h;
-
-  // now copy from fb to tex
-  bool okflag = true;
-  hr = _d3d_device->CopyRects(render_target, &src_rect, 1, tex_level_0, 0);
-  if (FAILED(hr)) {
-    dxgsg8_cat.info()
-      << "CopyRects failed in copy_texture " << D3DERRORSTRING(hr);
-    okflag = framebuffer_copy_to_ram(tex, view, z, dr, rb);
-  }
-
-  SAFE_RELEASE(render_target);
-  SAFE_RELEASE(tex_level_0);
-
-  if (okflag) {
-    dtc->mark_loaded();
-    dtc->enqueue_lru(&_prepared_objects->_graphics_memory_lru);
-
-  } else {
-    // The copy failed.  Fall back to copying it to RAM and back.
-    // Terribly slow, but what are you going to do?
-    return do_framebuffer_copy_to_ram(tex, view, z, dr, rb, true);
-  }
-
-  return true;
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::framebuffer_copy_to_ram
-//       Access: Public, Virtual
-//  Description: Copy the pixels within the indicated display region
-//               from the framebuffer into system memory, not texture
-//               memory.  Returns true on success, false on failure.
-//
-//               This completely redefines the ram image of the
-//               indicated texture.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-framebuffer_copy_to_ram(Texture *tex, int view, int z,
-                        const DisplayRegion *dr, const RenderBuffer &rb) {
-  return do_framebuffer_copy_to_ram(tex, view, z, dr, rb, false);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_framebuffer_copy_to_ram
-//       Access: Public
-//  Description: This is the implementation of
-//               framebuffer_copy_to_ram(); it adds one additional
-//               parameter, which should be true if the framebuffer is
-//               to be inverted during the copy (as in the same way it
-//               copies to texture memory).
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-do_framebuffer_copy_to_ram(Texture *tex, int view, int z,
-                           const DisplayRegion *dr, const RenderBuffer &rb,
-                           bool inverted) {
-  set_read_buffer(rb);
-
-  RECT rect;
-  nassertr(tex != NULL && dr != NULL, false);
-
-  int xo, yo, w, h;
-  dr->get_region_pixels_i(xo, yo, w, h);
-
-  Texture::Format format = tex->get_format();
-  Texture::ComponentType component_type = tex->get_component_type();
-
-  switch (format) {
-  case Texture::F_depth_stencil:
-    // Sorry, not (yet?) supported in pandadx.
-    return false;
-
-  default:
-    format = Texture::F_rgb;
-    component_type = Texture::T_unsigned_byte;
-  }
-
-  Texture::TextureType texture_type;
-  if (z >= 0) {
-    texture_type = Texture::TT_cube_map;
-  } else {
-    texture_type = Texture::TT_2d_texture;
-  }
-
-  if (tex->get_x_size() != w || tex->get_y_size() != h ||
-      tex->get_component_type() != component_type ||
-      tex->get_format() != format ||
-      tex->get_texture_type() != texture_type) {
-    // Re-setup the texture; its properties have changed.
-    tex->setup_texture(texture_type, w, h, tex->get_z_size(),
-                       component_type, format);
-  }
-
-  rect.top = yo;
-  rect.left = xo;
-  rect.right = xo + w;
-  rect.bottom = yo + h;
-  bool copy_inverted = false;
-
-  IDirect3DSurface8 *temp_surface = NULL;
-  HRESULT hr;
-
-  // Note if you try to grab the backbuffer and full-screen
-  // anti-aliasing is on, the backbuffer might be larger than the
-  // window size.  For screenshots it's safer to get the front buffer.
-  if (_cur_read_pixel_buffer & RenderBuffer::T_back) {
-    IDirect3DSurface8 *backbuffer = NULL;
-    // GetRenderTarget() seems to be a little more reliable than
-    // GetBackBuffer().  Might just be related to the swap_chain
-    // thing.
-    hr = _d3d_device->GetRenderTarget(&backbuffer);
-
-    if (FAILED(hr)) {
-      dxgsg8_cat.error() << "GetRenderTarget failed" << D3DERRORSTRING(hr);
-      return false;
-    }
-
-    // Since we might not be able to Lock the back buffer, we will
-    // need to copy it to a temporary surface of the appropriate type
-    // first.
-    hr = _d3d_device->CreateImageSurface(w, h, _screen->_display_mode.Format,
-                                         &temp_surface);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "CreateImageSurface failed in copy_pixel_buffer()"
-        << D3DERRORSTRING(hr);
-      backbuffer->Release();
-      return false;
-    }
-
-    // Now we must copy from the backbuffer to our temporary surface.
-    hr = _d3d_device->CopyRects(backbuffer, &rect, 1, temp_surface, NULL);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error() << "CopyRects failed" << D3DERRORSTRING(hr);
-      temp_surface->Release();
-      backbuffer->Release();
-      return false;
-    }
-
-    copy_inverted = true;
-
-    RELEASE(backbuffer, dxgsg8, "backbuffer", RELEASE_ONCE);
-
-  } else if (_cur_read_pixel_buffer & RenderBuffer::T_front) {
-
-    if (_screen->_presentation_params.Windowed) {
-      // GetFrontBuffer() retrieves the entire desktop for a monitor,
-      // so we need to reserve space for that.
-
-      // We have to use GetMonitorInfo(), since this GSG may not be
-      // for the primary monitor.
-      MONITORINFO minfo;
-      minfo.cbSize = sizeof(MONITORINFO);
-      GetMonitorInfo(_screen->_monitor, &minfo);
-
-      w = RECT_XSIZE(minfo.rcMonitor);
-      h = RECT_YSIZE(minfo.rcMonitor);
-
-      // set rect to client area of window in scrn coords
-      ClientToScreen(_screen->_window, (POINT*)&rect.left);
-      ClientToScreen(_screen->_window, (POINT*)&rect.right);
-    }
-
-    // For GetFrontBuffer(), we need a temporary surface of type
-    // A8R8G8B8.  Unlike GetBackBuffer(), GetFrontBuffer() implicitly
-    // performs a copy.
-    hr = _d3d_device->CreateImageSurface(w, h, D3DFMT_A8R8G8B8, &temp_surface);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "CreateImageSurface failed in copy_pixel_buffer()"
-        << D3DERRORSTRING(hr);
-      return false;
-    }
-
-    hr = _d3d_device->GetFrontBuffer(temp_surface);
-
-    if (hr == D3DERR_DEVICELOST) {
-      dxgsg8_cat.error()
-        << "copy_pixel_buffer failed: device lost\n";
-      temp_surface->Release();
-      return false;
-    }
-
-    copy_inverted = true;
-
-  } else {
-    dxgsg8_cat.error()
-      << "copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
-    temp_surface->Release();
-    return false;
-  }
-
-  if (inverted) {
-    copy_inverted = !copy_inverted;
-  }
-  DXTextureContext8::d3d_surface_to_texture(rect, temp_surface,
-                                            copy_inverted, tex, view, z);
-
-  RELEASE(temp_surface, dxgsg8, "temp_surface", RELEASE_ONCE);
-
-  nassertr(tex->has_ram_image(), false);
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::reset
-//       Access: Public, Virtual
-//  Description: Resets all internal state as if the gsg were newly
-//               created.  The GraphicsWindow pointer represents a
-//               typical window that might be used for this context;
-//               it may be required to set up the frame buffer
-//               properly the first time.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-reset() {
-  GraphicsStateGuardian::reset();
-
-  _auto_rescale_normal = false;
-
-  // overwrite gsg defaults with these values
-
-  HRESULT hr;
-
-  // make sure gsg passes all current state down to us
-  // set_state_and_transform(RenderState::make_empty(),
-  // TransformState::make_identity());
-  // want gsg to pass all state settings down so any non-matching defaults we set here get overwritten
-
-  if (_d3d_device == NULL) {
-    return;
-  }
-
-  nassertv(_screen->_d3d8 != NULL);
-
-  D3DCAPS8 d3d_caps;
-  _d3d_device->GetDeviceCaps(&d3d_caps);
-
-  if (dxgsg8_cat.is_debug()) {
-    dxgsg8_cat.debug()
-      << "\nHwTransformAndLight = " << ((d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
-      << "\nMaxTextureWidth = " << d3d_caps.MaxTextureWidth
-      << "\nMaxTextureHeight = " << d3d_caps.MaxTextureHeight
-      << "\nMaxVolumeExtent = " << d3d_caps.MaxVolumeExtent
-      << "\nMaxTextureAspectRatio = " << d3d_caps.MaxTextureAspectRatio
-      << "\nTexCoordCount = " << (d3d_caps.FVFCaps & D3DFVFCAPS_TEXCOORDCOUNTMASK)
-      << "\nMaxTextureBlendStages = " << d3d_caps.MaxTextureBlendStages
-      << "\nMaxSimultaneousTextures = " << d3d_caps.MaxSimultaneousTextures
-      << "\nMaxActiveLights = " << d3d_caps.MaxActiveLights
-      << "\nMaxUserClipPlanes = " << d3d_caps.MaxUserClipPlanes
-      << "\nMaxVertexBlendMatrices = " << d3d_caps.MaxVertexBlendMatrices
-      << "\nMaxVertexBlendMatrixIndex = " << d3d_caps.MaxVertexBlendMatrixIndex
-      << "\nMaxPointSize = " << d3d_caps.MaxPointSize
-      << "\nMaxPrimitiveCount = " << d3d_caps.MaxPrimitiveCount
-      << "\nMaxVertexIndex = " << d3d_caps.MaxVertexIndex
-      << "\nMaxStreams = " << d3d_caps.MaxStreams
-      << "\nMaxStreamStride = " << d3d_caps.MaxStreamStride
-      << "\nD3DTEXOPCAPS_MULTIPLYADD = " << ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_MULTIPLYADD) != 0)
-      << "\nD3DTEXOPCAPS_LERP = " << ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0)
-      << "\nD3DPMISCCAPS_TSSARGTEMP = " << ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0)
-      << "\nVertexShaderVersion = " << D3DSHADER_VERSION_MAJOR (d3d_caps.VertexShaderVersion) << "." << D3DSHADER_VERSION_MINOR (d3d_caps.VertexShaderVersion)
-      << "\nPixelShaderVersion = " << D3DSHADER_VERSION_MAJOR (d3d_caps.PixelShaderVersion) << "." << D3DSHADER_VERSION_MINOR (d3d_caps.PixelShaderVersion)
-      << "\nMaxVertexShaderConst = " << d3d_caps.MaxVertexShaderConst
-      << "\n";
-  }
-
-  if (support_stencil) {
-    int min_stencil = D3DSTENCILCAPS_ZERO | D3DSTENCILCAPS_REPLACE | D3DSTENCILCAPS_INCR | D3DSTENCILCAPS_DECR;
-    if ((d3d_caps.StencilCaps & min_stencil) == min_stencil) {
-      if (dxgsg8_cat.is_debug()) {
-        dxgsg8_cat.debug()
-          << "Checking for stencil; mode = "
-          << D3DFormatStr(_screen->_presentation_params.AutoDepthStencilFormat)
-          << "\n";
-      }
-      switch (_screen->_presentation_params.AutoDepthStencilFormat) {
-        // These are the only formats that support stencil.
-      case D3DFMT_D15S1:
-      case D3DFMT_D24S8:
-      case D3DFMT_D24X4S4:
-        _supports_stencil = true;
-        if (dxgsg8_cat.is_debug()) {
-          dxgsg8_cat.debug()
-            << "Stencils supported.\n";
-        }
-        break;
-
-      default:
-        if (dxgsg8_cat.is_debug()) {
-          dxgsg8_cat.debug()
-            << "Stencils NOT supported.\n";
-        }
-      }
-    }
-  }
-
-  _max_vertices_per_array = d3d_caps.MaxVertexIndex;
-  _max_vertices_per_primitive = d3d_caps.MaxPrimitiveCount;
-
-  _max_texture_stages = d3d_caps.MaxSimultaneousTextures;
-
-  _max_texture_dimension = min(d3d_caps.MaxTextureWidth, d3d_caps.MaxTextureHeight);
-
-  _supports_texture_combine = ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0);
-  _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
-  _supports_texture_dot3 = true;
-
-  // check for render to texture support
-  D3DDEVICE_CREATION_PARAMETERS creation_parameters;
-
-  _supports_render_texture = false;
-  _screen->_render_to_texture_d3d_format = D3DFMT_UNKNOWN;
-  _screen->_framebuffer_d3d_format = D3DFMT_UNKNOWN;
-
-  #define TOTAL_RENDER_TO_TEXTURE_FORMATS 3
-
-  D3DFORMAT render_to_texture_formats [TOTAL_RENDER_TO_TEXTURE_FORMATS] =
-  {
-    D3DFMT_A8R8G8B8,  // check for this format first
-    D3DFMT_X8R8G8B8,
-    D3DFMT_UNKNOWN,   // place holder for _screen->_display_mode.Format
-  };
-
-  render_to_texture_formats [TOTAL_RENDER_TO_TEXTURE_FORMATS - 1] = _screen->_display_mode.Format;
-
-  hr = _d3d_device->GetCreationParameters (&creation_parameters);
-  if (SUCCEEDED (hr)) {
-    _screen->_framebuffer_d3d_format = _screen->_display_mode.Format;
-
-    int index;
-    for (index = 0; index < TOTAL_RENDER_TO_TEXTURE_FORMATS; index++) {
-      hr = _screen->_d3d8->CheckDeviceFormat (
-          creation_parameters.AdapterOrdinal,
-          creation_parameters.DeviceType,
-          _screen->_display_mode.Format,
-          D3DUSAGE_RENDERTARGET,
-          D3DRTYPE_TEXTURE,
-          render_to_texture_formats [index]);
-      if (SUCCEEDED (hr)) {
-        _screen->_render_to_texture_d3d_format = render_to_texture_formats [index];
-        _supports_render_texture = true;
-      }
-      if (_supports_render_texture) {
-        break;
-      }
-    }
-  }
-  if (dxgsg8_cat.is_debug()) {
-    dxgsg8_cat.debug() << "Render to Texture Support = " << _supports_render_texture << "\n";
-  }
-
-  _supports_3d_texture = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) != 0);
-  if (_supports_3d_texture) {
-    _max_3d_texture_dimension = d3d_caps.MaxVolumeExtent;
-  }
-  _supports_cube_map = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) != 0);
-  if (_supports_cube_map) {
-    _max_cube_map_dimension = _max_texture_dimension;
-  }
-
-  _num_active_texture_stages = 0;
-
-  _max_lights = (int)d3d_caps.MaxActiveLights;
-  _max_clip_planes = (int)d3d_caps.MaxUserClipPlanes;
-  _max_vertex_transforms = d3d_caps.MaxVertexBlendMatrices;
-  _max_vertex_transform_indices = d3d_caps.MaxVertexBlendMatrixIndex;
-
-  _d3d_device->SetRenderState(D3DRS_AMBIENT, 0x0);
-
-  _clip_plane_bits = 0;
-  _d3d_device->SetRenderState(D3DRS_CLIPPLANEENABLE , 0x0);
-
-  _d3d_device->SetRenderState(D3DRS_CLIPPING, true);
-
-  _d3d_device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
-
-  _d3d_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
-
-  _d3d_device->SetRenderState(D3DRS_EDGEANTIALIAS, false);
-
-  _d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
-
-  _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
-
-  _d3d_device->SetRenderState(D3DRS_FOGENABLE, FALSE);
-
-  _has_scene_graph_color = false;
-
-  _last_testcooplevel_result = D3D_OK;
-
-  for(int i = 0; i < MAX_POSSIBLE_TEXFMTS; i++) {
-    // look for all possible DX8 texture fmts
-    D3DFORMAT_FLAG fmtflag = D3DFORMAT_FLAG(1 << i);
-    hr = _screen->_d3d8->CheckDeviceFormat(_screen->_card_id, D3DDEVTYPE_HAL, _screen->_display_mode.Format,
-                                           0x0, D3DRTYPE_TEXTURE, g_D3DFORMATmap[fmtflag]);
-    if (SUCCEEDED(hr)){
-      _screen->_supported_tex_formats_mask |= fmtflag;
-    }
-  }
-
-  // check if compressed textures are supported
-  #define CHECK_FOR_DXTVERSION(num) \
-  if (_screen->_supported_tex_formats_mask & DXT##num##_FLAG) {\
-    if (dxgsg8_cat.is_debug()) {\
-      dxgsg8_cat.debug() << "Compressed texture format DXT" << #num << " supported \n";\
-    }\
-    _supports_compressed_texture = true;\
-    _compressed_texture_formats.set_bit(Texture::CM_dxt##num);\
-  }
-
-  CHECK_FOR_DXTVERSION(1)
-  CHECK_FOR_DXTVERSION(2)
-  CHECK_FOR_DXTVERSION(3)
-  CHECK_FOR_DXTVERSION(4)
-  CHECK_FOR_DXTVERSION(5)
-
-  #undef CHECK_FOR_DXTVERSION
-
-  // s3 virge drivers sometimes give crap values for these
-  if (_screen->_d3dcaps.MaxTextureWidth == 0)
-    _screen->_d3dcaps.MaxTextureWidth = 256;
-
-  if (_screen->_d3dcaps.MaxTextureHeight == 0)
-    _screen->_d3dcaps.MaxTextureHeight = 256;
-
-  if (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) {
-    // Watch out for drivers that emulate per-pixel fog with
-    // per-vertex fog (Riva128, Matrox Millen G200).  Some of these
-    // require gouraud-shading to be set to work, as if you were using
-    // vertex fog
-    _do_fog_type = PerPixelFog;
-  } else {
-    // every card is going to have vertex fog, since it's implemented
-    // in d3d runtime.
-    nassertv((_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0);
-
-    // vertex fog may look crappy if you have large polygons in the
-    // foreground and they get clipped, so you may want to disable it
-
-    if (dx_no_vertex_fog) {
-      _do_fog_type = None;
-    } else {
-      _do_fog_type = PerVertexFog;
-
-      // range-based fog only works with vertex fog in dx7/8
-      if (dx_use_rangebased_fog && (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)) {
-        _d3d_device->SetRenderState(D3DRS_RANGEFOGENABLE, true);
-      }
-    }
-  }
-
-  _screen->_can_direct_disable_color_writes = ((_screen->_d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0);
-
-  // Lighting, let's turn it off initially.
-  _d3d_device->SetRenderState(D3DRS_LIGHTING, false);
-
-  // turn on dithering if the rendertarget is < 8bits/color channel
-  bool dither_enabled = ((!dx_no_dithering) && IS_16BPP_DISPLAY_FORMAT(_screen->_presentation_params.BackBufferFormat)
-                         && (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_DITHER));
-  _d3d_device->SetRenderState(D3DRS_DITHERENABLE, dither_enabled);
-
-  _d3d_device->SetRenderState(D3DRS_CLIPPING, true);
-
-  // Stencil test is off by default
-  _d3d_device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
-
-  // Antialiasing.
-  _d3d_device->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);
-
-  _current_fill_mode = RenderModeAttrib::M_filled;
-  _d3d_device->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
-  _d3d_device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);  // disables texturing
-
-  _cull_face_mode = CullFaceAttrib::M_cull_none;
-  _d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
-
-  _d3d_device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);
-  _d3d_device->SetRenderState(D3DRS_ALPHAREF, 255);
-  _d3d_device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
-
-  // this is a new DX8 state that lets you do additional operations other than ADD (e.g. subtract/max/min)
-  // must check (_screen->_d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_BLENDOP) (yes on GF2/Radeon8500, no on TNT)
-  _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
-
-  PRINT_REFCNT(dxgsg8, _d3d_device);
-
-  // Now that the GSG has been initialized, make it available for
-  // optimizations.
-  add_gsg(this);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::apply_fog
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-apply_fog(Fog *fog) {
-  if (_do_fog_type == None)
-    return;
-
-  Fog::Mode panda_fogmode = fog->get_mode();
-  D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode);
-
-  _d3d_device->SetRenderState((D3DRENDERSTATETYPE)_do_fog_type, d3dfogmode);
-
-  const LColor &fog_colr = fog->get_color();
-  _d3d_device->SetRenderState(D3DRS_FOGCOLOR,
-                              MY_D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f));  // Alpha bits are not used
-
-  // do we need to adjust fog start/end values based on D3DPRASTERCAPS_WFOG/D3DPRASTERCAPS_ZFOG ?
-  // if not WFOG, then docs say we need to adjust values to range [0, 1]
-
-  switch (panda_fogmode) {
-  case Fog::M_linear:
-    {
-      PN_stdfloat onset, opaque;
-      fog->get_linear_range(onset, opaque);
-
-      _d3d_device->SetRenderState(D3DRS_FOGSTART,
-                                  *((LPDWORD) (&onset)));
-      _d3d_device->SetRenderState(D3DRS_FOGEND,
-                                  *((LPDWORD) (&opaque)));
-    }
-    break;
-  case Fog::M_exponential:
-  case Fog::M_exponential_squared:
-    {
-      // Exponential fog is always camera-relative.
-      PN_stdfloat fog_density = fog->get_exp_density();
-      _d3d_device->SetRenderState(D3DRS_FOGDENSITY,
-                                  *((LPDWORD) (&fog_density)));
-    }
-    break;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_transform
-//       Access: Protected
-//  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 DXGraphicsStateGuardian8::
-do_issue_transform() {
-  const TransformState *transform = _internal_transform;
-  DO_PSTATS_STUFF(_transform_state_pcollector.add_level(1));
-
-  LMatrix4f mat = LCAST(float, transform->get_mat());
-  const D3DMATRIX *d3d_mat = (const D3DMATRIX *)mat.get_data();
-  _d3d_device->SetTransform(D3DTS_WORLD, d3d_mat);
-  _transform_stale = false;
-
-  if (_auto_rescale_normal) {
-    do_auto_rescale_normal();
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_alpha_test
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_alpha_test() {
-  const AlphaTestAttrib *target_alpha_test = DCAST(AlphaTestAttrib, _target_rs->get_attrib_def(AlphaTestAttrib::get_class_slot()));
-  AlphaTestAttrib::PandaCompareFunc mode = target_alpha_test->get_mode();
-  if (mode == AlphaTestAttrib::M_none) {
-    _d3d_device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
-
-  } else {
-    //  AlphaTestAttrib::PandaCompareFunc === D3DCMPFUNC
-    _d3d_device->SetRenderState(D3DRS_ALPHAFUNC, (D3DCMPFUNC)mode);
-    _d3d_device->SetRenderState(D3DRS_ALPHAREF, (UINT) (target_alpha_test->get_reference_alpha()*255.0f));  //d3d uses 0x0-0xFF, not a float
-    _d3d_device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_render_mode
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_render_mode() {
-  const RenderModeAttrib *target_render_mode = DCAST(RenderModeAttrib, _target_rs->get_attrib_def(RenderModeAttrib::get_class_slot()));
-  RenderModeAttrib::Mode mode = target_render_mode->get_mode();
-
-  switch (mode) {
-  case RenderModeAttrib::M_unchanged:
-  case RenderModeAttrib::M_filled:
-  case RenderModeAttrib::M_filled_flat:
-    _d3d_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
-    break;
-
-  case RenderModeAttrib::M_wireframe:
-    _d3d_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
-    break;
-
-  case RenderModeAttrib::M_point:
-    _d3d_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
-    break;
-
-  default:
-    dxgsg8_cat.error()
-      << "Unknown render mode " << (int)mode << endl;
-  }
-
-  // This might also specify the point size.
-  PN_stdfloat point_size = target_render_mode->get_thickness();
-  _d3d_device->SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&point_size));
-
-  if (target_render_mode->get_perspective()) {
-    _d3d_device->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
-
-    LVector3 height(0.0f, point_size, 1.0f);
-    height = height * _projection_mat->get_mat();
-    PN_stdfloat s = height[1] / point_size;
-
-    PN_stdfloat zero = 0.0f;
-    PN_stdfloat one_over_s2 = 1.0f / (s * s);
-    _d3d_device->SetRenderState(D3DRS_POINTSCALE_A, *((DWORD*)&zero));
-    _d3d_device->SetRenderState(D3DRS_POINTSCALE_B, *((DWORD*)&zero));
-    _d3d_device->SetRenderState(D3DRS_POINTSCALE_C, *((DWORD*)&one_over_s2));
-
-  } else {
-    _d3d_device->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
-  }
-
-  _current_fill_mode = mode;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_rescale_normal
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_rescale_normal() {
-  const RescaleNormalAttrib *target_rescale_normal = DCAST(RescaleNormalAttrib, _target_rs->get_attrib_def(RescaleNormalAttrib::get_class_slot()));
-  RescaleNormalAttrib::Mode mode = target_rescale_normal->get_mode();
-
-  _auto_rescale_normal = false;
-
-  switch (mode) {
-  case RescaleNormalAttrib::M_none:
-    _d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, false);
-    break;
-
-  case RescaleNormalAttrib::M_rescale:
-  case RescaleNormalAttrib::M_normalize:
-    _d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
-    break;
-
-  case RescaleNormalAttrib::M_auto:
-    _auto_rescale_normal = true;
-    do_auto_rescale_normal();
-    break;
-
-  default:
-    dxgsg8_cat.error()
-      << "Unknown rescale_normal mode " << (int)mode << endl;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_depth_test
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_depth_test() {
-  const DepthTestAttrib *target_depth_test = DCAST(DepthTestAttrib, _target_rs->get_attrib_def(DepthTestAttrib::get_class_slot()));
-  DepthTestAttrib::PandaCompareFunc mode = target_depth_test->get_mode();
-  if (mode == DepthTestAttrib::M_none) {
-    _d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
-  } else {
-    _d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
-    _d3d_device->SetRenderState(D3DRS_ZFUNC, (D3DCMPFUNC) mode);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_depth_write
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_depth_write() {
-  const DepthWriteAttrib *target_depth_write = DCAST(DepthWriteAttrib, _target_rs->get_attrib_def(DepthWriteAttrib::get_class_slot()));
-  if (target_depth_write->get_mode() == DepthWriteAttrib::M_on) {
-    _d3d_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
-  } else {
-    _d3d_device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_cull_face
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_cull_face() {
-  const CullFaceAttrib *target_cull_face = DCAST(CullFaceAttrib, _target_rs->get_attrib_def(CullFaceAttrib::get_class_slot()));
-  _cull_face_mode = target_cull_face->get_effective_mode();
-
-  switch (_cull_face_mode) {
-  case CullFaceAttrib::M_cull_none:
-    _d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
-    break;
-  case CullFaceAttrib::M_cull_clockwise:
-    _d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
-    break;
-  case CullFaceAttrib::M_cull_counter_clockwise:
-    _d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
-    break;
-  default:
-    dxgsg8_cat.error()
-      << "invalid cull face mode " << (int)_cull_face_mode << endl;
-    break;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_fog
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_fog() {
-  const FogAttrib *target_fog = DCAST(FogAttrib, _target_rs->get_attrib_def(FogAttrib::get_class_slot()));
-  if (!target_fog->is_off()) {
-    _d3d_device->SetRenderState(D3DRS_FOGENABLE, TRUE);
-    Fog *fog = target_fog->get_fog();
-    nassertv(fog != (Fog *)NULL);
-    apply_fog(fog);
-  } else {
-    _d3d_device->SetRenderState(D3DRS_FOGENABLE, FALSE);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_depth_offset
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_depth_offset() {
-  const DepthOffsetAttrib *target_depth_offset = DCAST(DepthOffsetAttrib, _target_rs->get_attrib_def(DepthOffsetAttrib::get_class_slot()));
-  int offset = target_depth_offset->get_offset();
-  _d3d_device->SetRenderState(D3DRS_ZBIAS, offset);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_shade_model
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_shade_model() {
-  const ShadeModelAttrib *target_shade_model = DCAST(ShadeModelAttrib, _target_rs->get_attrib_def(ShadeModelAttrib::get_class_slot()));
-  switch (target_shade_model->get_mode()) {
-  case ShadeModelAttrib::M_smooth:
-    _d3d_device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
-    break;
-
-  case ShadeModelAttrib::M_flat:
-    _d3d_device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
-    break;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_state_and_transform
-//       Access: Public, Virtual
-//  Description: Simultaneously resets the render state and the
-//               transform state.
-//
-//               This transform specified is the "internal" net
-//               transform, already converted into the GSG's internal
-//               coordinate space by composing it to
-//               get_cs_transform().  (Previously, this used to be the
-//               "external" net transform, with the assumption that
-//               that GSG would convert it internally, but that is no
-//               longer the case.)
-//
-//               Special case: if (state==NULL), then the target
-//               state is already stored in _target.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_state_and_transform(const RenderState *target,
-                        const TransformState *transform) {
-#ifndef NDEBUG
-  if (gsg_cat.is_spam()) {
-    gsg_cat.spam() << "Setting GSG state to " << (void *)target << ":\n";
-    target->write(gsg_cat.spam(false), 2);
-  }
-#endif
-  _state_pcollector.add_level(1);
-  PStatTimer timer1(_draw_set_state_pcollector);
-
-  if (transform != _internal_transform) {
-    //PStatTimer timer(_draw_set_state_transform_pcollector);
-    _state_pcollector.add_level(1);
-    _internal_transform = transform;
-    do_issue_transform();
-  }
-
-  if (target == _state_rs) {
-    return;
-  }
-  _target_rs = target;
-
-  int alpha_test_slot = AlphaTestAttrib::get_class_slot();
-  if (_target_rs->get_attrib(alpha_test_slot) != _state_rs->get_attrib(alpha_test_slot) ||
-      !_state_mask.get_bit(alpha_test_slot)) {
-    //PStatTimer timer(_draw_set_state_alpha_test_pcollector);
-    do_issue_alpha_test();
-    _state_mask.set_bit(alpha_test_slot);
-  }
-
-  int clip_plane_slot = ClipPlaneAttrib::get_class_slot();
-  if (_target_rs->get_attrib(clip_plane_slot) != _state_rs->get_attrib(clip_plane_slot) ||
-      !_state_mask.get_bit(clip_plane_slot)) {
-    //PStatTimer timer(_draw_set_state_clip_plane_pcollector);
-    do_issue_clip_plane();
-    _state_mask.set_bit(clip_plane_slot);
-  }
-
-  int color_slot = ColorAttrib::get_class_slot();
-  int color_scale_slot = ColorScaleAttrib::get_class_slot();
-  if (_target_rs->get_attrib(color_slot) != _state_rs->get_attrib(color_slot) ||
-      _target_rs->get_attrib(color_scale_slot) != _state_rs->get_attrib(color_scale_slot) ||
-      !_state_mask.get_bit(color_slot) ||
-      !_state_mask.get_bit(color_scale_slot)) {
-    //PStatTimer timer(_draw_set_state_color_pcollector);
-    do_issue_color();
-    do_issue_color_scale();
-    _state_mask.set_bit(color_slot);
-    _state_mask.set_bit(color_scale_slot);
-  }
-
-  int cull_face_slot = CullFaceAttrib::get_class_slot();
-  if (_target_rs->get_attrib(cull_face_slot) != _state_rs->get_attrib(cull_face_slot) ||
-      !_state_mask.get_bit(cull_face_slot)) {
-    //PStatTimer timer(_draw_set_state_cull_face_pcollector);
-    do_issue_cull_face();
-    _state_mask.set_bit(cull_face_slot);
-  }
-
-  int depth_offset_slot = DepthOffsetAttrib::get_class_slot();
-  if (_target_rs->get_attrib(depth_offset_slot) != _state_rs->get_attrib(depth_offset_slot) ||
-      !_state_mask.get_bit(depth_offset_slot)) {
-    //PStatTimer timer(_draw_set_state_depth_offset_pcollector);
-    do_issue_depth_offset();
-    _state_mask.set_bit(depth_offset_slot);
-  }
-
-  int depth_test_slot = DepthTestAttrib::get_class_slot();
-  if (_target_rs->get_attrib(depth_test_slot) != _state_rs->get_attrib(depth_test_slot) ||
-      !_state_mask.get_bit(depth_test_slot)) {
-    //PStatTimer timer(_draw_set_state_depth_test_pcollector);
-    do_issue_depth_test();
-    _state_mask.set_bit(depth_test_slot);
-  }
-
-  int depth_write_slot = DepthWriteAttrib::get_class_slot();
-  if (_target_rs->get_attrib(depth_write_slot) != _state_rs->get_attrib(depth_write_slot) ||
-      !_state_mask.get_bit(depth_write_slot)) {
-    //PStatTimer timer(_draw_set_state_depth_write_pcollector);
-    do_issue_depth_write();
-    _state_mask.set_bit(depth_write_slot);
-  }
-
-  int fog_slot = FogAttrib::get_class_slot();
-  if (_target_rs->get_attrib(fog_slot) != _state_rs->get_attrib(fog_slot) ||
-      !_state_mask.get_bit(fog_slot)) {
-    //PStatTimer timer(_draw_set_state_fog_pcollector);
-    do_issue_fog();
-    _state_mask.set_bit(fog_slot);
-  }
-
-  int render_mode_slot = RenderModeAttrib::get_class_slot();
-  if (_target_rs->get_attrib(render_mode_slot) != _state_rs->get_attrib(render_mode_slot) ||
-      !_state_mask.get_bit(render_mode_slot)) {
-    //PStatTimer timer(_draw_set_state_render_mode_pcollector);
-    do_issue_render_mode();
-    _state_mask.set_bit(render_mode_slot);
-  }
-
-  int rescale_normal_slot = RescaleNormalAttrib::get_class_slot();
-  if (_target_rs->get_attrib(rescale_normal_slot) != _state_rs->get_attrib(rescale_normal_slot) ||
-      !_state_mask.get_bit(rescale_normal_slot)) {
-    //PStatTimer timer(_draw_set_state_rescale_normal_pcollector);
-    do_issue_rescale_normal();
-    _state_mask.set_bit(rescale_normal_slot);
-  }
-
-  int shade_model_slot = ShadeModelAttrib::get_class_slot();
-  if (_target_rs->get_attrib(shade_model_slot) != _state_rs->get_attrib(shade_model_slot) ||
-      !_state_mask.get_bit(shade_model_slot)) {
-    //PStatTimer timer(_draw_set_state_shade_model_pcollector);
-    do_issue_shade_model();
-    _state_mask.set_bit(shade_model_slot);
-  }
-
-  int transparency_slot = TransparencyAttrib::get_class_slot();
-  int color_write_slot = ColorWriteAttrib::get_class_slot();
-  int color_blend_slot = ColorBlendAttrib::get_class_slot();
-  if (_target_rs->get_attrib(transparency_slot) != _state_rs->get_attrib(transparency_slot) ||
-      _target_rs->get_attrib(color_write_slot) != _state_rs->get_attrib(color_write_slot) ||
-      _target_rs->get_attrib(color_blend_slot) != _state_rs->get_attrib(color_blend_slot) ||
-      !_state_mask.get_bit(transparency_slot) ||
-      !_state_mask.get_bit(color_write_slot) ||
-      !_state_mask.get_bit(color_blend_slot)) {
-    //PStatTimer timer(_draw_set_state_blending_pcollector);
-    do_issue_blending();
-    _state_mask.set_bit(transparency_slot);
-    _state_mask.set_bit(color_write_slot);
-    _state_mask.set_bit(color_blend_slot);
-  }
-
-  int texture_slot = TextureAttrib::get_class_slot();
-  int tex_matrix_slot = TexMatrixAttrib::get_class_slot();
-  int tex_gen_slot = TexGenAttrib::get_class_slot();
-  if (_target_rs->get_attrib(texture_slot) != _state_rs->get_attrib(texture_slot) ||
-      _target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) ||
-      _target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) ||
-      !_state_mask.get_bit(texture_slot) ||
-      !_state_mask.get_bit(tex_matrix_slot) ||
-      !_state_mask.get_bit(tex_gen_slot)) {
-    //PStatTimer timer(_draw_set_state_texture_pcollector);
-    determine_target_texture();
-
-    // For some mysterious and disturbing reason, making this call
-    // here--which should have no effect--actually prevents the DX
-    // context from going awry.  If this call is omitted, the DX
-    // context goes foobar when switching states and refuses to draw
-    // anything at all.  I strongly suspect memory corruption
-    // somewhere, but can't locate it.
-    //    _target_texture->filter_to_max(_max_texture_stages);
-
-    do_issue_texture();
-
-    _state_texture = _target_texture;
-    _state_mask.set_bit(texture_slot);
-    _state_mask.set_bit(tex_matrix_slot);
-    _state_mask.set_bit(tex_gen_slot);
-  }
-
-  int material_slot = MaterialAttrib::get_class_slot();
-  if (_target_rs->get_attrib(material_slot) != _state_rs->get_attrib(material_slot) ||
-      !_state_mask.get_bit(material_slot)) {
-    //PStatTimer timer(_draw_set_state_material_pcollector);
-    do_issue_material();
-    _state_mask.set_bit(material_slot);
-  }
-
-  int light_slot = LightAttrib::get_class_slot();
-  if (_target_rs->get_attrib(light_slot) != _state_rs->get_attrib(light_slot) ||
-      !_state_mask.get_bit(light_slot)) {
-    //PStatTimer timer(_draw_set_state_light_pcollector);
-    do_issue_light();
-    _state_mask.set_bit(light_slot);
-  }
-
-  int stencil_slot = StencilAttrib::get_class_slot();
-  if (_target_rs->get_attrib(stencil_slot) != _state_rs->get_attrib(stencil_slot) ||
-      !_state_mask.get_bit(stencil_slot)) {
-    //PStatTimer timer(_draw_set_state_stencil_pcollector);
-    do_issue_stencil();
-    _state_mask.set_bit(stencil_slot);
-  }
-
-  int scissor_slot = ScissorAttrib::get_class_slot();
-  if (_target_rs->get_attrib(scissor_slot) != _state_rs->get_attrib(scissor_slot) ||
-      !_state_mask.get_bit(scissor_slot)) {
-    //PStatTimer timer(_draw_set_state_scissor_pcollector);
-    do_issue_scissor();
-    _state_mask.set_bit(scissor_slot);
-  }
-
-  _state_rs = _target_rs;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::bind_light
-//       Access: Public, Virtual
-//  Description: Called the first time a particular light has been
-//               bound to a given id within a frame, this should set
-//               up the associated hardware light with the light's
-//               properties.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-bind_light(PointLight *light_obj, const NodePath &light, int light_id) {
-  // Get the light in "world coordinates" (actually, view
-  // coordinates).  This means the light in the coordinate space of
-  // the camera, converted to DX's coordinate system.
-  CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path());
-  const LMatrix4 &light_mat = transform->get_mat();
-  LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
-  LPoint3f pos = LCAST(float, light_obj->get_point() * rel_mat);
-
-  D3DCOLORVALUE black;
-  black.r = black.g = black.b = black.a = 0.0f;
-  D3DLIGHT8 alight;
-  alight.Type =  D3DLIGHT_POINT;
-  alight.Diffuse  = get_light_color(light_obj);
-  alight.Ambient  =  black ;
-  LColorf color = LCAST(float, light_obj->get_specular_color());
-  alight.Specular = *(D3DCOLORVALUE *)(color.get_data());
-
-  // Position needs to specify x, y, z, and w
-  // w == 1 implies non-infinite position
-  alight.Position = *(D3DVECTOR *)pos.get_data();
-
-  alight.Range =  __D3DLIGHT_RANGE_MAX;
-  alight.Falloff =  1.0f;
-
-  const LVecBase3 &att = light_obj->get_attenuation();
-  alight.Attenuation0 = att[0];
-  alight.Attenuation1 = att[1];
-  alight.Attenuation2 = att[2];
-
-  HRESULT hr = _d3d_device->SetLight(light_id, &alight);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.warning()
-      << "Could not set light properties for " << light
-      << " to id " << light_id << ": " << D3DERRORSTRING(hr) << "\n";
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::bind_light
-//       Access: Public, Virtual
-//  Description: Called the first time a particular light has been
-//               bound to a given id within a frame, this should set
-//               up the associated hardware light with the light's
-//               properties.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) {
-  static PStatCollector _draw_set_state_light_bind_directional_pcollector("Draw:Set State:Light:Bind:Directional");
-  //PStatTimer timer(_draw_set_state_light_bind_directional_pcollector);
-
-  pair<DirectionalLights::iterator, bool> lookup = _dlights.insert(DirectionalLights::value_type(light, D3DLIGHT8()));
-  D3DLIGHT8 &fdata = (*lookup.first).second;
-  if (lookup.second) {
-    // Get the light in "world coordinates" (actually, view
-    // coordinates).  This means the light in the coordinate space of
-    // the camera, converted to DX's coordinate system.
-    CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path());
-    const LMatrix4 &light_mat = transform->get_mat();
-    LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
-    LVector3f dir = LCAST(float, light_obj->get_direction() * rel_mat);
-
-    D3DCOLORVALUE black;
-    black.r = black.g = black.b = black.a = 0.0f;
-
-    ZeroMemory(&fdata, sizeof(D3DLIGHT8));
-
-    fdata.Type =  D3DLIGHT_DIRECTIONAL;
-    fdata.Ambient  =  black ;
-    LColorf color = LCAST(float, light_obj->get_specular_color());
-    fdata.Specular = *(D3DCOLORVALUE *)(color.get_data());
-
-    fdata.Direction = *(D3DVECTOR *)dir.get_data();
-
-    fdata.Range =  __D3DLIGHT_RANGE_MAX;
-    fdata.Falloff =  1.0f;
-
-    fdata.Attenuation0 = 1.0f;       // constant
-    fdata.Attenuation1 = 0.0f;       // linear
-    fdata.Attenuation2 = 0.0f;       // quadratic
-  }
-
-  // We have to reset the Diffuse color at each call, because it might
-  // have changed independently of the light object itself (due to
-  // color_scale_via_lighting being in effect).
-  fdata.Diffuse  = get_light_color(light_obj);
-
-  HRESULT hr = _d3d_device->SetLight(light_id, &fdata);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.warning()
-      << "Could not set light properties for " << light
-      << " to id " << light_id << ": " << D3DERRORSTRING(hr) << "\n";
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::bind_light
-//       Access: Public, Virtual
-//  Description: Called the first time a particular light has been
-//               bound to a given id within a frame, this should set
-//               up the associated hardware light with the light's
-//               properties.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-bind_light(Spotlight *light_obj, const NodePath &light, int light_id) {
-  Lens *lens = light_obj->get_lens();
-  nassertv(lens != (Lens *)NULL);
-
-  // Get the light in "world coordinates" (actually, view
-  // coordinates).  This means the light in the coordinate space of
-  // the camera, converted to DX's coordinate system.
-  CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path());
-  const LMatrix4 &light_mat = transform->get_mat();
-  LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
-  LPoint3f pos = LCAST(float, lens->get_nodal_point() * rel_mat);
-  LVector3f dir = LCAST(float, lens->get_view_vector() * rel_mat);
-
-  D3DCOLORVALUE black;
-  black.r = black.g = black.b = black.a = 0.0f;
-
-  D3DLIGHT8  alight;
-  ZeroMemory(&alight, sizeof(D3DLIGHT8));
-
-  alight.Type =  D3DLIGHT_SPOT;
-  alight.Ambient  =  black ;
-  alight.Diffuse  = get_light_color(light_obj);
-  LColorf color = LCAST(float, light_obj->get_specular_color());
-  alight.Specular = *(D3DCOLORVALUE *)(color.get_data());
-
-  alight.Position = *(D3DVECTOR *)pos.get_data();
-
-  alight.Direction = *(D3DVECTOR *)dir.get_data();
-
-  alight.Range =  __D3DLIGHT_RANGE_MAX;
-
-  // I determined this formular empirically.  It seems to mostly
-  // approximate the OpenGL spotlight equation, for a reasonable range
-  // of values for FOV.
-  PN_stdfloat fov = lens->get_hfov();
-  alight.Falloff =  light_obj->get_exponent() * (fov * fov * fov) / 1620000.0f;
-
-  alight.Theta =  0.0f;
-  alight.Phi = deg_2_rad(fov);
-
-  const LVecBase3 &att = light_obj->get_attenuation();
-  alight.Attenuation0 = att[0];
-  alight.Attenuation1 = att[1];
-  alight.Attenuation2 = att[2];
-
-  HRESULT hr = _d3d_device->SetLight(light_id, &alight);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.warning()
-      << "Could not set light properties for " << light
-      << " to id " << light_id << ": " << D3DERRORSTRING(hr) << "\n";
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_index_type
-//       Access: Protected, Static
-//  Description: Maps from the Geom's internal numeric type symbols
-//               to DirectX's.
-////////////////////////////////////////////////////////////////////
-D3DFORMAT DXGraphicsStateGuardian8::
-get_index_type(Geom::NumericType numeric_type) {
-  switch (numeric_type) {
-  case Geom::NT_uint16:
-    return D3DFMT_INDEX16;
-
-  case Geom::NT_uint32:
-    return D3DFMT_INDEX32;
-  }
-
-  dxgsg8_cat.error()
-    << "Invalid index NumericType value (" << (int)numeric_type << ")\n";
-  return D3DFMT_INDEX16;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_material
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_material() {
-  static Material empty;
-  const Material *material;
-  const MaterialAttrib *target_material = DCAST(MaterialAttrib, _target_rs->get_attrib_def(MaterialAttrib::get_class_slot()));
-  if (target_material->is_off()) {
-    material = &empty;
-  } else {
-    material = target_material->get_material();
-  }
-
-  D3DMATERIAL8 cur_material;
-  LColorf color = LCAST(float, material->get_diffuse());
-  cur_material.Diffuse = *(D3DCOLORVALUE *)(color.get_data());
-  color = LCAST(float, material->get_ambient());
-  cur_material.Ambient = *(D3DCOLORVALUE *)(color.get_data());
-  color = LCAST(float, material->get_specular());
-  cur_material.Specular = *(D3DCOLORVALUE *)(color.get_data());
-  color = LCAST(float, material->get_emission());
-  cur_material.Emissive = *(D3DCOLORVALUE *)(color.get_data());
-  cur_material.Power = material->get_shininess();
-
-  if (material->has_diffuse()) {
-    // If the material specifies an diffuse color, use it.
-    _d3d_device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
-  } else {
-    // Otherwise, the diffuse color comes from the object color.
-    if (_has_material_force_color) {
-      color = LCAST(float, _material_force_color);
-      cur_material.Diffuse = *(D3DCOLORVALUE *)color.get_data();
-      _d3d_device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
-    } else {
-      _d3d_device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
-    }
-  }
-  if (material->has_ambient()) {
-    // If the material specifies an ambient color, use it.
-    _d3d_device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
-  } else {
-    // Otherwise, the ambient color comes from the object color.
-    if (_has_material_force_color) {
-      color = LCAST(float, _material_force_color);
-      cur_material.Ambient = *(D3DCOLORVALUE *)color.get_data();
-      _d3d_device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
-    } else {
-      _d3d_device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1);
-    }
-  }
-
-  if (material->has_specular()) {
-    _d3d_device->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
-  } else {
-    _d3d_device->SetRenderState(D3DRS_SPECULARENABLE, FALSE);
-  }
-
-  if (material->get_local()) {
-    _d3d_device->SetRenderState(D3DRS_LOCALVIEWER, TRUE);
-  } else {
-    _d3d_device->SetRenderState(D3DRS_LOCALVIEWER, FALSE);
-  }
-
-  _d3d_device->SetMaterial(&cur_material);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_texture
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_texture() {
-  DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
-
-  int num_stages = _target_texture->get_num_on_ff_stages();
-  nassertv(num_stages <= _max_texture_stages &&
-           _num_active_texture_stages <= _max_texture_stages);
-
-  _texture_involves_color_scale = false;
-
-  // We have to match up the texcoord stage index to the order written
-  // out by the DXGeomMunger.  This means the texcoord names are
-  // written in the order indicated by the TextureAttrib.
-
-  int si;
-  for (si = 0; si < num_stages; si++) {
-    TextureStage *stage = _target_texture->get_on_ff_stage(si);
-    int texcoord_index = _target_texture->get_ff_tc_index(si);
-
-    Texture *texture = _target_texture->get_on_texture(stage);
-    nassertv(texture != (Texture *)NULL);
-    const SamplerState &sampler = _target_texture->get_on_sampler(stage);
-
-    // We always reissue every stage in DX, just in case the texcoord
-    // index or texgen mode or some other property has changed.
-    TextureContext *tc = texture->prepare_now(0, _prepared_objects, this);
-    apply_texture(si, tc, sampler);
-    set_texture_blend_mode(si, stage);
-
-    int texcoord_dimensions = 2;
-
-    CPT(TransformState) tex_mat = TransformState::make_identity();
-    const TexMatrixAttrib *target_tex_matrix = DCAST(TexMatrixAttrib, _target_rs->get_attrib_def(TexMatrixAttrib::get_class_slot()));
-    if (target_tex_matrix->has_stage(stage)) {
-      tex_mat = target_tex_matrix->get_transform(stage);
-    }
-
-    // Issue the texgen mode.
-    TexGenAttrib::Mode mode = _target_tex_gen->get_mode(stage);
-    bool any_point_sprite = false;
-
-    switch (mode) {
-    case TexGenAttrib::M_off:
-    case TexGenAttrib::M_light_vector:
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX, texcoord_index);
-      break;
-
-    case TexGenAttrib::M_eye_sphere_map:
-      {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                          texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
-        // This texture matrix, applied on top of the texcoord
-        // computed by D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR,
-        // approximates the effect produced by OpenGL's GL_SPHERE_MAP.
-        static CPT(TransformState) sphere_map =
-          TransformState::make_mat(LMatrix4(0.33, 0.0f, 0.0f, 0.0f,
-                                             0.0f, 0.33, 0.0f, 0.0f,
-                                             0.0f, 0.0f, 1.0f, 0.0f,
-                                             0.5f, 0.5f, 0.0f, 1.0f));
-        tex_mat = tex_mat->compose(sphere_map);
-        texcoord_dimensions = 3;
-      }
-      break;
-
-    case TexGenAttrib::M_world_cube_map:
-      // To achieve world reflection vector, we must transform camera
-      // coordinates to world coordinates; i.e. apply the camera
-      // transform.  In the case of a vector, we should not apply the
-      // pos component of the transform.
-      {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                          texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
-        texcoord_dimensions = 3;
-        CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
-        tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3::zero()));
-      }
-      break;
-
-    case TexGenAttrib::M_eye_cube_map:
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                        texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
-      tex_mat = tex_mat->compose(_inv_cs_transform);
-      texcoord_dimensions = 3;
-      break;
-
-    case TexGenAttrib::M_world_normal:
-      // To achieve world normal, we must transform camera coordinates
-      // to world coordinates; i.e. apply the camera transform.  In
-      // the case of a normal, we should not apply the pos component
-      // of the transform.
-      {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                          texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL);
-        texcoord_dimensions = 3;
-        CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
-        tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3::zero()));
-      }
-      break;
-
-    case TexGenAttrib::M_eye_normal:
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                        texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL);
-      texcoord_dimensions = 3;
-      tex_mat = tex_mat->compose(_inv_cs_transform);
-      break;
-
-    case TexGenAttrib::M_world_position:
-      // To achieve world position, we must transform camera
-      // coordinates to world coordinates; i.e. apply the
-      // camera transform.
-      {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                          texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
-        texcoord_dimensions = 3;
-        CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
-        tex_mat = tex_mat->compose(camera_transform);
-      }
-      break;
-
-    case TexGenAttrib::M_eye_position:
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                        texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
-      texcoord_dimensions = 3;
-      tex_mat = tex_mat->compose(_inv_cs_transform);
-      break;
-
-    case TexGenAttrib::M_point_sprite:
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX, texcoord_index);
-      any_point_sprite = true;
-      break;
-
-    case TexGenAttrib::M_constant:
-      // To generate a constant UV(w) coordinate everywhere, we use
-      // CAMERASPACEPOSITION coordinates, but we construct a special
-      // matrix that flattens the existing values to zero and then
-      // adds our desired value.
-
-      // The only reason we need to specify CAMERASPACEPOSITION at
-      // all, instead of using whatever texture coordinates (if any)
-      // happen to be on the vertices, is because we need to guarantee
-      // that there are 3-d texture coordinates, because of the
-      // 3-component texture coordinate in get_constant_value().
-      {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
-                                          texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
-        texcoord_dimensions = 3;
-
-        const LTexCoord3 &v = _target_tex_gen->get_constant_value(stage);
-        CPT(TransformState) squash =
-          TransformState::make_pos_hpr_scale(v, LVecBase3::zero(),
-                                             LVecBase3::zero());
-        tex_mat = tex_mat->compose(squash);
-      }
-      break;
-    }
-
-    _d3d_device->SetRenderState(D3DRS_POINTSPRITEENABLE, any_point_sprite);
-
-    if (!tex_mat->is_identity()) {
-      if (/*tex_mat->is_2d() &&*/ texcoord_dimensions <= 2) {
-        // For 2-d texture coordinates, we have to reorder the matrix.
-        LMatrix4 m = tex_mat->get_mat();
-        LMatrix4f mf;
-        mf.set(m(0, 0), m(0, 1), m(0, 3), 0.0f,
-               m(1, 0), m(1, 1), m(1, 3), 0.0f,
-               m(3, 0), m(3, 1), m(3, 3), 0.0f,
-               0.0f, 0.0f, 0.0f, 1.0f);
-        _d3d_device->SetTransform(get_tex_mat_sym(si), (D3DMATRIX *)mf.get_data());
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXTURETRANSFORMFLAGS,
-                                          D3DTTFF_COUNT2);
-      } else {
-        LMatrix4f m = LCAST(float, tex_mat->get_mat());
-        _d3d_device->SetTransform(get_tex_mat_sym(si), (D3DMATRIX *)m.get_data());
-        DWORD transform_flags = texcoord_dimensions;
-        if (m.get_col(3) != LVecBase4(0.0f, 0.0f, 0.0f, 1.0f)) {
-          // If we have a projected texture matrix, we also need to
-          // set D3DTTFF_COUNT4.
-          transform_flags = D3DTTFF_COUNT4 | D3DTTFF_PROJECTED;
-        }
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXTURETRANSFORMFLAGS,
-                                          transform_flags);
-      }
-
-    } else {
-      _d3d_device->SetTextureStageState(si, D3DTSS_TEXTURETRANSFORMFLAGS,
-                                        D3DTTFF_DISABLE);
-      // For some reason, "disabling" texture coordinate transforms
-      // doesn't seem to be sufficient.  We'll load an identity matrix
-      // to underscore the point.
-      _d3d_device->SetTransform(get_tex_mat_sym(si), &_d3d_ident_mat);
-    }
-  }
-
-  // Disable the texture stages that are no longer used.
-  for (si = num_stages; si < _num_active_texture_stages; si++) {
-    _d3d_device->SetTextureStageState(si, D3DTSS_COLOROP, D3DTOP_DISABLE);
-  }
-
-  // Save the count of texture stages for next time.
-  _num_active_texture_stages = num_stages;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::reissue_transforms
-//       Access: Protected, Virtual
-//  Description: Called by clear_state_and_transform() to ensure that
-//               the current modelview and projection matrices are
-//               properly loaded in the graphics state, after a
-//               callback might have mucked them up.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-reissue_transforms() {
-  prepare_lens();
-  do_issue_transform();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_lighting
-//       Access: Protected, Virtual
-//  Description: Intended to be overridden by a derived class to
-//               enable or disable the use of lighting overall.  This
-//               is called by issue_light() according to whether any
-//               lights are in use or not.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-enable_lighting(bool enable) {
-  _d3d_device->SetRenderState(D3DRS_LIGHTING, (DWORD)enable);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_ambient_light
-//       Access: Protected, Virtual
-//  Description: Intended to be overridden by a derived class to
-//               indicate the color of the ambient light that should
-//               be in effect.  This is called by issue_light() after
-//               all other lights have been enabled or disabled.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_ambient_light(const LColor &color) {
-  LColor c = color;
-  c.set(c[0] * _light_color_scale[0],
-        c[1] * _light_color_scale[1],
-        c[2] * _light_color_scale[2],
-        c[3] * _light_color_scale[3]);
-
-  _d3d_device->SetRenderState(D3DRS_AMBIENT, LColor_to_D3DCOLOR(c));
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_light
-//       Access: Protected, Virtual
-//  Description: Intended to be overridden by a derived class to
-//               enable the indicated light id.  A specific Light will
-//               already have been bound to this id via bind_light().
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-enable_light(int light_id, bool enable) {
-  HRESULT hr = _d3d_device->LightEnable(light_id, enable);
-
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.warning()
-      << "Could not enable light " << light_id << ": "
-      << D3DERRORSTRING(hr) << "\n";
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::enable_clip_plane
-//       Access: Protected, Virtual
-//  Description: Intended to be overridden by a derived class to
-//               enable the indicated clip_plane id.  A specific
-//               PlaneNode will already have been bound to this id via
-//               bind_clip_plane().
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-enable_clip_plane(int plane_id, bool enable) {
-  if (enable) {
-    _clip_plane_bits |= ((DWORD)1 << plane_id);
-  } else {
-    _clip_plane_bits &= ~((DWORD)1 << plane_id);
-  }
-  _d3d_device->SetRenderState(D3DRS_CLIPPLANEENABLE, _clip_plane_bits);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::bind_clip_plane
-//       Access: Protected, Virtual
-//  Description: Called the first time a particular clip_plane has been
-//               bound to a given id within a frame, this should set
-//               up the associated hardware clip_plane with the clip_plane's
-//               properties.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-bind_clip_plane(const NodePath &plane, int plane_id) {
-  // Get the plane in "world coordinates" (actually, view
-  // coordinates).  This means the plane in the coordinate space of
-  // the camera, converted to DX's coordinate system.
-  CPT(TransformState) transform = plane.get_transform(_scene_setup->get_camera_path());
-  const LMatrix4 &plane_mat = transform->get_mat();
-  LMatrix4 rel_mat = plane_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
-  const PlaneNode *plane_node;
-  DCAST_INTO_V(plane_node, plane.node());
-  LPlanef world_plane = LCAST(float, plane_node->get_plane() * rel_mat);
-
-  HRESULT hr = _d3d_device->SetClipPlane(plane_id, world_plane.get_data());
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.warning()
-      << "Could not set clip plane for " << plane
-      << " to id " << plane_id << ": " << D3DERRORSTRING(hr) << "\n";
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_blend_mode
-//       Access: Protected, Virtual
-//  Description: Called after any of the things that might change
-//               blending state have changed, this function is
-//               responsible for setting the appropriate color
-//               blending mode based on the current properties.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_blending() {
-
-  // Handle the color_write attrib.  If color_write is off, then
-  // all the other blending-related stuff doesn't matter.  If the
-  // device doesn't support color-write, we use blending tricks
-  // to effectively disable color write.
-  const ColorWriteAttrib *target_color_write = DCAST(ColorWriteAttrib, _target_rs->get_attrib_def(ColorWriteAttrib::get_class_slot()));
-  unsigned int color_channels =
-    target_color_write->get_channels() & _color_write_mask;
-  if (color_channels == ColorWriteAttrib::C_off) {
-    if (_screen->_can_direct_disable_color_writes) {
-      _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
-      _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)0x0);
-    } else {
-      _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
-      _d3d_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
-      _d3d_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
-    }
-    return;
-  }
-
-  if (_screen->_can_direct_disable_color_writes) {
-    _d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, color_channels);
-  }
-
-  const ColorBlendAttrib *target_color_blend = DCAST(ColorBlendAttrib, _target_rs->get_attrib_def(ColorBlendAttrib::get_class_slot()));
-  ColorBlendAttrib::Mode color_blend_mode = target_color_blend->get_mode();
-
-  const TransparencyAttrib *target_transparency = DCAST(TransparencyAttrib, _target_rs->get_attrib_def(TransparencyAttrib::get_class_slot()));
-  TransparencyAttrib::Mode transparency_mode = target_transparency->get_mode();
-
-  // Is there a color blend set?
-  if (color_blend_mode != ColorBlendAttrib::M_none) {
-    _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
-
-    switch (color_blend_mode) {
-    case ColorBlendAttrib::M_add:
-      _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
-      break;
-
-    case ColorBlendAttrib::M_subtract:
-      _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_SUBTRACT);
-      break;
-
-    case ColorBlendAttrib::M_inv_subtract:
-      _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_REVSUBTRACT);
-      break;
-
-    case ColorBlendAttrib::M_min:
-      _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_MIN);
-      break;
-
-    case ColorBlendAttrib::M_max:
-      _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_MAX);
-      break;
-    }
-
-    _d3d_device->SetRenderState(D3DRS_SRCBLEND,
-                                get_blend_func(target_color_blend->get_operand_a()));
-    _d3d_device->SetRenderState(D3DRS_DESTBLEND,
-                                get_blend_func(target_color_blend->get_operand_b()));
-    return;
-  }
-
-  // No color blend; is there a transparency set?
-  switch (transparency_mode) {
-  case TransparencyAttrib::M_none:
-  case TransparencyAttrib::M_binary:
-    break;
-
-  case TransparencyAttrib::M_alpha:
-  case TransparencyAttrib::M_multisample:
-  case TransparencyAttrib::M_multisample_mask:
-  case TransparencyAttrib::M_dual:
-    _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
-    _d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
-    _d3d_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
-    _d3d_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
-    return;
-
-  default:
-    dxgsg8_cat.error()
-      << "invalid transparency mode " << (int)transparency_mode << endl;
-    break;
-  }
-
-  // Nothing's set, so disable blending.
-  _d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::close_gsg
-//       Access: Protected, Virtual
-//  Description: This is called by the associated GraphicsWindow when
-//               close_window() is called.  It should null out the
-//               _win pointer and possibly free any open resources
-//               associated with the GSG.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-close_gsg() {
-  GraphicsStateGuardian::close_gsg();
-
-  // Unlike in OpenGL, in DX8 it is safe to try to explicitly release
-  // any textures here.  And it may even be a good idea.
-  if (_prepared_objects->get_ref_count() == 1) {
-    release_all();
-
-    // Now we need to actually delete all of the objects we just
-    // released.
-    Thread *current_thread = Thread::get_current_thread();
-    _prepared_objects->begin_frame(this, current_thread);
-    _prepared_objects->end_frame(current_thread);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::free_nondx_resources
-//       Access: Public
-//  Description: Frees some memory that was explicitly allocated
-//               within the dxgsg.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-free_nondx_resources() {
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::free_d3d_device
-//       Access: Public
-//  Description: setup for re-calling dx_init(), this is not the final
-//               exit cleanup routine (see dx_cleanup)
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-free_d3d_device() {
-  // don't want a full reset of gsg, just a state clear
-  _state_rs = RenderState::make_empty();
-  _state_mask.clear();
-
-  // want gsg to pass all state settings through
-
-  _dx_is_ready = false;
-
-  if (_d3d_device != NULL)
-    for(int i = 0;i<D3D_MAXTEXTURESTAGES;i++)
-      _d3d_device->SetTexture(i, NULL);  // d3d should release this stuff internally anyway, but whatever
-
-  release_all();
-
-  if (_d3d_device != NULL)
-    RELEASE(_d3d_device, dxgsg8, "d3dDevice", RELEASE_DOWN_TO_ZERO);
-
-  free_nondx_resources();
-
-  // obviously we don't release ID3D8, just ID3DDevice8
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_draw_buffer
-//       Access: Protected
-//  Description: Sets up the glDrawBuffer to render into the buffer
-//               indicated by the RenderBuffer object.  This only sets
-//               up the color bits; it does not affect the depth,
-//               stencil, accum layers.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_draw_buffer(const RenderBuffer &rb) {
-  dxgsg8_cat.fatal() << "DX set_draw_buffer unimplemented!!!";
-  return;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_read_buffer
-//       Access: Protected
-//  Description: Vestigial analog of glReadBuffer
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_read_buffer(const RenderBuffer &rb) {
-  if (rb._buffer_type & RenderBuffer::T_front) {
-    _cur_read_pixel_buffer = RenderBuffer::T_front;
-  } else  if (rb._buffer_type & RenderBuffer::T_back) {
-    _cur_read_pixel_buffer = RenderBuffer::T_back;
-  } else {
-    dxgsg8_cat.error() << "Invalid or unimplemented Argument to set_read_buffer!\n";
-  }
-  return;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_auto_rescale_normal
-//       Access: Protected
-//  Description: Issues the appropriate GL commands to either rescale
-//               or normalize the normals according to the current
-//               transform.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_auto_rescale_normal() {
-  if (_internal_transform->has_identity_scale()) {
-    // If there's no scale, don't normalize anything.
-    _d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, false);
-
-  } else {
-    // If there is a scale, turn on normalization.
-    _d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::get_light_color
-//       Access: Public
-//  Description: Returns the array of four floats that should be
-//               issued as the light's color, as scaled by the current
-//               value of _light_color_scale, in the case of
-//               color_scale_via_lighting.
-////////////////////////////////////////////////////////////////////
-const D3DCOLORVALUE &DXGraphicsStateGuardian8::
-get_light_color(Light *light) const {
-  LColor c = light->get_color();
-  static LColorf cf;
-  cf.set(c[0] * _light_color_scale[0],
-         c[1] * _light_color_scale[1],
-         c[2] * _light_color_scale[2],
-         c[3] * _light_color_scale[3]);
-  return *(D3DCOLORVALUE *)cf.get_data();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_blend_func
-//       Access: Protected, Static
-//  Description: Maps from ColorBlendAttrib::Operand to D3DBLEND
-//               value.
-////////////////////////////////////////////////////////////////////
-D3DBLEND DXGraphicsStateGuardian8::
-get_blend_func(ColorBlendAttrib::Operand operand) {
-  switch (operand) {
-  case ColorBlendAttrib::O_zero:
-    return D3DBLEND_ZERO;
-
-  case ColorBlendAttrib::O_one:
-    return D3DBLEND_ONE;
-
-  case ColorBlendAttrib::O_incoming_color:
-    return D3DBLEND_SRCCOLOR;
-
-  case ColorBlendAttrib::O_one_minus_incoming_color:
-    return D3DBLEND_INVSRCCOLOR;
-
-  case ColorBlendAttrib::O_fbuffer_color:
-    return D3DBLEND_DESTCOLOR;
-
-  case ColorBlendAttrib::O_one_minus_fbuffer_color:
-    return D3DBLEND_INVDESTCOLOR;
-
-  case ColorBlendAttrib::O_incoming_alpha:
-    return D3DBLEND_SRCALPHA;
-
-  case ColorBlendAttrib::O_one_minus_incoming_alpha:
-    return D3DBLEND_INVSRCALPHA;
-
-  case ColorBlendAttrib::O_fbuffer_alpha:
-    return D3DBLEND_DESTALPHA;
-
-  case ColorBlendAttrib::O_one_minus_fbuffer_alpha:
-    return D3DBLEND_INVDESTALPHA;
-
-  case ColorBlendAttrib::O_constant_color:
-    // Not supported by DX.
-    return D3DBLEND_SRCCOLOR;
-
-  case ColorBlendAttrib::O_one_minus_constant_color:
-    // Not supported by DX.
-    return D3DBLEND_INVSRCCOLOR;
-
-  case ColorBlendAttrib::O_constant_alpha:
-    // Not supported by DX.
-    return D3DBLEND_SRCALPHA;
-
-  case ColorBlendAttrib::O_one_minus_constant_alpha:
-    // Not supported by DX.
-    return D3DBLEND_INVSRCALPHA;
-
-  case ColorBlendAttrib::O_incoming_color_saturate:
-    return D3DBLEND_SRCALPHASAT;
-  }
-
-  dxgsg8_cat.error()
-    << "Unknown color blend operand " << (int)operand << endl;
-  return D3DBLEND_ZERO;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::report_texmgr_stats
-//       Access: Protected
-//  Description: Reports the DX texture manager's activity to PStats.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-report_texmgr_stats() {
-
-#ifdef DO_PSTATS
-  HRESULT hr;
-#ifdef TEXMGRSTATS_USES_GETAVAILVIDMEM
-  DWORD dwTexTotal, dwTexFree, dwVidTotal, dwVidFree;
-
-  if (_total_texmem_pcollector.is_active()) {
-    DDSCAPS2 ddsCaps;
-
-    ZeroMemory(&ddsCaps, sizeof(ddsCaps));
-
-    ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
-    if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwVidTotal, &dwVidFree))) {
-      dxgsg8_cat.fatal() << "report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << D3DERRORSTRING(hr);
-      throw_event("panda3d-render-error");
-      return;
-    }
-
-    ddsCaps.dwCaps = DDSCAPS_TEXTURE;
-    if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwTexTotal, &dwTexFree))) {
-      dxgsg8_cat.fatal() << "report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << D3DERRORSTRING(hr);
-      throw_event("panda3d-render-error");
-      return;
-    }
-  }
-#endif  // TEXMGRSTATS_USES_GETAVAILVIDMEM
-
-  D3DDEVINFO_RESOURCEMANAGER all_resource_stats;
-  ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
-
-  if (!_tex_stats_retrieval_impossible) {
-    hr = _d3d_device->GetInfo(D3DDEVINFOID_RESOURCEMANAGER, &all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
-    if (hr != D3D_OK) {
-      if (hr == S_FALSE) {
-        static int PrintedMsg = 2;
-        if (PrintedMsg>0) {
-          if (dxgsg8_cat.is_debug()) {
-            dxgsg8_cat.debug()
-              << "texstats GetInfo() requires debug DX DLLs to be installed!!\n";
-          }
-          ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
-          _tex_stats_retrieval_impossible = true;
-        }
-      } else {
-        dxgsg8_cat.error() << "GetInfo(RESOURCEMANAGER) failed to get tex stats: result = " << D3DERRORSTRING(hr);
-        return;
-      }
-    }
-  }
-
-  // Tell PStats about the state of the texture memory.
-
-  if (_texmgrmem_total_pcollector.is_active()) {
-    // report zero if no debug dlls, to signal this info is invalid
-    _texmgrmem_total_pcollector.set_level(all_resource_stats.stats[D3DRTYPE_TEXTURE].TotalBytes);
-    _texmgrmem_resident_pcollector.set_level(all_resource_stats.stats[D3DRTYPE_TEXTURE].WorkingSetBytes);
-  }
-#ifdef TEXMGRSTATS_USES_GETAVAILVIDMEM
-  if (_total_texmem_pcollector.is_active()) {
-    _total_texmem_pcollector.set_level(dwTexTotal);
-    _used_texmem_pcollector.set_level(dwTexTotal - dwTexFree);
-  }
-#endif  // TEXMGRSTATS_USES_GETAVAILVIDMEM
-#endif  // DO_PSTATS
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_context
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_context(DXScreenData *new_context) {
-  nassertv(new_context != NULL);
-  _screen = new_context;
-  _d3d_device = _screen->_d3d_device;   //copy this one field for speed of deref
-  _swap_chain = _screen->_swap_chain;   //copy this one field for speed of deref
-
-  _screen->_dxgsg8 = this;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_render_target
-//       Access: Protected
-//  Description: Set render target to the backbuffer of current swap
-//               chain.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_render_target() {
-  if (_d3d_device == NULL) {
-    return;
-  }
-
-  LPDIRECT3DSURFACE8 back = NULL, stencil = NULL;
-
-  if (!_swap_chain)  //maybe fullscreen mode or main/single window
-    _d3d_device->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &back);
-  else
-    _swap_chain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &back);
-
-  //wdxdisplay8_cat.debug() << "swapchain is " << _swap_chain << "\n";
-  //wdxdisplay8_cat.debug() << "back buffer is " << back << "\n";
-
-  _d3d_device->GetDepthStencilSurface(&stencil);
-  _d3d_device->SetRenderTarget(back, stencil);
-  if (back) {
-    back->Release();
-  }
-  if (stencil) {
-    stencil->Release();
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_texture_blend_mode
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_texture_blend_mode(int i, const TextureStage *stage) {
-  switch (stage->get_mode()) {
-  case TextureStage::M_modulate:
-  case TextureStage::M_modulate_glow:
-  case TextureStage::M_modulate_gloss:
-    // emulates GL_MODULATE glTexEnv mode
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_MODULATE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
-    break;
-
-  case TextureStage::M_decal:
-    // emulates GL_DECAL glTexEnv mode
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
-
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
-    break;
-
-  case TextureStage::M_replace:
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
-
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
-    break;
-
-  case TextureStage::M_add:
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_ADD);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
-
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
-    _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
-    break;
-
-  case TextureStage::M_blend:
-  case TextureStage::M_blend_color_scale:
-    {
-      _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_LERP);
-      _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG0, D3DTA_TEXTURE);
-      _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
-      _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TFACTOR);
-
-      _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
-      _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
-      _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
-    }
-    break;
-
-  case TextureStage::M_combine:
-    // M_combine mode begins a collection of more sophisticated modes,
-    // which match up more closely with DirectX's built-in modes.
-    _d3d_device->SetTextureStageState
-      (i, D3DTSS_COLOROP,
-       get_texture_operation(stage->get_combine_rgb_mode(),
-                             stage->get_rgb_scale()));
-
-    switch (stage->get_num_combine_rgb_operands()) {
-    case 3:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_COLORARG0,
-         get_texture_argument(stage->get_combine_rgb_source2(),
-                              stage->get_combine_rgb_operand2()));
-      // fall through
-
-    case 2:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_COLORARG2,
-         get_texture_argument(stage->get_combine_rgb_source1(),
-                              stage->get_combine_rgb_operand1()));
-      // fall through
-
-    case 1:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_COLORARG1,
-         get_texture_argument(stage->get_combine_rgb_source0(),
-                              stage->get_combine_rgb_operand0()));
-      // fall through
-
-    default:
-      break;
-    }
-
-    _d3d_device->SetTextureStageState
-      (i, D3DTSS_ALPHAOP,
-       get_texture_operation(stage->get_combine_alpha_mode(),
-                             stage->get_alpha_scale()));
-
-    switch (stage->get_num_combine_alpha_operands()) {
-    case 3:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_ALPHAARG0,
-         get_texture_argument(stage->get_combine_alpha_source2(),
-                              stage->get_combine_alpha_operand2()));
-      // fall through
-
-    case 2:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_ALPHAARG2,
-         get_texture_argument(stage->get_combine_alpha_source1(),
-                              stage->get_combine_alpha_operand1()));
-      // fall through
-
-    case 1:
-      _d3d_device->SetTextureStageState
-        (i, D3DTSS_ALPHAARG1,
-         get_texture_argument(stage->get_combine_alpha_source0(),
-                              stage->get_combine_alpha_operand0()));
-      // fall through
-
-    default:
-      break;
-    }
-    break;
-
-  default:
-    dxgsg8_cat.error()
-      << "Unknown texture mode " << (int)stage->get_mode() << endl;
-    break;
-  }
-
-  if (stage->get_saved_result()) {
-    _d3d_device->SetTextureStageState(i, D3DTSS_RESULTARG, D3DTA_TEMP);
-  } else {
-    _d3d_device->SetTextureStageState(i, D3DTSS_RESULTARG, D3DTA_CURRENT);
-  }
-
-  if (stage->uses_color()) {
-    // Set up the constant color for this stage.
-
-    // Actually, DX8 doesn't support a per-stage constant color, but
-    // it does support one TEXTUREFACTOR color for the whole pipeline.
-    // This does mean you can't have two different blends in effect
-    // with different colors on the same object.  However, DX9 does
-    // support a per-stage constant color with the D3DTA_CONSTANT
-    // argument--so we should implement that when this code gets
-    // ported to DX9.
-
-    D3DCOLOR texture_factor;
-    if (stage->involves_color_scale() && _color_scale_enabled) {
-      LColor color = stage->get_color();
-      color.set(color[0] * _current_color_scale[0],
-                color[1] * _current_color_scale[1],
-                color[2] * _current_color_scale[2],
-                color[3] * _current_color_scale[3]);
-      _texture_involves_color_scale = true;
-      texture_factor = LColor_to_D3DCOLOR(color);
-    } else {
-      texture_factor = LColor_to_D3DCOLOR(stage->get_color());
-    }
-    _d3d_device->SetRenderState(D3DRS_TEXTUREFACTOR, texture_factor);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::dx_cleanup
-//       Access: Protected
-//  Description: Clean up the DirectX environment, accounting for exit()
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-dx_cleanup() {
-  if (!_d3d_device) {
-    return;
-  }
-
-  free_nondx_resources();
-  PRINT_REFCNT(dxgsg8, _d3d_device);
-
-  // Do a safe check for releasing the D3DDEVICE. RefCount should be zero.
-  // if we're called from exit(), _d3d_device may already have been released
-  RELEASE(_d3d_device, dxgsg8, "d3dDevice", RELEASE_DOWN_TO_ZERO);
-  _screen->_d3d_device = NULL;
-
-  // Releasing pD3D is now the responsibility of the GraphicsPipe destructor
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::reset_d3d_device
-//       Access: Protected
-//  Description: This function checks current device's framebuffer
-//               dimension against passed p_presentation_params backbuffer
-//               dimension to determine a device reset if there is
-//               only one window or it is the main window or
-//               fullscreen mode then, it resets the device. Finally
-//               it returns the new DXScreenData through parameter
-//               screen
-////////////////////////////////////////////////////////////////////
-HRESULT DXGraphicsStateGuardian8::
-reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params,
-                 DXScreenData **screen) {
-  HRESULT hr;
-
-  nassertr(IS_VALID_PTR(presentation_params), E_FAIL);
-  nassertr(IS_VALID_PTR(_screen->_d3d8), E_FAIL);
-  nassertr(IS_VALID_PTR(_d3d_device), E_FAIL);
-
-  // for windowed mode make sure our format matches the desktop fmt,
-  // in case the desktop mode has been changed
-  _screen->_d3d8->GetAdapterDisplayMode(_screen->_card_id, &_screen->_display_mode);
-  presentation_params->BackBufferFormat = _screen->_display_mode.Format;
-
-  // here we have to look at the _presentation_reset frame buffer dimension
-  // if current window's dimension is bigger than _presentation_reset
-  // we have to reset the device before creating new swapchain.
-  // inorder to reset properly, we need to release all swapchains
-
-  if (true || !(_screen->_swap_chain)
-      || (_presentation_reset.BackBufferWidth < presentation_params->BackBufferWidth)
-      || (_presentation_reset.BackBufferHeight < presentation_params->BackBufferHeight)) {
-    if (wdxdisplay8_cat.is_debug()) {
-      wdxdisplay8_cat.debug()
-        << "swap_chain = " << _screen->_swap_chain << " _presentation_reset = "
-        << _presentation_reset.BackBufferWidth << "x" << _presentation_reset.BackBufferHeight
-        << " presentation_params = "
-        << presentation_params->BackBufferWidth << "x" << presentation_params->BackBufferHeight << "\n";
-    }
-
-    get_engine()->reset_all_windows(false);// reset old swapchain by releasing
-
-    if (_screen->_swap_chain) {  //other windows might be using bigger buffers
-      _presentation_reset.BackBufferWidth = max(_presentation_reset.BackBufferWidth, presentation_params->BackBufferWidth);
-      _presentation_reset.BackBufferHeight = max(_presentation_reset.BackBufferHeight, presentation_params->BackBufferHeight);
-
-    } else {  // single window, must reset to the new presentation_params dimension
-      _presentation_reset.BackBufferWidth = presentation_params->BackBufferWidth;
-      _presentation_reset.BackBufferHeight = presentation_params->BackBufferHeight;
-    }
-
-    // Calling this forces all of the textures and vbuffers to be
-    // regenerated, a prerequisite to calling Reset().  Actually, this
-    // shouldn't be necessary, because all of our textures and
-    // vbuffers are stored in the D3DPOOL_MANAGED memory class.
-    release_all();
-
-    // Just to be extra-conservative for now, we'll go ahead and
-    // release the vbuffers and ibuffers at least; they're relatively
-    // cheap to replace.
-    release_all_vertex_buffers();
-    release_all_index_buffers();
-
-    Thread *current_thread = Thread::get_current_thread();
-    _prepared_objects->begin_frame(this, current_thread);
-
-    // release graphics buffer surfaces
-    {
-      wdxGraphicsBuffer8 *graphics_buffer;
-      list <wdxGraphicsBuffer8 **>::iterator graphics_buffer_iterator;
-
-      for (graphics_buffer_iterator = _graphics_buffer_list.begin( ); graphics_buffer_iterator != _graphics_buffer_list.end( ); graphics_buffer_iterator++)
-      {
-        graphics_buffer = **graphics_buffer_iterator;
-        if (graphics_buffer -> _color_backing_store)
-        {
-          graphics_buffer -> _color_backing_store -> Release ( );
-          graphics_buffer -> _color_backing_store = 0;
-        }
-        if (graphics_buffer -> _depth_backing_store)
-        {
-          graphics_buffer -> _depth_backing_store -> Release ( );
-          graphics_buffer -> _depth_backing_store = 0;
-        }
-      }
-    }
-
-    this -> mark_new();
-    hr = _d3d_device->Reset(&_presentation_reset);
-    if (FAILED(hr)) {
-      return hr;
-    }
-
-    get_engine()->reset_all_windows(true);// reset with new swapchains by creating
-    if (screen) {
-      *screen = NULL;
-    }
-
-    if (presentation_params != &_screen->_presentation_params) {
-      memcpy(&_screen->_presentation_params, presentation_params, sizeof(D3DPRESENT_PARAMETERS));
-    }
-
-    return hr;
-  }
-
-  // release the old swapchain and create a new one
-  if (_screen && _screen->_swap_chain) {
-    _screen->_swap_chain->Release();
-    wdxdisplay8_cat.debug()
-      << "swap chain " << _screen->_swap_chain << " is released\n";
-    _screen->_swap_chain = NULL;
-    hr = _d3d_device->CreateAdditionalSwapChain(presentation_params, &_screen->_swap_chain);
-  }
-  if (SUCCEEDED(hr)) {
-    if (presentation_params != &_screen->_presentation_params) {
-      memcpy(&_screen->_presentation_params, presentation_params, sizeof(D3DPRESENT_PARAMETERS));
-    }
-    if (screen) {
-      *screen = _screen;
-    }
-  }
-  return hr;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::check_cooperative_level
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-check_cooperative_level() {
-  bool bDoReactivateWindow = false;
-  if (_d3d_device == NULL) {
-    return false;
-  }
-  HRESULT hr = _d3d_device->TestCooperativeLevel();
-
-  if (SUCCEEDED(hr)) {
-    nassertr(SUCCEEDED(_last_testcooplevel_result), false);
-    return true;
-  }
-
-  switch (hr) {
-  case D3DERR_DEVICENOTRESET:
-    _dx_is_ready = false;
-
-    // call this just in case
-    _prepared_objects->begin_frame(this, Thread::get_current_thread());
-
-    hr = reset_d3d_device(&_screen->_presentation_params);
-    if (FAILED(hr)) {
-      // I think this shouldnt fail unless I've screwed up the
-      // _presentation_params from the original working ones somehow
-      dxgsg8_cat.error()
-        << "check_cooperative_level Reset() failed, hr = " << D3DERRORSTRING(hr);
-    }
-
-    hr = _d3d_device->TestCooperativeLevel();
-    if (FAILED(hr)) {
-      // internal chk, shouldnt fail
-      dxgsg8_cat.error()
-        << "TestCooperativeLevel following Reset() failed, hr = " << D3DERRORSTRING(hr);
-
-    }
-
-    _dx_is_ready = TRUE;
-    break;
-
-  case D3DERR_DEVICELOST:
-    // sleep while the device is lost to free up the CPU
-    Sleep (10);
-
-    if (SUCCEEDED(_last_testcooplevel_result)) {
-      if (_dx_is_ready) {
-        _dx_is_ready = false;
-        if (dxgsg8_cat.is_debug()) {
-          dxgsg8_cat.debug() << "D3D Device was Lost, waiting...\n";
-        }
-      }
-    }
-  }
-
-  _last_testcooplevel_result = hr;
-  return SUCCEEDED(hr);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::show_frame
-//       Access: Protected
-//  Description: redraw primary buffer
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-show_frame() {
-  if (_d3d_device == NULL) {
-    return;
-  }
-
-  HRESULT hr;
-
-  if (_swap_chain) {
-    hr = _swap_chain->Present((CONST RECT*)NULL, (CONST RECT*)NULL, (HWND)NULL, NULL);
-  } else {
-    hr = _d3d_device->Present((CONST RECT*)NULL, (CONST RECT*)NULL, (HWND)NULL, NULL);
-  }
-
-  if (FAILED(hr)) {
-    if (hr == D3DERR_DEVICELOST) {
-      check_cooperative_level();
-    } else {
-      dxgsg8_cat.error()
-        << "show_frame() - Present() failed" << D3DERRORSTRING(hr);
-      throw_event("panda3d-render-error");
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::create_swap_chain
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-create_swap_chain(DXScreenData *new_context) {
-  // Instead of creating a device and rendering as d3ddevice->present()
-  // we should render using SwapChain->present(). This is done to support
-  // multiple windows rendering. For that purpose, we need to set additional
-  // swap chains here.
-
-  HRESULT hr;
-  hr = new_context->_d3d_device->CreateAdditionalSwapChain(&new_context->_presentation_params, &new_context->_swap_chain);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.debug() << "Swapchain creation failed :"<<D3DERRORSTRING(hr)<<"\n";
-    return false;
-  }
-  wdxdisplay8_cat.debug()
-    << "Created swap chain " << new_context->_swap_chain << "\n";
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::release_swap_chain
-//       Access: Protected
-//  Description: Release the swap chain on this DXScreenData
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-release_swap_chain(DXScreenData *new_context) {
-  HRESULT hr;
-  wdxdisplay8_cat.debug()
-    << "Releasing swap chain " << new_context->_swap_chain << "\n";
-  if (new_context->_swap_chain) {
-    hr = new_context->_swap_chain->Release();
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.debug() << "Swapchain release failed:" << D3DERRORSTRING(hr) << "\n";
-      return false;
-    }
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::copy_pres_reset
-//       Access: Protected
-//  Description: copies the PresReset from passed DXScreenData
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-copy_pres_reset(DXScreenData *screen) {
-  memcpy(&_presentation_reset, &_screen->_presentation_params, sizeof(D3DPRESENT_PARAMETERS));
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_d3d_min_type
-//       Access: Protected, Static
-//  Description:
-////////////////////////////////////////////////////////////////////
-D3DTEXTUREFILTERTYPE DXGraphicsStateGuardian8::
-get_d3d_min_type(SamplerState::FilterType filter_type) {
-  switch (filter_type) {
-  case SamplerState::FT_nearest:
-    return D3DTEXF_POINT;
-
-  case SamplerState::FT_linear:
-    return D3DTEXF_LINEAR;
-
-  case SamplerState::FT_nearest_mipmap_nearest:
-    return D3DTEXF_POINT;
-
-  case SamplerState::FT_linear_mipmap_nearest:
-    return D3DTEXF_LINEAR;
-
-  case SamplerState::FT_nearest_mipmap_linear:
-    return D3DTEXF_POINT;
-
-  case SamplerState::FT_linear_mipmap_linear:
-    return D3DTEXF_LINEAR;
-
-  case SamplerState::FT_shadow:
-  case SamplerState::FT_default:
-    return D3DTEXF_LINEAR;
-  }
-
-  dxgsg8_cat.error()
-    << "Invalid FilterType value (" << (int)filter_type << ")\n";
-  return D3DTEXF_POINT;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_d3d_mip_type
-//       Access: Protected, Static
-//  Description:
-////////////////////////////////////////////////////////////////////
-D3DTEXTUREFILTERTYPE DXGraphicsStateGuardian8::
-get_d3d_mip_type(SamplerState::FilterType filter_type) {
-  switch (filter_type) {
-  case SamplerState::FT_nearest:
-    return D3DTEXF_NONE;
-
-  case SamplerState::FT_linear:
-    return D3DTEXF_NONE;
-
-  case SamplerState::FT_nearest_mipmap_nearest:
-    return D3DTEXF_POINT;
-
-  case SamplerState::FT_linear_mipmap_nearest:
-    return D3DTEXF_POINT;
-
-  case SamplerState::FT_nearest_mipmap_linear:
-    return D3DTEXF_LINEAR;
-
-  case SamplerState::FT_linear_mipmap_linear:
-    return D3DTEXF_LINEAR;
-
-  case SamplerState::FT_shadow:
-  case SamplerState::FT_default:
-    return D3DTEXF_NONE;
-  }
-
-  dxgsg8_cat.error()
-    << "Invalid FilterType value (" << (int)filter_type << ")\n";
-  return D3DTEXF_NONE;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_texture_operation
-//       Access: Protected, Static
-//  Description: Returns the D3DTEXTUREOP value corresponding to the
-//               indicated TextureStage::CombineMode enumerated type.
-////////////////////////////////////////////////////////////////////
-D3DTEXTUREOP DXGraphicsStateGuardian8::
-get_texture_operation(TextureStage::CombineMode mode, int scale) {
-  switch (mode) {
-  case TextureStage::CM_undefined:
-  case TextureStage::CM_replace:
-    return D3DTOP_SELECTARG1;
-
-  case TextureStage::CM_modulate:
-    if (scale < 2) {
-      return D3DTOP_MODULATE;
-    } else if (scale < 4) {
-      return D3DTOP_MODULATE2X;
-    } else {
-      return D3DTOP_MODULATE4X;
-    }
-
-  case TextureStage::CM_add:
-    return D3DTOP_ADD;
-
-  case TextureStage::CM_add_signed:
-    if (scale < 2) {
-      return D3DTOP_ADDSIGNED;
-    } else {
-      return D3DTOP_ADDSIGNED2X;
-    }
-
-  case TextureStage::CM_interpolate:
-    return D3DTOP_LERP;
-
-  case TextureStage::CM_subtract:
-    return D3DTOP_SUBTRACT;
-
-  case TextureStage::CM_dot3_rgb:
-  case TextureStage::CM_dot3_rgba:
-    return D3DTOP_DOTPRODUCT3;
-  }
-
-  dxgsg8_cat.error()
-    << "Invalid TextureStage::CombineMode value (" << (int)mode << ")\n";
-  return D3DTOP_DISABLE;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_texture_argument
-//       Access: Protected, Static
-//  Description: Returns the D3DTA value corresponding to the
-//               indicated TextureStage::CombineSource and
-//               TextureStage::CombineOperand enumerated types.
-////////////////////////////////////////////////////////////////////
-DWORD DXGraphicsStateGuardian8::
-get_texture_argument(TextureStage::CombineSource source,
-                     TextureStage::CombineOperand operand) {
-  switch (source) {
-  case TextureStage::CS_undefined:
-  case TextureStage::CS_texture:
-    return D3DTA_TEXTURE | get_texture_argument_modifier(operand);
-
-  case TextureStage::CS_constant:
-  case TextureStage::CS_constant_color_scale:
-    return D3DTA_TFACTOR | get_texture_argument_modifier(operand);
-
-  case TextureStage::CS_primary_color:
-    return D3DTA_DIFFUSE | get_texture_argument_modifier(operand);
-
-  case TextureStage::CS_previous:
-    return D3DTA_CURRENT | get_texture_argument_modifier(operand);
-
-  case TextureStage::CS_last_saved_result:
-    return D3DTA_TEMP | get_texture_argument_modifier(operand);
-  }
-  dxgsg8_cat.error()
-    << "Invalid TextureStage::CombineSource value (" << (int)source << ")\n";
-  return D3DTA_CURRENT;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_texture_argument_modifier
-//       Access: Protected, Static
-//  Description: Returns the extra bits that modify the D3DTA
-//               argument, according to the indicated
-//               TextureStage::CombineOperand enumerated type.
-////////////////////////////////////////////////////////////////////
-DWORD DXGraphicsStateGuardian8::
-get_texture_argument_modifier(TextureStage::CombineOperand operand) {
-  switch (operand) {
-  case TextureStage::CO_src_color:
-    return 0;
-
-  case TextureStage::CO_one_minus_src_color:
-    return D3DTA_COMPLEMENT;
-
-  case TextureStage::CO_src_alpha:
-    return D3DTA_ALPHAREPLICATE;
-
-  case TextureStage::CO_one_minus_src_alpha:
-    return D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT;
-
-  case TextureStage::CO_undefined:
-    break;
-  }
-  dxgsg8_cat.error()
-    << "Invalid TextureStage::CombineOperand value (" << (int)operand << ")\n";
-  return 0;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_primitive_up
-//       Access: Protected
-//  Description: Issues the DrawPrimitiveUP call to draw the indicated
-//               primitive_type from the given buffer.  We add the
-//               num_vertices parameter, so we can determine the size
-//               of the buffer.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
-                  unsigned int primitive_count,
-                  unsigned int first_vertex,
-                  unsigned int num_vertices,
-                  const unsigned char *buffer, size_t stride) {
-
-  // It appears that the common ATI driver seems to fail to draw
-  // anything in the DrawPrimitiveUP() call if the address range of
-  // the buffer supplied crosses over a multiple of 0x10000.  That's
-  // incredibly broken, yet it undeniably appears to be true.  We'll
-  // have to hack around it.
-
-  const unsigned char *buffer_start = buffer + stride * first_vertex;
-  const unsigned char *buffer_end = buffer_start + stride * num_vertices;
-
-  if (buffer_end - buffer_start > 0x10000) {
-    // Actually, the buffer doesn't fit within the required limit
-    // anyway.  Go ahead and draw it and hope for the best.
-    _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
-                                 buffer_start, stride);
-
-  } else if ((((long)buffer_end ^ (long)buffer_start) & ~0xffff) == 0) {
-    // No problem; we can draw the buffer directly.
-    _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
-                                 buffer_start, stride);
-
-  } else {
-    // We have a problem--the buffer crosses over a 0x10000 boundary.
-    // We have to copy the buffer to a temporary buffer that we can
-    // draw from.
-    unsigned char *safe_buffer_start = get_safe_buffer_start();
-    memcpy(safe_buffer_start, buffer_start, buffer_end - buffer_start);
-    _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
-                                 safe_buffer_start, stride);
-
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::draw_indexed_primitive_up
-//       Access: Protected
-//  Description: Issues the DrawIndexedPrimitiveUP call to draw the
-//               indicated primitive_type from the given buffer.  As
-//               in draw_primitive_up(), above, the parameter list is
-//               not exactly one-for-one with the
-//               DrawIndexedPrimitiveUP() call, but it's similar (in
-//               particular, we pass max_index instead of NumVertices,
-//               which always seemed ambiguous to me).
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-draw_indexed_primitive_up(D3DPRIMITIVETYPE primitive_type,
-                          unsigned int min_index, unsigned int max_index,
-                          unsigned int num_primitives,
-                          const unsigned char *index_data,
-                          D3DFORMAT index_type,
-                          const unsigned char *buffer, size_t stride) {
-  // As above, we'll hack the case of the buffer crossing the 0x10000
-  // boundary.
-  const unsigned char *buffer_start = buffer + stride * min_index;
-  const unsigned char *buffer_end = buffer + stride * (max_index + 1);
-
-  if (buffer_end - buffer > 0x10000) {
-    // Actually, the buffer doesn't fit within the required limit
-    // anyway.  Go ahead and draw it and hope for the best.
-    _d3d_device->DrawIndexedPrimitiveUP
-      (primitive_type, min_index, max_index - min_index + 1, num_primitives,
-       index_data, index_type, buffer, stride);
-
-  } else if ((((long)buffer_end ^ (long)buffer) & ~0xffff) == 0) {
-    // No problem; we can draw the buffer directly.
-    _d3d_device->DrawIndexedPrimitiveUP
-      (primitive_type, min_index, max_index - min_index + 1, num_primitives,
-       index_data, index_type, buffer, stride);
-
-  } else {
-    // We have a problem--the buffer crosses over a 0x10000 boundary.
-    // We have to copy the buffer to a temporary buffer that we can
-    // draw from.
-    unsigned char *safe_buffer_start = get_safe_buffer_start();
-    size_t offset = buffer_start - buffer;
-    memcpy(safe_buffer_start + offset, buffer_start, buffer_end - buffer_start);
-    _d3d_device->DrawIndexedPrimitiveUP
-      (primitive_type, min_index, max_index - min_index + 1, num_primitives,
-       index_data, index_type, safe_buffer_start, stride);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//  DX stencil code section
-////////////////////////////////////////////////////////////////////
-static int dx_stencil_comparison_function_array[] = {
-  D3DCMP_NEVER,
-  D3DCMP_LESS,
-  D3DCMP_EQUAL,
-  D3DCMP_LESSEQUAL,
-  D3DCMP_GREATER,
-  D3DCMP_NOTEQUAL,
-  D3DCMP_GREATEREQUAL,
-  D3DCMP_ALWAYS,
-};
-
-static int dx_stencil_operation_array[] = {
-  D3DSTENCILOP_KEEP,
-  D3DSTENCILOP_ZERO,
-  D3DSTENCILOP_REPLACE,
-  D3DSTENCILOP_INCR,
-  D3DSTENCILOP_DECR,
-  D3DSTENCILOP_INVERT,
-
-  D3DSTENCILOP_INCRSAT,
-  D3DSTENCILOP_DECRSAT,
-};
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::do_issue_stencil
-//       Access: Protected
-//  Description: Set stencil render states.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_stencil() {
-  if (!_supports_stencil) {
-    return;
-  }
-
-  const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib(StencilAttrib::get_class_slot()));
-
-  if (stencil != (const StencilAttrib *)NULL) {
-    // DEBUG
-    if (false) {
-      dxgsg8_cat.debug() << "STENCIL STATE CHANGE\n";
-      dxgsg8_cat.debug() << "\n"
-        << "SRS_front_comparison_function " << stencil->get_render_state(StencilAttrib::SRS_front_comparison_function) << "\n"
-        << "SRS_front_stencil_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation) << "\n"
-        << "SRS_front_stencil_pass_z_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n"
-        << "SRS_front_stencil_pass_z_pass_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n"
-        << "SRS_reference " << stencil->get_render_state(StencilAttrib::SRS_reference) << "\n"
-        << "SRS_read_mask " << stencil->get_render_state(StencilAttrib::SRS_read_mask) << "\n"
-        << "SRS_write_mask " << stencil->get_render_state(StencilAttrib::SRS_write_mask) << "\n";
-    }
-
-    unsigned int front_compare;
-    front_compare = stencil->get_render_state(StencilAttrib::SRS_front_comparison_function);
-    if (front_compare != RenderAttrib::M_none) {
-      set_render_state(D3DRS_STENCILENABLE, TRUE);
-      set_render_state(D3DRS_STENCILFUNC, dx_stencil_comparison_function_array[front_compare]);
-      set_render_state(D3DRS_STENCILFAIL, dx_stencil_operation_array[
-        stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation)]);
-      set_render_state(D3DRS_STENCILZFAIL, dx_stencil_operation_array[
-        stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation)]);
-      set_render_state(D3DRS_STENCILPASS, dx_stencil_operation_array[
-        stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation)]);
-
-      set_render_state(D3DRS_STENCILREF, stencil->get_render_state(StencilAttrib::SRS_reference));
-      set_render_state(D3DRS_STENCILMASK, stencil->get_render_state(StencilAttrib::SRS_read_mask));
-      set_render_state(D3DRS_STENCILWRITEMASK, stencil->get_render_state(StencilAttrib::SRS_write_mask));
-    } else {
-      set_render_state(D3DRS_STENCILENABLE, FALSE);
-    }
-
-    if (stencil->get_render_state(StencilAttrib::SRS_clear)) {
-      _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, 0, 0.0f, stencil->get_render_state(StencilAttrib::SRS_clear_value));
-    }
-
-  } else {
-    // DEBUG
-    if (false) {
-      dxgsg8_cat.debug() << "STENCIL STATE CHANGE TO OFF\n";
-    }
-
-    set_render_state(D3DRS_STENCILENABLE, FALSE);
-  }
-}
-
-LPDIRECT3DDEVICE8 DXGraphicsStateGuardian8::
-get_d3d_device() {
-  return _d3d_device;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: dxGraphicsStateGuardian8::do_issue_scissor
-//       Access: Protected
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-do_issue_scissor() {
-  const ScissorAttrib *target_scissor = DCAST(ScissorAttrib, _target_rs->get_attrib_def(ScissorAttrib::get_class_slot()));
-  const LVecBase4 &frame = target_scissor->get_frame();
-  set_scissor(frame[0], frame[1], frame[2], frame[3]);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_scissor
-//       Access: Private
-//  Description: Sets up the scissor region, as a set of coordinates
-//               relative to the current viewport.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-set_scissor(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
-  // DirectX8 doesn't have an explicit scissor control, independent of
-  // the viewport, so we have to do it by hand, by moving the viewport
-  // smaller but adjusting the projection matrix to compensate.
-
-  // First, constrain the viewport to the scissor region.
-  D3DVIEWPORT8 vp;
-  vp.Width = _current_viewport.Width * (right - left);
-  vp.X = _current_viewport.X + _current_viewport.Width * left;
-  vp.Height = _current_viewport.Height * (top - bottom);
-  vp.Y = _current_viewport.Y + _current_viewport.Height * (1.0f - top);
-  vp.MinZ = 0.0f;
-  vp.MaxZ = 1.0f;
-
-  HRESULT hr = _d3d_device->SetViewport(&vp);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "_screen->_swap_chain = " << _screen->_swap_chain << " _swap_chain = " << _swap_chain << "\n";
-    dxgsg8_cat.error()
-      << "SetViewport(" << vp.X << ", " << vp.Y << ", " << vp.Width << ", " << vp.Height
-      << ") failed" << D3DERRORSTRING(hr);
-
-    D3DVIEWPORT8 vp_old;
-    _d3d_device->GetViewport(&vp_old);
-    dxgsg8_cat.error()
-      << "GetViewport(" << vp_old.X << ", " << vp_old.Y << ", " << vp_old.Width << ", "
-      << vp_old.Height << ") returned: Trying to set that vp---->\n";
-    hr = _d3d_device->SetViewport(&vp_old);
-
-    if (FAILED(hr)) {
-      dxgsg8_cat.error() << "Failed again\n";
-      throw_event("panda3d-render-error");
-      nassertv(false);
-    }
-  }
-
-  // Now, compute _scissor_mat, which we use to compensate the
-  // projection matrix.
-  PN_stdfloat xsize = right - left;
-  PN_stdfloat ysize = top - bottom;
-  PN_stdfloat xcenter = (left + right) - 1.0f;
-  PN_stdfloat ycenter = (bottom + top) - 1.0f;
-  if (xsize == 0.0f || ysize == 0.0f) {
-    // If the scissor region is zero, nothing will be drawn anyway, so
-    // don't worry about it.
-    _scissor_mat = TransformState::make_identity();
-  } else {
-    _scissor_mat = TransformState::make_scale(LVecBase3(1.0f / xsize, 1.0f / ysize, 1.0f))->compose(TransformState::make_pos(LPoint3(-xcenter, -ycenter, 0.0f)));
-  }
-  prepare_lens();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: dxGraphicsStateGuardian8::calc_fb_properties
-//       Access: Public
-//  Description: Convert DirectX framebuffer format ids into a
-//               FrameBufferProperties structure.
-////////////////////////////////////////////////////////////////////
-FrameBufferProperties DXGraphicsStateGuardian8::
-calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype) {
-  FrameBufferProperties props;
-  int index=0;
-  int r=0, g=0, b=0, a=0;
-  switch (cformat) {
-  case D3DFMT_R8G8B8:      r=8; g=8; b=8; a=0; break;
-  case D3DFMT_A8R8G8B8:    r=8; g=8; b=8; a=8; break;
-  case D3DFMT_X8R8G8B8:    r=8; g=8; b=8; a=0; break;
-  case D3DFMT_R5G6B5:      r=5; g=6; b=5; a=0; break;
-  case D3DFMT_X1R5G5B5:    r=5; g=5; b=5; a=0; break;
-  case D3DFMT_A1R5G5B5:    r=5; g=5; b=5; a=1; break;
-  case D3DFMT_A4R4G4B4:    r=4; g=4; b=4; a=4; break;
-  case D3DFMT_R3G3B2:      r=3; g=3; b=2; a=0; break;
-  case D3DFMT_A8R3G3B2:    r=3; g=3; b=2; a=8; break;
-  case D3DFMT_X4R4G4B4:    r=4; g=4; b=4; a=0; break;
-  case D3DFMT_A2B10G10R10: r=10;g=10;b=10;a=2; break;
-  case D3DFMT_A8P8:        index=8; a=8; break;
-  case D3DFMT_P8:          index=8; a=0; break;
-  default: break;
-  }
-  if (index > 0) {
-    props.set_rgb_color(0);
-    props.set_indexed_color(1);
-    props.set_color_bits(index);
-  } else if (r + g + b > 0) {
-    props.set_rgb_color(1);
-    props.set_indexed_color(0);
-    props.set_rgba_bits(r, g, b, a);
-  }
-  props.set_alpha_bits(a);
-
-  int depth=0;
-  int stencil=0;
-  switch (dformat) {
-  case D3DFMT_D32:     depth=32; stencil=0; break;
-  case D3DFMT_D15S1:   depth=15; stencil=1; break;
-  case D3DFMT_D24S8:   depth=24; stencil=8; break;
-  case D3DFMT_D16:     depth=16; stencil=0; break;
-  case D3DFMT_D24X8:   depth=24; stencil=0; break;
-  case D3DFMT_D24X4S4: depth=24; stencil=4; break;
-  default: break;
-  }
-  props.set_depth_bits(depth);
-  props.set_stencil_bits(stencil);
-  props.set_multisamples(multisampletype);
-  return props;
-}
-
-#define GAMMA_1 (255.0 * 256.0)
-
-static bool _gamma_table_initialized = false;
-static unsigned short _orignial_gamma_table [256 * 3];
-
-void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table, unsigned short *original_green_table, unsigned short *original_blue_table, unsigned short *red_table, unsigned short *green_table, unsigned short *blue_table) {
-  int i;
-  double gamma_correction;
-
-  if (gamma <= 0.0) {
-    // avoid divide by zero and negative exponents
-    gamma = 1.0;
-  }
-  gamma_correction = 1.0 / (double) gamma;
-
-  for (i = 0; i < 256; i++) {
-    double r;
-    double g;
-    double b;
-
-    if (original_red_table) {
-      r = (double) original_red_table [i] / GAMMA_1;
-      g = (double) original_green_table [i] / GAMMA_1;
-      b = (double) original_blue_table [i] / GAMMA_1;
-    }
-    else {
-      r = ((double) i / 255.0);
-      g = r;
-      b = r;
-    }
-
-    r = pow (r, gamma_correction);
-    g = pow (g, gamma_correction);
-    b = pow (b, gamma_correction);
-
-    if (r > 1.00) {
-      r = 1.0;
-    }
-    if (g > 1.00) {
-      g = 1.0;
-    }
-    if (b > 1.00) {
-      b = 1.0;
-    }
-
-    r = r * GAMMA_1;
-    g = g * GAMMA_1;
-    b = b * GAMMA_1;
-
-    red_table [i] = r;
-    green_table [i] = g;
-    blue_table [i] = b;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::get_gamma_table
-//       Access: Public, Static
-//  Description: Static function for getting the original gamma.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-get_gamma_table(void) {
-  bool get;
-
-  get = false;
-  if (_gamma_table_initialized == false) {
-    HDC hdc = GetDC(NULL);
-
-    if (hdc) {
-      if (GetDeviceGammaRamp (hdc, (LPVOID) _orignial_gamma_table)) {
-        _gamma_table_initialized = true;
-        get = true;
-      }
-
-      ReleaseDC (NULL, hdc);
-    }
-  }
-
-  return get;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::static_set_gamma
-//       Access: Public, Static
-//  Description: Static function for setting gamma which is needed
-//               for atexit.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-static_set_gamma(bool restore, PN_stdfloat gamma) {
-  bool set;
-  HDC hdc = GetDC(NULL);
-
-  set = false;
-  if (hdc) {
-    unsigned short ramp [256 * 3];
-
-    if (restore && _gamma_table_initialized) {
-      _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
-    }
-    else {
-      _create_gamma_table (gamma, 0, 0, 0, &ramp [0], &ramp [256], &ramp [512]);
-    }
-
-    if (SetDeviceGammaRamp (hdc, ramp)) {
-      set = true;
-    }
-
-    ReleaseDC (NULL, hdc);
-  }
-
-  return set;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::set_gamma
-//       Access: Published
-//  Description: Non static version of setting gamma.  Returns true
-//               on success.
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian8::
-set_gamma(PN_stdfloat gamma) {
-  bool set;
-
-  set = static_set_gamma(false, gamma);
-  if (set) {
-    _gamma = gamma;
-  }
-
-  return set;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::restore_gamma
-//       Access: Published
-//  Description: Restore original gamma.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-restore_gamma() {
-  static_set_gamma(true, 1.0f);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian8::atexit_function
-//       Access: Public, Static
-//  Description: This function is passed to the atexit function.
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian8::
-atexit_function(void) {
-  static_set_gamma(true, 1.0);
-}

+ 0 - 309
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -1,309 +0,0 @@
-// Filename: dxGraphicsStateGuardian8.h
-// Created by:  mike (02Feb99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXGRAPHICSSTATEGUARDIAN8_H
-#define DXGRAPHICSSTATEGUARDIAN8_H
-
-#include "dxgsg8base.h"
-#include "dxTextureContext8.h"
-#include "config_dxgsg8.h"
-
-#include "graphicsStateGuardian.h"
-#include "texture.h"
-#include "displayRegion.h"
-#include "material.h"
-#include "depthTestAttrib.h"
-#include "cullFaceAttrib.h"
-#include "renderModeAttrib.h"
-#include "colorBlendAttrib.h"
-#include "fog.h"
-#include "pointerToArray.h"
-
-class Light;
-
-class DXTextureContext8;
-class DXVertexBufferContext8;
-class DXIndexBufferContext8;
-
-////////////////////////////////////////////////////////////////////
-//       Class : DXGraphicsStateGuardian8
-// Description : A GraphicsStateGuardian for rendering into DirectX8
-//               contexts.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXGraphicsStateGuardian8 : public GraphicsStateGuardian {
-public:
-  DXGraphicsStateGuardian8(GraphicsEngine *engine, GraphicsPipe *pipe);
-  ~DXGraphicsStateGuardian8();
-
-  FrameBufferProperties
-    calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype);
-
-  virtual TextureContext *prepare_texture(Texture *tex, int view);
-  void apply_texture(int i, TextureContext *tc, const SamplerState &sampler);
-  virtual bool update_texture(TextureContext *tc, bool force);
-  bool upload_texture(DXTextureContext8 *dtc, bool force);
-  virtual void release_texture(TextureContext *tc);
-  virtual bool extract_texture_data(Texture *tex);
-
-  virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data);
-  bool apply_vertex_buffer(VertexBufferContext *vbc,
-                           const GeomVertexArrayDataHandle *reader, bool force);
-  virtual void release_vertex_buffer(VertexBufferContext *vbc);
-
-  virtual IndexBufferContext *prepare_index_buffer(GeomPrimitive *data);
-  bool apply_index_buffer(IndexBufferContext *ibc,
-                          const GeomPrimitivePipelineReader *reader, bool force);
-  virtual void release_index_buffer(IndexBufferContext *ibc);
-
-  virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
-                                          Thread *current_thread);
-
-  virtual void clear(DrawableRegion *region);
-
-  virtual void prepare_display_region(DisplayRegionPipelineReader *dr);
-  virtual CPT(TransformState) calc_projection_mat(const Lens *lens);
-  virtual bool prepare_lens();
-
-  virtual bool begin_frame(Thread *current_thread);
-  virtual bool begin_scene();
-  virtual void end_scene();
-  virtual void end_frame(Thread *current_thread);
-
-  virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,
-                                     const GeomMunger *munger,
-                                     const GeomVertexDataPipelineReader *data_reader,
-                                     bool force);
-  virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader,
-                              bool force);
-  virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader,
-                              bool force);
-  virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader,
-                            bool force);
-  virtual bool draw_lines(const GeomPrimitivePipelineReader *reader,
-                          bool force);
-  virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader,
-                               bool force);
-  virtual bool draw_points(const GeomPrimitivePipelineReader *reader,
-                           bool force);
-  virtual void end_draw_primitives();
-
-  virtual bool framebuffer_copy_to_texture(Texture *tex, int view, int z,
-                                           const DisplayRegion *dr,
-                                           const RenderBuffer &rb);
-  virtual bool framebuffer_copy_to_ram(Texture *tex, int view, int z,
-                                       const DisplayRegion *dr,
-                                       const RenderBuffer &rb);
-  bool do_framebuffer_copy_to_ram(Texture *tex, int view, int z,
-                                  const DisplayRegion *dr,
-                                  const RenderBuffer &rb,
-                                  bool inverted);
-
-  virtual void reset();
-
-  virtual void apply_fog(Fog *fog);
-
-  virtual void bind_light(PointLight *light_obj, const NodePath &light,
-                          int light_id);
-  virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
-                          int light_id);
-  virtual void bind_light(Spotlight *light_obj, const NodePath &light,
-                          int light_id);
-
-  static D3DFORMAT get_index_type(Geom::NumericType numeric_type);
-  INLINE static DWORD LColor_to_D3DCOLOR(const LColor &cLColor);
-
-  virtual void set_state_and_transform(const RenderState *state,
-                                       const TransformState *transform);
-  LPDIRECT3DDEVICE8 get_d3d_device();
-  INLINE bool get_supports_render_texture() const;
-
-  static bool get_gamma_table(void);
-  static bool static_set_gamma(bool restore, PN_stdfloat gamma);
-  bool set_gamma(PN_stdfloat gamma);
-  void restore_gamma();
-  static void atexit_function(void);
-
-protected:
-  void do_issue_transform();
-  void do_issue_alpha_test();
-  void do_issue_render_mode();
-  void do_issue_rescale_normal();
-  void do_issue_color_write();
-  void do_issue_depth_test();
-  void do_issue_depth_write();
-  void do_issue_cull_face();
-  void do_issue_fog();
-  void do_issue_depth_offset();
-  void do_issue_tex_gen();
-  void do_issue_shade_model();
-  void do_issue_material();
-  void do_issue_texture();
-  void do_issue_blending();
-  void do_issue_stencil();
-  void do_issue_scissor();
-
-  void set_scissor(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top);
-
-  virtual void reissue_transforms();
-
-  virtual void enable_lighting(bool enable);
-  virtual void set_ambient_light(const LColor &color);
-  virtual void enable_light(int light_id, bool enable);
-
-  virtual void enable_clip_plane(int plane_id, bool enable);
-  virtual void bind_clip_plane(const NodePath &plane, int plane_id);
-
-  virtual void close_gsg();
-  void free_nondx_resources();
-  void free_d3d_device();
-
-  void set_draw_buffer(const RenderBuffer &rb);
-  void set_read_buffer(const RenderBuffer &rb);
-
-  void do_auto_rescale_normal();
-
-protected:
-  INLINE static D3DTEXTUREADDRESS get_texture_wrap_mode(SamplerState::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);
-
-  static D3DBLEND get_blend_func(ColorBlendAttrib::Operand operand);
-  void report_texmgr_stats();
-
-  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 *p_presentation_params,
-                           DXScreenData **screen = NULL);
-
-  bool check_cooperative_level();
-
-  void show_frame();
-
-  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(SamplerState::FilterType filter_type);
-  static D3DTEXTUREFILTERTYPE get_d3d_mip_type(SamplerState::FilterType filter_type);
-  static D3DTEXTUREOP get_texture_operation(TextureStage::CombineMode mode, int scale);
-  static DWORD get_texture_argument(TextureStage::CombineSource source,
-                                    TextureStage::CombineOperand operand);
-  static DWORD get_texture_argument_modifier(TextureStage::CombineOperand operand);
-
-  void draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
-       unsigned int primitive_count,
-       unsigned int first_vertex,
-       unsigned int num_vertices,
-       const unsigned char *buffer, size_t stride);
-  void draw_indexed_primitive_up(D3DPRIMITIVETYPE primitive_type,
-         unsigned int min_index, unsigned int max_index,
-         unsigned int num_primitives,
-         const unsigned char *index_data,
-         D3DFORMAT index_type,
-         const unsigned char *buffer, size_t stride);
-
-  INLINE static unsigned char *get_safe_buffer_start();
-
-protected:
-  DXScreenData *_screen;
-  LPDIRECT3DDEVICE8 _d3d_device;  // same as _screen->_d3d_device, cached for spd
-  IDirect3DSwapChain8 *_swap_chain;
-  D3DPRESENT_PARAMETERS _presentation_reset;  // This is built during reset device
-
-  bool _dx_is_ready;
-  HRESULT _last_testcooplevel_result;
-
-  bool _vertex_blending_enabled;
-  bool _supports_render_texture;
-
-  RenderBuffer::Type _cur_read_pixel_buffer;  // source for copy_pixel_buffer operation
-  bool _auto_rescale_normal;
-
-  PN_stdfloat _material_ambient;
-  PN_stdfloat _material_diffuse;
-  PN_stdfloat _material_specular;
-  PN_stdfloat _material_shininess;
-  PN_stdfloat _material_emission;
-
-  enum DxgsgFogType {
-    None,
-    PerVertexFog=D3DRS_FOGVERTEXMODE,
-    PerPixelFog=D3DRS_FOGTABLEMODE
-  };
-  DxgsgFogType _do_fog_type;
-
-  D3DVIEWPORT8 _current_viewport;
-
-  DWORD _clip_plane_bits;
-  CullFaceAttrib::Mode _cull_face_mode;
-  RenderModeAttrib::Mode _current_fill_mode;  //point/wireframe/solid
-
-  const DXVertexBufferContext8 *_active_vbuffer;
-  const DXIndexBufferContext8 *_active_ibuffer;
-
-  int _num_active_texture_stages;
-
-  // Cache the data necessary to bind each particular light each
-  // frame, so if we bind a given light multiple times, we only have
-  // to compute its data once.
-  typedef pmap<NodePath, D3DLIGHT8> DirectionalLights;
-  DirectionalLights _dlights;
-
-  bool _overlay_windows_supported;
-  bool _tex_stats_retrieval_impossible;
-
-  static D3DMATRIX _d3d_ident_mat;
-  CPT(TransformState) _scissor_mat;
-
-  static unsigned char *_temp_buffer;
-  static unsigned char *_safe_buffer_start;
-
-  list <wdxGraphicsBuffer8 **> _graphics_buffer_list;
-
-public:
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-
-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 wdxGraphicsBuffer8;
-  friend class wdxGraphicsPipe8;
-  friend class wdxGraphicsWindowGroup8;
-  friend class DXTextureContext8;
-};
-
-#include "dxGraphicsStateGuardian8.I"
-
-#endif
-

+ 0 - 14
panda/src/dxgsg8/dxIndexBufferContext8.I

@@ -1,14 +0,0 @@
-// Filename: dxIndexBufferContext8.I
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-

+ 0 - 173
panda/src/dxgsg8/dxIndexBufferContext8.cxx

@@ -1,173 +0,0 @@
-// Filename: dxIndexBufferContext8.cxx
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "dxIndexBufferContext8.h"
-#include "geomPrimitive.h"
-#include "config_dxgsg8.h"
-#include "graphicsStateGuardian.h"
-#include "pStatTimer.h"
-#include "dxgsg8base.h"
-
-TypeHandle DXIndexBufferContext8::_type_handle;
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXIndexBufferContext8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXIndexBufferContext8::
-DXIndexBufferContext8(PreparedGraphicsObjects *pgo, GeomPrimitive *data) :
-  IndexBufferContext(pgo, data),
-  _ibuffer(NULL)
-{
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXIndexBufferContext8::Destructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXIndexBufferContext8::
-~DXIndexBufferContext8() {
-  if (_ibuffer != NULL) {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "deleting index buffer " << _ibuffer << "\n";
-    }
-
-    RELEASE(_ibuffer, dxgsg8, "index buffer", RELEASE_ONCE);
-    _ibuffer = NULL;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXIndexBufferContext8::evict_lru
-//       Access: Public, Virtual
-//  Description: Evicts the page from the LRU.  Called internally when
-//               the LRU determines that it is full.  May also be
-//               called externally when necessary to explicitly evict
-//               the page.
-//
-//               It is legal for this method to either evict the page
-//               as requested, do nothing (in which case the eviction
-//               will be requested again at the next epoch), or
-//               requeue itself on the tail of the queue (in which
-//               case the eviction will be requested again much
-//               later).
-////////////////////////////////////////////////////////////////////
-void DXIndexBufferContext8::
-evict_lru() {
-  dequeue_lru();
-
-  if (_ibuffer != NULL) {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "deleting index buffer " << _ibuffer << "\n";
-    }
-
-    RELEASE(_ibuffer, dxgsg8, "index buffer", RELEASE_ONCE);
-    _ibuffer = NULL;
-  }
-
-  update_data_size_bytes(0);
-  mark_unloaded();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXIndexBufferContext8::create_ibuffer
-//       Access: Public
-//  Description: Creates a new index buffer (but does not upload data
-//               to it).
-////////////////////////////////////////////////////////////////////
-void DXIndexBufferContext8::
-create_ibuffer(DXScreenData &scrn, 
-               const GeomPrimitivePipelineReader *reader) {
-  nassertv(reader->get_object() == get_data());
-  Thread *current_thread = reader->get_current_thread();
-
-  if (_ibuffer != NULL) {
-    RELEASE(_ibuffer, dxgsg8, "index buffer", RELEASE_ONCE);
-    _ibuffer = NULL;
-  }
-
-  PStatTimer timer(GraphicsStateGuardian::_create_index_buffer_pcollector,
-                   current_thread);
-
-  D3DFORMAT index_type =
-    DXGraphicsStateGuardian8::get_index_type(reader->get_index_type());
-
-  HRESULT hr = scrn._d3d_device->CreateIndexBuffer
-//    (reader->get_data_size_bytes(), D3DUSAGE_WRITEONLY,
-//     index_type, D3DPOOL_MANAGED, &_ibuffer);
-    (reader->get_data_size_bytes(), D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC,
-     index_type, D3DPOOL_DEFAULT, &_ibuffer);
-  if (FAILED(hr)) {
-    dxgsg8_cat.warning()
-      << "CreateIndexBuffer failed" << D3DERRORSTRING(hr);
-    _ibuffer = NULL;
-  } else {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "creating index buffer " << _ibuffer << ": "
-        << reader->get_num_vertices() << " indices ("
-        << reader->get_vertices_reader()->get_array_format()->get_column(0)->get_numeric_type()
-        << ")\n";
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXIndexBufferContext8::upload_data
-//       Access: Public
-//  Description: Copies the latest data from the client store to
-//               DirectX.
-////////////////////////////////////////////////////////////////////
-bool DXIndexBufferContext8::
-upload_data(const GeomPrimitivePipelineReader *reader, bool force) {
-  nassertr(reader->get_object() == get_data(), false);
-  Thread *current_thread = reader->get_current_thread();
-
-  nassertr(_ibuffer != NULL, false);
-
-  const unsigned char *data_pointer = reader->get_read_pointer(force);
-  if (data_pointer == NULL) {
-    return false;
-  }
-  int data_size = reader->get_data_size_bytes();
-
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam()
-      << "copying " << data_size
-      << " bytes into index buffer " << _ibuffer << "\n";
-  }
-
-  PStatTimer timer(GraphicsStateGuardian::_load_index_buffer_pcollector,
-                   current_thread);
-
-  BYTE *local_pointer;
-//  HRESULT hr = _ibuffer->Lock(0, data_size, &local_pointer, 0);
-  HRESULT hr = _ibuffer->Lock(0, data_size, &local_pointer, D3DLOCK_DISCARD);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "IndexBuffer::Lock failed" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  GraphicsStateGuardian::_data_transferred_pcollector.add_level(data_size);
-  memcpy(local_pointer, data_pointer, data_size);
-
-  _ibuffer->Unlock();
-  return true;
-}
-

+ 0 - 62
panda/src/dxgsg8/dxIndexBufferContext8.h

@@ -1,62 +0,0 @@
-// Filename: dxIndexBufferContext8.h
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXINDEXBUFFERCONTEXT8_H
-#define DXINDEXBUFFERCONTEXT8_H
-
-#include "pandabase.h"
-#include "dxgsg8base.h"
-#include "indexBufferContext.h"
-
-////////////////////////////////////////////////////////////////////
-//       Class : DXIndexBufferContext8
-// Description : Caches a GeomPrimitive in the DirectX device as
-//               an index buffer.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXIndexBufferContext8 : public IndexBufferContext {
-public:
-  DXIndexBufferContext8(PreparedGraphicsObjects *pgo, GeomPrimitive *data);
-  virtual ~DXIndexBufferContext8();
-
-  virtual void evict_lru();
-
-  void create_ibuffer(DXScreenData &scrn,
-                      const GeomPrimitivePipelineReader *reader);
-  bool upload_data(const GeomPrimitivePipelineReader *reader, bool force);
-
-  IDirect3DIndexBuffer8 *_ibuffer;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    IndexBufferContext::init_type();
-    register_type(_type_handle, "DXIndexBufferContext8",
-                  IndexBufferContext::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-};
-
-#include "dxIndexBufferContext8.I"
-
-#endif
-
-

+ 0 - 272
panda/src/dxgsg8/dxInput8.cxx

@@ -1,272 +0,0 @@
-// Filename: dxInput8.cxx
-// Created by:  angelina jolie (07Oct99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "config_wdxdisplay8.h"
-#include "dxInput8.h"
-
-#define AXIS_RESOLUTION 2000   // use this many levels of resolution by default (could be more if needed and device supported it)
-#define AXIS_RANGE_CENTERED    // if defined, axis range is centered on 0, instead of starting on 0
-
-BOOL CALLBACK EnumGameCtrlsCallback( const DIDEVICEINSTANCE* pdidInstance,
-                                     VOID* pContext ) {
-    DI_DeviceInfos *pDevInfos = (DI_DeviceInfos *)pContext;
-
-    (*pDevInfos).push_back(*pdidInstance);
-
-    if(wdxdisplay_cat.is_debug())
-        wdxdisplay_cat.debug() << "Found DevType 0x" << (void*)pdidInstance->dwDevType << ": " << pdidInstance->tszInstanceName << ": " << pdidInstance->tszProductName <<endl;
-
-    return DIENUM_CONTINUE;
-}
-
-extern BOOL CALLBACK EnumObjectsCallbackJoystick(const DIDEVICEOBJECTINSTANCE* pdidoi,VOID* pContext);
-
-DInput8Info::DInput8Info() {
-    _pDInput8 = NULL;
-    _hDInputDLL = NULL;
-    _JoystickPollTimer = NULL;
-}
-
-DInput8Info::~DInput8Info() {
-  for(UINT i=0;i<_DeviceList.size();i++) {
-      _DeviceList[i]->Unacquire();
-      SAFE_RELEASE(_DeviceList[i]);
-  }
-
-  // bugbug: need to handle this
-  // if(_JoystickPollTimer!=NULL)
-  //   KillTimer(...)
-
-  SAFE_RELEASE(_pDInput8);
-  if(_hDInputDLL) {
-      FreeLibrary(_hDInputDLL);
-      _hDInputDLL=NULL;
-  }
-}
-
-bool DInput8Info::InitDirectInput() {
-    HRESULT hr;
-
-    // assumes dx8 exists
-    // use dynamic load so non-dinput programs don't have to load dinput
-    #define DLLNAME "dinput8.dll"
-    #define DINPUTCREATE "DirectInput8Create"
-
-    HINSTANCE _hDInputDLL = LoadLibrary(DLLNAME);
-    if(_hDInputDLL == 0) {
-        wdxdisplay_cat.fatal() << "LoadLibrary(" << DLLNAME <<") failed!, error=" << GetLastError() << endl;
-        exit(1);
-    }
-
-    typedef HRESULT (WINAPI * LPDIRECTINPUT8CREATE)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter);
-    LPDIRECTINPUT8CREATE pDInputCreate8;
-
-    pDInputCreate8 = (LPDIRECTINPUT8CREATE) GetProcAddress(_hDInputDLL,DINPUTCREATE);
-    if(pDInputCreate8 == NULL) {
-        wdxdisplay_cat.fatal() << "GetProcAddr failed for " << DINPUTCREATE << endl;
-        exit(1);
-    }
-
-    // Register with the DirectInput subsystem and get a pointer
-    // to a IDirectInput interface we can use.
-    // Create a DInput object
-    if( FAILED( hr = (*pDInputCreate8)(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
-                                         IID_IDirectInput8, (VOID**)&_pDInput8, NULL ) ) ) {
-        wdxdisplay_cat.error() << DINPUTCREATE << "failed" << D3DERRORSTRING(hr);
-        return false;
-    }
-
-    // enum all the joysticks,etc  (but not keybd/mouse)
-    if( FAILED( hr = _pDInput8->EnumDevices(DI8DEVCLASS_GAMECTRL,
-                                         EnumGameCtrlsCallback,
-                                         (LPVOID)&_DevInfos, DIEDFL_ATTACHEDONLY ) ) ) {
-        wdxdisplay_cat.error() << "EnumDevices failed" << D3DERRORSTRING(hr);
-        return false;
-    }
-
-    return true;
-}
-
-bool DInput8Info::CreateJoystickOrPad(HWND _window) {
-    bool bFoundDev = false;
-    UINT devnum=0;
-    char *errstr=NULL;
-
-    // look through the list for the first joystick or gamepad
-    for(;devnum<_DevInfos.size();devnum++) {
-        DWORD devType = GET_DIDEVICE_TYPE(_DevInfos[devnum].dwDevType);
-        if((devType==DI8DEVTYPE_GAMEPAD) ||(devType==DI8DEVTYPE_JOYSTICK)) {
-          bFoundDev=true;
-          break;
-        }
-    }
-
-    if(!bFoundDev) {
-        wdxdisplay_cat.error() << "Cant find an attached Joystick or GamePad!\n";
-        return false;
-    }
-
-    LPDIRECTINPUTDEVICE8 pJoyDevice;
-
-    // Obtain an interface to the enumerated joystick.
-    HRESULT hr = _pDInput8->CreateDevice(_DevInfos[devnum].guidInstance, &pJoyDevice, NULL );
-    if(FAILED(hr)) {
-        errstr="CreateDevice";
-        goto handle_error;
-    }
-
-    nassertr(pJoyDevice!=NULL, false);
-    _DeviceList.push_back(pJoyDevice);
-
-    // Set the data format to "simple joystick" - a predefined data format
-    //
-    // A data format specifies which controls on a device we are interested in,
-    // and how they should be reported. This tells DInput that we will be
-    // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
-    hr = pJoyDevice->SetDataFormat(&c_dfDIJoystick2);
-    if(FAILED(hr)) {
-        errstr="SetDataFormat";
-        goto handle_error;
-    }
-
-    // must be called AFTER SetDataFormat to get all the proper flags
-    DX_DECLARE_CLEAN(DIDEVCAPS, DIDevCaps);
-    hr = pJoyDevice->GetCapabilities(&DIDevCaps);
-    nassertr(SUCCEEDED(hr), false);
-
-    _DevCaps.push_back(DIDevCaps);
-
-    if(wdxdisplay_cat.is_debug())
-        wdxdisplay_cat.debug() << "Joy/Pad has " << DIDevCaps.dwAxes << " Axes, " <<  DIDevCaps.dwButtons << " Buttons, " <<  DIDevCaps.dwPOVs << " POVs" << endl;
-
-    // Set the cooperative level to let DInput know how this device should
-    // interact with the system and with other DInput applications.
-    hr = pJoyDevice->SetCooperativeLevel( _window, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
-    if(FAILED(hr)) {
-        errstr="SetCooperativeLevel";
-        goto handle_error;
-    }
-
-    // set the min/max values property for discovered axes.
-    hr = pJoyDevice->EnumObjects(EnumObjectsCallbackJoystick, (LPVOID)pJoyDevice, DIDFT_AXIS);
-    if(FAILED(hr)) {
-        errstr="EnumObjects";
-        goto handle_error;
-    }
-
-    return true;
-
-  handle_error:
-    wdxdisplay_cat.error() << errstr << " failed for (" << _DevInfos[devnum].tszInstanceName << ":" << _DevInfos[devnum].tszProductName << ")" << D3DERRORSTRING(hr);
-    return false;
-}
-
-//-----------------------------------------------------------------------------
-// Name: EnumObjectsCallback()
-// Desc: Callback function for enumerating objects (axes, buttons, POVs) on a
-//       joystick. This function enables user interface elements for objects
-//       that are found to exist, and scales axes min/max values.
-//-----------------------------------------------------------------------------
-BOOL CALLBACK EnumObjectsCallbackJoystick( const DIDEVICEOBJECTINSTANCE* pdidoi,
-                                   VOID* pContext ) {
-
-    LPDIRECTINPUTDEVICE8 pJoyDevice = (LPDIRECTINPUTDEVICE8) pContext;
-    HRESULT hr;
-
-    // For axes that are returned, set the DIPROP_RANGE property for the
-    // enumerated axis in order to scale min/max values.
-    if( pdidoi->dwType & DIDFT_AXIS ) {
-        DIPROPRANGE diprg;
-        diprg.diph.dwSize       = sizeof(DIPROPRANGE);
-        diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
-        diprg.diph.dwHow        = DIPH_BYID;
-        diprg.diph.dwObj        = pdidoi->dwType; // Specify the enumerated axis
-
-     #ifdef AXIS_RANGE_CENTERED
-        diprg.lMin              = -AXIS_RESOLUTION/2;
-        diprg.lMax              = +AXIS_RESOLUTION/2;
-     #else
-        diprg.lMin              = 0;
-        diprg.lMax              = +AXIS_RESOLUTION;
-     #endif
-
-        // Set the range for the axis
-        hr = pJoyDevice->SetProperty( DIPROP_RANGE, &diprg.diph);
-        if(FAILED(hr)) {
-          wdxdisplay_cat.error() << "SetProperty on axis failed" << D3DERRORSTRING(hr);
-          return DIENUM_STOP;
-        }
-    }
-
-    return DIENUM_CONTINUE;
-}
-
-bool DInput8Info::ReadJoystick(int devnum, DIJOYSTATE2 &js) {
-    LPDIRECTINPUTDEVICE8 pJoystick = _DeviceList[devnum];
-    nassertr(pJoystick!=NULL, false);
-    HRESULT hr;
-    char *errstr;
-
-    // Poll the device to read the current state
-
-    hr = pJoystick->Poll();
-
-    if( FAILED(hr) ) {
-        // DInput is telling us that the input stream has been
-        // interrupted. We aren't tracking any state between polls, so
-        // we don't have any special reset that needs to be done. We
-        // just re-acquire and try again.
-
-        if((hr==DIERR_NOTACQUIRED)||(hr == DIERR_INPUTLOST)) {
-            hr = pJoystick->Acquire();
-
-            if(FAILED(hr)) {
-                if(wdxdisplay_cat.is_spam())
-                   wdxdisplay_cat.spam() << "Acquire failed" << D3DERRORSTRING(hr);
-
-                // hr may be DIERR_OTHERAPPHASPRIO or other errors.  This
-                // may occur when the app is minimized or in the process of
-                // switching, so just try again later
-                return false;
-            }
-
-            hr = pJoystick->Poll();
-            if(FAILED(hr)) {
-                // should never happen!
-                errstr = "Poll after successful Acquire failed";
-                goto handle_error;
-            }
-        } else {
-            errstr =  "Unknown Poll failure";
-            goto handle_error;
-        }
-    }
-
-    // should we make a vector of devstate dataformats to generalize this fn for all device types?
-
-    // Get the input's device state
-    hr = pJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &js);
-    if(FAILED(hr)) {
-        errstr =  "GetDeviceState failed";
-        goto handle_error;
-    }
-
-    return true;
-
-  handle_error:
-     wdxdisplay_cat.fatal() << errstr << D3DERRORSTRING(hr);
-     return false;
-}
-
-

+ 0 - 41
panda/src/dxgsg8/dxInput8.h

@@ -1,41 +0,0 @@
-// Filename: dxInput8.h
-// Created by:  blllyjo (07Oct99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXINPUT8_H
-#define DXINPUT8_H
-
-#define DIRECTINPUT_VERSION 0x800
-#include <dinput.h>
-typedef vector<DIDEVICEINSTANCE> DI_DeviceInfos;
-typedef vector<DIDEVICEOBJECTINSTANCE> DI_DeviceObjInfos;
-
-class DInput8Info {
-public:
- DInput8Info();
- ~DInput8Info();
- bool InitDirectInput();
- bool CreateJoystickOrPad(HWND _window);
- bool ReadJoystick(int devnum, DIJOYSTATE2 &js);
-
- HINSTANCE _hDInputDLL;
- UINT_PTR  _JoystickPollTimer;
- LPDIRECTINPUT8 _pDInput8;
- DI_DeviceInfos _DevInfos;
- // arrays for all created devices.  Should probably put these together in a struct,
- // along with the data fmt info
- vector<LPDIRECTINPUTDEVICE8> _DeviceList;
- vector<DIDEVCAPS> _DevCaps;
-};
-
-#endif

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

@@ -1,69 +0,0 @@
-// Filename: dxTextureContext8.I
-// Created by:  drose (23May05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////////////
-//     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, whatever kind of texture it is.
-////////////////////////////////////////////////////////////////////
-INLINE IDirect3DBaseTexture8 *DXTextureContext8::
-get_d3d_texture() const {
-  return _d3d_texture;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::get_d3d_2d_texture
-//       Access: Public
-//  Description: Returns the Direct3D object that represents the
-//               texture, in the case of a 1-d or 2-d texture.
-////////////////////////////////////////////////////////////////////
-INLINE IDirect3DTexture8 *DXTextureContext8::
-get_d3d_2d_texture() const {
-  return _d3d_2d_texture;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::get_d3d_volume_texture
-//       Access: Public
-//  Description: Returns the Direct3D object that represents the
-//               texture, in the case of a 3-d texture.
-////////////////////////////////////////////////////////////////////
-INLINE IDirect3DVolumeTexture8 *DXTextureContext8::
-get_d3d_volume_texture() const {
-  return _d3d_volume_texture;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::get_d3d_cube_texture
-//       Access: Public
-//  Description: Returns the Direct3D object that represents the
-//               texture, in the case of a cube map texture.
-////////////////////////////////////////////////////////////////////
-INLINE IDirect3DCubeTexture8 *DXTextureContext8::
-get_d3d_cube_texture() const {
-  return _d3d_cube_texture;
-}

+ 0 - 1853
panda/src/dxgsg8/dxTextureContext8.cxx

@@ -1,1853 +0,0 @@
-// Filename: dxTextureContext8.cxx
-// Created by:  georges (02Feb02)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "dxTextureContext8.h"
-#include "config_dxgsg8.h"
-#include "dxGraphicsStateGuardian8.h"
-#include "pStatTimer.h"
-#include "dxgsg8base.h"
-#include "bamCache.h"
-#include "graphicsEngine.h"
-
-#include <assert.h>
-#include <time.h>
-
-TypeHandle DXTextureContext8::_type_handle;
-
-static const DWORD g_LowByteMask = 0x000000FF;
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXTextureContext8::
-DXTextureContext8(PreparedGraphicsObjects *pgo, Texture *tex, int view) :
-  TextureContext(pgo, tex, view) {
-
-  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;
-  _d3d_2d_texture = NULL;
-  _d3d_volume_texture = NULL;
-  _d3d_cube_texture = NULL;
-  _has_mipmaps = false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::Destructor
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXTextureContext8::
-~DXTextureContext8() {
-  delete_texture();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::evict_lru
-//       Access: Public, Virtual
-//  Description: Evicts the page from the LRU.  Called internally when
-//               the LRU determines that it is full.  May also be
-//               called externally when necessary to explicitly evict
-//               the page.
-//
-//               It is legal for this method to either evict the page
-//               as requested, do nothing (in which case the eviction
-//               will be requested again at the next epoch), or
-//               requeue itself on the tail of the queue (in which
-//               case the eviction will be requested again much
-//               later).
-////////////////////////////////////////////////////////////////////
-void DXTextureContext8::
-evict_lru() {
-  if (get_texture()->get_render_to_texture()) {
-    // Don't evict the result of render-to-texture.
-    mark_used_lru();
-    return;
-  }
-
-  dequeue_lru();
-  delete_texture();
-  update_data_size_bytes(0);
-  mark_unloaded();
-}
-
-////////////////////////////////////////////////////////////////////
-//     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.  The return value is true if the texture is
-//               successfully created, false otherwise.
-////////////////////////////////////////////////////////////////////
-bool DXTextureContext8::
-create_texture(DXScreenData &scrn) {
-  HRESULT hr;
-  int num_alpha_bits;     //  number of alpha bits in texture pixfmt
-  D3DFORMAT target_pixel_format = D3DFMT_UNKNOWN;
-  bool needs_luminance = false;
-  bool compress_texture = false;
-
-  Texture *tex = get_texture();
-  nassertr(IS_VALID_PTR(tex), false);
-
-  delete_texture();
-
-#ifdef DO_PSTATS
-  update_data_size_bytes(tex->estimate_texture_memory());
-#endif  // DO_PSTATS
-
-  // bpp indicates requested fmt, not texture fmt
-  DWORD target_bpp = get_bits_per_pixel(tex->get_format(), &num_alpha_bits);
-  DWORD num_color_channels = tex->get_num_components();
-
-  //PRINT_REFCNT(dxgsg8, scrn._d3d8);
-
-  DWORD orig_width = (DWORD)tex->get_x_size();
-  DWORD orig_height = (DWORD)tex->get_y_size();
-  DWORD orig_depth = (DWORD)tex->get_z_size();
-
-  if ((tex->get_format() == Texture::F_luminance_alpha)||
-      (tex->get_format() == Texture::F_luminance_alphamask) ||
-      (tex->get_format() == Texture::F_luminance)) {
-    needs_luminance = true;
-  }
-
-  if (num_alpha_bits > 0) {
-    if (num_color_channels == 3) {
-      dxgsg8_cat.error()
-        << "texture " << tex->get_name()
-        << " has no inherent alpha channel, but alpha format is requested!\n";
-    }
-  }
-
-  _d3d_format = D3DFMT_UNKNOWN;
-
-  // figure out what 'D3DFMT' the Texture is in, so D3DXLoadSurfFromMem knows how to perform copy
-
-  switch (num_color_channels) {
-  case 1:
-    if (num_alpha_bits > 0) {
-      _d3d_format = D3DFMT_A8;
-    } else if (needs_luminance) {
-      _d3d_format = D3DFMT_L8;
-    }
-    break;
-  case 2:
-    nassertr(needs_luminance && (num_alpha_bits > 0), false);
-    _d3d_format = D3DFMT_A8L8;
-    break;
-  case 3:
-    _d3d_format = D3DFMT_R8G8B8;
-    break;
-  case 4:
-    _d3d_format = D3DFMT_A8R8G8B8;
-    break;
-  }
-
-  // check for texture compression
-  bool texture_wants_compressed = false;
-  Texture::CompressionMode compression_mode = tex->get_ram_image_compression();
-  bool texture_stored_compressed = compression_mode != Texture::CM_off;
-  
-  if (texture_stored_compressed) {
-    texture_wants_compressed = true;  
-  }
-  else {
-    if (tex->get_compression() == Texture::CM_off) {
-      // no compression
-    }
-    else {    
-      if (tex->get_compression() == Texture::CM_default) {
-        // default = use "compressed-textures" config setting
-        if (compressed_textures) {
-          texture_wants_compressed = true;
-        }
-      }
-      else {
-        texture_wants_compressed = true;
-      }
-    }  
-  }
-
-  switch (tex->get_texture_type()) {
-    case Texture::TT_1d_texture:
-    case Texture::TT_2d_texture:
-    case Texture::TT_cube_map:
-      // no compression for render target textures, or very small
-      // textures
-      if (tex->get_render_to_texture() == false &&
-          orig_width >= 4 && orig_height >= 4) {
-        if (texture_wants_compressed){
-          compress_texture = true;
-        }
-      }
-      break;
-    case Texture::TT_3d_texture:
-      // not supported by all video chips
-      break;
-  }
-
-  // make sure we handled all the possible cases
-  nassertr(_d3d_format != D3DFMT_UNKNOWN, false);
-
-  DWORD target_width = orig_width;
-  DWORD target_height = orig_height;
-  DWORD target_depth = orig_depth;
-
-  DWORD filter_caps;
-
-  switch (tex->get_texture_type()) {
-  case Texture::TT_1d_texture:
-  case Texture::TT_2d_texture:
-    filter_caps = scrn._d3dcaps.TextureFilterCaps;
-
-    if (target_width > scrn._d3dcaps.MaxTextureWidth) {
-      target_width = scrn._d3dcaps.MaxTextureWidth;
-    }
-    if (target_height > scrn._d3dcaps.MaxTextureHeight) {
-      target_height = scrn._d3dcaps.MaxTextureHeight;
-    }
-
-    if (scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_POW2) {
-      if (!ISPOW2(target_width)) {
-        target_width = down_to_power_2(target_width);
-      }
-      if (!ISPOW2(target_height)) {
-        target_height = down_to_power_2(target_height);
-      }
-    }
-    break;
-
-  case Texture::TT_3d_texture:
-    if ((scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) == 0) {
-      dxgsg8_cat.warning()
-        << "3-d textures are not supported by this graphics driver.\n";
-      return false;
-    }
-
-    filter_caps = scrn._d3dcaps.VolumeTextureFilterCaps;
-
-    if (target_width > scrn._d3dcaps.MaxVolumeExtent) {
-      target_width = scrn._d3dcaps.MaxVolumeExtent;
-    }
-    if (target_height > scrn._d3dcaps.MaxVolumeExtent) {
-      target_height = scrn._d3dcaps.MaxVolumeExtent;
-    }
-    if (target_depth > scrn._d3dcaps.MaxVolumeExtent) {
-      target_depth = scrn._d3dcaps.MaxVolumeExtent;
-    }
-
-    if (scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2) {
-      if (!ISPOW2(target_width)) {
-        target_width = down_to_power_2(target_width);
-      }
-      if (!ISPOW2(target_height)) {
-        target_height = down_to_power_2(target_height);
-      }
-      if (!ISPOW2(target_depth)) {
-        target_depth = down_to_power_2(target_depth);
-      }
-    }
-    break;
-
-  case Texture::TT_cube_map:
-    if ((scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) == 0) {
-      dxgsg8_cat.warning()
-        << "Cube map textures are not supported by this graphics driver.\n";
-      return false;
-    }
-
-    filter_caps = scrn._d3dcaps.CubeTextureFilterCaps;
-
-    if (target_width > scrn._d3dcaps.MaxTextureWidth) {
-      target_width = scrn._d3dcaps.MaxTextureWidth;
-    }
-
-    if (scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) {
-      if (!ISPOW2(target_width)) {
-        target_width = down_to_power_2(target_width);
-      }
-    }
-
-    target_height = target_width;
-    break;
-  }
-
-  // checks for SQUARE reqmt (nvidia riva128 needs this)
-  if ((target_width != target_height) &&
-      (scrn._d3dcaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) != 0) {
-    // assume pow2 textures.  sum exponents, divide by 2 rounding down
-    // to get sq size
-    int i, width_exp, height_exp;
-    for (i = target_width, width_exp = 0; i > 1; width_exp++, i >>= 1) {
-    }
-    for (i = target_height, height_exp = 0; i > 1; height_exp++, i >>= 1) {
-    }
-    target_height = target_width = 1<<((width_exp+height_exp)>>1);
-  }
-
-  bool shrink_original = false;
-
-  if (orig_width != target_width || orig_height != target_height ||
-      orig_depth != target_depth) {
-    if (tex->get_texture_type() == Texture::TT_3d_texture) {
-      dxgsg8_cat.info()
-        << "Reducing size of " << tex->get_name()
-        << " from " << orig_width << "x" << orig_height << "x" << orig_depth
-        << " to " << target_width << "x" << target_height
-        << "x" << target_depth << "\n";
-    } else {
-      dxgsg8_cat.info()
-        << "Reducing size of " << tex->get_name()
-        << " from " << orig_width << "x" << orig_height
-        << " to " << target_width << "x" << target_height << "\n";
-    }
-
-    shrink_original = true;
-  }
-
-  const char *error_message;
-
-  error_message = "create_texture failed: couldn't find compatible device Texture Pixel Format for input texture";
-
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam()
-      << "create_texture handling target bitdepth: " << target_bpp
-      << " alphabits: " << num_alpha_bits << endl;
-  }
-
-  // I could possibly replace some of this logic with
-  // D3DXCheckTextureRequirements(), but it wouldn't handle all my
-  // specialized low-memory cases perfectly
-
-#define CHECK_FOR_FMT(FMT)  \
-                    if (scrn._supported_tex_formats_mask & FMT##_FLAG) {   \
-                        target_pixel_format = D3DFMT_##FMT;                 \
-                        goto found_matching_format; }
-
-  if (texture_stored_compressed && compress_texture) {
-    // if the texture is already compressed, we need to choose the
-    // corresponding format, otherwise we might end up
-    // cross-compressing from e.g. DXT5 to DXT3
-    switch (compression_mode){
-    case Texture::CM_dxt1:
-      CHECK_FOR_FMT(DXT1);
-      break;
-    case Texture::CM_dxt2:
-      CHECK_FOR_FMT(DXT2);
-      break;
-    case Texture::CM_dxt3:
-      CHECK_FOR_FMT(DXT3);
-      break;
-    case Texture::CM_dxt4:
-      CHECK_FOR_FMT(DXT4);
-      break;
-    case Texture::CM_dxt5:
-      CHECK_FOR_FMT(DXT5);
-      break;
-    }
-
-    // We don't support the compressed format.  Fall through.
-  }
-
-  if (compress_texture) {
-    if (num_alpha_bits <= 1) {
-      CHECK_FOR_FMT(DXT1);    
-    } else if (num_alpha_bits <= 4) {
-      CHECK_FOR_FMT(DXT3);    
-    } else {
-      CHECK_FOR_FMT(DXT5);
-    }
-  }
-
-  // We can't compress for some reason, so ensure the uncompressed
-  // image is ready to load.
-  if (texture_stored_compressed) {
-    tex->get_uncompressed_ram_image();
-    compression_mode = tex->get_ram_image_compression();
-    texture_stored_compressed = compression_mode != Texture::CM_off;
-    compress_texture = false;
-  }
-  
-  // handle each target bitdepth separately.  might be less confusing
-  // to reorg by num_color_channels (input type)
-  switch (target_bpp) {
-
-    // IMPORTANT NOTE:
-    // target_bpp is REQUESTED bpp, not what exists in the texture
-    // array (the texture array contains num_color_channels*8bits)
-
-  case 32:
-    if (!((num_color_channels == 3) || (num_color_channels == 4)))
-      break; //bail
-
-    CHECK_FOR_FMT(A8R8G8B8);
-    
-    if (num_alpha_bits>0) {
-      nassertr(num_color_channels == 4, false);
-
-      // no 32-bit fmt, look for 16 bit w/alpha  (1-15)
-
-      // 32 bit RGBA was requested, but only 16 bit alpha fmts are
-      // avail.  By default, convert to 4-4-4-4 which has 4-bit alpha
-      // for blurry edges.  If we know tex only needs 1 bit alpha
-      // (i.e. for a mask), use 1555 instead.
-
-
-      //  ConversionType ConvTo1 = Conv32to16_4444, ConvTo2 = Conv32to16_1555;
-      //  DWORD dwAlphaMask1 = 0xF000, dwAlphaMask2 = 0x8000;
-
-      // assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify
-      // 32->16 conversion.  This should be true on most cards.
-
-      if (num_alpha_bits == 1) {
-        CHECK_FOR_FMT(A1R5G5B5);
-      }
-
-      // normally prefer 4444 due to better alpha channel resolution
-      CHECK_FOR_FMT(A4R4G4B4);
-      CHECK_FOR_FMT(A1R5G5B5);
-
-      // At this point, bail.  Don't worry about converting to
-      // non-alpha formats yet, I think this will be a very rare case.
-      error_message = "create_texture failed: couldn't find compatible Tex DDPIXELFORMAT! no available 16 or 32-bit alpha formats!";
-    } else {
-      // convert 3 or 4 channel to closest 16bpp color fmt
-
-      if (num_color_channels == 3) {
-        CHECK_FOR_FMT(R5G6B5);
-        CHECK_FOR_FMT(X1R5G5B5);
-      } else {
-        CHECK_FOR_FMT(R5G6B5);
-        CHECK_FOR_FMT(X1R5G5B5);
-      }
-    }
-    break;
-
-  case 24:
-    nassertr(num_color_channels == 3, false);
-
-    CHECK_FOR_FMT(R8G8B8);
-    
-    // no 24-bit fmt.  look for 32 bit fmt (note: this is
-    // memory-hogging choice instead I could look for
-    // memory-conserving 16-bit fmt).
-    
-    CHECK_FOR_FMT(X8R8G8B8);
-    CHECK_FOR_FMT(A8R8G8B8);
-
-    // no 24-bit or 32 fmt.  look for 16 bit fmt (higher res 565 1st)
-    CHECK_FOR_FMT(R5G6B5);
-    CHECK_FOR_FMT(X1R5G5B5);
-    CHECK_FOR_FMT(A1R5G5B5);
-    break;
-
-  case 16:
-    if (needs_luminance) {
-      nassertr(num_alpha_bits > 0, false);
-      nassertr(num_color_channels == 2, false);
-
-      CHECK_FOR_FMT(A8L8);
-      CHECK_FOR_FMT(A8R8G8B8);
-
-      if (num_alpha_bits == 1) {
-        CHECK_FOR_FMT(A1R5G5B5);
-      }
-
-      // normally prefer 4444 due to better alpha channel resolution
-      CHECK_FOR_FMT(A4R4G4B4);
-      CHECK_FOR_FMT(A1R5G5B5);
-    } else {
-      nassertr((num_color_channels == 3)||(num_color_channels == 4), false);
-      // look for compatible 16bit fmts, if none then give up
-      // (don't worry about other bitdepths for 16 bit)
-      switch(num_alpha_bits) {
-      case 0:
-        if (num_color_channels == 3) {
-          CHECK_FOR_FMT(R5G6B5);
-          CHECK_FOR_FMT(X1R5G5B5);
-        } else {
-          nassertr(num_color_channels == 4, false);
-          // it could be 4 if user asks us to throw away the alpha channel
-          CHECK_FOR_FMT(R5G6B5);
-          CHECK_FOR_FMT(X1R5G5B5);
-        }
-        break;
-      case 1:
-        // app specifically requests 1-5-5-5 F_rgba5 case, where you
-        // explicitly want 1-5-5-5 fmt, as opposed to F_rgbm, which
-        // could use 32bpp ARGB.  fail if this particular fmt not
-        // avail.
-        nassertr(num_color_channels == 4, false);
-        CHECK_FOR_FMT(X1R5G5B5);
-        break;
-      case 4:
-        // app specifically requests 4-4-4-4 F_rgba4 case, as opposed
-        // to F_rgba, which could use 32bpp ARGB
-        nassertr(num_color_channels == 4, false);
-        CHECK_FOR_FMT(A4R4G4B4);
-        break;
-      default:
-        nassertr(false, false);  // problem in get_bits_per_pixel()?
-      }
-    }
-  case 8:
-    if (needs_luminance) {
-      // don't bother handling those other 8bit lum fmts like 4-4,
-      // since 16 8-8 is usually supported too
-      nassertr(num_color_channels == 1, false);
-
-      // look for native lum fmt first
-      CHECK_FOR_FMT(L8);
-      CHECK_FOR_FMT(L8);
-
-      CHECK_FOR_FMT(R8G8B8);
-      CHECK_FOR_FMT(X8R8G8B8);
-
-      CHECK_FOR_FMT(R5G6B5);
-      CHECK_FOR_FMT(X1R5G5B5);
-
-    } else if (num_alpha_bits == 8) {
-      // look for 16bpp A8L8, else 32-bit ARGB, else 16-4444.
-
-      // skip 8bit alpha only (D3DFMT_A8), because I think only voodoo
-      // supports it and the voodoo support isn't the kind of blending
-      // model we need somehow (is it that voodoo assumes color is
-      // white?  isnt that what we do in ConvAlpha8to32 anyway?)
-
-      CHECK_FOR_FMT(A8L8);
-      CHECK_FOR_FMT(A8R8G8B8);
-      CHECK_FOR_FMT(A4R4G4B4);
-    }
-    break;
-
-  default:
-    error_message = "create_texture failed: unhandled pixel bitdepth in DX loader";
-  }
-
-  // if we've gotten here, haven't found a match
-  dxgsg8_cat.error()
-    << error_message << ": " << tex->get_name() << endl
-    << "NumColorChannels: " << num_color_channels << "; NumAlphaBits: "
-    << num_alpha_bits << "; targetbpp: " <<target_bpp
-    << "; _supported_tex_formats_mask: 0x"
-    << (void*)scrn._supported_tex_formats_mask
-    << "; NeedLuminance: " << needs_luminance << endl;
-  goto error_exit;
-
-  ///////////////////////////////////////////////////////////
-
- found_matching_format:
-  // We found a suitable format that matches the texture's format.
-  
-  if (tex->get_match_framebuffer_format()) {
-    // Instead of creating a texture with the found format, we will
-    // need to make one that exactly matches the framebuffer's
-    // format.  Look up what that format is.
-    IDirect3DSurface8 *render_target;
-    hr = scrn._d3d_device->GetRenderTarget(&render_target);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "GetRenderTgt failed in create_texture: " << D3DERRORSTRING(hr);
-    } else {
-      D3DSURFACE_DESC surface_desc;
-      hr = render_target->GetDesc(&surface_desc);
-      if (FAILED(hr)) {
-        dxgsg8_cat.error()
-          << "GetDesc failed in create_texture: " << D3DERRORSTRING(hr);
-      } else {
-        if (target_pixel_format != surface_desc.Format) {
-          if (dxgsg8_cat.is_debug()) {
-            dxgsg8_cat.debug()
-              << "Chose format " << D3DFormatStr(surface_desc.Format)
-              << " instead of " << D3DFormatStr(target_pixel_format)
-              << " for texture to match framebuffer.\n";
-          }
-          target_pixel_format = surface_desc.Format;
-        }
-      }
-      SAFE_RELEASE(render_target);
-    }
-  }
-
-  // validate magfilter setting
-  // degrade filtering if no HW support
-
-  SamplerState::FilterType ft;
-
-  ft = tex->get_magfilter();
-  if ((ft != SamplerState::FT_linear) && ft != SamplerState::FT_nearest) {
-    // mipmap settings make no sense for magfilter
-    if (ft == SamplerState::FT_nearest_mipmap_nearest) {
-      ft = SamplerState::FT_nearest;
-    } else {
-      ft = SamplerState::FT_linear;
-    }
-  }
-
-  if (ft == SamplerState::FT_linear &&
-      (filter_caps & D3DPTFILTERCAPS_MAGFLINEAR) == 0) {
-    ft = SamplerState::FT_nearest;
-  }
-  tex->set_magfilter(ft);
-
-  // figure out if we are mipmapping this texture
-  ft = tex->get_minfilter();
-  _has_mipmaps = false;
-
-  if (!dx_ignore_mipmaps) {  // set if no HW mipmap capable
-    switch(ft) {
-    case SamplerState::FT_nearest_mipmap_nearest:
-    case SamplerState::FT_linear_mipmap_nearest:
-    case SamplerState::FT_nearest_mipmap_linear:  // pick nearest in each, interpolate linearly b/w them
-    case SamplerState::FT_linear_mipmap_linear:
-      _has_mipmaps = true;
-    }
-
-    if (dx_mipmap_everything) {  // debug toggle, ok to leave in since its just a creation cost
-      _has_mipmaps = true;
-      if (dxgsg8_cat.is_spam()) {
-        if (ft != SamplerState::FT_linear_mipmap_linear) {
-          dxgsg8_cat.spam()
-            << "Forcing trilinear mipmapping on DX texture ["
-            << tex->get_name() << "]\n";
-        }
-      }
-      ft = SamplerState::FT_linear_mipmap_linear;
-      tex->set_minfilter(ft);
-    }
-
-  } else if ((ft == SamplerState::FT_nearest_mipmap_nearest) ||   // cvt to no-mipmap filter types
-             (ft == SamplerState::FT_nearest_mipmap_linear)) {
-    ft = SamplerState::FT_nearest;
-
-  } else if ((ft == SamplerState::FT_linear_mipmap_nearest) ||
-            (ft == SamplerState::FT_linear_mipmap_linear)) {
-    ft = SamplerState::FT_linear;
-  }
-
-  nassertr((filter_caps & D3DPTFILTERCAPS_MINFPOINT) != 0, false);
-
-#define TRILINEAR_MIPMAP_TEXFILTERCAPS (D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MINFLINEAR)
-
-  // do any other filter type degradations necessary
-  switch(ft) {
-  case SamplerState::FT_linear_mipmap_linear:
-    if ((filter_caps & TRILINEAR_MIPMAP_TEXFILTERCAPS) != TRILINEAR_MIPMAP_TEXFILTERCAPS) {
-      if (filter_caps & D3DPTFILTERCAPS_MINFLINEAR) {
-        ft = SamplerState::FT_linear_mipmap_nearest;
-      } else {
-        // if you cant do linear in a level, you probably cant do
-        // linear b/w levels, so just do nearest-all
-        ft = SamplerState::FT_nearest_mipmap_nearest;
-      }
-    }
-    break;
-
-  case SamplerState::FT_nearest_mipmap_linear:
-    // if we don't have bilinear, do nearest_nearest
-    if (!((filter_caps & D3DPTFILTERCAPS_MIPFPOINT) &&
-          (filter_caps & D3DPTFILTERCAPS_MINFLINEAR))) {
-      ft = SamplerState::FT_nearest_mipmap_nearest;
-    }
-    break;
-
-  case SamplerState::FT_linear_mipmap_nearest:
-    // if we don't have mip linear, do nearest_nearest
-    if (!(filter_caps & D3DPTFILTERCAPS_MIPFLINEAR)) {
-      ft = SamplerState::FT_nearest_mipmap_nearest;
-    }
-    break;
-
-  case SamplerState::FT_linear:
-    if (!(filter_caps & D3DPTFILTERCAPS_MINFLINEAR)) {
-      ft = SamplerState::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 mip_level_count;
-
-  if (_has_mipmaps) {
-    tex->get_ram_image();
-    mip_level_count = tex->get_num_loadable_ram_mipmap_images();
-    if (mip_level_count < 2) {
-      // tell CreateTex to alloc space for all mip levels down to 1x1
-      mip_level_count = 0;
-
-      if (dxgsg8_cat.is_debug()) {
-        dxgsg8_cat.debug()
-          << "create_texture: generating mipmaps for " << tex->get_name()
-          << endl;
-      }
-    }
-  } else {
-    mip_level_count = 1;
-  }
-
-  DWORD usage;
-  D3DPOOL pool;
-
-  usage = 0;
-  if (tex->get_render_to_texture ()) {
-    // REQUIRED
-    pool = D3DPOOL_DEFAULT;
-    if (support_render_texture && scrn._dxgsg8 -> get_supports_render_texture ( )) {
-      usage |= D3DUSAGE_RENDERTARGET;
-    }
-  }
-  else {
-    pool = D3DPOOL_MANAGED;
-  }
-
-  switch (tex->get_texture_type()) {
-  case Texture::TT_1d_texture:
-  case Texture::TT_2d_texture:
-    hr = scrn._d3d_device->CreateTexture
-      (target_width, target_height, mip_level_count, usage,
-       target_pixel_format, pool, &_d3d_2d_texture);
-    _d3d_texture = _d3d_2d_texture;
-    break;
-
-  case Texture::TT_3d_texture:
-    hr = scrn._d3d_device->CreateVolumeTexture
-      (target_width, target_height, target_depth, mip_level_count, usage,
-       target_pixel_format, pool, &_d3d_volume_texture);
-    _d3d_texture = _d3d_volume_texture;
-    break;
-
-  case Texture::TT_cube_map:
-    hr = scrn._d3d_device->CreateCubeTexture
-      (target_width, mip_level_count, usage,
-       target_pixel_format, pool, &_d3d_cube_texture);
-    _d3d_texture = _d3d_cube_texture;
-    break;
-  }
-
-  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(target_pixel_format) << endl;
-  }
-
-  hr = fill_d3d_texture_pixels(scrn);
-  if (FAILED(hr)) {
-    goto error_exit;
-  }
-  
-  if (tex->get_post_load_store_cache()) {
-    tex->set_post_load_store_cache(false);
-    // OK, get the RAM image, and save it in a BamCache record.
-    if (extract_texture_data()) {
-      if (tex->has_ram_image()) {
-        BamCache *cache = BamCache::get_global_ptr();
-        PT(BamCacheRecord) record = cache->lookup(tex->get_fullpath(), "txo");
-        if (record != (BamCacheRecord *)NULL) {
-          record->set_data(tex, tex);
-          cache->store(record);
-        }
-      }
-    }
-  }
-
-  scrn._dxgsg8->get_engine()->texture_uploaded(tex);
-  mark_loaded();
-  return true;
-
- error_exit:
-
-  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
-  _d3d_2d_texture = NULL;
-  _d3d_volume_texture = NULL;
-  _d3d_cube_texture = NULL;
-  return false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::create_simple_texture
-//       Access: Public
-//  Description: 
-////////////////////////////////////////////////////////////////////
-bool DXTextureContext8::
-create_simple_texture(DXScreenData &scrn) {
-  nassertr(IS_VALID_PTR(get_texture()), false);
-
-  HRESULT hr;
-
-  delete_texture();
-
-  _d3d_format = D3DFMT_A8R8G8B8;
-  D3DFORMAT target_pixel_format = D3DFMT_A8R8G8B8;
-  DWORD target_bpp = 32;
-  DWORD num_color_channels = 4;
-
-  DWORD target_width = (DWORD)get_texture()->get_simple_x_size();
-  DWORD target_height = (DWORD)get_texture()->get_simple_y_size();
-  DWORD mip_level_count = 1;
-  DWORD usage = 0;
-  D3DPOOL pool = D3DPOOL_MANAGED;
-
-  int data_size = target_width * target_height * 4;
-
-  hr = scrn._d3d_device->CreateTexture
-    (target_width, target_height, mip_level_count, usage,
-     target_pixel_format, pool, &_d3d_2d_texture);
-  _d3d_texture = _d3d_2d_texture;      
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "D3D create_simple_texture failed!" << D3DERRORSTRING(hr);
-    dxgsg8_cat.error()
-      << "  width = " << target_width << " height = " << target_height << " target_pixel_format = " << target_pixel_format << "\n";
-
-    goto error_exit;
-  }
-
-  if (dxgsg8_cat.is_debug()) {
-    dxgsg8_cat.debug()
-      << "create_simple_texture: " << get_texture()->get_name()
-      << "\n";
-  }
-
-  {
-    CPTA_uchar image = get_texture()->get_simple_ram_image();
-
-    hr = -1;
-    //  hr = fill_d3d_texture_pixels(scrn);
-
-    IDirect3DSurface8 *surface = NULL;
-    _d3d_2d_texture->GetSurfaceLevel(0, &surface);
-
-    RECT source_size;
-    source_size.left = source_size.top = 0;
-    source_size.right = target_width;
-    source_size.bottom = target_height;
-
-    DWORD mip_filter = D3DX_FILTER_LINEAR;
-
-    hr = D3DXLoadSurfaceFromMemory
-      (surface, (PALETTEENTRY*)NULL, (RECT*)NULL, (LPCVOID)image.p(),
-       target_pixel_format, target_width * 4, (PALETTEENTRY*)NULL,
-       &source_size, mip_filter, (D3DCOLOR)0x0);
-
-    RELEASE(surface, dxgsg8, "create_simple_texture Surface", RELEASE_ONCE);
-  }
-    
-  if (FAILED(hr)) {
-    dxgsg8_cat.debug ()
-      << "*** fill_d3d_texture_pixels failed ***: format "
-      << target_pixel_format
-      << "\n";
-    
-    goto error_exit;
-  }
-
-  mark_simple_loaded();
-  return true;
-
- error_exit:
-  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
-  _d3d_2d_texture = NULL;
-  _d3d_volume_texture = NULL;
-  _d3d_cube_texture = NULL;
-  return false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::delete_texture
-//       Access: Public
-//  Description: Release the surface used to store the texture
-////////////////////////////////////////////////////////////////////
-void DXTextureContext8::
-delete_texture() {
-  if (_d3d_texture == NULL) {
-    // don't bother printing the msg below, since we already released it.
-    return;
-  }
-
-  RELEASE(_d3d_texture, dxgsg8, "texture", RELEASE_ONCE);
-  _d3d_2d_texture = NULL;
-  _d3d_volume_texture = NULL;
-  _d3d_cube_texture = NULL;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::extract_texture_data
-//       Access: Public
-//  Description: This method will be called in the draw thread to
-//               download the texture memory's image into its
-//               ram_image value.  It returns true on success, false
-//               otherwise.
-////////////////////////////////////////////////////////////////////
-bool DXTextureContext8::
-extract_texture_data() {
-  HRESULT hr;
-
-  Texture *tex = get_texture();
-  if (tex->get_texture_type() != Texture::TT_2d_texture) {
-    dxgsg8_cat.error()
-      << "Not supported: extract_texture_data for " << tex->get_texture_type()
-      << "\n";
-    return false;
-  }
-  nassertr(IS_VALID_PTR(_d3d_2d_texture), false);
-
-  D3DSURFACE_DESC desc;
-  hr = _d3d_2d_texture->GetLevelDesc(0, &desc);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "Texture::GetLevelDesc() failed!" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  int div = 1;
-  Texture::Format format = Texture::F_rgba;
-  Texture::CompressionMode compression = Texture::CM_off;
-
-  switch (desc.Format) {
-  case D3DFMT_R8G8B8:
-    format = Texture::F_rgb;
-    break;
-
-  case D3DFMT_A8R8G8B8:
-  case D3DFMT_X8R8G8B8:
-    break;
-
-  case D3DFMT_L8:
-    format = Texture::F_luminance;
-    break;
-
-  case D3DFMT_A8L8:
-    format = Texture::F_luminance_alpha;
-    break;
-
-  case D3DFMT_DXT1:
-    compression = Texture::CM_dxt1;
-    div = 4;
-    break;
-  case D3DFMT_DXT2:
-    compression = Texture::CM_dxt2;
-    div = 4;
-    break;
-  case D3DFMT_DXT3:
-    compression = Texture::CM_dxt3;
-    div = 4;
-    break;
-  case D3DFMT_DXT4:
-    compression = Texture::CM_dxt4;
-    div = 4;
-    break;
-  case D3DFMT_DXT5:
-    compression = Texture::CM_dxt5;
-    div = 4;
-    break;
-
-  default:
-    dxgsg8_cat.error()
-      << "Cannot extract texture data: unhandled surface format " 
-      << desc.Format << "\n";
-    return false;
-  }
-
-  int num_levels = _d3d_2d_texture->GetLevelCount();
-
-  tex->set_x_size(desc.Width);
-  tex->set_y_size(desc.Height);
-  tex->set_z_size(1);
-  tex->set_component_type(Texture::T_unsigned_byte);
-  tex->set_format(format);
-  tex->clear_ram_image();
-
-  for (int n = 0; n < num_levels; ++n) {
-    D3DLOCKED_RECT rect;
-    hr = _d3d_2d_texture->LockRect(n, &rect, NULL, D3DLOCK_READONLY);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "Texture::LockRect() failed!" << D3DERRORSTRING(hr);
-      return false;
-    }
-    
-    int x_size = tex->get_expected_mipmap_x_size(n);
-    int y_size = tex->get_expected_mipmap_y_size(n);
-    PTA_uchar image;
-
-    if (compression == Texture::CM_off) {
-      // Uncompressed, but we have to respect the pitch.
-      int pitch = x_size * tex->get_num_components() * tex->get_component_width();
-      pitch = min(pitch, (int)rect.Pitch);
-      int size = pitch * y_size;
-      image = PTA_uchar::empty_array(size);
-      if (pitch == rect.Pitch) {
-        // Easy copy.
-        memcpy(image.p(), rect.pBits, size);
-      } else {
-        // Harder copy: we have to de-interleave DirectX's extra bytes
-        // on the end of each row.
-        unsigned char *dest = image.p();
-        unsigned char *source = (unsigned char *)rect.pBits;
-        for (int yi = 0; yi < y_size; ++yi) {
-          memcpy(dest, source, pitch);
-          dest += pitch;
-          source += rect.Pitch;
-        }
-      }
-
-    } else {
-      // Compressed; just copy the data verbatim.
-      int size = rect.Pitch * (y_size / div);
-      image = PTA_uchar::empty_array(size);
-      memcpy(image.p(), rect.pBits, size);
-    }
-    
-    _d3d_2d_texture->UnlockRect(n);
-    if (n == 0) {
-      tex->set_ram_image(image, compression);
-    } else {
-      tex->set_ram_mipmap_image(n, image);
-    }
-  }
-    
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     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,
-           bool inverted, Texture *result, int view, int z) {
-
-  // still need custom conversion since d3d/d3dx has no way to convert
-  // arbitrary fmt to ARGB in-memory user buffer
-
-  HRESULT hr;
-  DWORD num_components = 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((num_components == 3) || (num_components == 4), E_FAIL);  // cant handle anything else now
-  nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
-
-  BYTE *buf = result->modify_ram_image();
-  if (z >= 0) {
-    nassertr(z < result->get_z_size(), E_FAIL);
-    buf += z * result->get_expected_ram_page_size();
-  }
-  if (view > 0) {
-    buf += (view * result->get_z_size()) * result->get_expected_ram_page_size();
-  }
-
-  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 x_window_offset, y_window_offset;
-  DWORD copy_width, copy_height;
-
-  D3DLOCKED_RECT locked_rect;
-  D3DSURFACE_DESC surface_desc;
-
-  hr = d3d_surface->GetDesc(&surface_desc);
-
-  x_window_offset = source_rect.left, y_window_offset = source_rect.top;
-  copy_width = RECT_XSIZE(source_rect);
-  copy_height = 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 (!((copy_width == result->get_x_size()) && (copy_height <= (DWORD)result->get_y_size()))) {
-    dxgsg8_cat.error()
-      << "d3d_surface_to_texture, Texture size (" << result->get_x_size()
-      << ", " << result->get_y_size()
-      << ") too small to hold display surface ("
-      << copy_width << ", " << copy_height << ")\n";
-    nassertr(false, E_FAIL);
-    return E_FAIL;
-  }
-
-  hr = d3d_surface->LockRect(&locked_rect, (CONST RECT*)NULL, (D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE));
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "d3d_surface_to_texture LockRect() failed!" << D3DERRORSTRING(hr);
-    return hr;
-  }
-
-  // ones not listed not handled yet
-  nassertr((surface_desc.Format == D3DFMT_A8R8G8B8) ||
-           (surface_desc.Format == D3DFMT_X8R8G8B8) ||
-           (surface_desc.Format == D3DFMT_R8G8B8) ||
-           (surface_desc.Format == D3DFMT_R5G6B5) ||
-           (surface_desc.Format == D3DFMT_X1R5G5B5) ||
-           (surface_desc.Format == D3DFMT_A1R5G5B5) ||
-           (surface_desc.Format == D3DFMT_A4R4G4B4), E_FAIL);
-
-  //buf contains raw ARGB in Texture byteorder
-
-  int byte_pitch = locked_rect.Pitch;
-  BYTE *surface_bytes = (BYTE *)locked_rect.pBits;
-
-  if (inverted) {
-    surface_bytes += byte_pitch * (y_window_offset + copy_height - 1);
-    byte_pitch = -byte_pitch;
-  } else {
-    surface_bytes += byte_pitch * y_window_offset;
-  }
-
-  // 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(surface_desc.Format)
-      << " DDSurf to " <<  num_components << "-channel panda Texture\n";
-  }
-
-  DWORD *dest_word = (DWORD *)buf;
-  BYTE *dest_byte = (BYTE *)buf;
-
-  switch(surface_desc.Format) {
-  case D3DFMT_A8R8G8B8:
-  case D3DFMT_X8R8G8B8: {
-    if (num_components == 4) {
-      DWORD *source_word;
-      BYTE *dest_line = (BYTE*)dest_word;
-
-      for (DWORD y = 0; y < copy_height; y++) {
-        source_word = ((DWORD*)surface_bytes) + x_window_offset;
-        memcpy(dest_line, source_word, byte_pitch);
-        dest_line += byte_pitch;
-  surface_bytes += byte_pitch;
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      DWORD *source_word;
-      for (DWORD y = 0; y < copy_height; y++) {
-        source_word = ((DWORD*)surface_bytes) + x_window_offset;
-
-        for (DWORD x = 0; x < copy_width; x++) {
-          BYTE r, g, b;
-          DWORD pixel = *source_word;
-
-          r = (BYTE)((pixel>>16) & g_LowByteMask);
-          g = (BYTE)((pixel>> 8) & g_LowByteMask);
-          b = (BYTE)((pixel    ) & g_LowByteMask);
-
-          *dest_byte++ = b;
-          *dest_byte++ = g;
-          *dest_byte++ = r;
-    source_word++;
-        }
-  surface_bytes += byte_pitch;
-      }
-    }
-    break;
-  }
-
-  case D3DFMT_R8G8B8: {
-    BYTE *source_byte;
-
-    if (num_components == 4) {
-      for (DWORD y = 0; y < copy_height; y++) {
-        source_byte = surface_bytes + x_window_offset * 3 * sizeof(BYTE);
-        for (DWORD x = 0; x < copy_width; x++) {
-          DWORD r, g, b;
-
-          b = *source_byte++;
-          g = *source_byte++;
-          r = *source_byte++;
-
-          *dest_word = 0xFF000000 | (r << 16) | (g << 8) | b;
-    dest_word++;
-        }
-  surface_bytes += byte_pitch;
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      for (DWORD y = 0; y < copy_height; y++) {
-        source_byte = surface_bytes + x_window_offset * 3 * sizeof(BYTE);
-        memcpy(dest_byte, source_byte, byte_pitch);
-        dest_byte += byte_pitch;
-  surface_bytes += byte_pitch;
-      }
-    }
-    break;
-  }
-
-  case D3DFMT_R5G6B5:
-  case D3DFMT_X1R5G5B5:
-  case D3DFMT_A1R5G5B5:
-  case D3DFMT_A4R4G4B4: {
-    WORD  *source_word;
-    // handle 0555, 1555, 0565, 4444 in same loop
-
-    BYTE redshift, greenshift, blueshift;
-    DWORD redmask, greenmask, bluemask;
-
-    if (surface_desc.Format == D3DFMT_R5G6B5) {
-      redshift = (11-3);
-      redmask = 0xF800;
-      greenmask = 0x07E0;
-      greenshift = (5-2);
-      bluemask = 0x001F;
-      blueshift = 3;
-    } else if (surface_desc.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;
-    }
-
-    if (num_components == 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 < copy_height; y++) {
-        source_word = ((WORD*)surface_bytes) + x_window_offset;
-        for (DWORD x = 0; x < copy_width; x++) {
-          WORD pixel = *source_word;
-          BYTE r, g, b;
-
-          b = (pixel & bluemask) << blueshift;
-          g = (pixel & greenmask) >> greenshift;
-          r = (pixel & redmask) >> redshift;
-
-          // alpha is just set to 0xFF
-
-          *dest_word = 0xFF000000 | (r << 16) | (g << 8) | b;
-    source_word++;
-    dest_word++;
-        }
-  surface_bytes += byte_pitch;
-      }
-    } else {
-      // 24bpp texture case (numComponents == 3)
-      for (DWORD y = 0; y < copy_height; y++) {
-        source_word = ((WORD*)surface_bytes) + x_window_offset;
-        for (DWORD x = 0; x < copy_width; x++) {
-          WORD pixel = *source_word;
-          BYTE r, g, b;
-
-          b = (pixel & bluemask) << blueshift;
-          g = (pixel & greenmask) >> greenshift;
-          r = (pixel & redmask) >> redshift;
-
-          *dest_byte++ = b;
-          *dest_byte++ = g;
-          *dest_byte++ = r;
-
-    source_word++;
-        }
-  surface_bytes += byte_pitch;
-      }
-    }
-    break;
-  }
-
-  default:
-    dxgsg8_cat.error()
-      << "d3d_surface_to_texture: unsupported D3DFORMAT!\n";
-  }
-
-  d3d_surface->UnlockRect();
-  return S_OK;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: calculate_row_byte_length
-//       Access: Private, hidden
-//  Description: local helper function, which calculates the 
-//               'row_byte_length' or 'pitch' needed for calling
-//               D3DXLoadSurfaceFromMemory.
-//               Takes compressed formats (DXTn) into account.
-////////////////////////////////////////////////////////////////////
-static UINT calculate_row_byte_length (int width, int num_color_channels, D3DFORMAT tex_format)
-{
-    UINT source_row_byte_length = 0;
-
-    // check for compressed textures and adjust source_row_byte_length and source_format accordingly
-    switch (tex_format) {
-      case D3DFMT_DXT1:
-          // for dxt1 compressed textures, the row_byte_lenght is "the width of one row of cells, in bytes"
-          // cells are 4 pixels wide, take up 8 bytes, and at least 1 cell has to be there.
-          source_row_byte_length = max(1,width / 4)*8;
-        break;
-      case D3DFMT_DXT2:
-      case D3DFMT_DXT3:
-      case D3DFMT_DXT4:
-      case D3DFMT_DXT5:
-          // analogue as above, but cells take up 16 bytes
-          source_row_byte_length = max(1,width / 4)*16;
-        break;
-      default:
-        // no known compression format.. usual calculation
-        source_row_byte_length = width*num_color_channels;
-        break;
-    }
-    return source_row_byte_length;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::fill_d3d_texture_mipmap_pixels
-//       Access: Private
-//  Description: Called from fill_d3d_texture_pixels, this function
-//               fills a single mipmap with texture data.
-//               Takes care of all necessery conversions and error
-//               handling.
-////////////////////////////////////////////////////////////////////
-HRESULT DXTextureContext8::fill_d3d_texture_mipmap_pixels(int mip_level, int depth_index, D3DFORMAT source_format)
-{
-  // This whole function was refactored out of fill_d3d_texture_pixels to make the code 
-  // more readable and to avoid code duplication.
-  IDirect3DSurface8 *mip_surface = NULL;
-  bool using_temp_buffer = false;
-  HRESULT hr = E_FAIL;
-  CPTA_uchar image = get_texture()->get_ram_mipmap_image(mip_level);
-  nassertr(!image.is_null(), E_FAIL);
-  BYTE *pixels = (BYTE*) image.p();
-  DWORD width  = (DWORD) get_texture()->get_expected_mipmap_x_size(mip_level);
-  DWORD height = (DWORD) get_texture()->get_expected_mipmap_y_size(mip_level);
-  int component_width = get_texture()->get_component_width();
-
-  pixels += depth_index * get_texture()->get_expected_ram_mipmap_page_size(mip_level);
-  
-  if (get_texture()->get_texture_type() == Texture::TT_cube_map) {
-    nassertr(IS_VALID_PTR(_d3d_cube_texture), E_FAIL);
-    hr = _d3d_cube_texture->GetCubeMapSurface((D3DCUBEMAP_FACES)depth_index, mip_level, &mip_surface);
-  } else {
-    nassertr(IS_VALID_PTR(_d3d_2d_texture), E_FAIL);
-    hr = _d3d_2d_texture->GetSurfaceLevel(mip_level, &mip_surface);
-  }
-
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "FillDDTextureMipmapPixels failed for " << get_texture()->get_name()
-      << ", GetSurfaceLevel failed" << D3DERRORSTRING(hr);
-    return E_FAIL;
-  }
-
-  RECT source_size;
-  source_size.left = source_size.top = 0;
-  source_size.right = width;
-  source_size.bottom = height;
-
-  UINT source_row_byte_length = calculate_row_byte_length(width, get_texture()->get_num_components(), source_format);
-
-  DWORD mip_filter;
-  // need filtering if size changes, (also if bitdepth reduced (need
-  // dithering)??)
-  mip_filter = D3DX_FILTER_LINEAR ; //| D3DX_FILTER_DITHER;  //dithering looks ugly on i810 for 4444 textures
-
-  // D3DXLoadSurfaceFromMemory will load black luminance and we want
-  // full white, so convert to explicit luminance-alpha format
-  if (_d3d_format == D3DFMT_A8) {
-    // alloc buffer for explicit D3DFMT_A8L8
-    USHORT *temp_buffer = new USHORT[width * height];
-    if (!IS_VALID_PTR(temp_buffer)) {
-      dxgsg8_cat.error()
-        << "FillDDTextureMipmapPixels couldnt alloc mem for temp pixbuf!\n";
-      goto exit_FillMipmapSurf;
-    }
-    using_temp_buffer = true;
-
-    USHORT *out_pixels = temp_buffer;
-    BYTE *source_pixels = pixels + component_width - 1;
-    for (UINT y = 0; y < height; y++) {
-      for (UINT x = 0; x < width; x++, source_pixels += component_width, out_pixels++) {
-        // add full white, which is our interpretation of alpha-only
-        // (similar to default adding full opaque alpha 0xFF to
-        // RGB-only textures)
-        *out_pixels = ((*source_pixels) << 8 ) | 0xFF;
-      }
-    }
-
-    source_format = D3DFMT_A8L8;
-    source_row_byte_length = width * sizeof(USHORT);
-    pixels = (BYTE*)temp_buffer;
-  } 
-  else if (component_width != 1) {
-    // Convert from 16-bit per channel (or larger) format down to
-    // 8-bit per channel.  This throws away precision in the
-    // original image, but dx8 doesn't support high-precision images
-    // anyway.
-
-    int num_components = get_texture()->get_num_components();
-    int num_pixels = width * height * num_components;
-    BYTE *temp_buffer = new BYTE[num_pixels];
-    if (!IS_VALID_PTR(temp_buffer)) {
-      dxgsg8_cat.error() << "FillDDTextureMipmapPixels couldnt alloc mem for temp pixbuf!\n";
-      goto exit_FillMipmapSurf;
-    }
-    using_temp_buffer = true;
-
-    BYTE *source_pixels = pixels + component_width - 1;
-    for (int i = 0; i < num_pixels; i++) {
-      temp_buffer[i] = *source_pixels;
-      source_pixels += component_width;
-    }
-    pixels = (BYTE*)temp_buffer;
-  }
-
-  // filtering may be done here if texture if targetsize != origsize
-#ifdef DO_PSTATS
-  GraphicsStateGuardian::_data_transferred_pcollector.add_level(source_row_byte_length * height);
-#endif
-  hr = D3DXLoadSurfaceFromMemory
-    (mip_surface, (PALETTEENTRY*)NULL, (RECT*)NULL, (LPCVOID)pixels,
-      source_format, source_row_byte_length, (PALETTEENTRY*)NULL,
-      &source_size, mip_filter, (D3DCOLOR)0x0);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "FillDDTextureMipmapPixels failed for " << get_texture()->get_name()
-      << ", mip_level " << mip_level
-      << ", D3DXLoadSurfFromMem failed" << D3DERRORSTRING(hr);
-  }
-
-exit_FillMipmapSurf:
-  if (using_temp_buffer) {
-    SAFE_DELETE_ARRAY(pixels);
-  }
-
-  RELEASE(mip_surface, dxgsg8, "FillDDTextureMipmapPixels MipSurface texture ptr", RELEASE_ONCE);
-  return hr;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::fill_d3d_texture_pixels
-//       Access: Private
-//  Description:
-////////////////////////////////////////////////////////////////////
-HRESULT DXTextureContext8::
-fill_d3d_texture_pixels(DXScreenData &scrn) {
-  Texture *tex = get_texture();
-  nassertr(IS_VALID_PTR(tex), E_FAIL);
-  if (tex->get_texture_type() == Texture::TT_3d_texture) {
-    return fill_d3d_volume_texture_pixels(scrn);
-  }
-
-  HRESULT hr = E_FAIL;
-  nassertr(IS_VALID_PTR(tex), E_FAIL);
-
-  CPTA_uchar image;
-  if (scrn._dxgsg8->get_supports_compressed_texture()) {
-    image = tex->get_ram_image();
-  } else {
-    image = tex->get_uncompressed_ram_image();
-  }
-
-  Texture::CompressionMode image_compression;
-  if (image.is_null()) {
-    image_compression = Texture::CM_off;
-  } else {
-    image_compression = tex->get_ram_image_compression();
-  }
-
-  if (!scrn._dxgsg8->get_supports_compressed_texture_format(image_compression)) {
-    image = tex->get_uncompressed_ram_image();
-    image_compression = Texture::CM_off;
-  }    
-  if (image.is_null()) {
-    // The texture doesn't have an image to load.  That's ok; it
-    // might be a texture we've rendered to by frame buffer
-    // operations or something.
-    return S_OK;
-  }
-  nassertr(IS_VALID_PTR((BYTE*)image.p()), E_FAIL);
-  nassertr(IS_VALID_PTR(_d3d_texture), E_FAIL);
-
-  PStatTimer timer(GraphicsStateGuardian::_load_texture_pcollector);
-
-  DWORD orig_depth = (DWORD) tex->get_z_size();
-  D3DFORMAT source_format = _d3d_format;
-
-  // check for compressed textures and adjust source_format accordingly
-  switch (image_compression) {
-  case Texture::CM_dxt1:
-    source_format = D3DFMT_DXT1;
-    break;
-  case Texture::CM_dxt2:
-    source_format = D3DFMT_DXT2;
-    break;
-  case Texture::CM_dxt3:
-    source_format = D3DFMT_DXT3;
-    break;
-  case Texture::CM_dxt4:
-    source_format = D3DFMT_DXT4;
-    break;
-  case Texture::CM_dxt5:
-    source_format = D3DFMT_DXT5;
-    break;
-  default:
-    // no known compression format.. no adjustment
-    break;
-  }
-  
-  for (unsigned int di = 0; di < orig_depth; di++) {
-    
-    // fill top level mipmap
-    hr = fill_d3d_texture_mipmap_pixels(0, di, source_format);
-    if (FAILED(hr)) {
-      return hr; // error message was already output in fill_d3d_texture_mipmap_pixels
-    }
-
-    if (_has_mipmaps) {
-      // if we have pre-calculated mipmap levels, use them, otherwise generate on the fly
-      int miplevel_count = _d3d_2d_texture->GetLevelCount(); // what if it's not a 2d texture?
-      if (miplevel_count <= tex->get_num_loadable_ram_mipmap_images()) {
-        dxgsg8_cat.debug()
-          << "Using pre-calculated mipmap levels for texture  " << tex->get_name() << "\n";
-
-        for (int mip_level = 1; mip_level < miplevel_count; ++mip_level) {
-          hr = fill_d3d_texture_mipmap_pixels(mip_level, di, source_format);
-          if (FAILED(hr)) {
-            return hr; // error message was already output in fill_d3d_texture_mipmap_pixels
-          }
-        }        
-      } 
-      else {
-        // mipmaps need to be generated.
-
-        DWORD mip_filter_flags;
-        if (!dx_use_triangle_mipgen_filter) {
-          mip_filter_flags = D3DX_FILTER_BOX;
-        } else {
-          mip_filter_flags = D3DX_FILTER_TRIANGLE;
-        }
-        
-        // mip_filter_flags |= D3DX_FILTER_DITHER;
-        hr = D3DXFilterTexture(_d3d_texture, (PALETTEENTRY*)NULL, 0,
-                               mip_filter_flags);
-        
-        if (FAILED(hr)) {
-          dxgsg8_cat.error()
-            << "FillDDSurfaceTexturePixels failed for " << tex->get_name()
-            << ", D3DXFilterTex failed" << D3DERRORSTRING(hr);
-        }
-      }
-    }
-  }
-
-  return hr;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::fill_d3d_volume_texture_pixels
-//       Access: Private
-//  Description:
-////////////////////////////////////////////////////////////////////
-HRESULT DXTextureContext8::
-fill_d3d_volume_texture_pixels(DXScreenData &scrn) {
-  Texture *tex = get_texture();
-  HRESULT hr = E_FAIL;
-  nassertr(IS_VALID_PTR(tex), E_FAIL);
-
-  CPTA_uchar image;
-  if (scrn._dxgsg8->get_supports_compressed_texture()) {
-    image = tex->get_ram_image();
-  } else {
-    image = tex->get_uncompressed_ram_image();
-  }
-
-  Texture::CompressionMode image_compression;
-  if (image.is_null()) {
-    image_compression = Texture::CM_off;
-  } else {
-    image_compression = tex->get_ram_image_compression();
-  }
-
-  if (!scrn._dxgsg8->get_supports_compressed_texture_format(image_compression) ||
-      tex->get_x_size() < 4 || tex->get_y_size() < 4) {
-    // If we don't support this particular compression method, or in
-    // any case if the texture is too small (DirectX won't accept a
-    // small compressed texture), then fetch and load the uncompressed
-    // version instead.
-    image = tex->get_uncompressed_ram_image();
-    image_compression = Texture::CM_off;
-  }    
-
-  if (image.is_null()) {
-    // The texture doesn't have an image to load.  That's ok; it
-    // might be a texture we've rendered to by frame buffer
-    // operations or something.
-    return S_OK;
-  }
-
-  PStatTimer timer(GraphicsStateGuardian::_load_texture_pcollector);
-
-  nassertr(IS_VALID_PTR(_d3d_texture), E_FAIL);
-  nassertr(tex->get_texture_type() == Texture::TT_3d_texture, E_FAIL);
-
-  DWORD orig_width  = (DWORD) tex->get_x_size();
-  DWORD orig_height = (DWORD) tex->get_y_size();
-  DWORD orig_depth = (DWORD) tex->get_z_size();
-  DWORD num_color_channels = tex->get_num_components();
-  D3DFORMAT source_format = _d3d_format;
-  BYTE *image_pixels = (BYTE*)image.p();
-  int component_width = tex->get_component_width();
-
-  nassertr(IS_VALID_PTR(image_pixels), E_FAIL);
-
-  IDirect3DVolume8 *mip_level_0 = NULL;
-  bool using_temp_buffer = false;
-  BYTE *pixels = image_pixels;
-
-  nassertr(IS_VALID_PTR(_d3d_volume_texture), E_FAIL);
-  hr = _d3d_volume_texture->GetVolumeLevel(0, &mip_level_0);
-
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "FillDDSurfaceTexturePixels failed for " << tex->get_name()
-      << ", GetSurfaceLevel failed" << D3DERRORSTRING(hr);
-    return E_FAIL;
-  }
-
-  D3DBOX source_size;
-  source_size.Left = source_size.Top = source_size.Front = 0;
-  source_size.Right = orig_width;
-  source_size.Bottom = orig_height;
-  source_size.Back = orig_depth;
-
-  UINT source_row_byte_length = orig_width * num_color_channels;
-  UINT source_page_byte_length = orig_height * source_row_byte_length;
-
-  DWORD level_0_filter, mip_filter_flags;
-  using_temp_buffer = false;
-
-  // need filtering if size changes, (also if bitdepth reduced (need
-  // dithering)??)
-  level_0_filter = D3DX_FILTER_LINEAR ; //| D3DX_FILTER_DITHER;  //dithering looks ugly on i810 for 4444 textures
-
-  // D3DXLoadSurfaceFromMemory will load black luminance and we want
-  // full white, so convert to explicit luminance-alpha format
-  if (_d3d_format == D3DFMT_A8) {
-    // alloc buffer for explicit D3DFMT_A8L8
-    USHORT *temp_buffer = new USHORT[orig_width * orig_height * orig_depth];
-    if (!IS_VALID_PTR(temp_buffer)) {
-      dxgsg8_cat.error()
-        << "FillDDSurfaceTexturePixels couldnt alloc mem for temp pixbuf!\n";
-      goto exit_FillDDSurf;
-    }
-    using_temp_buffer = true;
-
-    USHORT *out_pixels = temp_buffer;
-    BYTE *source_pixels = pixels + component_width - 1;
-    for (UINT z = 0; z < orig_depth; z++) {
-      for (UINT y = 0; y < orig_height; y++) {
-        for (UINT x = 0;
-             x < orig_width;
-             x++, source_pixels += component_width, out_pixels++) {
-          // add full white, which is our interpretation of alpha-only
-          // (similar to default adding full opaque alpha 0xFF to
-          // RGB-only textures)
-          *out_pixels = ((*source_pixels) << 8 ) | 0xFF;
-        }
-      }
-    }
-
-    source_format = D3DFMT_A8L8;
-    source_row_byte_length = orig_width * sizeof(USHORT);
-    source_page_byte_length = orig_height * source_row_byte_length;
-    pixels = (BYTE*)temp_buffer;
-
-  } else if (component_width != 1) {
-    // Convert from 16-bit per channel (or larger) format down to
-    // 8-bit per channel.  This throws away precision in the
-    // original image, but dx8 doesn't support high-precision images
-    // anyway.
-
-    int num_components = tex->get_num_components();
-    int num_pixels = orig_width * orig_height * orig_depth * num_components;
-    BYTE *temp_buffer = new BYTE[num_pixels];
-    if (!IS_VALID_PTR(temp_buffer)) {
-      dxgsg8_cat.error() << "FillDDSurfaceTexturePixels couldnt alloc mem for temp pixbuf!\n";
-      goto exit_FillDDSurf;
-    }
-    using_temp_buffer = true;
-
-    BYTE *source_pixels = pixels + component_width - 1;
-    for (int i = 0; i < num_pixels; i++) {
-      temp_buffer[i] = *source_pixels;
-      source_pixels += component_width;
-    }
-    pixels = (BYTE*)temp_buffer;
-  }
-
-
-  // filtering may be done here if texture if targetsize != origsize
-#ifdef DO_PSTATS
-  GraphicsStateGuardian::_data_transferred_pcollector.add_level(source_page_byte_length * orig_depth);
-#endif
-  hr = D3DXLoadVolumeFromMemory
-    (mip_level_0, (PALETTEENTRY*)NULL, (D3DBOX*)NULL, (LPCVOID)pixels,
-     source_format, source_row_byte_length, source_page_byte_length,
-     (PALETTEENTRY*)NULL,
-     &source_size, level_0_filter, (D3DCOLOR)0x0);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "FillDDSurfaceTexturePixels failed for " << tex->get_name()
-      << ", D3DXLoadVolumeFromMem failed" << D3DERRORSTRING(hr);
-    goto exit_FillDDSurf;
-  }
-
-  if (_has_mipmaps) {
-    if (!dx_use_triangle_mipgen_filter) {
-      mip_filter_flags = D3DX_FILTER_BOX;
-    } else {
-      mip_filter_flags = D3DX_FILTER_TRIANGLE;
-    }
-
-    //    mip_filter_flags| = D3DX_FILTER_DITHER;
-
-    hr = D3DXFilterTexture(_d3d_texture, (PALETTEENTRY*)NULL, 0,
-                           mip_filter_flags);
-    if (FAILED(hr)) {
-      dxgsg8_cat.error()
-        << "FillDDSurfaceTexturePixels failed for " << tex->get_name()
-        << ", D3DXFilterTex failed" << D3DERRORSTRING(hr);
-      goto exit_FillDDSurf;
-    }
-  }
-
- exit_FillDDSurf:
-  if (using_temp_buffer) {
-    SAFE_DELETE_ARRAY(pixels);
-  }
-  RELEASE(mip_level_0, dxgsg8, "FillDDSurf MipLev0 texture ptr", RELEASE_ONCE);
-  return hr;
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXTextureContext8::down_to_power_2
-//       Access: Private, Static
-//  Description: Returns the largest power of 2 less than or equal
-//               to value.
-////////////////////////////////////////////////////////////////////
-int DXTextureContext8::
-down_to_power_2(int value) {
-  int x = 1;
-  while ((x << 1) <= value) {
-    x = (x << 1);
-  }
-  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_stencil:
-    return 32;
-  case Texture::F_rgb5:
-    return 16;
-  case Texture::F_rgb8:
-  case Texture::F_rgb:
-    return 24;
-  case Texture::F_rgba8:
-  case Texture::F_rgba:
-    *alphbits = 8;
-    return 32;
-  case Texture::F_rgbm:
-    *alphbits = 1;
-    return 32;
-  case Texture::F_rgb12:
-    return 36;
-  case Texture::F_rgba12:
-    *alphbits = 12;
-    return 48;
-  }
-  return 8;
-}

+ 0 - 89
panda/src/dxgsg8/dxTextureContext8.h

@@ -1,89 +0,0 @@
-// Filename: dxTextureContext8.h
-// Created by:  drose (07Oct99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXTEXTURECONTEXT8_H
-#define DXTEXTURECONTEXT8_H
-
-#include "dxgsg8base.h"
-#include "texture.h"
-#include "textureContext.h"
-
-////////////////////////////////////////////////////////////////////
-//       Class : DXTextureContext8
-// Description :
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXTextureContext8 : public TextureContext {
-public:
-  DXTextureContext8(PreparedGraphicsObjects *pgo, Texture *tex, int view);
-  virtual ~DXTextureContext8();
-
-  virtual void evict_lru();
-
-  bool create_texture(DXScreenData &scrn);
-  bool create_simple_texture(DXScreenData &scrn);
-  void delete_texture();
-  bool extract_texture_data();
-
-  INLINE bool has_mipmaps() const;
-  INLINE IDirect3DBaseTexture8 *get_d3d_texture() const;
-  INLINE IDirect3DTexture8 *get_d3d_2d_texture() const;
-  INLINE IDirect3DVolumeTexture8 *get_d3d_volume_texture() const;
-  INLINE IDirect3DCubeTexture8 *get_d3d_cube_texture() const;
-
-  static HRESULT d3d_surface_to_texture(RECT &source_rect,
-          IDirect3DSurface8 *d3d_surface,
-          bool inverted, Texture *result,
-          int view, int z);
-
-private:
-  HRESULT fill_d3d_texture_mipmap_pixels(int mip_level, int depth_index, D3DFORMAT source_format);
-  HRESULT fill_d3d_texture_pixels();
-  HRESULT fill_d3d_texture_pixels(DXScreenData &scrn);
-  HRESULT fill_d3d_volume_texture_pixels(DXScreenData &scrn);
-  static int down_to_power_2(int value);
-  unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
-
-private:
-  D3DFORMAT _d3d_format;    // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
-  IDirect3DBaseTexture8 *_d3d_texture;
-  IDirect3DTexture8 *_d3d_2d_texture;
-  IDirect3DVolumeTexture8 *_d3d_volume_texture;
-  IDirect3DCubeTexture8 *_d3d_cube_texture;
-
-  bool _has_mipmaps;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    TextureContext::init_type();
-    register_type(_type_handle, "DXTextureContext8",
-          TextureContext::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-
-  friend class wdxGraphicsBuffer8;
-};
-
-#include "dxTextureContext8.I"
-
-#endif
-

+ 0 - 14
panda/src/dxgsg8/dxVertexBufferContext8.I

@@ -1,14 +0,0 @@
-// Filename: dxVertexBufferContext8.I
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-

+ 0 - 299
panda/src/dxgsg8/dxVertexBufferContext8.cxx

@@ -1,299 +0,0 @@
-// Filename: dxVertexBufferContext8.cxx
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "dxVertexBufferContext8.h"
-#include "geomVertexArrayData.h"
-#include "geomVertexArrayFormat.h"
-#include "graphicsStateGuardian.h"
-#include "pStatTimer.h"
-#include "internalName.h"
-#include "config_dxgsg8.h"
-#include "dxgsg8base.h"
-
-TypeHandle DXVertexBufferContext8::_type_handle;
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXVertexBufferContext8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXVertexBufferContext8::
-DXVertexBufferContext8(PreparedGraphicsObjects *pgo, GeomVertexArrayData *data) :
-  VertexBufferContext(pgo, data),
-  _vbuffer(NULL)
-{
-  // Now fill in the FVF code.
-  const GeomVertexArrayFormat *array_format = data->get_array_format();
-
-  // We have to start with the vertex data, and work up from there in
-  // order, since that's the way the FVF is defined.
-  int n = 0;
-  int num_columns = array_format->get_num_columns();
-
-  _fvf = 0;
-
-  if (n < num_columns &&
-      array_format->get_column(n)->get_name() == InternalName::get_vertex()) {
-    ++n;
-
-    int num_blend_values = 0;
-
-    if (n < num_columns &&
-        array_format->get_column(n)->get_name() == InternalName::get_transform_weight()) {
-      // We have hardware vertex animation.
-      num_blend_values = array_format->get_column(n)->get_num_values();
-      ++n;
-    }
-
-    if (n < num_columns &&
-        array_format->get_column(n)->get_name() == InternalName::get_transform_index()) {
-      // Furthermore, it's indexed vertex animation.
-      _fvf |= D3DFVF_LASTBETA_UBYTE4;
-      ++num_blend_values;
-      ++n;
-    }
-
-    switch (num_blend_values) {
-    case 0:
-      _fvf |= D3DFVF_XYZ;
-      break;
-
-    case 1:
-      _fvf |= D3DFVF_XYZB1;
-      break;
-
-    case 2:
-      _fvf |= D3DFVF_XYZB2;
-      break;
-
-    case 3:
-      _fvf |= D3DFVF_XYZB3;
-      break;
-
-    case 4:
-      _fvf |= D3DFVF_XYZB4;
-      break;
-
-    case 5:
-      _fvf |= D3DFVF_XYZB5;
-      break;
-    }
-  }
-
-  if (n < num_columns &&
-      array_format->get_column(n)->get_name() == InternalName::get_normal()) {
-    _fvf |= D3DFVF_NORMAL;
-    ++n;
-  }
-  if (n < num_columns &&
-      array_format->get_column(n)->get_name() == InternalName::get_color()) {
-    _fvf |= D3DFVF_DIFFUSE;
-    ++n;
-  }
-
-  // Now look for all of the texcoord names and enable them in the
-  // same order they appear in the array.
-  int texcoord_index = 0;
-  while (n < num_columns &&
-         array_format->get_column(n)->get_contents() == Geom::C_texcoord) {
-    const GeomVertexColumn *column = array_format->get_column(n);
-    switch (column->get_num_values()) {
-    case 1:
-      _fvf |= D3DFVF_TEXCOORDSIZE1(texcoord_index);
-      ++n;
-      break;
-    case 2:
-      _fvf |= D3DFVF_TEXCOORDSIZE2(texcoord_index);
-      ++n;
-      break;
-    case 3:
-      _fvf |= D3DFVF_TEXCOORDSIZE3(texcoord_index);
-      ++n;
-      break;
-    case 4:
-      _fvf |= D3DFVF_TEXCOORDSIZE4(texcoord_index);
-      ++n;
-      break;
-    }
-    ++texcoord_index;
-  }
-
-  switch (texcoord_index) {
-  case 0:
-    break;
-  case 1:
-    _fvf |= D3DFVF_TEX1;
-    break;
-  case 2:
-    _fvf |= D3DFVF_TEX2;
-    break;
-  case 3:
-    _fvf |= D3DFVF_TEX3;
-    break;
-  case 4:
-    _fvf |= D3DFVF_TEX4;
-    break;
-  case 5:
-    _fvf |= D3DFVF_TEX5;
-    break;
-  case 6:
-    _fvf |= D3DFVF_TEX6;
-    break;
-  case 7:
-    _fvf |= D3DFVF_TEX7;
-    break;
-  case 8:
-    _fvf |= D3DFVF_TEX8;
-    break;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXVertexBufferContext8::Destructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-DXVertexBufferContext8::
-~DXVertexBufferContext8() {
-  if (_vbuffer != NULL) {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "deleting vertex buffer " << _vbuffer << "\n";
-    }
-
-    RELEASE(_vbuffer, dxgsg8, "vertex buffer", RELEASE_ONCE);
-    _vbuffer = NULL;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXVertexBufferContext8::evict_lru
-//       Access: Public, Virtual
-//  Description: Evicts the page from the LRU.  Called internally when
-//               the LRU determines that it is full.  May also be
-//               called externally when necessary to explicitly evict
-//               the page.
-//
-//               It is legal for this method to either evict the page
-//               as requested, do nothing (in which case the eviction
-//               will be requested again at the next epoch), or
-//               requeue itself on the tail of the queue (in which
-//               case the eviction will be requested again much
-//               later).
-////////////////////////////////////////////////////////////////////
-void DXVertexBufferContext8::
-evict_lru() {
-  dequeue_lru();
-
-  if (_vbuffer != NULL) {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "deleting vertex buffer " << _vbuffer << "\n";
-    }
-
-    RELEASE(_vbuffer, dxgsg8, "vertex buffer", RELEASE_ONCE);
-    _vbuffer = NULL;
-  }
-
-  update_data_size_bytes(0);
-  mark_unloaded();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXVertexBufferContext8::create_vbuffer
-//       Access: Public
-//  Description: Creates a new vertex buffer (but does not upload data
-//               to it).
-////////////////////////////////////////////////////////////////////
-void DXVertexBufferContext8::
-create_vbuffer(DXScreenData &scrn,
-               const GeomVertexArrayDataHandle *reader) {
-  nassertv(reader->get_object() == get_data());
-  Thread *current_thread = reader->get_current_thread();
-
-  if (_vbuffer != NULL) {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "deleting vertex buffer " << _vbuffer << "\n";
-    }
-
-    RELEASE(_vbuffer, dxgsg8, "vertex buffer", RELEASE_ONCE);
-    _vbuffer = NULL;
-  }
-
-  PStatTimer timer(GraphicsStateGuardian::_create_vertex_buffer_pcollector,
-                   current_thread);
-
-  HRESULT hr = scrn._d3d_device->CreateVertexBuffer
-//    (reader->get_data_size_bytes(), D3DUSAGE_WRITEONLY,
-//     _fvf, D3DPOOL_MANAGED, &_vbuffer);
-     (reader->get_data_size_bytes(), D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC,
-     _fvf, D3DPOOL_DEFAULT, &_vbuffer);
-  if (FAILED(hr)) {
-    dxgsg8_cat.warning()
-      << "CreateVertexBuffer failed" << D3DERRORSTRING(hr);
-    _vbuffer = NULL;
-  } else {
-    if (dxgsg8_cat.is_debug()) {
-      dxgsg8_cat.debug()
-        << "created vertex buffer " << _vbuffer << ": "
-        << reader->get_num_rows() << " vertices "
-        << *reader->get_array_format() << "\n";
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DXVertexBufferContext8::upload_data
-//       Access: Public
-//  Description: Copies the latest data from the client store to
-//               DirectX.
-////////////////////////////////////////////////////////////////////
-bool DXVertexBufferContext8::
-upload_data(const GeomVertexArrayDataHandle *reader, bool force) {
-  nassertr(reader->get_object() == get_data(), false);
-  nassertr(_vbuffer != NULL, false);
-  Thread *current_thread = reader->get_current_thread();
-
-  const unsigned char *data_pointer = reader->get_read_pointer(force);
-  if (data_pointer == NULL) {
-    return false;
-  }
-  int data_size = reader->get_data_size_bytes();
-
-  if (dxgsg8_cat.is_spam()) {
-    dxgsg8_cat.spam()
-      << "copying " << data_size
-      << " bytes into vertex buffer " << _vbuffer << "\n";
-  }
-
-  PStatTimer timer(GraphicsStateGuardian::_load_vertex_buffer_pcollector,
-                   current_thread);
-
-  BYTE *local_pointer;
-//  HRESULT hr = _vbuffer->Lock(0, data_size, &local_pointer, 0);
-  HRESULT hr = _vbuffer->Lock(0, data_size, &local_pointer, D3DLOCK_DISCARD);
-  if (FAILED(hr)) {
-    dxgsg8_cat.error()
-      << "VertexBuffer::Lock failed" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  GraphicsStateGuardian::_data_transferred_pcollector.add_level(data_size);
-  memcpy(local_pointer, data_pointer, data_size);
-
-  _vbuffer->Unlock();
-  return true;
-}
-

+ 0 - 63
panda/src/dxgsg8/dxVertexBufferContext8.h

@@ -1,63 +0,0 @@
-// Filename: dxVertexBufferContext8.h
-// Created by:  drose (18Mar05)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXVERTEXBUFFERCONTEXT8_H
-#define DXVERTEXBUFFERCONTEXT8_H
-
-#include "pandabase.h"
-#include "dxgsg8base.h"
-#include "vertexBufferContext.h"
-
-////////////////////////////////////////////////////////////////////
-//       Class : DXVertexBufferContext8
-// Description : Caches a GeomVertexArrayData in the DirectX device as
-//               a vertex buffer.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX DXVertexBufferContext8 : public VertexBufferContext {
-public:
-  DXVertexBufferContext8(PreparedGraphicsObjects *pgo, GeomVertexArrayData *data);
-  virtual ~DXVertexBufferContext8();
-
-  virtual void evict_lru();
-
-  void create_vbuffer(DXScreenData &scrn,
-                      const GeomVertexArrayDataHandle *reader);
-  bool upload_data(const GeomVertexArrayDataHandle *reader, bool force);
-
-  IDirect3DVertexBuffer8 *_vbuffer;
-  int _fvf;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    VertexBufferContext::init_type();
-    register_type(_type_handle, "DXVertexBufferContext8",
-                  VertexBufferContext::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-};
-
-#include "dxVertexBufferContext8.I"
-
-#endif
-
-

+ 0 - 208
panda/src/dxgsg8/dxgsg8base.h

@@ -1,208 +0,0 @@
-// Filename: dxgsg8base.h
-// Created by:  georges (07Oct01)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef DXGSG8BASE_H
-#define DXGSG8BASE_H
-
-#include "pandabase.h"
-#include "graphicsWindow.h"
-#include "pmap.h"
-
-#define WIN32_LEAN_AND_MEAN   // get rid of mfc win32 hdr stuff
-#ifndef STRICT
-// enable strict type checking in windows.h, see msdn
-#define STRICT
-#endif
-
-#define DIRECT3D_VERSION 0x0800
-#include <windows.h>
-#include <d3d8.h>
-#include <d3dx8.h>
-#include <dxerr8.h>
-#include <d3dx8tex.h>
-#undef WIN32_LEAN_AND_MEAN
-
-#ifndef D3DERRORSTRING
-#ifdef NDEBUG
-#define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" <<  DXGetErrorString8(HRESULT) << endl  // leave out descriptions to shrink release build
-#else
-#define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" <<  DXGetErrorString8(HRESULT) << ": " << DXGetErrorDescription8(HRESULT) << endl
-#endif
-#endif
-
-// imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either
-#define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.VendorId==0x10DE) || (DDDEVICEID.VendorId==0x12D2))
-#define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002)
-#define IS_MATROX(DDDEVICEID) (DDDEVICEID.VendorId==0x102B)
-
-#define D3D_MAXTEXTURESTAGES 8
-
-typedef enum {VertexShader,PixelShader} ShaderType;
-typedef DWORD DXShaderHandle;
-
-#define ISPOW2(X) (((X) & ((X)-1))==0)
-#define IS_VALID_PTR(PTR)  (!IsBadWritePtr(PTR,sizeof(void*)))
-
-#define DX_DECLARE_CLEAN(type, var) \
-    type var;                       \
-    ZeroMemory(&var, sizeof(type)); \
-    var.dwSize = sizeof(type);
-
-#define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE)  \
-  if((HANDLE!=NULL)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE);  HANDLE=NULL; }
-
-#define SAFE_DELETE(p)       { if(p) { assert(IS_VALID_PTR(p));   delete (p);     (p)=NULL; } }
-#define SAFE_DELETE_ARRAY(p) { if(p) { assert(IS_VALID_PTR(p));   delete [] (p);   (p)=NULL; } }
-
-// for stuff outside a panda class
-#define SAFE_RELEASE(p)      { if(p) { assert(IS_VALID_PTR(p)); (p)->Release(); (p)=NULL; } }
-#define SAFE_FREELIB(hDLL)   { if(hDLL!=NULL) {  FreeLibrary(hDLL);hDLL = NULL; } }
-
-// this is bDoDownToZero argument to RELEASE()
-#define RELEASE_DOWN_TO_ZERO true
-#define RELEASE_ONCE false
-
-
-// uncomment to add refcnt debug output
-#define DEBUG_RELEASES
-
-#ifdef DEBUG_RELEASES
-#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)             {  \
-   ULONG refcnt;                                                \
-   if(IS_VALID_PTR(OBJECT)) {                                   \
-        refcnt = (OBJECT)->Release();                           \
-        MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; \
-        if((bDoDownToZero) && (refcnt>0)) {                     \
-              MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
-              do {                                \
-                refcnt = (OBJECT)->Release();     \
-              } while(refcnt>0);                  \
-        }                                         \
-        (OBJECT) = NULL;                          \
-      } else {                                    \
-        MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << endl;  \
-      }}
-
-#define PRINT_REFCNT(MODULE,p) { ULONG refcnt;  (p)->AddRef();  refcnt=(p)->Release(); \
-                                 MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; }
-
-#else
-#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)   { \
-   ULONG refcnt;                                        \
-   if(IS_VALID_PTR(OBJECT))                           { \
-        refcnt=(OBJECT)->Release();                     \
-        if((bDoDownToZero) && (refcnt>0)) {             \
-              MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
-              do {                                \
-                refcnt = (OBJECT)->Release();     \
-              } while(refcnt>0);                  \
-        }                                         \
-        (OBJECT) = NULL;                          \
-   }}
-
-#define PRINT_REFCNT(MODULE,p)
-#endif
-
-#ifdef DO_PSTATS
-#define DO_PSTATS_STUFF(XX) XX;
-#else
-#define DO_PSTATS_STUFF(XX)
-#endif
-
-#define PANDA_MAXNUMVERTS 0xFFFF  // Note Device may support more than this if it supports D3DFMT_INDEX32 indexbufs.
-
-#define FLG(NN) (1<<NN)
-#define MAX_POSSIBLE_TEXFMTS 32
-typedef enum {
-    R8G8B8_FLAG =       FLG(0),
-    A8R8G8B8_FLAG =     FLG(1),
-    X8R8G8B8_FLAG =     FLG(2),
-    R5G6B5_FLAG =       FLG(3),
-    X1R5G5B5_FLAG =     FLG(4),
-    A1R5G5B5_FLAG =     FLG(5),
-    A4R4G4B4_FLAG =     FLG(6),
-    R3G3B2_FLAG =       FLG(7),
-    A8_FLAG =           FLG(8),
-    A8R3G3B2_FLAG =     FLG(9),
-    X4R4G4B4_FLAG =     FLG(10),
-    A2B10G10R10_FLAG =  FLG(11),
-    G16R16_FLAG =       FLG(12),
-    A8P8_FLAG =         FLG(13),
-    P8_FLAG =           FLG(14),
-    L8_FLAG =           FLG(15),
-    A8L8_FLAG =         FLG(16),
-    A4L4_FLAG =         FLG(17),
-    V8U8_FLAG =         FLG(18),
-    L6V5U5_FLAG =       FLG(19),
-    X8L8V8U8_FLAG =     FLG(20),
-    Q8W8V8U8_FLAG =     FLG(21),
-    V16U16_FLAG =       FLG(22),
-    W11V11U10_FLAG =    FLG(23),
-    A2W10V10U10_FLAG =  FLG(24),
-    UYVY_FLAG =         FLG(25),
-    YUY2_FLAG =         FLG(26),
-    DXT1_FLAG =         FLG(27),
-    DXT2_FLAG =         FLG(28),
-    DXT3_FLAG =         FLG(29),
-    DXT4_FLAG =         FLG(30),
-    DXT5_FLAG =         FLG(31)
-} D3DFORMAT_FLAG;
-
-// this is only used in conjunction w/rendertgt fmts, so just make it something that can never be a rtgt
-#define DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT1_FLAG
-#define DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG DXT2_FLAG
-
-#define IS_16BPP_DISPLAY_FORMAT(FMT) (((FMT)==D3DFMT_R5G6B5)||((FMT)==D3DFMT_X1R5G5B5)||((FMT)==D3DFMT_A1R5G5B5))
-#define IS_16BPP_ZBUFFER(FMT) ((FMT==D3DFMT_D16)||(FMT==D3DFMT_D15S1))
-#define IS_STENCIL_FORMAT(FMT) (((FMT)==D3DFMT_D24S8) || ((FMT)==D3DFMT_D15S1) || ((FMT)==D3DFMT_D24X4S4))
-#define RECT_XSIZE(REC) (REC.right-REC.left)
-#define RECT_YSIZE(REC) (REC.bottom-REC.top)
-
-class DXGraphicsStateGuardian8;
-
-struct DXScreenData {
-  LPDIRECT3DDEVICE8 _d3d_device;
-  IDirect3DSwapChain8 *_swap_chain;
-  LPDIRECT3D8 _d3d8;  // copied from DXGraphicsPipe8 for convenience
-  HWND _window;
-  HMONITOR _monitor;
-  DWORD _max_available_video_memory;
-  ushort _card_id;  // adapter ID
-  ushort _depth_buffer_bitdepth;  //GetSurfaceDesc is not reliable so must store this explicitly
-  bool _can_direct_disable_color_writes;  // if true, don't need blending for this
-  bool _is_low_memory_card;
-  bool _is_tnl_device;
-  bool _can_use_hw_vertex_shaders;
-  bool _can_use_pixel_shaders;
-  bool _is_dx8_1;
-  UINT _supported_screen_depths_mask;
-  UINT _supported_tex_formats_mask;
-  D3DCAPS8 _d3dcaps;
-  D3DDISPLAYMODE _display_mode;
-  D3DPRESENT_PARAMETERS _presentation_params;  // not redundant with _display_mode since width/height must be 0 for windowed mode
-  D3DADAPTER_IDENTIFIER8 _dx_device_id;
-  D3DFORMAT _render_to_texture_d3d_format;
-  D3DFORMAT _framebuffer_d3d_format;
-
-  DXGraphicsStateGuardian8 *_dxgsg8;
-};
-
-
-//utility stuff
-extern pmap<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
-extern void Init_D3DFORMAT_map();
-extern const char *D3DFormatStr(D3DFORMAT fmt);
-
-#endif
-

+ 0 - 10
panda/src/dxgsg8/p3dxgsg8_composite1.cxx

@@ -1,10 +0,0 @@
-#include "dxgsg8base.h"
-#include "config_dxgsg8.cxx"
-#include "dxTextureContext8.cxx"
-#include "dxVertexBufferContext8.cxx"
-#include "dxIndexBufferContext8.cxx"
-#include "dxGeomMunger8.cxx"
-#include "wdxGraphicsPipe8.cxx"
-#include "wdxGraphicsWindow8.cxx"
-#include "wdxGraphicsBuffer8.cxx"
-#include "dxGraphicsDevice8.cxx"

+ 0 - 27
panda/src/dxgsg8/wdxGraphicsBuffer8.I

@@ -1,27 +0,0 @@
-// Filename: wdxGraphicsBuffer8.I
-// Created by:  zhao (29Sep12)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::get_supports_render_texture
-//       Access: Published, Virtual
-//  Description: Returns true if this particular GraphicsOutput can
-//               render directly into a texture, or false if it must
-//               always copy-to-texture at the end of each frame to
-//               achieve this effect.
-////////////////////////////////////////////////////////////////////
-INLINE bool wdxGraphicsBuffer8::
-get_supports_render_texture() const {
-  // DX8 buffers can always bind-to-texture.
-  return true;
-}

+ 0 - 575
panda/src/dxgsg8/wdxGraphicsBuffer8.cxx

@@ -1,575 +0,0 @@
-// Filename: wdxGraphicsBuffer8.cxx
-// Created by:  drose (08Feb04)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "wdxGraphicsPipe8.h"
-#include "wdxGraphicsBuffer8.h"
-#include "pStatTimer.h"
-
-
-// ISSUES:
-  // render to texure format
-    // can be specified via the DXGraphicsStateGuardian8 member
-    // _render_to_texture_d3d_format  default = D3DFMT_X8R8G8B8
-
-  // should check texture creation with CheckDepthStencilMatch
-  // support copy from texture to ram?
-    // check D3DCAPS2_DYNAMICTEXTURES
-
-#define FL << "\n" << __FILE__ << " " << __LINE__ << "\n"
-
-TypeHandle wdxGraphicsBuffer8::_type_handle;
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsBuffer8::
-wdxGraphicsBuffer8(GraphicsEngine *engine, GraphicsPipe *pipe,
-                   const string &name,
-                   const FrameBufferProperties &fb_prop,
-                   const WindowProperties &win_prop,
-                   int flags,
-                   GraphicsStateGuardian *gsg,
-                   GraphicsOutput *host):
-  GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
-{
-  // initialize all class members
-  _cube_map_index = -1;
-  _saved_color_buffer = NULL;
-  _saved_depth_buffer = NULL;
-  _color_backing_store = NULL;
-  _depth_backing_store = NULL;
-
-  // is this correct ???
-  // Since the pbuffer never gets flipped, we get screenshots from the
-  // same buffer we draw into.
-  _screenshot_buffer_type = _draw_buffer_type;
-
-  _this = 0;
-
-  if (_gsg) {
-    // save to GSG list to handle device lost issues
-    DXGraphicsStateGuardian8 *dxgsg;
-
-    dxgsg = DCAST (DXGraphicsStateGuardian8, _gsg);
-    _this = new (wdxGraphicsBuffer8 *);
-    *_this = this;
-    dxgsg -> _graphics_buffer_list.push_back(_this);
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::Destructor
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsBuffer8::
-~wdxGraphicsBuffer8() {
-  this -> close_buffer ( );
-
-  if (_gsg) {
-    // remove from GSG list
-    DXGraphicsStateGuardian8 *dxgsg;
-
-    dxgsg = DCAST (DXGraphicsStateGuardian8, _gsg);
-    if (_this) {
-      dxgsg -> _graphics_buffer_list.remove(_this);
-    }
-    _this = 0;
-    _gsg.clear();
-    _gsg = 0;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::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 wdxGraphicsBuffer8::
-begin_frame(FrameMode mode, Thread *current_thread) {
-
-  begin_frame_spam(mode);
-  if (_gsg == (GraphicsStateGuardian *)NULL) {
-    return false;
-  }
-  if (_dxgsg -> _d3d_device == 0) {
-    return false;
-  }
-
-  if (mode == FM_render) {
-    if (!save_bitplanes()) {
-      return false;
-    }
-    if (!rebuild_bitplanes()) {
-      restore_bitplanes();
-      return false;
-    }
-    clear_cube_map_selection();
-  }
-
-  _gsg->set_current_properties(&get_fb_properties());
-  return _gsg->begin_frame(current_thread);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::end_frame
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               after rendering is completed for a given frame.  It
-//               should do whatever finalization is required.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-end_frame(FrameMode mode, Thread *current_thread) {
-
-  end_frame_spam(mode);
-  nassertv(_gsg != (GraphicsStateGuardian *)NULL);
-
-  if (mode == FM_render) {
-    copy_to_textures();
-  }
-
-  _gsg->end_frame(current_thread);
-
-  if (mode == FM_render) {
-    trigger_flip();
-    clear_cube_map_selection();
-    restore_bitplanes();
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::save_bitplanes
-//       Access: Public
-//  Description: After rendering, d3d_device will need to be restored
-//               to its initial state.  This function saves the state.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsBuffer8::
-save_bitplanes() {
-  HRESULT hr;
-
-  hr = _dxgsg -> _d3d_device -> GetRenderTarget (&_saved_color_buffer);
-  if (!SUCCEEDED (hr)) {
-    dxgsg8_cat.error ( ) << "GetRenderTarget " << D3DERRORSTRING(hr) FL;
-    return false;
-  }
-  hr = _dxgsg -> _d3d_device -> GetDepthStencilSurface (&_saved_depth_buffer);
-  if (!SUCCEEDED (hr)) {
-    dxgsg8_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
-    return false;
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::restore_bitplanes
-//       Access: Public
-//  Description: After rendering, d3d_device will need to be restored
-//               to its initial state.  This function restores the state.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-restore_bitplanes() {
-  DXGraphicsStateGuardian8 *dxgsg;
-  DCAST_INTO_V(dxgsg, _gsg);
-
-  HRESULT hr;
-
-  hr = dxgsg -> _d3d_device ->
-    SetRenderTarget (_saved_color_buffer, _saved_depth_buffer);
-
-  if (!SUCCEEDED (hr)) {
-    dxgsg8_cat.error ( ) << "SetRenderTarget " << D3DERRORSTRING(hr) FL;
-  }
-
-  _saved_color_buffer->Release();
-  _saved_depth_buffer->Release();
-  _saved_color_buffer = NULL;
-  _saved_depth_buffer = NULL;
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::rebuild_bitplanes
-//       Access: Public
-//  Description: If necessary, reallocates (or allocates) the
-//               bitplanes for the buffer.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsBuffer8::
-rebuild_bitplanes() {
-
-  HRESULT hr;
-  Texture *color_tex = 0;
-  Texture *depth_tex = 0;
-  DXTextureContext8 *color_ctx = 0;
-  DXTextureContext8 *depth_ctx = 0;
-  IDirect3DTexture8 *color_d3d_tex = 0;
-  IDirect3DTexture8 *depth_d3d_tex = 0;
-  IDirect3DCubeTexture8 *color_cube = 0;
-  IDirect3DCubeTexture8 *depth_cube = 0;
-  IDirect3DSurface8 *color_surf = 0;
-  IDirect3DSurface8 *depth_surf = 0;
-
-  // Decide how big the bitplanes should be.
-
-  if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) {
-    if (_host->get_size() != _size) {
-      set_size_and_recalc(_host->get_x_size(),
-                          _host->get_y_size());
-    }
-  }
-  int bitplane_x = get_x_size();
-  int bitplane_y = get_y_size();
-  if (Texture::get_textures_power_2() != ATS_none) {
-    bitplane_x = Texture::up_to_power_2(bitplane_x);
-    bitplane_y = Texture::up_to_power_2(bitplane_y);
-  }
-
-  // Find the color and depth textures.  Either may be present,
-  // or neither.
-  //
-  // NOTE: Currently, depth-stencil textures are not implemented,
-  // but since it's coming soon, we're structuring for it.
-
-  int color_tex_index = -1;
-  int depth_tex_index = -1;
-  for (int i=0; i<count_textures(); i++) {
-    if (get_rtm_mode(i) == RTM_bind_or_copy) {
-      if ((get_texture(i)->get_format() != Texture::F_depth_stencil)&&
-          (get_texture(i)->get_format() != Texture::F_depth_component)&&
-          (color_tex_index < 0)) {
-        color_tex_index = i;
-      }
-    }
-  }
-
-
-  if (color_tex_index < 0) {
-    // Maintain the backing color surface.
-    if ((_color_backing_store)&&
-        ((bitplane_x != _backing_sizex)||(bitplane_y != _backing_sizey))) {
-      _color_backing_store->Release();
-      _color_backing_store = NULL;
-    }
-    if (!_color_backing_store) {
-      hr = _dxgsg -> _d3d_device ->
-        CreateImageSurface(bitplane_x, bitplane_y, _saved_color_desc.Format, &_color_backing_store);
-      if (!SUCCEEDED(hr)) {
-        dxgsg8_cat.error ( ) << "CreateImageSurface " << D3DERRORSTRING(hr) FL;
-      }
-    }
-    color_surf = _color_backing_store;
-  } else {
-    // Maintain the color texture.
-    if (_color_backing_store) {
-      _color_backing_store->Release();
-      _color_backing_store = NULL;
-    }
-    color_tex = get_texture(color_tex_index);
-    color_tex->set_x_size(bitplane_x);
-    color_tex->set_y_size(bitplane_y);
-    color_tex->set_format(Texture::F_rgba);
-    color_ctx =
-      DCAST(DXTextureContext8,
-            color_tex->prepare_now(0, _gsg->get_prepared_objects(), _gsg));
-    if (color_ctx) {
-      if (!color_ctx->create_texture(*_dxgsg->_screen)) {
-        dxgsg8_cat.error()
-          << "Unable to re-create texture " << *color_ctx->get_texture() << endl;
-        return false;
-      }
-      if (color_tex->get_texture_type() == Texture::TT_2d_texture) {
-        color_d3d_tex = color_ctx->_d3d_2d_texture;
-        nassertr(color_d3d_tex != 0, false);
-        hr = color_d3d_tex -> GetSurfaceLevel(0, &color_surf);
-        if (!SUCCEEDED(hr)) {
-          dxgsg8_cat.error ( ) << "GetSurfaceLevel " << D3DERRORSTRING(hr) FL;
-        }
-      } else {
-        color_cube = color_ctx->_d3d_cube_texture;
-        nassertr(color_cube != 0, false);
-        if (_cube_map_index >= 0 && _cube_map_index < 6) {
-          hr = color_cube -> GetCubeMapSurface ((D3DCUBEMAP_FACES) _cube_map_index, 0, &color_surf);
-          if (!SUCCEEDED(hr)) {
-            dxgsg8_cat.error ( ) << "GetCubeMapSurface " << D3DERRORSTRING(hr) FL;
-          }
-        }
-      }
-    }
-  }
-
-  if (depth_tex_index < 0) {
-    // Maintain the backing depth surface.
-    if ((_depth_backing_store)&&
-        ((bitplane_x != _backing_sizex)||(bitplane_y != _backing_sizey))) {
-      _depth_backing_store->Release();
-      _depth_backing_store = NULL;
-    }
-    if (!_depth_backing_store) {
-      hr = _dxgsg -> _d3d_device ->
-        CreateDepthStencilSurface (bitplane_x, bitplane_y, _saved_depth_desc.Format,
-                                   _saved_depth_desc.MultiSampleType, &_depth_backing_store);
-      if (!SUCCEEDED(hr)) {
-        dxgsg8_cat.error ( ) << "CreateDepthStencilSurface " << D3DERRORSTRING(hr) FL;
-      }
-    }
-    depth_surf = _depth_backing_store;
-  } else {
-    // Maintain the depth texture.
-    if (_depth_backing_store) {
-      _depth_backing_store->Release();
-      _depth_backing_store = NULL;
-    }
-    depth_tex = get_texture(depth_tex_index);
-    depth_tex->set_x_size(bitplane_x);
-    depth_tex->set_y_size(bitplane_y);
-    depth_tex->set_format(Texture::F_depth_stencil);
-    depth_ctx =
-      DCAST(DXTextureContext8,
-            depth_tex->prepare_now(0, _gsg->get_prepared_objects(), _gsg));
-    if (depth_ctx) {
-      if (!depth_ctx->create_texture(*_dxgsg->_screen)) {
-        dxgsg8_cat.error()
-          << "Unable to re-create texture " << *depth_ctx->get_texture() << endl;
-        return false;
-      }
-
-      if (depth_tex->get_texture_type() == Texture::TT_2d_texture) {
-        depth_d3d_tex = depth_ctx->_d3d_2d_texture;
-        nassertr(depth_d3d_tex != 0, false);
-        hr = depth_d3d_tex -> GetSurfaceLevel(0, &depth_surf);
-        if (!SUCCEEDED(hr)) {
-          dxgsg8_cat.error ( ) << "GetSurfaceLevel " << D3DERRORSTRING(hr) FL;
-        }
-      } else {
-        depth_cube = depth_ctx->_d3d_cube_texture;
-        nassertr(depth_cube != 0, false);
-        hr = depth_cube -> GetCubeMapSurface ((D3DCUBEMAP_FACES) _cube_map_index, 0, &depth_surf);
-        if (!SUCCEEDED(hr)) {
-          dxgsg8_cat.error ( ) << "GetCubeMapSurface " << D3DERRORSTRING(hr) FL;
-        }
-      }
-    }
-  }
-
-  _backing_sizex = bitplane_x;
-  _backing_sizey = bitplane_y;
-
-  // Load up the bitplanes.
-
-  if (color_surf && depth_surf) {
-    hr = _dxgsg -> _d3d_device -> SetRenderTarget (color_surf, depth_surf);
-    if (!SUCCEEDED (hr)) {
-      dxgsg8_cat.error ( ) << "SetRenderTarget " << D3DERRORSTRING(hr) FL;
-    }
-  }
-
-  // Decrement the reference counts on these surfaces. The refcounts
-  // were incremented earlier when we called GetSurfaceLevel.
-
-  if ((color_surf != 0)&&(color_surf != _color_backing_store)) {
-    color_surf->Release();
-  }
-  if ((depth_surf != 0)&&(depth_surf != _depth_backing_store)) {
-    depth_surf->Release();
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::select_target_tex_page
-//       Access: Public, Virtual
-//  Description: Called internally when the window is in
-//               render-to-a-texture mode and we are in the process of
-//               rendering the six faces of a cube map.  This should
-//               do whatever needs to be done to switch the buffer to
-//               the indicated face.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-select_target_tex_page(int page) {
-  _cube_map_index = page;
-
-  HRESULT hr;
-  Texture *color_tex = 0;
-  DXTextureContext8 *color_ctx = 0;
-  IDirect3DCubeTexture8 *color_cube = 0;
-  IDirect3DSurface8 *color_surf = 0;
-  int color_tex_index = -1;
-
-  for (int i=0; i<count_textures(); i++) {
-    if (get_rtm_mode(i) == RTM_bind_or_copy) {
-      if ((get_texture(i)->get_format() != Texture::F_depth_stencil)&&
-          (get_texture(i)->get_format() != Texture::F_depth_component)&&
-          (color_tex_index < 0)) {
-        color_tex_index = i;
-      }
-    }
-  }
-
-  color_tex = get_texture(color_tex_index);
-  if (color_tex) {
-    color_ctx =
-      DCAST(DXTextureContext8,
-            color_tex->prepare_now(0, _gsg->get_prepared_objects(), _gsg));
-    if (!color_ctx->create_texture(*_dxgsg->_screen)) {
-      dxgsg8_cat.error()
-        << "Unable to re-create texture " << *color_ctx->get_texture() << endl;
-      return;
-    }
-
-    color_cube = color_ctx->_d3d_cube_texture;
-
-    if (color_cube && _cube_map_index >= 0 && _cube_map_index < 6) {
-      hr = color_cube -> GetCubeMapSurface ((D3DCUBEMAP_FACES) _cube_map_index, 0, &color_surf);
-      if (!SUCCEEDED(hr)) {
-        dxgsg8_cat.error ( ) << "GetCubeMapSurface " << D3DERRORSTRING(hr) FL;
-      }
-
-      hr = _dxgsg -> _d3d_device -> SetRenderTarget (color_surf, 0);
-      if (!SUCCEEDED (hr)) {
-        dxgsg8_cat.error ( ) << "SetRenderTarget " << D3DERRORSTRING(hr) FL;
-      }
-      else {
-        color_surf->Release();
-      }
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::process_events
-//       Access: Public, Virtual
-//  Description: Do whatever processing is necessary to ensure that
-//               the window responds to user events.  Also, honor any
-//               requests recently made via request_properties()
-//
-//               This function is called only within the window
-//               thread.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-process_events() {
-  GraphicsBuffer::process_events();
-
-  MSG msg;
-
-  // Handle all the messages on the queue in a row.  Some of these
-  // might be for another window, but they will get dispatched
-  // appropriately.
-  while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
-    process_1_event();
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::close_buffer
-//       Access: Protected, Virtual
-//  Description: Closes the buffer right now.  Called from the window
-//               thread.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-close_buffer() {
-
-  if (_gsg != (GraphicsStateGuardian *)NULL) {
-    _gsg.clear();
-  }
-
-  if (_color_backing_store) {
-    _color_backing_store->Release();
-    _color_backing_store = NULL;
-  }
-  if (_depth_backing_store) {
-    _depth_backing_store->Release();
-    _depth_backing_store = NULL;
-  }
-
-  _cube_map_index = -1;
-  _is_valid = false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::open_buffer
-//       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 wdxGraphicsBuffer8::
-open_buffer() {
-
-  // GSG creation/initialization.
-  if (_gsg == 0) {
-    // The code below doesn't support creating a GSG on the fly.
-    // Just error out for now.
-    //_dxgsg = new DXGraphicsStateGuardian8(_engine, _pipe);
-    //_gsg = _dxgsg;
-    return false;
-  }
-   
-  DCAST_INTO_R(_dxgsg, _gsg, false);
-
-  if (!save_bitplanes()) {
-    return false;
-  }
-
-  HRESULT hr;
-  hr = _saved_color_buffer -> GetDesc (&_saved_color_desc);
-  if (!SUCCEEDED (hr)) {
-    dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL;
-    return false;
-  }
-  hr = _saved_depth_buffer -> GetDesc (&_saved_depth_desc);
-  if (!SUCCEEDED (hr)) {
-    dxgsg8_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL;
-    return false;
-  }
-  _fb_properties = _dxgsg->
-    calc_fb_properties(_saved_color_desc.Format,
-                       _saved_depth_desc.Format,
-                       _saved_depth_desc.MultiSampleType);
-  _fb_properties.set_force_hardware(1); // Wild guess.
-
-  if (!rebuild_bitplanes()) {
-    restore_bitplanes();
-    return false;
-  }
-
-  restore_bitplanes();
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::process_1_event
-//       Access: Private, Static
-//  Description: Handles one event from the message queue.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-process_1_event() {
-  MSG msg;
-
-  if (!GetMessage(&msg, NULL, 0, 0)) {
-    // WM_QUIT received.  We need a cleaner way to deal with this.
-    //    DestroyAllWindows(false);
-    exit(msg.wParam);  // this will invoke AtExitFn
-  }
-
-  // Translate virtual key messages
-  TranslateMessage(&msg);
-  // Call window_proc
-  DispatchMessage(&msg);
-}

+ 0 - 99
panda/src/dxgsg8/wdxGraphicsBuffer8.h

@@ -1,99 +0,0 @@
-// Filename: wdxGraphicsBuffer8.h
-// Created by:  drose (08Feb04)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef wdxGraphicsBuffer8_H
-#define wdxGraphicsBuffer8_H
-
-#include "pandabase.h"
-#include "graphicsBuffer.h"
-#include "dxgsg8base.h"
-
-
-////////////////////////////////////////////////////////////////////
-//       Class : wdxGraphicsBuffer8
-// Description : An offscreen render buffer.  In OpenGL under Windows,
-//               this simply renders into a window that is never made
-//               visible.  There's a Windows interface for rendering
-//               into a DIB, but this puts restrictions on the kind of
-//               pixelformat we can use, and thus makes it difficult
-//               to support one GSG rendering into an offscreen buffer
-//               and also into a window.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX wdxGraphicsBuffer8 : public GraphicsBuffer {
-public:
-  wdxGraphicsBuffer8(GraphicsEngine *engine, GraphicsPipe *pipe,
-                     const string &name,
-                     const FrameBufferProperties &fb_prop,
-                     const WindowProperties &win_prop,
-                     int flags,
-                     GraphicsStateGuardian *gsg,
-                     GraphicsOutput *host);
-  virtual ~wdxGraphicsBuffer8();
-  
-  virtual INLINE bool get_supports_render_texture() const;
-
-  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
-  virtual void end_frame(FrameMode mode, Thread *current_thread);
-
-  virtual void select_target_tex_page(int page);
-
-  virtual void process_events();
-
-protected:
-  virtual void close_buffer();
-  virtual bool open_buffer();
-
-private:
-  bool save_bitplanes();
-  bool rebuild_bitplanes();
-  void restore_bitplanes();
-  static void process_1_event();
-
-  int _cube_map_index;
-  DXGraphicsStateGuardian8 *_dxgsg;
-  IDirect3DSurface8 *_saved_color_buffer;
-  IDirect3DSurface8 *_saved_depth_buffer;
-  D3DSURFACE_DESC    _saved_color_desc;
-  D3DSURFACE_DESC    _saved_depth_desc;
-  IDirect3DSurface8 *_color_backing_store;
-  IDirect3DSurface8 *_depth_backing_store;
-  int _backing_sizex;
-  int _backing_sizey;
-
-  wdxGraphicsBuffer8 **_this;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    GraphicsBuffer::init_type();
-    register_type(_type_handle, "wdxGraphicsBuffer8",
-                  GraphicsBuffer::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-
-  friend class DXGraphicsStateGuardian8;
-  friend class DXTextureContext8;
-};
-
-#include "wdxGraphicsBuffer8.I"
-
-#endif

+ 0 - 13
panda/src/dxgsg8/wdxGraphicsPipe8.I

@@ -1,13 +0,0 @@
-// Filename: wdxGraphicsPipe8.I
-// Created by:  drose (20Dec02)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////

+ 0 - 931
panda/src/dxgsg8/wdxGraphicsPipe8.cxx

@@ -1,931 +0,0 @@
-// Filename: wdxGraphicsPipe8.cxx
-// Created by:  drose (20Dec02)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "wdxGraphicsPipe8.h"
-#include "dxGraphicsDevice8.h"
-#include "wdxGraphicsWindow8.h"
-#include "wdxGraphicsBuffer8.h"
-#include "config_dxgsg8.h"
-
-TypeHandle wdxGraphicsPipe8::_type_handle;
-
-#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
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsPipe8::
-wdxGraphicsPipe8() {
-  _hDDrawDLL = NULL;
-  _hD3D8_DLL = NULL;
-  __d3d8 = NULL;
-  _is_valid = init();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::Destructor
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsPipe8::
-~wdxGraphicsPipe8() {
-  RELEASE(__d3d8, wdxdisplay8, "ID3D8", RELEASE_DOWN_TO_ZERO);
-  SAFE_FREELIB(_hD3D8_DLL);
-  SAFE_FREELIB(_hDDrawDLL);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::get_interface_name
-//       Access: Published, Virtual
-//  Description: Returns the name of the rendering interface
-//               associated with this GraphicsPipe.  This is used to
-//               present to the user to allow him/her to choose
-//               between several possible GraphicsPipes available on a
-//               particular platform, so the name should be meaningful
-//               and unique for a given platform.
-////////////////////////////////////////////////////////////////////
-string wdxGraphicsPipe8::
-get_interface_name() const {
-  return "DirectX8";
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::pipe_constructor
-//       Access: Public, Static
-//  Description: This function is passed to the GraphicsPipeSelection
-//               object to allow the user to make a default
-//               wdxGraphicsPipe8.
-////////////////////////////////////////////////////////////////////
-PT(GraphicsPipe) wdxGraphicsPipe8::
-pipe_constructor() {
-  return new wdxGraphicsPipe8;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::make_output
-//       Access: Protected, Virtual
-//  Description: Creates a new window on the pipe, if possible.
-////////////////////////////////////////////////////////////////////
-PT(GraphicsOutput) wdxGraphicsPipe8::
-make_output(const string &name,
-            const FrameBufferProperties &fb_prop,
-            const WindowProperties &win_prop,
-            int flags,
-            GraphicsEngine *engine,
-            GraphicsStateGuardian *gsg,
-            GraphicsOutput *host,
-            int retry,
-            bool &precertify) {
-
-  if (!_is_valid) {
-    return NULL;
-  }
-
-  DXGraphicsStateGuardian8 *wdxgsg = 0;
-  if (gsg != 0) {
-    DCAST_INTO_R(wdxgsg, gsg, NULL);
-  }
-
-  // First thing to try: a visible window.
-
-  if (retry == 0) {
-    if (((flags&BF_require_parasite)!=0)||
-        ((flags&BF_refuse_window)!=0)||
-        ((flags&BF_resizeable)!=0)||
-        ((flags&BF_size_track_host)!=0)||
-        ((flags&BF_rtt_cumulative)!=0)||
-        ((flags&BF_can_bind_color)!=0)||
-        ((flags&BF_can_bind_every)!=0)) {
-      return NULL;
-    }
-    // Early failure - if we are sure that this buffer WONT
-    // meet specs, we can bail out early.
-    if ((flags & BF_fb_props_optional) == 0) {
-      if ((fb_prop.get_aux_rgba() > 0)||
-          (fb_prop.get_aux_rgba() > 0)||
-          (fb_prop.get_aux_float() > 0)) {
-        return NULL;
-      }
-    }
-    return new wdxGraphicsWindow8(engine, this, name, fb_prop, win_prop,
-                                  flags, gsg, host);
-  }
-
-  // Second thing to try: a wdxGraphicsBuffer8
-
-  if (retry == 1) {
-    if ((!support_render_texture)||
-        ((flags&BF_require_parasite)!=0)||
-        ((flags&BF_require_window)!=0)||
-        ((flags&BF_resizeable)!=0)||
-        ((flags&BF_size_track_host)!=0)||
-        ((flags&BF_rtt_cumulative)!=0)||
-        ((flags&BF_can_bind_every)!=0)) {
-      return NULL;
-    }
-    // Early failure - if we are sure that this buffer WONT
-    // meet specs, we can bail out early.
-    if ((flags & BF_fb_props_optional) == 0) {
-      if ((fb_prop.get_aux_rgba() > 0)||
-          (fb_prop.get_aux_rgba() > 0)||
-          (fb_prop.get_aux_float() > 0)||
-          (fb_prop.get_indexed_color() > 0)||
-          (fb_prop.get_back_buffers() > 0)||
-          (fb_prop.get_accum_bits() > 0)||
-          (fb_prop.get_multisamples() > 0)) {
-        return NULL;
-      }
-    }
-    // Early success - if we are sure that this buffer WILL
-    // meet specs, we can precertify it.
-    // This looks rather overly optimistic -- ie, buggy.
-    if ((gsg != 0)&&
-        (gsg->is_valid())&&
-        (!gsg->needs_reset())&&
-        (DCAST(DXGraphicsStateGuardian8, gsg)->get_supports_render_texture())) {
-      precertify = true;
-    }
-    return new wdxGraphicsBuffer8(engine, this, name, fb_prop, win_prop,
-                                  flags, gsg, host);
-  }
-
-  // Nothing else left to try.
-  return NULL;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::init
-//       Access: Private
-//  Description: Performs some initialization steps to load up
-//               function pointers from the relevant DLL's, and
-//               determine the number and type of available graphics
-//               adapters, etc.  Returns true on success, false on
-//               failure.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsPipe8::
-init() {
-  if (!MyLoadLib(_hDDrawDLL, "ddraw.dll")) {
-    goto error;
-  }
-
-  if (!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawCreateEx, "DirectDrawCreateEx")) {
-    goto error;
-  }
-
-  if (!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawEnumerateExA, "DirectDrawEnumerateExA")) {
-    goto error;
-  }
-
-  if (!MyLoadLib(_hD3D8_DLL, "d3d8.dll")) {
-    goto error;
-  }
-
-  if (!MyGetProcAddr(_hD3D8_DLL, (FARPROC*)&_Direct3DCreate8, "Direct3DCreate8")) {
-    goto error;
-  }
-
-  // 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
-
-  // are we using 8.0 or 8.1?
-  WIN32_FIND_DATA TempFindData;
-  HANDLE hFind;
-  char tmppath[_MAX_PATH + 128];
-  GetSystemDirectory(tmppath, MAX_PATH);
-  strcat(tmppath, "\\dpnhpast.dll");
-  hFind = FindFirstFile (tmppath, &TempFindData);
-  if (hFind != INVALID_HANDLE_VALUE) {
-    FindClose(hFind);
-    __is_dx8_1 = true;
-    __d3d8 = (*_Direct3DCreate8)(D3D_SDK_VERSION_8_1);
-  } else {
-    __is_dx8_1 = false;
-    __d3d8 = (*_Direct3DCreate8)(D3D_SDK_VERSION_8_0);
-  }
-
-  if (__d3d8 == NULL) {
-    wdxdisplay8_cat.error() << "Direct3DCreate8(8." << (__is_dx8_1 ? "1" : "0") << ") failed!, error = " << GetLastError() << endl;
-    //release_gsg();
-    goto error;
-  }
-
-  Init_D3DFORMAT_map();
-
-  return find_all_card_memavails();
-
- error:
-  return false;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::find_all_card_memavails
-//       Access: Private
-//  Description: Uses DX7 calls to determine how much video memory is
-//               available for each video adapter in the system.
-//               Returns true on success, false on failure.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsPipe8::
-find_all_card_memavails() {
-  HRESULT hr;
-
-  hr = (*_DirectDrawEnumerateExA)(dx7_driver_enum_callback, this,
-                                  DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.fatal()
-      << "DirectDrawEnumerateEx failed" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  if (_card_ids.empty()) {
-    wdxdisplay8_cat.error()
-      << "DirectDrawEnumerateEx enum'ed no devices!\n";
-    return false;
-  }
-
-  GUID ZeroGUID;
-  ZeroMemory(&ZeroGUID, sizeof(GUID));
-
-  if (_card_ids.size() > 1) {
-    nassertr(IsEqualGUID(ZeroGUID, _card_ids[0].DX7_DeviceGUID), false);
-    // delete enum of primary display (always the first), since it is
-    // duplicated by explicit entry
-    _card_ids.erase(_card_ids.begin());
-  }
-
-  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);
-
-    if (IsEqualGUID(*pGUID, ZeroGUID)) {
-      pGUID = NULL;
-    }
-
-    // Create the Direct Draw Object
-    hr = (*_DirectDrawCreateEx)(pGUID, (void **)&pDD, IID_IDirectDraw7, NULL);
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.error()
-        << "DirectDrawCreateEx failed for device (" << i
-        << ")" << D3DERRORSTRING(hr);
-      continue;
-    }
-
-    ZeroMemory(ddd_space, sizeof(DDDEVICEIDENTIFIER2));
-
-    hr = pDD->GetDeviceIdentifier(pDX7DeviceID, 0x0);
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.error()
-        << "GetDeviceID failed for device (" << i << ")" << D3DERRORSTRING(hr);
-      continue;
-    }
-
-    _card_ids[i].DeviceID = pDX7DeviceID->dwDeviceId;
-    _card_ids[i].VendorID = pDX7DeviceID->dwVendorId;
-
-    // Get Current VidMem avail.  Note this is only an estimate, when
-    // we switch to fullscreen mode from desktop, more vidmem will be
-    // available (typically 1.2 meg).  I don't want to switch to
-    // 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;
-    {
-      // print out total INCLUDING AGP just for information purposes
-      // and future use.  The real value I'm interested in for
-      // purposes of measuring possible valid screen sizes shouldnt
-      // include AGP.
-      ZeroMemory(&ddsGAVMCaps, sizeof(DDSCAPS2));
-      ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
-
-      hr = pDD->GetAvailableVidMem(&ddsGAVMCaps, &dwVidMemTotal, &dwVidMemFree);
-      if (FAILED(hr)) {
-        wdxdisplay8_cat.error()
-          << "GetAvailableVidMem failed for device #" << i
-          << D3DERRORSTRING(hr);
-        //goto skip_device;
-        //exit(1);  // probably want to exit, since it may be my fault
-      }
-    }
-
-    wdxdisplay8_cat.info()
-      << "GetAvailableVidMem (including AGP) returns Total: "
-      << dwVidMemTotal <<", Free: " << dwVidMemFree
-      << " for device #" << i << endl;
-
-    ZeroMemory(&ddsGAVMCaps, sizeof(DDSCAPS2));
-
-    // just want to measure localvidmem, not AGP texmem
-    ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
-
-    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;
-      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;
-
-    pDD->Release();  // release DD obj, since this is all we needed it for
-
-    if (!dx_do_vidmemsize_check) {
-      // still calling the DD stuff to get deviceID, etc.  is this necessary?
-      _card_ids[i]._max_available_video_memory = UNKNOWN_VIDMEM_SIZE;
-      _card_ids[i]._is_low_memory_card = false;
-      continue;
-    }
-
-    if (dwVidMemTotal == 0) {  // unreliable driver
-      dwVidMemTotal = UNKNOWN_VIDMEM_SIZE;
-    } else {
-      if (!ISPOW2(dwVidMemTotal)) {
-        // assume they wont return a proper max value, so
-        // round up to next pow of 2
-        UINT count = 0;
-        while ((dwVidMemTotal >> count) != 0x0) {
-          count++;
-        }
-        dwVidMemTotal = (1 << count);
-      }
-    }
-
-    // after Set_display_mode, GetAvailVidMem totalmem seems to go down
-    // by 1.2 meg (contradicting above comment and what I think would
-    // be correct behavior (shouldnt FS mode release the desktop
-    // vidmem?), so this is the true value
-    _card_ids[i]._max_available_video_memory = dwVidMemTotal;
-
-    // I can never get this stuff to work reliably, so I'm just
-    // rounding up to nearest pow2.  Could try to get
-    // HardwareInformation.Memory_size MB number from registry like
-    // video control panel, but its not clear how to find the proper
-    // registry location for a given card
-
-    // 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) &&
-       (dwVidMemTotal< LOWVIDMEMTHRESHOLD));
-
-    _card_ids[i]._is_low_memory_card = bLowVidMemFlag;
-    wdxdisplay8_cat.info()
-      << "SetLowVidMem flag to " << bLowVidMemFlag
-      << " based on adjusted VidMemTotal: " << dwVidMemTotal << endl;
-  }
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipe8::dx7_driver_enum_callback
-//       Access: Private, Static
-//  Description:
-////////////////////////////////////////////////////////////////////
-BOOL WINAPI wdxGraphicsPipe8::
-dx7_driver_enum_callback(GUID *pGUID, TCHAR *strDesc, TCHAR *strName,
-                         VOID *argptr, HMONITOR hm) {
-  wdxGraphicsPipe8 *self = (wdxGraphicsPipe8 *)argptr;
-
-  CardID card_id;
-  ZeroMemory(&card_id, sizeof(CardID));
-
-  if (hm == NULL) {
-    card_id._monitor = MonitorFromWindow(GetDesktopWindow(),
-                                     MONITOR_DEFAULTTOPRIMARY);
-  } else {
-    card_id._monitor = hm;
-  }
-
-  if (pGUID != NULL) {
-    memcpy(&card_id.DX7_DeviceGUID, pGUID, sizeof(GUID));
-  }
-
-  card_id._max_available_video_memory = UNKNOWN_VIDMEM_SIZE;
-
-  self->_card_ids.push_back(card_id);
-
-  return DDENUMRET_OK;
-}
-
-//////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::find_best_depth_format
-//       Access: Private
-//  Description:
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsPipe8::
-find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &Test_display_mode,
-                       D3DFORMAT *pBestFmt, bool bWantStencil,
-                       bool bForce16bpp, bool bVerboseMode) const {
-  if (dxgsg8_cat.is_debug()) {
-    bVerboseMode = true;
-  }
-
-  // list formats to try in order of preference.
-
-#define NUM_TEST_ZFMTS 6
-#define FIRST_NON_STENCIL_ZFMT 3
-  static D3DFORMAT FormatPrefList[NUM_TEST_ZFMTS] = {
-    D3DFMT_D24S8, D3DFMT_D24X4S4, D3DFMT_D15S1,  // with stencil
-    D3DFMT_D32, D3DFMT_D24X8, D3DFMT_D16         // without stencil
-  };
-
-  // do not use Display._display_mode since that is probably not set yet, use Test_display_mode instead
-
-  *pBestFmt = D3DFMT_UNKNOWN;
-  HRESULT hr;
-
-  // nvidia likes zbuf depth to match rendertarget depth
-  bool bOnlySelect16bpp = (bForce16bpp ||
-                           (IS_NVIDIA(Display._dx_device_id) && IS_16BPP_DISPLAY_FORMAT(Test_display_mode.Format)));
-
-  if (bVerboseMode) {
-    wdxdisplay8_cat.info()
-      << "FindBestDepthFmt: bSelectOnly16bpp: " << bOnlySelect16bpp << endl;
-  }
-
-  int first_format = (bWantStencil ? 0 : FIRST_NON_STENCIL_ZFMT);
-  for (int i = first_format; i < NUM_TEST_ZFMTS; i++) {
-    D3DFORMAT TestDepthFmt = FormatPrefList[i];
-
-    if (bOnlySelect16bpp && !IS_16BPP_ZBUFFER(TestDepthFmt)) {
-      continue;
-    }
-
-    hr = Display._d3d8->CheckDeviceFormat(Display._card_id,
-                                          D3DDEVTYPE_HAL,
-                                          Test_display_mode.Format,
-                                          D3DUSAGE_DEPTHSTENCIL,
-                                          D3DRTYPE_SURFACE, TestDepthFmt);
-
-    if (FAILED(hr)) {
-      if (hr == D3DERR_NOTAVAILABLE) {
-        if (bVerboseMode)
-          wdxdisplay8_cat.info()
-            << "FindBestDepthFmt: ChkDevFmt returns NotAvail for "
-            << D3DFormatStr(TestDepthFmt) << endl;
-        continue;
-      }
-
-      wdxdisplay8_cat.error()
-        << "unexpected CheckDeviceFormat failure" << D3DERRORSTRING(hr)
-        << endl;
-      exit(1);
-    }
-
-    hr = Display._d3d8->CheckDepthStencilMatch(Display._card_id,
-                                               D3DDEVTYPE_HAL,
-                                               Test_display_mode.Format,   // adapter format
-                                               Test_display_mode.Format,   // backbuffer fmt  (should be the same in my apps)
-                                               TestDepthFmt);
-    if (SUCCEEDED(hr)) {
-      *pBestFmt = TestDepthFmt;
-      break;
-    } else {
-      if (hr == D3DERR_NOTAVAILABLE) {
-        if (bVerboseMode) {
-          wdxdisplay8_cat.info()
-            << "FindBestDepthFmt: ChkDepMatch returns NotAvail for "
-            << D3DFormatStr(Test_display_mode.Format) << ", "
-            << D3DFormatStr(TestDepthFmt) << endl;
-        }
-      } else {
-        wdxdisplay8_cat.error()
-          << "unexpected CheckDepthStencilMatch failure for "
-          << D3DFormatStr(Test_display_mode.Format) << ", "
-          << D3DFormatStr(TestDepthFmt) << endl;
-      }
-    }
-  }
-
-  if (bVerboseMode) {
-    wdxdisplay8_cat.info()
-      << "FindBestDepthFmt returns fmt " << D3DFormatStr(*pBestFmt) << endl;
-  }
-
-  return (*pBestFmt != D3DFMT_UNKNOWN);
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::special_check_fullscreen_resolution
-//       Access: Private
-//  Description: overrides of the general estimator for known working
-//               cases
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsPipe8::
-special_check_fullscreen_resolution(DXScreenData &scrn, UINT x_size, UINT y_size) {
-  DWORD VendorId = scrn._dx_device_id.VendorId;
-  DWORD DeviceId = scrn._dx_device_id.DeviceId;
-
-  switch (VendorId) {
-  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;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::search_for_valid_displaymode
-//       Access: Private
-//  Description: All ptr args are output parameters.  If no valid mode
-//               found, returns *pSuggestedPixFmt = D3DFMT_UNKNOWN;
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsPipe8::
-search_for_valid_displaymode(DXScreenData &scrn,
-                             UINT RequestedX_Size, UINT RequestedY_Size,
-                             bool bWantZBuffer, bool bWantStencil,
-                             UINT *p_supported_screen_depths_mask,
-                             bool *pCouldntFindAnyValidZBuf,
-                             D3DFORMAT *pSuggestedPixFmt,
-                             bool bForce16bppZBuffer,
-                             bool bVerboseMode) {
-
-  nassertv(IS_VALID_PTR(scrn._d3d8));
-  HRESULT hr;
-
-  *pSuggestedPixFmt = D3DFMT_UNKNOWN;
-  *p_supported_screen_depths_mask = 0x0;
-  *pCouldntFindAnyValidZBuf = false;
-
-  int cNumModes = scrn._d3d8->GetAdapterModeCount(scrn._card_id);
-  D3DDISPLAYMODE BestDispMode;
-  ZeroMemory(&BestDispMode, sizeof(BestDispMode));
-
-  if (bVerboseMode) {
-    wdxdisplay8_cat.info()
-      << "searching for valid display modes at res: ("
-      << RequestedX_Size << ", " << RequestedY_Size
-      << "), TotalModes: " << cNumModes << endl;
-  }
-
-  // ignore memory based checks for min res 640x480.  some cards just
-  // don't give accurate memavails.  (should I do the check anyway for
-  // 640x480 32bpp?)
-  bool bDoMemBasedChecks =
-    ((!((RequestedX_Size == 640)&&(RequestedY_Size == 480))) &&
-     (scrn._max_available_video_memory != 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++) {
-    D3DDISPLAYMODE dispmode;
-    hr = scrn._d3d8->EnumAdapterModes(scrn._card_id, i, &dispmode);
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.error()
-        << "EnumAdapter_display_mode failed for device #"
-        << scrn._card_id << D3DERRORSTRING(hr);
-      continue;
-    }
-
-    if ((dispmode.Width != RequestedX_Size) ||
-        (dispmode.Height != RequestedY_Size)) {
-      if (bVerboseMode) {
-        wdxdisplay8_cat.info()
-          << "Mode dimension " << dispmode.Width << "x" << dispmode.Height
-          << "; format " << D3DFormatStr(dispmode.Format)
-          << ": onto next mode\n";
-      }
-      continue;
-    }
-
-    // disable refresh rate checking since SLI video cards may use 
-    // refresh rates less than 60
-    if (0) {
-      if ((dispmode.RefreshRate<60) && (dispmode.RefreshRate>1)) {
-        // don't want refresh rates under 60Hz, but 0 or 1 might indicate
-        // a default refresh rate, which is usually > = 60
-        if (bVerboseMode) {
-          wdxdisplay8_cat.info()
-            << "skipping mode[" << i << "], bad refresh rate: "
-            << dispmode.RefreshRate << endl;
-        }
-        continue;
-      }
-    }
-    
-    // Note no attempt is made to verify if format will work at
-    // requested size, so even if this call succeeds, could still get
-    // an out-of-video-mem error
-
-    hr = scrn._d3d8->CheckDeviceFormat(scrn._card_id, D3DDEVTYPE_HAL, dispmode.Format,
-                                       D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE,
-                                       dispmode.Format);
-    if (FAILED(hr)) {
-      if (hr == D3DERR_NOTAVAILABLE) {
-        if (bVerboseMode) {
-          wdxdisplay8_cat.info()
-            << "skipping mode[" << i
-            << "], CheckDevFmt returns NotAvail for fmt: "
-            << D3DFormatStr(dispmode.Format) << endl;
-        }
-        continue;
-      } else {
-        wdxdisplay8_cat.error()
-          << "CheckDeviceFormat failed for device #"
-          << scrn._card_id << D3DERRORSTRING(hr);
-        continue;
-      }
-    }
-
-    bool bIs16bppRenderTgt = IS_16BPP_DISPLAY_FORMAT(dispmode.Format);
-    PN_stdfloat RendTgtMinMemReqmt = 0.0f;
-
-    // if we have a valid memavail value, try to determine if we have
-    // enough space
-    if (bDoMemBasedChecks) {
-      // assume user is testing fullscreen, not windowed, so use the
-      // dwTotal value see if 3 scrnbufs (front/back/z)at 16bpp at
-      // x_size*y_size will fit with a few extra megs for texmem
-
-      // 8MB Rage Pro says it has 6.8 megs Total free and will run at
-      // 1024x768, so formula makes it so that is OK
-
-#define REQD_TEXMEM 1800000
-
-      PN_stdfloat bytes_per_pixel = (bIs16bppRenderTgt ? 2 : 4);
-
-      // *2 for double buffer
-
-      RendTgtMinMemReqmt =
-        ((PN_stdfloat)RequestedX_Size) * ((PN_stdfloat)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: "
-          << scrn._max_available_video_memory << endl;
-
-      if (RendTgtMinMemReqmt > scrn._max_available_video_memory) {
-        if (bVerboseMode || wdxdisplay8_cat.is_debug())
-          wdxdisplay8_cat.info()
-            << "not enough VidMem for render tgt, skipping display fmt "
-            << D3DFormatStr(dispmode.Format) << " ("
-            << (int)RendTgtMinMemReqmt << " > "
-            << scrn._max_available_video_memory << ")\n";
-        continue;
-      }
-    }
-
-    if (bWantZBuffer) {
-      D3DFORMAT zformat;
-      if (!find_best_depth_format(scrn, dispmode, &zformat,
-                                  bWantStencil, bForce16bppZBuffer)) {
-        *pCouldntFindAnyValidZBuf = true;
-        continue;
-      }
-
-      PN_stdfloat MinMemReqmt = 0.0f;
-
-      if (bDoMemBasedChecks) {
-        // test memory again, this time including zbuf size
-        PN_stdfloat zbytes_per_pixel = (IS_16BPP_ZBUFFER(zformat) ? 2 : 4);
-        PN_stdfloat MinMemReqmt = RendTgtMinMemReqmt + ((PN_stdfloat)RequestedX_Size)*((PN_stdfloat)RequestedY_Size)*zbytes_per_pixel;
-
-        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: "
-            << scrn._max_available_video_memory << endl;
-
-        if (MinMemReqmt > scrn._max_available_video_memory) {
-          if (bVerboseMode || wdxdisplay8_cat.is_debug())
-            wdxdisplay8_cat.info()
-              << "not enough VidMem for RendTgt+zbuf, skipping display fmt "
-              << D3DFormatStr(dispmode.Format) << " (" << (int)MinMemReqmt
-              << " > " << scrn._max_available_video_memory << ")\n";
-          continue;
-        }
-      }
-
-//      Optimizing for 16-bit depth does not work in all cases so turn it off.
-      if (false) {
-        if ((!bDoMemBasedChecks) || (MinMemReqmt<scrn._max_available_video_memory)) {
-          if (!IS_16BPP_ZBUFFER(zformat)) {
-            // see if things fit with a 16bpp zbuffer
-
-            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;
-              continue;
-            }
-
-            // right now I'm not going to use these flags, just let the
-            // create fail out-of-mem and retry at 16bpp
-            *p_supported_screen_depths_mask |=
-              (IS_16BPP_DISPLAY_FORMAT(dispmode.Format) ? DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG : DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG);
-          }
-        }
-      }
-    }
-
-    if (bVerboseMode || wdxdisplay8_cat.is_spam())
-      wdxdisplay8_cat.info()
-        << "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:
-      *p_supported_screen_depths_mask |= X1R5G5B5_FLAG;
-      break;
-    case D3DFMT_X8R8G8B8:
-      *p_supported_screen_depths_mask |= X8R8G8B8_FLAG;
-      break;
-    case D3DFMT_A8R8G8B8:
-      *p_supported_screen_depths_mask |= A8R8G8B8_FLAG;
-      break;
-    case D3DFMT_R5G6B5:
-      *p_supported_screen_depths_mask |= R5G6B5_FLAG;
-      break;
-    default:
-      // Render target formats should be only D3DFMT_X1R5G5B5,
-      // D3DFMT_R5G6B5, D3DFMT_X8R8G8B8 and D3DFMT_A8R8G8B8
-      wdxdisplay8_cat.error()
-        << "unrecognized supported fmt " << D3DFormatStr(dispmode.Format)
-        << " returned by EnumAdapter_display_modes!\n";
-    }
-  }
-
-  // note: this chooses 32bpp, which may not be preferred over 16 for
-  // memory & speed reasons on some older cards in particular
-  if (*p_supported_screen_depths_mask & X8R8G8B8_FLAG) {
-    *pSuggestedPixFmt = D3DFMT_X8R8G8B8;
-  } else if (*p_supported_screen_depths_mask & A8R8G8B8_FLAG) {
-    *pSuggestedPixFmt = D3DFMT_A8R8G8B8;
-  } else if (*p_supported_screen_depths_mask & R5G6B5_FLAG) {
-    *pSuggestedPixFmt = D3DFMT_R5G6B5;
-  } else if (*p_supported_screen_depths_mask & X1R5G5B5_FLAG) {
-    *pSuggestedPixFmt = D3DFMT_X1R5G5B5;
-  }
-
-  if (bVerboseMode || wdxdisplay8_cat.is_spam()) {
-    wdxdisplay8_cat.info()
-      << "search_for_valid_device returns fmt: "
-      << D3DFormatStr(*pSuggestedPixFmt) << endl;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsPipew8::make_device
-//       Access: Public, Virtual
-//  Description: Creates a new reference to a particular hardware
-//               device and associates it with the pipe.
-////////////////////////////////////////////////////////////////////
-PT(GraphicsDevice) wdxGraphicsPipe8::
-make_device(void *scrn) {
-  PT(DXGraphicsDevice8) device = new DXGraphicsDevice8(this);
-  memcpy(&device->_Scrn, scrn, sizeof(device->_Scrn));
-  device->_d3d_device = device->_Scrn._d3d_device;
-
-  _device = device;
-  wdxdisplay8_cat.info() << "walla: device" << device << "\n";
-
-  return device.p();
-}
-
-pmap<D3DFORMAT_FLAG, D3DFORMAT> g_D3DFORMATmap;
-
-void Init_D3DFORMAT_map() {
-  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);
-}
-
-
-
-const char *D3DFormatStr(D3DFORMAT fmt) {
-
-#define CASESTR(XX) case XX: return #XX;
-  switch(fmt) {
-    CASESTR(D3DFMT_UNKNOWN);
-    CASESTR(D3DFMT_R8G8B8);
-    CASESTR(D3DFMT_A8R8G8B8);
-    CASESTR(D3DFMT_X8R8G8B8);
-    CASESTR(D3DFMT_R5G6B5);
-    CASESTR(D3DFMT_X1R5G5B5);
-    CASESTR(D3DFMT_A1R5G5B5);
-    CASESTR(D3DFMT_A4R4G4B4);
-    CASESTR(D3DFMT_R3G3B2);
-    CASESTR(D3DFMT_A8);
-    CASESTR(D3DFMT_A8R3G3B2);
-    CASESTR(D3DFMT_X4R4G4B4);
-    CASESTR(D3DFMT_A2B10G10R10);
-    CASESTR(D3DFMT_G16R16);
-    CASESTR(D3DFMT_A8P8);
-    CASESTR(D3DFMT_P8);
-    CASESTR(D3DFMT_L8);
-    CASESTR(D3DFMT_A8L8);
-    CASESTR(D3DFMT_A4L4);
-    CASESTR(D3DFMT_V8U8);
-    CASESTR(D3DFMT_L6V5U5);
-    CASESTR(D3DFMT_X8L8V8U8);
-    CASESTR(D3DFMT_Q8W8V8U8);
-    CASESTR(D3DFMT_V16U16);
-    CASESTR(D3DFMT_W11V11U10);
-    CASESTR(D3DFMT_A2W10V10U10);
-    CASESTR(D3DFMT_UYVY);
-    CASESTR(D3DFMT_YUY2);
-    CASESTR(D3DFMT_DXT1);
-    CASESTR(D3DFMT_DXT2);
-    CASESTR(D3DFMT_DXT3);
-    CASESTR(D3DFMT_DXT4);
-    CASESTR(D3DFMT_DXT5);
-    CASESTR(D3DFMT_D16_LOCKABLE);
-    CASESTR(D3DFMT_D32);
-    CASESTR(D3DFMT_D15S1);
-    CASESTR(D3DFMT_D24S8);
-    CASESTR(D3DFMT_D16);
-    CASESTR(D3DFMT_D24X8);
-    CASESTR(D3DFMT_D24X4S4);
-    CASESTR(D3DFMT_VERTEXDATA);
-    CASESTR(D3DFMT_INDEX16);
-    CASESTR(D3DFMT_INDEX32);
-  }
-
-  return "Invalid D3DFORMAT";
-}
-

+ 0 - 122
panda/src/dxgsg8/wdxGraphicsPipe8.h

@@ -1,122 +0,0 @@
-// Filename: wdxGraphicsPipe8.h
-// Created by:  drose (20Dec02)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef WDXGRAPHICSPIPE8_H
-#define WDXGRAPHICSPIPE8_H
-
-#include "pandabase.h"
-#include "winGraphicsPipe.h"
-#include "pvector.h"
-#include "dxgsg8base.h"
-#include <ddraw.h>
-
-////////////////////////////////////////////////////////////////////
-//       Class : wdxGraphicsPipe8
-// Description : This graphics pipe represents the interface for
-//               creating DirectX8 graphics windows.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX wdxGraphicsPipe8 : public WinGraphicsPipe {
-public:
-  wdxGraphicsPipe8();
-  virtual ~wdxGraphicsPipe8();
-
-  virtual string get_interface_name() const;
-  static PT(GraphicsPipe) pipe_constructor();
-
-  virtual PT(GraphicsDevice) make_device(void *scrn);
-
-  bool find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &Test_display_mode,
-                              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 *p_supported_screen_depths_mask,
-                                    bool *pCouldntFindAnyValidZBuf,
-                                    D3DFORMAT *pSuggestedPixFmt,
-                                    bool bForce16bppZBuffer,
-                                    bool bVerboseMode = false);
-
-   bool special_check_fullscreen_resolution(DXScreenData &scrn, UINT x_size,UINT y_size);
-
-protected:
-   virtual PT(GraphicsOutput) make_output(const string &name,
-                                          const FrameBufferProperties &fb_prop,
-                                          const WindowProperties &win_prop,
-                                          int flags,
-                                          GraphicsEngine *engine,
-                                          GraphicsStateGuardian *gsg,
-                                          GraphicsOutput *host,
-                                          int retry,
-                                          bool &precertify);
-   
-private:
-  bool init();
-  bool find_all_card_memavails();
-
-  static BOOL WINAPI
-  dx7_driver_enum_callback(GUID *pGUID, TCHAR *strDesc, TCHAR *strName,
-                           VOID *argptr, HMONITOR hm);
-
-private:
-  HINSTANCE _hDDrawDLL;
-  HINSTANCE _hD3D8_DLL;
-  LPDIRECT3D8 __d3d8;
-
-
-  typedef LPDIRECT3D8 (WINAPI *Direct3DCreate8_ProcPtr)(UINT SDKVersion);
-  typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter);
-
-  LPDIRECTDRAWCREATEEX _DirectDrawCreateEx;
-  LPDIRECTDRAWENUMERATEEX _DirectDrawEnumerateExA;
-  Direct3DCreate8_ProcPtr _Direct3DCreate8;
-
-  // CardID is used in DX7 lowmem card-classification pass so DX8 can
-  // establish correspondence b/w DX7 mem info & DX8 device
-  struct CardID {
-    HMONITOR _monitor;
-    DWORD _max_available_video_memory;
-    bool  _is_low_memory_card;
-    GUID  DX7_DeviceGUID;
-    DWORD VendorID, DeviceID;
-  };
-
-  typedef pvector<CardID> CardIDs;
-  CardIDs _card_ids;
-  bool __is_dx8_1;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    WinGraphicsPipe::init_type();
-    register_type(_type_handle, "wdxGraphicsPipe8",
-                  WinGraphicsPipe::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-
-  friend class wdxGraphicsWindow8;
-};
-
-#include "wdxGraphicsPipe8.I"
-
-#endif

+ 0 - 13
panda/src/dxgsg8/wdxGraphicsWindow8.I

@@ -1,13 +0,0 @@
-// Filename: wdxGraphicsWindow8.I
-// Created by:  drose (20Dec02)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////

+ 0 - 1241
panda/src/dxgsg8/wdxGraphicsWindow8.cxx

@@ -1,1241 +0,0 @@
-// Filename: wdxGraphicsWindow8.cxx
-// Created by:  mike (09Jan00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "wdxGraphicsPipe8.h"
-#include "wdxGraphicsWindow8.h"
-#include "config_dxgsg8.h"
-#include "config_display.h"
-#include "keyboardButton.h"
-#include "mouseButton.h"
-#include "throw_event.h"
-#include "pStatTimer.h"
-#include "pmap.h"
-#include <ddraw.h>
-#include <errno.h>
-#include <time.h>
-#include <math.h>
-#include <tchar.h>
-
-TypeHandle wdxGraphicsWindow8::_type_handle;
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsWindow8::
-wdxGraphicsWindow8(GraphicsEngine *engine, GraphicsPipe *pipe,
-                   const string &name,
-                   const FrameBufferProperties &fb_prop,
-                   const WindowProperties &win_prop,
-                   int flags,
-                   GraphicsStateGuardian *gsg,
-                   GraphicsOutput *host):
-  WinGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
-{
-  // don't actually create the window in the constructor.  reason:
-  // multi-threading requires panda C++ window object to exist in
-  // separate thread from actual API window
-
-  _dxgsg = DCAST(DXGraphicsStateGuardian8, gsg);
-  _depth_buffer_bpp = 0;
-  _awaiting_restore = false;
-  ZeroMemory(&_wcontext, sizeof(_wcontext));
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::Destructor
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-wdxGraphicsWindow8::
-~wdxGraphicsWindow8() {
-}
-
-////////////////////////////////////////////////////////////////////
-//     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(FrameMode mode, Thread *current_thread) {
-  begin_frame_spam(mode);
-  if (_gsg == (GraphicsStateGuardian *)NULL) {
-    return false;
-  }
-  
-  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();
-  }
-
-  make_current();
-
-  if (mode == FM_render) {
-    clear_cube_map_selection();
-  }
-
-  _gsg->set_current_properties(&get_fb_properties());
-  bool return_val = _gsg->begin_frame(current_thread);
-  _dxgsg->set_render_target();
-  return return_val;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::end_frame
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               after rendering is completed for a given frame.  It
-//               should do whatever finalization is required.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-end_frame(FrameMode mode, Thread *current_thread) {
-
-  end_frame_spam(mode);
-  nassertv(_gsg != (GraphicsStateGuardian *)NULL);
-
-  if (mode == FM_render) {
-    copy_to_textures();
-  }
-
-  _gsg->end_frame(current_thread);
-
-  if (mode == FM_render) {
-    trigger_flip();
-    clear_cube_map_selection();
-  }
-}
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::make_current
-//       Access: Private
-//  Description: 
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
-
-  _dxgsg->set_context(&_wcontext);
-
-  // Now that we have made the context current to a window, we can
-  // reset the GSG state if this is the first time it has been used.
-  // (We can't just call reset() when we construct the GSG, because
-  // reset() requires having a current context.)
-  _dxgsg->reset_if_new();
-}
-
-////////////////////////////////////////////////////////////////////
-//     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
-//       Access: Public, Virtual
-//  Description: Determines which of the indicated window sizes are
-//               supported by available hardware (e.g. in fullscreen
-//               mode).
-//
-//               On entry, dimen is an array containing contiguous x, y
-//               pairs specifying possible display sizes; it is
-//               numsizes*2 words long.  The function will zero out
-//               any invalid x, y size pairs.  The return value is the
-//               number of valid sizes that were found.
-////////////////////////////////////////////////////////////////////
-int wdxGraphicsWindow8::
-verify_window_sizes(int numsizes, int *dimen) {
-  // unfortunately this only works AFTER you make the window
-  // initially, so its really mostly useful for resizes only
-  nassertr(IS_VALID_PTR(_dxgsg), 0);
-
-  int num_valid_modes = 0;
-
-  wdxGraphicsPipe8 *dxpipe;
-  DCAST_INTO_R(dxpipe, _pipe, 0);
-
-  // not requesting same refresh rate since changing res might not
-  // support same refresh rate at new size
-
-  int *pCurDim = dimen;
-
-  for (int i = 0; i < numsizes; i++, pCurDim += 2) {
-    int x_size = pCurDim[0];
-    int y_size = pCurDim[1];
-
-    bool bIsGoodMode = false;
-    bool CouldntFindAnyValidZBuf;
-    D3DFORMAT newPixFmt = D3DFMT_UNKNOWN;
-
-    if (dxpipe->special_check_fullscreen_resolution(_wcontext, x_size, y_size)) {
-      // bypass the test below for certain cards we know have valid modes
-      bIsGoodMode = true;
-
-    } else {
-      if (_wcontext._is_low_memory_card) {
-        bIsGoodMode = ((x_size == 640) && (y_size == 480));
-      } else  {
-        dxpipe->search_for_valid_displaymode
-          (_wcontext, x_size, y_size, _wcontext._presentation_params.EnableAutoDepthStencil != false,
-           IS_STENCIL_FORMAT(_wcontext._presentation_params.AutoDepthStencilFormat),
-           &_wcontext._supported_screen_depths_mask,
-           &CouldntFindAnyValidZBuf, &newPixFmt, dx_force_16bpp_zbuffer);
-        bIsGoodMode = (newPixFmt != D3DFMT_UNKNOWN);
-      }
-    }
-
-    if (bIsGoodMode) {
-      num_valid_modes++;
-    } else {
-      // tell caller the mode is invalid
-      pCurDim[0] = 0;
-      pCurDim[1] = 0;
-    }
-
-    if (wdxdisplay8_cat.is_spam()) {
-      wdxdisplay8_cat.spam()
-        << "Fullscrn Mode (" << x_size << ", " << y_size << ")\t"
-        << (bIsGoodMode ? "V" : "Inv") << "alid\n";
-    }
-  }
-
-  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.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-close_window() {
-  if (wdxdisplay8_cat.is_debug()) {
-    wdxdisplay8_cat.debug()
-      << "wdxGraphicsWindow8::close_window() " << this << "\n";
-  }
-
-  if (_gsg != (GraphicsStateGuardian*)NULL) {
-    _gsg.clear();
-  }
-
-  _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::
-open_window() {
-  PT(DXGraphicsDevice8) dxdev;
-  WindowProperties props;
-
-  // For now, let's make this configurable.  If this is true, then you
-  // can't open multiple different windows with the same GSG, but you
-  // may have more luck opening different windows with different
-  // GSG's.
-  static ConfigVariableBool always_discard_device("always-discard-device", true);
-  bool discard_device = always_discard_device;
-
-  // GSG creation/initialization.
-  if (_gsg == 0) {
-    _dxgsg = new DXGraphicsStateGuardian8(_engine, _pipe);
-    _gsg = _dxgsg;
-  } else {
-    DCAST_INTO_R(_dxgsg, _gsg, false);
-  }
-  
-  if (!choose_device()) {
-    return false;
-  }
-
-  // Ensure the window properties get set to the actual size of the
-  // window.
-  {
-    WindowProperties resized_props;
-    resized_props.set_size(_wcontext._display_mode.Width, 
-                           _wcontext._display_mode.Height);
-    _properties.add_properties(resized_props);
-  }
-
-  wdxdisplay8_cat.debug() << "_wcontext._window is " << _wcontext._window << "\n";
-  if (!WinGraphicsWindow::open_window()) {
-    return false;
-  }
-  _wcontext._window = _hWnd;
-
-  wdxdisplay8_cat.debug() << "_wcontext._window is " << _wcontext._window << "\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._display_mode.Width << "\n";
-      if (!create_screen_buffers_and_device(_wcontext, dx_force_16bpp_zbuffer)) {
-        wdxdisplay8_cat.error() << "Unable to create window with specified parameters.\n";
-        close_window();
-        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 _window.
-      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._presentation_params.Windowed = !is_fullscreen();
-      _wcontext._presentation_params.hDeviceWindow = _wcontext._window = _hWnd;
-      _wcontext._presentation_params.BackBufferWidth = _wcontext._display_mode.Width = props.get_x_size();
-      _wcontext._presentation_params.BackBufferHeight = _wcontext._display_mode.Height = props.get_y_size();
-
-      wdxdisplay8_cat.debug() << "device width " << _wcontext._presentation_params.BackBufferWidth << "\n";
-      if (!_dxgsg->create_swap_chain(&_wcontext)) {
-        discard_device = true;
-        continue; // try again
-      }
-      init_resized_window();
-      break;
-    }
-  }
-  wdxdisplay8_cat.debug() << "swapchain is " << _wcontext._swap_chain << "\n";
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     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) {
-  if (swapchain) {
-    if (_wcontext._swap_chain) {
-      _dxgsg->create_swap_chain(&_wcontext);
-      wdxdisplay8_cat.debug() << "created swapchain " << _wcontext._swap_chain << "\n";
-    }
-  }
-  else {
-    if (_wcontext._swap_chain) {
-      _dxgsg->release_swap_chain(&_wcontext);
-      wdxdisplay8_cat.debug() << "released swapchain " << _wcontext._swap_chain << "\n";
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::fullscreen_restored
-//       Access: Protected, Virtual
-//  Description: This is a hook for derived classes to do something
-//               special, if necessary, when a fullscreen window has
-//               been restored after being minimized.  The given
-//               WindowProperties struct will be applied to this
-//               window's properties after this function returns.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-fullscreen_restored(WindowProperties &properties) {
-  // In DX8, unlike DX7, for some reason we can't immediately start
-  // rendering as soon as the window is restored, even though
-  // BeginScene() says we can.  Instead, we have to wait until
-  // TestCooperativeLevel() lets us in.  We need to set a flag so we
-  // can handle this special case in begin_frame().
-  if (_dxgsg != NULL) {
-    _awaiting_restore = true;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::handle_reshape
-//       Access: Protected, Virtual
-//  Description: Called in the window thread when the window size or
-//               location is changed, this updates the properties
-//               structure accordingly.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-handle_reshape() {
-  GdiFlush();
-  WinGraphicsWindow::handle_reshape();
-
-  if (_dxgsg != NULL && _dxgsg->_d3d_device != NULL) {
-    // create the new resized rendertargets
-    WindowProperties props = get_properties();
-    int x_size = props.get_x_size();
-    int y_size = props.get_y_size();
-
-    if (_wcontext._presentation_params.BackBufferWidth != x_size ||
-        _wcontext._presentation_params.BackBufferHeight != y_size) {
-      bool resize_succeeded = reset_device_resize_window(x_size, y_size);
-
-      if (wdxdisplay8_cat.is_debug()) {
-        if (!resize_succeeded) {
-          wdxdisplay8_cat.debug()
-            << "windowed_resize to size: (" << x_size << ", " << y_size
-            << ") failed due to out-of-memory\n";
-        } else {
-          int x_origin = props.get_x_origin();
-          int y_origin = props.get_y_origin();
-          wdxdisplay8_cat.debug()
-            << "windowed_resize to origin: (" << x_origin << ", "
-            << y_origin << "), size: (" << x_size
-            << ", " << y_size << ")\n";
-        }
-      }
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::do_fullscreen_resize
-//       Access: Protected, Virtual
-//  Description: Called in the window thread to resize a fullscreen
-//               window.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-do_fullscreen_resize(int x_size, int y_size) {
-  if (!WinGraphicsWindow::do_fullscreen_resize(x_size, y_size)) {
-    return false;
-  }
-
-  bool bCouldntFindValidZBuf;
-  D3DFORMAT pixFmt;
-  bool bNeedZBuffer = (_wcontext._presentation_params.EnableAutoDepthStencil != false);
-  bool bNeedStencilBuffer = IS_STENCIL_FORMAT(_wcontext._presentation_params.AutoDepthStencilFormat);
-
-  wdxGraphicsPipe8 *dxpipe;
-  DCAST_INTO_R(dxpipe, _pipe, false);
-
-  bool bIsGoodMode = false;
-  bool bResizeSucceeded = false;
-
-  if (!dxpipe->special_check_fullscreen_resolution(_wcontext, x_size, y_size)) {
-    // bypass the lowvidmem test below for certain "lowmem" cards we know have valid modes
-
-    if (_wcontext._is_low_memory_card && (!((x_size == 640) && (y_size == 480)))) {
-      wdxdisplay8_cat.error() << "resize() failed: will not try to resize low vidmem device #" << _wcontext._card_id << " to non-640x480!\n";
-      return bResizeSucceeded;
-    }
-  }
-
-  // must ALWAYS use search_for_valid_displaymode even if we know
-  // a-priori that res is valid so we can get a valid pixfmt
-  dxpipe->search_for_valid_displaymode(_wcontext, x_size, y_size,
-                                       bNeedZBuffer, bNeedStencilBuffer,
-                                       &_wcontext._supported_screen_depths_mask,
-                                       &bCouldntFindValidZBuf,
-                                       &pixFmt, dx_force_16bpp_zbuffer);
-  bIsGoodMode = (pixFmt != D3DFMT_UNKNOWN);
-
-  if (!bIsGoodMode) {
-    wdxdisplay8_cat.error() << "resize() failed: "
-                            << (bCouldntFindValidZBuf ? "Couldnt find valid zbuffer format to go with FullScreen mode" : "No supported FullScreen modes")
-                            << " at " << x_size << "x" << y_size << " for device #" << _wcontext._card_id << endl;
-    return bResizeSucceeded;
-  }
-
-  // reset_device_resize_window handles both windowed & fullscrn,
-  // so need to set new displaymode manually here
-  _wcontext._display_mode.Width = x_size;
-  _wcontext._display_mode.Height = y_size;
-  _wcontext._display_mode.Format = pixFmt;
-  _wcontext._display_mode.RefreshRate = D3DPRESENT_RATE_DEFAULT;
-
-  _wcontext._presentation_params.BackBufferFormat = pixFmt;   // make reset_device_resize use presparams or displaymode??
-
-  bResizeSucceeded = reset_device_resize_window(x_size, y_size);
-
-  if (!bResizeSucceeded) {
-    wdxdisplay8_cat.error() << "resize() failed with OUT-OF-MEMORY error!\n";
-
-    if ((!IS_16BPP_DISPLAY_FORMAT(_wcontext._presentation_params.BackBufferFormat)) &&
-        (_wcontext._supported_screen_depths_mask & (R5G6B5_FLAG|X1R5G5B5_FLAG))) {
-      // fallback strategy, if we trying >16bpp, fallback to 16bpp buffers
-      _wcontext._display_mode.Format = ((_wcontext._supported_screen_depths_mask & R5G6B5_FLAG) ? D3DFMT_R5G6B5 : D3DFMT_X1R5G5B5);
-      dx_force_16bpp_zbuffer = true;
-      if (wdxdisplay8_cat.info())
-        wdxdisplay8_cat.info() << "CreateDevice failed with out-of-vidmem, retrying w/16bpp buffers on device #" << _wcontext._card_id << endl;
-
-      bResizeSucceeded = reset_device_resize_window(x_size, y_size);  // create the new resized rendertargets
-    }
-  }
-
-  return bResizeSucceeded;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::create_screen_buffers_and_device
-//       Access: Private
-//  Description: Called whenever the window is resized, this recreates
-//               the necessary buffers for rendering.
-//
-//               Sets _depth_buffer_bpp appropriately.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-create_screen_buffers_and_device(DXScreenData &display, bool force_16bpp_zbuffer) {
-  wdxGraphicsPipe8 *dxpipe;
-  DCAST_INTO_R(dxpipe, _pipe, false);
-
-  DWORD dwRenderWidth = display._display_mode.Width;
-  DWORD dwRenderHeight = display._display_mode.Height;
-  DWORD dwBehaviorFlags = 0x0;
-  LPDIRECT3D8 _d3d8 = display._d3d8;
-  D3DCAPS8 *pD3DCaps = &display._d3dcaps;
-  D3DPRESENT_PARAMETERS* presentation_params = &display._presentation_params;
-  RECT view_rect;
-  HRESULT hr;
-
-  wdxdisplay8_cat.debug() << "Display Width " << dwRenderWidth << " and PresParam Width " << _wcontext._presentation_params.BackBufferWidth << "\n";
-
-  bool bWantStencil = (_fb_properties.get_stencil_bits() > 0);
-
-  PRINT_REFCNT(wdxdisplay8, _d3d8);
-
-  nassertr(_d3d8 != NULL, false);
-  nassertr(pD3DCaps->DevCaps & D3DDEVCAPS_HWRASTERIZATION, false);
-
-  presentation_params->BackBufferFormat = display._display_mode.Format;  // don't need dest alpha, so just use adapter format
-  cerr << "attempting " << D3DFormatStr(presentation_params->BackBufferFormat) << "\n";
-
-  bool do_sync = sync_video;
-
-  if (do_sync && !(pD3DCaps->Caps & D3DCAPS_READ_SCANLINE)) {
-    wdxdisplay8_cat.info()
-      << "HW doesnt support syncing to vertical refresh, ignoring sync-video\n";
-    do_sync = false;
-  }
-
-  // verify the rendertarget fmt one last time
-  if (FAILED(_d3d8->CheckDeviceFormat(display._card_id, D3DDEVTYPE_HAL, display._display_mode.Format, D3DUSAGE_RENDERTARGET,
-                                      D3DRTYPE_SURFACE, presentation_params->BackBufferFormat))) {
-    wdxdisplay8_cat.error() << "device #" << display._card_id << " CheckDeviceFmt failed for surface fmt " << D3DFormatStr(presentation_params->BackBufferFormat) << endl;
-    goto Fallback_to_16bpp_buffers;
-  }
-
-  if (FAILED(_d3d8->CheckDeviceType(display._card_id, D3DDEVTYPE_HAL, display._display_mode.Format, presentation_params->BackBufferFormat,
-                                    is_fullscreen()))) {
-    wdxdisplay8_cat.error() << "device #" << display._card_id << " CheckDeviceType failed for surface fmt " << D3DFormatStr(presentation_params->BackBufferFormat) << endl;
-    goto Fallback_to_16bpp_buffers;
-  }
-
-  if (display._presentation_params.EnableAutoDepthStencil) {
-    if (!dxpipe->find_best_depth_format(display, display._display_mode,
-                                        &display._presentation_params.AutoDepthStencilFormat,
-                                        bWantStencil, false)) {
-      wdxdisplay8_cat.error()
-        << "find_best_depth_format failed in CreateScreenBuffers for device #"
-        << display._card_id << endl;
-      goto Fallback_to_16bpp_buffers;
-    }
-    _depth_buffer_bpp = D3DFMT_to_DepthBits(display._presentation_params.AutoDepthStencilFormat);
-  } else {
-    _depth_buffer_bpp = 0;
-  }
-
-  presentation_params->Windowed = !is_fullscreen();
-
-  if (dx_multisample_antialiasing_level>1) {
-    // need to check both rendertarget and zbuffer fmts
-    hr = _d3d8->CheckDeviceMultiSampleType(display._card_id, D3DDEVTYPE_HAL, display._display_mode.Format,
-                                           is_fullscreen(), D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value()));
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.fatal() << "device #" << display._card_id << " doesnt support multisample level " << dx_multisample_antialiasing_level << "surface fmt " << D3DFormatStr(display._display_mode.Format) << endl;
-      return false;
-    }
-
-    if (display._presentation_params.EnableAutoDepthStencil) {
-      hr = _d3d8->CheckDeviceMultiSampleType(display._card_id, D3DDEVTYPE_HAL, display._presentation_params.AutoDepthStencilFormat,
-                                             is_fullscreen(), D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value()));
-      if (FAILED(hr)) {
-        wdxdisplay8_cat.fatal() << "device #" << display._card_id << " doesnt support multisample level " << dx_multisample_antialiasing_level << "surface fmt " << D3DFormatStr(display._presentation_params.AutoDepthStencilFormat) << endl;
-        return false;
-      }
-    }
-
-    presentation_params->MultiSampleType = D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level.get_value());
-
-    if (wdxdisplay8_cat.is_info())
-      wdxdisplay8_cat.info() << "device #" << display._card_id << " using multisample antialiasing level " << dx_multisample_antialiasing_level << endl;
-  }
-
-  presentation_params->BackBufferCount = 1;
-  presentation_params->Flags = 0x0;
-  presentation_params->hDeviceWindow = display._window;
-  presentation_params->BackBufferWidth = display._display_mode.Width;
-  presentation_params->BackBufferHeight = display._display_mode.Height;
-
-  if (_wcontext._is_tnl_device) {
-    dwBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
-    // note: we could create a pure device in this case if I
-    // eliminated the GetRenderState calls in dxgsg
-
-    // also, no software vertex processing available since I specify
-    // D3DCREATE_HARDWARE_VERTEXPROCESSING and not
-    // D3DCREATE_MIXED_VERTEXPROCESSING
-  } else {
-    dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
-  }
-
-  if (dx_preserve_fpu_state)
-    dwBehaviorFlags |= D3DCREATE_FPU_PRESERVE;
-
-  // if window is not foreground in exclusive mode, ddraw thinks you
-  // are 'not active', so it changes your WM_ACTIVATEAPP from true to
-  // false, causing us to go into a 'wait-for WM_ACTIVATEAPP true'
-  // loop, and the event never comes so we hang in fullscreen wait.
-  // also doing this for windowed mode since it was requested.
-  if (!SetForegroundWindow(display._window)) {
-    wdxdisplay8_cat.warning() << "SetForegroundWindow() failed!\n";
-  }
-
-  if (is_fullscreen()) {
-    // CREATE FULLSCREEN BUFFERS
-
-    presentation_params->SwapEffect = D3DSWAPEFFECT_DISCARD;  // we don't care about preserving contents of old frame
-    presentation_params->FullScreen_PresentationInterval = (do_sync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE);
-    presentation_params->FullScreen_RefreshRateInHz = display._display_mode.RefreshRate;
-
-    ClearToBlack(display._window, get_properties());
-
-    hr = _d3d8->CreateDevice(display._card_id, D3DDEVTYPE_HAL, _hWnd,
-                             dwBehaviorFlags, presentation_params, &display._d3d_device);
-
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.fatal() << "D3D CreateDevice failed for device #" << display._card_id << ", " << D3DERRORSTRING(hr);
-
-      if (hr == D3DERR_OUTOFVIDEOMEMORY)
-        goto Fallback_to_16bpp_buffers;
-      else
-        return false;
-    }
-
-    SetRect(&view_rect, 0, 0, dwRenderWidth, dwRenderHeight);
-
-  } else {
-    // CREATE WINDOWED BUFFERS
-
-    D3DDISPLAYMODE dispmode;
-    hr = display._d3d8->GetAdapterDisplayMode(display._card_id, &dispmode);
-
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.fatal()
-        << "GetAdapterDisplayMode failed" << D3DERRORSTRING(hr);
-      return false;
-    }
-
-    if (dispmode.Format == D3DFMT_P8) {
-      wdxdisplay8_cat.fatal()
-        << "Can't run windowed in an 8-bit or less display mode" << endl;
-      return false;
-    }
-
-    presentation_params->FullScreen_PresentationInterval = 0;
-
-    if (dx_multisample_antialiasing_level<2) {
-      if (do_sync) {
-        // It turns out that COPY_VSYNC has real performance problems
-        // on many nVidia cards--it syncs at some random interval,
-        // possibly skipping over several video syncs.  Screw it,
-        // we'll effectively disable sync-video with windowed mode
-        // using DirectX8.
-        //presentation_params->SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
-        presentation_params->SwapEffect = D3DSWAPEFFECT_DISCARD;
-      } else {
-        presentation_params->SwapEffect = D3DSWAPEFFECT_DISCARD;
-      }
-    } else {
-      presentation_params->SwapEffect = D3DSWAPEFFECT_DISCARD;
-    }
-
-    //nassertv((dwRenderWidth == presentation_params->BackBufferWidth)&&(dwRenderHeight == presentation_params->BackBufferHeight));
-
-    hr = _d3d8->CreateDevice(display._card_id, D3DDEVTYPE_HAL, _hWnd,
-                             dwBehaviorFlags, presentation_params, &display._d3d_device);
-
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.warning() << "presentation_params->BackBufferWidth : " << presentation_params->BackBufferWidth << endl;
-      wdxdisplay8_cat.warning() << "presentation_params->BackBufferHeight : " << presentation_params->BackBufferHeight << endl;
-      wdxdisplay8_cat.warning() << "presentation_params->BackBufferFormat : " << presentation_params->BackBufferFormat << endl;
-      wdxdisplay8_cat.warning() << "presentation_params->BackBufferCount : " << presentation_params->BackBufferCount << endl;
-      wdxdisplay8_cat.warning() << "D3D CreateDevice failed for device #" << display._card_id << D3DERRORSTRING(hr);
-      goto Fallback_to_16bpp_buffers;
-    }
-  }  // end create windowed buffers
-
-  //  ========================================================
-
-  PRINT_REFCNT(wdxdisplay8, _wcontext._d3d_device);
-
-  if (presentation_params->EnableAutoDepthStencil) {
-    int depth_bits;
-    int stencil_bits;
-
-    depth_bits = 1;
-    stencil_bits = 0;
-    switch (presentation_params->AutoDepthStencilFormat)
-    {
-      case D3DFMT_D16_LOCKABLE:
-        depth_bits = 16;
-        break;
-      case D3DFMT_D32:
-        depth_bits = 32;
-        break;
-      case D3DFMT_D15S1:
-        depth_bits = 15;
-        stencil_bits = 1;
-        break;
-      case D3DFMT_D24S8:
-        depth_bits = 24;
-        stencil_bits = 8;
-        break;
-      case D3DFMT_D24X8:
-        depth_bits = 24;
-        break;
-      case D3DFMT_D24X4S4:
-        depth_bits = 24;
-        stencil_bits = 4;
-        break;
-      case D3DFMT_D16:
-        depth_bits = 16;
-        break;
-      default:
-        wdxdisplay8_cat.error() << "unknown depth stencil format  " << presentation_params->AutoDepthStencilFormat;
-        break;
-    }
-      
-    _fb_properties.set_stencil_bits(stencil_bits);
-    _fb_properties.set_depth_bits(depth_bits);
-  } else {
-    _fb_properties.set_depth_bits(0);
-    _fb_properties.set_stencil_bits(0);
-  }
-
-  init_resized_window();
-
-  return true;
-
- Fallback_to_16bpp_buffers:
-  if ((!IS_16BPP_DISPLAY_FORMAT(presentation_params->BackBufferFormat)) &&
-      (display._supported_screen_depths_mask & (R5G6B5_FLAG|X1R5G5B5_FLAG))) {
-    // fallback strategy, if we trying >16bpp, fallback to 16bpp buffers
-
-    display._display_mode.Format = ((display._supported_screen_depths_mask & R5G6B5_FLAG) ? D3DFMT_R5G6B5 : D3DFMT_X1R5G5B5);
-
-    if (wdxdisplay8_cat.info()) {
-      wdxdisplay8_cat.info()
-        << "CreateDevice failed with out-of-vidmem or invalid BackBufferFormat, retrying w/16bpp buffers on device #"
-        << display._card_id << endl;
-    }
-    return create_screen_buffers_and_device(display, true);
-    //return;
-
-  } else if (!((dwRenderWidth == 640)&&(dwRenderHeight == 480))) {
-    if (wdxdisplay8_cat.info())
-      wdxdisplay8_cat.info() << "CreateDevice failed w/out-of-vidmem, retrying at 640x480 w/16bpp buffers on device #" << display._card_id << endl;
-    // try final fallback to 640x480x16
-    display._display_mode.Width = 640;
-    display._display_mode.Height = 480;
-    return create_screen_buffers_and_device(display, true);
-    //return;
-
-  } else {
-    wdxdisplay8_cat.fatal()
-      << "Can't create any screen buffers, bailing out.\n";
-    return false;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::choose_device
-//       Access: Private
-//  Description: Looks at the list of available graphics adapters and
-//               chooses a suitable one for the window.
-//
-//               Returns true if successful, false on failure.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-choose_device() {
-  HRESULT hr;
-
-  wdxGraphicsPipe8 *dxpipe;
-  DCAST_INTO_R(dxpipe, _pipe, false);
-
-  int num_adapters = dxpipe->__d3d8->GetAdapterCount();
-  DXDeviceInfoVec device_infos;
-
-  for (int i = 0; i < num_adapters; i++) {
-    D3DADAPTER_IDENTIFIER8 adapter_info;
-    ZeroMemory(&adapter_info, sizeof(D3DADAPTER_IDENTIFIER8));
-    hr = dxpipe->__d3d8->GetAdapterIdentifier(i, D3DENUM_NO_WHQL_LEVEL, &adapter_info);
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.fatal()
-        << "D3D GetAdapterID(" << i << ") failed: "
-        << D3DERRORSTRING(hr) << endl;
-      continue;
-    }
-
-    LARGE_INTEGER *DrvVer = &adapter_info.DriverVersion;
-
-    wdxdisplay8_cat.info()
-      << "D3D8." << (dxpipe->__is_dx8_1 ?"1":"0") << " Adapter[" << i << "]: " << adapter_info.Description
-      << ", Driver: " << adapter_info.Driver << ", DriverVersion: ("
-      << HIWORD(DrvVer->HighPart) << "." << LOWORD(DrvVer->HighPart) << "."
-      << HIWORD(DrvVer->LowPart) << "." << LOWORD(DrvVer->LowPart)
-      << ")\nVendorID: 0x" << (void*) adapter_info.VendorId
-      << " DeviceID: 0x" <<  (void*) adapter_info.DeviceId
-      << " SubsysID: 0x" << (void*) adapter_info.SubSysId
-      << " Revision: 0x" << (void*) adapter_info.Revision << endl;
-
-    HMONITOR _monitor = dxpipe->__d3d8->GetAdapterMonitor(i);
-    if (_monitor == NULL) {
-      wdxdisplay8_cat.info()
-        << "D3D8 Adapter[" << i << "]: seems to be disabled, skipping it\n";
-      continue;
-    }
-
-    DXDeviceInfo devinfo;
-    ZeroMemory(&devinfo, sizeof(devinfo));
-    memcpy(&devinfo.guidDeviceIdentifier, &adapter_info.DeviceIdentifier,
-           sizeof(GUID));
-    strncpy(devinfo.szDescription, adapter_info.Description,
-            MAX_DEVICE_IDENTIFIER_STRING);
-    strncpy(devinfo.szDriver, adapter_info.Driver,
-            MAX_DEVICE_IDENTIFIER_STRING);
-    devinfo.VendorID = adapter_info.VendorId;
-    devinfo.DeviceID = adapter_info.DeviceId;
-    devinfo._monitor = _monitor;
-    devinfo.cardID = i;
-
-    device_infos.push_back(devinfo);
-  }
-
-  if (device_infos.empty()) {
-    wdxdisplay8_cat.error()
-      << "No available D3D8 devices found.\n";
-    return false;
-  }
-
-  // Since some adapters may have been disabled, we should re-obtain
-  // the number of available adapters.
-  num_adapters = (int)device_infos.size();
-
-  // Now choose a suitable adapter.
-
-  int adapter_num = D3DADAPTER_DEFAULT;
-
-  // Eventually, we should have some interface for specifying a device
-  // index interactively, instead of only via Configrc.
-  if (dx_preferred_device_id != -1) {
-    if (dx_preferred_device_id < 0 || dx_preferred_device_id >= num_adapters) {
-      wdxdisplay8_cat.error()
-        << "invalid 'dx-preferred-device-id', valid values are 0-"
-        << num_adapters - 1 << ", using default adapter instead.\n";
-    } else {
-      adapter_num = dx_preferred_device_id;
-    }
-  }
-
-  UINT good_device_count = 0;
-  for(UINT devnum = 0;devnum<device_infos.size() /*&& (good_device_count < num_windows)*/;devnum++) {
-    if (search_for_device(dxpipe, &device_infos[devnum]))
-      good_device_count++;
-  }
-
-  if (good_device_count == 0) {
-    wdxdisplay8_cat.error() << "no usable display devices.\n";
-    return false;
-  }
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::search_for_device
-//       Access: Private
-//  Description: Searches for a suitable hardware device for
-//               rendering.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-search_for_device(wdxGraphicsPipe8 *dxpipe, DXDeviceInfo *device_info) {
-
-  nassertr(dxpipe != NULL, false);
-  WindowProperties properties = get_properties();
-  DWORD dwRenderWidth = properties.get_x_size();
-  DWORD dwRenderHeight = properties.get_y_size();
-  HRESULT hr;
-  LPDIRECT3D8 _d3d8 = dxpipe->__d3d8;
-
-  nassertr(_dxgsg != NULL, false);
-  _wcontext._d3d8 = _d3d8;
-  _wcontext._is_dx8_1 = dxpipe->__is_dx8_1;
-  _wcontext._card_id = device_info->cardID;  // could this change by end?
-
-  bool bWantStencil = (_fb_properties.get_stencil_bits() > 0);
-
-  hr = _d3d8->GetAdapterIdentifier(device_info->cardID, D3DENUM_NO_WHQL_LEVEL,
-                                   &_wcontext._dx_device_id);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.error()
-      << "D3D GetAdapterID failed" << D3DERRORSTRING(hr);
-    return false;
-  }
-
-  D3DCAPS8 _d3dcaps;
-  hr = _d3d8->GetDeviceCaps(device_info->cardID, D3DDEVTYPE_HAL, &_d3dcaps);
-  if (FAILED(hr)) {
-    if ((hr == D3DERR_INVALIDDEVICE)||(hr == D3DERR_NOTAVAILABLE)) {
-      wdxdisplay8_cat.error()
-        << "No DirectX 8 D3D-capable 3D hardware detected for device # "
-        << device_info->cardID << " (" << device_info->szDescription
-        << ")!\n";
-    } else {
-      wdxdisplay8_cat.error()
-        << "GetDeviceCaps failed: " << D3DERRORSTRING(hr) << endl;
-    }
-    return false;
-  }
-
-  //search_for_valid_displaymode needs these to be set
-  memcpy(&_wcontext._d3dcaps, &_d3dcaps, sizeof(D3DCAPS8));
-  _wcontext._card_id = device_info->cardID;
-
-  _wcontext._max_available_video_memory = UNKNOWN_VIDMEM_SIZE;
-  _wcontext._is_low_memory_card = false;
-
-  // bugbug: wouldnt we like to do GetAVailVidMem so we can do
-  // upper-limit memory computation for dx8 cards too?  otherwise
-  // verify_window_sizes cant do much
-  if (_d3dcaps.MaxStreams == 0) {
-    if (wdxdisplay8_cat.is_debug()) {
-      wdxdisplay8_cat.debug()
-        << "checking vidmem size\n";
-    }
-
-    UINT IDnum;
-
-    // simple linear search to match DX7 card info w/DX8 card ID
-    for (IDnum = 0; IDnum < dxpipe->_card_ids.size(); IDnum++) {
-      if ((device_info->VendorID == dxpipe->_card_ids[IDnum].VendorID) &&
-          (device_info->DeviceID == dxpipe->_card_ids[IDnum].DeviceID) &&
-          (device_info->_monitor == dxpipe->_card_ids[IDnum]._monitor))
-        break;
-    }
-
-    if (IDnum < dxpipe->_card_ids.size()) {
-      _wcontext._max_available_video_memory = dxpipe->_card_ids[IDnum]._max_available_video_memory;
-      _wcontext._is_low_memory_card = dxpipe->_card_ids[IDnum]._is_low_memory_card;
-    } else {
-      wdxdisplay8_cat.error()
-        << "Error: couldnt find a CardID match in DX7 info, assuming card is not a lowmem card\n";
-    }
-  }
-
-  if ((bWantStencil) && (_d3dcaps.StencilCaps == 0x0)) {
-    wdxdisplay8_cat.fatal()
-      << "Stencil ability requested, but device #" << device_info->cardID
-      << " (" << _wcontext._dx_device_id.Description
-      << "), has no stencil capability!\n";
-    return false;
-  }
-
-  // just because TNL is true, it doesnt mean vtx shaders are
-  // supported in HW (see GF2) for this case, you probably want MIXED
-  // processing to use HW for fixed-fn vertex processing and SW for
-  // vtx shaders
-  _wcontext._is_tnl_device =
-    ((_d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0);
-  _wcontext._can_use_hw_vertex_shaders =
-    (_d3dcaps.VertexShaderVersion >= D3DVS_VERSION(1, 0));
-  _wcontext._can_use_pixel_shaders =
-    (_d3dcaps.PixelShaderVersion >= D3DPS_VERSION(1, 0));
-
-  bool bNeedZBuffer =
-    ((!(_d3dcaps.RasterCaps & D3DPRASTERCAPS_ZBUFFERLESSHSR )) &&
-     (_fb_properties.get_depth_bits() > 0));
-
-  _wcontext._presentation_params.EnableAutoDepthStencil = bNeedZBuffer;
-
-  D3DFORMAT pixFmt = D3DFMT_UNKNOWN;
-
-  if (is_fullscreen()) {
-    bool bCouldntFindValidZBuf;
-    dxpipe->search_for_valid_displaymode(_wcontext, dwRenderWidth, dwRenderHeight,
-                                         bNeedZBuffer, bWantStencil,
-                                         &_wcontext._supported_screen_depths_mask,
-                                         &bCouldntFindValidZBuf,
-                                         &pixFmt, dx_force_16bpp_zbuffer);
-    
-    // note I'm not saving refresh rate, will just use adapter
-    // default at given res for now
-    
-    if (pixFmt == D3DFMT_UNKNOWN) {
-      wdxdisplay8_cat.error()
-        << (bCouldntFindValidZBuf ? "Couldnt find valid zbuffer format to go with FullScreen mode" : "No supported FullScreen modes")
-        << " at " << dwRenderWidth << "x" << dwRenderHeight << " for device #" << _wcontext._card_id << endl;
-      
-      // run it again in verbose mode to get more dbg info to log
-      dxpipe->search_for_valid_displaymode(_wcontext, dwRenderWidth, dwRenderHeight,
-                                           bNeedZBuffer, bWantStencil,
-                                           &_wcontext._supported_screen_depths_mask,
-                                           &bCouldntFindValidZBuf,
-                                           &pixFmt, dx_force_16bpp_zbuffer, true);
-      
-      // if still D3DFMT_UNKNOWN return false
-      if (pixFmt == D3DFMT_UNKNOWN)
-        return false;
-    }
-  } else {
-    // Windowed Mode
-
-    D3DDISPLAYMODE dispmode;
-    hr = _d3d8->GetAdapterDisplayMode(device_info->cardID, &dispmode);
-    if (FAILED(hr)) {
-      wdxdisplay8_cat.error()
-        << "GetAdapterDisplayMode(" << device_info->cardID
-        << ") failed" << D3DERRORSTRING(hr);
-      return false;
-    }
-    pixFmt = dispmode.Format;
-  }
-
-  _wcontext._display_mode.Width = dwRenderWidth;
-  _wcontext._display_mode.Height = dwRenderHeight;
-  _wcontext._display_mode.Format = pixFmt;
-  _wcontext._display_mode.RefreshRate = D3DPRESENT_RATE_DEFAULT;
-  _wcontext._monitor = device_info->_monitor;
-
-  if (dwRenderWidth != properties.get_x_size() ||
-      dwRenderHeight != properties.get_y_size()) {
-    // This is probably not the best place to put this; I'm just
-    // putting it here for now because the code above might have
-    // changed the size of the window unexpectedly.  This code gets
-    // called when make_gsg() is called, which means it is called in
-    // the draw thread, but this method should really be called from
-    // the window thread.  In DirectX those may always be the same
-    // threads anyway, so we may be all right.  Still, it's a little
-    // strange that the window may change size after it has already
-    // been opened, at the time we create the GSG for it; it would be
-    // better if we could find a way to do this resolution-selection
-    // logic earlier, say at the time the window is created.
-    system_changed_size(dwRenderWidth, dwRenderHeight);
-    WindowProperties resized_props;
-    resized_props.set_size(dwRenderWidth, dwRenderHeight);
-    _properties.add_properties(resized_props);
-  }
-
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::reset_device_resize_window
-//       Access: Private
-//  Description: Called after a window (either fullscreen or windowed)
-//               has been resized, this recreates the D3D structures
-//               to match the new size.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-reset_device_resize_window(UINT new_xsize, UINT new_ysize) {
-  nassertr((new_xsize > 0) && (new_ysize > 0), false);
-  bool retval = true;
-
-  DXScreenData *screen = NULL;
-  D3DPRESENT_PARAMETERS d3dpp;
-  memcpy(&d3dpp, &_wcontext._presentation_params, sizeof(D3DPRESENT_PARAMETERS));
-  _wcontext._presentation_params.BackBufferWidth = new_xsize;
-  _wcontext._presentation_params.BackBufferHeight = new_ysize;
-  make_current();
-  HRESULT hr = _dxgsg->reset_d3d_device(&_wcontext._presentation_params, &screen);
-
-  if (FAILED(hr)) {
-    retval = false;
-    wdxdisplay8_cat.error()
-      << "reset_device_resize_window Reset() failed" << D3DERRORSTRING(hr);
-    if (hr == D3DERR_OUTOFVIDEOMEMORY) {
-      memcpy(&_wcontext._presentation_params, &d3dpp, sizeof(D3DPRESENT_PARAMETERS));
-      hr = _dxgsg->reset_d3d_device(&_wcontext._presentation_params, &screen);
-      if (FAILED(hr)) {
-        wdxdisplay8_cat.error()
-          << "reset_device_resize_window Reset() failed OutOfVidmem, then failed again doing Reset w/original params:" << D3DERRORSTRING(hr);
-        throw_event("panda3d-render-error");
-        return false;
-
-      } else {
-        if (wdxdisplay8_cat.is_info()) {
-          wdxdisplay8_cat.info()
-            << "reset of original size (" << _wcontext._presentation_params.BackBufferWidth
-            << ", " << _wcontext._presentation_params.BackBufferHeight << ") succeeded\n";
-        }
-      }
-    } else {
-      wdxdisplay8_cat.fatal()
-        << "Can't reset device, bailing out.\n";
-      throw_event("panda3d-render-error");
-      return false;
-    }
-  }
-  // before you init_resized_window you need to copy certain changes to _wcontext
-  if (screen) {
-    _wcontext._swap_chain = screen->_swap_chain;
-  }
-  wdxdisplay8_cat.debug() << "swapchain is " << _wcontext._swap_chain << "\n";
-  _gsg->mark_new();
-  init_resized_window();
-  return retval;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::init_resized_window
-//       Access: Private
-//  Description: Reinitializes the window after it has been resized,
-//               or after it is first created.
-//
-//               Assumes CreateDevice or Device->Reset() has just been
-//               called, and the new size is specified in
-//               _wcontext._presentation_params.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-init_resized_window() {
-  HRESULT hr;
-
-  DWORD newWidth = _wcontext._presentation_params.BackBufferWidth;
-  DWORD newHeight = _wcontext._presentation_params.BackBufferHeight;
-
-  nassertv((newWidth != 0) && (newHeight != 0));
-  nassertv(_wcontext._window != NULL);
-
-  if (_wcontext._presentation_params.Windowed) {
-    POINT ul, lr;
-    RECT client_rect;
-
-    // need to figure out x, y origin offset of window client area on screen
-    // (we already know the client area size)
-
-    GetClientRect(_wcontext._window, &client_rect);
-    ul.x = client_rect.left;
-    ul.y = client_rect.top;
-    lr.x = client_rect.right;
-    lr.y = client_rect.bottom;
-    ClientToScreen(_wcontext._window, &ul);
-    ClientToScreen(_wcontext._window, &lr);
-    client_rect.left = ul.x;
-    client_rect.top = ul.y;
-    client_rect.right = lr.x;
-    client_rect.bottom = lr.y;
-  }
-
-  // clear window to black ASAP
-  nassertv(_wcontext._window != NULL);
-  ClearToBlack(_wcontext._window, get_properties());
-
-  // clear textures and VB's out of video&AGP mem, so cache is reset
-  hr = _wcontext._d3d_device->ResourceManagerDiscardBytes(0);
-  if (FAILED(hr)) {
-    wdxdisplay8_cat.error()
-      << "ResourceManagerDiscardBytes failed for device #"
-      << _wcontext._card_id << D3DERRORSTRING(hr);
-  }
-
-  make_current();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::D3DFMT_to_DepthBits
-//       Access: Private, Static
-//  Description: Returns the number of depth bits represented by the
-//               indicated D3DFORMAT value.
-////////////////////////////////////////////////////////////////////
-int wdxGraphicsWindow8::
-D3DFMT_to_DepthBits(D3DFORMAT fmt) {
-  switch(fmt) {
-  case D3DFMT_D16:
-    return 16;
-
-  case D3DFMT_D24X8:
-  case D3DFMT_D24X4S4:
-  case D3DFMT_D24S8:
-    return 24;
-
-  case D3DFMT_D32:
-    return 32;
-
-  case D3DFMT_D15S1:
-    return 15;
-
-  default:
-    wdxdisplay8_cat.debug()
-      << "D3DFMT_DepthBits: unhandled D3DFMT!\n";
-    return 0;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::is_badvidmem_card
-//       Access: Private, Static
-//  Description: Returns true if the indicated video adapter card is
-//               known to report an inaccurate figure for available
-//               video memory.
-////////////////////////////////////////////////////////////////////
-bool wdxGraphicsWindow8::
-is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID) {
-  // don't trust Intel cards since they often use regular memory as vidmem
-  if (pDevID->VendorId == 0x00008086) {
-    return true;
-  }
-
-  return false;
-}

+ 0 - 108
panda/src/dxgsg8/wdxGraphicsWindow8.h

@@ -1,108 +0,0 @@
-// Filename: wdxGraphicsWindow8.h
-// Created by:  mike (09Jan97)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef WDXGRAPHICSWINDOW8_H
-#define WDXGRAPHICSWINDOW8_H
-
-#include "pandabase.h"
-#include "winGraphicsWindow.h"
-#include "dxGraphicsStateGuardian8.h"
-#include "dxInput8.h"
-#include "wdxGraphicsPipe8.h"
-
-class wdxGraphicsPipe8;
-
-////////////////////////////////////////////////////////////////////
-//       Class : wdxGraphicsWindow8
-// Description : A single graphics window for rendering DirectX under
-//               Microsoft Windows.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDADX wdxGraphicsWindow8 : public WinGraphicsWindow {
-public:
-  wdxGraphicsWindow8(GraphicsEngine *engine, GraphicsPipe *pipe,
-                     const string &name,
-                     const FrameBufferProperties &fb_prop,
-                     const WindowProperties &win_prop,
-                     int flags,
-                     GraphicsStateGuardian *gsg,
-                     GraphicsOutput *host);
-  virtual ~wdxGraphicsWindow8();
-
-  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
-  virtual void end_frame(FrameMode mode, Thread *current_thread);
-  virtual void end_flip();
-
-  virtual int verify_window_sizes(int numsizes, int *dimen);
-
-protected:
-  virtual void close_window();
-  virtual bool open_window();
-  virtual void reset_window(bool swapchain);
-
-  virtual void fullscreen_restored(WindowProperties &properties);
-  virtual void handle_reshape();
-  virtual bool do_fullscreen_resize(int x_size, int y_size);
-
-private:
-  struct DXDeviceInfo {
-    UINT cardID;
-    char szDriver[MAX_DEVICE_IDENTIFIER_STRING];
-    char szDescription[MAX_DEVICE_IDENTIFIER_STRING];
-    GUID guidDeviceIdentifier;
-    DWORD VendorID, DeviceID;
-    HMONITOR _monitor;
-  };
-  typedef pvector<DXDeviceInfo> DXDeviceInfoVec;
-
-  bool create_screen_buffers_and_device(DXScreenData &display,
-                                        bool force_16bpp_zbuffer);
-
-  bool choose_device();
-  bool search_for_device(wdxGraphicsPipe8 *dxpipe, DXDeviceInfo *device_info);
-
-  bool reset_device_resize_window(UINT new_xsize, UINT new_ysize);
-  void init_resized_window();
-  void make_current();
-  static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
-  static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
-
-  DXGraphicsStateGuardian8 *_dxgsg;
-  DXScreenData _wcontext;
-
-  int _depth_buffer_bpp;
-  bool _awaiting_restore;
-
-public:
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    WinGraphicsWindow::init_type();
-    register_type(_type_handle, "wdxGraphicsWindow8",
-                  WinGraphicsWindow::get_class_type());
-  }
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-
-private:
-  static TypeHandle _type_handle;
-  friend class wdxGraphicsPipe8;
-};
-
-
-#include "wdxGraphicsWindow8.I"
-
-#endif

+ 0 - 2
panda/src/framework/Sources.pp

@@ -15,8 +15,6 @@
     #define LOCAL_LIBS pandagl $[LOCAL_LIBS]
     #define LOCAL_LIBS pandagl $[LOCAL_LIBS]
   #elif $[HAVE_DX9]
   #elif $[HAVE_DX9]
     #define LOCAL_LIBS pandadx9 $[LOCAL_LIBS]
     #define LOCAL_LIBS pandadx9 $[LOCAL_LIBS]
-  #elif $[HAVE_DX8]
-    #define LOCAL_LIBS pandadx8 $[LOCAL_LIBS]
   #elif $[HAVE_TINYDISPLAY]
   #elif $[HAVE_TINYDISPLAY]
     #define LOCAL_LIBS p3tinydisplay $[LOCAL_LIBS]
     #define LOCAL_LIBS p3tinydisplay $[LOCAL_LIBS]
   #endif
   #endif

+ 21 - 24
panda/src/framework/pandaFramework.cxx

@@ -37,7 +37,7 @@ LoaderOptions PandaFramework::_loader_options;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaFramework::Constructor
 //     Function: PandaFramework::Constructor
 //       Access: Public
 //       Access: Public
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PandaFramework::
 PandaFramework::
 PandaFramework() :
 PandaFramework() :
@@ -63,7 +63,7 @@ PandaFramework() :
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaFramework::Destructor
 //     Function: PandaFramework::Destructor
 //       Access: Public, Virtual
 //       Access: Public, Virtual
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PandaFramework::
 PandaFramework::
 ~PandaFramework() {
 ~PandaFramework() {
@@ -98,9 +98,6 @@ open_framework(int &argc, char **&argv) {
   #elif defined(HAVE_DX9)
   #elif defined(HAVE_DX9)
   extern EXPCL_PANDADX9 void init_libpandadx9();
   extern EXPCL_PANDADX9 void init_libpandadx9();
   init_libpandadx9();
   init_libpandadx9();
-  #elif defined(HAVE_DX8)
-  extern EXPCL_PANDADX8 void init_libpandadx8();
-  init_libpandadx8();
   #elif defined(HAVE_TINYDISPLAY)
   #elif defined(HAVE_TINYDISPLAY)
   extern EXPCL_TINYDISPLAY void init_libtinydisplay();
   extern EXPCL_TINYDISPLAY void init_libtinydisplay();
   init_libtinydisplay();
   init_libtinydisplay();
@@ -158,7 +155,7 @@ open_framework(int &argc, char **&argv) {
     PT(GenericAsyncTask) task = new GenericAsyncTask("play_frame", task_play_frame, this);
     PT(GenericAsyncTask) task = new GenericAsyncTask("play_frame", task_play_frame, this);
     task->set_sort(55);
     task->set_sort(55);
     _task_mgr.add(task);
     _task_mgr.add(task);
-    
+
   } else if (!record_session.empty()) {
   } else if (!record_session.empty()) {
     // If the config file so indicates, create a recorder and start it
     // If the config file so indicates, create a recorder and start it
     // recording.
     // recording.
@@ -168,7 +165,7 @@ open_framework(int &argc, char **&argv) {
     PT(GenericAsyncTask) task = new GenericAsyncTask("record_frame", task_record_frame, this);
     PT(GenericAsyncTask) task = new GenericAsyncTask("record_frame", task_record_frame, this);
     task->set_sort(45);
     task->set_sort(45);
     _task_mgr.add(task);
     _task_mgr.add(task);
-  } 
+  }
 
 
   _event_handler.add_hook("window-event", event_window_event, this);
   _event_handler.add_hook("window-event", event_window_event, this);
 }
 }
@@ -263,7 +260,7 @@ get_mouse(GraphicsOutput *window) {
     GraphicsWindow *win = DCAST(GraphicsWindow, window);
     GraphicsWindow *win = DCAST(GraphicsWindow, window);
     MouseAndKeyboard *mouse_node = new MouseAndKeyboard(win, 0, "mouse");
     MouseAndKeyboard *mouse_node = new MouseAndKeyboard(win, 0, "mouse");
     mouse = data_root.attach_new_node(mouse_node);
     mouse = data_root.attach_new_node(mouse_node);
-    
+
     RecorderController *recorder = get_recorder();
     RecorderController *recorder = get_recorder();
     if (recorder != (RecorderController *)NULL) {
     if (recorder != (RecorderController *)NULL) {
       // If we're in recording or playback mode, associate a recorder.
       // If we're in recording or playback mode, associate a recorder.
@@ -272,7 +269,7 @@ get_mouse(GraphicsOutput *window) {
       recorder->add_recorder("mouse", mouse_recorder);
       recorder->add_recorder("mouse", mouse_recorder);
     }
     }
   }
   }
-    
+
   _mouses[window] = mouse;
   _mouses[window] = mouse;
 
 
   return mouse;
   return mouse;
@@ -415,7 +412,7 @@ open_window(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) {
   if (window_type == "offscreen") {
   if (window_type == "offscreen") {
     flags = GraphicsPipe::BF_refuse_window;
     flags = GraphicsPipe::BF_refuse_window;
   }
   }
-  
+
   return open_window(props, flags, pipe, gsg);
   return open_window(props, flags, pipe, gsg);
 }
 }
 
 
@@ -449,7 +446,7 @@ open_window(const WindowProperties &props, int flags,
   wf->set_perpixel(get_perpixel());
   wf->set_perpixel(get_perpixel());
   wf->set_background_type(get_background_type());
   wf->set_background_type(get_background_type());
 
 
-  GraphicsOutput *win = wf->open_window(props, flags, get_graphics_engine(), 
+  GraphicsOutput *win = wf->open_window(props, flags, get_graphics_engine(),
                                         pipe, gsg);
                                         pipe, gsg);
   _engine->open_windows();
   _engine->open_windows();
   if (win != (GraphicsOutput *)NULL && !win->is_valid()) {
   if (win != (GraphicsOutput *)NULL && !win->is_valid()) {
@@ -523,7 +520,7 @@ close_window(int n) {
   if (win != (GraphicsOutput *)NULL) {
   if (win != (GraphicsOutput *)NULL) {
     _engine->remove_window(win);
     _engine->remove_window(win);
   }
   }
-  
+
   wf->close_window();
   wf->close_window();
   _windows.erase(_windows.begin() + n);
   _windows.erase(_windows.begin() + n);
 }
 }
@@ -544,7 +541,7 @@ close_all_windows() {
     if (win != (GraphicsOutput *)NULL) {
     if (win != (GraphicsOutput *)NULL) {
       _engine->remove_window(win);
       _engine->remove_window(win);
     }
     }
-    
+
     wf->close_window();
     wf->close_window();
   }
   }
 
 
@@ -602,7 +599,7 @@ void PandaFramework::
 report_frame_rate(ostream &out) const {
 report_frame_rate(ostream &out) const {
   double now = ClockObject::get_global_clock()->get_frame_time();
   double now = ClockObject::get_global_clock()->get_frame_time();
   double delta = now - _start_time;
   double delta = now - _start_time;
-  
+
   int frame_count = ClockObject::get_global_clock()->get_frame_count();
   int frame_count = ClockObject::get_global_clock()->get_frame_count();
   int num_frames = frame_count - _frame_count;
   int num_frames = frame_count - _frame_count;
   if (num_frames > 0) {
   if (num_frames > 0) {
@@ -959,7 +956,7 @@ clear_text() {
 //               window).
 //               window).
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PandaFramework::
 void PandaFramework::
-event_esc(const Event *event, void *data) { 
+event_esc(const Event *event, void *data) {
   if (event->get_num_parameters() == 1) {
   if (event->get_num_parameters() == 1) {
     EventParameter param = event->get_parameter(0);
     EventParameter param = event->get_parameter(0);
     WindowFramework *wf;
     WindowFramework *wf;
@@ -1227,7 +1224,7 @@ event_A(const Event *, void *data) {
 void PandaFramework::
 void PandaFramework::
 event_h(const Event *, void *data) {
 event_h(const Event *, void *data) {
   PandaFramework *self = (PandaFramework *)data;
   PandaFramework *self = (PandaFramework *)data;
-  
+
   if (self->has_highlight()) {
   if (self->has_highlight()) {
     self->clear_highlight();
     self->clear_highlight();
   } else {
   } else {
@@ -1290,7 +1287,7 @@ event_arrow_left(const Event *, void *data) {
       nassertv(index >= 0);
       nassertv(index >= 0);
       int sibling = index - 1;
       int sibling = index - 1;
 
 
-      if (sibling >= 0 && 
+      if (sibling >= 0 &&
           parent.node()->get_child(sibling) == self->_highlight_wireframe.node()) {
           parent.node()->get_child(sibling) == self->_highlight_wireframe.node()) {
         // Skip over the special highlight node.
         // Skip over the special highlight node.
         sibling--;
         sibling--;
@@ -1323,12 +1320,12 @@ event_arrow_right(const Event *, void *data) {
       int num_children = parent.node()->get_num_children();
       int num_children = parent.node()->get_num_children();
       int sibling = index + 1;
       int sibling = index + 1;
 
 
-      if (sibling < num_children && 
+      if (sibling < num_children &&
           parent.node()->get_child(sibling) == self->_highlight_wireframe.node()) {
           parent.node()->get_child(sibling) == self->_highlight_wireframe.node()) {
         // Skip over the special highlight node.
         // Skip over the special highlight node.
         sibling++;
         sibling++;
       }
       }
-      
+
       if (sibling < num_children) {
       if (sibling < num_children) {
         self->set_highlight(NodePath(parent, parent.node()->get_child(sibling)));
         self->set_highlight(NodePath(parent, parent.node()->get_child(sibling)));
       }
       }
@@ -1416,11 +1413,11 @@ event_comma(const Event *event, void *) {
     case WindowFramework::BT_other:
     case WindowFramework::BT_other:
     case WindowFramework::BT_none:
     case WindowFramework::BT_none:
       break;
       break;
-      
+
     case WindowFramework::BT_white:
     case WindowFramework::BT_white:
       wf->set_background_type(WindowFramework::BT_default);
       wf->set_background_type(WindowFramework::BT_default);
       break;
       break;
-      
+
     default:
     default:
       wf->set_background_type((WindowFramework::BackgroundType)(wf->get_background_type() + 1));
       wf->set_background_type((WindowFramework::BackgroundType)(wf->get_background_type() + 1));
     }
     }
@@ -1450,8 +1447,8 @@ event_question(const Event *event, void *data) {
       // Build up a string to display.
       // Build up a string to display.
       ostringstream help;
       ostringstream help;
       KeyDefinitions::const_iterator ki;
       KeyDefinitions::const_iterator ki;
-      for (ki = self->_key_definitions.begin(); 
-           ki != self->_key_definitions.end(); 
+      for (ki = self->_key_definitions.begin();
+           ki != self->_key_definitions.end();
            ++ki) {
            ++ki) {
         const KeyDefinition &keydef = (*ki);
         const KeyDefinition &keydef = (*ki);
         help << keydef._event_name << "\t" << keydef._description << "\n";
         help << keydef._event_name << "\t" << keydef._description << "\n";
@@ -1513,7 +1510,7 @@ event_window_event(const Event *event, void *data) {
           self->close_window(window_index);
           self->close_window(window_index);
           window_index = self->find_window(win);
           window_index = self->find_window(win);
         }
         }
-        
+
         // Free up the mouse for that window.
         // Free up the mouse for that window.
         self->remove_mouse(win);
         self->remove_mouse(win);
 
 

+ 3 - 3
panda/src/windisplay/Sources.pp

@@ -6,14 +6,14 @@
 
 
 #define BUILDING_DLL BUILDING_PANDAWIN
 #define BUILDING_DLL BUILDING_PANDAWIN
 
 
-#define USE_PACKAGES dx8 dx9
+#define USE_PACKAGES dx9
 
 
 #begin lib_target
 #begin lib_target
   #define TARGET p3windisplay
   #define TARGET p3windisplay
   #define LOCAL_LIBS \
   #define LOCAL_LIBS \
     p3display p3putil
     p3display p3putil
     
     
-  #define COMBINED_SOURCES $[TARGET]_composite1.cxx winDetectDx9.cxx winDetectDx8.cxx
+  #define COMBINED_SOURCES $[TARGET]_composite1.cxx winDetectDx9.cxx
 
 
   #define SOURCES \
   #define SOURCES \
      config_windisplay.h \
      config_windisplay.h \
@@ -30,7 +30,7 @@
   #define INCLUDED_SOURCES \
   #define INCLUDED_SOURCES \
      config_windisplay.cxx winGraphicsPipe.cxx \
      config_windisplay.cxx winGraphicsPipe.cxx \
      winGraphicsWindow.cxx \
      winGraphicsWindow.cxx \
-     winDetectDx9.cxx winDetectDx8.cxx
+     winDetectDx9.cxx
 
 
   #define WIN_SYS_LIBS Imm32.lib winmm.lib kernel32.lib oldnames.lib user32.lib gdi32.lib
   #define WIN_SYS_LIBS Imm32.lib winmm.lib kernel32.lib oldnames.lib user32.lib gdi32.lib
 
 

+ 29 - 76
panda/src/windisplay/winDetectDx.h

@@ -38,10 +38,7 @@ static DISPLAY_FORMAT display_format_array [ ] = {
   D3DFMT_R5G6B5,      16, FALSE,
   D3DFMT_R5G6B5,      16, FALSE,
   D3DFMT_X1R5G5B5,    16, FALSE,
   D3DFMT_X1R5G5B5,    16, FALSE,
 
 
-#if DX8 
-#else
   D3DFMT_A2R10G10B10, 32, TRUE,
   D3DFMT_A2R10G10B10, 32, TRUE,
-#endif
 
 
   // terminator
   // terminator
   D3DFMT_UNKNOWN,      0, FALSE,
   D3DFMT_UNKNOWN,      0, FALSE,
@@ -226,7 +223,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           get_adapter_display_mode_state = true;
           get_adapter_display_mode_state = true;
         }
         }
         else {
         else {
-          get_adapter_display_mode_state = false;    
+          get_adapter_display_mode_state = false;
         }
         }
 
 
         flags = 0;
         flags = 0;
@@ -234,10 +231,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           // print adapter info
           // print adapter info
           d3d_adapter_identifier.Driver;
           d3d_adapter_identifier.Driver;
           d3d_adapter_identifier.Description;
           d3d_adapter_identifier.Description;
-          #if DX8 
-          #else
           d3d_adapter_identifier.DeviceName;
           d3d_adapter_identifier.DeviceName;
-          #endif
           d3d_adapter_identifier.DriverVersion;
           d3d_adapter_identifier.DriverVersion;
           d3d_adapter_identifier.VendorId;
           d3d_adapter_identifier.VendorId;
           d3d_adapter_identifier.DeviceId;
           d3d_adapter_identifier.DeviceId;
@@ -245,12 +239,12 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           d3d_adapter_identifier.Revision;
           d3d_adapter_identifier.Revision;
           d3d_adapter_identifier.DeviceIdentifier;
           d3d_adapter_identifier.DeviceIdentifier;
           d3d_adapter_identifier.WHQLLevel;
           d3d_adapter_identifier.WHQLLevel;
-          
+
           if (debug) {
           if (debug) {
             printf ("Driver: %s\n", d3d_adapter_identifier.Driver);
             printf ("Driver: %s\n", d3d_adapter_identifier.Driver);
             printf ("Description: %s\n", d3d_adapter_identifier.Description);
             printf ("Description: %s\n", d3d_adapter_identifier.Description);
           }
           }
-          
+
           char system_directory [MAX_PATH];
           char system_directory [MAX_PATH];
           char dll_file_path [MAX_PATH];
           char dll_file_path [MAX_PATH];
 
 
@@ -338,9 +332,6 @@ static int get_display_information (DisplaySearchParameters &display_search_para
 
 
         if (direct_3d -> GetDeviceCaps (adapter, device_type, &d3d_caps) == D3D_OK) {
         if (direct_3d -> GetDeviceCaps (adapter, device_type, &d3d_caps) == D3D_OK) {
 
 
-#if DX8
-          // shaders not supported in DX8
-#else
           int vertex_shader_version_major;
           int vertex_shader_version_major;
           int vertex_shader_version_minor;
           int vertex_shader_version_minor;
           int pixel_shader_version_major;
           int pixel_shader_version_major;
@@ -374,7 +365,6 @@ static int get_display_information (DisplaySearchParameters &display_search_para
               shader_model = GraphicsStateGuardian::SM_40;
               shader_model = GraphicsStateGuardian::SM_40;
               break;
               break;
           }
           }
-#endif
 
 
           if (debug) {
           if (debug) {
             printf ("shader_model = %d \n", shader_model);
             printf ("shader_model = %d \n", shader_model);
@@ -394,35 +384,26 @@ static int get_display_information (DisplaySearchParameters &display_search_para
         format_index = 0;
         format_index = 0;
         maximum_display_modes = 0;
         maximum_display_modes = 0;
 
 
-        while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) {      
+        while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) {
           d3d_format = display_format_array [format_index].d3d_format;
           d3d_format = display_format_array [format_index].d3d_format;
 
 
-#if DX8
-          display_mode_count = direct_3d -> GetAdapterModeCount (adapter);
-#else
           display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format);
           display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format);
-#endif
           if (display_mode_count > 0) {
           if (display_mode_count > 0) {
             UINT mode_index;
             UINT mode_index;
             D3DDISPLAYMODE d3d_display_mode;
             D3DDISPLAYMODE d3d_display_mode;
 
 
             for (mode_index = 0; mode_index < display_mode_count; mode_index++) {
             for (mode_index = 0; mode_index < display_mode_count; mode_index++) {
-#if DX8
-              if (direct_3d -> EnumAdapterModes (adapter, mode_index, &d3d_display_mode) == D3D_OK)
-#else
-              if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK)
-#endif          
-              {
+              if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK) {
                 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height &&
                 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height &&
-                    d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) {                  
+                    d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) {
                   if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel &&
                   if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel &&
-                      display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) {                
+                      display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) {
                     if (d3d_format == d3d_display_mode.Format) {
                     if (d3d_format == d3d_display_mode.Format) {
-                      maximum_display_modes++;                
+                      maximum_display_modes++;
                     }
                     }
                   }
                   }
                 }
                 }
-              }            
+              }
             }
             }
           }
           }
 
 
@@ -436,26 +417,17 @@ static int get_display_information (DisplaySearchParameters &display_search_para
         display_mode_array = new DisplayMode [maximum_display_modes];
         display_mode_array = new DisplayMode [maximum_display_modes];
 
 
         format_index = 0;
         format_index = 0;
-        while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) {      
+        while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) {
           d3d_format = display_format_array [format_index].d3d_format;
           d3d_format = display_format_array [format_index].d3d_format;
-#if DX8
-          display_mode_count = direct_3d -> GetAdapterModeCount (adapter);
-#else
           display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format);
           display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format);
-#endif      
           if (display_mode_count > 0) {
           if (display_mode_count > 0) {
             UINT mode_index;
             UINT mode_index;
             D3DDISPLAYMODE d3d_display_mode;
             D3DDISPLAYMODE d3d_display_mode;
 
 
             for (mode_index = 0; mode_index < display_mode_count; mode_index++) {
             for (mode_index = 0; mode_index < display_mode_count; mode_index++) {
-#if DX8
-              if (direct_3d -> EnumAdapterModes (adapter, mode_index, &d3d_display_mode) == D3D_OK)
-#else
-              if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK)
-#endif          
-              {
+              if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK) {
                 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height &&
                 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height &&
-                    d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) {                  
+                    d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) {
                   if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel &&
                   if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel &&
                       display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) {
                       display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) {
                     if (debug) {
                     if (debug) {
@@ -515,7 +487,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           direct_3d_device = 0;
           direct_3d_device = 0;
           memset (&present_parameters, 0, sizeof (D3DPRESENT_PARAMETERS));
           memset (&present_parameters, 0, sizeof (D3DPRESENT_PARAMETERS));
 
 
-          present_parameters.BackBufferWidth = width; 
+          present_parameters.BackBufferWidth = width;
           present_parameters.BackBufferHeight = height;
           present_parameters.BackBufferHeight = height;
           present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
           present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
           present_parameters.BackBufferCount = 1;
           present_parameters.BackBufferCount = 1;
@@ -528,11 +500,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
           present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
 
 
           present_parameters.FullScreen_RefreshRateInHz;
           present_parameters.FullScreen_RefreshRateInHz;
-
-#if DX8
-#else
           present_parameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
           present_parameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
-#endif
 
 
           if (d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
           if (d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
             behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
             behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
@@ -546,32 +514,18 @@ static int get_display_information (DisplaySearchParameters &display_search_para
           HRESULT result;
           HRESULT result;
 
 
           result = direct_3d -> CreateDevice (adapter, device_type, window_handle, behavior_flags, &present_parameters, &direct_3d_device);
           result = direct_3d -> CreateDevice (adapter, device_type, window_handle, behavior_flags, &present_parameters, &direct_3d_device);
-          if (result == D3D_OK) {  
+          if (result == D3D_OK) {
 
 
-            // allocate 512x512 32-bit textures (1MB size) until we run out or hit the limit            
+            // allocate 512x512 32-bit textures (1MB size) until we run out or hit the limit
             #define MAXIMUM_TEXTURES (2048 - 1)
             #define MAXIMUM_TEXTURES (2048 - 1)
-            
+
             int total_textures;
             int total_textures;
-            HRESULT texture_result; 
-            #if DX8
-            IDirect3DTexture8 *texture_array [MAXIMUM_TEXTURES];
-            #else
+            HRESULT texture_result;
             IDirect3DTexture9 *texture_array [MAXIMUM_TEXTURES];
             IDirect3DTexture9 *texture_array [MAXIMUM_TEXTURES];
-            #endif
-            
+
             total_textures = 0;
             total_textures = 0;
             while (total_textures < MAXIMUM_TEXTURES) {
             while (total_textures < MAXIMUM_TEXTURES) {
 
 
-              #if DX8
-              texture_result = direct_3d_device -> CreateTexture (
-                512,
-                512,
-                1,
-                D3DUSAGE_RENDERTARGET,
-                D3DFMT_A8R8G8B8,
-                D3DPOOL_DEFAULT,
-                &texture_array [total_textures]);
-              #else
               texture_result = direct_3d_device -> CreateTexture (
               texture_result = direct_3d_device -> CreateTexture (
                 512,
                 512,
                 512,
                 512,
@@ -581,28 +535,27 @@ static int get_display_information (DisplaySearchParameters &display_search_para
                 D3DPOOL_DEFAULT,
                 D3DPOOL_DEFAULT,
                 &texture_array [total_textures],
                 &texture_array [total_textures],
                 NULL);
                 NULL);
-              #endif
-              if (texture_result == D3D_OK) {                
+              if (texture_result == D3D_OK) {
                 total_textures++;
                 total_textures++;
               }
               }
               else {
               else {
                 if (texture_result == D3DERR_OUTOFVIDEOMEMORY) {
                 if (texture_result == D3DERR_OUTOFVIDEOMEMORY) {
                   if (debug) {
                   if (debug) {
                     printf ("D3DERR_OUTOFVIDEOMEMORY \n");
                     printf ("D3DERR_OUTOFVIDEOMEMORY \n");
-                  }                
-                }                
+                  }
+                }
                 break;
                 break;
-              }               
+              }
             }
             }
 
 
             // free all allocated textures
             // free all allocated textures
-            int index;           
+            int index;
             for (index = 0; index < total_textures; index++) {
             for (index = 0; index < total_textures; index++) {
-              texture_array [index] -> Release ( );            
+              texture_array [index] -> Release ( );
             }
             }
 
 
             video_memory = (total_textures * 1024 * 1024);
             video_memory = (total_textures * 1024 * 1024);
-            
+
             if (debug) {
             if (debug) {
               printf ("video_memory = %d \n", video_memory);
               printf ("video_memory = %d \n", video_memory);
             }
             }
@@ -612,9 +565,9 @@ static int get_display_information (DisplaySearchParameters &display_search_para
               printf ("texture_memory = %d \n", texture_memory);
               printf ("texture_memory = %d \n", texture_memory);
             }
             }
 
 
-            direct_3d_device -> Release ( );    
+            direct_3d_device -> Release ( );
 
 
-            state = DisplayInformation::DS_success;    
+            state = DisplayInformation::DS_success;
             success = true;
             success = true;
           }
           }
           else
           else
@@ -623,7 +576,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
               printf ("CreateDevice failed.\n");
               printf ("CreateDevice failed.\n");
             }
             }
 
 
-            state = DisplayInformation::DS_create_device_error;    
+            state = DisplayInformation::DS_create_device_error;
             success = true;
             success = true;
           }
           }
 
 
@@ -641,7 +594,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
       }
       }
     }
     }
     else {
     else {
-      state = DisplayInformation::DS_direct_3d_create_error;  
+      state = DisplayInformation::DS_direct_3d_create_error;
     }
     }
 
 
     FreeLibrary (d3d_dll);
     FreeLibrary (d3d_dll);

+ 0 - 48
panda/src/windisplay/winDetectDx8.cxx

@@ -1,48 +0,0 @@
-// Filename: winDetectDx8.cxx
-// Created by:  aignacio (18Jan07)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) Carnegie Mellon University.  All rights reserved.
-//
-// All use of this software is subject to the terms of the revised BSD
-// license.  You should have received a copy of this license along
-// with this source code in a file named "LICENSE."
-//
-////////////////////////////////////////////////////////////////////
-
-#include "pandabase.h"
-
-#ifdef HAVE_DX8
-
-#define WIN32_LEAN_AND_MEAN
-#include <d3d8.h>
-#include "graphicsStateGuardian.h"
-#include "graphicsPipe.h"
-#include "displaySearchParameters.h"
-
-
-#define DX8 1
-#define Direct3DCreate Direct3DCreate8
-
-typedef LPDIRECT3D8 (WINAPI *DIRECT3DCREATE8)(UINT SDKVersion);
-typedef LPDIRECT3D8 DIRECT_3D;
-typedef D3DCAPS8 D3DCAPS;
-typedef D3DADAPTER_IDENTIFIER8 D3DADAPTER_IDENTIFIER;
-typedef LPDIRECT3DDEVICE8 DIRECT_3D_DEVICE;
-typedef DIRECT3DCREATE8 DIRECT_3D_CREATE;
-
-static char *d3d_dll_name = "d3d8.dll";
-static char *direct_3d_create_function_name = "Direct3DCreate8";
-
-
-// include common source code
-#include "winDetectDx.h"
-
-
-int dx8_display_information (DisplaySearchParameters &display_search_parameters, DisplayInformation *display_information) {
-  return get_display_information (display_search_parameters, display_information);
-}
-
-#endif

+ 0 - 1
panda/src/windisplay/winDetectDx9.cxx

@@ -22,7 +22,6 @@
 #include "graphicsPipe.h"
 #include "graphicsPipe.h"
 #include "displaySearchParameters.h"
 #include "displaySearchParameters.h"
 
 
-#define DX8 0
 #define Direct3DCreate Direct3DCreate9
 #define Direct3DCreate Direct3DCreate9
 
 
 typedef LPDIRECT3D9 (WINAPI *DIRECT3DCREATE9)(UINT SDKVersion);
 typedef LPDIRECT3D9 (WINAPI *DIRECT3DCREATE9)(UINT SDKVersion);

+ 14 - 25
panda/src/windisplay/winGraphicsPipe.cxx

@@ -758,7 +758,7 @@ count_number_of_cpus(DisplayInformation *display_information) {
       if (buffer != NULL) {
       if (buffer != NULL) {
         PANDA_FREE_ARRAY(buffer);
         PANDA_FREE_ARRAY(buffer);
       }
       }
-      
+
       buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)PANDA_MALLOC_ARRAY(buffer_length);
       buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)PANDA_MALLOC_ARRAY(buffer_length);
       nassertv(buffer != NULL);
       nassertv(buffer != NULL);
     } else {
     } else {
@@ -777,7 +777,7 @@ count_number_of_cpus(DisplayInformation *display_information) {
   while (ptr < end) {
   while (ptr < end) {
     if (ptr->Relationship == RelationProcessorCore) {
     if (ptr->Relationship == RelationProcessorCore) {
       num_cpu_cores++;
       num_cpu_cores++;
-      
+
       // A hyperthreaded core supplies more than one logical processor.
       // A hyperthreaded core supplies more than one logical processor.
       num_logical_cpus += count_bits_in_word((PN_uint64)(ptr->ProcessorMask));
       num_logical_cpus += count_bits_in_word((PN_uint64)(ptr->ProcessorMask));
     }
     }
@@ -798,14 +798,14 @@ count_number_of_cpus(DisplayInformation *display_information) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinGraphicsPipe::Constructor
 //     Function: WinGraphicsPipe::Constructor
 //       Access: Public
 //       Access: Public
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WinGraphicsPipe::
 WinGraphicsPipe::
 WinGraphicsPipe() {
 WinGraphicsPipe() {
 
 
   bool state;
   bool state;
   char string [512];
   char string [512];
-  
+
   state = false;
   state = false;
   _supported_types = OT_window | OT_fullscreen_window;
   _supported_types = OT_window | OT_fullscreen_window;
 
 
@@ -815,7 +815,7 @@ WinGraphicsPipe() {
 
 
   _hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
   _hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
   if (_hUser32 != NULL) {
   if (_hUser32 != NULL) {
-    _pfnTrackMouseEvent = 
+    _pfnTrackMouseEvent =
       (PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent");
       (PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent");
   }
   }
 
 
@@ -830,17 +830,6 @@ WinGraphicsPipe() {
   }
   }
 #endif
 #endif
 
 
-#ifdef HAVE_DX8
-  if (request_dxdisplay_information){
-    DisplaySearchParameters display_search_parameters_dx8;
-    int dx8_display_information (DisplaySearchParameters &display_search_parameters_dx8, DisplayInformation *display_information);
-    
-    if (state == false && dx8_display_information (display_search_parameters_dx8, _display_information)) {
-      state = true;    
-    }
-  }
-#endif
-
   if (auto_cpu_data) {
   if (auto_cpu_data) {
     lookup_cpu_data();
     lookup_cpu_data();
   }
   }
@@ -852,32 +841,32 @@ WinGraphicsPipe() {
     sprintf (string, "OS version: %d.%d.%d.%d \n", version_info.dwMajorVersion, version_info.dwMinorVersion, version_info.dwPlatformId, version_info.dwBuildNumber);
     sprintf (string, "OS version: %d.%d.%d.%d \n", version_info.dwMajorVersion, version_info.dwMinorVersion, version_info.dwPlatformId, version_info.dwBuildNumber);
     windisplay_cat.info() << string;
     windisplay_cat.info() << string;
     windisplay_cat.info() << "  " << version_info.szCSDVersion << "\n";
     windisplay_cat.info() << "  " << version_info.szCSDVersion << "\n";
-    
+
     _display_information -> _os_version_major = version_info.dwMajorVersion;
     _display_information -> _os_version_major = version_info.dwMajorVersion;
     _display_information -> _os_version_minor = version_info.dwMinorVersion;
     _display_information -> _os_version_minor = version_info.dwMinorVersion;
-    _display_information -> _os_version_build = version_info.dwBuildNumber;     
+    _display_information -> _os_version_build = version_info.dwBuildNumber;
     _display_information -> _os_platform_id = version_info.dwPlatformId;
     _display_information -> _os_platform_id = version_info.dwPlatformId;
   }
   }
   // Screen size
   // Screen size
   _display_width = GetSystemMetrics(SM_CXSCREEN);
   _display_width = GetSystemMetrics(SM_CXSCREEN);
   _display_height = GetSystemMetrics(SM_CYSCREEN);
   _display_height = GetSystemMetrics(SM_CYSCREEN);
-  
+
   HMODULE power_dll;
   HMODULE power_dll;
 
 
   power_dll = LoadLibrary ("PowrProf.dll");
   power_dll = LoadLibrary ("PowrProf.dll");
-  if (power_dll) {    
+  if (power_dll) {
     CallNtPowerInformationFunction = (CallNtPowerInformationType) GetProcAddress (power_dll, "CallNtPowerInformation");
     CallNtPowerInformationFunction = (CallNtPowerInformationType) GetProcAddress (power_dll, "CallNtPowerInformation");
-    if (CallNtPowerInformationFunction) {    
-    
+    if (CallNtPowerInformationFunction) {
+
       _display_information -> _update_cpu_frequency_function = update_cpu_frequency_function;
       _display_information -> _update_cpu_frequency_function = update_cpu_frequency_function;
       update_cpu_frequency_function(0, _display_information);
       update_cpu_frequency_function(0, _display_information);
 
 
-      sprintf (string, "max Mhz %I64d, current Mhz %I64d \n", _display_information -> _maximum_cpu_frequency, _display_information -> _current_cpu_frequency);     
+      sprintf (string, "max Mhz %I64d, current Mhz %I64d \n", _display_information -> _maximum_cpu_frequency, _display_information -> _current_cpu_frequency);
 
 
-      windisplay_cat.info() << string;    
+      windisplay_cat.info() << string;
     }
     }
   }
   }
-  
+
   if (state) {
   if (state) {
 
 
   }
   }

+ 0 - 1
pandatool/src/scripts/builder.cshrc

@@ -38,7 +38,6 @@ alias setbrowseinfo1 setenv CL_MAKE_BROWSE_INFO 1
 alias setbrowseinfo0 setenv CL_MAKE_BROWSE_INFO 0
 alias setbrowseinfo0 setenv CL_MAKE_BROWSE_INFO 0
 
 
 setenv HAVE_GL yes
 setenv HAVE_GL yes
-setenv HAVE_DX8 yes
 setenv HAVE_DX9 yes
 setenv HAVE_DX9 yes
 setenv USE_NSPR t
 setenv USE_NSPR t