added picker for present and formats
This commit is contained in:
parent
0fb09b9e43
commit
a95e3a79b1
1 changed files with 54 additions and 6 deletions
52
src/main.c
52
src/main.c
|
|
@ -304,20 +304,57 @@ bool checkDeviceExtensionSupport(VkPhysicalDevice device) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO: find a better way of managing memory
|
||||
SwapChainSupportDetails querySwapchainSupport(VkPhysicalDevice device,
|
||||
VkSurfaceKHR *surface) {
|
||||
SwapChainSupportDetails details = {0};
|
||||
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, *surface,
|
||||
&details.capabilities);
|
||||
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, *surface, &details.numFormats,
|
||||
NULL);
|
||||
if (details.numFormats > 0) {
|
||||
details.formats = malloc(details.numFormats * sizeof(VkSurfaceFormatKHR));
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, *surface, &details.numFormats,
|
||||
details.formats);
|
||||
}
|
||||
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, *surface,
|
||||
&details.numPresentModes, NULL);
|
||||
if (details.numPresentModes > 0) {
|
||||
details.presentModes =
|
||||
malloc(details.numFormats * sizeof(VkPresentModeKHR));
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
device, *surface, &details.numPresentModes, details.presentModes);
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
// Prefer one format but otherwise go for
|
||||
VkSurfaceFormatKHR chooseSwapSurfaceFormat(VkSurfaceFormatKHR *availableFormats,
|
||||
size_t availableFormatCount) {
|
||||
for (uint i = 0; i < availableFormatCount; i++) {
|
||||
if (availableFormats[i].format == VK_FORMAT_B8G8R8_SRGB &&
|
||||
availableFormats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
|
||||
return availableFormats[i];
|
||||
}
|
||||
}
|
||||
return availableFormats[0];
|
||||
}
|
||||
|
||||
// Prefer mailbox otherwise go for the garenteed available present mode
|
||||
VkPresentModeKHR chooseSwapPresentMode(VkPresentModeKHR *availablePresentModes,
|
||||
size_t availablePresentModesCount) {
|
||||
for (uint i = 0; i < availablePresentModesCount; i++) {
|
||||
if (availablePresentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
|
||||
return availablePresentModes[i];
|
||||
}
|
||||
}
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
|
||||
bool isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR *surface) {
|
||||
QueueFamilyIndices indices = findQueueFamilies(device, surface);
|
||||
bool completeIndeces =
|
||||
|
|
@ -325,10 +362,21 @@ bool isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR *surface) {
|
|||
|
||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||
|
||||
SwapChainSupportDetails swapChaindetails =
|
||||
bool swapChainAdequate = false;
|
||||
if (extensionsSupported) {
|
||||
SwapChainSupportDetails swapChainDetails =
|
||||
querySwapchainSupport(device, surface);
|
||||
|
||||
return completeIndeces && extensionsSupported;
|
||||
if (swapChainDetails.numFormats > 0 &&
|
||||
swapChainDetails.numPresentModes > 0) {
|
||||
swapChainAdequate = true;
|
||||
}
|
||||
|
||||
free(swapChainDetails.presentModes);
|
||||
free(swapChainDetails.formats);
|
||||
}
|
||||
|
||||
return completeIndeces && extensionsSupported && swapChainAdequate;
|
||||
}
|
||||
|
||||
void pickPhysicalDevice(Application *app) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue