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

Simplify draw state #996

Closed
bvssvni opened this issue Sep 2, 2015 · 3 comments
Closed

Simplify draw state #996

bvssvni opened this issue Sep 2, 2015 · 3 comments
Assignees
Labels

Comments

@bvssvni
Copy link
Member

bvssvni commented Sep 2, 2015

Instead of converting from one draw state API to another, an idea is to use a simplified draw state that cover the use cases we have today.

pub struct DrawState {
    pub blend: Blend,
    pub stencil: Option<Stencil>,
    pub scissor: Option<[u32; 4]>,
}

impl Default for DrawState {
    fn default() -> Self {
        DrawState {
            blend: Blend::Alpha,
            stencil: None,
            scissor: None,
        }
    }
}

pub enum Blend {
    Alpha,
    Add,
    Multiply,
    Invert,
}

pub enum Stencil {
    Clip(u8),
    Inside(u8),
    Outside(u8),
}
bvssvni added a commit to bvssvni/graphics that referenced this issue Sep 2, 2015
@bvssvni
Copy link
Member Author

bvssvni commented Sep 5, 2015

Since additive blending gives different effect than adding color components for semi-transparent colors (see #1001), I suggest that we remove Add and Multiply to avoid confusion. Instead we could add a variant that lets you control the equations in more detail.

@bvssvni
Copy link
Member Author

bvssvni commented Sep 5, 2015

There seem to be several blending techniques with different benefits/drawbacks:

  • Simple: A linear equation with two terms as implemented in fixed hardware pipelines
  • Pre-multiplied alpha: Simple + a step in the fragment shader that preprocesses the colors
  • Porter/Duff: A complete algebra for blending that requires an additional term with the product of both source and destination alpha channel

@bvssvni
Copy link
Member Author

bvssvni commented Feb 2, 2016

I am considering implementing this for the new Gfx design. See #1030.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant