aboutsummaryrefslogtreecommitdiff
path: root/cube/cube.cpp
diff options
context:
space:
mode:
authorJeremy Kniager <jeremyk@lunarg.com>2019-11-22 14:55:57 -0700
committerjeremyk-lunarg <jeremyk@lunarg.com>2019-11-27 10:02:44 -0700
commit979b531e9fff8ef044cf036d8ebd7fab3c17bec3 (patch)
tree26e06759d1c6f5a62301b83d04d62cfdd5caebcf /cube/cube.cpp
parent6f6e3371c92ac63bf29d5010b2933659e3f8dbef (diff)
downloadusermoji-979b531e9fff8ef044cf036d8ebd7fab3c17bec3.tar.xz
vkcube: Fix Cube Squishing on Resize
Modified viewport creation in vkcube to keep the aspect ratio square and centered. This change prevents cube from squishing and warping when the window is resized. It now shrinks and grows. Change-Id: Ie2b3c5747293dfed968af5d83b581ac74d81bb10
Diffstat (limited to 'cube/cube.cpp')
-rw-r--r--cube/cube.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/cube/cube.cpp b/cube/cube.cpp
index abe80a88..4af97856 100644
--- a/cube/cube.cpp
+++ b/cube/cube.cpp
@@ -850,9 +850,23 @@ void Demo::draw_build_cmd(vk::CommandBuffer commandBuffer) {
commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline_layout, 0, 1,
&swapchain_image_resources[current_buffer].descriptor_set, 0, nullptr);
-
- auto const viewport =
- vk::Viewport().setWidth((float)width).setHeight((float)height).setMinDepth((float)0.0f).setMaxDepth((float)1.0f);
+ float viewport_dimension;
+ float viewport_x = 0.0f;
+ float viewport_y = 0.0f;
+ if (width < height) {
+ viewport_dimension = (float)width;
+ viewport_y = (height - width) / 2.0f;
+ } else {
+ viewport_dimension = (float)height;
+ viewport_x = (width - height) / 2.0f;
+ }
+ auto const viewport = vk::Viewport()
+ .setX(viewport_x)
+ .setY(viewport_y)
+ .setWidth((float)viewport_dimension)
+ .setHeight((float)viewport_dimension)
+ .setMinDepth((float)0.0f)
+ .setMaxDepth((float)1.0f);
commandBuffer.setViewport(0, 1, &viewport);
vk::Rect2D const scissor(vk::Offset2D(0, 0), vk::Extent2D(width, height));