Skip to content

Commit

Permalink
Require VertexSource<Vec<Arc<Buffer>>> for GraphicsPipelineAbstract
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Feb 22, 2017
1 parent 1db28b8 commit 64459fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
5 changes: 3 additions & 2 deletions vulkano/src/pipeline/graphics_pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;
use std::u32;
use smallvec::SmallVec;

use buffer::Buffer;
use buffer::BufferInner;
use device::Device;
use device::DeviceOwned;
Expand Down Expand Up @@ -1123,13 +1124,13 @@ impl Drop for Inner {

/// Trait implemented on objects that reference a graphics pipeline. Can be made into a trait
/// object.
pub unsafe trait GraphicsPipelineAbstract: PipelineLayoutAbstract + RenderPassAbstract /* + ... */ {
pub unsafe trait GraphicsPipelineAbstract: PipelineLayoutAbstract + RenderPassAbstract + VertexSource<Vec<Arc<Buffer>>> {
/// Returns an opaque object that represents the inside of the graphics pipeline.
fn inner(&self) -> GraphicsPipelineSys;
}

unsafe impl<Mv, L, Rp> GraphicsPipelineAbstract for GraphicsPipeline<Mv, L, Rp>
where L: PipelineLayoutAbstract, Rp: RenderPassAbstract
where L: PipelineLayoutAbstract, Rp: RenderPassAbstract, Mv: VertexSource<Vec<Arc<Buffer>>>
{
#[inline]
fn inner(&self) -> GraphicsPipelineSys {
Expand Down
34 changes: 33 additions & 1 deletion vulkano/src/pipeline/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::option::IntoIter as OptionIntoIter;
use std::sync::Arc;
use std::vec::IntoIter as VecIntoIter;

use buffer::Buffer;
use buffer::BufferInner;
use buffer::TypedBuffer;
use format::Format;
Expand Down Expand Up @@ -163,7 +165,7 @@ pub struct AttributeInfo {
}

/// Trait for types that describe the definition of the vertex input used by a graphics pipeline.
pub unsafe trait VertexDefinition<I> {
pub unsafe trait VertexDefinition<I>: VertexSource<Vec<Arc<Buffer>>> {
/// Iterator that returns the offset, the stride (in bytes) and input rate of each buffer.
type BuffersIter: ExactSizeIterator<Item = (u32, usize, InputRate)>;
/// Iterator that returns the attribute location, buffer id, and infos.
Expand Down Expand Up @@ -297,6 +299,18 @@ unsafe impl<T, I> VertexDefinition<I> for SingleBufferDefinition<T>
}
}

unsafe impl<V> VertexSource<Vec<Arc<Buffer>>> for SingleBufferDefinition<V>
where V: Vertex
{
#[inline]
fn decode<'l>(&self, source: &'l Vec<Arc<Buffer>>) -> (Vec<BufferInner<'l>>, usize, usize) {
// FIXME: safety
assert_eq!(source.len(), 1);
let len = source[0].size() / mem::size_of::<V>();
(vec![source[0].inner()], len, 1)
}
}

unsafe impl<'a, B, V> VertexSource<B> for SingleBufferDefinition<V>
where B: TypedBuffer<Content = [V]>, V: Vertex
{
Expand Down Expand Up @@ -367,6 +381,15 @@ unsafe impl<T, U, I> VertexDefinition<I> for TwoBuffersDefinition<T, U>
}
}

unsafe impl<T, U> VertexSource<Vec<Arc<Buffer>>> for TwoBuffersDefinition<T, U>
where T: Vertex, U: Vertex
{
#[inline]
fn decode<'l>(&self, source: &'l Vec<Arc<Buffer>>) -> (Vec<BufferInner<'l>>, usize, usize) {
unimplemented!() // FIXME: implement
}
}

unsafe impl<'a, T, U, Bt, Bu> VertexSource<(Bt, Bu)> for TwoBuffersDefinition<T, U>
where T: Vertex, Bt: TypedBuffer<Content = [T]>,
U: Vertex, Bu: TypedBuffer<Content = [U]>
Expand Down Expand Up @@ -439,6 +462,15 @@ unsafe impl<T, U, I> VertexDefinition<I> for OneVertexOneInstanceDefinition<T, U
}
}

unsafe impl<T, U> VertexSource<Vec<Arc<Buffer>>> for OneVertexOneInstanceDefinition<T, U>
where T: Vertex, U: Vertex
{
#[inline]
fn decode<'l>(&self, source: &'l Vec<Arc<Buffer>>) -> (Vec<BufferInner<'l>>, usize, usize) {
unimplemented!() // FIXME: implement
}
}

unsafe impl<'a, T, U, Bt, Bu> VertexSource<(Bt, Bu)> for OneVertexOneInstanceDefinition<T, U>
where T: Vertex, Bt: TypedBuffer<Content = [T]>,
U: Vertex, Bu: TypedBuffer<Content = [U]>
Expand Down

0 comments on commit 64459fc

Please # to comment.