persist module render commands

This commit is contained in:
2025-03-30 10:44:01 -05:00
parent 64636c2771
commit 03776d16bc
5 changed files with 26 additions and 13 deletions

View File

@@ -21,6 +21,7 @@ namespace Archimedes {
protected:
Window* window;
//Renderer* renderer;
};
}

View File

@@ -17,7 +17,16 @@ namespace Archimedes {
void render();
void addRenderCmd(renderCmd* cmd) { rc.push_back(cmd); }
std::list<renderCmd*>::iterator addRenderCmd(renderCmd* cmd) {
auto it = rc.end();
rc.push_back(cmd);
return it;
}
void removeRenderCmd(std::list<renderCmd*>::iterator cmd) {
rc.erase(cmd);
}
private:
std::list<renderCmd*> rc;

View File

@@ -27,7 +27,6 @@ namespace Archimedes {
for(auto* f : cmdList)
f();
cmdList.clear();
}
};

View File

@@ -12,6 +12,7 @@ TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a)
}
TestImgui::~TestImgui() {
window->getRenderer().removeRenderCmd(rcmd);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
@@ -40,6 +41,17 @@ void TestImgui::onLoad() {
ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true);
ImGui_ImplOpenGL3_Init("#version 130");
rcmd = window->getRenderer().addRenderCmd([](){
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
/*if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}*/
});
//cmdlist.push_back(it);
}
void TestImgui::run() {
@@ -51,15 +63,6 @@ void TestImgui::run() {
ImGui::Render();
window->getRenderer().addRenderCmd([](){
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
/*if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}*/
});
if(window->shouldClose())
app->end();

View File

@@ -18,13 +18,14 @@ class TestImgui : public Archimedes::GuiModule {
private:
bool demo = true;
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
};
#ifndef TESTIMGUI_STATIC
extern "C" {
Archimedes::Module* create(void* handle, Archimedes::App* app) {
return new TestImgui(handle, app);
return (Archimedes::Module*) new TestImgui(handle, app);
}
}