Browse Source

minor reorg of prev change

cxgeorge 24 years ago
parent
commit
9fac91aa0e

+ 16 - 10
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -588,6 +588,13 @@ dx_init(  LPDIRECTDRAW7     context,
         exit(1);
         exit(1);
     }
     }
 
 
+    // s3 virge drivers sometimes give crap values for these
+    if(_D3DDevDesc.dwMaxTextureWidth==0)
+       _D3DDevDesc.dwMaxTextureWidth=256;
+
+    if(_D3DDevDesc.dwMaxTextureHeight==0)
+       _D3DDevDesc.dwMaxTextureHeight=256;
+
     _bIsTNLDevice = (IsEqualGUID(_D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0);
     _bIsTNLDevice = (IsEqualGUID(_D3DDevDesc.deviceGUID,IID_IDirect3DTnLHalDevice)!=0);
 
 
     if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) {
     if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) {
@@ -3932,7 +3939,7 @@ draw_sphere(GeomSphere *geom, GeomContext *gc) {
 TextureContext *DXGraphicsStateGuardian::
 TextureContext *DXGraphicsStateGuardian::
 prepare_texture(Texture *tex) {
 prepare_texture(Texture *tex) {
 
 
-    DXTextureContext *gtc = new DXTextureContext(tex);
+    DXTextureContext *dtc = new DXTextureContext(tex);
 #ifdef WBD_GL_MODE
 #ifdef WBD_GL_MODE
     glGenTextures(1, &gtc->_index);
     glGenTextures(1, &gtc->_index);
 
 
@@ -3941,20 +3948,20 @@ prepare_texture(Texture *tex) {
     specify_texture(tex);
     specify_texture(tex);
     apply_texture_immediate(tex);
     apply_texture_immediate(tex);
 #else
 #else
-    if (gtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) {
-        delete gtc;
+    if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc) == NULL) {
+        delete dtc;
         return NULL;
         return NULL;
     }
     }
 #endif              // WBD_GL_MODE
 #endif              // WBD_GL_MODE
 
 
-    bool inserted = mark_prepared_texture(gtc);
+    bool inserted = mark_prepared_texture(dtc);
 
 
     // If this assertion fails, the same texture was prepared twice,
     // If this assertion fails, the same texture was prepared twice,
     // which shouldn't be possible, since the texture itself should
     // which shouldn't be possible, since the texture itself should
     // detect this.
     // detect this.
     nassertr(inserted, NULL);
     nassertr(inserted, NULL);
 
 
-    return gtc;
+    return dtc;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -3997,10 +4004,9 @@ apply_texture(TextureContext *tc) {
           }
           }
     
     
           dtc->DeleteTexture();
           dtc->DeleteTexture();
-          if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts) == NULL) {
+          if (dtc->CreateTexture(_d3dDevice,_cNumTexPixFmts,_pTexPixFmts,&_D3DDevDesc)==NULL) {
             // Oops, we can't re-create the texture for some reason.
             // Oops, we can't re-create the texture for some reason.
-            dxgsg_cat.error()
-              << "Unable to re-create texture " << *dtc->_texture << endl;
+            dxgsg_cat.error() << "Unable to re-create texture " << *dtc->_texture << endl;
     
     
             release_texture(dtc);
             release_texture(dtc);
             enable_texturing(false);
             enable_texturing(false);
@@ -6320,8 +6326,8 @@ bool recreate_tex_callback(TextureContext *tc,void *void_dxgsg_ptr) {
      // Re-fill the contents of textures and vertex buffers
      // Re-fill the contents of textures and vertex buffers
      // which just got restored now.
      // which just got restored now.
 
 
-     LPDIRECTDRAWSURFACE7 ddtex = dtc->CreateTexture(dxgsg->_d3dDevice,
-                                                     dxgsg->_cNumTexPixFmts,dxgsg->_pTexPixFmts);
+     LPDIRECTDRAWSURFACE7 ddtex = dtc->CreateTexture(dxgsg->_d3dDevice,dxgsg->_cNumTexPixFmts,
+                                                     dxgsg->_pTexPixFmts,&dxgsg->_D3DDevDesc);
      return ddtex!=NULL;
      return ddtex!=NULL;
 }
 }
 
 

+ 1 - 2
panda/src/dxgsg/dxGraphicsStateGuardian.h

@@ -230,6 +230,7 @@ public:
   LPDIRECT3DDEVICE7 _d3dDevice;
   LPDIRECT3DDEVICE7 _d3dDevice;
   LPDDPIXELFORMAT   _pTexPixFmts;
   LPDDPIXELFORMAT   _pTexPixFmts;
   int               _cNumTexPixFmts;
   int               _cNumTexPixFmts;
+  D3DDEVICEDESC7    _D3DDevDesc;
 
 
 protected:
 protected:
   void free_pointers();            // free local internal buffers
   void free_pointers();            // free local internal buffers
@@ -265,8 +266,6 @@ protected:
 
 
   RenderBuffer::Type _cur_read_pixel_buffer;  // source for copy_pixel_buffer operation
   RenderBuffer::Type _cur_read_pixel_buffer;  // source for copy_pixel_buffer operation
 
 
-  D3DDEVICEDESC7    _D3DDevDesc;
-
   void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize,
   void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize,
                     void *pIndexSpace,DWORD dwIndexSpaceByteSize,
                     void *pIndexSpace,DWORD dwIndexSpaceByteSize,
                     D3DVECTOR *pCenter, float fRadius,
                     D3DVECTOR *pCenter, float fRadius,

+ 23 - 32
panda/src/dxgsg/dxTextureContext.cxx

@@ -972,7 +972,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
 //       texture, and then copies the bitmap into the texture.
 //       texture, and then copies the bitmap into the texture.
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 LPDIRECTDRAWSURFACE7 DXTextureContext::
 LPDIRECTDRAWSURFACE7 DXTextureContext::
-CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts) {
+CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts, LPD3DDEVICEDESC7 pD3DDevDesc) {
     HRESULT hr;
     HRESULT hr;
     int i;
     int i;
     PixelBuffer *pbuf = _texture->_pbuffer;
     PixelBuffer *pbuf = _texture->_pbuffer;
@@ -1006,19 +1006,10 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
     DWORD dwOrigWidth  = (DWORD)pbuf->get_xsize();
     DWORD dwOrigWidth  = (DWORD)pbuf->get_xsize();
     DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
     DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
 
 
-    // Get the device caps so we can check if the device has any constraints
-    // when using textures.  Could we use the
-    D3DDEVICEDESC7 devDesc;
-    if(FAILED( pd3dDevice->GetCaps( &devDesc ) )) {
-        goto error_exit;
-    }
-
-    // s3 virge drivers sometimes give crap values for these
-    if(devDesc.dwMaxTextureWidth==0)
-       devDesc.dwMaxTextureWidth=256;
+    // Use the device caps so we can check if the device has any constraints
+    // when using textures. 
 
 
-    if(devDesc.dwMaxTextureHeight==0)
-       devDesc.dwMaxTextureHeight=256;
+    assert((pD3DDevDesc->dwMaxTextureWidth>0) && (pD3DDevDesc->dwMaxTextureHeight>0));
 
 
     // Setup the new surface desc for the texture. Note how we are using the
     // Setup the new surface desc for the texture. Note how we are using the
     // texture manage attribute, so Direct3D does alot of dirty work for us
     // texture manage attribute, so Direct3D does alot of dirty work for us
@@ -1073,21 +1064,21 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
     bool bShrinkOriginal;
     bool bShrinkOriginal;
     bShrinkOriginal=false;
     bShrinkOriginal=false;
 
 
-    if((dwOrigWidth>devDesc.dwMaxTextureWidth)||(dwOrigHeight>devDesc.dwMaxTextureHeight)) {
+    if((dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)||(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)) {
         #ifdef _DEBUG
         #ifdef _DEBUG
-           dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !!\n"
-           << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<<  devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !\n";
+           dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !!\n"
+           << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<<  pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !\n";
         #endif
         #endif
 
 
-        if(dwOrigWidth>devDesc.dwMaxTextureWidth)
-            ddsd.dwWidth=devDesc.dwMaxTextureWidth;
-        if(dwOrigHeight>devDesc.dwMaxTextureHeight)
-            ddsd.dwHeight=devDesc.dwMaxTextureHeight;
+        if(dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)
+            ddsd.dwWidth=pD3DDevDesc->dwMaxTextureWidth;
+        if(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)
+            ddsd.dwHeight=pD3DDevDesc->dwMaxTextureHeight;
         bShrinkOriginal=true;
         bShrinkOriginal=true;
     }
     }
 
 
     // checks for SQUARE reqmt (nvidia riva128 needs this)
     // checks for SQUARE reqmt (nvidia riva128 needs this)
-    if((ddsd.dwWidth != ddsd.dwHeight) && (devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
+    if((ddsd.dwWidth != ddsd.dwHeight) && (pD3DDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
 
 
         // assume pow2 textures.   sum exponents, divide by 2 rounding down to get sq size
         // assume pow2 textures.   sum exponents, divide by 2 rounding down to get sq size
         int i,width_exp,height_exp;
         int i,width_exp,height_exp;
@@ -1489,7 +1480,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
         else ft=Texture::FT_linear;
         else ft=Texture::FT_linear;
     }
     }
 
 
-    if((ft==Texture::FT_linear) && !(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
+    if((ft==Texture::FT_linear) && !(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
         ft=Texture::FT_nearest;
         ft=Texture::FT_nearest;
     _tex->set_magfilter(ft);
     _tex->set_magfilter(ft);
 
 
@@ -1522,26 +1513,26 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
         ft=Texture::FT_linear;
         ft=Texture::FT_linear;
     }
     }
 
 
-    assert((devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0);
+    assert((pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0);
 
 
     switch(ft) {
     switch(ft) {
         case Texture::FT_nearest_mipmap_linear:
         case Texture::FT_nearest_mipmap_linear:
-            if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
+            if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
                 ft=Texture::FT_nearest_mipmap_nearest;
                 ft=Texture::FT_nearest_mipmap_nearest;
             break;
             break;
         case Texture::FT_linear_mipmap_nearest:
         case Texture::FT_linear_mipmap_nearest:
-            if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
+            if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
                 ft=Texture::FT_nearest_mipmap_nearest;
                 ft=Texture::FT_nearest_mipmap_nearest;
             break;
             break;
         case Texture::FT_linear_mipmap_linear:
         case Texture::FT_linear_mipmap_linear:
-            if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) {
-                if(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)
+            if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) {
+                if(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)
                     ft=Texture::FT_linear_mipmap_nearest;
                     ft=Texture::FT_linear_mipmap_nearest;
                 else ft=Texture::FT_nearest_mipmap_nearest;  // if you cant do linear in a level, you probably cant do linear b/w levels, so just do nearest-all
                 else ft=Texture::FT_nearest_mipmap_nearest;  // if you cant do linear in a level, you probably cant do linear b/w levels, so just do nearest-all
             }
             }
             break;
             break;
         case Texture::FT_linear:
         case Texture::FT_linear:
-            if(!(devDesc.dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
+            if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR))
                 ft=Texture::FT_nearest;
                 ft=Texture::FT_nearest;
             break;
             break;
     }
     }
@@ -1551,14 +1542,14 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
     uint aniso_degree;
     uint aniso_degree;
 
 
     aniso_degree=1;
     aniso_degree=1;
-    if(devDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
+    if(pD3DDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) {
         aniso_degree=_tex->get_anisotropic_degree();
         aniso_degree=_tex->get_anisotropic_degree();
-        if((aniso_degree>devDesc.dwMaxAnisotropy)
+        if((aniso_degree>pD3DDevDesc->dwMaxAnisotropy)
 #ifdef _DEBUG
 #ifdef _DEBUG
            || dx_force_anisotropic_filtering
            || dx_force_anisotropic_filtering
 #endif
 #endif
           )
           )
-            aniso_degree=devDesc.dwMaxAnisotropy;
+            aniso_degree=pD3DDevDesc->dwMaxAnisotropy;
     }
     }
     _tex->set_anisotropic_degree(aniso_degree);
     _tex->set_anisotropic_degree(aniso_degree);
 #ifdef _DEBUG
 #ifdef _DEBUG
@@ -1572,7 +1563,7 @@ CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT
         dxgsg_cat.debug() << "CreateTexture: generating mipmaps for "<< _tex->get_name() << endl;
         dxgsg_cat.debug() << "CreateTexture: generating mipmaps for "<< _tex->get_name() << endl;
     }
     }
 
 
-    if(devDesc.dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) {
+    if(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) {
         // must assign a texture to a specific stage
         // must assign a texture to a specific stage
         // for now I'm just going to use stage 0 for all
         // for now I'm just going to use stage 0 for all
         ddsd.dwTextureStage=0;
         ddsd.dwTextureStage=0;

+ 2 - 2
panda/src/dxgsg/dxTextureContext.h

@@ -55,8 +55,8 @@ public:
   LPDIRECTDRAWSURFACE7  _surface;
   LPDIRECTDRAWSURFACE7  _surface;
   Texture *_tex;            // ptr to parent, primarily for access to namestr
   Texture *_tex;            // ptr to parent, primarily for access to namestr
 
 
-  LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts);
-
+  LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, 
+                                     LPDDPIXELFORMAT pTexPixFmts,LPD3DDEVICEDESC7 pD3DDevDesc);
   bool _bHasMipMaps;
   bool _bHasMipMaps;
   DWORD _PixBufConversionType;  // enum ConversionType
   DWORD _PixBufConversionType;  // enum ConversionType