@@ -25,15 +25,31 @@ namespace Myra.Graphics2D
2525 public enum TextureFiltering
2626 {
2727 Nearest ,
28- Linear
29- }
28+ Linear ,
29+ Anisotropic
30+ }
3031
3132 public partial class RenderContext : IDisposable
3233 {
3334#if MONOGAME || FNA
3435 private static RasterizerState _uiRasterizerState ;
35-
36- private static RasterizerState UIRasterizerState
36+ private static SamplerState _textureFilteringAnisotropic = new SamplerState
37+ {
38+ Filter = TextureFilter . Anisotropic ,
39+ AddressU = TextureAddressMode . Clamp ,
40+ AddressV = TextureAddressMode . Clamp ,
41+ AddressW = TextureAddressMode . Clamp ,
42+ BorderColor = Color . Transparent ,
43+ MaxAnisotropy = 16 ,
44+ MaxMipLevel = 16 ,
45+ MipMapLevelOfDetailBias = 0f ,
46+ ComparisonFunction = CompareFunction . Never ,
47+ FilterMode = TextureFilterMode . Default
48+ } ;
49+
50+ private bool IsAnisotropicFilteringOn = false ;
51+
52+ private static RasterizerState UIRasterizerState
3753 {
3854 get
3955 {
@@ -255,7 +271,7 @@ public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? s
255271 /// <param name="depth"></param>
256272 public void Draw ( Texture2D texture , Vector2 position , Rectangle ? sourceRectangle , Color color , float rotation , Vector2 scale , float depth = 0.0f )
257273 {
258- SetTextureFiltering ( TextureFiltering . Nearest ) ;
274+ SetTextureFiltering ( IsAnisotropicFilteringOn ? TextureFiltering . Anisotropic : TextureFiltering . Nearest ) ;
259275 color = CrossEngineStuff . MultiplyColor ( color , Opacity ) ;
260276 scale *= Transform . Scale ;
261277 rotation += Transform . Rotation ;
@@ -430,7 +446,7 @@ public void DrawRichText(RichTextLayout richText, Vector2 position, Color color,
430446 public void Begin ( )
431447 {
432448#if MONOGAME || FNA
433- var samplerState = _textureFiltering == TextureFiltering . Nearest ? SamplerState . PointClamp : SamplerState . LinearClamp ;
449+ var samplerState = SelectedSamplerState ( ) ;
434450
435451 _renderer . Begin ( SpriteSortMode . Deferred ,
436452 BlendState . AlphaBlend ,
@@ -455,7 +471,22 @@ public void Begin()
455471 _beginCalled = true ;
456472 }
457473
458- public void End ( )
474+ private SamplerState SelectedSamplerState ( )
475+ {
476+ switch ( _textureFiltering )
477+ {
478+ case TextureFiltering . Nearest :
479+ return SamplerState . PointClamp ;
480+ case TextureFiltering . Linear :
481+ return SamplerState . LinearClamp ;
482+ case TextureFiltering . Anisotropic :
483+ return _textureFilteringAnisotropic ;
484+ default :
485+ throw new ArgumentOutOfRangeException ( ) ;
486+ }
487+ }
488+
489+ public void End ( )
459490 {
460491 _renderer . End ( ) ;
461492 _beginCalled = false ;
@@ -489,5 +520,10 @@ public void Dispose()
489520 {
490521 ReleaseUnmanagedResources ( ) ;
491522 }
492- }
523+
524+ public void SetAnisotropicFilteringMode ( bool isAnisotropicFiltering )
525+ {
526+ IsAnisotropicFilteringOn = isAnisotropicFiltering ;
527+ }
528+ }
493529}
0 commit comments