From a6fa5b0570f60170269d99da4b9cc450f5403bdf Mon Sep 17 00:00:00 2001 From: Mars Date: Sun, 17 Nov 2024 22:10:56 -0500 Subject: [PATCH] sum changes --- src/init/vulkan_instance.cpp | 12 +++++------- src/main.cpp | 38 +++++++++++++++--------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/init/vulkan_instance.cpp b/src/init/vulkan_instance.cpp index 22410a3..f000f5a 100644 --- a/src/init/vulkan_instance.cpp +++ b/src/init/vulkan_instance.cpp @@ -28,7 +28,7 @@ fn VulkanInstance::create() -> vk::UniqueInstance { }; // Get required extensions - auto extensions = getRequiredExtensions(); + std::vector extensions = getRequiredExtensions(); #ifndef NDEBUG fmt::println("Available extensions:"); @@ -52,7 +52,7 @@ fn VulkanInstance::create() -> vk::UniqueInstance { .ppEnabledExtensionNames = extensions.data() }; - auto instance = vk::createInstanceUnique(createInfo); + vk::UniqueInstance instance = vk::createInstanceUnique(createInfo); // Initialize the dynamic dispatcher with the instance VULKAN_HPP_DEFAULT_DISPATCHER.init(instance.get()); @@ -81,22 +81,20 @@ fn VulkanInstance::getRequiredExtensions() -> std::vector { fn VulkanInstance::checkValidationLayerSupport() -> bool { // Get available layers - auto availableLayers = vk::enumerateInstanceLayerProperties(); + std::vector availableLayers = vk::enumerateInstanceLayerProperties(); // Check if all requested validation layers are available for (const char* layerName : validationLayers) { bool layerFound = false; - for (const auto& layerProperties : availableLayers) { + for (const vk::LayerProperties& layerProperties : availableLayers) if (strcmp(layerName, layerProperties.layerName) == 0) { layerFound = true; break; } - } - if (!layerFound) { + if (!layerFound) return false; - } } return true; diff --git a/src/main.cpp b/src/main.cpp index 2a50fc7..0e92c5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,10 +40,6 @@ #include #include -// GLFW configuration and inclusion -#define VKFW_NO_STRUCT_CONSTRUCTORS // Use aggregate initialization for GLFW structs -#include "vkfw.hpp" // Include GLFW C++ bindings - using namespace constants; /** @@ -467,16 +463,14 @@ class VulkanApp { if (ImGui::CollapsingHeader("Camera Settings", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::SliderFloat("Camera Speed", &mCameraSpeed, 0.1F, 10.0F, "%.1f"); ImGui::SliderFloat("Field of View", &mFieldOfView, 45.0F, 120.0F, "%.1f"); - if (ImGui::Button("Reset Camera")) { + if (ImGui::Button("Reset Camera")) mCamera = Camera(); - } } // Rendering Settings if (ImGui::CollapsingHeader("Rendering Settings", ImGuiTreeNodeFlags_DefaultOpen)) { - if (ImGui::Checkbox("Wireframe Mode", &mWireframeMode)) { + if (ImGui::Checkbox("Wireframe Mode", &mWireframeMode)) recreateSwapChain(); - } if (mWireframeMode) { if (mWideLineSupport) { @@ -501,7 +495,6 @@ class VulkanApp { ImGui::BulletText("WASD to move horizontally"); ImGui::BulletText("Space/Shift to move up/down"); ImGui::BulletText("ESC to toggle mouse capture"); - ImGui::BulletText("Tab to toggle this menu"); } } @@ -1130,9 +1123,9 @@ class VulkanApp { mCrosshairPipelineLayout = mDevice->createPipelineLayoutUnique(pipelineLayoutInfo); // Load shaders - auto vertShaderCode = + std::vector vertShaderCode = ShaderCompiler::getCompiledShader(CROSSHAIR_VERTEX_SHADER_PATH, shaderc_vertex_shader); - auto fragShaderCode = + std::vector fragShaderCode = ShaderCompiler::getCompiledShader(CROSSHAIR_FRAGMENT_SHADER_PATH, shaderc_fragment_shader); vk::UniqueShaderModule vertShaderModule = createShaderModule(vertShaderCode); @@ -1149,8 +1142,9 @@ class VulkanApp { std::array shaderStages = { vertShaderStageInfo, fragShaderStageInfo }; // Vertex input - auto bindingDescription = CrosshairVertex::getBindingDescription(); - auto attributeDescriptions = CrosshairVertex::getAttributeDescriptions(); + vk::VertexInputBindingDescription bindingDescription = CrosshairVertex::getBindingDescription(); + std::array attributeDescriptions = + CrosshairVertex::getAttributeDescriptions(); vk::PipelineVertexInputStateCreateInfo vertexInputInfo { .vertexBindingDescriptionCount = 1, @@ -1226,7 +1220,7 @@ class VulkanApp { // Create vertex buffer vk::DeviceSize bufferSize = sizeof(crosshairVertices[0]) * crosshairVertices.size(); - auto stagingBuffer = createBuffer( + std::pair stagingBuffer = createBuffer( bufferSize, vk::BufferUsageFlagBits::eTransferSrc, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent @@ -1249,7 +1243,7 @@ class VulkanApp { // Create index buffer bufferSize = sizeof(crosshairIndices[0]) * crosshairIndices.size(); - auto stagingBufferIndices = createBuffer( + std::pair stagingBufferIndices = createBuffer( bufferSize, vk::BufferUsageFlagBits::eTransferSrc, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent @@ -2409,7 +2403,7 @@ class VulkanApp { glm::translate(glm::mat4(1.0F), glm::vec3(-2.0F, 0.0F, 0.0F)), glm::translate(glm::mat4(1.0F), glm::vec3(0.0F, 2.0F, 0.0F)) }; - for (const auto& modelMatrix : modelMatrices) { + for (const glm::mat4& modelMatrix : modelMatrices) { // Update model matrix for each clone ubo.model = modelMatrix; memcpy(mUniformBuffersMapped[mCurrentFrame], &ubo, sizeof(ubo)); @@ -2432,18 +2426,17 @@ class VulkanApp { // Draw the crosshair commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, mCrosshairPipeline.get()); - std::array vertexBuffers = { mCrosshairVertexBuffer.get() }; - std::array offsets = { 0 }; - commandBuffer.bindVertexBuffers(0, 1, vertexBuffers.data(), offsets.data()); + commandBuffer.bindVertexBuffers( + 0, 1, &mCrosshairVertexBuffer.get(), std::array { 0 }.data() + ); commandBuffer.bindIndexBuffer(mCrosshairIndexBuffer.get(), 0, vk::IndexType::eUint16); // Draw the crosshair commandBuffer.drawIndexed(static_cast(crosshairIndices.size()), 1, 0, 0, 0); // Render ImGui if we have a draw data (ImGui::Render was called) - if (ImGui::GetDrawData()) { + if (ImGui::GetDrawData()) ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), commandBuffer); - } // End the render pass commandBuffer.endRenderPass(); @@ -2670,7 +2663,8 @@ class VulkanApp { ) -> vk::PresentModeKHR { // Check if mailbox mode is available (adaptive sync) for (const vk::PresentModeKHR& availablePresentMode : availablePresentModes) - if (availablePresentMode == vk::PresentModeKHR::eMailbox) + if (availablePresentMode == vk::PresentModeKHR::eMailbox || + availablePresentMode == vk::PresentModeKHR::eImmediate) return availablePresentMode; // If mailbox mode is not available, use FIFO mode (vsync)