Add SwapchainImage struct

This commit is contained in:
Pierre Krieger 2016-03-23 18:01:32 +01:00
parent c191bb2ba3
commit 50d71b2900
2 changed files with 94 additions and 1 deletions

View File

@ -41,8 +41,9 @@ use check_errors;
use vk;
pub mod attachment;
pub mod traits;
pub mod swapchain;
pub mod sys;
pub mod traits;
pub unsafe trait AbstractImage: Resource + ::VulkanObjectU64 {
/// All images in vulkano must have a *default layout*. Whenever this image is used in a

View File

@ -0,0 +1,92 @@
use std::sync::Arc;
use command_buffer::Submission;
use format::Format;
use image::traits::AccessRange;
use image::traits::Image;
use image::traits::ImageView;
use image::sys::Layout;
use image::sys::UnsafeImage;
use image::sys::UnsafeImageView;
use image::sys::Usage;
use swapchain::Swapchain;
use OomError;
pub struct SwapchainImage {
image: UnsafeImage,
view: UnsafeImageView,
format: Format,
usage: Usage,
swapchain: Arc<Swapchain>,
}
impl SwapchainImage {
pub unsafe fn from_raw(image: UnsafeImage, format: Format, swapchain: &Arc<Swapchain>,
usage: &Usage) -> Result<Arc<SwapchainImage>, OomError>
{
let view = try!(UnsafeImageView::new(&image));
Ok(Arc::new(SwapchainImage {
image: image,
view: view,
format: format,
usage: usage.clone(),
swapchain: swapchain.clone(),
}))
}
}
unsafe impl Image for SwapchainImage {
#[inline]
fn inner_image(&self) -> &UnsafeImage {
&self.image
}
fn needs_fence(&self, access: &mut Iterator<Item = AccessRange>) -> Option<bool> {
Some(false)
}
unsafe fn gpu_access(&self, access: &mut Iterator<Item = AccessRange>,
submission: &Arc<Submission>) -> Vec<Arc<Submission>>
{
vec![]
}
}
unsafe impl ImageView for SwapchainImage {
#[inline]
fn parent(&self) -> &Image {
self
}
#[inline]
fn inner_view(&self) -> &UnsafeImageView {
&self.view
}
#[inline]
fn descriptor_set_storage_image_layout(&self, _: AccessRange) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_combined_image_sampler_layout(&self, _: AccessRange) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_sampled_image_layout(&self, _: AccessRange) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn descriptor_set_input_attachment_layout(&self, _: AccessRange) -> Layout {
Layout::ColorAttachmentOptimal
}
#[inline]
fn identity_swizzle(&self) -> bool {
true
}
}