summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp117
1 files changed, 66 insertions, 51 deletions
diff --git a/src/window.cpp b/src/window.cpp
index e44b498..0b9de86 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,27 +1,24 @@
-#include "backends/imgui_impl_vulkan.h"
-#include "math-helpers.hpp"
-#include "static-missing-texture.hpp"
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
+#include "backends/imgui_impl_glfw.h"
+#include "backends/imgui_impl_vulkan.h"
+
#include "window.hpp"
#include "asset-manager.hpp"
#include "camera.hpp"
#include "ecs.hpp"
-#include "entities.hpp"
-#include "event.hpp"
#include "game-settings.hpp"
-#include "helpers.hpp"
+#include "math-helpers.hpp"
#include "plugins.hpp"
#include "static-cube.hpp"
+#include "static-missing-texture.hpp"
#include "window-types.hpp"
#include "glm/ext/matrix_transform.hpp"
-#include "glm/gtc/matrix_transform.hpp"
#include <cstdint>
-#include <fstream>
struct pk_membucket *MemBkt_Vulkan = nullptr;
struct pke_vkAllocData {
@@ -135,6 +132,9 @@ VkBool32 UserDebugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData) {
+ (void)messageSeverity;
+ (void)messageType;
+ (void)pUserData;
printf("Validation Layer: %s\n", pCallbackData->pMessage);
return VK_FALSE;
}
@@ -210,7 +210,7 @@ void EndTransferBuffer(VkBuffer &buffer, VkDeviceMemory &deviceMemory) {
vkFreeMemory(vkDevice, deviceMemory, vkAllocator);
}
-unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSupport = -1, VkQueueFlagBits includeBits = (VkQueueFlagBits)0U, VkQueueFlagBits excludeBits = (VkQueueFlagBits)0U) {
+unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, char hasPresentSupport = -1, VkQueueFlagBits includeBits = (VkQueueFlagBits)0U, VkQueueFlagBits excludeBits = (VkQueueFlagBits)0U) {
if (hasPresentSupport == -1 && includeBits == 0 && excludeBits == 0) {
return 0U;
@@ -232,7 +232,7 @@ unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSuppo
VkBool32 presentSupport;
VkResult vkResult = vkGetPhysicalDeviceSurfaceSupportKHR(device, i, vkSurfaceKHR, &presentSupport);
assert(vkResult == VK_SUCCESS);
- if (presentSupport != hasPresentSupport) {
+ if (presentSupport != (VkBool32)hasPresentSupport) {
continue;
}
}
@@ -245,11 +245,12 @@ unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSuppo
}
void PKE_vkFreeFunction(void *pUserData, void *pMemory) {
+ (void)pUserData;
if (pMemory == nullptr) return;
pke_vkAllocData *chunk = nullptr;
size_t index = -1;
- size_t count = vulkanAllocs->Count();
- for (long i = 0; i < count; ++i) {
+ int64_t count = vulkanAllocs->Count();
+ for (int64_t i = 0; i < count; ++i) {
if ((*vulkanAllocs)[i].data == pMemory) {
chunk = &(*vulkanAllocs)[i];
index = i;
@@ -266,6 +267,8 @@ void PKE_vkFreeFunction(void *pUserData, void *pMemory) {
}
void *PKE_vkAllocateFunction(void *pUserData, size_t size, size_t alignment, VkSystemAllocationScope allocScope) {
+ (void)pUserData;
+ (void)allocScope;
if (size == 0) {
return nullptr;
}
@@ -278,6 +281,7 @@ void *PKE_vkAllocateFunction(void *pUserData, size_t size, size_t alignment, VkS
}
void *PKE_vkReallocationFunction(void *pUserData, void *pOriginal, size_t size, size_t alignment, VkSystemAllocationScope allocScope) {
+ (void)pUserData;
if (pOriginal == nullptr) {
return PKE_vkAllocateFunction(pUserData, size, alignment, allocScope);
}
@@ -287,8 +291,8 @@ void *PKE_vkReallocationFunction(void *pUserData, void *pOriginal, size_t size,
}
pke_vkAllocData *chunk = nullptr;
size_t index = -1;
- size_t count = vulkanAllocs->Count();
- for (long i = 0; i < count; ++i) {
+ int64_t count = vulkanAllocs->Count();
+ for (int64_t i = 0; i < count; ++i) {
if ((*vulkanAllocs)[i].data == pOriginal) {
chunk = &((*vulkanAllocs)[i]);
index = i;
@@ -312,10 +316,18 @@ void *PKE_vkReallocationFunction(void *pUserData, void *pOriginal, size_t size,
}
void PKE_vkInternalAllocationNotification(void *pUserData, size_t size, VkInternalAllocationType allocationType, VkSystemAllocationScope allocationScope) {
+ (void)pUserData;
+ (void)size;
+ (void)allocationType;
+ (void)allocationScope;
return;
}
void PKE_vkInternalFreeNotification(void *pUserData, size_t size, VkInternalAllocationType allocationType, VkSystemAllocationScope allocationScope) {
+ (void)pUserData;
+ (void)size;
+ (void)allocationType;
+ (void)allocationScope;
return;
}
@@ -646,39 +658,41 @@ void InitVulkan() {
}
void CreateImageResources_Inner(VkImageCreateInfo *imageCreateInfo, VkImageViewCreateInfo *imageViewCreateInfo, VkBufferUsageFlagBits bufferUsageFlagBits, VkBuffer *imagesBuffer, VkImage *images, VkImageView *imageViews, VkDeviceMemory *deviceMemory) {
- VkImage tmpImage;
- VkResult vkResult;
- vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &tmpImage);
- assert(vkResult == VK_SUCCESS);
+ (void)bufferUsageFlagBits;
+ (void)imagesBuffer;
+ VkImage tmpImage;
+ VkResult vkResult;
+ vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &tmpImage);
+ assert(vkResult == VK_SUCCESS);
- VkMemoryRequirements imageMemoryRequirements;
- vkGetImageMemoryRequirements(vkDevice, tmpImage, &imageMemoryRequirements);
+ VkMemoryRequirements imageMemoryRequirements;
+ vkGetImageMemoryRequirements(vkDevice, tmpImage, &imageMemoryRequirements);
- VkDeviceSize paddedImageSize = imageMemoryRequirements.size + (imageMemoryRequirements.alignment - (imageMemoryRequirements.size % imageMemoryRequirements.alignment));
- assert(paddedImageSize % imageMemoryRequirements.alignment == 0);
+ VkDeviceSize paddedImageSize = imageMemoryRequirements.size + (imageMemoryRequirements.alignment - (imageMemoryRequirements.size % imageMemoryRequirements.alignment));
+ assert(paddedImageSize % imageMemoryRequirements.alignment == 0);
- vkDestroyImage(vkDevice, tmpImage, vkAllocator);
+ vkDestroyImage(vkDevice, tmpImage, vkAllocator);
- VkMemoryAllocateInfo vkMemoryAllocateInfo{};
- vkMemoryAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- vkMemoryAllocateInfo.pNext = nullptr;
- vkMemoryAllocateInfo.allocationSize = paddedImageSize * MAX_FRAMES_IN_FLIGHT;
- vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(imageMemoryRequirements.memoryTypeBits,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
+ VkMemoryAllocateInfo vkMemoryAllocateInfo{};
+ vkMemoryAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ vkMemoryAllocateInfo.pNext = nullptr;
+ vkMemoryAllocateInfo.allocationSize = paddedImageSize * MAX_FRAMES_IN_FLIGHT;
+ vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(imageMemoryRequirements.memoryTypeBits,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
- vkResult = vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, deviceMemory);
- assert(vkResult == VK_SUCCESS);
+ vkResult = vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, deviceMemory);
+ assert(vkResult == VK_SUCCESS);
- for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
- vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &images[i]);
- assert(vkResult == VK_SUCCESS);
- vkResult = vkBindImageMemory(vkDevice, images[i], *deviceMemory, paddedImageSize * i);
- assert(vkResult == VK_SUCCESS);
+ for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
+ vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &images[i]);
+ assert(vkResult == VK_SUCCESS);
+ vkResult = vkBindImageMemory(vkDevice, images[i], *deviceMemory, paddedImageSize * i);
+ assert(vkResult == VK_SUCCESS);
- imageViewCreateInfo->image = images[i];
- vkResult = vkCreateImageView(vkDevice, imageViewCreateInfo, vkAllocator, &imageViews[i]);
- assert(vkResult == VK_SUCCESS);
- }
+ imageViewCreateInfo->image = images[i];
+ vkResult = vkCreateImageView(vkDevice, imageViewCreateInfo, vkAllocator, &imageViews[i]);
+ assert(vkResult == VK_SUCCESS);
+ }
}
void CreateSwapchain() {
@@ -715,10 +729,8 @@ void CreateSwapchain() {
Extent.width = width;
Extent.height = height;
// clamp
- width = Extent.width < surfaceCapabilities.minImageExtent.width ? surfaceCapabilities.minImageExtent.width : Extent.width;
- Extent.width = width > surfaceCapabilities.maxImageExtent.width ? surfaceCapabilities.maxImageExtent.width : width;
- height = Extent.height < surfaceCapabilities.minImageExtent.height ? surfaceCapabilities.minImageExtent.height : Extent.height;
- Extent.height = height > surfaceCapabilities.maxImageExtent.height ? surfaceCapabilities.maxImageExtent.height : height;
+ Extent.width = PK_CLAMP(Extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width);
+ Extent.height = PK_CLAMP(Extent.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height);
vkPresentModeKHR = VK_PRESENT_MODE_FIFO_KHR;
if (pkeSettings.graphicsSettings.isWaitingForVsync == false || pkeSettings.graphicsSettings.isFramerateUnlocked == true) {
@@ -728,8 +740,8 @@ void CreateSwapchain() {
VkPresentModeKHR *presentModes = pk_new<VkPresentModeKHR>(presentModeCount);
vkResult = vkGetPhysicalDeviceSurfacePresentModesKHR(vkPhysicalDevice, vkSurfaceKHR, &presentModeCount, presentModes);
assert(vkResult == VK_SUCCESS);
- uint32_t immediateIndex = -1;
- uint32_t fifoRelaxedIndex = -1;
+ int32_t immediateIndex = -1;
+ int32_t fifoRelaxedIndex = -1;
/*
uint32_t mailboxIndex = -1;
uint32_t fifoIndex = -1;
@@ -2376,11 +2388,11 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
VkDeviceSize offsets[1] = {0U};
- const uint64_t bindBucketCount = ECS_GetGrBinds_BucketCount();
- for (long b = 0; b < bindBucketCount; ++b) {
- uint64_t itemCount;
+ pk_handle_bucket_index_T bindBucketCount = ECS_GetGrBinds_BucketCount();
+ for (pk_handle_bucket_index_T b = 0; b < bindBucketCount; ++b) {
+ pk_handle_item_index_T itemCount;
CompGrBinds *items = ECS_GetGrBinds(b, itemCount);
- for (long i = 0; i < itemCount; ++i) {
+ for (pk_handle_item_index_T i = 0; i < itemCount; ++i) {
CompGrBinds *binder = &items[i];
if (binder->grBindsHandle == GrBindsHandle_MAX)
continue;
@@ -2571,7 +2583,10 @@ void RecreateSwapchain() {
}
void FramebufferResizeCallback(GLFWwindow *window, int width, int height) {
- if (Extent.width == width && Extent.height != height) {
+ (void)window;
+ assert(width > -1);
+ assert(height > -1);
+ if (Extent.width == (uint32_t)width && Extent.height != (uint32_t)height) {
return;
}
shouldRecreateSwapchain = true;