mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
refactor render tasks (added name())
add opengl renderer imgui tools to menu bar
This commit is contained in:
parent
7e1137732b
commit
e3ae6c1521
@ -27,6 +27,18 @@ if(EMSCRIPTEN)
|
||||
set_target_properties(opengl_renderer_s PROPERTIES LINK_FLAGS "-s USE_SDL=2")
|
||||
endif()
|
||||
|
||||
############# imgui opengl renderer tools ###########
|
||||
|
||||
add_library(imgui_opengl_renderer_tools
|
||||
src/mm/services/opengl_renderer_tools.hpp
|
||||
src/mm/services/opengl_renderer_tools.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(imgui_opengl_renderer_tools
|
||||
opengl_renderer_s
|
||||
imgui_service
|
||||
)
|
||||
|
||||
############# imgui render task ###########
|
||||
|
||||
add_library(imgui_render_task
|
||||
|
@ -22,6 +22,8 @@ namespace MM::OpenGL {
|
||||
public:
|
||||
virtual ~RenderTask(void) = default;
|
||||
|
||||
virtual const char* name(void) = 0;//{ return "NoName"; };
|
||||
|
||||
virtual void render(Services::OpenGLRenderer& rs, Engine& engine) = 0;
|
||||
|
||||
// a place to reload/compile shaders etc.
|
||||
|
@ -42,6 +42,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
BatchedSpriteSheet(Engine& engine);
|
||||
~BatchedSpriteSheet(void);
|
||||
|
||||
const char* name(void) override { return "BatchedSpriteSheet"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -11,6 +11,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
BlitFB(Engine& engine);
|
||||
~BlitFB(void);
|
||||
|
||||
const char* name(void) override { return "BlitFB"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -26,6 +26,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
Blur(Engine& engine);
|
||||
~Blur(void);
|
||||
|
||||
const char* name(void) override { return "Blur"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -9,6 +9,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
Clear(Engine& engine);
|
||||
~Clear(void);
|
||||
|
||||
const char* name(void) override { return "Clear"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -22,6 +22,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
CopyToFB(Engine& engine);
|
||||
~CopyToFB(void);
|
||||
|
||||
const char* name(void) override { return "CopyToFB"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -33,6 +33,8 @@ namespace MM::OpenGL {
|
||||
FastSky(MM::Engine& engine);
|
||||
~FastSky(void);
|
||||
|
||||
const char* name(void) override { return "FastSky"; }
|
||||
|
||||
void render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -11,6 +11,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
ImGuiRT(Engine& engine);
|
||||
~ImGuiRT(void);
|
||||
|
||||
const char* name(void) override { return "ImGuiRT"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
};
|
||||
|
||||
|
@ -31,6 +31,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
SimpleRect(Engine& engine);
|
||||
~SimpleRect(void);
|
||||
|
||||
const char* name(void) override { return "SimpleRect"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -31,6 +31,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
SimpleSprite(Engine& engine);
|
||||
~SimpleSprite(void);
|
||||
|
||||
const char* name(void) override { return "SimpleSprite"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -31,6 +31,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
SimpleSpriteSheet(Engine& engine);
|
||||
~SimpleSpriteSheet(void);
|
||||
|
||||
const char* name(void) override { return "SimpleSpriteSheet"; }
|
||||
|
||||
void render(Services::OpenGLRenderer& rs, Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -25,6 +25,8 @@ namespace MM::OpenGL::RenderTasks {
|
||||
Tilemap(MM::Engine& engine);
|
||||
~Tilemap(void);
|
||||
|
||||
const char* name(void) override { return "Tilemap"; }
|
||||
|
||||
void render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) override;
|
||||
|
||||
public:
|
||||
|
@ -0,0 +1,97 @@
|
||||
#include "./opengl_renderer_tools.hpp"
|
||||
|
||||
#include <mm/services/opengl_renderer.hpp>
|
||||
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <mm/imgui/widgets/texture_resource_manager.hpp>
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
bool ImGuiOpenGLRendererTools::enable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["OpenGL"]["RenderTasks"] = [this](Engine&) {
|
||||
ImGui::MenuItem("Render Tasks", NULL, &_show_render_tasks);
|
||||
};
|
||||
|
||||
menu_bar.menu_tree["OpenGL"]["TextureCacheLegacy"] = [this](Engine&) {
|
||||
ImGui::MenuItem("Texture Cache (legacy)", NULL, &_show_texture_cache_legacy);
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGuiOpenGLRendererTools::disable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["OpenGL"].erase("RenderTasks");
|
||||
menu_bar.menu_tree["OpenGL"].erase("TextureCacheLegacy");
|
||||
}
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiOpenGLRendererTools::registerUpdates(void) {
|
||||
using namespace entt::literals;
|
||||
return {
|
||||
{
|
||||
"ImGuiOpenGLRendererTools::render"_hs,
|
||||
"ImGuiOpenGLRendererTools::render",
|
||||
[this](Engine& e) { renderImGui(e); },
|
||||
UpdateStrategies::update_phase_t::MAIN,
|
||||
true,
|
||||
{
|
||||
"ImGuiMenuBar::render"_hs
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ImGuiOpenGLRendererTools::renderImGui(Engine& engine) {
|
||||
if (_show_render_tasks) {
|
||||
renderRenderTasks(engine);
|
||||
}
|
||||
|
||||
if (_show_texture_cache_legacy) {
|
||||
renderTextureCacheLegacy(engine);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiOpenGLRendererTools::renderRenderTasks(Engine& engine) {
|
||||
if (ImGui::Begin("RenderTasks##OpenGLRendererTools", &_show_render_tasks)) {
|
||||
auto& ogl_renderer = engine.getService<MM::Services::OpenGLRenderer>();
|
||||
|
||||
if (ImGui::BeginTable("table", 1)) {
|
||||
for (const auto& task : ogl_renderer.render_tasks) {
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", task->name());
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ImGuiOpenGLRendererTools::renderTextureCacheLegacy(Engine& engine) {
|
||||
if (ImGui::Begin("TextureCache (legacy)##OpenGLRendererTools", &_show_texture_cache_legacy)) {
|
||||
if (ImGui::BeginTabBar("tabs")) {
|
||||
if (ImGui::BeginTabItem("Texture List")) {
|
||||
ImGuiWidgets::TextureResourceManagerList();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Texture Loader")) {
|
||||
ImGuiWidgets::TextureResourceManagerLoader(engine);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // MM::Services
|
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <mm/services/imgui_menu_bar.hpp>
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
class ImGuiOpenGLRendererTools : public Service {
|
||||
public:
|
||||
const char* name(void) override { return "ImGuiOpenGLRendererTools"; }
|
||||
|
||||
bool enable(Engine& engine) override;
|
||||
void disable(Engine& engine) override;
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
|
||||
|
||||
private:
|
||||
bool _show_render_tasks = false;
|
||||
bool _show_texture_cache_legacy = false;
|
||||
|
||||
private:
|
||||
void renderImGui(Engine& engine);
|
||||
|
||||
void renderRenderTasks(Engine& engine);
|
||||
void renderTextureCacheLegacy(Engine& engine);
|
||||
};
|
||||
|
||||
} // namespace MM::Services
|
||||
|
Loading…
Reference in New Issue
Block a user