SilkyNvg 1.2.0
dotnet add package SilkyNvg --version 1.2.0
NuGet\Install-Package SilkyNvg -Version 1.2.0
<PackageReference Include="SilkyNvg" Version="1.2.0" />
paket add SilkyNvg --version 1.2.0
#r "nuget: SilkyNvg, 1.2.0"
// Install SilkyNvg as a Cake Addin #addin nuget:?package=SilkyNvg&version=1.2.0 // Install SilkyNvg as a Cake Tool #tool nuget:?package=SilkyNvg&version=1.2.0
SilkyNvg
NanoVectorGraphicsExceptItUsesSilkNETNowWooHoo (Thank KoziLord for the description) (A port of memononen/nanovg to .NET8.0)
SilkyNvg is a small library providing basic 2D-Drawing functionallity well suited for UI and other such applications. It provides basic shape capabillities like rectangles or circles, as well as the abillity to build custom paths which can either be filled or stroked (lines).
The colour can either be a colour (SilkyNvg.Colour
), a paint (SilkyNvg.Paint
) or an image (SilkyNvg.Paint
).
On top of this a simple text-drawing-API is provided. See FontStash.NET for further details.
Usage / Examples
A transcription of the NanoVG example can be found in the 'samples' directory.
Initialization And Rendering
To create a new Nvg instance, an implementation of SilkyNvg.Rendering.INvgRenderer
must be specified,
then an instance can simply be created like this: Nvg nvg = Nvg.Create(renderer);
.
All calls to the render-API must be wrapped between Nvg.BeginFrame(width, height, pixelRatio);
and Nvg.EndFrame();
. To transform from a pixel-based coordinate system to any other, with and height can have any values independant from the actual window's size.
The implementations are split up into different components, these being:
- SilkyNvg.Blending for global blending
- SilkyNvg.Graphics for render styles
- SilkyNvg.Images for images
- SilkyNvg.Paths for creating and drawing paths
- SilkyNvg.Scissoring for custom scissors
- SilkyNvg.Text for text
- SilkyNvg.Transforms for creating and altering the transform
- SilkyNvg for core methods, such as BeginFrame, DebugDumpCache, Colour and Paint
All components are linked to
SilkyNvg.Nvg
via extension methods in their respective namespaces.
Renderers
The renderers are specified when creating the Nvg instance in Nvg.Create
.
SilkyNvg provides a Vulkan- and OpenGL-Renderer out of the box, but custom renderers can easilly be built using the SilkyNvg.Rendering.INvgRenderer
interface.
It is standard for renderers taking a CreateFlags
mask in their constructor used to specifiy renderer-specific settings.
Antialiasing
SilkyNvg automatically calculates antialiased vertices if SilkyNvg.Rendering.INvgRenderer.EdgeAntiAlias
is set to true. This is done because some renderers might not support antialiasing. In the custom renderers, the CreateFlags specify wheather or not antialiasing should be done.
OpenGL Renderer
The OpenGL renderer's constructor takes 2 arguments; SilkyNvg.Rendering.OpenGL.CreateFlags
and Silk.NET.OpenGL.GL
. The second parameter is an API-Instance of OpenGL, the CreateFlags
mask has the following options:
CreateFlags.Antialias
States that the renderer should draw antialiased or raw meshes.CreateFlags.StencilStrokes
States that the renderer should use the stencil buffer when drawing strokes (lines).CreateFlags.Debug
States that the renderer should print errors.
Vulkan Renderer
The Vulkan renderer's constructor takes 3 arguments:
SilkyNvg.Rendering.Vulkan.CreateFlags
, SilkyNvg.Rendering.Vulkan.VulkanRendererParams
and Silk.NET.Vulkan.VK
. The last parameter is an API-Instance of Vulkan.
The SilkyNvg.Rendering.Vulkan.CreateFlags
mask has the following options:
CreateFlags.Antialias
States that the renderer should draw antialiased or raw meshes.CreateFlags.StencilStrokes
States that the renderer should use the stencil buffer when drawing strokes (lines).CreateFlags.TriangleListFill
Doesn't useVK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN
, as it is not supported universally. Performances decreases somewhat.CreateFlags.Debug
States that the renderer should print errors.
The SilkyNvg.Rendering.Vulkan.VulkanRendererParams
struct:
VulkanRendererParams.PhysicalDevice
The physical device.VulkanRendererParams.Device
The device, matching the physical device specified.VulkanRendererParams.AllocationCallbacks
A safe IntPtr to potential AllocationCallbacks. UseIntPtr.Zero
if none are used or leave empty.VulkanRendererParams.InitialCommandBuffer
Can specify the command buffer to draw to. If this is set, updating the command buffer every frame is not necessary.VulkanRendererParams.FrameCount
How many frames can be drawn simultaniously. (No multithreading!)VulkanRendererParams.AdvanceFrameIndexAutomatically
If the index of the frame used should be incremented automatically after drawing a frame. Loops back to 0.VulkanRendererParams.RenderPass
The render pass.VulkanRendererParams.SubpassIndex
The index of the subpass to be used.VulkanRendererParams.ImageQueueFamily
The queue family to be used for image layout transition and buffer copying. Must supportVK__QUEUE_GRAPHICS_BIT
.VulkanRendererParams.ImageQueueFamilyIndex
Which index to create the queue running the afforementioned operations on should be created from.
Further Details
For further details, see the NanoVG doc, as the API and implementations are intentionally kept similar.
Custom Renderer Implementations
To create a custom render implementation, the renderer class musst implement SilkyNvg.Rendering.INvgRenderer
.
This interface contains the following methods and properties:
INvgRenderer
bool EdgeAntiAlias
Wheather or not antialiasing was enabled when creating the renderer. Can depend on wheather antialiasing is supported and if its use was specified when instantiating the renderer.bool Create()
Is called when NanoVG is initialized. Initialize the renderer here. Return false if initialization failed, otherwise return true.int CreateTexture(Texture type, Vector2D<uint> size, ImageFlags imageFlags, ReadOnlySpan<byte> data)
Is called to create a new image. type parameter specifies wheather data should be interpreted either as RGBA or Alpha values. Return handle to the new image.bool DeleteTexture(int image)
Is called to delete an image. Return false if image was not found, otherwise return true.bool UpdateTexture(int image, Rectangle<uint> bounds, ReadOnlySpan<byte> data)
Updates a specific section of the image to the new data. Return false if the image was not found, otherwise true.bool GetTextureSize(int image, out Vector2D<uint> size)
Returns the size of the specified image. Return false if the image was not found, otherwise true.void Viewport(Vector2D<float> size, float devicePxRatio)
Is called once per frame duringNvg.BeginFrame
to set the viewport size and pixel ratio.void Cancel()
Stops drawing the frame. Clear all cached data.void Flush()
Draws the frame. Render everything here.void Fill(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, float fringe, Box2D<float> bounds, IReadOnlyList<Path> paths)
Is called onNvg.Fill()
. Signals that the data contained in paths should be added to the rendered when flushing.Stroke(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, float fringe, float strokeWidth, IReadOnlyList<Path> paths)
Is called onNvg.Stroke()
. Signals that the data contained in paths should be added to the rendered when flushing.Triangles(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, ICollection<Vertex> vertices, float fringeWidth)
Is called when rendering text. Signals that the vertices should be added should be added to the rendered when flushing.Dispose()
Delete and shut down the renderer.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- SilkyNvg.Blending (>= 1.0.0)
- SilkyNvg.Core (>= 1.0.0)
- SilkyNvg.Graphics (>= 1.0.0)
- SilkyNvg.Images (>= 1.0.0)
- SilkyNvg.Paths (>= 1.0.0)
- SilkyNvg.Rendering (>= 1.0.0)
- SilkyNvg.Scissoring (>= 1.0.0)
- SilkyNvg.Text (>= 1.0.0)
- SilkyNvg.Tools (>= 1.0.0)
- SilkyNvg.Transforms (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SilkyNvg:
Package | Downloads |
---|---|
SilkyNvg.Rendering.OpenGL
A port of memononen/nanovg to .NET5.0 primarilly centered around the Silk.NET framework. |
|
SilkyNvg.Rendering.Vulkan
A port of memononen/nanovg to .NET5.0 primarilly centered around the Silk.NET framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated to .NET8.0 LTS