Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put draw state in Graphics #1087

Open
bvssvni opened this issue Sep 14, 2017 · 0 comments
Open

Put draw state in Graphics #1087

bvssvni opened this issue Sep 14, 2017 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Sep 14, 2017

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 Graphics trait, 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:

  1. Add two new method to Graphics:
  • fn set_draw_state(&mut self, &DrawState)
  • fn get_draw_state(&self) -> DrawState
  1. Remove Context::draw_state
  2. Remove draw state parameters on draw methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant