add z-buffering to glow/wasm backends. helps #21

This commit is contained in:
Dustin Carlino 2020-03-17 11:16:22 -07:00
parent 0bcbac1fee
commit ad4ebeeb61
2 changed files with 30 additions and 3 deletions

View File

@ -1,9 +1,8 @@
use crate::drawing::Uniforms;
use crate::{Canvas, Color, ScreenDims, ScreenRectangle};
use geom::{Angle, Polygon, Pt2D};
use geom::Polygon;
use glow::HasContext;
use std::cell::{Cell, RefCell};
use std::collections::{BTreeMap, HashMap};
use std::cell::Cell;
pub fn setup(
window_title: &str,
@ -60,6 +59,17 @@ pub fn setup(
gl.use_program(Some(program));
gl.enable(glow::SCISSOR_TEST);
gl.enable(glow::DEPTH_TEST);
gl.depth_func(glow::LEQUAL);
gl.enable(glow::BLEND);
gl.blend_func_separate(
glow::SRC_ALPHA,
glow::ONE_MINUS_SRC_ALPHA,
glow::SRC_ALPHA,
glow::ONE_MINUS_SRC_ALPHA,
);
}
let window_size = event_loop.primary_monitor().size();
@ -90,6 +100,9 @@ impl<'a> GfxCtxInnards<'a> {
Color::RGBA(r, g, b, a) => unsafe {
self.gl.clear_color(r, g, b, a);
self.gl.clear(glow::COLOR_BUFFER_BIT);
self.gl.clear_depth_f32(1.0);
self.gl.clear(glow::DEPTH_BUFFER_BIT);
},
_ => unreachable!(),
}

View File

@ -81,6 +81,17 @@ pub fn setup(
gl.use_program(Some(program));
gl.enable(glow::SCISSOR_TEST);
gl.enable(glow::DEPTH_TEST);
gl.depth_func(glow::LEQUAL);
gl.enable(glow::BLEND);
gl.blend_func_separate(
glow::SRC_ALPHA,
glow::ONE_MINUS_SRC_ALPHA,
glow::SRC_ALPHA,
glow::ONE_MINUS_SRC_ALPHA,
);
}
(
@ -109,6 +120,9 @@ impl<'a> GfxCtxInnards<'a> {
Color::RGBA(r, g, b, a) => unsafe {
self.gl.clear_color(r, g, b, a);
self.gl.clear(glow::COLOR_BUFFER_BIT);
self.gl.clear_depth_f32(1.0);
self.gl.clear(glow::DEPTH_BUFFER_BIT);
},
_ => unreachable!(),
}