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 1 commit
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
8 changes: 8 additions & 0 deletions frontend/services/gui/src/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "widgets/DefaultStyle.h"
#include "windows/HotkeyEditor.h"
#include "windows/PerformanceMonitor.h"
#include "windows/RenderingEndPoint.h"


using namespace megamol::gui;
Expand Down Expand Up @@ -54,6 +55,8 @@ GUIManager::GUIManager()
this->win_configurator_ptr = this->win_collection.GetWindow<Configurator>();
assert(this->win_configurator_ptr != nullptr);

requested_resources = win_collection.requested_lifetime_resources();

this->init_state();
}

Expand Down Expand Up @@ -1541,3 +1544,8 @@ void GUIManager::RegisterHotkeys(
win_hkeditor_ptr->RegisterHotkeys(&cmdregistry, &megamolgraph, &this->win_collection, &this->gui_hotkeys);
}
}


void megamol::gui::GUIManager::setRequestedResources(std::vector<frontend::FrontendResource> resources) {
win_collection.setRequestedResources(resources);
}
15 changes: 15 additions & 0 deletions frontend/services/gui/src/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "windows/Configurator.h"
#include "windows/LogConsole.h"
#include "windows/WindowCollection.h"
#include "FrontendResource.h"


namespace megamol {
Expand Down Expand Up @@ -176,6 +177,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 @@ -305,6 +311,12 @@ class GUIManager {
return this->win_configurator_ptr->GetGraphCollection().NotifyRunningGraph_DisableEntryPoint(module_inst);
}

std::vector<std::string> requested_lifetime_resources() const {
return requested_resources;
}

void setRequestedResources(std::vector<frontend::FrontendResource> resources);

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

private:
Expand Down Expand Up @@ -377,6 +389,9 @@ class GUIManager {
/** GUI element collections. */
WindowCollection win_collection;

std::vector<std::string> requested_resources;
std::vector<frontend::FrontendResource> requested_ResourceReferences;

struct PopUpData {
std::weak_ptr<bool> open_flag;
std::function<void()> draw_callback;
Expand Down
14 changes: 14 additions & 0 deletions frontend/services/gui/src/GUI_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ bool GUI_Service::init(const Config& config) {
};

this->m_gui = std::make_shared<megamol::gui::GUIManager>();
auto gui_resources = m_gui->requested_lifetime_resources();
m_requestedResourcesNames.insert(m_requestedResourcesNames.end(), gui_resources.begin(), gui_resources.end());

// Set function pointer in state resource once
this->m_providedStateResource.request_gui_state = [&](bool as_lua) -> std::string {
Expand Down Expand Up @@ -371,6 +373,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*>(
&m_requestedResourceReferences[14].getResource<frontend_resources::common_types::lua_func_type>());
Expand Down Expand Up @@ -419,6 +427,8 @@ void GUI_Service::setRequestedResources(std::vector<FrontendResource> resources)

megamolgraph_subscription.subscribe(gui_subscription);

auto gui_win_it = m_requestedResourceReferences.begin() + 17;

#ifdef MEGAMOL_USE_PROFILING
// PerformanceManager
perf_manager = const_cast<megamol::frontend_resources::PerformanceManager*>(
Expand All @@ -427,7 +437,11 @@ void GUI_Service::setRequestedResources(std::vector<FrontendResource> resources)
m_gui->SetPerformanceManager(perf_manager);
perf_manager->subscribe_to_updates(
[&](const frontend_resources::PerformanceManager::frame_info& fi) { m_gui->AppendPerformanceData(fi); });
gui_win_it = m_requestedResourceReferences.begin() + 18;
#endif

// now come the resources for the gui windows
m_gui->setRequestedResources({gui_win_it, m_requestedResourceReferences.end()});
}


Expand Down
11 changes: 10 additions & 1 deletion frontend/services/gui/src/windows/AbstractWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <string>
#include <vector>

#include "FrontendResource.h"


namespace megamol {
namespace gui {
Expand All @@ -39,7 +41,8 @@ class AbstractWindow {
WINDOW_ID_HOTKEYEDITOR = 4,
WINDOW_ID_TRANSFER_FUNCTION = 5,
WINDOW_ID_CONFIGURATOR = 6,
WINDOW_ID_LOGCONSOLE = 7
WINDOW_ID_LOGCONSOLE = 7,
WINDOW_IF_RENDERING_ENDPOINT = 8
};

struct BasicConfig {
Expand All @@ -56,6 +59,12 @@ class AbstractWindow {

typedef std::function<void(AbstractWindow::BasicConfig&)> VolatileDrawCallback_t;

virtual std::vector<std::string> requested_lifetime_resources() const {
return std::vector<std::string>();
}

virtual void setRequestedResources(std::vector<frontend::FrontendResource> resources){};

AbstractWindow(const std::string& name, WindowConfigID window_id)
: win_config()
, win_hotkeys()
Expand Down
64 changes: 64 additions & 0 deletions frontend/services/gui/src/windows/RenderingEndPoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "RenderingEndPoint.h"


megamol::gui::RenderingEndPoint::RenderingEndPoint(std::string const& window_name)
: AbstractWindow(window_name, AbstractWindow::WINDOW_IF_RENDERING_ENDPOINT) {}


void megamol::gui::RenderingEndPoint::SetTexture(GLuint texture, uint32_t x, uint32_t y) {
tex_ = reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture));
size_ = ImVec2(x, y);
}


bool megamol::gui::RenderingEndPoint::Draw() {
static const char* current_item = nullptr;
megamol::frontend::ImagePresentation_Service::EntryPointRenderFunctions entry_point;
/*if (ImGui::BeginMainMenuBar()) {


ImGui::EndMainMenuBar();
}*/

auto& img_pres_ep_resource_ptr = resources_[0].getResource<frontend_resources::ImagePresentationEntryPoints>();

bool isSelected = false;
if (ImGui::BeginCombo("Views", current_item)) {
for (auto const& item : entry_points_) {
if (ImGui::Selectable(item.first.c_str(), &isSelected)) {
current_item = item.first.c_str();
entry_point = item.second;
}
}
ImGui::EndCombo();
}

/*ImGui::Text("RenderEndPoint");
ImGui::Spacing();*/

//entry_point
if (current_item != nullptr) {
auto ep = img_pres_ep_resource_ptr.get_entry_point(current_item);
if (ep.has_value()) {
frontend_resources::EntryPoint& ep_v = ep.value();

ep_v.entry_point_data->update();

ep_v.execute(ep_v.modulePtr, ep_v.entry_point_resources, ep_v.execution_result_image);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done by the image presentation service once a framce for each registered entry point. Triggering re-rendering of a frame from inside the GUI seems a bad idea. The intended approach is to then use the ep_v.execution_result_image texture handle (either GL or CPU texture) to present the rendered texture in an ImGui window.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rendering execution result image is only available after entry point/graph execution, which introduces a recursive dependency on showing the entry point results in the GUI, which itself is rendered as an entry point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose dragging the frontend resources up until here would also be not necessary without executing the entry points?


ImGui::Image(ep_v.execution_result_image.referenced_image_handle,
ImVec2{(float)ep_v.execution_result_image.size.width, (float)ep_v.execution_result_image.size.height},
ImVec2(0, 1), ImVec2(1, 0));
//ImGui::Image(tex_, size_, ImVec2(0, 1), ImVec2(1, 0));
}
}
/*if (ImGui::Begin("RenderingEndPoint")) {
ImGui::Text("RenderEndPoint");
ImGui::Spacing();

ImGui::Image(tex_, size_, ImVec2(0, 1), ImVec2(1, 0));
}
ImGui::End();*/

return true;
}
62 changes: 62 additions & 0 deletions frontend/services/gui/src/windows/RenderingEndPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include <map>
#include <stdint.h>

#include <glad/gl.h>

#include "AbstractWindow.h"

#include "ImagePresentationEntryPoints.h"
#include "ImagePresentation_Service.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency between GUI (GUI Service) and Image Presentation Service may lead to problems. For cleaner separation of code it will be cleaner to pull the dependencies from ImagePresentation_Service.hpp into a separate header or otherwise restructure the affected code.


namespace megamol::gui {
class RenderingEndPoint : public AbstractWindow {
public:
std::vector<std::string> requested_lifetime_resources() const override {
auto res = AbstractWindow::requested_lifetime_resources();
res.push_back("ImagePresentationEntryPoints");
return res;
}

void setRequestedResources(std::vector<frontend::FrontendResource> resources) override {
resources_ = resources;
auto& img_pres_ep_resource_ptr = resources[0].getResource<frontend_resources::ImagePresentationEntryPoints>();

auto sub_func = [&](frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent const& event,
std::vector<std::any> const& args) -> void {
switch (event) {
case frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent::Add: {
entry_points_.insert(std::make_pair(std::any_cast<std::string>(args[0]),
std::any_cast<frontend::ImagePresentation_Service::EntryPointRenderFunctions>(args[1])));
} break;
case frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent::Remove: {
entry_points_.erase(std::any_cast<std::string>(args[0]));
} break;
case frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent::Rename: {
auto func = entry_points_[std::any_cast<std::string>(args[0])];
entry_points_.erase(std::any_cast<std::string>(args[0]));
entry_points_.insert(std::make_pair(std::any_cast<std::string>(args[1]), func));
} break;
case frontend_resources::ImagePresentationEntryPoints::SubscriptionEvent::Clear:
default:
break;
}
};

img_pres_ep_resource_ptr.subscribe_to_entry_point_changes(sub_func);
}

explicit RenderingEndPoint(const std::string& window_name);

void SetTexture(GLuint texture, uint32_t x, uint32_t y);

bool Draw() override;

private:
ImTextureID tex_;
ImVec2 size_;
std::map<std::string, frontend::ImagePresentation_Service::EntryPointRenderFunctions> entry_points_;
std::vector<frontend::FrontendResource> resources_;
};
} // namespace megamol::gui
27 changes: 27 additions & 0 deletions frontend/services/gui/src/windows/WindowCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ParameterList.h"
#include "PerformanceMonitor.h"
#include "TransferFunctionEditor.h"
#include "RenderingEndPoint.h"


using namespace megamol;
Expand All @@ -27,6 +28,7 @@ WindowCollection::WindowCollection() : windows() {
this->windows.emplace_back(std::make_shared<PerformanceMonitor>("Performance Metrics"));
this->windows.emplace_back(
std::make_shared<Configurator>("Configurator", this->GetWindow<TransferFunctionEditor>()));
this->windows.emplace_back(std::make_shared<RenderingEndPoint>("Rendering Endpoint"));
// Requires Configurator and TFEditor to be added before
this->add_parameter_window("Parameters", AbstractWindow::WINDOW_ID_MAIN_PARAMETERS);

Expand All @@ -35,6 +37,15 @@ WindowCollection::WindowCollection() : windows() {
[&](std::shared_ptr<AbstractWindow> const& a, std::shared_ptr<AbstractWindow> const& b) {
return (a->Config().hotkey.key > b->Config().hotkey.key);
});

// retrieve resource requests of each window class
for (auto const& win : windows) {
auto res = win->requested_lifetime_resources();
requested_resources.insert(requested_resources.end(), res.begin(), res.end());
for (auto const& r : res) {
requested_resources_map[r].push_back(win);
}
}
}


Expand Down Expand Up @@ -221,6 +232,22 @@ bool WindowCollection::DeleteWindow(size_t win_hash_id) {
}


void megamol::gui::WindowCollection::setRequestedResources(std::vector<frontend::FrontendResource> resources) {
if (resources.size() == requested_resources.size()) {
std::unordered_map<std::shared_ptr<AbstractWindow>, std::vector<frontend::FrontendResource>> res_map;
for (uint64_t i = 0; i < requested_resources.size(); ++i) {
auto ptrs = requested_resources_map[requested_resources[i]];
for (auto& ptr : ptrs) {
res_map[ptr].push_back(resources[i]);
}
}
for (auto& [ptr, res] : res_map) {
ptr->setRequestedResources(res);
}
}
}


void WindowCollection::add_parameter_window(
const std::string& window_name, AbstractWindow::WindowConfigID win_id, ImGuiID initial_module_uid) {

Expand Down
12 changes: 12 additions & 0 deletions frontend/services/gui/src/windows/WindowCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <map>
#include <string>
#include <vector>
#include "FrontendResource.h"
#include <unordered_map>


namespace megamol {
Expand Down Expand Up @@ -66,11 +68,21 @@ class WindowCollection {

bool DeleteWindow(size_t hash_id);

std::vector<std::string> requested_lifetime_resources() const {
return requested_resources;
}

void setRequestedResources(std::vector<frontend::FrontendResource> resources);

private:
// VARIABLES ------------------------------------------------------

std::vector<std::shared_ptr<AbstractWindow>> windows;

std::vector<std::string> requested_resources;

std::unordered_map<std::string, std::vector<std::shared_ptr<AbstractWindow>>> requested_resources_map;

// FUNCTIONS ------------------------------------------------------

void add_parameter_window(const std::string& window_name, AbstractWindow::WindowConfigID win_id,
Expand Down