Now generating a struct for the values of the cleared attachments

This commit is contained in:
Pierre Krieger 2016-03-13 14:14:56 +01:00
parent 3dae5ccdc3
commit 9365d3b2e8
4 changed files with 62 additions and 6 deletions

View File

@ -218,7 +218,9 @@ fn main() {
vulkano::command_buffer::PrimaryCommandBufferBuilder::new(&cb_pool).unwrap()
.copy_buffer_to_color_image(&pixel_buffer, &texture)
//.clear_color_image(&texture, [0.0, 1.0, 0.0, 1.0])
.draw_inline(&renderpass, &framebuffer, ([0.0, 0.0, 1.0, 1.0],))
.draw_inline(&renderpass, &framebuffer, renderpass::ClearValues {
color: [0.0, 0.0, 1.0, 1.0]
})
.draw(&pipeline, &vertex_buffer, &vulkano::command_buffer::DynamicState::none(), set.clone())
.draw_end()
.build().unwrap()

View File

@ -208,7 +208,10 @@ fn main() {
let command_buffers = framebuffers.iter().map(|framebuffer| {
vulkano::command_buffer::PrimaryCommandBufferBuilder::new(&cb_pool).unwrap()
.draw_inline(&renderpass, &framebuffer, ([0.0, 0.0, 1.0, 1.0], 1.0))
.draw_inline(&renderpass, &framebuffer, renderpass::ClearValues {
color: [0.0, 0.0, 1.0, 1.0],
depth: 1.0,
})
.draw_indexed(&pipeline, (&vertex_buffer, &normals_buffer), &index_buffer, &vulkano::command_buffer::DynamicState::none(), set.clone())
.draw_end()
.build().unwrap()

View File

@ -670,6 +670,8 @@ pub enum ClearValue {
DepthStencil((f32, u32)),
}
// TODO: remove all these From implementations once they are no longer needed
impl From<[f32; 1]> for ClearValue {
#[inline]
fn from(val: [f32; 1]) -> ClearValue {
@ -775,6 +777,8 @@ impl From<(f32, u32)> for ClearValue {
}
}
// TODO: remove once no longer needed
pub unsafe trait ClearValuesTuple {
type Iter: Iterator<Item = ClearValue>;
fn iter(self) -> Self::Iter;

View File

@ -350,6 +350,7 @@ macro_rules! ordered_passes_renderpass {
) => {
use std; // TODO: import everything instead
use std::sync::Arc;
use $crate::format::ClearValue;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Layout;
@ -445,17 +446,63 @@ macro_rules! ordered_passes_renderpass {
}
}
pub type ClearValues = ($(<$crate::format::$format as $crate::format::FormatDesc>::ClearValue,)*); // TODO: only attachments with ClearOp should be in there
ordered_passes_renderpass!{__impl_clear_values__ [0] [] [$($atch_name $format $load,)*] }
unsafe impl $crate::framebuffer::LayoutClearValues<ClearValues> for Layout {
type ClearValuesIter = std::vec::IntoIter<$crate::format::ClearValue>;
type ClearValuesIter = ClearValuesIter;
#[inline]
fn convert_clear_values(&self, val: ClearValues) -> Self::ClearValuesIter {
$crate::format::ClearValuesTuple::iter(val)
fn convert_clear_values(&self, val: ClearValues) -> ClearValuesIter {
ClearValuesIter(val, 0)
}
}
};
(__impl_clear_values__ [$num:expr] [$($s:tt)*] [$atch_name:ident $format:ident Clear, $($rest:tt)*]) => {
ordered_passes_renderpass!{__impl_clear_values__ [$num+1] [$($s)* $atch_name [$num] $format,] [$($rest)*] }
};
(__impl_clear_values__ [$num:expr] [$($s:tt)*] [$atch_name:ident $format:ident $misc:ident, $($rest:tt)*]) => {
ordered_passes_renderpass!{__impl_clear_values__ [$num+1] [$($s)*] [$($rest)*] }
};
(__impl_clear_values__ [$total:expr] [$($atch:ident [$num:expr] $format:ident,)*] []) => {
pub struct ClearValues {
$(
pub $atch: <$crate::format::$format as $crate::format::FormatDesc>::ClearValue,
)*
}
pub struct ClearValuesIter(ClearValues, usize);
impl Iterator for ClearValuesIter {
type Item = $crate::format::ClearValue;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
$(
if self.1 == $num {
self.1 += 1;
return Some(ClearValue::from((self.0).$atch)); // FIXME: should use Format::decode_clear_value instead
}
)+
if self.1 >= $total {
None
} else {
Some(ClearValue::None)
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = $total - self.1;
(len, Some(len))
}
}
impl ExactSizeIterator for ClearValuesIter {}
};
}
/// Describes what the implementation should do with an attachment after all the subpasses have