Hacked in vulkan support for macOS
This commit is contained in:
+3
-1
@@ -12,6 +12,7 @@ find_package(OpenGL REQUIRED)
|
|||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
|
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
|
||||||
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
add_subdirectory(external/discord-rpc)
|
add_subdirectory(external/discord-rpc)
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ add_executable(ossp MACOSX_BUNDLE
|
|||||||
external/imgui/imgui_demo.cpp
|
external/imgui/imgui_demo.cpp
|
||||||
external/imgui/backends/imgui_impl_sdl2.cpp
|
external/imgui/backends/imgui_impl_sdl2.cpp
|
||||||
external/imgui/backends/imgui_impl_opengl2.cpp
|
external/imgui/backends/imgui_impl_opengl2.cpp
|
||||||
|
external/imgui/backends/imgui_impl_vulkan.cpp
|
||||||
external/sqlite3/sqlite3.c
|
external/sqlite3/sqlite3.c
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -82,4 +84,4 @@ else()
|
|||||||
include_directories(${GSTREAMER_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIRS})
|
include_directories(${GSTREAMER_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIRS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(ossp PRIVATE OpenSSL::SSL OpenSSL::Crypto CURL::libcurl SDL2::SDL2 ${OPENGL_LIBRARIES} discord-rpc ${BZ2_LIBRARIES} ${GSTREAMER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVUTIL_LIBRARIES} avformat avutil)
|
target_link_libraries(ossp PRIVATE OpenSSL::SSL OpenSSL::Crypto CURL::libcurl SDL2::SDL2 ${OPENGL_LIBRARIES} Vulkan::Vulkan discord-rpc ${BZ2_LIBRARIES} ${GSTREAMER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVUTIL_LIBRARIES} avformat avutil)
|
||||||
|
|||||||
+1894
File diff suppressed because it is too large
Load Diff
+235
@@ -0,0 +1,235 @@
|
|||||||
|
// dear imgui: Renderer Backend for Vulkan
|
||||||
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||||
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|
||||||
|
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
|
||||||
|
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
|
||||||
|
// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
|
||||||
|
// You will use those if you want to use this rendering backend in your engine/app.
|
||||||
|
// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
|
||||||
|
// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
|
||||||
|
// Read comments in imgui_impl_vulkan.h.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "../imgui.h" // IMGUI_IMPL_API
|
||||||
|
|
||||||
|
// [Configuration] in order to use a custom Vulkan function loader:
|
||||||
|
// (1) You'll need to disable default Vulkan function prototypes.
|
||||||
|
// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag.
|
||||||
|
// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit:
|
||||||
|
// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file
|
||||||
|
// - Or as a compilation flag in your build system
|
||||||
|
// - Or uncomment here (not recommended because you'd be modifying imgui sources!)
|
||||||
|
// - Do not simply add it in a .cpp file!
|
||||||
|
// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function.
|
||||||
|
// If you have no idea what this is, leave it alone!
|
||||||
|
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
||||||
|
|
||||||
|
// Convenience support for Volk
|
||||||
|
// (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().)
|
||||||
|
//#define IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
|
||||||
|
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
||||||
|
#define VK_NO_PROTOTYPES
|
||||||
|
#endif
|
||||||
|
#if defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(NOMINMAX)
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Vulkan includes
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
#include <volk.h>
|
||||||
|
#else
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
#endif
|
||||||
|
#if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering)
|
||||||
|
#define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Backend uses a small number of descriptors per font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
|
||||||
|
#define IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE (8) // Minimum per atlas
|
||||||
|
|
||||||
|
// Initialization data, for ImGui_ImplVulkan_Init()
|
||||||
|
// [Please zero-clear before use!]
|
||||||
|
// - About descriptor pool:
|
||||||
|
// - A VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
|
||||||
|
// and must contain a pool size large enough to hold a small number of VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptors.
|
||||||
|
// - As an convenience, by setting DescriptorPoolSize > 0 the backend will create one for you.
|
||||||
|
// - About dynamic rendering:
|
||||||
|
// - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure.
|
||||||
|
struct ImGui_ImplVulkan_InitInfo
|
||||||
|
{
|
||||||
|
uint32_t ApiVersion; // Fill with API version of Instance, e.g. VK_API_VERSION_1_3 or your value of VkApplicationInfo::apiVersion. May be lower than header version (VK_HEADER_VERSION_COMPLETE)
|
||||||
|
VkInstance Instance;
|
||||||
|
VkPhysicalDevice PhysicalDevice;
|
||||||
|
VkDevice Device;
|
||||||
|
uint32_t QueueFamily;
|
||||||
|
VkQueue Queue;
|
||||||
|
VkDescriptorPool DescriptorPool; // See requirements in note above; ignored if using DescriptorPoolSize > 0
|
||||||
|
uint32_t DescriptorPoolSize; // Optional: set to create internal descriptor pool automatically instead of using DescriptorPool.
|
||||||
|
uint32_t MinImageCount; // >= 2
|
||||||
|
uint32_t ImageCount; // >= MinImageCount
|
||||||
|
VkPipelineCache PipelineCache; // Optional
|
||||||
|
|
||||||
|
// Pipeline
|
||||||
|
VkRenderPass RenderPass; // Ignored if using dynamic rendering
|
||||||
|
uint32_t Subpass;
|
||||||
|
VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT
|
||||||
|
|
||||||
|
// (Optional) Dynamic Rendering
|
||||||
|
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineRenderingCreateInfo.
|
||||||
|
bool UseDynamicRendering;
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||||
|
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// (Optional) Allocation, Debugging
|
||||||
|
const VkAllocationCallbacks* Allocator;
|
||||||
|
void (*CheckVkResultFn)(VkResult err);
|
||||||
|
VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to recreate pipeline without reinitializing the backend (see #8110, #8111)
|
||||||
|
// The main window pipeline will be created by ImGui_ImplVulkan_Init() if possible (== RenderPass xor (UseDynamicRendering && PipelineRenderingCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR))
|
||||||
|
// Else, the pipeline can be created, or re-created, using ImGui_ImplVulkan_CreateMainPipeline() before rendering.
|
||||||
|
struct ImGui_ImplVulkan_MainPipelineCreateInfo
|
||||||
|
{
|
||||||
|
VkRenderPass RenderPass = VK_NULL_HANDLE;
|
||||||
|
uint32_t Subpass = 0;
|
||||||
|
VkSampleCountFlagBits MSAASamples = {};
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||||
|
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_CreateMainPipeline(const ImGui_ImplVulkan_MainPipelineCreateInfo& info); // (render_pass xor (p_dynamic_rendering && p_dynamic_rendering is correct (sType and pNext)))
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
|
// Register a texture (VkDescriptorSet == ImTextureID)
|
||||||
|
// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem
|
||||||
|
// Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
|
||||||
|
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set);
|
||||||
|
|
||||||
|
// Optional: load Vulkan functions with a custom function loader
|
||||||
|
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
|
||||||
|
|
||||||
|
// [BETA] Selected render state data shared with callbacks.
|
||||||
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call.
|
||||||
|
// (Please open an issue if you feel you need access to more data)
|
||||||
|
struct ImGui_ImplVulkan_RenderState
|
||||||
|
{
|
||||||
|
VkCommandBuffer CommandBuffer;
|
||||||
|
VkPipeline Pipeline;
|
||||||
|
VkPipelineLayout PipelineLayout;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Internal / Miscellaneous Vulkan Helpers
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.
|
||||||
|
//
|
||||||
|
// You probably do NOT need to use or care about those functions.
|
||||||
|
// Those functions only exist because:
|
||||||
|
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
||||||
|
// 2) the multi-viewport / platform window implementation needs them internally.
|
||||||
|
// Generally we avoid exposing any kind of superfluous high-level helpers in the backends,
|
||||||
|
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
||||||
|
//
|
||||||
|
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain,
|
||||||
|
// render pass, frame buffers, etc.). You may read this code if you are curious, but
|
||||||
|
// it is recommended you use your own custom tailored code to do equivalent work.
|
||||||
|
//
|
||||||
|
// We don't provide a strong guarantee that we won't change those functions API.
|
||||||
|
//
|
||||||
|
// The ImGui_ImplVulkanH_XXX functions should NOT interact with any of the state used
|
||||||
|
// by the regular ImGui_ImplVulkan_XXX functions.
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct ImGui_ImplVulkanH_Frame;
|
||||||
|
struct ImGui_ImplVulkanH_Window;
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
|
||||||
|
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
||||||
|
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
||||||
|
IMGUI_IMPL_API VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance);
|
||||||
|
IMGUI_IMPL_API uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device);
|
||||||
|
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||||
|
|
||||||
|
// Helper structure to hold the data needed by one rendering frame
|
||||||
|
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||||
|
// [Please zero-clear before use!]
|
||||||
|
struct ImGui_ImplVulkanH_Frame
|
||||||
|
{
|
||||||
|
VkCommandPool CommandPool;
|
||||||
|
VkCommandBuffer CommandBuffer;
|
||||||
|
VkFence Fence;
|
||||||
|
VkImage Backbuffer;
|
||||||
|
VkImageView BackbufferView;
|
||||||
|
VkFramebuffer Framebuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGui_ImplVulkanH_FrameSemaphores
|
||||||
|
{
|
||||||
|
VkSemaphore ImageAcquiredSemaphore;
|
||||||
|
VkSemaphore RenderCompleteSemaphore;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper structure to hold the data needed by one rendering context into one OS window
|
||||||
|
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||||
|
struct ImGui_ImplVulkanH_Window
|
||||||
|
{
|
||||||
|
int Width;
|
||||||
|
int Height;
|
||||||
|
VkSwapchainKHR Swapchain;
|
||||||
|
VkSurfaceKHR Surface;
|
||||||
|
VkSurfaceFormatKHR SurfaceFormat;
|
||||||
|
VkPresentModeKHR PresentMode;
|
||||||
|
VkRenderPass RenderPass;
|
||||||
|
VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo
|
||||||
|
bool UseDynamicRendering;
|
||||||
|
bool ClearEnable;
|
||||||
|
VkClearValue ClearValue;
|
||||||
|
uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
|
||||||
|
uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
|
||||||
|
uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR
|
||||||
|
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
||||||
|
ImVector<ImGui_ImplVulkanH_Frame> Frames;
|
||||||
|
ImVector<ImGui_ImplVulkanH_FrameSemaphores> FrameSemaphores;
|
||||||
|
|
||||||
|
ImGui_ImplVulkanH_Window()
|
||||||
|
{
|
||||||
|
memset((void*)this, 0, sizeof(*this));
|
||||||
|
PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
|
||||||
|
ClearEnable = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
+369
-26
@@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
#include "../external/imgui/imgui.h"
|
#include "../external/imgui/imgui.h"
|
||||||
#include "../external/imgui/backends/imgui_impl_sdl2.h"
|
#include "../external/imgui/backends/imgui_impl_sdl2.h"
|
||||||
#include "../external/imgui/backends/imgui_impl_opengl2.h"
|
#include "../external/imgui/backends/imgui_impl_vulkan.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_opengl.h>
|
#include <SDL_vulkan.h>
|
||||||
#include "gui_entry.hpp"
|
#include "gui_entry.hpp"
|
||||||
#include "../configHandler.h"
|
#include "../configHandler.h"
|
||||||
#include "../libopensubsonic/httpclient.h"
|
#include "../libopensubsonic/httpclient.h"
|
||||||
@@ -24,6 +24,315 @@
|
|||||||
#include "../player/player.h"
|
#include "../player/player.h"
|
||||||
#include "../libopensubsonic/endpoint_getInternetRadioStations.h"
|
#include "../libopensubsonic/endpoint_getInternetRadioStations.h"
|
||||||
|
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
#define VOLK_IMPLEMENTATION
|
||||||
|
#include <volk.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static VkAllocationCallbacks* g_Allocator = nullptr;
|
||||||
|
static VkInstance g_Instance = VK_NULL_HANDLE;
|
||||||
|
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
||||||
|
static VkDevice g_Device = VK_NULL_HANDLE;
|
||||||
|
static uint32_t g_QueueFamily = (uint32_t)-1;
|
||||||
|
static VkQueue g_Queue = VK_NULL_HANDLE;
|
||||||
|
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||||
|
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
static ImGui_ImplVulkanH_Window g_MainWindowData;
|
||||||
|
static uint32_t g_MinImageCount = 2;
|
||||||
|
static bool g_SwapChainRebuild = false;
|
||||||
|
|
||||||
|
static void check_vk_result(VkResult err)
|
||||||
|
{
|
||||||
|
if (err == VK_SUCCESS)
|
||||||
|
return;
|
||||||
|
fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err);
|
||||||
|
if (err < 0)
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData)
|
||||||
|
{
|
||||||
|
(void)flags; (void)object; (void)location; (void)messageCode; (void)pUserData; (void)pLayerPrefix; // Unused arguments
|
||||||
|
fprintf(stderr, "[vulkan] Debug report from ObjectType: %i\nMessage: %s\n\n", objectType, pMessage);
|
||||||
|
return VK_FALSE;
|
||||||
|
}
|
||||||
|
#endif // APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
|
||||||
|
static bool IsExtensionAvailable(const ImVector<VkExtensionProperties>& properties, const char* extension)
|
||||||
|
{
|
||||||
|
for (const VkExtensionProperties& p : properties)
|
||||||
|
if (strcmp(p.extensionName, extension) == 0)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
||||||
|
{
|
||||||
|
VkResult err;
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
volkInitialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create Vulkan Instance
|
||||||
|
{
|
||||||
|
VkInstanceCreateInfo create_info = {};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
|
|
||||||
|
// Enumerate available extensions
|
||||||
|
uint32_t properties_count;
|
||||||
|
ImVector<VkExtensionProperties> properties;
|
||||||
|
vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, nullptr);
|
||||||
|
properties.resize(properties_count);
|
||||||
|
err = vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, properties.Data);
|
||||||
|
check_vk_result(err);
|
||||||
|
|
||||||
|
// Enable required extensions
|
||||||
|
if (IsExtensionAvailable(properties, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
|
||||||
|
instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
|
||||||
|
#ifdef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME
|
||||||
|
if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME))
|
||||||
|
{
|
||||||
|
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||||
|
create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enabling validation layers
|
||||||
|
#ifdef APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
const char* layers[] = { "VK_LAYER_KHRONOS_validation" };
|
||||||
|
create_info.enabledLayerCount = 1;
|
||||||
|
create_info.ppEnabledLayerNames = layers;
|
||||||
|
instance_extensions.push_back("VK_EXT_debug_report");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create Vulkan Instance
|
||||||
|
create_info.enabledExtensionCount = (uint32_t)instance_extensions.Size;
|
||||||
|
create_info.ppEnabledExtensionNames = instance_extensions.Data;
|
||||||
|
err = vkCreateInstance(&create_info, g_Allocator, &g_Instance);
|
||||||
|
check_vk_result(err);
|
||||||
|
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
volkLoadInstance(g_Instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Setup the debug report callback
|
||||||
|
#ifdef APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
auto f_vkCreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT");
|
||||||
|
IM_ASSERT(f_vkCreateDebugReportCallbackEXT != nullptr);
|
||||||
|
VkDebugReportCallbackCreateInfoEXT debug_report_ci = {};
|
||||||
|
debug_report_ci.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
|
||||||
|
debug_report_ci.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
|
||||||
|
debug_report_ci.pfnCallback = debug_report;
|
||||||
|
debug_report_ci.pUserData = nullptr;
|
||||||
|
err = f_vkCreateDebugReportCallbackEXT(g_Instance, &debug_report_ci, g_Allocator, &g_DebugReport);
|
||||||
|
check_vk_result(err);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select Physical Device (GPU)
|
||||||
|
g_PhysicalDevice = ImGui_ImplVulkanH_SelectPhysicalDevice(g_Instance);
|
||||||
|
IM_ASSERT(g_PhysicalDevice != VK_NULL_HANDLE);
|
||||||
|
|
||||||
|
// Select graphics queue family
|
||||||
|
g_QueueFamily = ImGui_ImplVulkanH_SelectQueueFamilyIndex(g_PhysicalDevice);
|
||||||
|
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
||||||
|
|
||||||
|
// Create Logical Device (with 1 queue)
|
||||||
|
{
|
||||||
|
ImVector<const char*> device_extensions;
|
||||||
|
device_extensions.push_back("VK_KHR_swapchain");
|
||||||
|
|
||||||
|
// Enumerate physical device extension
|
||||||
|
uint32_t properties_count;
|
||||||
|
ImVector<VkExtensionProperties> properties;
|
||||||
|
vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, nullptr);
|
||||||
|
properties.resize(properties_count);
|
||||||
|
vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, properties.Data);
|
||||||
|
#ifdef VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME
|
||||||
|
if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME))
|
||||||
|
device_extensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const float queue_priority[] = { 1.0f };
|
||||||
|
VkDeviceQueueCreateInfo queue_info[1] = {};
|
||||||
|
queue_info[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||||
|
queue_info[0].queueFamilyIndex = g_QueueFamily;
|
||||||
|
queue_info[0].queueCount = 1;
|
||||||
|
queue_info[0].pQueuePriorities = queue_priority;
|
||||||
|
VkDeviceCreateInfo create_info = {};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||||
|
create_info.queueCreateInfoCount = sizeof(queue_info) / sizeof(queue_info[0]);
|
||||||
|
create_info.pQueueCreateInfos = queue_info;
|
||||||
|
create_info.enabledExtensionCount = (uint32_t)device_extensions.Size;
|
||||||
|
create_info.ppEnabledExtensionNames = device_extensions.Data;
|
||||||
|
err = vkCreateDevice(g_PhysicalDevice, &create_info, g_Allocator, &g_Device);
|
||||||
|
check_vk_result(err);
|
||||||
|
vkGetDeviceQueue(g_Device, g_QueueFamily, 0, &g_Queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Descriptor Pool
|
||||||
|
// If you wish to load e.g. additional textures you may need to alter pools sizes and maxSets.
|
||||||
|
{
|
||||||
|
VkDescriptorPoolSize pool_sizes[] =
|
||||||
|
{
|
||||||
|
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
|
||||||
|
};
|
||||||
|
VkDescriptorPoolCreateInfo pool_info = {};
|
||||||
|
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
|
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||||
|
pool_info.maxSets = 0;
|
||||||
|
for (VkDescriptorPoolSize& pool_size : pool_sizes)
|
||||||
|
pool_info.maxSets += pool_size.descriptorCount;
|
||||||
|
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
|
||||||
|
pool_info.pPoolSizes = pool_sizes;
|
||||||
|
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);
|
||||||
|
check_vk_result(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo.
|
||||||
|
// Your real engine/app may not use them.
|
||||||
|
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
||||||
|
{
|
||||||
|
wd->Surface = surface;
|
||||||
|
|
||||||
|
// Check for WSI support
|
||||||
|
VkBool32 res;
|
||||||
|
vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, wd->Surface, &res);
|
||||||
|
if (res != VK_TRUE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error no WSI support on physical device 0\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select Surface Format
|
||||||
|
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
|
||||||
|
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
|
||||||
|
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);
|
||||||
|
|
||||||
|
// Select Present Mode
|
||||||
|
#ifdef APP_USE_UNLIMITED_FRAME_RATE
|
||||||
|
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
|
||||||
|
#else
|
||||||
|
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
|
||||||
|
#endif
|
||||||
|
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
|
||||||
|
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
||||||
|
|
||||||
|
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||||
|
IM_ASSERT(g_MinImageCount >= 2);
|
||||||
|
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CleanupVulkan()
|
||||||
|
{
|
||||||
|
vkDestroyDescriptorPool(g_Device, g_DescriptorPool, g_Allocator);
|
||||||
|
|
||||||
|
#ifdef APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
// Remove the debug report callback
|
||||||
|
auto f_vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkDestroyDebugReportCallbackEXT");
|
||||||
|
f_vkDestroyDebugReportCallbackEXT(g_Instance, g_DebugReport, g_Allocator);
|
||||||
|
#endif // APP_USE_VULKAN_DEBUG_REPORT
|
||||||
|
|
||||||
|
vkDestroyDevice(g_Device, g_Allocator);
|
||||||
|
vkDestroyInstance(g_Instance, g_Allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CleanupVulkanWindow()
|
||||||
|
{
|
||||||
|
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, &g_MainWindowData, g_Allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FrameRender(ImGui_ImplVulkanH_Window* wd, ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
VkSemaphore image_acquired_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore;
|
||||||
|
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
|
||||||
|
VkResult err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
|
||||||
|
if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
|
||||||
|
g_SwapChainRebuild = true;
|
||||||
|
if (err == VK_ERROR_OUT_OF_DATE_KHR)
|
||||||
|
return;
|
||||||
|
if (err != VK_SUBOPTIMAL_KHR)
|
||||||
|
check_vk_result(err);
|
||||||
|
|
||||||
|
ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
|
||||||
|
{
|
||||||
|
err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
|
||||||
|
check_vk_result(err);
|
||||||
|
|
||||||
|
err = vkResetFences(g_Device, 1, &fd->Fence);
|
||||||
|
check_vk_result(err);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
|
||||||
|
check_vk_result(err);
|
||||||
|
VkCommandBufferBeginInfo info = {};
|
||||||
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||||
|
err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
|
||||||
|
check_vk_result(err);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
VkRenderPassBeginInfo info = {};
|
||||||
|
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
|
info.renderPass = wd->RenderPass;
|
||||||
|
info.framebuffer = fd->Framebuffer;
|
||||||
|
info.renderArea.extent.width = wd->Width;
|
||||||
|
info.renderArea.extent.height = wd->Height;
|
||||||
|
info.clearValueCount = 1;
|
||||||
|
info.pClearValues = &wd->ClearValue;
|
||||||
|
vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record dear imgui primitives into command buffer
|
||||||
|
ImGui_ImplVulkan_RenderDrawData(draw_data, fd->CommandBuffer);
|
||||||
|
|
||||||
|
// Submit command buffer
|
||||||
|
vkCmdEndRenderPass(fd->CommandBuffer);
|
||||||
|
{
|
||||||
|
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
VkSubmitInfo info = {};
|
||||||
|
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
info.waitSemaphoreCount = 1;
|
||||||
|
info.pWaitSemaphores = &image_acquired_semaphore;
|
||||||
|
info.pWaitDstStageMask = &wait_stage;
|
||||||
|
info.commandBufferCount = 1;
|
||||||
|
info.pCommandBuffers = &fd->CommandBuffer;
|
||||||
|
info.signalSemaphoreCount = 1;
|
||||||
|
info.pSignalSemaphores = &render_complete_semaphore;
|
||||||
|
|
||||||
|
err = vkEndCommandBuffer(fd->CommandBuffer);
|
||||||
|
check_vk_result(err);
|
||||||
|
err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
|
||||||
|
check_vk_result(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FramePresent(ImGui_ImplVulkanH_Window* wd)
|
||||||
|
{
|
||||||
|
if (g_SwapChainRebuild)
|
||||||
|
return;
|
||||||
|
VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
|
||||||
|
VkPresentInfoKHR info = {};
|
||||||
|
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
|
info.waitSemaphoreCount = 1;
|
||||||
|
info.pWaitSemaphores = &render_complete_semaphore;
|
||||||
|
info.swapchainCount = 1;
|
||||||
|
info.pSwapchains = &wd->Swapchain;
|
||||||
|
info.pImageIndices = &wd->FrameIndex;
|
||||||
|
VkResult err = vkQueuePresentKHR(g_Queue, &info);
|
||||||
|
if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
|
||||||
|
g_SwapChainRebuild = true;
|
||||||
|
if (err == VK_ERROR_OUT_OF_DATE_KHR)
|
||||||
|
return;
|
||||||
|
if (err != VK_SUBOPTIMAL_KHR)
|
||||||
|
check_vk_result(err);
|
||||||
|
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->SemaphoreCount; // Now we can use the next set of semaphores
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern configHandler_config_t* configObj;
|
extern configHandler_config_t* configObj;
|
||||||
bool bLikedSongsShow = false;
|
bool bLikedSongsShow = false;
|
||||||
bool bAudioSettingsShow = false;
|
bool bAudioSettingsShow = false;
|
||||||
@@ -48,23 +357,35 @@ int gui_entry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup window
|
// Setup window
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
|
||||||
float main_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(0);
|
float main_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(0);
|
||||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
SDL_Window* window = SDL_CreateWindow("OSSP v0.3a", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (int)(1280 * main_scale), (int)(800 * main_scale), window_flags);
|
SDL_Window* window = SDL_CreateWindow("OSSP v0.3a", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (int)(1280 * main_scale), (int)(800 * main_scale), window_flags);
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
printf("SDL could not create window: %s\n", SDL_GetError());
|
printf("SDL could not create window: %s\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GL context
|
ImVector<const char*> extensions;
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
uint32_t extensions_count = 0;
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, nullptr);
|
||||||
SDL_GL_SetSwapInterval(1); // Vsync
|
extensions.resize(extensions_count);
|
||||||
|
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions.Data);
|
||||||
|
SetupVulkan(extensions);
|
||||||
|
|
||||||
|
// Create Window Surface
|
||||||
|
VkSurfaceKHR surface;
|
||||||
|
VkResult err;
|
||||||
|
if (SDL_Vulkan_CreateSurface(window, g_Instance, &surface) == 0)
|
||||||
|
{
|
||||||
|
printf("Failed to create Vulkan surface.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Framebuffers
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
|
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
|
||||||
|
SetupVulkanWindow(wd, surface, w, h);
|
||||||
|
|
||||||
// Create ImGui context
|
// Create ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@@ -80,8 +401,24 @@ int gui_entry() {
|
|||||||
style.FontScaleDpi = main_scale;
|
style.FontScaleDpi = main_scale;
|
||||||
|
|
||||||
// Setup platform/renderer backends
|
// Setup platform/renderer backends
|
||||||
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
ImGui_ImplSDL2_InitForVulkan(window);
|
||||||
ImGui_ImplOpenGL2_Init();
|
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||||
|
//init_info.ApiVersion = VK_API_VERSION_1_3; // Pass in your value of VkApplicationInfo::apiVersion, otherwise will default to header version.
|
||||||
|
init_info.Instance = g_Instance;
|
||||||
|
init_info.PhysicalDevice = g_PhysicalDevice;
|
||||||
|
init_info.Device = g_Device;
|
||||||
|
init_info.QueueFamily = g_QueueFamily;
|
||||||
|
init_info.Queue = g_Queue;
|
||||||
|
init_info.PipelineCache = g_PipelineCache;
|
||||||
|
init_info.DescriptorPool = g_DescriptorPool;
|
||||||
|
init_info.RenderPass = wd->RenderPass;
|
||||||
|
init_info.Subpass = 0;
|
||||||
|
init_info.MinImageCount = g_MinImageCount;
|
||||||
|
init_info.ImageCount = wd->ImageCount;
|
||||||
|
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
init_info.Allocator = g_Allocator;
|
||||||
|
init_info.CheckVkResultFn = check_vk_result;
|
||||||
|
ImGui_ImplVulkan_Init(&init_info);
|
||||||
|
|
||||||
// START START START
|
// START START START
|
||||||
ImVec4 background_color = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
ImVec4 background_color = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||||
@@ -102,7 +439,7 @@ int gui_entry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start new frame
|
// Start new frame
|
||||||
ImGui_ImplOpenGL2_NewFrame();
|
ImGui_ImplVulkan_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
@@ -180,20 +517,26 @@ int gui_entry() {
|
|||||||
|
|
||||||
// Render
|
// Render
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
ImDrawData* draw_data = ImGui::GetDrawData();
|
||||||
glClearColor(background_color.x * background_color.w, background_color.y * background_color.w, background_color.z * background_color.w, background_color.w);
|
const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
if (!is_minimized)
|
||||||
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
|
{
|
||||||
SDL_GL_SwapWindow(window);
|
wd->ClearValue.color.float32[0] = background_color.x * background_color.w;
|
||||||
|
wd->ClearValue.color.float32[1] = background_color.y * background_color.w;
|
||||||
|
wd->ClearValue.color.float32[2] = background_color.z * background_color.w;
|
||||||
|
wd->ClearValue.color.float32[3] = background_color.w;
|
||||||
|
FrameRender(wd, draw_data);
|
||||||
|
FramePresent(wd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
ImGui_ImplOpenGL2_Shutdown();
|
//ImGui_ImplOpenGL2_Shutdown();
|
||||||
ImGui_ImplSDL2_Shutdown();
|
//ImGui_ImplSDL2_Shutdown();
|
||||||
ImGui::DestroyContext();
|
//ImGui::DestroyContext();
|
||||||
SDL_GL_DeleteContext(gl_context);
|
//SDL_GL_DeleteContext(gl_context);
|
||||||
SDL_DestroyWindow(window);
|
//SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
//SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user