depth testing
This commit is contained in:
@@ -17,7 +17,7 @@ use num_traits::identities::One;
|
||||
use piston_window::{PistonWindow, Window, WindowSettings};
|
||||
|
||||
pub type ColorFormat = gfx::format::Srgba8;
|
||||
//pub type DepthFormat = gfx::format::DepthStencil;
|
||||
pub type DepthFormat = gfx::format::DepthStencil;
|
||||
|
||||
const NEAR: f32 = 0.01;
|
||||
const FAR: f32 = 1000.0;
|
||||
@@ -36,6 +36,7 @@ gfx_defines!{
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
trans: gfx::ConstantBuffer<Trans> = "b_trans",
|
||||
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
|
||||
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +64,9 @@ fn main() {
|
||||
pipe::new())
|
||||
.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");
|
||||
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");
|
||||
let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX);
|
||||
|
||||
@@ -73,16 +74,19 @@ fn main() {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
pixcolor: window.output_color.clone(),
|
||||
depth: window.output_stencil.clone(),
|
||||
};
|
||||
let pipe_left = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
pixcolor: tgt_left,
|
||||
depth: depth_left,
|
||||
};
|
||||
let pipe_right = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
pixcolor: tgt_right,
|
||||
depth: depth_right,
|
||||
};
|
||||
window.encoder.update_constant_buffer(
|
||||
&pipe_monitor.trans,
|
||||
@@ -128,6 +132,7 @@ fn main() {
|
||||
.into_iter() {
|
||||
info!("\tpass for eye: {:?}", pass.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
|
||||
if let Some((eye, tex)) = pass.0 {
|
||||
|
||||
29
src/vr.rs
29
src/vr.rs
@@ -5,10 +5,11 @@ extern crate num_traits;
|
||||
extern crate openvr as vr;
|
||||
extern crate openvr_sys;
|
||||
|
||||
use self::gfx::{tex, Factory, Typed};
|
||||
|
||||
pub use self::vr::Eye;
|
||||
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::num_traits::identities::Zero;
|
||||
use self::num_traits::identities::One;
|
||||
@@ -16,7 +17,7 @@ use self::num_traits::identities::One;
|
||||
pub struct VR {
|
||||
system: vr::IVRSystem,
|
||||
compositor: vr::IVRCompositor,
|
||||
gfx_handles: gfx::handle::Manager<gfx_device_gl::Resources>,
|
||||
gfx_handles: gfx::handle::Manager<GLResources>,
|
||||
}
|
||||
|
||||
impl VR {
|
||||
@@ -33,7 +34,7 @@ impl VR {
|
||||
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()) {
|
||||
&gfx_device_gl::NewTexture::Surface(id) => id,
|
||||
_ => 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,
|
||||
size: vr::common::Size)
|
||||
-> Result<(gfx::handle::Texture<gfx_device_gl::Resources,
|
||||
T::Surface>,
|
||||
gfx::handle::RenderTargetView<gfx_device_gl::Resources,
|
||||
T>),
|
||||
gfx::CombinedError>
|
||||
where T: gfx::format::RenderFormat + gfx::format::TextureFormat {
|
||||
pub fn create_eyebuffer<T, D>(factory: &mut gfx_device_gl::Factory,
|
||||
size: vr::common::Size)
|
||||
-> Result<(gfx::handle::Texture<GLResources, T::Surface>,
|
||||
gfx::handle::RenderTargetView<GLResources, T>,
|
||||
gfx::handle::DepthStencilView<GLResources, D>),
|
||||
gfx::CombinedError>
|
||||
where T: gfx::format::RenderFormat + gfx::format::TextureFormat,
|
||||
D: gfx::format::DepthFormat + gfx::format::TextureFormat {
|
||||
let tex = try!(factory.create_texture(
|
||||
tex::Kind::D2(size.width as tex::Size, size.height as tex::Size, tex::AaMode::Single),
|
||||
1, // levels
|
||||
@@ -101,5 +102,7 @@ pub fn create_eyebuffer<T>(factory: &mut gfx_device_gl::Factory,
|
||||
gfx::Usage::GpuOnly, // Usage
|
||||
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));
|
||||
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user