-
-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
Description
Currently, you pass the draw state as argument to every draw method on the backend implementing the Graphics trait. The benefit of this design is that the API is state-less: The draw state object keeps track of the state of the backend.
However, in practice there are some downsides to this approach:
- Most code never changes the default draw state. It is mostly used for stencil clipping and scissoring, which changes infrequently.
- Passing in draw state leads to typing more code.
- The backend code, to perform efficiently, needs a state for the draw state and detecting when to pack the vertices into buffers anyway. Checking the draw state for equality against previously set draw state leads to unnecessary overhead. When changing the draw state through the
Graphicstrait, the backend can do this directly and detect whether flushing of buffers is required. - Instead of manipulating the draw state for clipping, one could use a separate object with a method taking a closure that changes the draw state and sets it back end to previous state when done.
Plan:
- Add two new method to
Graphics:
fn set_draw_state(&mut self, &DrawState)fn get_draw_state(&self) -> DrawState
- Remove
Context::draw_state - Remove draw state parameters on draw methods