draw2d / rfcs

Somewhere to start to discuss how a 2d drawing library would work in rust, whether it is necessary, and what it should look like.
Apache License 2.0
22 stars 1 forks source link

Modern 2d rendering for games #3

Open nical opened 5 years ago

nical commented 5 years ago

Let's talk about the technical aspects of rendering complex vector graphics in interactive applications like games. To me this topic is very different from making UIs. I'll elaborate on that when I have a bit of time before me.

derekdreery commented 5 years ago

It sounds like for games, the difficulty is getting the balance between full GPU control, and some scene graph retained state. We want to

  1. abstract away the parts of GPU programming that aren't interesting to 2D games developers (if there are any),
  2. provide utility/helper functionality for common 2D tasks, like tessellating paths, standard effects (blur et. al.),
  3. either allow or force the library consumer to decide some of the implementation details for their program, for example when to transfer memory between CPU/GPU, batching strategies, memory locality on the GPU etc.
  4. Probably more

I suspect it may be worth having 2 crates, a gfx-2d or equivalent, that provides full control over the GPU for 2d applications, but is as simple as possible, and then a drawing library that abstracts a bit and provides the utility functionality. Should there be some sort of scene graph? Or should that be the consumer/higher level library's responsibility.

I think it's important to have a stack, so consumers can choose the level of abstraction that is easiest to use while still giving the access to performance they need.

derekdreery commented 5 years ago

It might be worth reaching out to the Chucklefish developers, since they are doing commercial work, and at least Starbound was 2D (not sure about their future work). A games library should be low-level enough for professional game development, even if it stays as an experiment.

derekdreery commented 5 years ago

Can I ask what operations are important for 2D gaming? Is the following list accurate:

  1. Blitting images (or sprites, I'm not sure I understand the distinction) onto a framebuffer
  2. Lighting/shadows/blur/other blend effects

In particular none of the layout stuff from UI where you calculate position and size. Also no shape primitives - everything is a rectange of pixels.

Are there other possibilities? Would people use vector graphics to describe their assets, and want them to scale? What other ways to use 2D graphics are there? Also, would you want all the UI stuff anyway since you usually have a UI in-game?

derekdreery commented 5 years ago

Possibly interesting article: https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch25.html

nical commented 5 years ago

I wrote some stuff here: https://nical.github.io/posts/rust-2d-graphics-02.html about memory management and modern graphics APIs.

nical commented 5 years ago

Sorry I thought I had answered that a while back:

Can I ask what operations are important for 2D gaming? Is the following list accurate:

1. Blitting images (or sprites, I'm not sure I understand the distinction) onto a framebuffer

2. Lighting/shadows/blur/other blend effects

If all you need is blitting sprites, ggez already provides the functionality along with a lot of useful stuff. Effects are certainly nice. What I'm personally interested in is general purpose vector graphics (as in, arbitrary paths) because it's a hard problem (and an interesting one), and it doesn't have a lot of known libraries that are adapted to complex interactive scenes.