Giter Club home page Giter Club logo

rgx.legacy's Introduction

rgx

A mid-level 2D graphics library for rust

Introduction

rgx is a 2D graphics library built on top of wgpu and Vulkan/Metal. This library aims to be "mid-level" in that it provides an API that is higher level than Vulkan/Metal, but lower level than most 2D graphics libraries in the wild, by exposing the user to concepts such as pipelines, buffers and swap chains. The goal of rgx is to provide as simple an API as possible without sacrificing performance or control over the rendering pipeline. See the examples directory to get a feel.

At this stage, the focus is on 2D bitmap graphics and sprite rendering. Basic shape rendering is also supported, but not the core strength of this library. In the future, text rendering and more complex vector rasterization may be supported - however, these are incredibly difficult to do correctly, and I would recommend looking at Mozilla's pathfinder project for these needs. rgx aims to do one thing really well, and that is bitmap rendering.

Overview

The library is split into two modules, kit, and core. The latter provides rgx's core API with no assumption on what kind of 2D graphics will be rendered, while the former exposes some useful building blocks for various use-cases, such as a shape-oriented pipeline and a sprite oriented pipeline. Users can construct their own pipelines and use them with rgx.

rgx can be used with, or without a rendering backend. To use it with, turn on the renderer feature. When used without a backend, the kit module's backend-agnostic utilities can be used.

Pipelines included in the kit

  • shape2d: for batched 2D shape rendering
  • sprite2d: for batched 2D sprite rendering

Features

  • Batched texture rendering
  • Batched shape rendering
  • Basic primitives for sprite animation
  • Off-screen rendering support
  • Custom shader support
  • Custom pipeline support
  • Built-in depth testing

Usage

See examples/helloworld.rs for a simple usage example.

Rebuilding the shaders

To rebuild the shaders run the following:

glslc -c -Werror --target-env=vulkan ./examples/data/framebuffer.vert -o ./examples/data/framebuffer.vert.spv
glslc -c -Werror --target-env=vulkan ./examples/data/framebuffer.frag -o ./examples/data/framebuffer.frag.spv
glslc -c -Werror --target-env=vulkan ./src/kit/data/shape.frag        -o ./src/kit/data/shape.frag.spv
glslc -c -Werror --target-env=vulkan ./src/kit/data/sprite.frag       -o ./src/kit/data/sprite.frag.spv
glslc -c -Werror --target-env=vulkan ./src/kit/data/shape.vert        -o ./src/kit/data/shape.vert.spv
glslc -c -Werror --target-env=vulkan ./src/kit/data/sprite.vert       -o ./src/kit/data/sprite.vert.spv

Support

If you find this project useful, consider supporting it by sending โ‚ฟ (Bitcoin) to 1HMfp9QFXmVUarNPmHxa1rhecZXyAPiPZd. <3

Copyright

(c) 2019 Alexis Sellier
Licensed under the MIT license.

rgx.legacy's People

Contributors

cloudhead avatar dhardy avatar ecton avatar jazzay avatar rbisewski avatar xla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgx.legacy's Issues

shapes example hangs

cargo run --example shapes --features="renderer" creates a window but it does not draw anything.
I had to comment out two occurences of window.request_redraw(); to make it work.
All the other examples work normally.

Ability to create filled polygon

Hi! I'm interested in creating a filled in polygon from a series of lines. I noticed rgx has the ability to create lines, so I could create the outline of a polygon from a series of lines, but not sure about filling it in. Is this currently possible? If it's possible, I'm willing to add an example to the examples/ folder to demonstrate it!

Sprite rotation

Are there any plans to introduce an ability to rotate sprites added to the sprite batch?

In theory, it should be pretty easily done by introducing something like RotationRect as an extension of Rect, which will contain additional info about the angle and origin of rotation. Later this RotationRect may be used by calling batch.add_rotated.
As an alternative, it might be a good solution to go "XNA" way by adding both angle and origin to the direct batch.add call.

Add a Changelog

What changed in version 0.2.0? Adding a changelog would be very nice.

Document shader compilation steps

Likely done with glslc but it would be good to document or even have a command/script to regenrate the spirv of the shaders. As an example while working on the shape2d pipeline I used this command for the vertex shader:

glslc -Werror -o src/kit/data/shape.vert.spv  src/kit/data/shape.vert

Y-axis is Inverted

I'm trying to understand the coordinate system in RGX and think that there is an inverted y-axis somewhere. I've modified the sprite example to only create one instance of the sprite in the batch as follows:

                let rect =
                    Rect::new(0.0, 0.0, sw, sh);
                batch.add(
                    anim.val(),
                    rect,
                    ZDepth::default(),
                    Rgba::new(0.5, 0.5, 0.5, 0.5),
                    1.0,
                    Repeat::default(),
                );
                batch.offset(mx, my);

then the pipeline is set to:

                r.update_pipeline(
                    &pip,
                    kit::ortho(out.width, out.height, Origin::BottomLeft),
                    &mut frame,
                );

However, the sprite then appears in the upper left (and is upside down). Similarly, if I change the origin in kit::ortho to Origin::TopLeft, the the sprite is in the BottomLeft.

This is on metal backend.

shape2d circle API Inconsistency Issues

In the process of adding more to my engine, I've identified two minor inconsistencies in the public API.

  • shape2d::Circle does not have its fields marked as pub, which means if you're trying to modifying a Circle either by mutation or by copying to a new structure, you can't actually retrieve the inner values of the Circle struct. This is different than the rest of the shape2d kit.
  • shape2d::circle() takes a Point2<f32> rather than an Into<Point2<f32>>. The other shape2d types take Into<> values

I'll be submitting a small PR for these changes shortly

Batch-based, cross-platform, language-agnostic API

Hi there!

Just posting this as an idea here. What about defining a very high-level API in something like Protocol buffers? Considering there will be a server-like wrapper for the RGX itself that will receive serialized commands via a customizable transport layer (TCP, UDP or inter-process) it will allow this library to serve as a simple graphics system for something like Deno or Wasmer. Obviously, such an API should be centered around a concept of batches to reduce the cost of transporting the requests. That, probably, means something like command queues in normal graphics.

Most probably, something like this should be implementable on the side as an external solution using RGX, however, I am interesting in your input on such an idea.

Cheers!

Threaded example panics on Linux

My engine that I based on rgx is panicing on linux. All of the examples work fine except the threaded example. Here's the backtrace:

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.3/src/command/mod.rs:266:23
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: std::panicking::begin_panic_fmt
             at src/libstd/panicking.rs:373
  13: <wgpu_native::hub::Storage<T,I> as core::ops::index::Index<I>>::index
             at /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.3/src/hub.rs:120
  14: wgpu_native::command::command_encoder_begin_render_pass::{{closure}}
             at /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.3/src/command/mod.rs:266
  15: core::option::Option<T>::map
             at /home/ecton/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/option.rs:456
  16: wgpu_native::command::command_encoder_begin_render_pass
             at /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.3/src/command/mod.rs:264
  17: wgpu_command_encoder_begin_render_pass
             at /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.3/src/command/mod.rs:739
  18: wgpu::CommandEncoder::begin_render_pass
             at /home/ecton/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.4.0/src/lib.rs:1059
  19: rgx::core::Pass::begin
             at src/core/mod.rs:837
  20: rgx::core::Frame::pass
             at ./src/core/mod.rs:794
  21: threaded::main::{{closure}}
             at examples/threaded.rs:68
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

If I enable Vsync, the panic goes away both in the example and in my code. I attempted to investigate updating rgx to wgpu 0.5 to see if that would help, but there are significant API changes that I wasn't sure how to handle.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.