Improved Resolution handling.
This commit is contained in:
parent
6e14b74244
commit
abdd7137ab
|
|
@ -122,9 +122,9 @@ main(int, char **)
|
|||
Camera camera = {
|
||||
.m_View = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)),
|
||||
.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_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;
|
||||
|
|
@ -273,7 +273,14 @@ main(int, char **)
|
|||
gui::Init(&context, &device, &window, swapchain.m_Format, Cast<u32>(swapchain.m_ImageViews.size()),
|
||||
queueAllocation.m_Family, commandQueue);
|
||||
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();
|
||||
|
||||
|
|
@ -285,31 +292,45 @@ main(int, char **)
|
|||
gui::StartBuild();
|
||||
|
||||
gui::Begin("Settings");
|
||||
gui::Text("Window Resolution: %udx%ud", swapchain.m_Extent.width, swapchain.m_Extent.height);
|
||||
gui::Text("FrameBuffer Resolution %dx%d", currentInternalResolution[0], currentInternalResolution[1]);
|
||||
gui::InputInt("FrameBuffer Height", ¤tInternalResolution[1], 1, 10);
|
||||
|
||||
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)
|
||||
gui::Text("Window Resolution: %ux%u", swapchain.m_Extent.width, swapchain.m_Extent.height);
|
||||
gui::Text("FrameBuffer Resolution %ux%u", internalResolution.width, internalResolution.height);
|
||||
gui::Checkbox("Lock Resolution to Window", &lockToScreen);
|
||||
if (!lockToScreen)
|
||||
{
|
||||
val = eastl::clamp(val, 64, 7680);
|
||||
}
|
||||
camera.m_Perspective = glm::perspective(70_deg, camera.m_AspectRatio, 0.1f, 100.0f);
|
||||
|
||||
if (gui::Button("Change Resolution"))
|
||||
{
|
||||
if (currentInternalResolution[0] != internalResolution.width ||
|
||||
currentInternalResolution[1] != internalResolution.height)
|
||||
if (gui::InputInt("FrameBuffer Height", &height, 1, 10))
|
||||
{
|
||||
internalResolution =
|
||||
vk::Extent2D{}.setWidth(currentInternalResolution[0]).setHeight(currentInternalResolution[1]);
|
||||
height = eastl::clamp(height, 64, 4320);
|
||||
}
|
||||
|
||||
inputResolution.height = height;
|
||||
inputResolution.width = Cast<i32>(camera.m_AspectRatio * Cast<f32>(inputResolution.height));
|
||||
|
||||
if (gui::Button("Change Resolution"))
|
||||
{
|
||||
if (inputResolution.width != internalResolution.width ||
|
||||
inputResolution.height != internalResolution.height)
|
||||
{
|
||||
internalResolution = inputResolution;
|
||||
viewport.width = Cast<f32>(internalResolution.width);
|
||||
viewport.height = -Cast<f32>(internalResolution.height);
|
||||
viewport.y = Cast<f32>(internalResolution.height);
|
||||
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("FPS: %0.6f", 1.0f / Time::m_Delta);
|
||||
gui::Checkbox("Rotate", &rotating);
|
||||
|
|
|
|||
Loading…
Reference in New Issue