heavy refactoring
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
#include "WindowModule.h"
|
||||
|
||||
WindowModule::WindowModule(void* h, Archimedes::App* a) : Module(h, a) {
|
||||
name = "Window";
|
||||
}
|
||||
|
||||
WindowModule::~WindowModule() {
|
||||
if(window)
|
||||
delete window;
|
||||
@@ -14,11 +10,21 @@ WindowModule::~WindowModule() {
|
||||
void WindowModule::onLoad() {
|
||||
|
||||
window = new Archimedes::Window();
|
||||
renderer = new Archimedes::Renderer();
|
||||
//renderer = new Archimedes::Renderer();
|
||||
|
||||
window->setRenderer(renderer);
|
||||
//window->setRenderer(renderer);
|
||||
|
||||
renderer = window->getRenderer();
|
||||
|
||||
renderer->init();
|
||||
if(!renderer->init()) {
|
||||
std::cout << "Renderer init failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
data["window"] = window->getWindowImpl().getWindow();
|
||||
data["renderCmdList"] = &renderer->getCmdList();
|
||||
|
||||
std::cout << "WindowModule GLFWwindow*: " << std::any_cast<decltype(window->getWindowImpl().getWindow())>(data["window"]) << std::endl;
|
||||
}
|
||||
|
||||
void WindowModule::run() {
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
#ifndef WINDOWMODULE_H
|
||||
#define WINDOWMODULE_H
|
||||
|
||||
#ifdef GUIMODULE
|
||||
#undef GUIMODULE
|
||||
#include "Archimedes.h"
|
||||
#define GUIMODULE
|
||||
#else
|
||||
#include "Archimedes.h"
|
||||
#endif
|
||||
|
||||
#include "utils/Window/Window.h"
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
|
||||
class WindowModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
WindowModule(void*, Archimedes::App*);
|
||||
WindowModule(void* h, Archimedes::App* a) : Archimedes::Module(h, a) {
|
||||
name = "WindowModule";
|
||||
}
|
||||
|
||||
|
||||
~WindowModule();
|
||||
|
||||
void run();
|
||||
|
||||
void onLoad();
|
||||
|
||||
|
||||
//interface for other modules
|
||||
std::list<Archimedes::Renderer::renderCmd*>::iterator addRenderCmd(Archimedes::Renderer::renderCmd* cmd) {
|
||||
return renderer->addRenderCmd(cmd);
|
||||
}
|
||||
|
||||
void removeRenderCmd(std::list<Archimedes::Renderer::renderCmd*>::iterator cmd) {
|
||||
renderer->removeRenderCmd(cmd);
|
||||
}
|
||||
|
||||
auto getWindowImpl() { return window->getWindowImpl(); }
|
||||
|
||||
private:
|
||||
|
||||
Archimedes::Window* window;
|
||||
Archimedes::Renderer* renderer;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,14 +12,24 @@ TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a)
|
||||
}
|
||||
|
||||
TestImgui::~TestImgui() {
|
||||
windowModule->removeRenderCmd(rcmd);
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
Archimedes::Module* wm = depsInstances["WindowModule"];
|
||||
|
||||
if(!wm) {
|
||||
std::cout << "No WindowModule for TestImgui!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
@@ -27,26 +37,45 @@ void TestImgui::onLoad() {
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
|
||||
// Setup Dear ImGui style
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
std::cout << "init backends\n";
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(windowModule->getWindowImpl().getWindow(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
rcmd = windowModule->addRenderCmd([](){
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
std::cout << wm->getName() << std::endl;
|
||||
GLFWwindow* w = std::any_cast<GLFWwindow*>(wm->getData("window"));
|
||||
|
||||
/*if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
}*/
|
||||
});
|
||||
std::cout << "TestImgui GLFWwindow*: " << w << std::endl;
|
||||
|
||||
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::cout << "register renderCmd\n";
|
||||
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void TestImgui::run() {
|
||||
@@ -60,5 +89,4 @@ void TestImgui::run() {
|
||||
app->end();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "utils/Window/Window.h"
|
||||
|
||||
class TestImgui : public Archimedes::GuiModule {
|
||||
|
||||
@@ -16,9 +17,12 @@ class TestImgui : public Archimedes::GuiModule {
|
||||
|
||||
void run();
|
||||
|
||||
|
||||
private:
|
||||
bool demo = true;
|
||||
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
|
||||
|
||||
Archimedes::Window* window;
|
||||
};
|
||||
|
||||
#ifndef TESTIMGUI_STATIC
|
||||
|
||||
Reference in New Issue
Block a user