Small tweaks
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_init.h>
|
||||
#include <SDL3/SDL_log.h>
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vk_types.hh"
|
||||
|
||||
const std::vector<const char*> validationLayers = {
|
||||
"VK_LAYER_KHRONOS_validation"
|
||||
@@ -21,56 +25,42 @@ const std::vector<const char*> deviceExtensions = {
|
||||
|
||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
#ifdef NDEBUG
|
||||
const bool enableValidationLayers = false;
|
||||
#else
|
||||
const bool enableValidationLayers = true;
|
||||
#endif
|
||||
|
||||
VkResult CreateDebugUtilsMessengerEXT(VkInstance, const VkDebugUtilsMessengerCreateInfoEXT*, const VkAllocationCallbacks*, VkDebugUtilsMessengerEXT*);
|
||||
void DestroyDebugUtilsMessengerEXT(VkInstance, VkDebugUtilsMessengerEXT, const VkAllocationCallbacks*);
|
||||
|
||||
struct QueueFamilyIndices {
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
|
||||
bool complete() {
|
||||
return graphicsFamily.has_value() && presentFamily.has_value();
|
||||
}
|
||||
};
|
||||
|
||||
struct SwapChainSupportDetails {
|
||||
VkSurfaceCapabilitiesKHR capabilities;
|
||||
std::vector<VkSurfaceFormatKHR> formats;
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
};
|
||||
|
||||
class VulkanApp {
|
||||
public:
|
||||
VulkanApp(const uint32_t& _w, const uint32_t& _h) :
|
||||
mWin(nullptr), mWidth(_w), mHeight(_h) {}
|
||||
VulkanApp(const char *_t, const uint32_t& _w, const uint32_t& _h) :
|
||||
mWin(nullptr), mWidth(_w), mHeight(_h), mTitle(_t),
|
||||
mResized(false), mMinimized(false),
|
||||
mPhysicalDevice(nullptr) {}
|
||||
~VulkanApp() { cleanup(); }
|
||||
|
||||
void init();
|
||||
void loop();
|
||||
void cleanup();
|
||||
SDL_AppResult mAppState = SDL_APP_CONTINUE;
|
||||
SDL_AppResult init();
|
||||
SDL_AppResult loop();
|
||||
inline bool minimized() { return mMinimized; }
|
||||
inline void minimized(bool v) { mMinimized = v; }
|
||||
inline void resized(bool v) { mResized = v; }
|
||||
inline void minimized(bool _v) { mMinimized = _v; }
|
||||
inline void resized(bool _v) { mResized = _v; }
|
||||
private:
|
||||
// SDL2
|
||||
// SDL3
|
||||
SDL_Window *mWin;
|
||||
SDL_Event mEvent;
|
||||
|
||||
// Not tied to library
|
||||
uint32_t mWidth;
|
||||
uint32_t mHeight;
|
||||
// bool mActive = false;
|
||||
bool mResized = false;
|
||||
bool mMinimized = false;
|
||||
const char *mTitle;
|
||||
bool mResized;
|
||||
bool mMinimized;
|
||||
|
||||
#ifdef NDEBUG
|
||||
const bool mEnableValidationLayers = false;
|
||||
#else
|
||||
const bool mEnableValidationLayers = true;
|
||||
#endif
|
||||
|
||||
// Vulkan
|
||||
VkInstance mInstance;
|
||||
VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice mPhysicalDevice;
|
||||
VkDevice mLogicalDevice;
|
||||
VkSurfaceKHR mSurface;
|
||||
|
||||
@@ -95,7 +85,6 @@ private:
|
||||
std::vector<VkSemaphore> mRenderFinishedSemaphores;
|
||||
std::vector<VkFence> mInFlightFences;
|
||||
|
||||
|
||||
VkDebugUtilsMessengerEXT mDebugMessenger;
|
||||
|
||||
void createInstance();
|
||||
@@ -116,6 +105,7 @@ private:
|
||||
|
||||
void recordCommandBuffer(VkCommandBuffer, uint32_t);
|
||||
void drawFrame();
|
||||
void cleanup();
|
||||
|
||||
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice);
|
||||
bool isDeviceSuitable(VkPhysicalDevice);
|
||||
@@ -135,11 +125,11 @@ private:
|
||||
(void)pUserData;
|
||||
|
||||
if(messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||
fprintf(stderr, "Validation Layer [Error/Warning]: %s \n", pCallbackData->pMessage);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Validation Layer [Error/Warning]: %s \n", pCallbackData->pMessage);
|
||||
} else if(messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) {
|
||||
fprintf(stderr, "Validation Layer [General]: %s \n", pCallbackData->pMessage);
|
||||
SDL_Log("Validation Layer [General]: %s \n", pCallbackData->pMessage);
|
||||
} else {
|
||||
fprintf(stderr, "Validation Layer: %s \n", pCallbackData->pMessage);
|
||||
SDL_Log("Validation Layer: %s \n", pCallbackData->pMessage);
|
||||
}
|
||||
|
||||
return VK_FALSE;
|
||||
18
include/vk_types.hh
Normal file
18
include/vk_types.hh
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
struct QueueFamilyIndices {
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
|
||||
bool complete() {
|
||||
return graphicsFamily.has_value() && presentFamily.has_value();
|
||||
}
|
||||
};
|
||||
|
||||
struct SwapChainSupportDetails {
|
||||
VkSurfaceCapabilitiesKHR capabilities;
|
||||
std::vector<VkSurfaceFormatKHR> formats;
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
};
|
||||
Reference in New Issue
Block a user