Add conversions from Extent2D to Extent3D and Rect2D (#557)
These two conversions occur all the time in Vulkan applications. For example, Extent2D -> Extent3D occurs whenever you need to make an image the same size as a surface and Extent2D -> Rect2D occurs whenever you fill out a scissors or render area from a surface resolution. Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
This commit is contained in:
parent
cebfd544fc
commit
fbcc45fffe
|
@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased] - ReleaseDate
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added conversions from `Extent2D` to `Extent3D` and `Rect2D` (#557)
|
||||||
|
|
||||||
## [0.35.1] - 2022-01-18
|
## [0.35.1] - 2022-01-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::vk;
|
||||||
|
|
||||||
/// Holds 24 bits in the least significant bits of memory,
|
/// Holds 24 bits in the least significant bits of memory,
|
||||||
/// and 8 bytes in the most significant bits of that memory,
|
/// and 8 bytes in the most significant bits of that memory,
|
||||||
/// occupying a single [`u32`] in total. This is commonly used in
|
/// occupying a single [`u32`] in total. This is commonly used in
|
||||||
|
@ -31,3 +33,22 @@ impl super::ColorComponentFlags {
|
||||||
/// Contraction of [`Self::R`] | [`Self::G`] | [`Self::B`] | [`Self::A`]
|
/// Contraction of [`Self::R`] | [`Self::G`] | [`Self::B`] | [`Self::A`]
|
||||||
pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0);
|
pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<vk::Extent2D> for vk::Extent3D {
|
||||||
|
fn from(value: vk::Extent2D) -> Self {
|
||||||
|
Self {
|
||||||
|
width: value.width,
|
||||||
|
height: value.height,
|
||||||
|
depth: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<vk::Extent2D> for vk::Rect2D {
|
||||||
|
fn from(extent: vk::Extent2D) -> Self {
|
||||||
|
Self {
|
||||||
|
offset: Default::default(),
|
||||||
|
extent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -264,7 +264,8 @@ fn main() {
|
||||||
let image = image::load_from_memory(include_bytes!("../../assets/rust.png"))
|
let image = image::load_from_memory(include_bytes!("../../assets/rust.png"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_rgba8();
|
.to_rgba8();
|
||||||
let image_dimensions = image.dimensions();
|
let (width, height) = image.dimensions();
|
||||||
|
let image_extent = vk::Extent2D { width, height };
|
||||||
let image_data = image.into_raw();
|
let image_data = image.into_raw();
|
||||||
let image_buffer_info = vk::BufferCreateInfo {
|
let image_buffer_info = vk::BufferCreateInfo {
|
||||||
size: (std::mem::size_of::<u8>() * image_data.len()) as u64,
|
size: (std::mem::size_of::<u8>() * image_data.len()) as u64,
|
||||||
|
@ -313,11 +314,7 @@ fn main() {
|
||||||
let texture_create_info = vk::ImageCreateInfo {
|
let texture_create_info = vk::ImageCreateInfo {
|
||||||
image_type: vk::ImageType::TYPE_2D,
|
image_type: vk::ImageType::TYPE_2D,
|
||||||
format: vk::Format::R8G8B8A8_UNORM,
|
format: vk::Format::R8G8B8A8_UNORM,
|
||||||
extent: vk::Extent3D {
|
extent: image_extent.into(),
|
||||||
width: image_dimensions.0,
|
|
||||||
height: image_dimensions.1,
|
|
||||||
depth: 1,
|
|
||||||
},
|
|
||||||
mip_levels: 1,
|
mip_levels: 1,
|
||||||
array_layers: 1,
|
array_layers: 1,
|
||||||
samples: vk::SampleCountFlags::TYPE_1,
|
samples: vk::SampleCountFlags::TYPE_1,
|
||||||
|
@ -388,11 +385,7 @@ fn main() {
|
||||||
.layer_count(1)
|
.layer_count(1)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.image_extent(vk::Extent3D {
|
.image_extent(image_extent.into());
|
||||||
width: image_dimensions.0,
|
|
||||||
height: image_dimensions.1,
|
|
||||||
depth: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
device.cmd_copy_buffer_to_image(
|
device.cmd_copy_buffer_to_image(
|
||||||
texture_command_buffer,
|
texture_command_buffer,
|
||||||
|
@ -623,10 +616,7 @@ fn main() {
|
||||||
min_depth: 0.0,
|
min_depth: 0.0,
|
||||||
max_depth: 1.0,
|
max_depth: 1.0,
|
||||||
}];
|
}];
|
||||||
let scissors = [vk::Rect2D {
|
let scissors = [base.surface_resolution.into()];
|
||||||
extent: base.surface_resolution,
|
|
||||||
..Default::default()
|
|
||||||
}];
|
|
||||||
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
||||||
.scissors(&scissors)
|
.scissors(&scissors)
|
||||||
.viewports(&viewports);
|
.viewports(&viewports);
|
||||||
|
@ -727,10 +717,7 @@ fn main() {
|
||||||
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
||||||
.render_pass(renderpass)
|
.render_pass(renderpass)
|
||||||
.framebuffer(framebuffers[present_index as usize])
|
.framebuffer(framebuffers[present_index as usize])
|
||||||
.render_area(vk::Rect2D {
|
.render_area(base.surface_resolution.into())
|
||||||
offset: vk::Offset2D { x: 0, y: 0 },
|
|
||||||
extent: base.surface_resolution,
|
|
||||||
})
|
|
||||||
.clear_values(&clear_values);
|
.clear_values(&clear_values);
|
||||||
|
|
||||||
record_submit_commandbuffer(
|
record_submit_commandbuffer(
|
||||||
|
|
|
@ -277,10 +277,7 @@ fn main() {
|
||||||
min_depth: 0.0,
|
min_depth: 0.0,
|
||||||
max_depth: 1.0,
|
max_depth: 1.0,
|
||||||
}];
|
}];
|
||||||
let scissors = [vk::Rect2D {
|
let scissors = [base.surface_resolution.into()];
|
||||||
offset: vk::Offset2D { x: 0, y: 0 },
|
|
||||||
extent: base.surface_resolution,
|
|
||||||
}];
|
|
||||||
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
||||||
.scissors(&scissors)
|
.scissors(&scissors)
|
||||||
.viewports(&viewports);
|
.viewports(&viewports);
|
||||||
|
@ -380,10 +377,7 @@ fn main() {
|
||||||
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
||||||
.render_pass(renderpass)
|
.render_pass(renderpass)
|
||||||
.framebuffer(framebuffers[present_index as usize])
|
.framebuffer(framebuffers[present_index as usize])
|
||||||
.render_area(vk::Rect2D {
|
.render_area(base.surface_resolution.into())
|
||||||
offset: vk::Offset2D { x: 0, y: 0 },
|
|
||||||
extent: base.surface_resolution,
|
|
||||||
})
|
|
||||||
.clear_values(&clear_values);
|
.clear_values(&clear_values);
|
||||||
|
|
||||||
record_submit_commandbuffer(
|
record_submit_commandbuffer(
|
||||||
|
|
|
@ -425,11 +425,7 @@ impl ExampleBase {
|
||||||
let depth_image_create_info = vk::ImageCreateInfo::builder()
|
let depth_image_create_info = vk::ImageCreateInfo::builder()
|
||||||
.image_type(vk::ImageType::TYPE_2D)
|
.image_type(vk::ImageType::TYPE_2D)
|
||||||
.format(vk::Format::D16_UNORM)
|
.format(vk::Format::D16_UNORM)
|
||||||
.extent(vk::Extent3D {
|
.extent(surface_resolution.into())
|
||||||
width: surface_resolution.width,
|
|
||||||
height: surface_resolution.height,
|
|
||||||
depth: 1,
|
|
||||||
})
|
|
||||||
.mip_levels(1)
|
.mip_levels(1)
|
||||||
.array_layers(1)
|
.array_layers(1)
|
||||||
.samples(vk::SampleCountFlags::TYPE_1)
|
.samples(vk::SampleCountFlags::TYPE_1)
|
||||||
|
|
Loading…
Reference in a new issue