diff --git a/vulkano/Cargo.toml b/vulkano/Cargo.toml index 743657a6..070c8739 100644 --- a/vulkano/Cargo.toml +++ b/vulkano/Cargo.toml @@ -15,6 +15,7 @@ glsl-to-spirv = { path = "../glsl-to-spirv" } vulkano-shaders = { path = "../vulkano-shaders" } [dev-dependencies] +cgmath = "0.7.0" gdi32-sys = "*" kernel32-sys = "*" user32-sys = "*" diff --git a/vulkano/examples/teapot.rs b/vulkano/examples/teapot.rs index 94c8c2fa..0c33ec4d 100644 --- a/vulkano/examples/teapot.rs +++ b/vulkano/examples/teapot.rs @@ -2,6 +2,7 @@ extern crate kernel32; extern crate gdi32; extern crate user32; extern crate winapi; +extern crate cgmath; #[macro_use] extern crate vulkano; @@ -34,8 +35,7 @@ fn main() { .expect("couldn't find a graphical queue family"); let (device, queues) = vulkano::device::Device::new(&physical, physical.supported_features(), - [(queue, 0.5)].iter().cloned(), - &[]) + [(queue, 0.5)].iter().cloned(), &[]) .expect("failed to create device"); let queue = queues.into_iter().next().unwrap(); @@ -80,18 +80,17 @@ fn main() { } } + let proj = cgmath::perspective(cgmath::rad(3.141592 / 2.0), { let d = images[0].dimensions(); d[1] as f32 / d[0] as f32 }, 0.01, 100.0); + let view = cgmath::Matrix4::look_at(cgmath::Point3::new(-2.0, 0.0, 0.4), cgmath::Point3::new(0.0, 0.0, 0.0), cgmath::Vector3::new(0.0, -1.0 /* FIXME */, 0.0)); + let scale = cgmath::Matrix4::from_scale(0.01); + let uniform_buffer = vulkano::buffer::Buffer::<[[f32; 4]; 4], _> ::new(&device, &vulkano::buffer::Usage::all(), vulkano::memory::HostVisible, &queue) .expect("failed to create buffer"); { let mut mapping = uniform_buffer.try_write().unwrap(); - *mapping = [ - [0.01, 0.0, 0.0, 0.0], - [0.0, 0.01, 0.0, 0.0], - [0.0, 0.0, 1.0, 0.0], - [0.0, 0.0, 0.0, 1.0] - ]; + *mapping = (proj * view * scale).into(); } mod vs { include!{concat!(env!("OUT_DIR"), "/examples-teapot_vs.rs")} } diff --git a/vulkano/src/image.rs b/vulkano/src/image.rs index 6c4f7890..de2d37da 100644 --- a/vulkano/src/image.rs +++ b/vulkano/src/image.rs @@ -453,8 +453,34 @@ pub struct ImagePrototype where Ty: ImageTypeMarker { } impl ImagePrototype - where Ty: ImageTypeMarker + where M: MemorySourceChunk, Ty: ImageTypeMarker, F: FormatMarker { + /// Returns the dimensions of this image. + #[inline] + pub fn dimensions(&self) -> Ty::Dimensions { + self.image.dimensions() + } + + /// Returns the number of array layers of this image. + #[inline] + pub fn array_layers(&self) -> u32 { + self.image.array_layers() + } + + /// Returns the number of mipmap levels of this image. + #[inline] + pub fn mipmap_levels(&self) -> u32 { + self.image.mipmap_levels() + } + + /// Returns the number of samples of each pixel of this image. + /// + /// Returns `1` if the image is not multisampled. + #[inline] + pub fn num_samples(&self) -> u32 { + self.image.num_samples() + } + /// Transitions the image prototype into a real image by submitting a one-shot command buffer. /// /// # Panic