All Projects → nyorain → Rvg

nyorain / Rvg

Licence: bsl-1.0
High level vulkan 2D vector-like graphics api (C++)

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Rvg

Vulkan Samples
One stop solution for all Vulkan samples
Stars: ✭ 2,009 (+1074.85%)
Mutual labels:  graphics, vulkan
Rgx
Modern mid-level 2D graphics library
Stars: ✭ 172 (+0.58%)
Mutual labels:  graphics, vulkan
Veldrid
A low-level, portable graphics library for .NET.
Stars: ✭ 1,784 (+943.27%)
Mutual labels:  graphics, vulkan
Flycube
Graphics API wrapper is written in C++ on top of Directx 12 and Vulkan. Provides main features including ray tracing.
Stars: ✭ 78 (-54.39%)
Mutual labels:  graphics, vulkan
Node Sylvester
🐱 Sylvester is a vector, matrix, and geometry library for JavaScript, that runs in the browser and on the server.
Stars: ✭ 144 (-15.79%)
Mutual labels:  vector, graphics
Rust Game Development Frameworks
List of curated frameworks by the **Game Development in Rust** community.
Stars: ✭ 81 (-52.63%)
Mutual labels:  graphics, vulkan
Bsf
Modern C++14 library for the development of real-time graphical applications
Stars: ✭ 1,640 (+859.06%)
Mutual labels:  graphics, vulkan
Gl vs vk
Comparison of OpenGL and Vulkan API in terms of performance.
Stars: ✭ 65 (-61.99%)
Mutual labels:  graphics, vulkan
Shaderc Rs
Rust bindings for the shaderc library.
Stars: ✭ 143 (-16.37%)
Mutual labels:  graphics, vulkan
Plutovg
Tiny 2D vector graphics library in C
Stars: ✭ 141 (-17.54%)
Mutual labels:  vector, graphics
Gpcs4
A Playstation 4 emulator just begin
Stars: ✭ 1,186 (+593.57%)
Mutual labels:  graphics, vulkan
Floor
A C++ Compute/Graphics Library and Toolchain enabling same-source CUDA/Host/Metal/OpenCL/Vulkan C++ programming and execution.
Stars: ✭ 166 (-2.92%)
Mutual labels:  graphics, vulkan
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+6740.94%)
Mutual labels:  graphics, vulkan
Bgfx
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Stars: ✭ 10,252 (+5895.32%)
Mutual labels:  graphics, vulkan
Shaderconductor
ShaderConductor is a tool designed for cross-compiling HLSL to other shading languages
Stars: ✭ 1,146 (+570.18%)
Mutual labels:  graphics, vulkan
Svg.skia
An SVG rendering library.
Stars: ✭ 122 (-28.65%)
Mutual labels:  vector, graphics
Vktk
Vulkan Toolkit
Stars: ✭ 32 (-81.29%)
Mutual labels:  graphics, vulkan
Shaderc
A collection of tools, libraries, and tests for Vulkan shader compilation.
Stars: ✭ 1,016 (+494.15%)
Mutual labels:  graphics, vulkan
Filament
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Stars: ✭ 13,215 (+7628.07%)
Mutual labels:  graphics, vulkan
Vulkancore
Vulkan 1.0 graphics and compute API bindings for .NET Standard
Stars: ✭ 162 (-5.26%)
Mutual labels:  graphics, vulkan

Retained vulkan/vector graphics

NOTE: this isn't very actively maintained at the moment. It might still be useful as a proof of concept. Just for reference, you might prefer to look at an experimental rework I worked on for a while, where rendering is a lot more optimized. Development here might be resumed in future

Vulkan library for high-level 2D vector-like rendering in modern C++17. Modeled loosely after svg, inspired by nanoVG. Uses an object-oriented, retained mode idiom for rendering which makes it highly efficient for rendering with vulkan since curves and shapes are not recomputed and uploaded every frame but just once (or when changed). Does not even need a command buffer rerecord every frame, even things like paints, shapes or transforms can be changed without triggering the need for a command buffer rerecord which makes it use way less cpu performance than immediate mode alternatives. Aims to provide a compromise between high level drawing functionality and an api that can efficiently be implemented on the gpu. Could e.g. easily be used for a vulkan gui library.

The project builds upon tested and proven libraries where possible, such as fontstash for font atlas building and some stb headers. Note that the project is still in a rather early stage, please report all issues and questions (simple things such as spelling errors or missing docs on a function are appreciated as well).

For more information check out the example concepts below, the example showing off many features, or read the introduction which documents some basic concepts and shows how to integrate rvg in more detail.

Example

Since rvg uses a retained mode you will first have to create the resources you might to use/draw and then actually draw them (via recording into a command buffer). The example below shows initialization of some basic rvg resources (on the highest abstraction level), there are more and more advanced settings, refer to the inline documentation in the headers:

init(vpp::Device& dev, vk::RenderPass renderPass) {
	// First create a rvg context: creates pipelines and such
	// We have to specify the renderPass and subpass we want to use it
	// (There are much more settings like pipelineCache/anti aliasing or
	// enabled features, see rvg/context.hpp).
	rvg::Context context {dev, {renderPass, 0u}};

	// Now we can create resources
	// rectangle at {100, 100} with size {200, 200}
	// the last parameter is the draw mode: in this case we want to
	// build fill data but will never stroke it
	auto rect = rvg::RectShape(ctx, {100, 100}, {200, 200}, {true, 0.f});

	// a circle at {300, 300} with radius 10 that we can
	// stroke (with thickness 3.f) and fill
	auto circle = rvg::CircleShape(ctx, {300, 300}, 10, {true, 3.f});

	// a scissor that only render into the given rect (at {50, 50} with size
	// {100, 100})
	auto scissor = rvg::Scissor(ctx, {{50, 50}, {100, 100}});

	// a transform that transforms coordinates from the space we just used
	// (which may e.g. be level or window coordinates) to normalized
	// vulkan coords ([-1, 1] x [-1, 1])
	auto transform = rvg::Transform(ctx, <transform matrix>);

	// a paint that will specify how shapes are filled/stroked
	auto colorPaint1 = rvg::Paint(ctx, rvg::colorPaint(rvg::Color::red));
	auto colorPaint2 = rvg::Paint(ctx, rvg::colorPaint({255u, 128u, 190u}));

	// rvg does also support gradients and texture paints
	// linear gradient from ({100, 100}: red) to ({200, 200}: green)
	auto gradient = rvg::Paint(ctx, rvg::linearGradient(
		{100, 100}, {200, 200},
		rvg::Color::red, rvg::Color::green));

	// create a FontAtlas and load a font
	// rvg uses the font handling from nuklear (using stb truetype & rectpack)
	rvg::FontAtlas fontAtlas(ctx);
	rvg::Font font(fontAtlas, "OpenSans.ttf");
	fontAtlas.bake();

	// using the font we can now create a text object at {400, 100}
	// we could also align it using the metrics information by Font and Text
	rvg::Text text(ctx, "Text to display", font, {400, 100});
}

After having all these resources created we naturally want to render them. Since rvg tries to stay as modular and univerally usable as possible, the interface all resources use for rendering is a raw vulkan command buffer. Binding state (like transform/paint/scissor) will result in a simple descriptor set bind while rendering shapes will result always in an indirect draw. Assuming the resources from above, this could look like this:

render(vk::CommandBuffer cb) {
	// Binds default (full) scissor, identity transform and other required
	// state
	ctx.bindDefaults(cb);

	// We can bind state and draw what we want now.
	// Bound state stays the same until replaced
	// First, we bind our transform
	transform.bind(cb);

	// Now, let's draw!
	// Starting with the rect shape: we specified that we might want
	// to fill it but don't need the stroke data. So now we can record
	// its fill commands but were not allowed to stroke it
	paint1.bind(cb);
	rect.fill(cb);

	circle.fill(cb);

	paint2.bind(cb);
	circleShape.stroke(cb);

	// we can also fill/stroke shapes multiple times
	scissor.bind(cb);
	rect.fill(cb);

	// explicitly reset the limiting scissor bound above:
	ctx.defaultScissor().bind(cb);

	gradient.bind(cb);
	text.draw(cb);
}

It's now probably pretty easy to imagine how you could use rvg to further build your own (roughly) object-oriented interfaces and divide the work into small components.

Screenshots

Screenshot of example/example.cpp:

<Currently not loading example picture :(>

Building

The library uses meson as build system. It uses a few of my other libraries as dependencies to stay modular but those will be automatically built using meson. The only hard dependencies are vulkan as well as glslang for building the spirv shaders. You need a solid C++17 compiler (currently not tested with msvc), gcc >= 7 is tested. For gcc 7 you currently have to turn off werror in meson (meson configure -Dwerror=false in build dir). For the glfw example you need the glfw3 library (obviously with vulkan support).

After building

meson build -Dexample-glfw=true
cd build
ninja

you should be able to run the example in the build dir via ./example/example_glfw. There is also an example using my experimental ny window abstraction instead of glfw, enable it via -Dexample-ny=true (requires several low level xcb/wayland libraries).

Notes

Please read the linked introduction (requirements) before reporting build issues. Contributions welcome, always want to hear ideas and suggestions.

This library is the successor of/inspired my attempt to write a nanoVG vulkan backend, which worked but didn't really make use of vulkans advantages. That inspired me to look into which kind of abstraction would make sense for vulkan.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].