From 3f96161dff5c8f5aa977eed2b3cf2497d11c56b9 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 16 Oct 2018 20:34:54 -0400 Subject: [PATCH] Properly use render target aspect ratio --- include/worldpass.h | 3 ++- src/renderer.cpp | 2 +- src/worldpass.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/worldpass.h b/include/worldpass.h index 258a08d..c107e5b 100644 --- a/include/worldpass.h +++ b/include/worldpass.h @@ -4,13 +4,14 @@ class Renderer; class World; +struct RenderTarget; class WorldPass { public: WorldPass(Renderer& renderer); ~WorldPass(); - void render(World& world, VkCommandBuffer commandBuffer); + void render(VkCommandBuffer commandBuffer, World& world, RenderTarget* target); private: void createPipeline(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 79d6e28..7193ee1 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -79,7 +79,7 @@ void Renderer::render(World& world, RenderTarget* target) { vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); - worldPass_->render(world, commandBuffer); + worldPass_->render(commandBuffer, world, target); vkCmdEndRenderPass(commandBuffer); diff --git a/src/worldpass.cpp b/src/worldpass.cpp index 86d7287..9033f91 100644 --- a/src/worldpass.cpp +++ b/src/worldpass.cpp @@ -16,12 +16,12 @@ WorldPass::~WorldPass() { vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr); } -void WorldPass::render(World& world, VkCommandBuffer commandBuffer) { +void WorldPass::render(VkCommandBuffer commandBuffer, World& world, RenderTarget* target) { vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_); for(const auto& mesh : world.meshes) { glm::mat4 mvp; - mvp = glm::perspective(glm::radians(75.0f), 640.0f / 480.0f, 0.1f, 100.0f); + mvp = glm::perspective(glm::radians(75.0f), (float)target->extent.width / target->extent.height, 0.1f, 100.0f); mvp *= glm::lookAt(glm::vec3(2), glm::vec3(0), glm::vec3(0, -1, 0)); vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &mvp);