work on layers

This commit is contained in:
2025-04-08 11:47:24 -05:00
parent fbfa13a742
commit 3a797fb19a
10 changed files with 183 additions and 87 deletions

View File

@@ -12,64 +12,21 @@ TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a)
}
TestImgui::~TestImgui() {
std::list<Archimedes::Renderer::renderCmd*>* cmdList =
std::any_cast<std::list<Archimedes::Renderer::renderCmd*>*>(depsInstances["WindowModule"]->getData("renderCmdList"));
cmdList->erase(rcmd);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void TestImgui::onLoad() {
WindowModule* wm = (WindowModule*) depsInstances["WindowModule"];
std::cout << "Say hello: " << wm->sayHello() << std::endl;
if(!wm) {
std::cout << "No WindowModule for TestImgui!\n";
std::abort();
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
GLFWwindow* w = std::any_cast<GLFWwindow*>(wm->getData("window"));
if(!ImGui_ImplGlfw_InitForOpenGL(w, true))
std::cout << "GLFWImpl failed\n";
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
}
std::list<Archimedes::Renderer::renderCmd*>* cmdList =
std::any_cast<std::list<Archimedes::Renderer::renderCmd*>*>(wm->getData("renderCmdList"));
cmdList->push_back([](){
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
});
rcmd = --cmdList->end();
cmdList->end()++;
//Compute first frame ahead of first WindowModule->run()
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::Render();
wm->getLayerstack()->push(&layer);
}
void TestImgui::run() {
@@ -103,3 +60,53 @@ void TestImgui::run() {
}
ImGui::Render();
}
TestImgui::TILayer::~TILayer() {}
void TestImgui::TILayer::onAttach() {
WindowModule* wm = (WindowModule*) ti->depsInstances["WindowModule"];
if(!wm) {
std::cout << "No WindowModule for TestImgui!\n";
std::abort();
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
GLFWwindow* w = wm->getWindow()->getWindowImpl().getWindow();
if(!ImGui_ImplGlfw_InitForOpenGL(w, true))
std::cout << "GLFWImpl failed\n";
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
}
//Compute first frame ahead of first WindowModule->run()
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::Render();
}
void TestImgui::TILayer::onRender() {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
void TestImgui::TILayer::onDetach() {
}
bool TestImgui::TILayer::onEvent(const Archimedes::Event&) { return false; }

View File

@@ -23,6 +23,27 @@ class TestImgui : public Archimedes::GuiModule {
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
Archimedes::Window* window;
class TILayer : public Archimedes::Layer {
public:
TILayer(TestImgui* _ti) : ti(_ti) {}
~TILayer();
void onRender();
void onAttach();
void onDetach();
bool onEvent(const Archimedes::Event&);
private:
TestImgui* ti;
} layer = TILayer(this);
};
#ifdef TESTIMGUI_DYNAMIC