layers are redundant
This commit is contained in:
@@ -6,13 +6,16 @@
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
ImguiModule::ImguiModule(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a) {
|
||||
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::GuiModule(a, h) {
|
||||
|
||||
name = "ImguiModule";
|
||||
}
|
||||
|
||||
ImguiModule::~ImguiModule() {
|
||||
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void ImguiModule::onLoad() {
|
||||
@@ -22,40 +25,7 @@ void ImguiModule::onLoad() {
|
||||
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) {
|
||||
std::cout << "No WindowModule for ImguiModule!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
@@ -77,34 +47,38 @@ void ImguiModule::IGLayer::onAttach() {
|
||||
}
|
||||
|
||||
|
||||
wm->getRenderer()->getCmdList().push_back([](){
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
});
|
||||
|
||||
//Compute first frame ahead of first WindowModule->run()
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
}
|
||||
|
||||
void ImguiModule::IGLayer::onRender() {
|
||||
ImGui::Render();
|
||||
void ImguiModule::run() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
static float f = 0.0f;
|
||||
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_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
bool ImguiModule::IGLayer::onEvent(const Archimedes::Event& e) { return false; }
|
||||
|
||||
void ImguiModule::IGLayer::onDetach() {
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -9,39 +9,20 @@
|
||||
class ImguiModule : public Archimedes::GuiModule {
|
||||
|
||||
public:
|
||||
ImguiModule(void*, Archimedes::App*);
|
||||
ImguiModule(Archimedes::App*, void*);
|
||||
|
||||
~ImguiModule();
|
||||
|
||||
void onLoad();
|
||||
|
||||
bool onEvent(const Archimedes::Event& e) { return false; }
|
||||
|
||||
void run();
|
||||
|
||||
|
||||
private:
|
||||
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
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "WindowModule.h"
|
||||
|
||||
WindowModule::~WindowModule() {
|
||||
if(layers) {
|
||||
delete layers;
|
||||
}
|
||||
if(renderer) {
|
||||
renderer->getCmdList().clear();
|
||||
delete renderer;
|
||||
@@ -23,14 +20,10 @@ void WindowModule::onLoad() {
|
||||
|
||||
//renderer = window->getRenderer();
|
||||
|
||||
layers = new Archimedes::Layerstack();
|
||||
|
||||
if(!renderer->init()) {
|
||||
std::cout << "Renderer init failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
renderer->getCmdList().push_back([this](){ layers->renderAll(); });
|
||||
}
|
||||
|
||||
void WindowModule::run() {
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
|
||||
#include "utils/Window/Window.h"
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
#include "utils/Layers/Layerstack.h"
|
||||
|
||||
class WindowModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
WindowModule(void* h, Archimedes::App* a) : Archimedes::Module(h, a) {
|
||||
WindowModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
||||
name = "WindowModule";
|
||||
}
|
||||
|
||||
@@ -31,13 +30,11 @@ class WindowModule : public Archimedes::Module {
|
||||
|
||||
Archimedes::Window* getWindow() { return window; }
|
||||
Archimedes::Renderer* getRenderer() { return renderer; }
|
||||
Archimedes::Layerstack* getLayerstack() { return layers; }
|
||||
|
||||
private:
|
||||
|
||||
Archimedes::Window* window;
|
||||
Archimedes::Renderer* renderer;
|
||||
Archimedes::Layerstack* layers;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user