work on layers
This commit is contained in:
@@ -13,17 +13,43 @@ ImguiModule::ImguiModule(void* h, Archimedes::App* a) : Archimedes::GuiModule(h,
|
||||
|
||||
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() {
|
||||
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) {
|
||||
std::cout << "No WindowModule for ImguiModule!\n";
|
||||
@@ -44,57 +70,41 @@ void ImguiModule::onLoad() {
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
GLFWwindow* w = std::any_cast<GLFWwindow*>(wm->getData("window"));
|
||||
|
||||
if(!ImGui_ImplGlfw_InitForOpenGL(w, true))
|
||||
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), 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();
|
||||
}
|
||||
|
||||
void ImguiModule::run() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
|
||||
{
|
||||
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();
|
||||
}
|
||||
ImGui::Render();
|
||||
}
|
||||
|
||||
void ImguiModule::IGLayer::onRender() {
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -19,9 +19,29 @@ class ImguiModule : public Archimedes::GuiModule {
|
||||
|
||||
|
||||
private:
|
||||
std::list<Archimedes::Renderer::renderCmd*>::iterator rcmd;
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user