Complete "Hello Triangle" program with resizing and minimization handled
This commit is contained in:
@@ -17,6 +17,8 @@ const std::vector<const char*> deviceExtensions = {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
||||
};
|
||||
|
||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
#ifdef NDEBUG
|
||||
const bool enableValidationLayers = false;
|
||||
#else
|
||||
@@ -44,7 +46,7 @@ struct SwapChainSupportDetails {
|
||||
class VulkanApp {
|
||||
public:
|
||||
VulkanApp(const uint32_t& _w, const uint32_t& _h) :
|
||||
mWidth(_w), mHeight(_h), mWin(nullptr), mActive(false) {}
|
||||
mWin(nullptr), mWidth(_w), mHeight(_h) {}
|
||||
|
||||
void init();
|
||||
void loop();
|
||||
@@ -55,9 +57,11 @@ private:
|
||||
SDL_Event mEvent;
|
||||
|
||||
// Not tied to library
|
||||
const uint32_t mWidth;
|
||||
const uint32_t mHeight;
|
||||
bool mActive;
|
||||
uint32_t mWidth;
|
||||
uint32_t mHeight;
|
||||
bool mActive = false;
|
||||
bool mResized = false;
|
||||
bool mMinimized = false;
|
||||
|
||||
// Vulkan
|
||||
VkInstance mInstance;
|
||||
@@ -77,14 +81,14 @@ private:
|
||||
VkPipeline mGraphicsPipeline;
|
||||
|
||||
VkCommandPool mCommandPool;
|
||||
VkCommandBuffer mCommandBuffer;
|
||||
std::vector<VkCommandBuffer> mCommandBuffers;
|
||||
|
||||
VkQueue mGraphicsQueue;
|
||||
VkQueue mPresentQueue;
|
||||
|
||||
VkSemaphore mImageAvailableSemaphore;
|
||||
VkSemaphore mRenderFinishedSemaphore;
|
||||
VkFence mInFlightFence;
|
||||
std::vector<VkSemaphore> mImageAvailableSemaphores;
|
||||
std::vector<VkSemaphore> mRenderFinishedSemaphores;
|
||||
std::vector<VkFence> mInFlightFences;
|
||||
|
||||
|
||||
VkDebugUtilsMessengerEXT mDebugMessenger;
|
||||
@@ -92,7 +96,11 @@ private:
|
||||
void createInstance();
|
||||
void selectPhysicalDevice();
|
||||
void createLogicalDevice();
|
||||
|
||||
void createSwapChain();
|
||||
void recreateSwapChain();
|
||||
void cleanupSwapChain();
|
||||
|
||||
void createImageViews();
|
||||
void createRenderPass();
|
||||
void createGraphicsPipeline();
|
||||
@@ -118,7 +126,15 @@ private:
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) {
|
||||
fprintf(stderr, "Validation Layer: %s \n", pCallbackData->pMessage);
|
||||
(void)pUserData;
|
||||
|
||||
if(messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||
fprintf(stderr, "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);
|
||||
} else {
|
||||
fprintf(stderr, "Validation Layer: %s \n", pCallbackData->pMessage);
|
||||
}
|
||||
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user