wrap imgui impl funcs

This commit is contained in:
2025-05-04 22:51:45 -05:00
parent 853881e5e8
commit 2820387851
4 changed files with 136 additions and 78 deletions

View File

@@ -1,52 +1,5 @@
#include "ImguiModule.h"
#define RENDERER_OPENGL
#define WINDOW_GLFW
#ifdef RENDERER_OPENGL
#include "backends/imgui_impl_opengl3.h"
#define RENDERER_INIT() ImGui_ImplOpenGL3_Init("#version 330")
#define RENDERER_SHUTDOWN() ImGui_ImplOpenGL3_Shutdown()
#define RENDERER_NEWFRAME() ImGui_ImplOpenGL3_NewFrame()
#define RENDERER_RENDERDRAWDATA(x) ImGui_ImplOpenGL3_RenderDrawData(x)
#endif
#ifdef WINDOW_GLFW
#include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h>
#ifdef RENDERER_OPENGL
#define WINDOW_INIT() ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true)
#endif
#define WINDOW_SHUTDOWN() ImGui_ImplGlfw_Shutdown()
#define WINDOW_NEWFRAME() ImGui_ImplGlfw_NewFrame()
#endif
#ifdef WINDOW_SDL3
#include "backends/imgui_impl_sdl3.h"
#include <SDL3/SDL.h>
#ifdef RENDERER_OPENGL
#define WINDOW_INIT() ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext())
#endif
#define WINDOW_SHUTDOWN() ImGui_ImplSDL3_Shutdown()
#define WINDOW_NEWFRAME() ImGui_ImplSDL3_NewFrame()
#define WINDOW_PROCESSEVENT() ImGui_ImplSDL3_ProcessEvent(&e)
#endif
#include "pch.hpp"
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
@@ -64,8 +17,8 @@ ImguiModule::~ImguiModule() {
wm->getRenderer()->getCmdList().erase(rcmd_it);
RENDERER_SHUTDOWN();
WINDOW_SHUTDOWN();
rendererShutdown();
windowShutdown();
ImGui::DestroyContext();
wm->releaseWindow(window);
@@ -100,28 +53,28 @@ void ImguiModule::onLoad() {
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
if(!WINDOW_INIT())
std::cout << "WINDOW_INIT failed\n";
if(!windowInit())
std::cout << "windowInit failed\n";
if(!RENDERER_INIT()) {
std::cout << "RENDERER_INIT failed!\n" << std::endl;
if(!rendererInit()) {
std::cout << "rendererInit failed!\n" << std::endl;
}
wm->getRenderer()->getCmdList().push_back([](){
ImGui::Render();
RENDERER_RENDERDRAWDATA(ImGui::GetDrawData());
rendererRenderDrawData();
RENDERER_NEWFRAME();
WINDOW_NEWFRAME();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
});
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
//Compute first frame ahead of first WindowModule->run()
RENDERER_NEWFRAME();
WINDOW_NEWFRAME();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}

View File

@@ -9,6 +9,26 @@
#include "modules/WindowModule/src/WindowModule.h"
#ifdef RENDERER_OPENGL
#include "backends/imgui_impl_opengl3.h"
#endif
#ifdef WINDOW_GLFW
#include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h>
#endif
#ifdef WINDOW_SDL3
#include "backends/imgui_impl_sdl3.h"
#include <SDL3/SDL.h>
#endif
class ImguiModule : public Archimedes::Module {
public:
@@ -44,9 +64,46 @@ class ImguiModule : public Archimedes::Module {
Archimedes::Window* window;
std::list<std::function<void()>>::iterator rcmd_it;
#ifdef RENDERER_OPENGL
auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); }
void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); }
void rendererNewFrame() { ImGui_ImplOpenGL3_NewFrame(); }
void rendererRenderDrawData() { ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); }
#endif
#ifdef WINDOW_GLFW
#ifdef RENDERER_OPENGL
auto windowInit(Archimedes::Window* window) { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); }
#endif
void windowShutdown() { ImGui_ImplGlfw_Shutdown(); }
void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); }
#endif
#ifdef WINDOW_SDL3
#ifdef RENDERER_OPENGL
auto windowInit(Archimedes::Window* window) { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); }
#endif
#define windowShutdown() ImGui_ImplSDL3_Shutdown()
void windowShutdown() { ImGui_ImplSDL3_Shutdown(); }
#define windowNewFrame() ImGui_ImplSDL3_NewFrame()
void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); }
void windowProcessEvent(SDL_Event e) { ImGui_ImplSDL3_ProcessEvent(&e); }
#endif
};
#ifdef IMGUIMODULE_DYNAMIC
#define MODULE_TYPE ImguiModule
#include "endModule.h"
#endif