Преглед изворни кода

fix anisotropic filter settings bug

cxgeorge пре 23 година
родитељ
комит
25fbc0f86d
2 измењених фајлова са 43 додато и 35 уклоњено
  1. 42 34
      panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx
  2. 1 1
      panda/src/dxgsg8/dxGraphicsStateGuardian8.h

+ 42 - 34
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -797,7 +797,7 @@ dx_init(HCURSOR hMouseCursor) {
     scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE);  // disables texturing
     scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE);  // disables texturing
 
 
     // Init more Texture State
     // Init more Texture State
-    _CurTexMagFilter=_CurTexMinFilter=Texture::FT_nearest;
+    _CurTexMagFilter=_CurTexMinFilter=D3DTEXF_NONE;
     _CurTexWrapModeU=_CurTexWrapModeV=Texture::WM_clamp;
     _CurTexWrapModeU=_CurTexWrapModeV=Texture::WM_clamp;
     _CurTexAnisoDegree=1;
     _CurTexAnisoDegree=1;
 
 
@@ -3135,23 +3135,27 @@ apply_texture(TextureContext *tc) {
     uint aniso_degree=tex->get_anisotropic_degree();
     uint aniso_degree=tex->get_anisotropic_degree();
     Texture::FilterType ft=tex->get_magfilter();
     Texture::FilterType ft=tex->get_magfilter();
 
 
+    if(_CurTexAnisoDegree != aniso_degree) {
+        scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_MAXANISOTROPY,aniso_degree);
+        _CurTexAnisoDegree = aniso_degree;
+    }
+
+    D3DTEXTUREFILTERTYPE newMagFilter;
     if (aniso_degree<=1) {
     if (aniso_degree<=1) {
-        if (_CurTexMagFilter!=ft) {
+        newMagFilter=((ft!=Texture::FT_nearest) ? D3DTEXF_LINEAR : D3DTEXF_POINT);
 
 
-            _CurTexMagFilter = ft;
-            scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER,(ft==Texture::FT_nearest)? D3DTEXF_POINT : D3DTEXF_LINEAR);
-#ifdef _DEBUG
-            if((ft!=Texture::FT_linear)&&(ft!=Texture::FT_nearest)) {
-                dxgsg_cat.error() << "MipMap filter type setting for texture magfilter makes no sense,  texture: " << tex->get_name() << "\n";
-            }
-#endif
+        #ifdef _DEBUG
+        if((ft!=Texture::FT_linear)&&(ft!=Texture::FT_nearest)) {
+             dxgsg_cat.error() << "MipMap filter type setting for texture magfilter makes no sense,  texture: " << tex->get_name() << "\n";
         }
         }
+        #endif
     } else {
     } else {
-        if (aniso_degree!=_CurTexAnisoDegree) {
-            _CurTexAnisoDegree = aniso_degree;
-            scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_ANISOTROPIC );
-            scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY,aniso_degree);
-        }
+        newMagFilter=D3DTEXF_ANISOTROPIC;
+    }
+
+    if(_CurTexMagFilter!=newMagFilter) {
+        _CurTexMagFilter=newMagFilter;
+        scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, newMagFilter);
     }
     }
 
 
 #ifdef _DEBUG
 #ifdef _DEBUG
@@ -3170,35 +3174,39 @@ apply_texture(TextureContext *tc) {
 
 
     ft=tex->get_minfilter();
     ft=tex->get_minfilter();
 
 
-    if ((ft!=_CurTexMinFilter)||(aniso_degree!=_CurTexAnisoDegree)) {
-
 #ifdef _DEBUG
 #ifdef _DEBUG
-        if(ft > Texture::FT_linear_mipmap_linear) {
+    if(ft > Texture::FT_linear_mipmap_linear) {
                 dxgsg_cat.error() << "Unknown tex filter type for tex: " << tex->get_name() << "  filter: "<<(DWORD)ft<<"\n";
                 dxgsg_cat.error() << "Unknown tex filter type for tex: " << tex->get_name() << "  filter: "<<(DWORD)ft<<"\n";
                 return;
                 return;
-        }
+    }
 #endif
 #endif
 
 
-        D3DTEXTUREFILTERTYPE minfilter = PandaToD3DMinType[(DWORD)ft];
-        D3DTEXTUREFILTERTYPE mipfilter = PandaToD3DMipType[(DWORD)ft];
+    D3DTEXTUREFILTERTYPE newMipFilter = PandaToD3DMipType[(DWORD)ft];
 
 
-        #ifndef NDEBUG
-            extern char *PandaFilterNameStrs[];
-            if((!(dtc->_bHasMipMaps))&&(mipfilter!=D3DTEXF_NONE)) {
-                dxgsg_cat.error() << "Trying to set mipmap filtering for texture with no generated mipmaps!! texname[" << tex->get_name() << "], filter("<<PandaFilterNameStrs[ft]<<")\n";
-                mipfilter=D3DTEXF_NONE;
-            }
-        #endif
+    #ifndef NDEBUG
+      // sanity check
+    extern char *PandaFilterNameStrs[];
+    if((!(dtc->_bHasMipMaps))&&(mipfilter!=D3DTEXF_NONE)) {
+        dxgsg_cat.error() << "Trying to set mipmap filtering for texture with no generated mipmaps!! texname[" << tex->get_name() << "], filter("<<PandaFilterNameStrs[ft]<<")\n";
+        newMipFilter=D3DTEXF_NONE;
+    }
+    #endif
 
 
-        if (aniso_degree>1) {
-            minfilter=D3DTEXF_ANISOTROPIC;
-        }
 
 
-        scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, minfilter);
-        scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, mipfilter);
+    D3DTEXTUREFILTERTYPE newMinFilter = PandaToD3DMinType[(DWORD)ft];
 
 
-        _CurTexMinFilter = ft;
-        _CurTexAnisoDegree = aniso_degree;
+    if(aniso_degree>=2) {
+        newMinFilter=D3DTEXF_ANISOTROPIC;
+    }
+    
+    if(newMinFilter!=_CurTexMinFilter) {
+        _CurTexMinFilter = newMinFilter;
+        scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, newMinFilter);
+    }
+
+    if(newMipFilter!=_CurTexMipFilter) {
+        _CurTexMipFilter = newMipFilter;
+        scrn.pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, newMipFilter);
     }
     }
 
 
     // bugbug:  does this handle the case of untextured geometry?
     // bugbug:  does this handle the case of untextured geometry?

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

@@ -306,7 +306,7 @@ protected:
 
 
   // Cur Texture State
   // Cur Texture State
   TextureApplyAttrib::Mode _CurTexBlendMode;
   TextureApplyAttrib::Mode _CurTexBlendMode;
-  Texture::FilterType _CurTexMagFilter,_CurTexMinFilter;
+  D3DTEXTUREFILTERTYPE _CurTexMagFilter,_CurTexMinFilter,_CurTexMipFilter;
   DWORD _CurTexAnisoDegree;
   DWORD _CurTexAnisoDegree;
   Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
   Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
   LMatrix4f _current_projection_mat;
   LMatrix4f _current_projection_mat;