Browse Source

fix nvidia 16bpp depth prob

georges 25 years ago
parent
commit
0067eb1d46
1 changed files with 46 additions and 43 deletions
  1. 46 43
      panda/src/wdxdisplay/wdxGraphicsWindow.cxx

+ 46 - 43
panda/src/wdxdisplay/wdxGraphicsWindow.cxx

@@ -1,26 +1,14 @@
-// Filename: wdxGraphicsWindow.cxx  
+// Filename: wdxGraphicsWindow.cxx
 // Created by:  mike (09Jan00)
 // Created by:  mike (09Jan00)
 //
 //
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-// Copyright (C) 1999-2000
-// Walt Disney Imagineering, Inc.
-//
-// These  coded  instructions,  statements,  data   structures   and
-// computer  programs contain unpublished proprietary information of
-// Walt Disney Imagineering and are protected by  Federal  copyright
-// law.  They may  not be  disclosed to third  parties  or copied or
-// duplicated in any form, in whole or in part,  without  the  prior
-// written consent of Walt Disney Imagineering Inc.
-////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////
 // Includes
 // Includes
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 #ifndef STRICT
 #ifndef STRICT
 #define STRICT
 #define STRICT
 #endif
 #endif
 #define D3D_OVERLOADS
 #define D3D_OVERLOADS
-#define  INITGUID
+//#define  INITGUID  dont need this if linking w/dxguid.lib
 #include <d3d.h>
 #include <d3d.h>
 #include "wdxGraphicsWindow.h"
 #include "wdxGraphicsWindow.h"
 #include "wdxGraphicsPipe.h"
 #include "wdxGraphicsPipe.h"
@@ -1077,13 +1065,12 @@ void wdxGraphicsWindow::config(void) {
   RECT win_rect;
   RECT win_rect;
   SetRect(&win_rect, _props._xorg,  _props._yorg, _props._xorg + _props._xsize, 
   SetRect(&win_rect, _props._xorg,  _props._yorg, _props._xorg + _props._xsize, 
 				 _props._yorg + _props._ysize);
 				 _props._yorg + _props._ysize);
-  HWND desktop = GetDesktopWindow();
 
 
   // rect now contains the coords for the entire window, not the client
   // rect now contains the coords for the entire window, not the client
   if (dx_full_screen) {
   if (dx_full_screen) {
 	  _mwindow = CreateWindow("wdxDisplay", _props._title.c_str(),
 	  _mwindow = CreateWindow("wdxDisplay", _props._title.c_str(),
                               WS_POPUP, 0, 0, _props._xsize,_props._ysize,
                               WS_POPUP, 0, 0, _props._xsize,_props._ysize,
-                              desktop, NULL, hinstance, 0);
+                              NULL, NULL, hinstance, 0);
   } else  {
   } else  {
 	  if (_props._border)
 	  if (_props._border)
 		    style = WS_OVERLAPPEDWINDOW; 
 		    style = WS_OVERLAPPEDWINDOW; 
@@ -1099,7 +1086,7 @@ void wdxGraphicsWindow::config(void) {
 	  _mwindow = CreateWindow("wdxDisplay", _props._title.c_str(),
 	  _mwindow = CreateWindow("wdxDisplay", _props._title.c_str(),
 		style, win_rect.left, win_rect.top, win_rect.right-win_rect.left, 
 		style, win_rect.left, win_rect.top, win_rect.right-win_rect.left, 
 		win_rect.bottom-win_rect.top,
 		win_rect.bottom-win_rect.top,
-		desktop, NULL, hinstance, 0);
+		NULL, NULL, hinstance, 0);
   }
   }
 
 
   if (!_mwindow) {
   if (!_mwindow) {
@@ -1132,8 +1119,8 @@ void wdxGraphicsWindow::config(void) {
     GraphicsWindowInputDevice::pointer_and_keyboard("keyboard/mouse");
     GraphicsWindowInputDevice::pointer_and_keyboard("keyboard/mouse");
   _input_devices.push_back(device);
   _input_devices.push_back(device);
 
 
-    ShowWindow(_mwindow, SW_SHOWNORMAL);
-    ShowWindow(_mwindow, SW_SHOWNORMAL);
+  ShowWindow(_mwindow, SW_SHOWNORMAL);
+  ShowWindow(_mwindow, SW_SHOWNORMAL);  // call twice to override STARTUPINFO value, which may be set to hidden initially by emacs
 //  UpdateWindow( _mwindow );
 //  UpdateWindow( _mwindow );
 }
 }
 
 
@@ -1204,12 +1191,17 @@ dx_setup()
     
     
       FreeLibrary(DDHinst);  //undo LoadLib above, decrement ddrawl.dll refcnt (after DDrawCreate, since dont want to unload/reload)
       FreeLibrary(DDHinst);  //undo LoadLib above, decrement ddrawl.dll refcnt (after DDrawCreate, since dont want to unload/reload)
     
     
-#ifdef _DEBUG
+
       DDDEVICEIDENTIFIER2 dddi;
       DDDEVICEIDENTIFIER2 dddi;
       pDD->GetDeviceIdentifier(&dddi,0x0);
       pDD->GetDeviceIdentifier(&dddi,0x0);
+
+#ifdef _DEBUG
       wdxdisplay_cat.debug()
       wdxdisplay_cat.debug()
-          << " GfxCard: " << dddi.szDescription <<  "; DriverVer: " << HIWORD(dddi.liDriverVersion.HighPart) << "." << LOWORD(dddi.liDriverVersion.HighPart) << "." << HIWORD(dddi.liDriverVersion.LowPart) << "." << LOWORD(dddi.liDriverVersion.LowPart) << endl;
+          << " GfxCard: " << dddi.szDescription <<  "; VendorID: " <<dddi.dwVendorId <<"; DriverVer: " << HIWORD(dddi.liDriverVersion.HighPart) << "." << LOWORD(dddi.liDriverVersion.HighPart) << "." << HIWORD(dddi.liDriverVersion.LowPart) << "." << LOWORD(dddi.liDriverVersion.LowPart) << endl;
 #endif
 #endif
+
+      // imperfect method to ID NVid, could also scan desc str, but that isnt fullproof either
+      BOOL bIsNvidia = (dddi.dwVendorId==4318) || (dddi.dwVendorId==4818);  
     
     
       // Query DirectDraw for access to Direct3D
       // Query DirectDraw for access to Direct3D
     
     
@@ -1357,9 +1349,7 @@ dx_setup()
 #endif
 #endif
 
 
 	    // Setup to create the primary surface w/backbuffer
 	    // Setup to create the primary surface w/backbuffer
-	    DDSURFACEDESC2 ddsd;
-	    ZeroMemory( &ddsd, sizeof(ddsd) );
-	    ddsd.dwSize            = sizeof(ddsd);
+	    DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd)
 	    ddsd.dwFlags           = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
 	    ddsd.dwFlags           = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
 	    ddsd.ddsCaps.dwCaps    = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE |
 	    ddsd.ddsCaps.dwCaps    = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE |
 	                             DDSCAPS_FLIP | DDSCAPS_COMPLEX;
 	                             DDSCAPS_FLIP | DDSCAPS_COMPLEX;
@@ -1503,30 +1493,43 @@ dx_setup()
         }
         }
     #endif
     #endif
     
     
-        {
+        LPDDPIXELFORMAT pCurPixFmt,pz16=NULL,pz24=NULL,pz32=NULL;
+        for(i=0,pCurPixFmt=ZBufPixFmts;i<cNumZBufFmts;i++,pCurPixFmt++) {
+            switch(pCurPixFmt->dwRGBBitCount) {
+               case 16:
+                  if(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER))
+                      pz16=pCurPixFmt;
+                  break;
+               case 24:
+                  assert(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER));  // shouldnt be stencil at 24bpp
+                  pz24=pCurPixFmt;
+                  break;
+               case 32:
+                  if(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER))
+                      pz32=pCurPixFmt;
+                  break;
+            }
+        }
+    
+        if(bIsNvidia) {	    
+            DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_pri)
+            pPrimaryDDSurf->GetSurfaceDesc(&ddsd_pri);
+
+            // must pick zbuf depth to match primary surface depth for nvidia
+            if(ddsd_pri.ddpfPixelFormat.dwRGBBitCount==16) {
+                assert(pz16!=NULL);
+                ddsd.ddpfPixelFormat = *pz16;                
+            } else {
+                assert(pz24!=NULL);
+                ddsd.ddpfPixelFormat = *pz24;  //take the no-stencil version of the 32-bit Zbuf
+            }
+        } else {
             // pick the largest non-stencil zbuffer format avail (wont support stenciling
             // pick the largest non-stencil zbuffer format avail (wont support stenciling
             // until we definitely need it).  Note: this is choosing to waste memory
             // until we definitely need it).  Note: this is choosing to waste memory
             // and possibly perf for more accuracy at long distance (std 16bpp would be smaller/
             // and possibly perf for more accuracy at long distance (std 16bpp would be smaller/
             // maybe faster)
             // maybe faster)
         
         
-            LPDDPIXELFORMAT pCurPixFmt,pz16=NULL,pz24=NULL,pz32=NULL;
-            for(i=0,pCurPixFmt=ZBufPixFmts;i<cNumZBufFmts;i++,pCurPixFmt++) {
-                switch(pCurPixFmt->dwRGBBitCount) {
-                   case 16:
-                      if(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER))
-                          pz16=pCurPixFmt;
-                      break;
-                   case 24:
-                      assert(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER));  // shouldnt be stencil at 24bpp
-                      pz24=pCurPixFmt;
-                      break;
-                   case 32:
-                      if(!(pCurPixFmt->dwFlags & DDPF_STENCILBUFFER))
-                          pz32=pCurPixFmt;
-                      break;
-                }
-            }
-        
+
             if(pz32!=NULL) {
             if(pz32!=NULL) {
                 ddsd.ddpfPixelFormat = *pz32;
                 ddsd.ddpfPixelFormat = *pz32;
             } else if(pz24!=NULL) {
             } else if(pz24!=NULL) {