byte-engine-ghi 0.1.0

Graphics hardware interface layer used by Byte-Engine.
use std::num::NonZeroU32;

use ash::vk;
use utils::Extent;

use crate::{image::ImageHandle, DeviceAccesses, Formats, HandleLike, Next, Uses};

/// The `Image` struct provides Vulkan resources and views for GHI images.
///
/// Swapchain-backed images keep native handles and image views. They chain across
/// frames through `next`, do not own the images, and do not keep their extents.
#[derive(Clone)]
pub(crate) struct Image {
	pub(crate) next: Option<ImageHandle>,
	pub(crate) staging_buffer: Option<vk::Buffer>,
	pub(crate) pointer: Option<*mut u8>,
	pub(crate) image: vk::Image,
	pub(crate) full_image_view: vk::ImageView,
	pub(crate) image_views: [vk::ImageView; 8],
	pub(crate) extent: Extent,
	pub(crate) format: vk::Format,
	pub(crate) format_: Formats,
	pub(crate) access: DeviceAccesses,
	pub(crate) size: usize,
	pub(crate) uses: Uses,
	pub(crate) layers: Option<NonZeroU32>,
	pub(crate) owns_image: bool,
}

impl Next for Image {
	type Handle = ImageHandle;

	fn next(&self) -> Option<Self::Handle> {
		self.next
	}
}

impl HandleLike for ImageHandle {
	type Item = Image;

	fn build(value: u64) -> Self {
		Self(value)
	}

	fn access<'a>(&self, collection: &'a [Self::Item]) -> &'a Self::Item {
		&collection[self.0 as usize]
	}
}