Fix viewport resizing not updating camera aspect ratio
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#undef max
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
@@ -43,7 +44,7 @@ namespace openVulkanoCpp
|
||||
this->frameBufferClearColor = frameBufferClearColor;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::array<float, 4> GetFrameBufferClearColor() const
|
||||
[[nodiscard]] const std::array<float, 4>& GetFrameBufferClearColor() const
|
||||
{
|
||||
return frameBufferClearColor;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ namespace openVulkanoCpp
|
||||
~Camera() override = default;
|
||||
|
||||
public:
|
||||
void Init(float nearPlane, float farPlane)
|
||||
{
|
||||
Init(16, 9, farPlane, nearPlane);
|
||||
}
|
||||
|
||||
void Init(float width, float height, float nearPlane, float farPlane)
|
||||
{
|
||||
this->width = width;
|
||||
@@ -43,6 +48,7 @@ namespace openVulkanoCpp
|
||||
|
||||
virtual void SetSize(const float width, const float height)
|
||||
{
|
||||
if (this->width == width && this->height == height) return;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
UpdateProjectionMatrix();
|
||||
@@ -73,7 +79,7 @@ namespace openVulkanoCpp
|
||||
|
||||
void UpdateViewProjectionMatrix()
|
||||
{ // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped
|
||||
viewProjection = projection * Math::Matrix4f(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * view;
|
||||
viewProjection = projection * Math::Matrix4f(1,0,0,0,0,-1,0,0,0,0,-1,0,0,0,0,1) * view;
|
||||
}
|
||||
|
||||
void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat) override
|
||||
@@ -98,12 +104,18 @@ namespace openVulkanoCpp
|
||||
PerspectiveCamera() = default;
|
||||
~PerspectiveCamera() override = default;
|
||||
|
||||
PerspectiveCamera(float fovDegrees, float width, float height, float nearPlane = 0.1f, float farPlane = 1000.0f)
|
||||
PerspectiveCamera(float fovDegrees, float nearPlane = 0.1f, float farPlane = 1000.0f, float width = 16, float height = 9)
|
||||
: Camera()
|
||||
{
|
||||
Init(fovDegrees, width, height, nearPlane, farPlane);
|
||||
PerspectiveCamera::UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Init(float fovDegrees, float nearPlane, float farPlane)
|
||||
{
|
||||
Init(fovDegrees, 16, 9, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
void Init(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
||||
{
|
||||
this->fov = Math::Utils::radians(fovDegrees);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Scene/VulkanGeometry.hpp"
|
||||
#include "Scene/VulkanNode.hpp"
|
||||
#include "Scene/VulkanShader.hpp"
|
||||
#include "Base/UI/IVulkanWindow.hpp"
|
||||
#include "Host/PlatformProducer.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -62,6 +63,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
void Renderer::Tick()
|
||||
{
|
||||
currentImageId = context.swapChain.AcquireNextImage();
|
||||
scene->GetCamera()->SetSize(context.window->GetWidth(), context.window->GetHeight());
|
||||
Render();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,10 @@ namespace openVulkanoCpp::Vulkan
|
||||
const vk::SurfaceCapabilitiesKHR surfaceCapabilities = device->physicalDevice.getSurfaceCapabilitiesKHR(surface);
|
||||
if(surfaceCapabilities.currentExtent.width != ~static_cast<uint32_t>(0))
|
||||
{ // The surface does provide it's size to the vulkan driver
|
||||
if (surfaceCapabilities.currentExtent != size)
|
||||
{
|
||||
Logger::RENDER->warn("Surface resolution ({}, {}) does not match given render resolution ({}, {}).", size.width, size.height, surfaceCapabilities.currentExtent.width, surfaceCapabilities.currentExtent.height);
|
||||
}
|
||||
size = surfaceCapabilities.currentExtent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user