@@ -25,15 +25,29 @@ 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 static RasterizerState UIRasterizerState
3751 {
3852 get
3953 {
@@ -105,6 +119,7 @@ internal Rectangle DeviceScissor
105119 }
106120 }
107121
122+ private bool _isAnisotropicFilteringOn ;
108123
109124 public Rectangle Scissor
110125 {
@@ -255,7 +270,7 @@ public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? s
255270 /// <param name="depth"></param>
256271 public void Draw ( Texture2D texture , Vector2 position , Rectangle ? sourceRectangle , Color color , float rotation , Vector2 scale , float depth = 0.0f )
257272 {
258- SetTextureFiltering ( TextureFiltering . Nearest ) ;
273+ SetTextureFiltering ( _isAnisotropicFilteringOn ? TextureFiltering . Anisotropic : TextureFiltering . Nearest ) ;
259274 color = CrossEngineStuff . MultiplyColor ( color , Opacity ) ;
260275 scale *= Transform . Scale ;
261276 rotation += Transform . Rotation ;
@@ -430,7 +445,7 @@ public void DrawRichText(RichTextLayout richText, Vector2 position, Color color,
430445 public void Begin ( )
431446 {
432447#if MONOGAME || FNA
433- var samplerState = _textureFiltering == TextureFiltering . Nearest ? SamplerState . PointClamp : SamplerState . LinearClamp ;
448+ var samplerState = SelectedSamplerState ( ) ;
434449
435450 _renderer . Begin ( SpriteSortMode . Deferred ,
436451 BlendState . AlphaBlend ,
@@ -439,9 +454,8 @@ public void Begin()
439454 UIRasterizerState ,
440455 null ) ;
441456#elif STRIDE
442- var samplerState = _textureFiltering == TextureFiltering . Nearest ?
443- MyraEnvironment . Game . GraphicsDevice . SamplerStates . PointClamp :
444- MyraEnvironment . Game . GraphicsDevice . SamplerStates . LinearClamp ;
457+ var samplerState = SelectedSamplerState ( ) ;
458+
445459 _renderer . Begin ( MyraEnvironment . Game . GraphicsContext ,
446460 SpriteSortMode . Deferred ,
447461 BlendStates . AlphaBlend ,
@@ -455,7 +469,39 @@ public void Begin()
455469 _beginCalled = true ;
456470 }
457471
458- public void End ( )
472+ #if MONOGAME || FNA
473+ private SamplerState SelectedSamplerState ( )
474+ {
475+ switch ( _textureFiltering )
476+ {
477+ case TextureFiltering . Nearest :
478+ return SamplerState . PointClamp ;
479+ case TextureFiltering . Linear :
480+ return SamplerState . LinearClamp ;
481+ case TextureFiltering . Anisotropic :
482+ return _textureFilteringAnisotropic ;
483+ default :
484+ throw new ArgumentOutOfRangeException ( ) ;
485+ }
486+ }
487+ #elif STRIDE
488+ private SamplerState SelectedSamplerState ( )
489+ {
490+ switch ( _textureFiltering )
491+ {
492+ case TextureFiltering . Nearest :
493+ return MyraEnvironment . Game . GraphicsDevice . SamplerStates . PointClamp ;
494+ case TextureFiltering . Linear :
495+ return MyraEnvironment . Game . GraphicsDevice . SamplerStates . LinearClamp ;
496+ case TextureFiltering . Anisotropic :
497+ return MyraEnvironment . Game . GraphicsDevice . SamplerStates . AnisotropicClamp ;
498+ default :
499+ throw new ArgumentOutOfRangeException ( ) ;
500+ }
501+ }
502+ #endif
503+
504+ public void End ( )
459505 {
460506 _renderer . End ( ) ;
461507 _beginCalled = false ;
@@ -489,5 +535,10 @@ public void Dispose()
489535 {
490536 ReleaseUnmanagedResources ( ) ;
491537 }
492- }
538+
539+ public void SetAnisotropicFilteringMode ( bool isAnisotropicFiltering )
540+ {
541+ _isAnisotropicFilteringOn = isAnisotropicFiltering ;
542+ }
543+ }
493544}
0 commit comments