Skip to content

Commit 43c08cd

Browse files
committed
Fixed FNA version
1 parent 96d1bb1 commit 43c08cd

File tree

5 files changed

+109
-90
lines changed

5 files changed

+109
-90
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<LangVersion>8.0</LangVersion>
1313
<InfoLundinMathVersion>1.2.6</InfoLundinMathVersion>
1414
<MonoGameVersion>3.8.0.1641</MonoGameVersion>
15-
<AppMonoGameVersion>3.8.2.1105</AppMonoGameVersion>
15+
<AppMonoGameVersion>3.8.4</AppMonoGameVersion>
1616
<StrideVersion>4.2.0.2067</StrideVersion>
1717
<AppTargetFramework>net8.0</AppTargetFramework>
1818
</PropertyGroup>

src/Myra/Graphics2D/RenderContext.cs

Lines changed: 78 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,49 @@ public enum TextureFiltering
2626
{
2727
Nearest,
2828
Linear,
29-
Anisotropic
30-
}
29+
#if MONOGAME
30+
Anisotropic
31+
#endif
32+
}
3133

3234
public partial class RenderContext : IDisposable
3335
{
36+
#if MONOGAME
37+
private static SamplerState _textureFilteringAnisotropic = new SamplerState
38+
{
39+
Filter = TextureFilter.Anisotropic,
40+
AddressU = TextureAddressMode.Clamp,
41+
AddressV = TextureAddressMode.Clamp,
42+
AddressW = TextureAddressMode.Clamp,
43+
BorderColor = Color.Transparent,
44+
MaxAnisotropy = 16,
45+
MaxMipLevel = 16,
46+
MipMapLevelOfDetailBias = 0f,
47+
ComparisonFunction = CompareFunction.Never,
48+
FilterMode = TextureFilterMode.Default
49+
};
50+
51+
public void SetAnisotropicFilteringMode(bool isAnisotropicFiltering)
52+
{
53+
_isAnisotropicFilteringOn = isAnisotropicFiltering;
54+
}
55+
#elif FNA
56+
#elif STRIDE
57+
private static readonly RasterizerStateDescription _uiRasterizerState;
58+
59+
static RenderContext()
60+
{
61+
var rs = new RasterizerStateDescription();
62+
rs.SetDefault();
63+
rs.ScissorTestEnable = true;
64+
_uiRasterizerState = rs;
65+
}
66+
#endif
67+
3468
#if MONOGAME || FNA
3569
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
70+
71+
private static RasterizerState UIRasterizerState
5172
{
5273
get
5374
{
@@ -63,16 +84,6 @@ private static RasterizerState UIRasterizerState
6384
return _uiRasterizerState;
6485
}
6586
}
66-
#elif STRIDE
67-
private static readonly RasterizerStateDescription _uiRasterizerState;
68-
69-
static RenderContext()
70-
{
71-
var rs = new RasterizerStateDescription();
72-
rs.SetDefault();
73-
rs.ScissorTestEnable = true;
74-
_uiRasterizerState = rs;
75-
}
7687
#endif
7788

7889
#if MONOGAME || FNA || STRIDE
@@ -90,6 +101,9 @@ static RenderContext()
90101
private Rectangle _scissor;
91102
private TextureFiltering _textureFiltering = TextureFiltering.Nearest;
92103
public Transform Transform;
104+
#if MONOGAME
105+
private bool _isAnisotropicFilteringOn;
106+
#endif
93107

94108
internal Rectangle DeviceScissor
95109
{
@@ -119,8 +133,6 @@ internal Rectangle DeviceScissor
119133
}
120134
}
121135

122-
private bool _isAnisotropicFilteringOn;
123-
124136
public Rectangle Scissor
125137
{
126138
get
@@ -270,7 +282,11 @@ public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? s
270282
/// <param name="depth"></param>
271283
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 scale, float depth = 0.0f)
272284
{
285+
#if MONOGAME
273286
SetTextureFiltering(_isAnisotropicFilteringOn ? TextureFiltering.Anisotropic : TextureFiltering.Nearest);
287+
#else
288+
SetTextureFiltering(TextureFiltering.Nearest);
289+
#endif
274290
color = CrossEngineStuff.MultiplyColor(color, Opacity);
275291
scale *= Transform.Scale;
276292
rotation += Transform.Rotation;
@@ -445,7 +461,7 @@ public void DrawRichText(RichTextLayout richText, Vector2 position, Color color,
445461
public void Begin()
446462
{
447463
#if MONOGAME || FNA
448-
var samplerState = SelectedSamplerState();
464+
var samplerState = SelectedSamplerState();
449465

450466
_renderer.Begin(SpriteSortMode.Deferred,
451467
BlendState.AlphaBlend,
@@ -470,38 +486,40 @@ public void Begin()
470486
}
471487

472488
#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-
}
489+
private SamplerState SelectedSamplerState()
490+
{
491+
switch (_textureFiltering)
492+
{
493+
case TextureFiltering.Nearest:
494+
return SamplerState.PointClamp;
495+
case TextureFiltering.Linear:
496+
return SamplerState.LinearClamp;
497+
#if MONOGAME
498+
case TextureFiltering.Anisotropic:
499+
return _textureFilteringAnisotropic;
500+
#endif
501+
default:
502+
throw new ArgumentOutOfRangeException();
503+
}
504+
}
487505
#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-
}
506+
private SamplerState SelectedSamplerState()
507+
{
508+
switch (_textureFiltering)
509+
{
510+
case TextureFiltering.Nearest:
511+
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.PointClamp;
512+
case TextureFiltering.Linear:
513+
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.LinearClamp;
514+
case TextureFiltering.Anisotropic:
515+
return MyraEnvironment.Game.GraphicsDevice.SamplerStates.AnisotropicClamp;
516+
default:
517+
throw new ArgumentOutOfRangeException();
518+
}
519+
}
502520
#endif
503521

504-
public void End()
522+
public void End()
505523
{
506524
_renderer.End();
507525
_beginCalled = false;
@@ -535,10 +553,5 @@ public void Dispose()
535553
{
536554
ReleaseUnmanagedResources();
537555
}
538-
539-
public void SetAnisotropicFilteringMode(bool isAnisotropicFiltering)
540-
{
541-
_isAnisotropicFilteringOn = isAnisotropicFiltering;
542-
}
543-
}
556+
}
544557
}

