Examples: Vulkan: Formatting and tweaks (to match SDL's main).
This commit is contained in:
parent
bcdfd5d61c
commit
387f724d33
@ -1,4 +1,4 @@
|
|||||||
// ImGui - standalone example application for Glfw + Vulkan, using programmable pipeline
|
// ImGui - standalone example application for Glfw + Vulkan
|
||||||
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
@ -10,6 +10,7 @@
|
|||||||
#define GLFW_INCLUDE_NONE
|
#define GLFW_INCLUDE_NONE
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
#define IMGUI_MAX_POSSIBLE_BACK_BUFFERS 16
|
#define IMGUI_MAX_POSSIBLE_BACK_BUFFERS 16
|
||||||
#define IMGUI_UNLIMITED_FRAME_RATE
|
#define IMGUI_UNLIMITED_FRAME_RATE
|
||||||
@ -59,7 +60,7 @@ static void check_vk_result(VkResult err)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resize_vulkan(GLFWwindow* /*window*/, int w, int h)
|
static void resize_vulkan(GLFWwindow*, int w, int h)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
VkSwapchainKHR old_swapchain = g_Swapchain;
|
VkSwapchainKHR old_swapchain = g_Swapchain;
|
||||||
@ -199,19 +200,16 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(
|
|||||||
}
|
}
|
||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
|
|
||||||
static void setup_vulkan(GLFWwindow* window)
|
static void setup_vulkan(GLFWwindow* window, const char** extensions, uint32_t extensions_count)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
|
||||||
// Create Vulkan Instance
|
// Create Vulkan Instance
|
||||||
{
|
{
|
||||||
uint32_t extensions_count;
|
|
||||||
const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
|
||||||
|
|
||||||
VkInstanceCreateInfo create_info = {};
|
VkInstanceCreateInfo create_info = {};
|
||||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
create_info.enabledExtensionCount = extensions_count;
|
create_info.enabledExtensionCount = extensions_count;
|
||||||
create_info.ppEnabledExtensionNames = glfw_extensions;
|
create_info.ppEnabledExtensionNames = extensions;
|
||||||
|
|
||||||
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
||||||
// enabling multiple validation layers grouped as lunarg standard validation
|
// enabling multiple validation layers grouped as lunarg standard validation
|
||||||
@ -222,7 +220,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
// need additional storage for char pointer to debug report extension
|
// need additional storage for char pointer to debug report extension
|
||||||
const char** extensions = (const char**)malloc(sizeof(const char*) * (extensions_count + 1));
|
const char** extensions = (const char**)malloc(sizeof(const char*) * (extensions_count + 1));
|
||||||
for (size_t i = 0; i < extensions_count; i++)
|
for (size_t i = 0; i < extensions_count; i++)
|
||||||
extensions[i] = glfw_extensions[i];
|
extensions[i] = extensions[i];
|
||||||
extensions[extensions_count] = "VK_EXT_debug_report";
|
extensions[extensions_count] = "VK_EXT_debug_report";
|
||||||
create_info.enabledExtensionCount = extensions_count + 1;
|
create_info.enabledExtensionCount = extensions_count + 1;
|
||||||
create_info.ppEnabledExtensionNames = extensions;
|
create_info.ppEnabledExtensionNames = extensions;
|
||||||
@ -250,7 +248,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Window Surface
|
// Create Window Surface (with GLFW)
|
||||||
{
|
{
|
||||||
err = glfwCreateWindowSurface(g_Instance, window, g_Allocator, &g_Surface);
|
err = glfwCreateWindowSurface(g_Instance, window, g_Allocator, &g_Surface);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
@ -333,9 +331,8 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
bool requestedFound = false;
|
bool requestedFound = false;
|
||||||
for (size_t i = 0; i < sizeof(requestSurfaceImageFormat) / sizeof(requestSurfaceImageFormat[0]); i++)
|
for (size_t i = 0; i < sizeof(requestSurfaceImageFormat) / sizeof(requestSurfaceImageFormat[0]); i++)
|
||||||
{
|
{
|
||||||
if( requestedFound ) {
|
if (requestedFound)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
for (uint32_t j = 0; j < count; j++)
|
for (uint32_t j = 0; j < count; j++)
|
||||||
{
|
{
|
||||||
if (formats[j].format == requestSurfaceImageFormat[i] && formats[j].colorSpace == requestSurfaceColorSpace)
|
if (formats[j].format == requestSurfaceImageFormat[i] && formats[j].colorSpace == requestSurfaceColorSpace)
|
||||||
@ -612,7 +609,9 @@ int main(int, char**)
|
|||||||
printf("GLFW: Vulkan Not Supported\n");
|
printf("GLFW: Vulkan Not Supported\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
setup_vulkan(window);
|
uint32_t extensions_count = 0;
|
||||||
|
const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
||||||
|
setup_vulkan(window, glfw_extensions, extensions_count);
|
||||||
|
|
||||||
// Setup ImGui binding
|
// Setup ImGui binding
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
@ -739,6 +738,7 @@ int main(int, char**)
|
|||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rendering
|
||||||
memcpy(&g_ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
|
memcpy(&g_ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
|
||||||
frame_begin();
|
frame_begin();
|
||||||
ImGui_ImplVulkan_Render(g_CommandBuffer[g_FrameIndex]);
|
ImGui_ImplVulkan_Render(g_CommandBuffer[g_FrameIndex]);
|
||||||
|
Loading…
Reference in New Issue
Block a user