Skip to content

Commit

Permalink
Simplify draw state
Browse files Browse the repository at this point in the history
  • Loading branch information
bvssvni committed Sep 2, 2015
1 parent 6c4b66c commit 4c53e61
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 223 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ name = "graphics"
path = "./src/lib.rs"

[dependencies]
draw_state = "0.2.0"
interpolation = "0.1.0"
piston-texture = "0.2.1"
piston-viewport = "0.1.0"
Expand Down
55 changes: 0 additions & 55 deletions src/clip_draw_state.rs

This file was deleted.

7 changes: 3 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Transformation context

use draw_state::DrawState;
use default_draw_state;
use math::{
abs_transform,
identity,
Expand Down Expand Up @@ -33,7 +32,7 @@ impl Context {
Context {
view: identity(),
transform: identity(),
draw_state: *default_draw_state(),
draw_state: Default::default(),
viewport: None,
}
}
Expand All @@ -54,7 +53,7 @@ impl Context {
Context {
view: mat,
transform: mat,
draw_state: *default_draw_state(),
draw_state: Default::default(),
viewport: Some(viewport),
}
}
Expand All @@ -75,7 +74,7 @@ impl Context {
Context {
view: mat,
transform: mat,
draw_state: *default_draw_state(),
draw_state: Default::default(),
viewport: None,
}
}
Expand Down
36 changes: 0 additions & 36 deletions src/default_draw_state.rs

This file was deleted.

113 changes: 113 additions & 0 deletions src/draw_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//! Draw state parameters.

/// Draw state parameters.
#[derive(Copy, Clone)]
pub struct DrawState {
/// Blend effect.
pub blend: Blend,
/// Stencil effect.
pub stencil: Option<Stencil>,
/// Scissor rectangle.
/// Limits the area of rendered pixels.
/// Uses frame buffer coordinates.
pub scissor: Option<[u32; 4]>,
}

impl DrawState {
/// Clip draw state.
pub fn clip(mut self) -> DrawState {
self.stencil = Some(Stencil::Clip(1));
self
}

/// Inside draw state.
pub fn inside(mut self) -> DrawState {
self.stencil = Some(Stencil::Inside(1));
self
}

/// Outside draw state.
pub fn outside(mut self) -> DrawState {
self.stencil = Some(Stencil::Outside(1));
self
}

/// Blend effect.
pub fn blend(mut self, blend: Blend) -> DrawState {
self.blend = blend;
self
}

/// Stencil effect.
pub fn stencil(mut self, stencil: Stencil) -> DrawState {
self.stencil = Some(stencil);
self
}

/// Scissor rectangle.
pub fn scissor(mut self, scissor: [u32; 4]) -> DrawState {
self.scissor = Some(scissor);
self
}
}

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

#[derive(Copy, Clone)]
/// Blend effect.
///
/// This effect is applied after shaders.
/// Most hardware supports simple blending effects.
///
/// Simple blend effects are documented with their corresponding fixed
/// pipeline blending equation.
///
/// blend_equation: `source * (blend_parameter) <op> destination * (blend_parameter)`
pub enum Blend {
/// Alpha blends colors.
///
/// color: `source * (source_alpha) + destination * (1 - source_alpha)`
///
/// alpha: `source * (1) + destination * (1)`
Alpha,
/// Adds color components.
///
/// color: `source * (1) + destination * (1)`
///
/// alpha: `source * (1) + destination * (1)`
Add,
/// Multiplies the color components.
///
/// color: `source * (destination) + destination * (0)`
///
/// alpha: `source * (destination_alpha) + destination * (0)`
Multiply,
/// Inverts the rendered color.
///
/// color: `source * (1) - destination * (source)`
///
/// alpha: `source * (0) + destination * (1)`.
Invert,
}

#[derive(Copy, Clone)]
/// Stencil effect.
pub enum Stencil {
/// Assign stencil value to pixels that are rendered invisible.
/// This is used to define the area of clipping.
Clip(u8),
/// Renders pixels that has a stencil value.
/// This is used to render inside an area of clipping.
Inside(u8),
/// Renders pixels that does not have a stencil value.
/// This is used to render outside an area of clipping.
Outside(u8),
}
55 changes: 0 additions & 55 deletions src/inside_draw_state.rs

This file was deleted.

Loading

0 comments on commit 4c53e61

Please sign in to comment.