src/Myra/Graphics2D/UI/Simple/Image.cs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,24 @@ public class Image : Widget, IPressable
3535
{
3636
private IImage _image, _overImage, _pressedImage;
3737

38-
private bool _isAnisotropicFiltering = false;
39-
40-
public bool IsAnisotropicFiltering
41-
{
42-
get
43-
{
44-
return _isAnisotropicFiltering;
45-
}
46-
set
47-
{
48-
_isAnisotropicFiltering = value;
49-
InvalidateMeasure();
50-
}
51-
}
52-
53-
[Category("Appearance")]
38+
#if MONOGAME
39+
private bool _isAnisotropicFiltering = false;
40+
41+
public bool IsAnisotropicFiltering
42+
{
43+
get
44+
{
45+
return _isAnisotropicFiltering;
46+
}
47+
set
48+
{
49+
_isAnisotropicFiltering = value;
50+
InvalidateMeasure();
51+
}
52+
}
53+
#endif
54+
55+
[Category("Appearance")]
5456
public IImage Renderable
5557
{
5658
get
@@ -179,10 +181,14 @@ public override void InternalRender(RenderContext context)
179181
bounds.Height = (int)(bounds.Width * aspect);
180182
}
181183

182-
context.SetAnisotropicFilteringMode(_isAnisotropicFiltering);
183-
image.Draw(context, bounds, Color);
184-
context.SetAnisotropicFilteringMode(false);
185-
}
184+
#if MONOGAME
185+
context.SetAnisotropicFilteringMode(_isAnisotropicFiltering);
186+
#endif
187+
image.Draw(context, bounds, Color);
188+
#if MONOGAME
189+
context.SetAnisotropicFilteringMode(false);
190+
#endif
191+
}
186192
}
187193

188194
public void ApplyPressableImageStyle(PressableImageStyle imageStyle)

src/Myra/Myra.FNA.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121

2222
<ItemGroup>
2323
<ProjectReference Include="..\..\..\FontStashSharp\src\XNA\FontStashSharp.FNA.Core.csproj" />
24-
<ProjectReference Include="..\..\..\XNAssets\src\XNAssets.FNA.Core.csproj" />
24+
<ProjectReference Include="..\..\..\XNAssets\src\XNAssets\XNAssets.FNA.Core.csproj" />
2525
</ItemGroup>
2626
</Project>

src/Myra/MyraAssetManagerExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public static TextureRegion LoadTextureRegion(this AssetManager assetManager, st
243243
#endif
244244
}
245245

246-
public static FontSystem LoadFontSystem(this AssetManager assetManager, string assetName, string[] additionalFonts = null, Texture2D existingTexture = null, Rectangle existingTextureUsedSpace = default(Rectangle))
246+
internal static FontSystem LoadFontSystem(this AssetManager assetManager, string assetName, string[] additionalFonts = null, Texture2D existingTexture = null, Rectangle existingTextureUsedSpace = default(Rectangle))
247247
{
248248
FontSystemLoadingSettings settings = null;
249249
if (additionalFonts != null || existingTexture != null)
@@ -259,15 +259,15 @@ public static TextureRegion LoadTextureRegion(this AssetManager assetManager, st
259259
return assetManager.UseLoader(_fontSystemLoader, assetName, settings);
260260
}
261261

262-
public static StaticSpriteFont LoadStaticSpriteFont(this AssetManager assetManager, string assetName) => assetManager.UseLoader(_staticFontLoader, assetName);
262+
internal static StaticSpriteFont LoadStaticSpriteFont(this AssetManager assetManager, string assetName) => assetManager.UseLoader(_staticFontLoader, assetName);
263263

264264
/// <summary>
265265
/// Loads a font by either ttf name/size(i.e. 'font.ttf:32') or by fnt name(i.e. 'font.fnt')
266266
/// </summary>
267267
/// <param name="assetManager"></param>
268268
/// <param name="assetName"></param>
269269
/// <returns></returns>
270-
public static SpriteFontBase LoadFont(this AssetManager assetManager, string assetName)
270+
internal static SpriteFontBase LoadFont(this AssetManager assetManager, string assetName)
271271
{
272272
if (assetName.Contains(".fnt"))
273273
{

0 commit comments

Comments
 (0)