Skip to content

Commit

Permalink
Version 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Jan 31, 2019
1 parent fdf28be commit 4964312
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 13 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
]
}
32 changes: 31 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.5.0.{build}
version: 0.5.1.{build}
configuration: Release
dotnet_csproj:
patch: true
Expand Down
2 changes: 1 addition & 1 deletion samples/NvgSharp.Samples.Demo/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion samples/NvgSharp.Samples.Demo/NvgSharp.Samples.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</PropertyGroup>

<ItemGroup Condition="$(DefineConstants.Contains('MONOGAME'))">
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.7.1.189" Condition="$(DefineConstants.Contains('MONOGAME'))" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.7.1.189" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/NvgSharp.Samples.Demo/PerfGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/NvgSharp/NvgContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/NvgSharp/Renderer.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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");
Expand Down
27 changes: 26 additions & 1 deletion src/NvgSharp/Resources.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework.Graphics;

namespace NvgSharp
{
internal static class Resources
{
private static byte[] _effectSource = null;

#if MONOGAME
private static bool? _isOpenGL;
#endif

public static byte[] NvgEffectSource
{
get
Expand All @@ -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
Expand All @@ -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
}
}

0 comments on commit 4964312

Please sign in to comment.