summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-11-07 16:28:48 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-11-07 16:33:16 -0500
commit3ac80971cd3a31a3d23c226b8ab3f918e677940b (patch)
tree37851d1291165206708f5b293fa7f5789fd2017b
parent5891af6843661a9d30c12c3ef0f9efeb534aee88 (diff)
expose window VkExtent2D Extent
-rw-r--r--src/window.cpp46
-rw-r--r--src/window.hpp2
2 files changed, 25 insertions, 23 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 91e23f2..609a71b 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -56,7 +56,7 @@ VkSwapchainKHR vkSwapchainKHR = VK_NULL_HANDLE;
VkSurfaceFormatKHR vkSurfaceFormatKHR;
VkFormat depthFormat;
VkPresentModeKHR vkPresentModeKHR = VK_PRESENT_MODE_FIFO_KHR;
-VkExtent2D extent;
+VkExtent2D Extent;
VkImage *swapchainImages = nullptr;
VkImageView *swapchainImageViews = nullptr;
VkImage *renderImages = nullptr;
@@ -618,13 +618,13 @@ void CreateSwapchain() {
int width, height;
glfwGetFramebufferSize(window, &width, &height);
- extent.width = width;
- extent.height = height;
+ 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;
+ 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;
vkPresentModeKHR = VK_PRESENT_MODE_FIFO_KHR;
if (pkeSettings.graphicsSettings.isWaitingForVsync == false || pkeSettings.graphicsSettings.isFramerateUnlocked == true) {
@@ -679,7 +679,7 @@ void CreateSwapchain() {
vkSwapchainCreateInfo.minImageCount = MAX_FRAMES_IN_FLIGHT;
vkSwapchainCreateInfo.imageFormat = vkSurfaceFormatKHR.format;
vkSwapchainCreateInfo.imageColorSpace = vkSurfaceFormatKHR.colorSpace;
- vkSwapchainCreateInfo.imageExtent = extent;
+ vkSwapchainCreateInfo.imageExtent = Extent;
vkSwapchainCreateInfo.imageArrayLayers = 1;
vkSwapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
// vkSwapchainCreateInfo.imageSharingMode = {};
@@ -754,8 +754,8 @@ void CreateSwapchain() {
renderTargetImageCI.flags = 0;
renderTargetImageCI.imageType = VK_IMAGE_TYPE_2D;
renderTargetImageCI.format = vkSurfaceFormatKHR.format;
- renderTargetImageCI.extent.width = extent.width;
- renderTargetImageCI.extent.height = extent.height;
+ renderTargetImageCI.extent.width = Extent.width;
+ renderTargetImageCI.extent.height = Extent.height;
renderTargetImageCI.extent.depth = 1;
renderTargetImageCI.mipLevels = 1;
renderTargetImageCI.arrayLayers = 1;
@@ -814,7 +814,7 @@ void UpdatePresentDescriptorSets() {
}
void UpdateCameraProjection() {
- UBO.proj = glm::perspective(glm::radians(45.f), extent.width / (float)extent.height, 0.1f, 100.f);
+ UBO.proj = glm::perspective(glm::radians(45.f), Extent.width / (float)Extent.height, 0.1f, 100.f);
UBO.proj[1][1] *= -1;
}
@@ -986,14 +986,14 @@ void CreatePresentPipeline() {
VkViewport viewport;
viewport.x = 0.0f;
viewport.y = 0.0f;
- viewport.width = (float) extent.width;
- viewport.height = (float) extent.height;
+ viewport.width = (float) Extent.width;
+ viewport.height = (float) Extent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor;
scissor.offset = {0, 0};
- scissor.extent = extent;
+ scissor.extent = Extent;
VkPipelineViewportStateCreateInfo viewportState;
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
@@ -1183,8 +1183,8 @@ void CreateFramebuffers() {
framebufferInfo.renderPass = presentRenderPass;
framebufferInfo.attachmentCount = 1;
framebufferInfo.pAttachments = nullptr;
- framebufferInfo.width = extent.width;
- framebufferInfo.height = extent.height;
+ framebufferInfo.width = Extent.width;
+ framebufferInfo.height = Extent.height;
framebufferInfo.layers = 1;
for (long i = 0; i < swapchainLength; ++i) {
@@ -2222,7 +2222,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
renderPassInfo.renderPass = renderRenderPass;
renderPassInfo.framebuffer = renderImageFramebuffers[imageIndex];
renderPassInfo.renderArea.offset = {0, 0};
- renderPassInfo.renderArea.extent = extent;
+ renderPassInfo.renderArea.extent = Extent;
renderPassInfo.clearValueCount = 2;
renderPassInfo.pClearValues = clearValues;
renderPassInfo.pNext = VK_NULL_HANDLE;
@@ -2233,14 +2233,14 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
VkViewport viewport;
viewport.x = 0.0f;
viewport.y = 0.0f;
- viewport.width = (float)extent.width;
- viewport.height = (float)extent.height;
+ viewport.width = (float)Extent.width;
+ viewport.height = (float)Extent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
VkRect2D scissor;
scissor.offset = {0, 0};
- scissor.extent = extent;
+ scissor.extent = Extent;
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
@@ -2401,8 +2401,8 @@ void RecreateSwapchain() {
glfwGetFramebufferSize(window, &width, &height);
glfwWaitEvents();
}
- extent.width = width;
- extent.height = height;
+ Extent.width = width;
+ Extent.height = height;
DetermineMonitor();
vkDeviceWaitIdle(vkDevice);
DestroySwapchain();
@@ -2414,7 +2414,7 @@ void RecreateSwapchain() {
}
void FramebufferResizeCallback(GLFWwindow *window, int width, int height) {
- if (extent.width == width && extent.height != height) {
+ if (Extent.width == width && Extent.height != height) {
return;
}
shouldRecreateSwapchain = true;
diff --git a/src/window.hpp b/src/window.hpp
index e94598b..5f640f9 100644
--- a/src/window.hpp
+++ b/src/window.hpp
@@ -57,6 +57,8 @@ struct UniformBufferObject {
extern UniformBufferObject UBO;
extern VkBuffer UniformBuffers[MAX_FRAMES_IN_FLIGHT];
+extern VkExtent2D Extent;
+
struct DebugHitbox {
VkImage vkImage = VK_NULL_HANDLE;
VkImageView vkImageView = VK_NULL_HANDLE;