浏览代码

add get_depth_bitwidth

cxgeorge 24 年之前
父节点
当前提交
e0bc027a90

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

@@ -626,6 +626,12 @@ verify_window_sizes(unsigned int numsizes,unsigned int *dimen) {
   return numsizes;
 }
 
+int GraphicsWindow::
+get_depth_bitwidth(void) {
+    display_cat.warning() << "get_depth_bitwidth() unimplemented by " << get_type() << endl; 
+    return -1;
+}
+
 void GraphicsWindow::deactivate_window(void) { return; }
 void GraphicsWindow::reactivate_window(void) { return; }
 

+ 2 - 0
panda/src/display/graphicsWindow.h

@@ -112,6 +112,8 @@ PUBLISHED:
   INLINE int get_xorg() const;
   INLINE int get_yorg() const;
 
+  virtual int get_depth_bitwidth(void);  // # of z bits/pixel
+
   INLINE GraphicsStateGuardian *get_gsg() const;
   INLINE GraphicsPipe *get_pipe() const;
 

+ 28 - 13
panda/src/wdxdisplay/wdxGraphicsWindow.cxx

@@ -332,7 +332,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
             if(!((wparam=='V') && (GetKeyState(VK_CONTROL) < 0))) {
                handle_keypress(lookup_key(wparam), point.x, point.y);
             } else {
-                HGLOBAL   hglb; 
+                HGLOBAL hglb; 
                 char    *lptstr; 
             
                 if (!IsClipboardFormatAvailable(CF_TEXT)) 
@@ -1794,23 +1794,24 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD
             exit(1);
         }
 
+        #define SET_ZBUF_DEPTH(DEPTH) { assert(pz##DEPTH != NULL); _depth_buffer_bpp=DEPTH; ddsd.ddpfPixelFormat = *pz##DEPTH;}
+
         if(IS_NVIDIA(_DXDeviceID)) {
            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;
+                SET_ZBUF_DEPTH(16);
             } else {
                 if(dx_force_16bpp_zbuffer) {
                     wdxdisplay_cat.fatal() << "'dx-force-16bpp-zbuffer #t' requires a 16bpp desktop on nvidia cards\n";
                     exit(1);
                 }
                 // take the smaller of 24 or 32.  (already assured to match stencil capability)
-                if(pz24!=NULL)
-                    ddsd.ddpfPixelFormat = *pz24; 
-                  else ddsd.ddpfPixelFormat = *pz32; 
+                if(pz24!=NULL) {
+                    SET_ZBUF_DEPTH(24);
+                } else SET_ZBUF_DEPTH(32);
             }
         } else {
             if(dx_force_16bpp_zbuffer) {
@@ -1819,7 +1820,9 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD
                     exit(1);
                 }
 
-                wdxdisplay_cat.debug() << "forcing use of 16bpp Z-Buffer\n";
+                if(wdxdisplay_cat.is_debug())
+                   wdxdisplay_cat.debug() << "forcing use of 16bpp Z-Buffer\n";
+                SET_ZBUF_DEPTH(16);
                 ddsd.ddpfPixelFormat = *pz16;
             } else {
                 // pick the highest res zbuffer format avail.  Note: this is choosing to waste vid-memory
@@ -1829,15 +1832,14 @@ CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,LPDIRECTD
 
                 if(bWantStencil && (pz32!=NULL)) {
                     // dont want to select 16/8 z/stencil over 24/8 z/stenc
-                    ddsd.ddpfPixelFormat = *pz32;
+                    SET_ZBUF_DEPTH(32);
                 } else {
                     if(pz24!=NULL) {
-                        ddsd.ddpfPixelFormat = *pz24;
+                        SET_ZBUF_DEPTH(24);
                     } else if(pz32!=NULL) {
-                        ddsd.ddpfPixelFormat = *pz32;
+                        SET_ZBUF_DEPTH(32);
                     } else {
-                        assert(pz16!=NULL);
-                        ddsd.ddpfPixelFormat = *pz16;
+                        SET_ZBUF_DEPTH(16);
                     }
                 }
             }
@@ -2197,7 +2199,7 @@ TypeHandle wdxGraphicsWindow::get_type(void) const {
 //       Access:
 //  Description:
 ////////////////////////////////////////////////////////////////////
-ButtonHandle  wdxGraphicsWindow::
+ButtonHandle wdxGraphicsWindow::
 lookup_key(WPARAM wparam) const {
     switch(wparam) {
         case VK_BACK: return KeyboardButton::backspace();
@@ -2292,6 +2294,19 @@ lookup_key(WPARAM wparam) const {
     return ButtonHandle::none();
 }
 
+int wdxGraphicsWindow::
+get_depth_bitwidth(void) {
+    if((_dxgsg==NULL) || (_dxgsg->_zbuf==NULL))
+      return -1;
+
+    return _depth_buffer_bpp;
+
+// this is not reliable, on GF2, GetSurfDesc returns 32bpp when you created a 24bpp zbuf
+//    DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd);
+//    _dxgsg->_zbuf->GetSurfaceDesc(&ddsd); 
+//  return ddsd.ddpfPixelFormat.dwRGBBitCount;
+}
+
 // Global system parameters we want to modify during our run
 static int iMouseTrails;
 static bool bCursorShadowOn,bMouseVanish;

+ 2 - 0
panda/src/wdxdisplay/wdxGraphicsWindow.h

@@ -83,6 +83,7 @@ public:
   
   virtual void resize(unsigned int xsize,unsigned int ysize);
   virtual unsigned int verify_window_sizes(unsigned int numsizes,unsigned int *dimen);
+  virtual int get_depth_bitwidth(void);
 
 protected:
   void CreateScreenBuffersAndDevice(LPDIRECTDRAW7 pDD,LPDIRECT3D7 pD3DI);
@@ -119,6 +120,7 @@ private:
   bool              _window_inactive;
   bool              _active_minimized_fullscreen;
   bool              _return_control_to_app;
+  int               _depth_buffer_bpp;
 
 public:
   static TypeHandle get_class_type(void);

+ 5 - 0
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -336,6 +336,7 @@ void wglGraphicsWindow::config(void) {
     _pCurrent_display_settings = NULL;
     _mwindow = NULL;
     _gsg = NULL;
+    ZeroMemory(&_pixelformat,sizeof(_pixelformat));
     _hOldForegroundWindow=GetForegroundWindow();
     
     WNDCLASS wc;
@@ -1338,6 +1339,10 @@ void wglGraphicsWindow::unmake_current(void) {
   }
 }
 
+int wglGraphicsWindow::get_depth_bitwidth(void) {
+    return _pixelformat.cDepthBits;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsWindow::get_gsg_type
 //       Access: Public, Virtual

+ 1 - 0
panda/src/wgldisplay/wglGraphicsWindow.h

@@ -68,6 +68,7 @@ public:
   virtual void update(void);
   virtual void end_frame( void );
   virtual void swap( void );
+  virtual int get_depth_bitwidth(void);
 
   virtual TypeHandle get_gsg_type() const;
   static GraphicsWindow* make_wglGraphicsWindow(const FactoryParams &params);