PistonDevelopers / graphics

A library for 2D graphics, written in Rust, that works with multiple back-ends
MIT License
479 stars 55 forks source link

Back-end design #6

Closed bvssvni closed 10 years ago

bvssvni commented 10 years ago

One way is to have context wrap a generic type T:

pub struct Context<'a, Backend> {
  ....
   backend: &'a Backend
}
bvssvni commented 10 years ago

If I want to write Context::opengl() then there will be an 'opengl' method for every generic instance of that struct.

bvssvni commented 10 years ago

One idea is to write traits in the back-end library as new methods on top of the graphics library. This makes it possible for the back-end to choose different ways of reading out the geometry.

bvssvni commented 10 years ago

A back-end could provide different methods which the graphics library recognizes. The back-end could tell with some flags which format is preferred under which circumstances. For example, whether to use triangle strips or triangle lists, whether to use indices or to use colors per vertex.

bvssvni commented 10 years ago

One could have a context for each transform, color, rectangle etc.

There could be a type for each combination of the base context. How would this work mathematically?

bvssvni commented 10 years ago

Using a design where Rust-Graphics makes assumptions about performance and checks the back-end for supported features in performance order. Some features, such as alpha blending, can be ignored.