Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderingEndPoint #1147

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/include/mmcore/MegaMolGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class MegaMolGraph {

bool SetGraphEntryPoint(std::string moduleName);

bool AddGraphEntryPoint(std::string moduleName);

bool RemoveGraphEntryPoint(std::string moduleName);

bool AddFrontendResources(std::vector<megamol::frontend::FrontendResource> const& resources);
Expand Down
4 changes: 4 additions & 0 deletions core/src/MegaMolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ std::vector<megamol::core::param::ParamSlot*> megamol::core::MegaMolGraph::ListP
}

bool megamol::core::MegaMolGraph::SetGraphEntryPoint(std::string module) {
return AddGraphEntryPoint(module);
}

bool megamol::core::MegaMolGraph::AddGraphEntryPoint(std::string module) {
auto moduleName = clean(module);
// currently, we expect the entry point to be derived from AbstractViewInterface
auto module_it = find_module(moduleName);
Expand Down
10 changes: 9 additions & 1 deletion frontend/resources/include/ImagePresentationEntryPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "EntryPoint.h"
#include "FrontendResource.h"
#include "ImagePresentationSink.h"

#include <any>
#include <functional>
Expand All @@ -28,14 +29,21 @@ using EntryPointRenderFunctions = std::tuple<
// the ImagePresentation Service manages the entry points - things that are held and "get rendered" by the frontend
// using the ImagePresentationEntryPoints resource participants (services) may add/remove entry points to the image presentation
struct ImagePresentationEntryPoints {
static std::string const GLFW_Sink_Name;
std::function<bool(std::string const&, EntryPointRenderFunctions const&)> add_entry_point;
std::function<bool(std::string const&, const int)> set_entry_point_priority;
std::function<bool(std::string const&)> remove_entry_point;
std::function<bool(std::string const&, std::string const&)> rename_entry_point;
std::function<void()> clear_entry_points;

std::function<bool(ImagePresentationSink const&)> add_sink;
std::function<bool(std::string const&)> remove_sink;

std::function<bool(std::string const&, std::string const&)> bind_sink_entry_point;
std::function<bool(std::string const&, std::string const&)> unbind_sink_entry_point;

// services may also subscribe to entry point changes to get notified when entry points get added/removed
enum class SubscriptionEvent { Add, Remove, Rename, Clear };
enum class SubscriptionEvent { Add, Remove, Rename, Clear, AddSink, RemoveSink, BindSink, UnbindSink };

using SubscriberFunction =
std::function<void(frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent const&,
Expand Down
4 changes: 4 additions & 0 deletions frontend/resources/src/ImagePresentationEntryPoints.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "ImagePresentationEntryPoints.h"

std::string const megamol::frontend_resources::ImagePresentationEntryPoints::GLFW_Sink_Name =
std::string("GLFW Window Presentation Sink");
96 changes: 67 additions & 29 deletions frontend/services/gui/src/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
#include "widgets/CorporateWhiteStyle.h"
#include "widgets/DefaultStyle.h"
#include "windows/HotkeyEditor.h"
#include "windows/ParameterList.h"
#include "windows/PerformanceMonitor.h"
#include "windows/RenderingEndPoint.h"


using namespace megamol::gui;


#define LOGCONSOLE_NAME "LogConsole"
#define HOTKEYEDITOR_NAME "HotkeyEditor"
#define CONFIGURATOR_NAME "Configurator"
#define TRANSFERFUNCTIONEDITOR_NAME "TransferFunctionEditor"
#define PARAMLIST_NAME "ParameterList"
#define PERFORMANCEMONITOR_NAME "PerformanceMonitor"


GUIManager::GUIManager()
: gui_hotkeys()
, imgui_context(nullptr)
Expand Down Expand Up @@ -51,6 +61,26 @@ GUIManager::GUIManager()
this->gui_hotkeys[HOTKEY_GUI_SHOW_HIDE_GUI] = {"_hotkey_gui_show-hide",
megamol::core::view::KeyCode(megamol::core::view::Key::KEY_G, core::view::Modifier::CTRL), false};

win_collection2.RegisterWindowType<TransferFunctionEditor>();
win_collection2.AddWindow<TransferFunctionEditor>(TRANSFERFUNCTIONEDITOR_NAME, true);
win_collection2.RegisterWindowType<PerformanceMonitor>();
win_collection2.AddWindow<PerformanceMonitor>(PERFORMANCEMONITOR_NAME);
win_collection2.RegisterWindowType<HotkeyEditor>();
win_collection2.AddWindow<HotkeyEditor>(HOTKEYEDITOR_NAME);
win_collection2.RegisterWindowType<LogConsole>();
win_collection2.AddWindow<LogConsole>(LOGCONSOLE_NAME);
win_collection2.RegisterWindowType<Configurator>();
win_collection2.AddWindow<Configurator>(
CONFIGURATOR_NAME, win_collection2.GetWindow<TransferFunctionEditor>(TRANSFERFUNCTIONEDITOR_NAME));
win_collection2.RegisterWindowType<ParameterList>();
ParameterList::RequestParamWindowCallback_t add_param_list_func = [&](std::string const& name, ImGuiID id) {
win_collection2.AddWindow<ParameterList>(name, id, win_collection2.GetWindow<Configurator>(CONFIGURATOR_NAME),
win_collection2.GetWindow<TransferFunctionEditor>(TRANSFERFUNCTIONEDITOR_NAME), add_param_list_func);
};
win_collection2.AddWindow<ParameterList>(PARAMLIST_NAME, GUI_INVALID_ID,
win_collection2.GetWindow<Configurator>(CONFIGURATOR_NAME),
win_collection2.GetWindow<TransferFunctionEditor>(TRANSFERFUNCTIONEDITOR_NAME), add_param_list_func);

this->win_configurator_ptr = this->win_collection.GetWindow<Configurator>();
assert(this->win_configurator_ptr != nullptr);

Expand Down Expand Up @@ -226,13 +256,13 @@ bool GUIManager::PreDraw(glm::vec2 framebuffer_size, glm::vec2 window_size, doub
}

// Propagate window specific data
if (auto win_perfmon_ptr = this->win_collection.GetWindow<PerformanceMonitor>()) {
if (auto win_perfmon_ptr = this->win_collection2.GetWindow<PerformanceMonitor>(PERFORMANCEMONITOR_NAME)) {
win_perfmon_ptr->SetData(
this->gui_state.stat_averaged_fps, this->gui_state.stat_averaged_ms, this->gui_state.stat_frame_count);
}

// Update windows
this->win_collection.Update();
this->win_collection2.Update();

// Delete window
if (this->gui_state.win_delete_hash_id != 0) {
Expand Down Expand Up @@ -311,7 +341,7 @@ bool GUIManager::PostDraw() {
this->picking_buffer.EnableInteraction(glm::vec2(io.DisplaySize.x, io.DisplaySize.y));

graph_ptr->DrawGlobalParameterWidgets(
this->picking_buffer, this->win_collection.GetWindow<TransferFunctionEditor>());
this->picking_buffer, this->win_collection2.GetWindow<TransferFunctionEditor>(TRANSFERFUNCTIONEDITOR_NAME));

this->picking_buffer.DisableInteraction();
}
Expand Down Expand Up @@ -549,12 +579,12 @@ void megamol::gui::GUIManager::SetScale(float scale) {
}
}
// Scale all windows
const auto size_func = [&](AbstractWindow& wc) {
const auto size_func = [&](AbstractWindow2& wc) {
wc.Config().reset_size *= megamol::gui::gui_scaling.TransitionFactor();
wc.Config().size *= megamol::gui::gui_scaling.TransitionFactor();
wc.Config().reset_pos_size = true;
};
this->win_collection.EnumWindows(size_func);
this->win_collection2.EnumWindows(size_func);
}


Expand Down Expand Up @@ -834,30 +864,33 @@ void GUIManager::draw_menu() {
if (ImGui::BeginMenu("Windows")) {
ImGui::MenuItem(
"Menu", this->gui_hotkeys[HOTKEY_GUI_MENU].keycode.ToString().c_str(), &this->gui_state.menu_visible);
const auto func = [&](AbstractWindow& wc) {
bool registered_window = (wc.Config().hotkey.key != core::view::Key::KEY_UNKNOWN);
if (registered_window) {
ImGui::MenuItem(wc.Name().c_str(), wc.Config().hotkey.ToString().c_str(), &wc.Config().show);
const auto func = [&](WindowType const& wc) {
//bool registered_window = (wc.hotkey.key != core::view::Key::KEY_UNKNOWN);
if (wc.unique) {
ImGui::MenuItem(wc.name.c_str(), wc.hotkey.ToString().c_str(), &wc.show);
} else {
// Custom unregistered parameter window
if (ImGui::BeginMenu(wc.Name().c_str())) {
std::string GUI_MENU_label = "Show";
if (wc.Config().show)
GUI_MENU_label = "Hide";
if (ImGui::MenuItem(GUI_MENU_label.c_str(), wc.Config().hotkey.ToString().c_str(), nullptr)) {
wc.Config().show = !wc.Config().show;
}
// Enable option to delete custom newly created parameter windows
if (wc.WindowID() == AbstractWindow::WINDOW_ID_PARAMETERS) {
if (ImGui::MenuItem("Delete Window")) {
this->gui_state.win_delete_hash_id = wc.Hash();
}
}
ImGui::EndMenu();
if (ImGui::MenuItem("Add", wc.hotkey.ToString().c_str(), nullptr)) {
//win_collection2.AddWindow<
}
// Custom unregistered parameter window
//if (ImGui::BeginMenu(wc.name.c_str())) {
// std::string GUI_MENU_label = "Show";
// if (wc.Config().show)
// GUI_MENU_label = "Hide";
// if (ImGui::MenuItem(GUI_MENU_label.c_str(), wc.hotkey.ToString().c_str(), nullptr)) {
// wc.Config().show = !wc.Config().show;
// }
// // Enable option to delete custom newly created parameter windows
// /*if (wc.WindowID() == AbstractWindow::WINDOW_ID_PARAMETERS) {
// if (ImGui::MenuItem("Delete Window")) {
// this->gui_state.win_delete_hash_id = wc.Hash();
// }
// }*/
// ImGui::EndMenu();
//}
}
};
this->win_collection.EnumWindows(func);
this->win_collection2.EnumRegisteredWindows(func);

ImGui::Separator();

Expand Down Expand Up @@ -922,8 +955,8 @@ void GUIManager::draw_menu() {
ImGui::TextDisabled("Graph Entries:");
for (auto& module_ptr : graph_ptr->Modules()) {
if (module_ptr->IsView()) {
if (ImGui::MenuItem(module_ptr->FullName().c_str(), "", module_ptr->IsGraphEntry())) {
if (!module_ptr->IsGraphEntry()) {
if (ImGui::MenuItem(module_ptr->FullName().c_str(), "", module_ptr->HasGLFWSink())) {
if (!module_ptr->HasGLFWSink()) {
graph_ptr->AddGraphEntry(module_ptr, graph_ptr->GenerateUniqueGraphEntryName());
} else {
graph_ptr->RemoveGraphEntry(module_ptr);
Expand Down Expand Up @@ -1327,7 +1360,7 @@ void megamol::gui::GUIManager::load_preset_window_docking(ImGuiID global_docking
break;
}
};
this->win_collection.EnumWindows(func);
this->win_collection.EnumCreatedWindows(func);

ImGui::DockBuilderFinish(global_docking_id);
#endif
Expand Down Expand Up @@ -1547,7 +1580,7 @@ std::string GUIManager::extract_fontname(const std::string& imgui_fontname) cons
void GUIManager::RegisterHotkeys(
megamol::core::view::CommandRegistry& cmdregistry, megamol::core::MegaMolGraph& megamolgraph) {

if (auto win_hkeditor_ptr = this->win_collection.GetWindow<HotkeyEditor>()) {
if (auto win_hkeditor_ptr = this->win_collection2.GetWindow<HotkeyEditor>(HOTKEYEDITOR_NAME)) {
win_hkeditor_ptr->RegisterHotkeys(&cmdregistry, &megamolgraph, &this->win_collection, &this->gui_hotkeys);
}
}
Expand All @@ -1557,3 +1590,8 @@ void megamol::gui::GUIManager::setRequestedResources(
std::shared_ptr<frontend_resources::FrontendResourcesMap> const& resources) {
win_collection.setRequestedResources(resources);
}


void megamol::gui::GUIManager::digestChangedRequestedResources() {
win_collection.digestChangedRequestedResources();
}
15 changes: 13 additions & 2 deletions frontend/services/gui/src/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "windows/LogConsole.h"
#include "windows/WindowCollection.h"

#include "windows/WindowCollection2.h"


namespace megamol {
namespace gui {
Expand Down Expand Up @@ -177,6 +179,11 @@ class GUIManager {
return this->render_backend.GetImage();
}


std::vector<megamol::frontend_resources::ImagePresentationEntryPoints::SubscriberFunction> GetSubscribers() {
return std::vector<megamol::frontend_resources::ImagePresentationEntryPoints::SubscriberFunction>();
}

///////// SET ///////////

/**
Expand Down Expand Up @@ -252,7 +259,7 @@ class GUIManager {
void RegisterHotkeys(megamol::core::view::CommandRegistry& cmdregistry, megamol::core::MegaMolGraph& megamol_graph);

void SetLuaFunc(megamol::frontend_resources::common_types::lua_func_type* lua_func) {
auto cons = win_collection.GetWindow<LogConsole>();
auto cons = win_collection2.GetWindow<LogConsole>("LogConsole");
if (cons) {
cons->SetLuaFunc(lua_func);
}
Expand Down Expand Up @@ -318,6 +325,8 @@ class GUIManager {

void setRequestedResources(std::shared_ptr<frontend_resources::FrontendResourcesMap> const& resources);

void digestChangedRequestedResources();

///////////////////////////////////////////////////////////////////////

private:
Expand Down Expand Up @@ -388,7 +397,9 @@ class GUIManager {
StateBuffer gui_state;

/** GUI element collections. */
WindowCollection win_collection;
// WindowCollection win_collection;

WindowCollection2 win_collection2;

/** Resource requests from the GUI windows. */
std::vector<std::string> requested_resources;
Expand Down
7 changes: 7 additions & 0 deletions frontend/services/gui/src/GUI_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void GUI_Service::digestChangedRequestedResources() {
this->setShutdown(this->m_gui->GetTriggeredShutdown());

// Check for updates in requested resources --------------------------------
m_gui->digestChangedRequestedResources();

/// KeyboardEvents = resource index 2
auto maybe_keyboard_events = frontend_resources->getOptional<megamol::frontend_resources::KeyboardEvents>();
Expand Down Expand Up @@ -362,6 +363,12 @@ void GUI_Service::setRequestedResources(std::vector<FrontendResource> resources)
megamol::core::utility::log::Log::DefaultLog.WriteInfo(
"GUI_Service: error adding graph entry point ... image presentation service rejected GUI Service.");
}
{
auto subs = m_gui->GetSubscribers();
for (auto const& sub : subs) {
image_presentation.subscribe_to_entry_point_changes(sub);
}
}

m_exec_lua = const_cast<megamol::frontend_resources::common_types::lua_func_type*>(
&frontend_resources->get<frontend_resources::common_types::lua_func_type>());
Expand Down
Loading