sum changes
This commit is contained in:
parent
d4163fa7d6
commit
a6fa5b0570
|
@ -28,7 +28,7 @@ fn VulkanInstance::create() -> vk::UniqueInstance {
|
|||
};
|
||||
|
||||
// Get required extensions
|
||||
auto extensions = getRequiredExtensions();
|
||||
std::vector<const char*> 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,23 +81,21 @@ fn VulkanInstance::getRequiredExtensions() -> std::vector<const char*> {
|
|||
|
||||
fn VulkanInstance::checkValidationLayerSupport() -> bool {
|
||||
// Get available layers
|
||||
auto availableLayers = vk::enumerateInstanceLayerProperties();
|
||||
std::vector<vk::LayerProperties> 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;
|
||||
}
|
||||
|
|
38
src/main.cpp
38
src/main.cpp
|
@ -40,10 +40,6 @@
|
|||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_vulkan.h>
|
||||
|
||||
// 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<u32> vertShaderCode =
|
||||
ShaderCompiler::getCompiledShader(CROSSHAIR_VERTEX_SHADER_PATH, shaderc_vertex_shader);
|
||||
auto fragShaderCode =
|
||||
std::vector<u32> 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<vk::VertexInputAttributeDescription, 2> 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<vk::UniqueBuffer, vk::UniqueDeviceMemory> 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<vk::UniqueBuffer, vk::UniqueDeviceMemory> 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<vk::Buffer, 1> vertexBuffers = { mCrosshairVertexBuffer.get() };
|
||||
std::array<vk::DeviceSize, 1> offsets = { 0 };
|
||||
commandBuffer.bindVertexBuffers(0, 1, vertexBuffers.data(), offsets.data());
|
||||
commandBuffer.bindVertexBuffers(
|
||||
0, 1, &mCrosshairVertexBuffer.get(), std::array<vk::DeviceSize, 1> { 0 }.data()
|
||||
);
|
||||
commandBuffer.bindIndexBuffer(mCrosshairIndexBuffer.get(), 0, vk::IndexType::eUint16);
|
||||
|
||||
// Draw the crosshair
|
||||
commandBuffer.drawIndexed(static_cast<u32>(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)
|
||||
|
|
Loading…
Reference in a new issue