depth testing

This commit is contained in:
2016-09-15 00:21:13 -07:00
parent a7562b449c
commit 9f7246efba
2 changed files with 24 additions and 16 deletions

View File

@@ -17,7 +17,7 @@ use num_traits::identities::One;
use piston_window::{PistonWindow, Window, WindowSettings}; use piston_window::{PistonWindow, Window, WindowSettings};
pub type ColorFormat = gfx::format::Srgba8; pub type ColorFormat = gfx::format::Srgba8;
//pub type DepthFormat = gfx::format::DepthStencil; pub type DepthFormat = gfx::format::DepthStencil;
const NEAR: f32 = 0.01; const NEAR: f32 = 0.01;
const FAR: f32 = 1000.0; const FAR: f32 = 1000.0;
@@ -36,6 +36,7 @@ gfx_defines!{
vbuf: gfx::VertexBuffer<Vertex> = (), vbuf: gfx::VertexBuffer<Vertex> = (),
trans: gfx::ConstantBuffer<Trans> = "b_trans", trans: gfx::ConstantBuffer<Trans> = "b_trans",
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor", pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
} }
} }
@@ -63,9 +64,9 @@ fn main() {
pipe::new()) pipe::new())
.expect("create pipeline"); .expect("create pipeline");
let (tex_left, tgt_left) = vr::create_eyebuffer(&mut window.factory, render_size) let (tex_left, tgt_left, depth_left) = vr::create_eyebuffer(&mut window.factory, render_size)
.expect("create left renderbuffer"); .expect("create left renderbuffer");
let (tex_right, tgt_right) = vr::create_eyebuffer(&mut window.factory, render_size) let (tex_right, tgt_right, depth_right) = vr::create_eyebuffer(&mut window.factory, render_size)
.expect("create right renderbuffer"); .expect("create right renderbuffer");
let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX); let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX);
@@ -73,16 +74,19 @@ fn main() {
vbuf: vertex_buffer.clone(), vbuf: vertex_buffer.clone(),
trans: window.factory.create_constant_buffer(1), trans: window.factory.create_constant_buffer(1),
pixcolor: window.output_color.clone(), pixcolor: window.output_color.clone(),
depth: window.output_stencil.clone(),
}; };
let pipe_left = pipe::Data { let pipe_left = pipe::Data {
vbuf: vertex_buffer.clone(), vbuf: vertex_buffer.clone(),
trans: window.factory.create_constant_buffer(1), trans: window.factory.create_constant_buffer(1),
pixcolor: tgt_left, pixcolor: tgt_left,
depth: depth_left,
}; };
let pipe_right = pipe::Data { let pipe_right = pipe::Data {
vbuf: vertex_buffer.clone(), vbuf: vertex_buffer.clone(),
trans: window.factory.create_constant_buffer(1), trans: window.factory.create_constant_buffer(1),
pixcolor: tgt_right, pixcolor: tgt_right,
depth: depth_right,
}; };
window.encoder.update_constant_buffer( window.encoder.update_constant_buffer(
&pipe_monitor.trans, &pipe_monitor.trans,
@@ -128,6 +132,7 @@ fn main() {
.into_iter() { .into_iter() {
info!("\tpass for eye: {:?}", pass.0); info!("\tpass for eye: {:?}", pass.0);
window.encoder.clear(&pass.1.pixcolor, [0.1, 0.2, 0.3, 1.0]); window.encoder.clear(&pass.1.pixcolor, [0.1, 0.2, 0.3, 1.0]);
window.encoder.clear_depth(&pass.1.depth, 1.0);
// Submit eye textures // Submit eye textures
if let Some((eye, tex)) = pass.0 { if let Some((eye, tex)) = pass.0 {

View File

@@ -5,10 +5,11 @@ extern crate num_traits;
extern crate openvr as vr; extern crate openvr as vr;
extern crate openvr_sys; extern crate openvr_sys;
use self::gfx::{tex, Factory, Typed};
pub use self::vr::Eye; pub use self::vr::Eye;
pub use self::vr::tracking::TrackedDeviceClass; pub use self::vr::tracking::TrackedDeviceClass;
use self::gfx::{tex, Factory, Typed};
use self::gfx_device_gl::Resources as GLResources;
use self::na::Inverse; use self::na::Inverse;
use self::num_traits::identities::Zero; use self::num_traits::identities::Zero;
use self::num_traits::identities::One; use self::num_traits::identities::One;
@@ -16,7 +17,7 @@ use self::num_traits::identities::One;
pub struct VR { pub struct VR {
system: vr::IVRSystem, system: vr::IVRSystem,
compositor: vr::IVRCompositor, compositor: vr::IVRCompositor,
gfx_handles: gfx::handle::Manager<gfx_device_gl::Resources>, gfx_handles: gfx::handle::Manager<GLResources>,
} }
impl VR { impl VR {
@@ -33,7 +34,7 @@ impl VR {
self.compositor.wait_get_poses() self.compositor.wait_get_poses()
} }
pub fn submit<T>(&mut self, eye: Eye, tex: &gfx::handle::Texture<gfx_device_gl::Resources, T>) { pub fn submit<T>(&mut self, eye: Eye, tex: &gfx::handle::Texture<GLResources, T>) {
let tex_id = match self.gfx_handles.ref_texture(tex.raw()) { let tex_id = match self.gfx_handles.ref_texture(tex.raw()) {
&gfx_device_gl::NewTexture::Surface(id) => id, &gfx_device_gl::NewTexture::Surface(id) => id,
_ => panic!("Not a surface") _ => panic!("Not a surface")
@@ -86,14 +87,14 @@ impl<N: Copy> AsMatrix4<N> for [[N; 4]; 4] {
} }
} }
pub fn create_eyebuffer<T>(factory: &mut gfx_device_gl::Factory, pub fn create_eyebuffer<T, D>(factory: &mut gfx_device_gl::Factory,
size: vr::common::Size) size: vr::common::Size)
-> Result<(gfx::handle::Texture<gfx_device_gl::Resources, -> Result<(gfx::handle::Texture<GLResources, T::Surface>,
T::Surface>, gfx::handle::RenderTargetView<GLResources, T>,
gfx::handle::RenderTargetView<gfx_device_gl::Resources, gfx::handle::DepthStencilView<GLResources, D>),
T>), gfx::CombinedError>
gfx::CombinedError> where T: gfx::format::RenderFormat + gfx::format::TextureFormat,
where T: gfx::format::RenderFormat + gfx::format::TextureFormat { D: gfx::format::DepthFormat + gfx::format::TextureFormat {
let tex = try!(factory.create_texture( let tex = try!(factory.create_texture(
tex::Kind::D2(size.width as tex::Size, size.height as tex::Size, tex::AaMode::Single), tex::Kind::D2(size.width as tex::Size, size.height as tex::Size, tex::AaMode::Single),
1, // levels 1, // levels
@@ -101,5 +102,7 @@ pub fn create_eyebuffer<T>(factory: &mut gfx_device_gl::Factory,
gfx::Usage::GpuOnly, // Usage gfx::Usage::GpuOnly, // Usage
Some(<T::Channel as gfx::format::ChannelTyped>::get_channel_type()))); // hint: format::ChannelType? Some(<T::Channel as gfx::format::ChannelTyped>::get_channel_type()))); // hint: format::ChannelType?
let tgt = try!(factory.view_texture_as_render_target(&tex, 0, None)); let tgt = try!(factory.view_texture_as_render_target(&tex, 0, None));
Ok((tex, tgt)) let depth = try!(factory.create_depth_stencil_view_only(size.width as tex::Size,
size.height as tex::Size));
Ok((tex, tgt, depth))
} }