From fa10dcf2706c1e869882a64a5ed31aabe2213fc7 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 19:12:42 +0200 Subject: [PATCH 01/14] Setting up the base for the bgfx integration --- CMakeLists.txt | 46 ++++++++++++++-- cmake_build.sh | 55 ++++++++++++++---- imgui.ini | 4 ++ src/schism/Core/Application.cpp | 11 ++-- src/schism/Core/Events/Event.h | 2 +- src/schism/Core/Window.cpp | 98 ++++++++++++++++++++++----------- src/schism/Core/Window.h | 38 ++++++++----- src/schism/Core/WindowData.h | 15 +++++ src/schism/Core/WindowUtil.h | 30 ++++++++++ src/schism/Schism.h | 2 +- src/schism/System/Debug.h | 4 ++ src/schism/pch.h | 27 +++++++++ vcpkg.json | 17 +++++- 13 files changed, 276 insertions(+), 73 deletions(-) create mode 100644 imgui.ini create mode 100644 src/schism/Core/WindowData.h create mode 100644 src/schism/Core/WindowUtil.h create mode 100644 src/schism/pch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 89e4a8a..b64d559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.18) + project(schism) +# set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) option(GLFW_BUILD_DOCS OFF) option(GLFW_BUILD_EXAMPLES OFF) @@ -11,13 +13,36 @@ option(USE_CPPCHECK "Enable cppcheck, must have cppcheck in the PATH") # Hardcode the architecture to arm64 on macOS if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + message("MacOs detected") + set(MACOSX TRUE) set(CMAKE_OSX_ARCHITECTURES "arm64") + add_compile_definitions(SCHISM_PLATFORM_MAC) + add_compile_definitions(GLFW_EXPOSE_NATIVE_COCOA) + add_compile_definitions(GLFW_EXPOSE_NATIVE_NSGL) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + message("Windows detected") + add_compile_definitions(SCHISM_PLATFORM_WIN) + add_compile_definitions(GLFW_EXPOSE_NATIVE_WIN32) + add_compile_definitions(GLFW_EXPOSE_NATIVE_WGL) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + message("Linux detected") add_compile_definitions(SCHISM_PLATFORM_LINUX) + + if ($ENV{XDG_SESSION_TYPE} STREQUAL "x11") + message("X11 deteced, building for x11") + add_compile_definitions(SCHISM_LINUX_X11) + add_compile_definitions(GLFW_EXPOSE_NATIVE_X11) + add_compile_definitions(GLFW_EXPOSE_NATIVE_GLX) + else() + message("Wayland detected, building for wayland") + set(SCHISM_LINUX_WAYLAND 1) + add_compile_definitions(SCHISM_LINUX_WAYLAND) + add_compile_definitions(GLFW_EXPOSE_NATIVE_WAYLAND) + list(APPEND VCPKG_MANIFEST_FEATURES "wayland") + endif() endif() if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") @@ -31,9 +56,6 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") set(USING_MSVC 1) endif() - -# set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) -# find_package(glfw3 CONFIG REQUIRED) include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) find_package(glfw3 CONFIG REQUIRED) @@ -57,11 +79,17 @@ find_path(PARALLEL_HASHMAP_INCLUDE_DIRS "parallel_hashmap/btree.h") set(CMAKE_CXX_STANDARD 20) if(${ENABLE_SANITIZER}) + message("AddressSanitizer has been enabled") add_compile_options(-fsanitize=address -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak) if(ENABLE_SANITIZER_THREAD) add_compile_options(-fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=thread) endif() + link_libraries( + -fsanitize=address + -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak + ) + if(ENABLE_SANITIZER AND ENABLE_SANITIZER_THREAD) message(FATAL_ERROR "ENABLE_SANITIZER and ENABLE_SANITIZER_THREAD can not be used together!") endif() @@ -72,7 +100,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_compile_options(/W4) elseif(USING_GCC) add_compile_options(-fdiagnostics-color=always) - add_compile_options(-Wall -Wextra -Wpedantic -Weffc++) + # add_compile_options(-Wall -Wextra -Wpedantic -Weffc++) elseif(USING_CLANGD) add_compile_options(-Weverything) add_compile_options(-fcolor-diagnostics) @@ -106,7 +134,7 @@ source_group("Headers" FILES ${HEADERS}) source_group("Sources" FILES ${SOURCES}) file(GLOB CONFIGS CMakeLists.txt - Readme.md + Readme.m .gitattributes .gitignore .gitmodules) @@ -119,6 +147,10 @@ add_executable(${PROJECT_NAME} ${GUIZMO_SOURCES} ${PROJECT_CONFIGS}) +if (${SCHISM_LINUX_WAYLAND}) + target_link_libraries(${PROJECT_NAME} PRIVATE wayland-egl) +endif() + target_link_libraries(${PROJECT_NAME} PRIVATE asio::asio EnTT::EnTT @@ -139,6 +171,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE ${PARALLEL_HASHMAP_INCLUDE_DIRS}) +# this will have to be moved when we switch to c++ modules and also when +# we switch to different projects for the runtime and the editor +# for now leave it like this +target_precompile_headers(${PROJECT_NAME} PRIVATE "./src/schism/pch.h") set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/) diff --git a/cmake_build.sh b/cmake_build.sh index 9b4cab5..6e421cc 100755 --- a/cmake_build.sh +++ b/cmake_build.sh @@ -1,31 +1,62 @@ #!/bin/bash +build_type="Debug" +refresh=false +rebuild=false +run=false -if [ $# -gt 0 ]; then +on_build_type () { if echo "$1" | grep -qi "debug"; then build_type="Debug" elif echo "$1" | grep -qi "release"; then build_type="Release" - elif [ "$1" == "--d" ]; then + elif [ "$1" == "-d" ]; then build_type="Debug" - elif [ "$1" == "--r" ]; then + elif [ "$1" == "-r" ]; then build_type="Release" - else - build_type="Debug" fi -else - build_type="Debug" +} + +handle_other_args () { + if echo "$1" | grep -qi "refresh"; then + refresh=true + fi + + if echo "$1" | grep -qi "rebuild"; then + rebuild=true + fi + + if echo "$1" | grep -qi "run"; then + run=true + fi +} + +for arg in "$@" +do + on_build_type "$arg" + handle_other_args "$arg" +done + +if [ "$rebuild" = true ]; then + rm -rf build + rm -rf bin fi -if [ ! -d ./build ]; then +if [ ! -d ./build ] || [ "$refresh" = true ]; then ./cmake_generate.sh "$build_type" fi -if cmake --build build -j $(nproc); then +if cmake --build build -j "$(nproc)"; then ./copy_res.sh - cd bin - ./schism - cd .. + + if [ $run = true ]; then + echo "Running with build type $build_type" + cd ./bin + ./schism + cd .. + fi + else echo BUILD FAILED fi + diff --git a/imgui.ini b/imgui.ini new file mode 100644 index 0000000..9930887 --- /dev/null +++ b/imgui.ini @@ -0,0 +1,4 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 + diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index b1b4925..52041ec 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -28,11 +28,12 @@ Application::Application(int w, int h, const char* name) { Ref Window = MakeRef(); - Window->Create(w, h, name); - SetupEventHandlers(); - Window->AttachEventAdapter(m_EventManager); + // we have to attach the event adapter before we create the window + // in the future possibly pass this into Create(w, h, name) + // Multi window can support multiple event propagation schemes + Window->Create(w, h, name, m_EventManager); m_Ctx = CreateSharedContext(Window); @@ -76,7 +77,7 @@ Application::Application(int w, int h, const char* name) { (void)io; ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(Window->GetNativeWindow(), true); + ImGui_ImplGlfw_InitForOpenGL(Window->GetGLFWWindow(), true); ImGui_ImplOpenGL3_Init("#version 400"); } @@ -96,7 +97,7 @@ void Application::OnEvent(Event& e) { void Application::Run() { // Boilerplate code - auto winPtr = m_Ctx->window->GetNativeWindow(); + auto winPtr = m_Ctx->window->GetGLFWWindow(); auto StartTime = std::chrono::high_resolution_clock::now(); auto LastFrameTime = StartTime; diff --git a/src/schism/Core/Events/Event.h b/src/schism/Core/Events/Event.h index 0d6df79..567ad77 100644 --- a/src/schism/Core/Events/Event.h +++ b/src/schism/Core/Events/Event.h @@ -52,7 +52,7 @@ class EventHandler { template ::value>::type> - constexpr auto Handle(const F& func) { + inline constexpr auto Handle(const F& func) { if (m_Evt.GetEventType() == T::GetStaticType()) { auto e = static_cast(m_Evt); using ret_type = decltype(func(e)); diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index 44a0a1a..3fbcd36 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -1,4 +1,7 @@ #include "Window.h" +#include +#include +#include #include "Events/KeyEvents.h" #include "Events/Keyboard.h" @@ -9,58 +12,83 @@ namespace Schism::Core { -Window::Window() : m_WindowPtr(nullptr), m_LoadWinPtr(nullptr), m_Data() {} +Window::Window() : m_created(false), m_WindowPtr(nullptr), m_Data() {} Window::~Window() { - glfwDestroyWindow(m_LoadWinPtr); glfwDestroyWindow(m_WindowPtr); } -void Window::Create(int w, int h, const char* name) { - if (!glfwInit()) { - SC_CORE_TRACE("Couldn't initialize glfw"); - } +void Window::Create(int w, int h, const char* name, + Ref eventAdapter) { - glfwWindowHint(GLFW_VISIBLE, 0); - m_LoadWinPtr = glfwCreateWindow(1, 1, "Loading Context", NULL, NULL); + if (m_created) { + SC_CORE_ERROR( + "Trying to create a window, while this current window is already " + "created"); + return; + } - if (m_LoadWinPtr == NULL) { - SC_CORE_TRACE("Couldn't create loading context!"); + if (!glfwInit()) { + SC_CORE_TRACE("Couldn't initialize glfw"); } glfwWindowHint(GLFW_VISIBLE, 1); - m_WindowPtr = glfwCreateWindow(w, h, name, NULL, m_LoadWinPtr); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + + m_WindowPtr = glfwCreateWindow(w, h, name, NULL, NULL); if (m_WindowPtr == NULL) { SC_CORE_TRACE("Couldn't create window!"); } - glfwMakeContextCurrent(m_WindowPtr); - - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - SC_CORE_TRACE("Couldn't load glad!"); - } - - glfwSetWindowUserPointer(m_WindowPtr, &m_Data); - m_Data.Width = w; m_Data.Height = h; + m_Data.eventAdapter = eventAdapter; + + glfwSetWindowUserPointer(m_WindowPtr, &m_Data); HookGLFWEventFunctions(); + SetNativeHandle(); + + // this could possibly be an atomic + m_created = true; } void Window::ProcessEvents() { + // when we add multi window support this might have to be called once at the + // application level glfwPollEvents(); } -void Window::AttachEventAdapter(Ref eventAdapter) { - m_Data.eventAdapter = eventAdapter; -} - void Window::Swap() const { glfwSwapBuffers(m_WindowPtr); } +void Window::SetNativeHandle() { +#if defined(SCHISM_PLATFORM_LINUX) + +#if defined(SCHISM_LINUX_WAYLAND) + + struct wl_surface* surface = + (struct wl_surface*)glfwGetWaylandWindow(m_WindowPtr); + + SC_ASSERT(surface, "Cannot get native wayland window surface"); + + m_nativeHandle = wl_egl_window_create(surface, m_Data.Width, m_Data.Height); + +#elif defined(SCHISM_LINUX_X11) + m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(m_WindowPtr); +#else + SC_STATIC_FAIL("Not a support linux window protocol") +#endif + +#elif defined(SCHISM_PLATFORM_WINDOWS) + m_nativeHandle = glfwGetWin32Window(m_WindowPtr); +#elif defined(SCHISM_PLATFORM_MAC) + m_nativeHandle = glfwGetCocoaWindow(m_WindowPtr); +#endif +} + void Window::HookGLFWEventFunctions() { HookMouseEvents(); HookKeyEvents(); @@ -68,11 +96,12 @@ void Window::HookGLFWEventFunctions() { } void Window::HookMouseEvents() { - SC_ASSERT(m_Data.eventManager, "There is no attached EventManager"); + SC_ASSERT(m_Data.eventAdapter, "There is no attached EventManager"); glfwSetScrollCallback( m_WindowPtr, [](GLFWwindow* win, double xoffset, double yoffset) { - auto data = static_cast(glfwGetWindowUserPointer(win)); + auto data = + static_cast(glfwGetWindowUserPointer(win)); data->eventAdapter->OnEvent(MouseScrollEvent(xoffset, yoffset)); }); @@ -84,7 +113,8 @@ void Window::HookMouseEvents() { return; } - auto data = static_cast(glfwGetWindowUserPointer((win))); + auto data = + static_cast(glfwGetWindowUserPointer((win))); double xpos; double ypos; @@ -104,30 +134,34 @@ void Window::HookMouseEvents() { glfwSetCursorPosCallback(m_WindowPtr, [](GLFWwindow* win, double xpos, double ypos) { - auto data = static_cast(glfwGetWindowUserPointer((win))); + auto data = + static_cast(glfwGetWindowUserPointer((win))); data->eventAdapter->OnEvent(MouseMoveEvent(xpos, ypos)); }); } void Window::HookWindowEvents() { - SC_ASSERT(m_Data.eventManager, "There is no attached EventManager"); + SC_ASSERT(m_Data.eventAdapter, "There is no attached EventManager"); glfwSetWindowSizeCallback(m_WindowPtr, [](GLFWwindow* win, int width, int height) { - auto data = static_cast(glfwGetWindowUserPointer((win))); + auto data = + static_cast(glfwGetWindowUserPointer((win))); data->eventAdapter->OnEvent(WindowResizeEvent(width, height)); }); glfwSetWindowCloseCallback(m_WindowPtr, [](GLFWwindow* win) { - auto data = static_cast(glfwGetWindowUserPointer((win))); + auto data = + static_cast(glfwGetWindowUserPointer((win))); data->eventAdapter->OnEvent(WindowCloseEvent()); }); } void Window::HookKeyEvents() { - SC_ASSERT(m_Data.eventManager, "There is no attached EventManager"); + SC_ASSERT(m_Data.eventAdapter, "There is no attached EventManager"); glfwSetKeyCallback(m_WindowPtr, [](GLFWwindow* win, int key, int scancode, int action, int mods) { - auto data = static_cast(glfwGetWindowUserPointer((win))); + auto data = + static_cast(glfwGetWindowUserPointer((win))); if (action == GLFW_PRESS) { data->eventAdapter->OnEvent(KeyDownEvent((Keyboard::Key)key)); } else if (action == GLFW_RELEASE) { diff --git a/src/schism/Core/Window.h b/src/schism/Core/Window.h index 1be2b48..45da116 100644 --- a/src/schism/Core/Window.h +++ b/src/schism/Core/Window.h @@ -1,46 +1,54 @@ #pragma once #include "schism/Core/EventHandlers/EventAdapterBase.h" +#include "schism/Core/WindowData.h" #include "schism/System/Ptr.h" #include "GLFW/glfw3.h" +// This is the main window class, once we start to support wasm, android, this will have to be an interface or something namespace Schism::Core { class Window { + public: + using NativeHandle = void*; + using GLFWwindowHandle = GLFWwindow*; + public: Window(); virtual ~Window(); + void Create(int w, int h, const char* name, + Ref eventAdapter); + + void SwapEventAdapter(Ref eventAdapter); + + void Resize(); + int GetWidth() const { return m_Data.Width; } int GetHeight() const { return m_Data.Height; } void Swap() const; - void Create(int w, int h, const char* name); void ProcessEvents(); - void AttachEventAdapter(Ref eventManager); - // Temporary, shouldn't expose glfw window - GLFWwindow* GetNativeWindow() const { return m_WindowPtr; } + // Temporary, shouldn't expose glfw window, or maybe it should, idk + GLFWwindow* GetGLFWWindow() const { return m_WindowPtr; } - GLFWwindow* GetLoadingContext() const { return m_LoadWinPtr; } + NativeHandle GetNativeHandle() const { return m_nativeHandle; } private: + void SetNativeHandle(); + + // Event Handling void HookGLFWEventFunctions(); void HookMouseEvents(); void HookWindowEvents(); void HookKeyEvents(); - GLFWwindow* m_WindowPtr; - GLFWwindow* m_LoadWinPtr; - - struct WindowData { - // don't know if this will be needed - int Width; - int Height; + bool m_created; + NativeHandle m_nativeHandle; + GLFWwindowHandle m_WindowPtr; - // this is definatelly needed - Ref eventAdapter; - } m_Data; + detail::WindowData m_Data; }; } // namespace Schism::Core diff --git a/src/schism/Core/WindowData.h b/src/schism/Core/WindowData.h new file mode 100644 index 0000000..6fc3ef8 --- /dev/null +++ b/src/schism/Core/WindowData.h @@ -0,0 +1,15 @@ +#pragma once + +#include "schism/System/Ptr.h" +#include "schism/Core/EventHandlers/EventAdapterBase.h" + +namespace Schism::Core::detail { +struct WindowData { + // don't know if this will be needed + int Width; + int Height; + + // this is definatelly needed + Ref eventAdapter; +}; +} // namespace Schism::Core::detail diff --git a/src/schism/Core/WindowUtil.h b/src/schism/Core/WindowUtil.h new file mode 100644 index 0000000..a2d368a --- /dev/null +++ b/src/schism/Core/WindowUtil.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include +#include + +namespace Schism::Core::detail { + +inline static void* glfwNativeWindowHandler(Window& window) { +#if defined(SCHISM_PLATFORM_LINUX) + +#if defined(SCHISM_LINUX_WAYLAND) + +#else + return +#endif + +#elif defined(SCHISM_PLATFORM_WINDOWS) + return glfwGetWin32Window(window); +#elfi defined(SCHISM_PLATFORM_MAC) + return glfwGetCocoaWindow(window); +#else + SC_ASSERT(false, "This platform is not yet supported"); + + return nullptr; +#endif +}; +} // namespace Schism::Core::detail diff --git a/src/schism/Schism.h b/src/schism/Schism.h index 42d5c1f..2df87d8 100644 --- a/src/schism/Schism.h +++ b/src/schism/Schism.h @@ -16,4 +16,4 @@ static void Init() { SC_CORE_CRITICAL("Coudn't initialize glfw"); } } -} // namespace Schism \ No newline at end of file +} // namespace Schism diff --git a/src/schism/System/Debug.h b/src/schism/System/Debug.h index d3ca14c..ea8f429 100644 --- a/src/schism/System/Debug.h +++ b/src/schism/System/Debug.h @@ -22,6 +22,7 @@ if (!(x)) { \ SC_CORE_CRITICAL(__VA__ARGS__); \ } + #else #define SC_ASSERT(x, ...) \ {} @@ -30,3 +31,6 @@ #define SC_ERR(x, ...) \ {} #endif + +#define SC_STATIC_FAIL(str) \ + { static_assert(false, str); } diff --git a/src/schism/pch.h b/src/schism/pch.h new file mode 100644 index 0000000..ee6eb4c --- /dev/null +++ b/src/schism/pch.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "schism/System/Log.h" +#include "schism/System/System.h" +#include "schism/System/Ptr.h" +#include "schism/System/Debug.h" +#include "schism/System/SyncQueue.h" diff --git a/vcpkg.json b/vcpkg.json index ae79ccb..811e792 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "schism", - "builtin-baseline": "352c108a6b6d698c09a8272d8e95fdce550ae408", + "builtin-baseline": "68d349964cb4e8da561fd849d9491e6ba11c5681", "dependencies" : [ "glfw3", "openal-soft", @@ -26,5 +26,18 @@ "multithreaded" ] } - ] + ], + "features": { + "wayland": { + "description": "Build with native wayland support", + "dependencies": [ + { + "name": "glfw3", + "features": [ + "wayland" + ] + } + ] + } + } } From 5be4d07a3c419573c3e711ed25a25b704871f1df Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 19:20:02 +0200 Subject: [PATCH 02/14] Defaulted session type so it can build in actions --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b64d559..f7683fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,17 +31,25 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") message("Linux detected") add_compile_definitions(SCHISM_PLATFORM_LINUX) - if ($ENV{XDG_SESSION_TYPE} STREQUAL "x11") + if (NOT DEFINED $ENV{XDG_SESSION_TYPE}) + # default to x11 if we cannot find the session type + # this is mainly done so it can build in git actions + add_compile_definitions(SCHISM_LINUX_X11) + add_compile_definitions(GLFW_EXPOSE_NATIVE_X11) + add_compile_definitions(GLFW_EXPOSE_NATIVE_GLX) + elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "x11") message("X11 deteced, building for x11") add_compile_definitions(SCHISM_LINUX_X11) add_compile_definitions(GLFW_EXPOSE_NATIVE_X11) add_compile_definitions(GLFW_EXPOSE_NATIVE_GLX) - else() + elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "wayland") message("Wayland detected, building for wayland") set(SCHISM_LINUX_WAYLAND 1) add_compile_definitions(SCHISM_LINUX_WAYLAND) add_compile_definitions(GLFW_EXPOSE_NATIVE_WAYLAND) list(APPEND VCPKG_MANIFEST_FEATURES "wayland") + else() + message("Cannot detect display protocol, linux")) endif() endif() From f1f0352af5138745a26337a91118a374b94d9eb3 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 19:22:08 +0200 Subject: [PATCH 03/14] fixed typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7683fe..86a1b41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") add_compile_definitions(GLFW_EXPOSE_NATIVE_WAYLAND) list(APPEND VCPKG_MANIFEST_FEATURES "wayland") else() - message("Cannot detect display protocol, linux")) + message("Cannot detect display protocol, linux") endif() endif() From ccc7a2250dfd94620892a6eb25b99dd585f404cc Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 19:27:09 +0200 Subject: [PATCH 04/14] guard the wayland include only on wayland platforms --- CMakeLists.txt | 1 + src/schism/Core/Window.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86a1b41..b699fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE glfw glm::glm imgui::imgui + # this is becase the port on vcpkg has a bug so we use a submodule to get it # imguizmo::imguizmo OpenAL::OpenAL spdlog::spdlog diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index 3fbcd36..bc1ff62 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -1,13 +1,15 @@ #include "Window.h" #include #include + +#if defined(SCHISM_LINUX_WAYLAND) #include +#endif #include "Events/KeyEvents.h" #include "Events/Keyboard.h" #include "Events/MouseEvents.h" #include "Events/WindowEvents.h" -#include "glad/glad.h" #include "schism/System/Log.h" namespace Schism::Core { From 54acadff5c5b3b2d5cac3f12a8352dabf9a9c017 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 19:29:00 +0200 Subject: [PATCH 05/14] remove glad include, we depend of bgfx now --- src/schism/Core/Window.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index bc1ff62..6a84b2a 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -1,4 +1,5 @@ #include "Window.h" + #include #include From 784528a066c578188e3f595410a8d62caf7179b4 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 8 Sep 2024 21:06:54 +0200 Subject: [PATCH 06/14] remove precompiled headers, weird bug --- CMakeLists.txt | 11 ++++++++--- cmake_generate.sh | 5 +++-- src/schism/Renderer/Texture.cpp | 3 +-- src/schism/pch.h | 5 ++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b699fbf..76a8893 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") elseif(USING_CLANGD) add_compile_options(-Weverything) add_compile_options(-fcolor-diagnostics) + add_compile_options(-msse2) endif() add_compile_definitions(SC_DEBUG) @@ -119,7 +120,7 @@ else() add_compile_definitions(SC_NODEBUG) endif() -add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD USE_IMGUI_API) +add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD USE_IMGUI_API STB_IMAGE_IMPLEMENTATION) include_directories( vendor/json/include/ @@ -142,7 +143,7 @@ source_group("Headers" FILES ${HEADERS}) source_group("Sources" FILES ${SOURCES}) file(GLOB CONFIGS CMakeLists.txt - Readme.m + Readme.md .gitattributes .gitignore .gitmodules) @@ -183,7 +184,11 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PARALLEL_HASHMAP_INCLUDE_DI # this will have to be moved when we switch to c++ modules and also when # we switch to different projects for the runtime and the editor # for now leave it like this -target_precompile_headers(${PROJECT_NAME} PRIVATE "./src/schism/pch.h") +# if we enable pre compiled headers there is a bug that happens with the definition of _OPTIMIZE +# spdlog or to be more exact defines _OPTIMIZE there and when stb image calls simd instructions +# it's selecting the wrong or let's say another function/macro definition that is unable to compiled +# very fucking interesting! +# target_precompile_headers(${PROJECT_NAME} PRIVATE "./src/schism/pch.h") set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/) diff --git a/cmake_generate.sh b/cmake_generate.sh index f058217..3a2973e 100755 --- a/cmake_generate.sh +++ b/cmake_generate.sh @@ -18,8 +18,9 @@ fi # add cmake presets in the future if [ "$build_type" == "Debug" ]; then - cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_SANITIZER=1 -DUSE_CPPCHECK=0 - cp ./build/compile_commands.json ./ + if cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_SANITIZER=1 -DUSE_CPPCHECK=0; then + cp ./build/compile_commands.json ./ + fi else cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type" fi diff --git a/src/schism/Renderer/Texture.cpp b/src/schism/Renderer/Texture.cpp index 920684e..fb60a53 100644 --- a/src/schism/Renderer/Texture.cpp +++ b/src/schism/Renderer/Texture.cpp @@ -1,6 +1,5 @@ #include "Texture.h" -#define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" namespace Schism::Renderer { @@ -75,4 +74,4 @@ void Texture::Bind(uint8_t slot) { Texture::~Texture() { glDeleteTextures(1, &m_TextureID); } -} // namespace Schism::Renderer \ No newline at end of file +} // namespace Schism::Renderer diff --git a/src/schism/pch.h b/src/schism/pch.h index ee6eb4c..4c24e10 100644 --- a/src/schism/pch.h +++ b/src/schism/pch.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -19,9 +20,7 @@ #include #include #include +#include -#include "schism/System/Log.h" #include "schism/System/System.h" -#include "schism/System/Ptr.h" -#include "schism/System/Debug.h" #include "schism/System/SyncQueue.h" From 030bb4140b0595060a157b2097971c9d33c21af4 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Mon, 9 Sep 2024 18:36:43 +0200 Subject: [PATCH 07/14] testing some bgfx stuff --- CMakeLists.txt | 63 +++++++++++++++++++------------ src/schism/Core/Application.cpp | 17 ++++++--- src/schism/Core/Window.cpp | 4 +- src/schism/Core/Window.h | 2 + src/schism/Renderer/RenderAPI.cpp | 55 +++++++++++++++++---------- src/schism/Renderer/RenderAPI.h | 4 +- src/schism/Sandbox/Sandbox.cpp | 10 ++--- src/schism/System/Defines.h | 23 +++++++++++ 8 files changed, 120 insertions(+), 58 deletions(-) create mode 100644 src/schism/System/Defines.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 76a8893..8b5c4f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,10 @@ cmake_minimum_required(VERSION 3.18) project(schism) # set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) -option(GLFW_BUILD_DOCS OFF) -option(GLFW_BUILD_EXAMPLES OFF) -option(GLFW_BUILD_TESTS OFF) - option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF) option(ENABLE_SANITIZER_THREAD "Enable TSAN ()." OFF) -option(USE_CPPCHECK "Enable cppcheck, must have cppcheck in the PATH") +option(USE_CPPCHECK "Enable cppcheck, must have cppcheck in the PATH" OFF) +option(INCLUDE_WARNING "Include all the warning from the compiler") # Hardcode the architecture to arm64 on macOS if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -18,35 +15,48 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(MACOSX TRUE) set(CMAKE_OSX_ARCHITECTURES "arm64") - add_compile_definitions(SCHISM_PLATFORM_MAC) - add_compile_definitions(GLFW_EXPOSE_NATIVE_COCOA) - add_compile_definitions(GLFW_EXPOSE_NATIVE_NSGL) + add_compile_definitions( + SCHISM_PLATFORM_MAC + GLFW_EXPOSE_NATIVE_COCOA + GLFW_EXPOSE_NATIVE_NSGL + ) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") message("Windows detected") - add_compile_definitions(SCHISM_PLATFORM_WIN) - add_compile_definitions(GLFW_EXPOSE_NATIVE_WIN32) - add_compile_definitions(GLFW_EXPOSE_NATIVE_WGL) + add_compile_definitions( + SCHISM_PLATFORM_WIN + GLFW_EXPOSE_NATIVE_WIN32 + GLFW_EXPOSE_NATIVE_WGL + ) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") message("Linux detected") add_compile_definitions(SCHISM_PLATFORM_LINUX) - if (NOT DEFINED $ENV{XDG_SESSION_TYPE}) + if (NOT DEFINED ENV{XDG_SESSION_TYPE}) # default to x11 if we cannot find the session type # this is mainly done so it can build in git actions - add_compile_definitions(SCHISM_LINUX_X11) - add_compile_definitions(GLFW_EXPOSE_NATIVE_X11) - add_compile_definitions(GLFW_EXPOSE_NATIVE_GLX) + message("Didn't detect the session type") + add_compile_definitions( + SCHISM_LINUX_X11 + GLFW_EXPOSE_NATIVE_X11 + GLFW_EXPOSE_NATIVE_GLX + ) elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "x11") message("X11 deteced, building for x11") - add_compile_definitions(SCHISM_LINUX_X11) - add_compile_definitions(GLFW_EXPOSE_NATIVE_X11) - add_compile_definitions(GLFW_EXPOSE_NATIVE_GLX) + set(GLFW_BUILD_X11 1) + add_compile_definitions( + SCHISM_LINUX_X11 + GLFW_EXPOSE_NATIVE_X11 + GLFW_EXPOSE_NATIVE_GLX + ) elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "wayland") message("Wayland detected, building for wayland") set(SCHISM_LINUX_WAYLAND 1) - add_compile_definitions(SCHISM_LINUX_WAYLAND) - add_compile_definitions(GLFW_EXPOSE_NATIVE_WAYLAND) + set(GLFW_BUILD_WAYLAND 1) + add_compile_definitions( + SCHISM_LINUX_WAYLAND + GLFW_EXPOSE_NATIVE_WAYLAND + ) list(APPEND VCPKG_MANIFEST_FEATURES "wayland") else() message("Cannot detect display protocol, linux") @@ -64,9 +74,14 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") set(USING_MSVC 1) endif() + include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) -find_package(glfw3 CONFIG REQUIRED) +if (${GLFW_BUILD_WAYLAND}) + message("BUILDING WAYLAND GLFW") +elseif (${GLFW_BUILD_X11}) + message("BUILDING X11 GLFW") +endif() find_package(EnTT CONFIG REQUIRED) find_package(glad CONFIG REQUIRED) find_package(glm CONFIG REQUIRED) @@ -84,7 +99,8 @@ find_package(sol2 CONFIG REQUIRED) find_package(lua REQUIRED) find_path(PARALLEL_HASHMAP_INCLUDE_DIRS "parallel_hashmap/btree.h") -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) + if(${ENABLE_SANITIZER}) message("AddressSanitizer has been enabled") @@ -112,7 +128,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") elseif(USING_CLANGD) add_compile_options(-Weverything) add_compile_options(-fcolor-diagnostics) - add_compile_options(-msse2) endif() add_compile_definitions(SC_DEBUG) @@ -164,7 +179,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE asio::asio EnTT::EnTT glad::glad - glfw + # glfw glm::glm imgui::imgui # this is becase the port on vcpkg has a bug so we use a submodule to get it diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index 52041ec..76e2fc1 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -18,6 +18,7 @@ #include "schism/System/System.h" #include +#include namespace Schism { Application::Application(int w, int h, const char* name) { @@ -26,7 +27,7 @@ Application::Application(int w, int h, const char* name) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - Ref Window = MakeRef(); + Core::WindowRef Window = MakeRef(); SetupEventHandlers(); @@ -46,8 +47,10 @@ Application::Application(int w, int h, const char* name) { m_SceneManager.InitContext(m_Ctx); - Renderer::API::Init(); + SC_CORE_ERROR("Got here before window"); + Renderer::API::Init(Window); + SC_CORE_ERROR("Got here after window"); ALCdevice* aldevice = alcOpenDevice(nullptr); ALCcontext* context = alcCreateContext(aldevice, nullptr); @@ -77,8 +80,8 @@ Application::Application(int w, int h, const char* name) { (void)io; ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(Window->GetGLFWWindow(), true); - ImGui_ImplOpenGL3_Init("#version 400"); + /*ImGui_ImplGlfw_InitForOpenGL(Window->GetGLFWWindow(), true);*/ + /*ImGui_ImplOpenGL3_Init("#version 400");*/ } Application::~Application() { @@ -113,13 +116,15 @@ void Application::Run() { Renderer::API::Clear(); m_Ctx->window->ProcessEvents(); - m_SceneManager.OnUpdate(ts); + /*m_SceneManager.OnUpdate(ts);*/ ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - m_SceneManager.OnDraw(); + bgfx::dbgTextClear(); + bgfx::dbgTextPrintf(10, 10, 0x0f, "Testing bgfx"); + /*m_SceneManager.OnDraw();*/ ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index 6a84b2a..2abbaac 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -71,18 +71,16 @@ void Window::SetNativeHandle() { #if defined(SCHISM_PLATFORM_LINUX) #if defined(SCHISM_LINUX_WAYLAND) - struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(m_WindowPtr); SC_ASSERT(surface, "Cannot get native wayland window surface"); m_nativeHandle = wl_egl_window_create(surface, m_Data.Width, m_Data.Height); - #elif defined(SCHISM_LINUX_X11) m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(m_WindowPtr); #else - SC_STATIC_FAIL("Not a support linux window protocol") + SC_STATIC_FAIL("Not a supported window protocol") #endif #elif defined(SCHISM_PLATFORM_WINDOWS) diff --git a/src/schism/Core/Window.h b/src/schism/Core/Window.h index 45da116..dc25479 100644 --- a/src/schism/Core/Window.h +++ b/src/schism/Core/Window.h @@ -8,6 +8,8 @@ // This is the main window class, once we start to support wasm, android, this will have to be an interface or something namespace Schism::Core { +using WindowRef = Ref; + class Window { public: using NativeHandle = void*; diff --git a/src/schism/Renderer/RenderAPI.cpp b/src/schism/Renderer/RenderAPI.cpp index 243d4a4..e522f66 100644 --- a/src/schism/Renderer/RenderAPI.cpp +++ b/src/schism/Renderer/RenderAPI.cpp @@ -2,36 +2,53 @@ #include "glad/glad.h" -#include "Renderer2D.h" -#include "SpriteRenderer.h" -#include "schism/System/Log.h" +#include +#include +#include namespace Schism::Renderer { -void API::Init() { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_DEPTH_TEST); +bool API::Init(Core::WindowRef window) { // Renderer2D::Init(); // This will be deprecated, stays here to test other parts while the batch renderer gets finished - SpriteRenderer::Init(); + + bgfx::Init bgfxInit; + +#if defined(SCHISM_PLATFORM_WINDOWS) || defined(SCHISM_PLATFORM_LINUX) + bgfxInit.type = bgfx::RendererType::Vulkan; +#elif defined(SCHISM_PLATFORM_MAC) + bgfxInit.type = bgfx::RendererType::Metal; +#else + SC_STATIC_FAIL("Currently we are not supporting this platform"); +#endif + + bgfxInit.resolution.width = window->GetWidth(); + bgfxInit.resolution.height = window->GetHeight(); + + bgfxInit.resolution.reset = BGFX_RESET_VSYNC; + + bgfxInit.platformData.nwh = window->GetNativeHandle(); + + int k = 1; + + bgfx::renderFrame(); + if (!bgfx::init(bgfxInit)) { + return false; + } + + bgfx::setViewClear(0, BGFX_CLEAR_COLOR); + bgfx::setViewRect(0, 0, 0, window->GetWidth(), window->GetHeight()); + + return true; } void API::Shutdown() { // Renderer2D::Shutdown(); - SpriteRenderer::Shutdown(); } -void API::SetClearColor(const glm::vec4& color) { - glClearColor(color.r, color.g, color.b, color.a); -} +void API::SetClearColor(const glm::vec4& color) {} -void API::Clear() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} +void API::Clear() {} -void API::SetViewport(uint32_t width, uint32_t height) { - glViewport(0, 0, width, height); -} +void API::SetViewport(uint32_t width, uint32_t height) {} } // namespace Schism::Renderer diff --git a/src/schism/Renderer/RenderAPI.h b/src/schism/Renderer/RenderAPI.h index d76b6a3..a530b21 100644 --- a/src/schism/Renderer/RenderAPI.h +++ b/src/schism/Renderer/RenderAPI.h @@ -2,11 +2,13 @@ #include #include +#include +#include "schism/Core/Window.h" namespace Schism::Renderer { class API { public: - static void Init(); + static bool Init(Core::WindowRef window); static void Shutdown(); static void SetClearColor(const glm::vec4& color); diff --git a/src/schism/Sandbox/Sandbox.cpp b/src/schism/Sandbox/Sandbox.cpp index 380a6b9..ec534f5 100644 --- a/src/schism/Sandbox/Sandbox.cpp +++ b/src/schism/Sandbox/Sandbox.cpp @@ -4,12 +4,12 @@ namespace Schism { Sandbox::Sandbox() : Application(1280, 720, "Sandbox") { - m_Ctx->GlobalAssets.Textures.Load("ship1sprite", "res/ships/1.png"); - m_Ctx->GlobalAssets.Shaders.Load("spriterenderer", - "res/shaders/sprite_renderer.vert", - "res/shaders/sprite_renderer.frag"); + /*m_Ctx->GlobalAssets.Textures.Load("ship1sprite", "res/ships/1.png");*/ + /*m_Ctx->GlobalAssets.Shaders.Load("spriterenderer",*/ + /*"res/shaders/sprite_renderer.vert",*/ + /*"res/shaders/sprite_renderer.frag");*/ - m_SceneManager.Register("samplescene"); + /*m_SceneManager.Register("samplescene");*/ } Sandbox::~Sandbox() {} diff --git a/src/schism/System/Defines.h b/src/schism/System/Defines.h new file mode 100644 index 0000000..c5713a7 --- /dev/null +++ b/src/schism/System/Defines.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "schism/System/System.h" + +namespace Schism { + +using u8 = std::uint8_t; +using u16 = std::uint16_t; +using u32 = std::uint32_t; +using u64 = std::uint64_t; + +using i8 = std::int8_t; +using i16 = std::int16_t; +using i32 = std::int32_t; +using i64 = std::int64_t; + +using f32 = float; +using f64 = double; + +} // namespace Schism From 0edbd35e6c9e6a4884762d98457df7048cd1809b Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Tue, 17 Sep 2024 23:48:20 +0200 Subject: [PATCH 08/14] working wayland window with bgfx --- .gitmodules | 3 ++ CMakeLists.txt | 16 +++++---- src/schism/Core/Application.cpp | 57 ++++++++++++++++--------------- src/schism/Core/Window.cpp | 5 +++ src/schism/Core/Window.h | 3 ++ src/schism/Renderer/RenderAPI.cpp | 3 +- vendor/atomic_queue | 2 +- vendor/bgfx | 1 + vendor/dr_libs | 2 +- vendor/imguizmo | 2 +- vendor/phmap | 2 +- 11 files changed, 57 insertions(+), 39 deletions(-) create mode 160000 vendor/bgfx diff --git a/.gitmodules b/.gitmodules index bd91f0f..06e0bb5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "vendor/imguizmo"] path = vendor/imguizmo url = https://github.com/CedricGuillemet/ImGuizmo.git +[submodule "vendor/bgfx"] + path = vendor/bgfx + url = https://github.com/bkaradzic/bgfx.cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b5c4f3..fa050cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,11 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") message("Wayland detected, building for wayland") set(SCHISM_LINUX_WAYLAND 1) set(GLFW_BUILD_WAYLAND 1) + set(BGFX_WITH_WAYLAND TRUE) add_compile_definitions( SCHISM_LINUX_WAYLAND GLFW_EXPOSE_NATIVE_WAYLAND + WL_EGL_PLATFORM ) list(APPEND VCPKG_MANIFEST_FEATURES "wayland") else() @@ -74,6 +76,7 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") set(USING_MSVC 1) endif() +set(CMAKE_CXX_STANDARD 23) include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) @@ -82,11 +85,11 @@ if (${GLFW_BUILD_WAYLAND}) elseif (${GLFW_BUILD_X11}) message("BUILDING X11 GLFW") endif() + find_package(EnTT CONFIG REQUIRED) find_package(glad CONFIG REQUIRED) find_package(glm CONFIG REQUIRED) find_package(imgui CONFIG REQUIRED) -find_package(bgfx CONFIG REQUIRED) # this is commented out because there is a bug in imguizmo version 1.83 # using it as a submodule @@ -99,8 +102,7 @@ find_package(sol2 CONFIG REQUIRED) find_package(lua REQUIRED) find_path(PARALLEL_HASHMAP_INCLUDE_DIRS "parallel_hashmap/btree.h") -set(CMAKE_CXX_STANDARD 23) - +add_subdirectory("vendor/bgfx") if(${ENABLE_SANITIZER}) message("AddressSanitizer has been enabled") @@ -188,10 +190,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog sol2 ${LUA_LIBRARIES} - bgfx::bx - bgfx::bgfx - bgfx::bimg - bgfx::bimg_decode + bx + bgfx + bimg + bimg_decode ) target_include_directories(${PROJECT_NAME} PRIVATE ${PARALLEL_HASHMAP_INCLUDE_DIRS}) diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index 76e2fc1..5be494f 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -4,6 +4,8 @@ #include "AL/alc.h" #include "GLFW/glfw3.h" #include "Window.h" +#include "bgfx/defines.h" +#include "bgfx/platform.h" #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" @@ -59,27 +61,27 @@ Application::Application(int w, int h, const char* name) { return; } - auto vendor = - std::string(reinterpret_cast(glGetString(GL_VENDOR))); - auto renderer = - std::string(reinterpret_cast(glGetString(GL_RENDERER))); - auto version = - std::string(reinterpret_cast(glGetString(GL_VERSION))); - auto shader_version = std::string(reinterpret_cast( - glGetString(GL_SHADING_LANGUAGE_VERSION))); - - SC_CORE_INFO("Schism succesfully initialized"); - SC_CORE_INFO("Gpu - {0} {1}", vendor, renderer); - SC_CORE_INFO("Driver - {0}", version); - SC_CORE_INFO("Shader Version - {0}", shader_version); - SC_CORE_INFO("Processor count - {0}", std::thread::hardware_concurrency()); - + /*auto vendor =*/ + /* std::string(reinterpret_cast(glGetString(GL_VENDOR)));*/ + /*auto renderer =*/ + /* std::string(reinterpret_cast(glGetString(GL_RENDERER)));*/ + /*auto version =*/ + /* std::string(reinterpret_cast(glGetString(GL_VERSION)));*/ + /*auto shader_version = std::string(reinterpret_cast(*/ + /* glGetString(GL_SHADING_LANGUAGE_VERSION)));*/ + /**/ + /*SC_CORE_INFO("Schism succesfully initialized");*/ + /*SC_CORE_INFO("Gpu - {0} {1}", vendor, renderer);*/ + /*SC_CORE_INFO("Driver - {0}", version);*/ + /*SC_CORE_INFO("Shader Version - {0}", shader_version);*/ + /*SC_CORE_INFO("Processor count - {0}", std::thread::hardware_concurrency());*/ + /**/ // TEMPPPPP !!! - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - (void)io; - - ImGui::StyleColorsDark(); + /*ImGui::CreateContext();*/ + /*ImGuiIO& io = ImGui::GetIO();*/ + /*(void)io;*/ + /**/ + /*ImGui::StyleColorsDark();*/ /*ImGui_ImplGlfw_InitForOpenGL(Window->GetGLFWWindow(), true);*/ /*ImGui_ImplOpenGL3_Init("#version 400");*/ } @@ -118,16 +120,17 @@ void Application::Run() { m_Ctx->window->ProcessEvents(); /*m_SceneManager.OnUpdate(ts);*/ - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - bgfx::dbgTextClear(); + /*ImGui_ImplOpenGL3_NewFrame();*/ + /*ImGui_ImplGlfw_NewFrame();*/ + /*ImGui::NewFrame();*/ + bgfx::touch(0); bgfx::dbgTextPrintf(10, 10, 0x0f, "Testing bgfx"); /*m_SceneManager.OnDraw();*/ - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + /*ImGui::Render();*/ + /*ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/ + bgfx::setDebug(BGFX_DEBUG_TEXT); + bgfx::frame(); m_Ctx->window->Swap(); } diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index 2abbaac..d160790 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -77,6 +77,11 @@ void Window::SetNativeHandle() { SC_ASSERT(surface, "Cannot get native wayland window surface"); m_nativeHandle = wl_egl_window_create(surface, m_Data.Width, m_Data.Height); + m_nativeDisplay = glfwGetWaylandDisplay(); + + SC_ASSERT(m_nativeHandle, "Native window handle isn't valid"); + SC_ASSERT(m_nativeDisplay, "Native window handle isn't valid"); + #elif defined(SCHISM_LINUX_X11) m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(m_WindowPtr); #else diff --git a/src/schism/Core/Window.h b/src/schism/Core/Window.h index dc25479..a0c53a5 100644 --- a/src/schism/Core/Window.h +++ b/src/schism/Core/Window.h @@ -36,6 +36,8 @@ class Window { // Temporary, shouldn't expose glfw window, or maybe it should, idk GLFWwindow* GetGLFWWindow() const { return m_WindowPtr; } + NativeHandle GetNativeDisplay() const { return m_nativeDisplay; }; + NativeHandle GetNativeHandle() const { return m_nativeHandle; } private: @@ -49,6 +51,7 @@ class Window { bool m_created; NativeHandle m_nativeHandle; + NativeHandle m_nativeDisplay; GLFWwindowHandle m_WindowPtr; detail::WindowData m_Data; diff --git a/src/schism/Renderer/RenderAPI.cpp b/src/schism/Renderer/RenderAPI.cpp index e522f66..5d5c808 100644 --- a/src/schism/Renderer/RenderAPI.cpp +++ b/src/schism/Renderer/RenderAPI.cpp @@ -25,9 +25,10 @@ bool API::Init(Core::WindowRef window) { bgfxInit.resolution.width = window->GetWidth(); bgfxInit.resolution.height = window->GetHeight(); - bgfxInit.resolution.reset = BGFX_RESET_VSYNC; + /*bgfxInit.resolution.reset = BGFX_RESET_VSYNC;*/ bgfxInit.platformData.nwh = window->GetNativeHandle(); + bgfxInit.platformData.ndt = window->GetNativeDisplay(); int k = 1; diff --git a/vendor/atomic_queue b/vendor/atomic_queue index 187fa4e..cf52f25 160000 --- a/vendor/atomic_queue +++ b/vendor/atomic_queue @@ -1 +1 @@ -Subproject commit 187fa4ed8d7cf2e74822c3b176695402883bfe05 +Subproject commit cf52f25c4c4da311a8f7a3d4d99389523991d72b diff --git a/vendor/bgfx b/vendor/bgfx new file mode 160000 index 0000000..9418487 --- /dev/null +++ b/vendor/bgfx @@ -0,0 +1 @@ +Subproject commit 94184872a86738baa847ef12877f0da0b273a888 diff --git a/vendor/dr_libs b/vendor/dr_libs index a4b73d3..da35f9d 160000 --- a/vendor/dr_libs +++ b/vendor/dr_libs @@ -1 +1 @@ -Subproject commit a4b73d3d423e1cea0652b76d0806e7620337a40f +Subproject commit da35f9d6c7374a95353fd1df1d394d44ab66cf01 diff --git a/vendor/imguizmo b/vendor/imguizmo index ba662b1..99358b3 160000 --- a/vendor/imguizmo +++ b/vendor/imguizmo @@ -1 +1 @@ -Subproject commit ba662b119d64f9ab700bb2cd7b2781f9044f5565 +Subproject commit 99358b3afc8cdfff5c264f97ab1718b2d8089319 diff --git a/vendor/phmap b/vendor/phmap index 1f2671f..63acc33 160000 --- a/vendor/phmap +++ b/vendor/phmap @@ -1 +1 @@ -Subproject commit 1f2671ff0a12710f19c92080693c857f918bda88 +Subproject commit 63acc3336f941c6f324c88eb9ee4ce623a460cd5 From 714881288e034dab93fa7dc1d7c1db409613a105 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Wed, 18 Sep 2024 00:16:50 +0200 Subject: [PATCH 09/14] Random testing --- src/schism/Core/Application.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index 5be494f..f7ce153 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace Schism { Application::Application(int w, int h, const char* name) { @@ -124,7 +125,9 @@ void Application::Run() { /*ImGui_ImplGlfw_NewFrame();*/ /*ImGui::NewFrame();*/ bgfx::touch(0); - bgfx::dbgTextPrintf(10, 10, 0x0f, "Testing bgfx"); + bgfx::dbgTextPrintf( + 10, 10, 0x0f, + std::format("Testing bgfx, {}", ts.GetMiliseconds()).c_str()); /*m_SceneManager.OnDraw();*/ /*ImGui::Render();*/ From 0624b876ff37575a023d021f4f75124f480529a5 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sat, 19 Oct 2024 13:50:54 +0200 Subject: [PATCH 10/14] Misc fixes, recursive submodules --- .github/workflows/build.yml | 4 +- CMakeLists.txt | 8 +- src/chess/Game.cpp | 3 +- src/chess/GameClient.cpp | 2 +- src/game/Game.cpp | 9 +- src/schism/Audio/Source.cpp | 10 +- src/schism/Core/Application.cpp | 62 +++-- src/schism/Core/Window.cpp | 14 +- src/schism/Core/Window.h | 2 +- src/schism/Renderer/RenderAPI.cpp | 31 +-- src/schism/Renderer/RenderAPI.h | 3 +- src/schism/Sandbox/Sandbox.cpp | 2 +- vcpkg.json | 8 +- vendor/bgfx-imgui/README.md | 5 + vendor/bgfx-imgui/fs_ocornut_imgui.bin.h | 186 +++++++++++++++ vendor/bgfx-imgui/imgui_impl_bgfx.cpp | 189 +++++++++++++++ vendor/bgfx-imgui/imgui_impl_bgfx.h | 20 ++ vendor/bgfx-imgui/vs_ocornut_imgui.bin.h | 278 +++++++++++++++++++++++ 18 files changed, 774 insertions(+), 62 deletions(-) create mode 100644 vendor/bgfx-imgui/README.md create mode 100644 vendor/bgfx-imgui/fs_ocornut_imgui.bin.h create mode 100644 vendor/bgfx-imgui/imgui_impl_bgfx.cpp create mode 100644 vendor/bgfx-imgui/imgui_impl_bgfx.h create mode 100644 vendor/bgfx-imgui/vs_ocornut_imgui.bin.h diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9b6b20..0747c98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: - name: Git checkout uses: actions/checkout@v3 with: - submodules: 'true' + submodules: 'recursive' - name: run-vcpkg uses: lukka/run-vcpkg@v11.5 @@ -60,7 +60,7 @@ jobs: - name: Git checkout uses: actions/checkout@v3 with: - submodules: 'true' + submodules: 'recursive' - name: run-vcpkg uses: lukka/run-vcpkg@v11.5 diff --git a/CMakeLists.txt b/CMakeLists.txt index fa050cb..afd5454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ else() add_compile_definitions(SC_NODEBUG) endif() -add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD USE_IMGUI_API STB_IMAGE_IMPLEMENTATION) +add_compile_definitions(USE_IMGUI_API STB_IMAGE_IMPLEMENTATION) include_directories( vendor/json/include/ @@ -147,11 +147,12 @@ include_directories( vendor/imguizmo/ ${Stb_INCLUDE_DIR} ${LUA_INCLUDE_DIR} + vendor/bgfx-imgui/ src/ ) - file(GLOB GUIZMO_SOURCES vendor/imguizmo/*.cpp) +file(GLOB BGFX_IMGUI vendor/bgfx-imgui/*.cpp) file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE HEADERS src/*.h) file(GLOB_RECURSE RESOURCES res/*) @@ -171,6 +172,7 @@ add_definitions(-DGLFW_INCLUDE_NONE add_executable(${PROJECT_NAME} ${SOURCES} ${GUIZMO_SOURCES} + ${BGFX_IMGUI} ${PROJECT_CONFIGS}) if (${SCHISM_LINUX_WAYLAND}) @@ -181,7 +183,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE asio::asio EnTT::EnTT glad::glad - # glfw + glfw glm::glm imgui::imgui # this is becase the port on vcpkg has a bug so we use a submodule to get it diff --git a/src/chess/Game.cpp b/src/chess/Game.cpp index d24090e..b64fbd5 100644 --- a/src/chess/Game.cpp +++ b/src/chess/Game.cpp @@ -30,7 +30,6 @@ Game::Game( m_State.gameId = e.gameId; m_Engine.Reset(); }); - ListenGameEvent([this](Net::SuccessfulMove&& e) { if (e.gameId != m_State.gameId) { return; // todo:: Handle multiple games @@ -143,4 +142,4 @@ void Game::DrawBoard() { m_BoardRenderer.DrawBoard(m_Engine.GetBoardState(), !m_State.isWhite); } -} // namespace Chess \ No newline at end of file +} // namespace Chess diff --git a/src/chess/GameClient.cpp b/src/chess/GameClient.cpp index 5cb7a42..1203348 100644 --- a/src/chess/GameClient.cpp +++ b/src/chess/GameClient.cpp @@ -98,4 +98,4 @@ void GameClient::HandleRead(size_t length) { } } } -} // namespace Chess \ No newline at end of file +} // namespace Chess diff --git a/src/game/Game.cpp b/src/game/Game.cpp index b4978e4..3aedda6 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -2,12 +2,7 @@ #include #include -#include -#include -#include #include "chess/Chess.h" -#include "schism/Audio/Source.h" -#include "schism/Audio/WavLoader.h" #include "schism/Sandbox/SampleScene.h" #include "schism/System/Log.h" @@ -30,11 +25,11 @@ Game::Game() : Application(800, 800, "Chess") { m_SceneManager.Register("sample scene"); // m_SceneManager.Register("chess"); - ALfloat listenerOri[] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f}; + ALfloat listernetOrientation[] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f}; alListener3f(AL_POSITION, 0, 0, 1.f); alListener3f(AL_VELOCITY, 0, 0, 0); - alListenerfv(AL_ORIENTATION, listenerOri); + alListenerfv(AL_ORIENTATION, listernetOrientation); SC_CORE_INFO("Playing audio!"); m_Ctx->GlobalAssets.Audio.GetHandle("testaudio")->Play(); } diff --git a/src/schism/Audio/Source.cpp b/src/schism/Audio/Source.cpp index 0be9ce7..c35d7ae 100644 --- a/src/schism/Audio/Source.cpp +++ b/src/schism/Audio/Source.cpp @@ -23,16 +23,22 @@ Source::Source(const std::vector& data, std::uint32_t sampleRate, } Ref Source::Create(std::filesystem::path filePath) { + if (filePath.extension() != ".wav") { + SC_CORE_ERROR( + "At this point we only support wav audio format, unable to load {}", + filePath.string()); + } + WavLoader wav(filePath); if (!wav.Load()) { - SC_CORE_ERROR("Error creating audio source, with file: ", + SC_CORE_ERROR("Error creating audio source, with file: {}", filePath.string()); return nullptr; } auto& header = wav.Header(); auto& data = wav.Data(); - SC_CORE_INFO("Wav file loaded!"); + return MakeRef(data, header.sampleRate, header.bitsPerSample, header.channels); } diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index f7ce153..d2f6405 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -7,8 +7,8 @@ #include "bgfx/defines.h" #include "bgfx/platform.h" #include "imgui.h" +#include "imconfig.h" #include "imgui_impl_glfw.h" -#include "imgui_impl_opengl3.h" #include "schism/Core/EventHandlers/EventManager.h" #include "schism/Core/EventHandlers/KeyboardEventHandler.h" #include "schism/Core/EventHandlers/MouseEventHandler.h" @@ -20,16 +20,12 @@ #include "schism/System/System.h" #include +#include #include #include namespace Schism { Application::Application(int w, int h, const char* name) { - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - Core::WindowRef Window = MakeRef(); SetupEventHandlers(); @@ -51,7 +47,7 @@ Application::Application(int w, int h, const char* name) { m_SceneManager.InitContext(m_Ctx); SC_CORE_ERROR("Got here before window"); - Renderer::API::Init(Window); + auto renderType = Renderer::API::Init(Window); SC_CORE_ERROR("Got here after window"); ALCdevice* aldevice = alcOpenDevice(nullptr); @@ -78,13 +74,32 @@ Application::Application(int w, int h, const char* name) { /*SC_CORE_INFO("Processor count - {0}", std::thread::hardware_concurrency());*/ /**/ // TEMPPPPP !!! - /*ImGui::CreateContext();*/ - /*ImGuiIO& io = ImGui::GetIO();*/ - /*(void)io;*/ - /**/ - /*ImGui::StyleColorsDark();*/ - /*ImGui_ImplGlfw_InitForOpenGL(Window->GetGLFWWindow(), true);*/ - /*ImGui_ImplOpenGL3_Init("#version 400");*/ + // + + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + + io.DisplaySize.x = Window->GetWidth(); + io.DisplaySize.y = Window->GetHeight(); + + (void)io; + + ImGui::StyleColorsDark(); + ImGui_Implbgfx_Init(0); + + auto* glfwWindow = Window->GetGLFWWindow(); + switch (*renderType) { + case bgfx::RendererType::Vulkan: + ImGui_ImplGlfw_InitForVulkan(glfwWindow, true); + break; + + case bgfx::RendererType::OpenGL: + ImGui_ImplGlfw_InitForOpenGL(glfwWindow, true); + break; + + default: + ImGui_ImplGlfw_InitForOther(glfwWindow, true); + } } Application::~Application() { @@ -95,6 +110,8 @@ void Application::OnEvent(Event& e) { EventHandler evt(e); CLASSEVENT(evt, WindowResizeEvent) { + SC_CORE_WARN("Window resized"); + /*m_Ctx->window->Resize(e.GetWidth(), e.GetHeight());*/ Renderer::API::SetViewport(e.GetWidth(), e.GetHeight()); }); @@ -121,20 +138,27 @@ void Application::Run() { m_Ctx->window->ProcessEvents(); /*m_SceneManager.OnUpdate(ts);*/ - /*ImGui_ImplOpenGL3_NewFrame();*/ - /*ImGui_ImplGlfw_NewFrame();*/ - /*ImGui::NewFrame();*/ bgfx::touch(0); + + /*ImGui::NewFrame();*/ bgfx::dbgTextPrintf( 10, 10, 0x0f, std::format("Testing bgfx, {}", ts.GetMiliseconds()).c_str()); /*m_SceneManager.OnDraw();*/ /*ImGui::Render();*/ - /*ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/ - bgfx::setDebug(BGFX_DEBUG_TEXT); + /*bgfx::setDebug(BGFX_DEBUG_TEXT);*/ bgfx::frame(); + ImGui_Implbgfx_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + + ImGui::NewFrame(); + ImGui::ShowDemoWindow(); + ImGui::Render(); + + ImGui_Implbgfx_RenderDrawLists(ImGui::GetDrawData()); + m_Ctx->window->Swap(); } diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index d160790..3a12433 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -2,6 +2,7 @@ #include #include +#include #if defined(SCHISM_LINUX_WAYLAND) #include @@ -23,7 +24,6 @@ Window::~Window() { void Window::Create(int w, int h, const char* name, Ref eventAdapter) { - if (m_created) { SC_CORE_ERROR( "Trying to create a window, while this current window is already " @@ -63,6 +63,15 @@ void Window::ProcessEvents() { glfwPollEvents(); } +void Window::Resize(std::size_t width, std::size_t height) { + glfwSetWindowSize(m_WindowPtr, width, height); + +#if defined(SCHISM_LINUX_WAYLAND) + auto* wlWindow = reinterpret_cast(m_nativeHandle); + wl_egl_window_resize(wlWindow, width, height, 0, 0); +#endif +} + void Window::Swap() const { glfwSwapBuffers(m_WindowPtr); } @@ -76,11 +85,12 @@ void Window::SetNativeHandle() { SC_ASSERT(surface, "Cannot get native wayland window surface"); + // not sure if width and height should be updated manually m_nativeHandle = wl_egl_window_create(surface, m_Data.Width, m_Data.Height); m_nativeDisplay = glfwGetWaylandDisplay(); SC_ASSERT(m_nativeHandle, "Native window handle isn't valid"); - SC_ASSERT(m_nativeDisplay, "Native window handle isn't valid"); + SC_ASSERT(m_nativeDisplay, "Native display handle isn't valid"); #elif defined(SCHISM_LINUX_X11) m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(m_WindowPtr); diff --git a/src/schism/Core/Window.h b/src/schism/Core/Window.h index a0c53a5..e688c26 100644 --- a/src/schism/Core/Window.h +++ b/src/schism/Core/Window.h @@ -24,7 +24,7 @@ class Window { void SwapEventAdapter(Ref eventAdapter); - void Resize(); + void Resize(std::size_t width, std::size_t height); int GetWidth() const { return m_Data.Width; } diff --git a/src/schism/Renderer/RenderAPI.cpp b/src/schism/Renderer/RenderAPI.cpp index 5d5c808..4170492 100644 --- a/src/schism/Renderer/RenderAPI.cpp +++ b/src/schism/Renderer/RenderAPI.cpp @@ -5,19 +5,18 @@ #include #include #include +#include namespace Schism::Renderer { -bool API::Init(Core::WindowRef window) { - - // Renderer2D::Init(); - // This will be deprecated, stays here to test other parts while the batch renderer gets finished - +std::optional API::Init(Core::WindowRef window) { bgfx::Init bgfxInit; -#if defined(SCHISM_PLATFORM_WINDOWS) || defined(SCHISM_PLATFORM_LINUX) - bgfxInit.type = bgfx::RendererType::Vulkan; +#if defined(SCHISM_PLATFORM_WINDOWS) + bgfxInit.type = bgfx::RendererType::Direct3D12; #elif defined(SCHISM_PLATFORM_MAC) bgfxInit.type = bgfx::RendererType::Metal; +#elif defined(SCHISM_PLATFORM_LINUX) + bgfxInit.type = bgfx::RendererType::Vulkan; #else SC_STATIC_FAIL("Currently we are not supporting this platform"); #endif @@ -25,22 +24,24 @@ bool API::Init(Core::WindowRef window) { bgfxInit.resolution.width = window->GetWidth(); bgfxInit.resolution.height = window->GetHeight(); - /*bgfxInit.resolution.reset = BGFX_RESET_VSYNC;*/ + bgfxInit.resolution.reset = BGFX_RESET_VSYNC; bgfxInit.platformData.nwh = window->GetNativeHandle(); bgfxInit.platformData.ndt = window->GetNativeDisplay(); - int k = 1; - + // here we would start the render thread on the main thread + // call to renderFrame so bgfx doesn't start a render trhead + // but in the future this should be defered into an another thread bgfx::renderFrame(); if (!bgfx::init(bgfxInit)) { - return false; + return std::nullopt; } - bgfx::setViewClear(0, BGFX_CLEAR_COLOR); + bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH); bgfx::setViewRect(0, 0, 0, window->GetWidth(), window->GetHeight()); - return true; + // here we would instantiate all of the specific renderers + return bgfxInit.type; } void API::Shutdown() { @@ -51,5 +52,7 @@ void API::SetClearColor(const glm::vec4& color) {} void API::Clear() {} -void API::SetViewport(uint32_t width, uint32_t height) {} +void API::SetViewport(uint32_t width, uint32_t height) { + bgfx::setViewRect(0, 0, 0, width, height); +} } // namespace Schism::Renderer diff --git a/src/schism/Renderer/RenderAPI.h b/src/schism/Renderer/RenderAPI.h index a530b21..30d15cf 100644 --- a/src/schism/Renderer/RenderAPI.h +++ b/src/schism/Renderer/RenderAPI.h @@ -8,7 +8,8 @@ namespace Schism::Renderer { class API { public: - static bool Init(Core::WindowRef window); + static std::optional Init( + Core::WindowRef window); static void Shutdown(); static void SetClearColor(const glm::vec4& color); diff --git a/src/schism/Sandbox/Sandbox.cpp b/src/schism/Sandbox/Sandbox.cpp index ec534f5..7df77b5 100644 --- a/src/schism/Sandbox/Sandbox.cpp +++ b/src/schism/Sandbox/Sandbox.cpp @@ -3,7 +3,7 @@ #include "SampleScene.h" namespace Schism { -Sandbox::Sandbox() : Application(1280, 720, "Sandbox") { +Sandbox::Sandbox() : Application(1920, 1080, "Sandbox") { /*m_Ctx->GlobalAssets.Textures.Load("ship1sprite", "res/ships/1.png");*/ /*m_Ctx->GlobalAssets.Shaders.Load("spriterenderer",*/ /*"res/shaders/sprite_renderer.vert",*/ diff --git a/vcpkg.json b/vcpkg.json index 811e792..36f9a6e 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -19,13 +19,7 @@ ] }, "sol2", - "lua", - { - "name": "bgfx", - "features": [ - "multithreaded" - ] - } + "lua" ], "features": { "wayland": { diff --git a/vendor/bgfx-imgui/README.md b/vendor/bgfx-imgui/README.md new file mode 100644 index 0000000..79c2c4b --- /dev/null +++ b/vendor/bgfx-imgui/README.md @@ -0,0 +1,5 @@ +# bgfx-imgui + +This code is a port of a [Gist](https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0) by Richard Gale. + +`vs_ocornut_imgui.bin.h` and `fs_ocornut_imgui.bin.h` are copied from the [examples/common/imgui](https://github.com/bkaradzic/bgfx/tree/master/examples/common/imgui) of the [bgfx](https://github.com/bkaradzic/bgfx) repo (to make the use of `bgfx::EmbeddedShader` easier). diff --git a/vendor/bgfx-imgui/fs_ocornut_imgui.bin.h b/vendor/bgfx-imgui/fs_ocornut_imgui.bin.h new file mode 100644 index 0000000..f2cbe78 --- /dev/null +++ b/vendor/bgfx-imgui/fs_ocornut_imgui.bin.h @@ -0,0 +1,186 @@ +static const uint8_t fs_ocornut_imgui_glsl[189] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x00, // _tex............ + 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, // ..varying vec4 v + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, // _color0;.varying + 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, // vec2 v_texcoord + 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, // 0;.uniform sampl + 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, // er2D s_tex;.void + 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, // main ().{. gl_ + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x28, 0x74, 0x65, 0x78, // FragColor = (tex + 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x2c, 0x20, 0x76, // ture2D (s_tex, v + 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x20, 0x2a, 0x20, 0x76, 0x5f, // _texcoord0) * v_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // color0);.}... +}; +static const uint8_t fs_ocornut_imgui_essl[246] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, // _tex............ + 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // ..varying highp + 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, // vec4 v_color0;.v + 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, // arying highp vec + 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, // 2 v_texcoord0;.u + 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, // niform sampler2D + 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, // s_tex;.void mai + 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, // n ().{. lowp ve + 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, // c4 tmpvar_1;. t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, // mpvar_1 = textur + 0x65, 0x32, 0x44, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, // e2D (s_tex, v_te + 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, // xcoord0);. gl_F + 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x28, 0x74, 0x6d, 0x70, 0x76, // ragColor = (tmpv + 0x61, 0x72, 0x5f, 0x31, 0x20, 0x2a, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x29, // ar_1 * v_color0) + 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ;.}... +}; +static const uint8_t fs_ocornut_imgui_spv[910] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1a, 0x00, 0x68, 0x03, // _tex0.........h. + 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x97, 0x00, // ....#........... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, // ................ + 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, // ......GLSL.std.4 + 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // 50.............. + 0x00, 0x00, 0x0f, 0x00, 0x09, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma + 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x55, 0x00, // in....N...Q...U. + 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, // ..b............. + 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, // ................ + 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, // ......main...... + 0x06, 0x00, 0x23, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x53, 0x61, 0x6d, 0x70, 0x6c, // ..#...s_texSampl + 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x26, 0x00, 0x00, 0x00, 0x73, 0x5f, // er........&...s_ + 0x74, 0x65, 0x78, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, // texTexture...... + 0x06, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, // ..N...gl_FragCoo + 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x51, 0x00, 0x00, 0x00, 0x76, 0x5f, // rd........Q...v_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x55, 0x00, // color0........U. + 0x00, 0x00, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x00, 0x05, 0x00, // ..v_texcoord0... + 0x06, 0x00, 0x62, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ..b...bgfx_FragD + 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, // ata0..G...#...". + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x21, 0x00, // ......G...#...!. + 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x22, 0x00, // ......G...&...". + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x21, 0x00, // ......G...&...!. + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x0b, 0x00, // ......G...N..... + 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x51, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...Q..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x55, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...U..... + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...b..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, // ..............!. + 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x02, 0x00, 0x06, 0x00, // ................ + 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x19, 0x00, // .......... ..... + 0x09, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, // ................ + 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, // ................ + 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, // .. ..."......... + 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, // ..;..."...#..... + 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, // .. ...%......... + 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, // ..;...%...&..... + 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x32, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, // ......2....... . + 0x04, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, // ..M...........;. + 0x04, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, // ..M...N.......;. + 0x04, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, // ..M...Q....... . + 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, // ..T...........;. + 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, // ..T...U....... . + 0x04, 0x00, 0x61, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, // ..a...........;. + 0x04, 0x00, 0x61, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, // ..a...b.......6. + 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ + 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, // ..........=..... + 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, // ..$...#...=..... + 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, // ..'...&...=..... + 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, // ..R...Q...=..... + 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x56, 0x00, 0x05, 0x00, 0x32, 0x00, // ..V...U...V...2. + 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x57, 0x00, // ......'...$...W. + 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x56, 0x00, // ..............V. + 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x96, 0x00, // ................ + 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x62, 0x00, 0x00, 0x00, 0x86, 0x00, // ..R...>...b..... + 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ......8....... +}; +static const uint8_t fs_ocornut_imgui_dx9[239] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, // _tex0........... + 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, // ..........CTAB.. + 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, // ..O............. + 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, // ......H...0..... + 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x5f, // ......8.......s_ + 0x74, 0x65, 0x78, 0x00, 0xab, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, // tex............. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, // ......ps_3_0.Mic + 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, // rosoft (R) HLSL + 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, // Shader Compiler + 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, // 10.1............ + 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x01, 0x00, 0x03, 0x90, 0x1f, 0x00, // ................ + 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, // ..........B..... + 0x0f, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x08, // ................ + 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00, 0x00, // ............... +}; +static const uint8_t fs_ocornut_imgui_dx11[422] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x73, // _tex0..........s + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, // _tex0.........p. + 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0xbe, 0x78, 0xe7, 0xa5, 0x19, 0x0c, 0x70, 0xeb, 0x4c, 0xb1, // ..DXBC.x....p.L. + 0xac, 0x1f, 0x16, 0x84, 0xe9, 0x97, 0x01, 0x00, 0x00, 0x00, 0x70, 0x01, 0x00, 0x00, 0x03, 0x00, // ..........p..... + 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x49, 0x53, // ..,...........IS + 0x47, 0x4e, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x00, // GNl...........P. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x62, 0x00, // ..............b. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, // ................ + 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, // ......SV_POSITIO + 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, // N.COLOR.TEXCOORD + 0x00, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, // ..OSGN,......... + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // .. ............. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, // ..........SV_TAR + 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x94, 0x00, 0x00, 0x00, 0x40, 0x00, // GET...SHDR....@. + 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, // ..%...Z....`.... + 0x00, 0x00, 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, // ..X....p......UU + 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x62, 0x10, // ..b...........b. + 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, // ..2.......e.... + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x45, 0x00, // ......h.......E. + 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x02, 0x00, // ..........F..... + 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, // ..F~.......`.... + 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, // ..8.... ......F. + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, // ......F.......>. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // ...... +}; +static const uint8_t fs_ocornut_imgui_mtl[609] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x73, // FSH............s + 0x5f, 0x74, 0x65, 0x78, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x11, 0x01, 0xff, 0xff, 0x01, // _texSampler..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x54, 0x65, 0x78, 0x74, 0x75, // ......s_texTextu + 0x72, 0x65, 0x11, 0x01, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x73, 0x5f, 0x74, // re...........s_t + 0x65, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x02, 0x00, 0x00, // ex.............. + 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, // #include .#include + 0x20, 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, // .. + 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, // using namespace + 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, // metal;..struct x + 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, // latMtlMain_out.{ + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, // . float4 bgfx + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, // _FragData0 [[col + 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, // or(0)]];.};..str + 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, // uct xlatMtlMain_ + 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // in.{. float4 + 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, // v_color0 [[user( + 0x6c, 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, // locn0)]];. fl + 0x6f, 0x61, 0x74, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, // oat2 v_texcoord0 + 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x31, 0x29, 0x5d, 0x5d, // [[user(locn1)]] + 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, // ;.};..fragment x + 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, // latMtlMain_out x + 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, // latMtlMain(xlatM + 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, 0x5b, 0x73, // tlMain_in in [[s + 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, // tage_in]], textu + 0x72, 0x65, 0x32, 0x64, 0x3c, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x3e, 0x20, 0x73, 0x5f, 0x74, 0x65, // re2d s_te + 0x78, 0x20, 0x5b, 0x5b, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, // x [[texture(0)]] + 0x2c, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x53, // , sampler s_texS + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x20, 0x5b, 0x5b, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, // ampler [[sampler + 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, // (0)]]).{. xla + 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, // tMtlMain_out out + 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, // = {};. out.b + 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, // gfx_FragData0 = + 0x73, 0x5f, 0x74, 0x65, 0x78, 0x2e, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x28, 0x73, 0x5f, 0x74, // s_tex.sample(s_t + 0x65, 0x78, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x69, 0x6e, 0x2e, 0x76, 0x5f, // exSampler, in.v_ + 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x20, 0x2a, 0x20, 0x69, 0x6e, 0x2e, // texcoord0) * in. + 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, // v_color0;. re + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x20, // turn out;.}.... + 0x00, // . +}; +extern const uint8_t* fs_ocornut_imgui_pssl; +extern const uint32_t fs_ocornut_imgui_pssl_size; diff --git a/vendor/bgfx-imgui/imgui_impl_bgfx.cpp b/vendor/bgfx-imgui/imgui_impl_bgfx.cpp new file mode 100644 index 0000000..d54a4fc --- /dev/null +++ b/vendor/bgfx-imgui/imgui_impl_bgfx.cpp @@ -0,0 +1,189 @@ +// Derived from this Gist by Richard Gale: +// https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 + +// ImGui BFFX binding +// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture +// identifier. Read the FAQ about ImTextureID in imgui.cpp. + +// You can copy and use unmodified imgui_impl_* files in your project. See +// main.cpp for an example of using this. If you use this binding you'll need to +// call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), +// ImGui::Render() and ImGui_ImplXXXX_Shutdown(). If you are new to ImGui, see +// examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +#include "imgui_impl_bgfx.h" +#include +#include +#include "imgui.h" + +// BGFX/BX +#include "bgfx/bgfx.h" +#include "bgfx/embedded_shader.h" +#include "bx/math.h" +#include "bx/timer.h" + +// Data +static uint8_t g_View = 255; +static bgfx::TextureHandle g_FontTexture = BGFX_INVALID_HANDLE; +static bgfx::ProgramHandle g_ShaderHandle = BGFX_INVALID_HANDLE; +static bgfx::UniformHandle g_AttribLocationTex = BGFX_INVALID_HANDLE; +static bgfx::VertexLayout g_VertexLayout; + +// This is the main rendering function that you have to implement and call after +// ImGui::Render(). Pass ImGui::GetDrawData() to this function. +// Note: If text or lines are blurry when integrating ImGui into your engine, +// in your Render function, try translating your projection matrix by +// (0.5f,0.5f) or (0.375f,0.375f) +void ImGui_Implbgfx_RenderDrawLists(ImDrawData* draw_data) { + // Avoid rendering when minimized, scale coordinates for retina displays + // (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) { + return; + } + + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + + // Setup render state: alpha-blending enabled, no face culling, + // no depth testing, scissor enabled + uint64_t state = BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | + BGFX_STATE_MSAA | + BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, + BGFX_STATE_BLEND_INV_SRC_ALPHA); + + const bgfx::Caps* caps = bgfx::getCaps(); + + // Setup viewport, orthographic projection matrix + glm::mat4 ortho(1.f); + bx::mtxOrtho(reinterpret_cast(&ortho), 0.0f, io.DisplaySize.x, + io.DisplaySize.y, 0.0f, 0.0f, 1000.0f, 0.0f, + caps->homogeneousDepth); + + bgfx::setViewTransform(g_View, NULL, (float*)&ortho); + bgfx::setViewRect(g_View, 0, 0, (uint16_t)fb_width, (uint16_t)fb_height); + + // Render command lists + for (int n = 0; n < draw_data->CmdListsCount; n++) { + const ImDrawList* cmd_list = draw_data->CmdLists[n]; + + bgfx::TransientVertexBuffer tvb; + bgfx::TransientIndexBuffer tib; + + uint32_t numVertices = (uint32_t)cmd_list->VtxBuffer.size(); + uint32_t numIndices = (uint32_t)cmd_list->IdxBuffer.size(); + + if ((numVertices != bgfx::getAvailTransientVertexBuffer( + numVertices, g_VertexLayout)) || + (numIndices != bgfx::getAvailTransientIndexBuffer(numIndices))) { + // not enough space in transient buffer, quit drawing the rest... + break; + } + + bgfx::allocTransientVertexBuffer(&tvb, numVertices, g_VertexLayout); + bgfx::allocTransientIndexBuffer(&tib, numIndices); + + ImDrawVert* verts = (ImDrawVert*)tvb.data; + memcpy(verts, cmd_list->VtxBuffer.begin(), + numVertices * sizeof(ImDrawVert)); + + ImDrawIdx* indices = (ImDrawIdx*)tib.data; + memcpy(indices, cmd_list->IdxBuffer.begin(), + numIndices * sizeof(ImDrawIdx)); + + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { + const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; + + if (pcmd->UserCallback) { + pcmd->UserCallback(cmd_list, pcmd); + } else { + const uint16_t xx = (uint16_t)bx::max(pcmd->ClipRect.x, 0.0f); + const uint16_t yy = (uint16_t)bx::max(pcmd->ClipRect.y, 0.0f); + bgfx::setScissor( + xx, yy, (uint16_t)bx::min(pcmd->ClipRect.z, 65535.0f) - xx, + (uint16_t)bx::min(pcmd->ClipRect.w, 65535.0f) - yy); + + bgfx::setState(state); + bgfx::TextureHandle texture = { + (uint16_t)((intptr_t)pcmd->TextureId & 0xffff)}; + bgfx::setTexture(0, g_AttribLocationTex, texture); + bgfx::setVertexBuffer(0, &tvb, 0, numVertices); + bgfx::setIndexBuffer(&tib, pcmd->IdxOffset, pcmd->ElemCount); + bgfx::submit(g_View, g_ShaderHandle); + } + } + } +} + +bool ImGui_Implbgfx_CreateFontsTexture() { + // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); + unsigned char* pixels; + int width, height; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + // Upload texture to graphics system + g_FontTexture = bgfx::createTexture2D( + (uint16_t)width, (uint16_t)height, false, 1, bgfx::TextureFormat::BGRA8, + 0, bgfx::copy(pixels, width * height * 4)); + + // Store our identifier + io.Fonts->TexID = (void*)(intptr_t)g_FontTexture.idx; + + return true; +} + +#include "fs_ocornut_imgui.bin.h" +#include "vs_ocornut_imgui.bin.h" + +static const bgfx::EmbeddedShader s_embeddedShaders[] = { + BGFX_EMBEDDED_SHADER(vs_ocornut_imgui), + BGFX_EMBEDDED_SHADER(fs_ocornut_imgui), BGFX_EMBEDDED_SHADER_END()}; + +bool ImGui_Implbgfx_CreateDeviceObjects() { + bgfx::RendererType::Enum type = bgfx::getRendererType(); + g_ShaderHandle = bgfx::createProgram( + bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_ocornut_imgui"), + bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_ocornut_imgui"), + true); + + g_VertexLayout.begin() + .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) + .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float) + .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true) + .end(); + + g_AttribLocationTex = + bgfx::createUniform("g_AttribLocationTex", bgfx::UniformType::Sampler); + + ImGui_Implbgfx_CreateFontsTexture(); + + return true; +} + +void ImGui_Implbgfx_InvalidateDeviceObjects() { + bgfx::destroy(g_AttribLocationTex); + bgfx::destroy(g_ShaderHandle); + + if (isValid(g_FontTexture)) { + bgfx::destroy(g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture.idx = bgfx::kInvalidHandle; + } +} + +void ImGui_Implbgfx_Init(int view) { + g_View = (uint8_t)(view & 0xff); +} + +void ImGui_Implbgfx_Shutdown() { + ImGui_Implbgfx_InvalidateDeviceObjects(); +} + +void ImGui_Implbgfx_NewFrame() { + if (!isValid(g_FontTexture)) { + ImGui_Implbgfx_CreateDeviceObjects(); + } +} diff --git a/vendor/bgfx-imgui/imgui_impl_bgfx.h b/vendor/bgfx-imgui/imgui_impl_bgfx.h new file mode 100644 index 0000000..e31ab86 --- /dev/null +++ b/vendor/bgfx-imgui/imgui_impl_bgfx.h @@ -0,0 +1,20 @@ +// Derived from this Gist by Richard Gale: +// https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 + +// ImGui BGFX binding + +// You can copy and use unmodified imgui_impl_* files in your project. See +// main.cpp for an example of using this. If you use this binding you'll need to +// call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), +// ImGui::Render() and ImGui_ImplXXXX_Shutdown(). If you are new to ImGui, see +// examples/README.txt and documentation at the top of imgui.cpp. +// https://github.com/ocornut/imgui + +void ImGui_Implbgfx_Init(int view); +void ImGui_Implbgfx_Shutdown(); +void ImGui_Implbgfx_NewFrame(); +void ImGui_Implbgfx_RenderDrawLists(struct ImDrawData* draw_data); + +// Use if you want to reset your rendering device without losing ImGui state. +void ImGui_Implbgfx_InvalidateDeviceObjects(); +bool ImGui_Implbgfx_CreateDeviceObjects(); diff --git a/vendor/bgfx-imgui/vs_ocornut_imgui.bin.h b/vendor/bgfx-imgui/vs_ocornut_imgui.bin.h new file mode 100644 index 0000000..f78301d --- /dev/null +++ b/vendor/bgfx-imgui/vs_ocornut_imgui.bin.h @@ -0,0 +1,278 @@ +static const uint8_t vs_ocornut_imgui_glsl[460] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0xa4, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, // .......attribute + 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, // vec4 a_color0;. + 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, // attribute vec2 a + 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, // _position;.attri + 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, // bute vec2 a_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, // oord0;.varying v + 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, // ec4 v_color0;.va + 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, // rying vec2 v_tex + 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, // coord0;.uniform + 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, // mat4 u_viewProj; + 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, // .void main ().{. + 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, // vec4 tmpvar_1; + 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x7a, 0x77, 0x20, 0x3d, // . tmpvar_1.zw = + 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, // vec2(0.0, 1.0); + 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x20, 0x3d, // . tmpvar_1.xy = + 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x76, // a_position;. v + 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, // ec4 tmpvar_2;. + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x7a, 0x77, 0x20, 0x3d, 0x20, 0x76, 0x65, // tmpvar_2.zw = ve + 0x63, 0x32, 0x28, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, // c2(0.0, 1.0);. + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x75, // tmpvar_2.xy = (u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, // _viewProj * tmpv + 0x61, 0x72, 0x5f, 0x31, 0x29, 0x2e, 0x78, 0x79, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, // ar_1).xy;. gl_P + 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // osition = tmpvar + 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, // _2;. v_texcoord + 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, // 0 = a_texcoord0; + 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, // . v_color0 = a_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // color0;.}... +}; +static const uint8_t vs_ocornut_imgui_essl[508] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0xd4, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, // .......attribute + 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, // highp vec4 a_co + 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, // lor0;.attribute + 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, // highp vec2 a_pos + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, // ition;.attribute + 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, 0x74, 0x65, // highp vec2 a_te + 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, // xcoord0;.varying + 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, // highp vec4 v_co + 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, // lor0;.varying hi + 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, // ghp vec2 v_texco + 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, // ord0;.uniform hi + 0x67, 0x68, 0x70, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, // ghp mat4 u_viewP + 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, // roj;.void main ( + 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // ).{. highp vec4 + 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // tmpvar_1;. tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x7a, 0x77, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, // var_1.zw = vec2( + 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // 0.0, 1.0);. tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, // var_1.xy = a_pos + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, // ition;. highp v + 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, // ec4 tmpvar_2;. + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x7a, 0x77, 0x20, 0x3d, 0x20, 0x76, 0x65, // tmpvar_2.zw = ve + 0x63, 0x32, 0x28, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, // c2(0.0, 1.0);. + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x75, // tmpvar_2.xy = (u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, // _viewProj * tmpv + 0x61, 0x72, 0x5f, 0x31, 0x29, 0x2e, 0x78, 0x79, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, // ar_1).xy;. gl_P + 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // osition = tmpvar + 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, // _2;. v_texcoord + 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, // 0 = a_texcoord0; + 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, // . v_color0 = a_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // color0;.}... +}; +static const uint8_t vs_ocornut_imgui_spv[1293] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0xdc, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, // .........#...... + 0x00, 0x08, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, // ...|............ + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, // ...........GLSL. + 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, // std.450......... + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // ................ + 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x42, // ...main....>...B + 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x57, // ...E...P...S...W + 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, // ................ + 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, // .......main..... + 0x00, 0x06, 0x00, 0x23, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, // ...#...UniformBl + 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, // ock........#.... + 0x00, 0x00, 0x00, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, 0x00, 0x05, // ...u_viewProj... + 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x3e, // ...%...........> + 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x05, // ...a_color0..... + 0x00, 0x05, 0x00, 0x42, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // ...B...a_positio + 0x6e, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x45, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x74, 0x65, 0x78, // n......E...a_tex + 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x50, 0x00, 0x00, 0x00, 0x40, // coord0.....P...@ + 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, // entryPointOutput + 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // .gl_Position.... + 0x00, 0x09, 0x00, 0x53, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, // ...S...@entryPoi + 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // ntOutput.v_color + 0x30, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x57, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, // 0......W...@entr + 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x76, 0x5f, 0x74, // yPointOutput.v_t + 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x23, // excoord0...H...# + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x23, // ...........H...# + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, // .......#.......H + 0x00, 0x05, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, // ...#............ + 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, // ...G...#.......G + 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, // ...%...".......G + 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, // ...%...!.......G + 0x00, 0x04, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, // ...>...........G + 0x00, 0x04, 0x00, 0x42, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, // ...B...........G + 0x00, 0x04, 0x00, 0x45, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, // ...E...........G + 0x00, 0x04, 0x00, 0x50, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, // ...P...........G + 0x00, 0x04, 0x00, 0x53, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, // ...S...........G + 0x00, 0x04, 0x00, 0x57, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, // ...W............ + 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, // .......!........ + 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, // ........... .... + 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x17, // ................ + 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, // ................ + 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, // ....... .......+ + 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x2b, // ..............?+ + 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, // ................ + 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1e, // ..."............ + 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x24, // ...#..."... ...$ + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x24, // .......#...;...$ + 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x14, // ...%.......+.... + 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x27, // ...&....... ...' + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x3d, // ......."... ...= + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3d, // ...........;...= + 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x41, // ...>....... ...A + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, // ...........;...A + 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, // ...B.......;...A + 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x4f, // ...E....... ...O + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, // ...........;...O + 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, // ...P.......;...O + 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x56, // ...S....... ...V + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x56, // ...........;...V + 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, // ...W.......6.... + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, // ................ + 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3f, // .......=.......? + 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x43, // ...>...=.......C + 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x46, // ...B...=.......F + 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x71, // ...E...Q.......q + 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, // ...C.......Q.... + 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, // ...r...C.......P + 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x72, // .......s...q...r + 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x27, // ...........A...' + 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3d, // ...t...%...&...= + 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x90, // ..."...u...t.... + 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x75, // .......v...s...u + 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x76, // ...Q.......x...v + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x7a, // .......Q.......z + 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x07, // ...v.......P.... + 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x17, // ...{...x...z.... + 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, // .......>...P...{ + 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x53, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3e, // ...>...S...?...> + 0x00, 0x03, 0x00, 0x57, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, // ...W...F.......8 + 0x00, 0x01, 0x00, 0x00, 0x03, 0x05, 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // ...........@. +}; +static const uint8_t vs_ocornut_imgui_dx9[364] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0x44, 0x01, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0xfe, 0xff, 0x20, 0x00, 0x43, // ...D......... .C + 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0x01, // TAB....S........ + 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x30, // ...........L...0 + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, // ...........<.... + 0x00, 0x00, 0x00, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, 0xab, 0x03, // ...u_viewProj... + 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, // ...............v + 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, // s_3_0.Microsoft + 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, // (R) HLSL Shader + 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x51, // Compiler 10.1..Q + 0x00, 0x00, 0x05, 0x04, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, // ..............?. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x00, // ................ + 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, // ................ + 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, // ................ + 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x01, // ................ + 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x02, 0x00, 0x03, 0xe0, 0x05, // ................ + 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x55, 0x90, 0x04, // .............U.. + 0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x90, 0x00, // ................ + 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0xe4, 0x80, 0x03, // ................ + 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0c, 0xe0, 0x04, 0x00, 0x44, 0xa0, 0x01, // .............D.. + 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x02, // ................ + 0x00, 0x03, 0xe0, 0x02, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00, 0x00, // ............ +}; +static const uint8_t vs_ocornut_imgui_dx11[617] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0x38, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0xa9, 0x5b, 0xb0, 0xfb, 0xae, // ...8...DXBC.[... + 0x5e, 0xc6, 0x4a, 0xef, 0x25, 0x0b, 0x81, 0x23, 0x55, 0x3d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x38, // ^.J.%..#U=.....8 + 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x10, // .......,........ + 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x68, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, // ...ISGNh........ + 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // ...P............ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, // ...........V.... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, // ................ + 0x03, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // ..._............ + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, // ...........COLOR + 0x00, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, // .POSITION.TEXCOO + 0x52, 0x44, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, // RD.OSGNl........ + 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, // ...P............ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, // ................ + 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // ...b............ + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, // ...........SV_PO + 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, // SITION.COLOR.TEX + 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0x53, 0x48, 0x44, 0x52, 0x20, 0x01, 0x00, 0x00, 0x40, // COORD..SHDR ...@ + 0x00, 0x01, 0x00, 0x48, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, // ...H...Y...F. .. + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x00, // ......._........ + 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5f, // ..._...2......._ + 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, // ...2.......g.... + 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, // ..........e.... + 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0x32, 0x20, 0x10, 0x00, 0x02, // ......e...2 ... + 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08, 0x32, // ...h.......8...2 + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x15, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, // .......V.......F + 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x32, // . .........2...2 + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .......F. ...... + 0x00, 0x00, 0x00, 0x06, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x00, // ...........F.... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x32, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, // .......2 ......F + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // .......F. ...... + 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, 0xc2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // ...6.... ....... + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // @............... + 0x00, 0x80, 0x3f, 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, // ..?6.... ......F + 0x1e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x32, 0x20, 0x10, 0x00, 0x02, // .......6...2 ... + 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, // ...F.......>.... + 0x03, 0x05, 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // .......@. +}; +static const uint8_t vs_ocornut_imgui_mtl[855] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0a, 0x75, // VSH............u + 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, // _viewProj....... + 0x00, 0x00, 0x00, 0x26, 0x03, 0x00, 0x00, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, // ...&...#include + 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, // .# + 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, // include ..using nam + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, // espace metal;..s + 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, // truct _Global.{. + 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x78, 0x34, 0x20, 0x75, 0x5f, 0x76, // float4x4 u_v + 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, // iewProj;.};..str + 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, // uct xlatMtlMain_ + 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // out.{. float4 + 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, // _entryPointOutp + 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, // ut_v_color0 [[us + 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, // er(locn0)]];. + 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, // float2 _entryPo + 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // intOutput_v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, // oord0 [[user(loc + 0x6e, 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // n1)]];. float + 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, // 4 gl_Position [[ + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, // position]];.};.. + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, // struct xlatMtlMa + 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, // in_in.{. floa + 0x74, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x61, 0x74, // t4 a_color0 [[at + 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // tribute(0)]];. + 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, // float2 a_posit + 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, // ion [[attribute( + 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, // 1)]];. float2 + 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x61, // a_texcoord0 [[a + 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, // ttribute(2)]];.} + 0x3b, 0x0a, 0x0a, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // ;..vertex xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // lMain_out xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, // lMain(xlatMtlMai + 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, // n_in in [[stage_ + 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, // in]], constant _ + 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, // Global& _mtl_u [ + 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, // [buffer(0)]]).{. + 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, // xlatMtlMain_ + 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, // out out = {};. + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // out.gl_Positio + 0x6e, 0x20, 0x3d, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x28, 0x5f, 0x6d, 0x74, 0x6c, // n = float4((_mtl + 0x5f, 0x75, 0x2e, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, // _u.u_viewProj * + 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, // float4(in.a_posi + 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x29, // tion, 0.0, 1.0)) + 0x2e, 0x78, 0x79, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, // .xy, 0.0, 1.0);. + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, // out._entryPo + 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // intOutput_v_colo + 0x72, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // r0 = in.a_color0 + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, // ;. out._entry + 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x74, 0x65, // PointOutput_v_te + 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x74, // xcoord0 = in.a_t + 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, // excoord0;. re + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x03, 0x05, // turn out;.}..... + 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // .....@. +}; +extern const uint8_t* vs_ocornut_imgui_pssl; +extern const uint32_t vs_ocornut_imgui_pssl_size; From fe020c5dff3e45a34eeb18e827aba65bdfad1c10 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sat, 19 Oct 2024 14:11:56 +0200 Subject: [PATCH 11/14] guard wayland includes --- src/schism/Core/Window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index 3a12433..e9896d0 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -2,9 +2,9 @@ #include #include -#include #if defined(SCHISM_LINUX_WAYLAND) +#include #include #endif From d00bfde4aab90acdca1b9b6d17a6c5d95fb6cf6f Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sat, 19 Oct 2024 14:13:04 +0200 Subject: [PATCH 12/14] Fix windows compile definition --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afd5454..5e92888 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") message("Windows detected") add_compile_definitions( - SCHISM_PLATFORM_WIN + SCHISM_PLATFORM_WINDOWS GLFW_EXPOSE_NATIVE_WIN32 GLFW_EXPOSE_NATIVE_WGL ) From e0acb2b1b4d69d71e731f46d94ee1b23e0ba2705 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sat, 19 Oct 2024 14:13:58 +0200 Subject: [PATCH 13/14] Don't use std::format --- src/schism/Core/Application.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/schism/Core/Application.cpp b/src/schism/Core/Application.cpp index d2f6405..f8c021e 100644 --- a/src/schism/Core/Application.cpp +++ b/src/schism/Core/Application.cpp @@ -141,9 +141,7 @@ void Application::Run() { bgfx::touch(0); /*ImGui::NewFrame();*/ - bgfx::dbgTextPrintf( - 10, 10, 0x0f, - std::format("Testing bgfx, {}", ts.GetMiliseconds()).c_str()); + bgfx::dbgTextPrintf(10, 10, 0x0f, "Testing BGFX"); /*m_SceneManager.OnDraw();*/ /*ImGui::Render();*/ From 2b5419259a366ec659be8426b7886227be258639 Mon Sep 17 00:00:00 2001 From: Angel Stojanov Date: Sun, 20 Oct 2024 21:26:23 +0200 Subject: [PATCH 14/14] Display Handler, Display and signals --- src/schism/Core/Display.cpp | 43 ++++++ src/schism/Core/Display.h | 75 +++++++++++ src/schism/Core/DisplayUtils.cpp | 159 +++++++++++++++++++++++ src/schism/Core/DisplayUtils.h | 20 +++ src/schism/Core/Window.cpp | 2 +- src/schism/Util/ScopedSignalConnection.h | 17 +++ src/schism/Util/Signal.cpp | 19 +++ src/schism/Util/Signal.h | 81 ++++++++++++ src/schism/Util/SignalConnection.h | 26 ++++ src/schism/Util/SingleSignal.h | 7 +- vendor/atomic_queue | 2 +- vendor/bgfx | 2 +- vendor/imguizmo | 2 +- vendor/phmap | 2 +- 14 files changed, 449 insertions(+), 8 deletions(-) create mode 100644 src/schism/Core/Display.cpp create mode 100644 src/schism/Core/Display.h create mode 100644 src/schism/Core/DisplayUtils.cpp create mode 100644 src/schism/Core/DisplayUtils.h create mode 100644 src/schism/Util/ScopedSignalConnection.h create mode 100644 src/schism/Util/Signal.cpp create mode 100644 src/schism/Util/Signal.h create mode 100644 src/schism/Util/SignalConnection.h diff --git a/src/schism/Core/Display.cpp b/src/schism/Core/Display.cpp new file mode 100644 index 0000000..35b77b7 --- /dev/null +++ b/src/schism/Core/Display.cpp @@ -0,0 +1,43 @@ +#include + +#include +#include + +namespace Schism::Core { +Display::Display(GLFWmonitor* monitor) + : m_glfwMonitor(monitor), m_Name(glfwGetMonitorName(monitor)) {} + +void* Display::getNativeHandle() {} + +std::string Display::Name() { + return m_Name; +} + +glm::vec2 Display::PhysicalSize() { + return vec2Getter(&glfwGetMonitorPhysicalSize); +} + +glm::vec2 Display::ContentScale() { + return vec2Getter(&glfwGetMonitorContentScale); +} + +glm::vec2 Display::VirtualPosition() { + return vec2Getter(&glfwGetMonitorPos); +} + +glm::vec4 Display::WorkArea() { + int x; + int y; + + int w; + int h; + + glfwGetMonitorWorkarea(m_glfwMonitor, &x, &y, &w, &h); + + return {x, y, w, h}; +} + +std::vector Display::VideoModes() {} + +struct Display::VideoMode Display::VideoMode() {} +} // namespace Schism::Core diff --git a/src/schism/Core/Display.h b/src/schism/Core/Display.h new file mode 100644 index 0000000..29b1e6e --- /dev/null +++ b/src/schism/Core/Display.h @@ -0,0 +1,75 @@ +#pragma once + +#include + +#include + +#include + +#include +#include + +namespace Schism::Core { + +namespace DisplayUtils::detail { +class DisplayHandler; +} + +// this can be abstracted away into a base class and then implement the platform dependent stuff to avoid fwd declaration +// into other classes but meh... +class Display { + + friend DisplayUtils::detail::DisplayHandler; + + public: + struct VideoMode { + int width; + int height; + int redBits; + int greenBits; + int blueBits; + int refreshRate; + }; + + public: + void* getNativeHandle(); + + std::string Name(); + bool Active(); + glm::vec2 PhysicalSize(); + glm::vec2 ContentScale(); + glm::vec2 VirtualPosition(); + glm::vec4 WorkArea(); + + std::vector VideoModes(); + VideoMode VideoMode(); + + bool operator==(const Display& display); + + bool operator==(Ref const& display); + + private: + Display(GLFWmonitor* monitor); + + void SetActive(bool isActive); + bool operator==(GLFWmonitor* monitor); + + template + inline glm::vec2 vec2Getter(void (*f)(GLFWmonitor*, T*, T*)) { + T x; + T y; + + f(m_glfwMonitor, &x, &y); + + return {x, y}; + } + + private: + GLFWmonitor* m_glfwMonitor; + void* m_nativeHandle; + + bool m_isActive{true}; + std::string m_Name; +}; + +} // namespace Schism::Core diff --git a/src/schism/Core/DisplayUtils.cpp b/src/schism/Core/DisplayUtils.cpp new file mode 100644 index 0000000..e611a2c --- /dev/null +++ b/src/schism/Core/DisplayUtils.cpp @@ -0,0 +1,159 @@ +#include + +#include + +#include +#include "schism/Util/SignalConnection.h" + +/*#include "schism/Util/SignalConnection.h"*/ + +namespace Schism::Core::DisplayUtils { + +namespace detail { +class DisplayHandler { + public: + DisplayHandler() { + glfwSetMonitorCallback(monitorCallback); + refreshDisplays(); + } + + auto ListDisplays() { return m_displays; } + + Ref PrimaryDisplay() { + auto* primary = glfwGetPrimaryMonitor(); + auto display = findDisplay(primary); + + if (!display) { + refreshDisplays(); + + display = findDisplay(primary); + + if (display) { + auto display = Ref(new Display(primary)); + m_displays.push_back(display); + return display; + } + } + + return display; + } + + Util::SignalConnection OnDisplayAttached(DisplayCallback&& callback) { + return m_attached.connect(callback); + } + + Util::SignalConnection OnDisplayRemoved(DisplayCallback&& callback) { + return m_removed.connect(callback); + } + + private: + static void monitorCallback(GLFWmonitor* monitor, int event) { + auto handler = reinterpret_cast( + glfwGetMonitorUserPointer(monitor)); + + if (event == GLFW_CONNECTED) { + handler->AttachedDisplay(monitor); + } else if (event == GLFW_DISCONNECTED) { + handler->RemovedDisplay(monitor); + } + } + + private: + Ref findDisplay(GLFWmonitor* monitor) { + auto found = std::ranges::find_if(m_displays, + [monitor](Ref& display) { + return *display == monitor; + }); + + return found != std::end(m_displays) ? *found : nullptr; + } + + void AttachedDisplay(GLFWmonitor* monitor) { + Ref display = findDisplay(monitor); + + if (!display) { + display = Ref(new Display(monitor)); + m_displays.push_back(display); + } + + auto active = display->Active(); + display->SetActive(display ? true : true); + + m_attached(display); + } + + void RemovedDisplay(GLFWmonitor* monitor) { + Ref display = findDisplay(monitor); + + if (!display) { + SC_CORE_ERROR( + "Yeah, weird, removed display is not actually in our " + "store"); + return; + } + + display->SetActive(false); + + std::erase_if(m_displays, [monitor](const Ref& d) { + return *d == monitor; + }); + } + + void refreshDisplays() { + int count; + GLFWmonitor** arr = glfwGetMonitors(&count); + + m_displays.clear(); + m_displays.reserve(count); + + for (int i = 0; i < count; i++) { + auto* monitor = arr[i]; + + glfwSetMonitorUserPointer(monitor, this); + + Ref display = Ref(new Display(monitor)); + + m_displays.push_back(display); + } + }; + + private: + std::vector> m_displays; + Util::Signal)> m_attached; + Util::Signal)> m_removed; +}; + +// This can be done to avoid static initialization, use a manager for static object for +// manual allocation and deallocation +static Ptr handler; + +static const Ptr& getHandler() { + if (!handler) { + handler = Ptr(); + } + + return handler; +}; + +} // namespace detail + +std::vector> ListDisplays() { + auto& h = detail::getHandler(); + return h->ListDisplays(); +} + +Ref PrimaryDisplay() { + auto& h = detail::getHandler(); + return h->PrimaryDisplay(); +} + +Util::SignalConnection OnDisplayAttached(DisplayCallback&& callback) { + auto& h = detail::getHandler(); + return h->OnDisplayAttached(std::move(callback)); +} + +Util::SignalConnection OnDisplayRemoved(DisplayCallback&& callback) { + auto& h = detail::getHandler(); + return h->OnDisplayRemoved(std::move(callback)); +} +} // namespace Schism::Core::DisplayUtils diff --git a/src/schism/Core/DisplayUtils.h b/src/schism/Core/DisplayUtils.h new file mode 100644 index 0000000..195aece --- /dev/null +++ b/src/schism/Core/DisplayUtils.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +#include +#include + +namespace Schism::Core::DisplayUtils { + +using DisplayCallback = std::function& display)>; + +static std::vector> ListDisplays(); +static Ref PrimaryDisplay(); + +static Util::SignalConnection OnDisplayAttached(DisplayCallback&& callback); +static Util::SignalConnection OnDisplayRemoved(DisplayCallback&& callback); + +} // namespace Schism::Core::DisplayUtils diff --git a/src/schism/Core/Window.cpp b/src/schism/Core/Window.cpp index e9896d0..1bef170 100644 --- a/src/schism/Core/Window.cpp +++ b/src/schism/Core/Window.cpp @@ -95,7 +95,7 @@ void Window::SetNativeHandle() { #elif defined(SCHISM_LINUX_X11) m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(m_WindowPtr); #else - SC_STATIC_FAIL("Not a supported window protocol") + SC_STATIC_FAIL("Not a supported linux window protocol") #endif #elif defined(SCHISM_PLATFORM_WINDOWS) diff --git a/src/schism/Util/ScopedSignalConnection.h b/src/schism/Util/ScopedSignalConnection.h new file mode 100644 index 0000000..91ac568 --- /dev/null +++ b/src/schism/Util/ScopedSignalConnection.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace Schism::Util { + +class ScopedSignalConnection : public SignalConnection { + public: + ScopedSignalConnection(const SignalConnection& conn) + : SignalConnection(conn) {} + + ScopedSignalConnection(const SignalConnection&& conn) + : SignalConnection(conn) {} + + ~ScopedSignalConnection() { disconnect(); } +}; +} // namespace Schism::Util diff --git a/src/schism/Util/Signal.cpp b/src/schism/Util/Signal.cpp new file mode 100644 index 0000000..6ff008e --- /dev/null +++ b/src/schism/Util/Signal.cpp @@ -0,0 +1,19 @@ +#include +#include + +namespace Schism::Util { + +template +SignalConnection Signal::connect(Signal::func&& callback) { + auto id = m_idCounter.fetch_add(1); + + doSyncOperation([&] { m_funcs.emplace_back(id, callback); }); + + auto close_func = [this](u64 id) { + CloseConnection(id); + }; + + return {id, close_func}; +} + +} // namespace Schism::Util diff --git a/src/schism/Util/Signal.h b/src/schism/Util/Signal.h new file mode 100644 index 0000000..55eb3af --- /dev/null +++ b/src/schism/Util/Signal.h @@ -0,0 +1,81 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +namespace Schism::Util { + +class SignalConnection; + +template +class Signal { + using func = std::function; + + struct FuncHandle { + u64 id{0}; + func f; + }; + + public: + ~Signal() {} + + SignalConnection connect(func&& callback); + + void operator()() { + for (auto const& handle : m_funcs) { + handle.f(); + } + } + + template + void operator()(Args&... args) { + doOperation([&] { + for (auto const& handle : m_funcs) { + handle.f(std::forward(args)...); + } + }); + } + + template + void operator()(Args&&... args) { + doOperation([&] { + for (auto const& handle : m_funcs) { + handle.f(std::forward(args)...); + } + }); + } + + private: + inline void doOperation(std::function&& operation) { + if constexpr (Sync) { + std::lock_guard lck(m_mGuard); + operation(); + } else { + operation(); + } + } + + void CloseConnection(u64 id) { + // can be extended depending on the use case + // in small sets this is faster than a map, in bigger ones + // this could be swapped out with a better container + // good enough for now + // TODO: angel: optimize this! + doOperation([&] { + std::erase_if(m_funcs, [id](const FuncHandle& handle) { + return handle.id == id; + }); + }); + } + + private: + std::vector m_funcs; + std::atomic m_idCounter; + std::mutex m_mGuard; +}; +} // namespace Schism::Util diff --git a/src/schism/Util/SignalConnection.h b/src/schism/Util/SignalConnection.h new file mode 100644 index 0000000..f75429a --- /dev/null +++ b/src/schism/Util/SignalConnection.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace Schism::Util { + +// this can be extended to support multiple type and stuff +class SignalConnection { + using close_func = std::function; + + class Signal; + friend Signal; + + private: + SignalConnection(u64 id, close_func&& closeFunc) + : m_id(id), m_closeFunc(closeFunc) {} + + public: + // can be extended later on + void disconnect() { m_closeFunc(m_id); } + + private: + close_func m_closeFunc; + u64 m_id; +}; +} // namespace Schism::Util diff --git a/src/schism/Util/SingleSignal.h b/src/schism/Util/SingleSignal.h index c69216a..f42ae25 100644 --- a/src/schism/Util/SingleSignal.h +++ b/src/schism/Util/SingleSignal.h @@ -1,7 +1,8 @@ #pragma once +#include + #include -#include "schism/System/Debug.h" namespace Schism::Util { @@ -10,12 +11,12 @@ class SingleSignal { using func = std::function; public: - ~SingleSignal() { disconnect_slot(); } - void disconnect_slot() { m_func = nullptr; } void connect(func&& callback) { m_func = std::move(callback); } + // this possibly has to be guarded if we have a void return type + // BUG prone auto operator()() { return m_func(); } template diff --git a/vendor/atomic_queue b/vendor/atomic_queue index cf52f25..62f94f9 160000 --- a/vendor/atomic_queue +++ b/vendor/atomic_queue @@ -1 +1 @@ -Subproject commit cf52f25c4c4da311a8f7a3d4d99389523991d72b +Subproject commit 62f94f91452f42da58e2c4fb05a208ad7631235c diff --git a/vendor/bgfx b/vendor/bgfx index 9418487..f531516 160000 --- a/vendor/bgfx +++ b/vendor/bgfx @@ -1 +1 @@ -Subproject commit 94184872a86738baa847ef12877f0da0b273a888 +Subproject commit f531516396e7507f63c0e448543bc6d9bc546191 diff --git a/vendor/imguizmo b/vendor/imguizmo index 99358b3..6d58820 160000 --- a/vendor/imguizmo +++ b/vendor/imguizmo @@ -1 +1 @@ -Subproject commit 99358b3afc8cdfff5c264f97ab1718b2d8089319 +Subproject commit 6d588209f99b1324a608783d1f52faa518886c29 diff --git a/vendor/phmap b/vendor/phmap index 63acc33..4817a6d 160000 --- a/vendor/phmap +++ b/vendor/phmap @@ -1 +1 @@ -Subproject commit 63acc3336f941c6f324c88eb9ee4ce623a460cd5 +Subproject commit 4817a6d3b8407063cf0328eb92dbb27ee2f55528