Skip to content

Put draw state in Graphics #1087

@bvssvni

Description

@bvssvni

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions