Skip to content

Commit

Permalink
Leave initial scissor/viewport state to the user
Browse files Browse the repository at this point in the history
These are usually already set.
  • Loading branch information
Ralith committed Nov 29, 2023
1 parent 232a7a8 commit bcb4463
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
14 changes: 14 additions & 0 deletions crates/yakui-vulkan/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ impl VulkanTest {
},
},
];
let viewports = [vk::Viewport {
x: 0.0,
y: 0.0,
width: self.swapchain_info.surface_resolution.width as f32,
height: self.swapchain_info.surface_resolution.height as f32,
min_depth: 0.0,
max_depth: 1.0,
}];

let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
.render_pass(self.render_pass)
Expand All @@ -638,6 +646,12 @@ impl VulkanTest {
&render_pass_begin_info,
vk::SubpassContents::INLINE,
);
device.cmd_set_viewport(self.draw_command_buffer, 0, &viewports);
device.cmd_set_scissor(
self.draw_command_buffer,
0,
&[self.swapchain_info.surface_resolution.into()],
);
}
present_index
}
Expand Down
13 changes: 1 addition & 12 deletions crates/yakui-vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl YakuiVulkan {
///
/// ## Safety
/// - `vulkan_context` must be the same as the one used to create this [`YakuiVulkan`] instance
/// - `cmd` must be in rendering state, with viewport and scissor dynamic states set.
pub unsafe fn paint(
&mut self,
paint: &yakui_core::paint::PaintDom,
Expand Down Expand Up @@ -416,15 +417,6 @@ impl YakuiVulkan {
) {
let device = vulkan_context.device;

let viewports = [vk::Viewport {
x: 0.0,
y: 0.0,
width: resolution.width as f32,
height: resolution.height as f32,
min_depth: 0.0,
max_depth: 1.0,
}];

let surface_size = UVec2::new(resolution.width, resolution.height);

unsafe {
Expand All @@ -433,11 +425,8 @@ impl YakuiVulkan {
vk::PipelineBindPoint::GRAPHICS,
self.graphics_pipeline,
);
device.cmd_set_viewport(command_buffer, 0, &viewports);
let default_scissor = [resolution.into()];

// We set the scissor first here as it's against the spec not to do so.
device.cmd_set_scissor(command_buffer, 0, &default_scissor);
device.cmd_bind_vertex_buffers(command_buffer, 0, &[self.vertex_buffer.handle], &[0]);
device.cmd_bind_index_buffer(
command_buffer,
Expand Down

0 comments on commit bcb4463

Please sign in to comment.