Improved Resolution handling.

This commit is contained in:
Anish Bhobe 2024-07-24 22:06:01 +02:00
parent 6e14b74244
commit abdd7137ab
1 changed files with 41 additions and 20 deletions

View File

@ -122,9 +122,9 @@ main(int, char **)
Camera camera = { Camera camera = {
.m_View = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)), .m_View = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)),
.m_Perspective = glm::perspective( .m_Perspective = glm::perspective(
70_deg, Cast<f32>(internalResolution.width) / Cast<f32>(internalResolution.height), 0.1f, 100.0f), 70_deg, Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height), 0.1f, 100.0f),
.m_Position = vec4{0.0f, 2.0f, 2.0f, 1.0f}, .m_Position = vec4{0.0f, 2.0f, 2.0f, 1.0f},
.m_AspectRatio = Cast<f32>(internalResolution.width) / Cast<f32>(internalResolution.height), .m_AspectRatio = Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height),
}; };
UniformBuffer ubo; UniformBuffer ubo;
@ -273,7 +273,14 @@ main(int, char **)
gui::Init(&context, &device, &window, swapchain.m_Format, Cast<u32>(swapchain.m_ImageViews.size()), gui::Init(&context, &device, &window, swapchain.m_Format, Cast<u32>(swapchain.m_ImageViews.size()),
queueAllocation.m_Family, commandQueue); queueAllocation.m_Family, commandQueue);
bool rotating = false; bool rotating = false;
i32 currentInternalResolution[2] = {Cast<i32>(internalResolution.width), Cast<i32>(internalResolution.height)}; bool lockToScreen = true;
i32 height = Cast<i32>(internalResolution.height);
vk::Extent2D inputResolution = internalResolution;
swapchain.RegisterResizeCallback([&camera](vk::Extent2D extent) {
camera.m_AspectRatio = Cast<f32>(extent.width) / Cast<f32>(extent.height);
camera.m_Perspective = glm::perspective(70_deg, camera.m_AspectRatio, 0.1f, 100.0f);
});
Time::Init(); Time::Init();
@ -285,31 +292,45 @@ main(int, char **)
gui::StartBuild(); gui::StartBuild();
gui::Begin("Settings"); gui::Begin("Settings");
gui::Text("Window Resolution: %udx%ud", swapchain.m_Extent.width, swapchain.m_Extent.height); gui::Text("Window Resolution: %ux%u", swapchain.m_Extent.width, swapchain.m_Extent.height);
gui::Text("FrameBuffer Resolution %dx%d", currentInternalResolution[0], currentInternalResolution[1]); gui::Text("FrameBuffer Resolution %ux%u", internalResolution.width, internalResolution.height);
gui::InputInt("FrameBuffer Height", &currentInternalResolution[1], 1, 10); gui::Checkbox("Lock Resolution to Window", &lockToScreen);
if (!lockToScreen)
camera.m_AspectRatio = Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height);
currentInternalResolution[0] = Cast<i32>(camera.m_AspectRatio * currentInternalResolution[1]);
for (i32 &val : currentInternalResolution)
{ {
val = eastl::clamp(val, 64, 7680); if (gui::InputInt("FrameBuffer Height", &height, 1, 10))
{
height = eastl::clamp(height, 64, 4320);
} }
camera.m_Perspective = glm::perspective(70_deg, camera.m_AspectRatio, 0.1f, 100.0f);
inputResolution.height = height;
inputResolution.width = Cast<i32>(camera.m_AspectRatio * Cast<f32>(inputResolution.height));
if (gui::Button("Change Resolution")) if (gui::Button("Change Resolution"))
{ {
if (currentInternalResolution[0] != internalResolution.width || if (inputResolution.width != internalResolution.width ||
currentInternalResolution[1] != internalResolution.height) inputResolution.height != internalResolution.height)
{ {
internalResolution = internalResolution = inputResolution;
vk::Extent2D{}.setWidth(currentInternalResolution[0]).setHeight(currentInternalResolution[1]);
viewport.width = Cast<f32>(internalResolution.width); viewport.width = Cast<f32>(internalResolution.width);
viewport.height = -Cast<f32>(internalResolution.height); viewport.height = -Cast<f32>(internalResolution.height);
viewport.y = Cast<f32>(internalResolution.height); viewport.y = Cast<f32>(internalResolution.height);
scissor.extent = internalResolution; scissor.extent = internalResolution;
} }
} }
}
else
{
if (swapchain.m_Extent.width != internalResolution.width ||
swapchain.m_Extent.height != internalResolution.height)
{
internalResolution = swapchain.m_Extent;
viewport.width = Cast<f32>(internalResolution.width);
viewport.height = -Cast<f32>(internalResolution.height);
viewport.y = Cast<f32>(internalResolution.height);
scissor.extent = internalResolution;
}
}
gui::Separator();
gui::Text("Delta: %0.6f ms", 1000.0f * Time::m_Delta); gui::Text("Delta: %0.6f ms", 1000.0f * Time::m_Delta);
gui::Text("FPS: %0.6f", 1.0f / Time::m_Delta); gui::Text("FPS: %0.6f", 1.0f / Time::m_Delta);
gui::Checkbox("Rotate", &rotating); gui::Checkbox("Rotate", &rotating);