aquire and release
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "ImguiModule.h"
|
||||
|
||||
#include "modules/WindowModule/src/WindowModule.h"
|
||||
|
||||
#include "backends/imgui_impl_glfw.h"
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
|
||||
@@ -27,6 +25,8 @@ ImguiModule::~ImguiModule() {
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
wm->releaseWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ void ImguiModule::onLoad() {
|
||||
std::cout << "No WindowModule for ImguiModule!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
window = wm->aquireWindow();
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
context = ImGui::CreateContext();
|
||||
@@ -56,7 +58,7 @@ void ImguiModule::onLoad() {
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
|
||||
if(!ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true))
|
||||
std::cout << "GLFWImpl failed\n";
|
||||
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
||||
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
#include "modules/WindowModule/src/WindowModule.h"
|
||||
|
||||
class ImguiModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
@@ -20,12 +22,27 @@ class ImguiModule : public Archimedes::Module {
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
ImGuiContext* getContext() { return context; }
|
||||
ImGuiContext* aquireContext() {
|
||||
contextRefs++;
|
||||
return context;
|
||||
}
|
||||
|
||||
void releaseContext(ImGuiContext* ctxt) {
|
||||
if(ctxt == context && context != nullptr) {
|
||||
if(--contextRefs == 0) {
|
||||
app->stopModule(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
int contextRefs = 0;
|
||||
|
||||
ImGuiContext* context;
|
||||
|
||||
Archimedes::Window* window;
|
||||
|
||||
std::list<std::function<void()>>::iterator rcmd_it;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user