Fix GPU abstraction
This commit is contained in:
parent
8b4c06fe2a
commit
6b9adcb6fc
|
@ -48,15 +48,25 @@ impl GLDevice {
|
||||||
BlendState::Off => {
|
BlendState::Off => {
|
||||||
gl::Disable(gl::BLEND); ck();
|
gl::Disable(gl::BLEND); ck();
|
||||||
}
|
}
|
||||||
|
BlendState::RGBOneAlphaOne => {
|
||||||
|
gl::BlendEquation(gl::FUNC_ADD); ck();
|
||||||
|
gl::BlendFunc(gl::ONE, gl::ONE); ck();
|
||||||
|
gl::Enable(gl::BLEND); ck();
|
||||||
|
}
|
||||||
BlendState::RGBOneAlphaOneMinusSrcAlpha => {
|
BlendState::RGBOneAlphaOneMinusSrcAlpha => {
|
||||||
|
gl::BlendEquation(gl::FUNC_ADD); ck();
|
||||||
gl::BlendFuncSeparate(gl::ONE,
|
gl::BlendFuncSeparate(gl::ONE,
|
||||||
gl::ONE_MINUS_SRC_ALPHA,
|
gl::ONE_MINUS_SRC_ALPHA,
|
||||||
gl::ONE,
|
gl::ONE,
|
||||||
gl::ONE); ck();
|
gl::ONE); ck();
|
||||||
gl::Enable(gl::BLEND); ck();
|
gl::Enable(gl::BLEND); ck();
|
||||||
}
|
}
|
||||||
BlendState::RGBOneAlphaOne => {
|
BlendState::RGBSrcAlphaAlphaOneMinusSrcAlpha => {
|
||||||
gl::BlendFunc(gl::ONE, gl::ONE); ck();
|
gl::BlendEquation(gl::FUNC_ADD); ck();
|
||||||
|
gl::BlendFuncSeparate(gl::SRC_ALPHA,
|
||||||
|
gl::ONE_MINUS_SRC_ALPHA,
|
||||||
|
gl::ONE,
|
||||||
|
gl::ONE); ck();
|
||||||
gl::Enable(gl::BLEND); ck();
|
gl::Enable(gl::BLEND); ck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,9 +77,9 @@ impl GLDevice {
|
||||||
gl::Disable(gl::DEPTH_TEST); ck();
|
gl::Disable(gl::DEPTH_TEST); ck();
|
||||||
}
|
}
|
||||||
Some(ref state) => {
|
Some(ref state) => {
|
||||||
gl::Enable(gl::DEPTH_TEST); ck();
|
|
||||||
gl::DepthFunc(state.func.to_gl_depth_func()); ck();
|
gl::DepthFunc(state.func.to_gl_depth_func()); ck();
|
||||||
gl::DepthMask(state.write as GLboolean); ck();
|
gl::DepthMask(state.write as GLboolean); ck();
|
||||||
|
gl::Enable(gl::DEPTH_TEST); ck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +92,13 @@ impl GLDevice {
|
||||||
gl::StencilFunc(state.func.to_gl_stencil_func(),
|
gl::StencilFunc(state.func.to_gl_stencil_func(),
|
||||||
state.reference as GLint,
|
state.reference as GLint,
|
||||||
state.mask); ck();
|
state.mask); ck();
|
||||||
let pass_action = if state.pass_replace { gl::REPLACE } else { gl::KEEP };
|
let (pass_action, write_mask) = if state.write {
|
||||||
|
(gl::REPLACE, state.mask)
|
||||||
|
} else {
|
||||||
|
(gl::KEEP, 0)
|
||||||
|
};
|
||||||
gl::StencilOp(gl::KEEP, gl::KEEP, pass_action); ck();
|
gl::StencilOp(gl::KEEP, gl::KEEP, pass_action); ck();
|
||||||
|
gl::StencilMask(write_mask);
|
||||||
gl::Enable(gl::STENCIL_TEST); ck();
|
gl::Enable(gl::STENCIL_TEST); ck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +113,9 @@ impl GLDevice {
|
||||||
unsafe {
|
unsafe {
|
||||||
match render_state.blend {
|
match render_state.blend {
|
||||||
BlendState::Off => {}
|
BlendState::Off => {}
|
||||||
BlendState::RGBOneAlphaOneMinusSrcAlpha | BlendState::RGBOneAlphaOne => {
|
BlendState::RGBOneAlphaOneMinusSrcAlpha |
|
||||||
|
BlendState::RGBOneAlphaOne |
|
||||||
|
BlendState::RGBSrcAlphaAlphaOneMinusSrcAlpha => {
|
||||||
gl::Disable(gl::BLEND); ck();
|
gl::Disable(gl::BLEND); ck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +125,7 @@ impl GLDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
if render_state.stencil.is_some() {
|
if render_state.stencil.is_some() {
|
||||||
|
gl::StencilMask(!0); ck();
|
||||||
gl::Disable(gl::STENCIL_TEST); ck();
|
gl::Disable(gl::STENCIL_TEST); ck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,14 +454,17 @@ impl Device for GLDevice {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut flags = 0;
|
let mut flags = 0;
|
||||||
if let Some(color) = color {
|
if let Some(color) = color {
|
||||||
|
gl::ColorMask(gl::TRUE, gl::TRUE, gl::TRUE, gl::TRUE); ck();
|
||||||
gl::ClearColor(color.x(), color.y(), color.z(), color.w()); ck();
|
gl::ClearColor(color.x(), color.y(), color.z(), color.w()); ck();
|
||||||
flags |= gl::COLOR_BUFFER_BIT;
|
flags |= gl::COLOR_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
if let Some(depth) = depth {
|
if let Some(depth) = depth {
|
||||||
|
gl::DepthMask(gl::TRUE); ck();
|
||||||
gl::ClearDepth(depth as GLdouble); ck();
|
gl::ClearDepth(depth as GLdouble); ck();
|
||||||
flags |= gl::DEPTH_BUFFER_BIT;
|
flags |= gl::DEPTH_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
if let Some(stencil) = stencil {
|
if let Some(stencil) = stencil {
|
||||||
|
gl::StencilMask(!0); ck();
|
||||||
gl::ClearStencil(stencil as GLint); ck();
|
gl::ClearStencil(stencil as GLint); ck();
|
||||||
flags |= gl::STENCIL_BUFFER_BIT;
|
flags |= gl::STENCIL_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ impl<D> Renderer<D> where D: Device {
|
||||||
self.device.set_uniform(&self.mask_tile_program.view_box_origin_uniform,
|
self.device.set_uniform(&self.mask_tile_program.view_box_origin_uniform,
|
||||||
UniformData::Vec2(F32x4::default()));
|
UniformData::Vec2(F32x4::default()));
|
||||||
let render_state = RenderState {
|
let render_state = RenderState {
|
||||||
blend: BlendState::RGBOneAlphaOneMinusSrcAlpha,
|
blend: BlendState::RGBSrcAlphaAlphaOneMinusSrcAlpha,
|
||||||
stencil: self.stencil_state(),
|
stencil: self.stencil_state(),
|
||||||
..RenderState::default()
|
..RenderState::default()
|
||||||
};
|
};
|
||||||
|
@ -400,7 +400,7 @@ impl<D> Renderer<D> where D: Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.device.draw_arrays(Primitive::TriangleFan, 4, &RenderState {
|
self.device.draw_arrays(Primitive::TriangleFan, 4, &RenderState {
|
||||||
blend: BlendState::RGBOneAlphaOneMinusSrcAlpha,
|
blend: BlendState::RGBSrcAlphaAlphaOneMinusSrcAlpha,
|
||||||
..RenderState::default()
|
..RenderState::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ impl<D> Renderer<D> where D: Device {
|
||||||
func: StencilFunc::Always,
|
func: StencilFunc::Always,
|
||||||
reference: 1,
|
reference: 1,
|
||||||
mask: 1,
|
mask: 1,
|
||||||
pass_replace: true,
|
write: true,
|
||||||
}),
|
}),
|
||||||
color_mask: false,
|
color_mask: false,
|
||||||
..RenderState::default()
|
..RenderState::default()
|
||||||
|
@ -467,7 +467,7 @@ impl<D> Renderer<D> where D: Device {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(StencilState { func: StencilFunc::Equal, reference: 1, mask: 1, pass_replace: false })
|
Some(StencilState { func: StencilFunc::Equal, reference: 1, mask: 1, write: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ pub enum Primitive {
|
||||||
Lines,
|
Lines,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RenderState {
|
pub struct RenderState {
|
||||||
pub blend: BlendState,
|
pub blend: BlendState,
|
||||||
pub depth: Option<DepthState>,
|
pub depth: Option<DepthState>,
|
||||||
|
@ -176,8 +176,9 @@ pub struct RenderState {
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum BlendState {
|
pub enum BlendState {
|
||||||
Off,
|
Off,
|
||||||
RGBOneAlphaOneMinusSrcAlpha,
|
|
||||||
RGBOneAlphaOne,
|
RGBOneAlphaOne,
|
||||||
|
RGBOneAlphaOneMinusSrcAlpha,
|
||||||
|
RGBSrcAlphaAlphaOneMinusSrcAlpha,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Debug)]
|
#[derive(Clone, Copy, Default, Debug)]
|
||||||
|
@ -197,7 +198,7 @@ pub struct StencilState {
|
||||||
pub func: StencilFunc,
|
pub func: StencilFunc,
|
||||||
pub reference: u32,
|
pub reference: u32,
|
||||||
pub mask: u32,
|
pub mask: u32,
|
||||||
pub pass_replace: bool,
|
pub write: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
@ -207,6 +208,13 @@ pub enum StencilFunc {
|
||||||
NotEqual,
|
NotEqual,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RenderState {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> RenderState {
|
||||||
|
RenderState { blend: BlendState::default(), depth: None, stencil: None, color_mask: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for BlendState {
|
impl Default for BlendState {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> BlendState {
|
fn default() -> BlendState {
|
||||||
|
@ -217,7 +225,7 @@ impl Default for BlendState {
|
||||||
impl Default for StencilState {
|
impl Default for StencilState {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> StencilState {
|
fn default() -> StencilState {
|
||||||
StencilState { func: StencilFunc::default(), reference: 0, mask: !0, pass_replace: false }
|
StencilState { func: StencilFunc::default(), reference: 0, mask: !0, write: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue