51 releases

Uses old Rust 2015

0.18.3 Feb 27, 2023
0.18.2 Oct 3, 2019
0.18.1 Apr 25, 2019
0.18.0 Feb 12, 2019
0.2.4 Mar 14, 2015

#913 in Graphics APIs

Download history 3271/week @ 2024-07-20 3155/week @ 2024-07-27 2718/week @ 2024-08-03 6115/week @ 2024-08-10 3184/week @ 2024-08-17 3631/week @ 2024-08-24 3549/week @ 2024-08-31 2958/week @ 2024-09-07 2861/week @ 2024-09-14 3647/week @ 2024-09-21 2978/week @ 2024-09-28 1112/week @ 2024-10-05 2197/week @ 2024-10-12 2171/week @ 2024-10-19 2636/week @ 2024-10-26 2100/week @ 2024-11-02

9,177 downloads per month
Used in fewer than 60 crates

Apache-2.0

305KB
5.5K SLoC

Documentation on docs.rs Travis Build Status AppVeyor Build Status gfx on crates.io Gitter Chat
Documentation | LearningGfx tutorial | Graphics By Squares tutorial | Blog

gfx-rs

gfx is a high-performance, bindless graphics API for the Rust programming language. It aims to be the default API for Rust graphics: for one-off applications, or higher level libraries or engines.

Motivation

  • Graphics APIs are mostly designed with C and C++ in mind, and hence are dangerous and error prone, with little static safety guarantees.
  • Providing type safe wrappers around platform-specific APIs is feasible, but only pushes the problem of platform independence to a higher level of abstraction, often to the game or rendering engine.
  • Modern graphics APIs, whilst providing a great degree of flexibility and a high level of performance, often have a much higher barrier to entry than traditional fixed-function APIs.
  • Graphics APIs like OpenGL still require the developer to 'bind' and 'unbind' objects in order to perform operations on them. This results in a large amount of boiler plate code, and brings with it the usual problems associated with global state.

Features

Graphics backends:

Hardware features:

  • off-screen render targets
  • multisampling
  • instancing
  • geometry shaders
  • tessellation
  • computing
  • persistent mapping

Who's using it?

Biggest open-source projects are:

Shiny screens, including some older projects:

Hematite LazyBox Vange-rs Claymore ZoC Rust-oids

Getting started

The gfx-rs git repository contains a number of examples. Those examples are automatically downloaded if you clone the gfx directory:

$ cd <my_dir>
$ git clone https://github.com/gfx-rs/gfx

where <my_dir> is a directory name of your choice. Once gfx is downloaded you can build any of the gfx examples. The examples are listed in the <my_dir>/gfx/Cargo.toml file. For example try:

$ cd gfx
$ cargo run --example cube

If you compile the example for the first time, it may take some while since all dependencies must be compiled too.

If you want to build your own stand-alone gfx program, add the following to your new Cargo.toml:

[dependencies]
gfx = "0.18"

For gfx to work, it needs access to the graphics system of the OS. This is typically provided through some window initialization API. gfx can use a couple of those to acquire graphical contexts. For example; glfw or glutin.

To see how the graphic context is acquired, see the cube example or the triangle example.

To use glutin, for example, your Cargo.toml must be extended with the following dependencies:

[dependencies]
...
glutin ="*"
gfx_window_glutin = "*"

Alternatively, an excellent introduction into gfx and its related crates can be found here.

Structure and current versions

gfx consist of several crates. You can find all of them in this repository.

Core functionality: Graphic backends: Window backends:
gfx on crates.io gfx_device_gl on crates.io gfx_window_sdl on crates.io
gfx_app on crates.io gfx_device_dx11 on crates.io gfx_window_dxgi on crates.io
gfx_core on crates.io gfx_device_metal on crates.io gfx_window_glfw on crates.io
gfx_macros on crates.io gfx_device_vulkan on crates.io gfx_window_metal on crates.io
gfx_window_glutin on crates.io
gfx_window_vulkan on crates.io

Note

gfx is still in development. API may change with new backends/features to be implemented. If you are interested in helping out, checkout contrib.md and do not hesitate to contact the developers on Gitter.

Dependencies

~145–355KB