feat: reformatted code
This commit is contained in:
@@ -8,13 +8,16 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ struct Vertex {
|
|||||||
};
|
};
|
||||||
return bindingDescription;
|
return bindingDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescription() {
|
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescription() {
|
||||||
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
|
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
|
||||||
attributeDescriptions[0].binding = 0;
|
attributeDescriptions[0].binding = 0;
|
||||||
@@ -94,8 +98,10 @@ void HelloTriangleApplication::run() {
|
|||||||
|
|
||||||
void HelloTriangleApplication::createSwapChain() {
|
void HelloTriangleApplication::createSwapChain() {
|
||||||
int width, height;
|
int width, height;
|
||||||
uint32_t queueFamilyIndices[] = {myVkInstance->indices.graphicsFamily.value(), myVkInstance->indices.presentFamily.value()};
|
uint32_t queueFamilyIndices[] = {myVkInstance->indices.graphicsFamily.value(),
|
||||||
SwapChainSupportDetails swapChainSupportDetails = querySwapChainSupport(myVkInstance->physicalDevice, myVkInstance->surface);
|
myVkInstance->indices.presentFamily.value()};
|
||||||
|
SwapChainSupportDetails swapChainSupportDetails = querySwapChainSupport(myVkInstance->physicalDevice,
|
||||||
|
myVkInstance->surface);
|
||||||
|
|
||||||
VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupportDetails.formats);
|
VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupportDetails.formats);
|
||||||
VkPresentModeKHR presentMode = chooseSwapChainPresentMode(swapChainSupportDetails.presentModes);
|
VkPresentModeKHR presentMode = chooseSwapChainPresentMode(swapChainSupportDetails.presentModes);
|
||||||
@@ -222,7 +228,8 @@ void HelloTriangleApplication::createDescriptorSetLayout() {
|
|||||||
.pBindings = &uboLayoutBinding,
|
.pBindings = &uboLayoutBinding,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateDescriptorSetLayout(myVkInstance->device, &layoutCreateInfo, nullptr, &descriptorSetLayout) != VK_SUCCESS ) {
|
if (vkCreateDescriptorSetLayout(myVkInstance->device, &layoutCreateInfo, nullptr, &descriptorSetLayout) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
throw std::runtime_error("Failed to create descriptor set layout!");
|
throw std::runtime_error("Failed to create descriptor set layout!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,7 +423,8 @@ void HelloTriangleApplication::createGraphicsPipeline() {
|
|||||||
.pPushConstantRanges = nullptr,
|
.pPushConstantRanges = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreatePipelineLayout(myVkInstance->device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout) != VK_SUCCESS) {
|
if (vkCreatePipelineLayout(myVkInstance->device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
throw std::runtime_error("failed to create pipeline layout");
|
throw std::runtime_error("failed to create pipeline layout");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +447,8 @@ void HelloTriangleApplication::createGraphicsPipeline() {
|
|||||||
.basePipelineIndex = -1,
|
.basePipelineIndex = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateGraphicsPipelines(myVkInstance->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {
|
if (vkCreateGraphicsPipelines(myVkInstance->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
throw std::runtime_error("Failed to create graphics pipeline");
|
throw std::runtime_error("Failed to create graphics pipeline");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,13 +471,16 @@ void HelloTriangleApplication::createFrameBuffers() {
|
|||||||
.height = swapChainExtent.height,
|
.height = swapChainExtent.height,
|
||||||
.layers = 1
|
.layers = 1
|
||||||
};
|
};
|
||||||
if (vkCreateFramebuffer(myVkInstance->device, &framebufferCreateInfo, nullptr, &swapChainFrameBuffers[i]) != VK_SUCCESS) {
|
if (vkCreateFramebuffer(myVkInstance->device, &framebufferCreateInfo, nullptr, &swapChainFrameBuffers[i]) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
throw std::runtime_error("Failed to create frame buffer");
|
throw std::runtime_error("Failed to create frame buffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelloTriangleApplication::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
|
void
|
||||||
|
HelloTriangleApplication::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
|
||||||
|
VkBuffer &buffer, VkDeviceMemory &bufferMemory) {
|
||||||
VkBufferCreateInfo bufferCreateInfo{
|
VkBufferCreateInfo bufferCreateInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
.size = size,
|
.size = size,
|
||||||
@@ -501,7 +513,8 @@ void HelloTriangleApplication::createVertexBuffer() {
|
|||||||
VkBuffer stagingBuffer;
|
VkBuffer stagingBuffer;
|
||||||
VkDeviceMemory stagingBufferMemory;
|
VkDeviceMemory stagingBufferMemory;
|
||||||
createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory);
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer,
|
||||||
|
stagingBufferMemory);
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
vkMapMemory(myVkInstance->device, stagingBufferMemory, 0, bufferSize, 0, &data);
|
vkMapMemory(myVkInstance->device, stagingBufferMemory, 0, bufferSize, 0, &data);
|
||||||
@@ -522,7 +535,8 @@ void HelloTriangleApplication::createIndexBuffer() {
|
|||||||
VkBuffer stagingBuffer;
|
VkBuffer stagingBuffer;
|
||||||
VkDeviceMemory stagingBufferMemory;
|
VkDeviceMemory stagingBufferMemory;
|
||||||
createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory);
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer,
|
||||||
|
stagingBufferMemory);
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
vkMapMemory(myVkInstance->device, stagingBufferMemory, 0, bufferSize, 0, &data);
|
vkMapMemory(myVkInstance->device, stagingBufferMemory, 0, bufferSize, 0, &data);
|
||||||
@@ -587,7 +601,9 @@ void HelloTriangleApplication::createUniformBuffers() {
|
|||||||
uniformBuffersMemory.resize(swapChainImages.size());
|
uniformBuffersMemory.resize(swapChainImages.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < swapChainImages.size(); ++i) {
|
for (size_t i = 0; i < swapChainImages.size(); ++i) {
|
||||||
createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, uniformBuffers[i], uniformBuffersMemory[i]);
|
createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, uniformBuffers[i],
|
||||||
|
uniformBuffersMemory[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,7 +647,8 @@ void HelloTriangleApplication::createCommandBuffers() {
|
|||||||
VkDeviceSize offset[] = {0};
|
VkDeviceSize offset[] = {0};
|
||||||
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offset);
|
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offset);
|
||||||
vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
||||||
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr);
|
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1,
|
||||||
|
&descriptorSets[i], 0, nullptr);
|
||||||
vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0);
|
vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0);
|
||||||
vkCmdEndRenderPass(commandBuffers[i]);
|
vkCmdEndRenderPass(commandBuffers[i]);
|
||||||
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
|
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
|
||||||
@@ -654,8 +671,10 @@ void HelloTriangleApplication::createSyncObjects() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
|
for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
|
||||||
if (vkCreateSemaphore(myVkInstance->device, &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]) != VK_SUCCESS ||
|
if (vkCreateSemaphore(myVkInstance->device, &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]) !=
|
||||||
vkCreateSemaphore(myVkInstance->device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]) != VK_SUCCESS ||
|
VK_SUCCESS ||
|
||||||
|
vkCreateSemaphore(myVkInstance->device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]) !=
|
||||||
|
VK_SUCCESS ||
|
||||||
vkCreateFence(myVkInstance->device, &fenceInfo, nullptr, &inFlightFences[i])) {
|
vkCreateFence(myVkInstance->device, &fenceInfo, nullptr, &inFlightFences[i])) {
|
||||||
throw std::runtime_error("failed to create semaphore");
|
throw std::runtime_error("failed to create semaphore");
|
||||||
}
|
}
|
||||||
@@ -707,7 +726,8 @@ void HelloTriangleApplication::cleanupSwapChain() {
|
|||||||
vkDestroyFramebuffer(myVkInstance->device, swapChainFrameBuffer, nullptr);
|
vkDestroyFramebuffer(myVkInstance->device, swapChainFrameBuffer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkFreeCommandBuffers(myVkInstance->device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());
|
vkFreeCommandBuffers(myVkInstance->device, commandPool, static_cast<uint32_t>(commandBuffers.size()),
|
||||||
|
commandBuffers.data());
|
||||||
|
|
||||||
vkDestroyPipeline(myVkInstance->device, graphicsPipeline, nullptr);
|
vkDestroyPipeline(myVkInstance->device, graphicsPipeline, nullptr);
|
||||||
vkDestroyPipelineLayout(myVkInstance->device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(myVkInstance->device, pipelineLayout, nullptr);
|
||||||
@@ -738,7 +758,8 @@ void HelloTriangleApplication::mainLoop() {
|
|||||||
void HelloTriangleApplication::drawFrame() {
|
void HelloTriangleApplication::drawFrame() {
|
||||||
vkWaitForFences(myVkInstance->device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
vkWaitForFences(myVkInstance->device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
||||||
uint32_t imageIndex;
|
uint32_t imageIndex;
|
||||||
VkResult result = vkAcquireNextImageKHR(myVkInstance->device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
|
VkResult result = vkAcquireNextImageKHR(myVkInstance->device, swapChain, UINT64_MAX,
|
||||||
|
imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case VK_ERROR_OUT_OF_DATE_KHR:
|
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||||
recreateSwapChain();
|
recreateSwapChain();
|
||||||
@@ -815,7 +836,8 @@ void HelloTriangleApplication::updateUniformBuffer(uint32_t imageIndex) {
|
|||||||
UniformBufferObject ubo{
|
UniformBufferObject ubo{
|
||||||
.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
||||||
.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
||||||
.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.f),
|
.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f,
|
||||||
|
10.f),
|
||||||
};
|
};
|
||||||
ubo.proj[1][1] *= -1;
|
ubo.proj[1][1] *= -1;
|
||||||
void *data;
|
void *data;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||||
@@ -53,27 +54,44 @@ private:
|
|||||||
|
|
||||||
// Vulkan initialisation
|
// Vulkan initialisation
|
||||||
void createSwapChain();
|
void createSwapChain();
|
||||||
|
|
||||||
void createImageViews();
|
void createImageViews();
|
||||||
|
|
||||||
void createRenderPass();
|
void createRenderPass();
|
||||||
|
|
||||||
void createDescriptorSetLayout();
|
void createDescriptorSetLayout();
|
||||||
|
|
||||||
void createDescriptorPool();
|
void createDescriptorPool();
|
||||||
|
|
||||||
void createDescriptorSets();
|
void createDescriptorSets();
|
||||||
|
|
||||||
void createGraphicsPipeline();
|
void createGraphicsPipeline();
|
||||||
|
|
||||||
void createFrameBuffers();
|
void createFrameBuffers();
|
||||||
|
|
||||||
void createCommandPool();
|
void createCommandPool();
|
||||||
|
|
||||||
void createVertexBuffer();
|
void createVertexBuffer();
|
||||||
|
|
||||||
void createIndexBuffer();
|
void createIndexBuffer();
|
||||||
|
|
||||||
void createUniformBuffers();
|
void createUniformBuffers();
|
||||||
|
|
||||||
void createCommandBuffers();
|
void createCommandBuffers();
|
||||||
|
|
||||||
void createSyncObjects();
|
void createSyncObjects();
|
||||||
|
|
||||||
void initVulkan();
|
void initVulkan();
|
||||||
|
|
||||||
void recreateSwapChain();
|
void recreateSwapChain();
|
||||||
|
|
||||||
void cleanupSwapChain();
|
void cleanupSwapChain();
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
void mainLoop();
|
void mainLoop();
|
||||||
|
|
||||||
void drawFrame();
|
void drawFrame();
|
||||||
|
|
||||||
void updateUniformBuffer(uint32_t imageIndex);
|
void updateUniformBuffer(uint32_t imageIndex);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ bool isSuitableDevice(VkPhysicalDevice device, VkSurfaceKHR surface) {
|
|||||||
vkGetPhysicalDeviceFeatures(device, &features);
|
vkGetPhysicalDeviceFeatures(device, &features);
|
||||||
indices = findQueueFamilies(device, surface);
|
indices = findQueueFamilies(device, surface);
|
||||||
|
|
||||||
bool extensionSupport = checkDeviceExtensionSupport(device, deviceExtensions, sizeof(deviceExtensions) / sizeof(void*));
|
bool extensionSupport = checkDeviceExtensionSupport(device, deviceExtensions,
|
||||||
|
sizeof(deviceExtensions) / sizeof(void *));
|
||||||
bool swapChainAdequate = false;
|
bool swapChainAdequate = false;
|
||||||
if (extensionSupport) {
|
if (extensionSupport) {
|
||||||
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device, surface);
|
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device, surface);
|
||||||
@@ -157,7 +158,8 @@ void MyVkInstance::createLogicalDevice() {
|
|||||||
this->indices = findQueueFamilies(physicalDevice, surface);
|
this->indices = findQueueFamilies(physicalDevice, surface);
|
||||||
|
|
||||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
||||||
std::set<uint32_t> uniqueQueueFamilies = {this->indices.graphicsFamily.value(), this->indices.presentFamily.value()};
|
std::set<uint32_t> uniqueQueueFamilies = {this->indices.graphicsFamily.value(),
|
||||||
|
this->indices.presentFamily.value()};
|
||||||
float queuePriority = 1.0f;
|
float queuePriority = 1.0f;
|
||||||
for (uint32_t queueFamily : uniqueQueueFamilies) {
|
for (uint32_t queueFamily : uniqueQueueFamilies) {
|
||||||
VkDeviceQueueCreateInfo queueCreateInfo{};
|
VkDeviceQueueCreateInfo queueCreateInfo{};
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
#ifndef VULKANTEST_MYVKINSTANCE_H
|
#ifndef VULKANTEST_MYVKINSTANCE_H
|
||||||
#define VULKANTEST_MYVKINSTANCE_H
|
#define VULKANTEST_MYVKINSTANCE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "queues.h"
|
#include "queues.h"
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@
|
|||||||
class MyVkInstance {
|
class MyVkInstance {
|
||||||
public:
|
public:
|
||||||
MyVkInstance();
|
MyVkInstance();
|
||||||
|
|
||||||
MyVkInstance(int width, int height, char *&title);
|
MyVkInstance(int width, int height, char *&title);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
@@ -21,6 +24,7 @@ public:
|
|||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
void getFrameBufferSize(int *pWidth, int *pHeight) const;
|
void getFrameBufferSize(int *pWidth, int *pHeight) const;
|
||||||
|
|
||||||
void registerResizeCallback(void *, void (*callback)(void *, int, int));
|
void registerResizeCallback(void *, void (*callback)(void *, int, int));
|
||||||
|
|
||||||
VkInstance instance{};
|
VkInstance instance{};
|
||||||
@@ -42,6 +46,7 @@ private:
|
|||||||
int height{};
|
int height{};
|
||||||
std::string title;
|
std::string title;
|
||||||
void *framebufferResizeCallbackThis;
|
void *framebufferResizeCallbackThis;
|
||||||
|
|
||||||
void (*framebufferResizeCallback)(void *, int, int) = nullptr;
|
void (*framebufferResizeCallback)(void *, int, int) = nullptr;
|
||||||
|
|
||||||
#ifdef WITH_VALIDATION_LAYERS
|
#ifdef WITH_VALIDATION_LAYERS
|
||||||
@@ -53,9 +58,13 @@ private:
|
|||||||
|
|
||||||
// init vulkan
|
// init vulkan
|
||||||
void initVulkan();
|
void initVulkan();
|
||||||
|
|
||||||
void createInstance();
|
void createInstance();
|
||||||
|
|
||||||
void createSurface();
|
void createSurface();
|
||||||
|
|
||||||
void pickPhysicalDevice();
|
void pickPhysicalDevice();
|
||||||
|
|
||||||
void createLogicalDevice();
|
void createLogicalDevice();
|
||||||
|
|
||||||
static void frameBufferResizeCallbackHandler(GLFWwindow *glfwWindow, int width, int height);
|
static void frameBufferResizeCallbackHandler(GLFWwindow *glfwWindow, int width, int height);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef WITH_VALIDATION_LAYERS
|
#ifdef WITH_VALIDATION_LAYERS
|
||||||
|
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
@@ -18,7 +19,9 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
|||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
|
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
|
||||||
|
const VkAllocationCallbacks *pAllocator,
|
||||||
|
VkDebugUtilsMessengerEXT *pDebugMessenger) {
|
||||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
|
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
|
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
|
||||||
@@ -27,8 +30,10 @@ VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
|
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger,
|
||||||
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
|
const VkAllocationCallbacks *pAllocator) {
|
||||||
|
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance,
|
||||||
|
"vkDestroyDebugUtilsMessengerEXT");
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func(instance, debugMessenger, pAllocator);
|
func(instance, debugMessenger, pAllocator);
|
||||||
}
|
}
|
||||||
@@ -59,8 +64,12 @@ bool checkValidationLayerSupport() {
|
|||||||
void setupDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT *debugMessenger) {
|
void setupDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT *debugMessenger) {
|
||||||
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||||
createInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
createInfo.messageSeverity =
|
||||||
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
|
||||||
|
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||||
|
createInfo.messageType =
|
||||||
|
VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
|
||||||
|
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
||||||
createInfo.pfnUserCallback = debugCallback;
|
createInfo.pfnUserCallback = debugCallback;
|
||||||
createInfo.pUserData = nullptr;
|
createInfo.pUserData = nullptr;
|
||||||
|
|
||||||
@@ -68,4 +77,5 @@ void setupDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT* debugMes
|
|||||||
throw std::runtime_error("Failed to setup debug messenger");
|
throw std::runtime_error("Failed to setup debug messenger");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#ifndef VULKANTEST_DEBUGLAYERS_H
|
#ifndef VULKANTEST_DEBUGLAYERS_H
|
||||||
#define VULKANTEST_DEBUGLAYERS_H
|
#define VULKANTEST_DEBUGLAYERS_H
|
||||||
#ifdef WITH_VALIDATION_LAYERS
|
#ifdef WITH_VALIDATION_LAYERS
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
@@ -17,9 +18,16 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
|||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
|
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
|
||||||
void *pUserData);
|
void *pUserData);
|
||||||
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger);
|
|
||||||
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
|
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
|
||||||
|
const VkAllocationCallbacks *pAllocator,
|
||||||
|
VkDebugUtilsMessengerEXT *pDebugMessenger);
|
||||||
|
|
||||||
|
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger,
|
||||||
|
const VkAllocationCallbacks *pAllocator);
|
||||||
|
|
||||||
bool checkValidationLayerSupport();
|
bool checkValidationLayerSupport();
|
||||||
|
|
||||||
void setupDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT *debugMessenger);
|
void setupDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT *debugMessenger);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -91,7 +91,9 @@ VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, uint3
|
|||||||
return capabilities.currentExtent;
|
return capabilities.currentExtent;
|
||||||
}
|
}
|
||||||
VkExtent2D actualExtend = {width, height};
|
VkExtent2D actualExtend = {width, height};
|
||||||
actualExtend.width = std::max(capabilities.minImageExtent.width, std::min(capabilities.maxImageExtent.width, actualExtend.width));
|
actualExtend.width = std::max(capabilities.minImageExtent.width,
|
||||||
actualExtend.height = std::max(capabilities.minImageExtent.height, std::min(capabilities.maxImageExtent.height, actualExtend.height));
|
std::min(capabilities.maxImageExtent.width, actualExtend.width));
|
||||||
|
actualExtend.height = std::max(capabilities.minImageExtent.height,
|
||||||
|
std::min(capabilities.maxImageExtent.height, actualExtend.height));
|
||||||
return actualExtend;
|
return actualExtend;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#ifndef VULKANTEST_QUEUES_H
|
#ifndef VULKANTEST_QUEUES_H
|
||||||
#define VULKANTEST_QUEUES_H
|
#define VULKANTEST_QUEUES_H
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -24,10 +25,15 @@ struct SwapChainSupportDetails {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool checkDeviceExtensionSupport(VkPhysicalDevice device, const char **deviceExtensions, int size);
|
bool checkDeviceExtensionSupport(VkPhysicalDevice device, const char **deviceExtensions, int size);
|
||||||
|
|
||||||
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface);
|
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface);
|
||||||
|
|
||||||
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
|
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
|
||||||
|
|
||||||
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR> &availableFormats);
|
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR> &availableFormats);
|
||||||
|
|
||||||
VkPresentModeKHR chooseSwapChainPresentMode(const std::vector<VkPresentModeKHR> &availablePresentModes);
|
VkPresentModeKHR chooseSwapChainPresentMode(const std::vector<VkPresentModeKHR> &availablePresentModes);
|
||||||
|
|
||||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities, uint32_t width, uint32_t height);
|
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities, uint32_t width, uint32_t height);
|
||||||
|
|
||||||
#endif //VULKANTEST_QUEUES_H
|
#endif //VULKANTEST_QUEUES_H
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#ifndef VULKANTEST_UTIL_H
|
#ifndef VULKANTEST_UTIL_H
|
||||||
#define VULKANTEST_UTIL_H
|
#define VULKANTEST_UTIL_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user