Kale
Loading...
Searching...
No Matches
SwapChainSupportDetails.cpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifdef KALE_VULKAN
18
20
23
24#include <limits>
25#include <algorithm>
26
27using namespace Kale;
28using namespace Kale::Vulkan;
29
36
41SwapChainSupportDetails::SwapChainSupportDetails(const vk::PhysicalDevice& physicalDevice) :
42 capabilities(physicalDevice.getSurfaceCapabilitiesKHR(Core::surface.get())),
43 formats(physicalDevice.getSurfaceFormatsKHR(Core::surface.get())),
44 presentModes(physicalDevice.getSurfacePresentModesKHR(Core::surface.get())) {
45
46 // Empty Body
47}
48
54 return !formats.empty() && !presentModes.empty();
55}
56
61vk::SurfaceFormatKHR SwapChainSupportDetails::chooseFormat() const {
62 for (const vk::SurfaceFormatKHR& format : formats)
63 if (format.format == vk::Format::eR8G8B8A8Srgb && format.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear)
64 return format;
65
66 return formats[0];
67}
68
74 // TODO - Add configuration settings for high/medium/low graphics
75 if (std::find(presentModes.begin(), presentModes.end(), vk::PresentModeKHR::eMailbox) != presentModes.end())
76 return vk::PresentModeKHR::eMailbox;
77 else
78 return vk::PresentModeKHR::eFifo;
79}
80
86 if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) {
87 // We're required to use the vulkan/window current extent
88 return capabilities.currentExtent;
89 }
90 else {
91 // Get the window size and clamp it then return
92 Vector2ui32 winSize = mainApp->getWindow().getSize().cast<uint32_t>();
93 winSize.clampTo(capabilities.minImageExtent.width, capabilities.maxImageExtent.width,
94 capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
95 return vk::Extent2D{winSize.x, winSize.y};
96 }
97}
98
99#endif
Window & getWindow() noexcept
Vector2< A > cast() const
Definition Vector.hpp:144
void clampTo(T minX, T maxX, T minY, T maxY)
Definition Vector.hpp:134
std::vector< vk::SurfaceFormatKHR > formats
std::vector< vk::PresentModeKHR > presentModes
Vector2ui getSize() const
Application * mainApp