work on layers
This commit is contained in:
@@ -143,6 +143,14 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void unload(std::string name) {
|
virtual void unload(std::string name) {
|
||||||
|
|
||||||
|
//unload modules that depend on the one we are unloading
|
||||||
|
for(std::string s : runOrder) {
|
||||||
|
if(modules[s]->deps.find(name) != modules[s]->deps.end()) {
|
||||||
|
unload(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Module* m = modules[name];
|
Module* m = modules[name];
|
||||||
void* h = m->getHandle();
|
void* h = m->getHandle();
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void push(Layer* l) {
|
void push(Layer* l) {
|
||||||
lstack.push_front(l);
|
if(l) {
|
||||||
l->onAttach();
|
lstack.push_front(l);
|
||||||
|
l->onAttach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop() {
|
void pop() {
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ namespace Archimedes {
|
|||||||
return glewInit() == GLEW_OK;
|
return glewInit() == GLEW_OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
void render(std::list<renderCmd*> cmdList, int& w, int& h) {
|
void render(std::list<std::function<void()>> cmdList, int& w, int& h) {
|
||||||
|
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
for(auto* f : cmdList)
|
for(auto f : cmdList)
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,17 +13,43 @@ ImguiModule::ImguiModule(void* h, Archimedes::App* a) : Archimedes::GuiModule(h,
|
|||||||
|
|
||||||
ImguiModule::~ImguiModule() {
|
ImguiModule::~ImguiModule() {
|
||||||
|
|
||||||
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 ImguiModule::onLoad() {
|
void ImguiModule::onLoad() {
|
||||||
|
WindowModule* wm = (WindowModule*) depsInstances["WindowModule"];
|
||||||
|
|
||||||
Archimedes::Module* wm = depsInstances["WindowModule"];
|
if(!wm) {
|
||||||
|
std::cout << "No WindowModule for ImguiModule!\n";
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
wm->getLayerstack()->push(&layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiModule::run() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
static float f = 0.0f;
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
|
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||||
|
|
||||||
|
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||||
|
|
||||||
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||||
|
|
||||||
|
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||||
|
counter++;
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("counter = %d", counter);
|
||||||
|
|
||||||
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImguiModule::IGLayer::~IGLayer() {}
|
||||||
|
|
||||||
|
void ImguiModule::IGLayer::onAttach() {
|
||||||
|
WindowModule* wm = (WindowModule*) imgui->depsInstances["WindowModule"];
|
||||||
|
|
||||||
if(!wm) {
|
if(!wm) {
|
||||||
std::cout << "No WindowModule for ImguiModule!\n";
|
std::cout << "No WindowModule for ImguiModule!\n";
|
||||||
@@ -44,57 +70,41 @@ void ImguiModule::onLoad() {
|
|||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
// Setup Platform/Renderer backends
|
||||||
GLFWwindow* w = std::any_cast<GLFWwindow*>(wm->getData("window"));
|
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
|
||||||
|
|
||||||
if(!ImGui_ImplGlfw_InitForOpenGL(w, true))
|
|
||||||
std::cout << "GLFWImpl failed\n";
|
std::cout << "GLFWImpl failed\n";
|
||||||
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
||||||
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
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()
|
//Compute first frame ahead of first WindowModule->run()
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
}
|
|
||||||
|
|
||||||
void ImguiModule::run() {
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
}
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
void ImguiModule::IGLayer::onRender() {
|
||||||
static float f = 0.0f;
|
ImGui::Render();
|
||||||
static int counter = 0;
|
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
bool ImguiModule::IGLayer::onEvent(const Archimedes::Event& e) { return false; }
|
||||||
counter++;
|
|
||||||
ImGui::SameLine();
|
void ImguiModule::IGLayer::onDetach() {
|
||||||
ImGui::Text("counter = %d", counter);
|
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::End();
|
ImGui::DestroyContext();
|
||||||
}
|
|
||||||
ImGui::Render();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,29 @@ class ImguiModule : public Archimedes::GuiModule {
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
|
|
||||||
|
|
||||||
Archimedes::Window* window;
|
Archimedes::Window* window;
|
||||||
|
|
||||||
|
class IGLayer : public Archimedes::Layer {
|
||||||
|
public:
|
||||||
|
|
||||||
|
IGLayer(ImguiModule* _imgui) : imgui(_imgui) {}
|
||||||
|
|
||||||
|
~IGLayer();
|
||||||
|
|
||||||
|
void onRender();
|
||||||
|
|
||||||
|
void onAttach();
|
||||||
|
|
||||||
|
void onDetach();
|
||||||
|
|
||||||
|
bool onEvent(const Archimedes::Event&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
ImguiModule* imgui;
|
||||||
|
|
||||||
|
} layer = IGLayer(this);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef TESTIMGUI_DYNAMIC
|
#ifdef TESTIMGUI_DYNAMIC
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#include "WindowModule.h"
|
#include "WindowModule.h"
|
||||||
|
|
||||||
WindowModule::~WindowModule() {
|
WindowModule::~WindowModule() {
|
||||||
if(layers)
|
if(layers) {
|
||||||
delete layers;
|
delete layers;
|
||||||
if(renderer)
|
}
|
||||||
|
if(renderer) {
|
||||||
|
renderer->getCmdList().clear();
|
||||||
delete renderer;
|
delete renderer;
|
||||||
if(window)
|
}
|
||||||
|
if(window) {
|
||||||
delete window;
|
delete window;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowModule::onLoad() {
|
void WindowModule::onLoad() {
|
||||||
@@ -27,9 +31,6 @@ void WindowModule::onLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderer->getCmdList().push_back([this](){ layers->renderAll(); });
|
renderer->getCmdList().push_back([this](){ layers->renderAll(); });
|
||||||
|
|
||||||
data["window"] = window->getWindowImpl().getWindow();
|
|
||||||
data["renderCmdList"] = &renderer->getCmdList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowModule::run() {
|
void WindowModule::run() {
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestImgui::~TestImgui() {
|
TestImgui::~TestImgui() {
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestImgui::onLoad() {
|
void TestImgui::onLoad() {
|
||||||
@@ -86,9 +84,7 @@ void TestImgui::TILayer::onAttach() {
|
|||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
// Setup Platform/Renderer backends
|
||||||
GLFWwindow* w = wm->getWindow()->getWindowImpl().getWindow();
|
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
|
||||||
|
|
||||||
if(!ImGui_ImplGlfw_InitForOpenGL(w, true))
|
|
||||||
std::cout << "GLFWImpl failed\n";
|
std::cout << "GLFWImpl failed\n";
|
||||||
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
||||||
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
||||||
@@ -107,6 +103,9 @@ void TestImgui::TILayer::onRender() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TestImgui::TILayer::onDetach() {
|
void TestImgui::TILayer::onDetach() {
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestImgui::TILayer::onEvent(const Archimedes::Event&) { return false; }
|
bool TestImgui::TILayer::onEvent(const Archimedes::Event&) { return false; }
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class TestImgui : public Archimedes::GuiModule {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool demo = true;
|
bool demo = true;
|
||||||
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
|
|
||||||
|
|
||||||
Archimedes::Window* window;
|
Archimedes::Window* window;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user