diff --git a/.vscode/launch.json b/.vscode/launch.json
index 3c3f0f0..11cc124 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -26,7 +26,31 @@
"cwd": "${workspaceFolder}/samples/NvgSharp.Samples.Demo/bin/FNA/Release/netcoreapp2.1/",
"console": "internalConsole",
"stopAtEntry": false,
+ "internalConsoleOptions": "openOnSessionStart"
+ },
+ {
+ "name": "MonoGame Demo Debug",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "MonoGame Debug",
+ "program": "${workspaceFolder}/samples/NvgSharp.Samples.Demo/bin/MonoGame/Debug/netcoreapp2.1/NvgSharp.Samples.Demo.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}/samples/NvgSharp.Samples.Demo/bin/MonoGame/Debug/netcoreapp2.1/",
+ "console": "internalConsole",
+ "stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
+ {
+ "name": "MonoGame Demo Release",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "MonoGame Release",
+ "program": "${workspaceFolder}/samples/NvgSharp.Samples.Demo/bin/MonoGame/Release/netcoreapp2.1/NvgSharp.Samples.Demo.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}/samples/NvgSharp.Samples.Demo/bin/MonoGame/Release/netcoreapp2.1/",
+ "console": "internalConsole",
+ "stopAtEntry": false,
+ "internalConsoleOptions": "openOnSessionStart"
+ },
]
}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 46a1718..42e6d23 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -32,6 +32,36 @@
"reveal": "silent"
},
"problemMatcher": "$msCompile"
- }
+ },
+ {
+ "label": "MonoGame Debug",
+ "command": "dotnet build",
+ "type": "shell",
+ "group": "build",
+ "args": [
+ "build/MonoGame/NvgSharp.sln",
+ "/t:build",
+ "/p:Configuration=Debug"
+ ],
+ "presentation": {
+ "reveal": "silent"
+ },
+ "problemMatcher": "$msCompile"
+ },
+ {
+ "label": "MonoGame Release",
+ "command": "dotnet build",
+ "type": "shell",
+ "group": "build",
+ "args": [
+ "build/MonoGame/NvgSharp.sln",
+ "/t:build",
+ "/p:Configuration=Release"
+ ],
+ "presentation": {
+ "reveal": "silent"
+ },
+ "problemMatcher": "$msCompile"
+ }
]
}
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
index f29c582..c5ae98e 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-version: 0.5.0.{build}
+version: 0.5.1.{build}
configuration: Release
dotnet_csproj:
patch: true
diff --git a/samples/NvgSharp.Samples.Demo/Game1.cs b/samples/NvgSharp.Samples.Demo/Game1.cs
index 359baf5..0a1d3c3 100644
--- a/samples/NvgSharp.Samples.Demo/Game1.cs
+++ b/samples/NvgSharp.Samples.Demo/Game1.cs
@@ -42,7 +42,7 @@ protected override void LoadContent()
{
var device = GraphicsDevice;
- _context = new NvgContext(GraphicsDevice, 0);
+ _context = new NvgContext(GraphicsDevice);
_demo = new Demo();
_demo.loadDemoData(GraphicsDevice, _context);
diff --git a/samples/NvgSharp.Samples.Demo/NvgSharp.Samples.Demo.csproj b/samples/NvgSharp.Samples.Demo/NvgSharp.Samples.Demo.csproj
index f11a2c2..073ced4 100644
--- a/samples/NvgSharp.Samples.Demo/NvgSharp.Samples.Demo.csproj
+++ b/samples/NvgSharp.Samples.Demo/NvgSharp.Samples.Demo.csproj
@@ -26,7 +26,7 @@
-
+
diff --git a/samples/NvgSharp.Samples.Demo/PerfGraph.cs b/samples/NvgSharp.Samples.Demo/PerfGraph.cs
index 26b31c1..80907fe 100644
--- a/samples/NvgSharp.Samples.Demo/PerfGraph.cs
+++ b/samples/NvgSharp.Samples.Demo/PerfGraph.cs
@@ -101,7 +101,7 @@ public void Render(NvgContext vg, float x, float y)
vg.FontFace("sans");
- if (string.IsNullOrEmpty(_name))
+ if (!string.IsNullOrEmpty(_name))
{
vg.FontSize(14.0f);
vg.TextAlign(Alignment.Left | Alignment.Top);
diff --git a/src/NvgSharp/NvgContext.cs b/src/NvgSharp/NvgContext.cs
index 2bc698c..d0ae66e 100644
--- a/src/NvgSharp/NvgContext.cs
+++ b/src/NvgSharp/NvgContext.cs
@@ -22,7 +22,7 @@ public unsafe class NvgContext : IDisposable
private float _devicePxRatio;
private float _distTol;
private int _drawCallCount;
- private readonly int _edgeAntiAlias;
+ private readonly bool _edgeAntiAlias;
private int _fillTriCount;
private int _fontImageIdx;
private FontSystem _fontSystem;
@@ -33,9 +33,10 @@ public unsafe class NvgContext : IDisposable
private float _tessTol;
private int _textTriCount;
- public NvgContext(GraphicsDevice device, int edgeAntiAlias)
+
+ public NvgContext(GraphicsDevice device, bool edgeAntiAlias = true)
{
- _renderer = new XNARenderer(device);
+ _renderer = new Renderer(device);
var fontParams = new FontSystemParams();
@@ -847,7 +848,7 @@ public void Fill()
var fillPaint = state.Fill;
var i = 0;
__flattenPaths();
- if (_edgeAntiAlias != 0 && state.ShapeAntiAlias != 0)
+ if (_edgeAntiAlias && state.ShapeAntiAlias != 0)
__expandFill(_fringeWidth, NvgSharp.LineCap.Miter, 2.4f);
else
__expandFill(0.0f, NvgSharp.LineCap.Miter, 2.4f);
@@ -889,7 +890,7 @@ public void Stroke()
MultiplyAlpha(ref strokePaint.OuterColor, state.Alpha);
__flattenPaths();
- if (_edgeAntiAlias != 0 && state.ShapeAntiAlias != 0)
+ if (_edgeAntiAlias && state.ShapeAntiAlias != 0)
__expandStroke(strokeWidth * 0.5f, _fringeWidth, state.LineCap, state.LineJoin, state.MiterLimit);
else
__expandStroke(strokeWidth * 0.5f, 0.0f, state.LineCap, state.LineJoin, state.MiterLimit);
diff --git a/src/NvgSharp/Renderer.cs b/src/NvgSharp/Renderer.cs
index 9038782..5cf27ea 100644
--- a/src/NvgSharp/Renderer.cs
+++ b/src/NvgSharp/Renderer.cs
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using FontStashSharp;
+
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace NvgSharp
{
- internal class XNARenderer : IRenderer
+ internal class Renderer : IRenderer
{
private readonly BlendState _blendStateNoDraw = new BlendState
{
@@ -72,7 +73,7 @@ internal class XNARenderer : IRenderer
private readonly EffectParameter _scissorScaleParam;
private readonly EffectParameter _paintMatParam;
- public XNARenderer(GraphicsDevice device)
+ public Renderer(GraphicsDevice device)
{
if (device == null)
throw new ArgumentNullException("device");
diff --git a/src/NvgSharp/Resources.cs b/src/NvgSharp/Resources.cs
index 1ca4aaa..cf16045 100644
--- a/src/NvgSharp/Resources.cs
+++ b/src/NvgSharp/Resources.cs
@@ -1,4 +1,7 @@
using System.IO;
+using System.Linq;
+using System.Reflection;
+using Microsoft.Xna.Framework.Graphics;
namespace NvgSharp
{
@@ -6,6 +9,10 @@ internal static class Resources
{
private static byte[] _effectSource = null;
+#if MONOGAME
+ private static bool? _isOpenGL;
+#endif
+
public static byte[] NvgEffectSource
{
get
@@ -18,7 +25,7 @@ public static byte[] NvgEffectSource
var assembly = typeof(Resources).Assembly;
#if MONOGAME
- var path = "NvgSharp.Resources.Effect.ogl.mgfxo";
+ var path = IsOpenGL?"NvgSharp.Resources.Effect.ogl.mgfxo":"NvgSharp.Resources.Effect.dx11.mgfxo";
#elif FNA
var path = "NvgSharp.Resources.Effect.fxb";
#endif
@@ -33,5 +40,23 @@ public static byte[] NvgEffectSource
return _effectSource;
}
}
+
+#if MONOGAME
+ public static bool IsOpenGL
+ {
+ get
+ {
+ if (_isOpenGL == null)
+ {
+ _isOpenGL = (from f in typeof(GraphicsDevice).GetFields(BindingFlags.NonPublic |
+ BindingFlags.Instance)
+ where f.Name == "glFramebuffer"
+ select f).FirstOrDefault() != null;
+ }
+
+ return _isOpenGL.Value;
+ }
+ }
+#endif
}
}