-
Notifications
You must be signed in to change notification settings - Fork 36
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
base: master
Are you sure you want to change the base?
RenderingEndPoint #1147
Changes from 13 commits
2078a50
408844e
6395573
eac2adc
6c65508
6302e48
97fa665
3fd7031
c20d6ae
c8aa318
e86cbc8
cfb910d
9c5be3b
1c79b20
27467b9
cb5da54
4f6e420
02933ab
27992c8
84ad2d3
9d722f7
219f00a
78c587b
c4e3804
0607843
e4bf0ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "RenderingEndPoint.h" | ||
|
||
|
||
megamol::gui::RenderingEndPoint::RenderingEndPoint(std::string const& window_name) | ||
: AbstractWindow(window_name, AbstractWindow::WINDOW_ID_RENDERING_ENDPOINT) { | ||
sink_.name = window_name; | ||
sink_.present_images = std::bind(&RenderingEndPoint::PresentImageCB, this, std::placeholders::_1); | ||
} | ||
|
||
|
||
//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 = frontend_resources->get<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)) { | ||
if (current_item != nullptr) { | ||
img_pres_ep_resource_ptr.unbind_sink_entry_point(this->Name(), item.first); | ||
} | ||
current_item = item.first.c_str(); | ||
entry_point = item.second; | ||
img_pres_ep_resource_ptr.bind_sink_entry_point(this->Name(), item.first); | ||
} | ||
} | ||
ImGui::EndCombo(); | ||
} | ||
|
||
/*ImGui::Text("RenderEndPoint"); | ||
ImGui::Spacing();*/ | ||
|
||
//entry_point | ||
if (current_item != nullptr) { | ||
for (auto& image : images_) { | ||
ImGui::Image(image.referenced_image_handle, ImVec2{(float)image.size.width, (float)image.size.height}, | ||
ImVec2(0, 1), ImVec2(1, 0)); | ||
} | ||
|
||
//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);*/ | ||
|
||
// 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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <stdint.h> | ||
|
||
#include <glad/gl.h> | ||
|
||
#include "AbstractWindow.h" | ||
|
||
#include "ImagePresentationEntryPoints.h" | ||
#include "ImagePresentation_Service.hpp" | ||
|
||
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::shared_ptr<frontend_resources::FrontendResourcesMap> const& resources) override { | ||
AbstractWindow::setRequestedResources(resources); | ||
auto& img_pres_ep_resource_ptr = frontend_resources->get<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); | ||
img_pres_ep_resource_ptr.add_sink(sink_); | ||
} | ||
|
||
explicit RenderingEndPoint(const std::string& window_name); | ||
|
||
//virtual ~RenderingEndPoint() { | ||
// auto& img_pres_ep_resource_ptr = frontend_resources->get<frontend_resources::ImagePresentationEntryPoints>(); | ||
// img_pres_ep_resource_ptr.remove_sink(sink_.name); | ||
//} | ||
|
||
//void SetTexture(GLuint texture, uint32_t x, uint32_t y); | ||
|
||
bool Draw() override; | ||
|
||
void PresentImageCB(std::vector<frontend_resources::ImageWrapper> const& images) { | ||
images_ = images; | ||
} | ||
|
||
private: | ||
/*ImTextureID tex_; | ||
ImVec2 size_;*/ | ||
std::map<std::string, frontend::ImagePresentation_Service::EntryPointRenderFunctions> entry_points_; | ||
std::vector<frontend_resources::ImageWrapper> images_; | ||
frontend_resources::ImagePresentationSink sink_; | ||
}; | ||
} // namespace megamol::gui |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include <functional> | ||
#include <map> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,23 @@ bool ImagePresentation_Service::init(const Config& config) { | |
}; | ||
m_entry_points_registry_resource.get_entry_point = [&](auto const& name) { return get_entry_point(name); }; | ||
|
||
m_entry_points_registry_resource.add_sink = [&](auto const& sink) { | ||
return add_sink(sink) && tell_subscribers(ev::AddSink, {sink}); | ||
}; | ||
|
||
m_entry_points_registry_resource.remove_sink = [&](auto const& name) { | ||
return remove_sink(name) && tell_subscribers(ev::RemoveSink, {name}); | ||
}; | ||
|
||
m_entry_points_registry_resource.bind_sink_entry_point = [&](std::string const& sink_name, | ||
std::string const& ep_name) { | ||
return bind_sink_to_ep(sink_name, ep_name) && tell_subscribers(ev::BindSink, {sink_name, ep_name}); | ||
}; | ||
m_entry_points_registry_resource.unbind_sink_entry_point = [&](std::string const& sink_name, | ||
std::string const& ep_name) { | ||
return unbind_sink_to_ep(sink_name, ep_name) && tell_subscribers(ev::UnbindSink, {sink_name, ep_name}); | ||
}; | ||
|
||
this->m_providedResourceReferences = { | ||
{"ImagePresentationEntryPoints", m_entry_points_registry_resource}, // used by MegaMolGraph to set entry points | ||
{"EntryPointToPNG_ScreenshotTrigger", m_entrypointToPNG_trigger}, | ||
|
@@ -203,18 +220,20 @@ void ImagePresentation_Service::PresentRenderedImages() { | |
// this way sinks can access the current fbo size as previous_state | ||
m_global_framebuffer_events.clear(); | ||
|
||
// pull result images into separate list | ||
static std::vector<ImageWrapper> wrapped_images; | ||
wrapped_images.clear(); | ||
wrapped_images.reserve(m_entry_points.size()); | ||
// pull result images into separate lists | ||
std::unordered_map<std::string, std::vector<ImageWrapper>> sink_img_map; | ||
sink_img_map.reserve(m_presentation_sinks.size()); | ||
|
||
// rendering results are presented in order of execution of entry points | ||
for (auto& entry : m_entry_points) { | ||
wrapped_images.push_back(entry.execution_result_image); | ||
auto const& sink_list = ep_sink_map[entry.moduleName]; | ||
for (auto const& sink : sink_list) { | ||
sink_img_map[sink].push_back(entry.execution_result_image); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about the details but it might lead to many GL texture / Byte texture copy operations when putting |
||
} | ||
} | ||
|
||
for (auto& sink : m_presentation_sinks) { | ||
sink.present_images(wrapped_images); | ||
sink.present_images(sink_img_map[sink.name]); | ||
} | ||
} | ||
|
||
|
@@ -331,6 +350,8 @@ bool ImagePresentation_Service::add_entry_point(std::string const& name, EntryPo | |
// ensure sorting of entry points according to priorities | ||
set_entry_point_priority(name, 0); | ||
|
||
bind_sink_to_ep("GLFW Window Presentation Sink", name); | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -352,6 +373,8 @@ bool ImagePresentation_Service::set_entry_point_priority(std::string const& name | |
|
||
bool ImagePresentation_Service::remove_entry_point(std::string const& name) { | ||
|
||
ep_sink_map.erase(name); | ||
|
||
m_entry_points.remove_if([&](auto& entry) { return entry.moduleName == name; }); | ||
|
||
return true; | ||
|
@@ -368,12 +391,47 @@ bool ImagePresentation_Service::rename_entry_point(std::string const& oldName, s | |
|
||
entry_it->moduleName = newName; | ||
|
||
auto l = ep_sink_map[oldName]; | ||
ep_sink_map.erase(oldName); | ||
ep_sink_map[newName] = l; | ||
|
||
return true; | ||
} | ||
|
||
bool ImagePresentation_Service::clear_entry_points() { | ||
m_entry_points.clear(); | ||
|
||
ep_sink_map.clear(); | ||
|
||
return true; | ||
} | ||
|
||
bool ImagePresentation_Service::add_sink(ImagePresentationSink const& sink) { | ||
m_presentation_sinks.push_back(sink); | ||
return true; | ||
} | ||
|
||
bool ImagePresentation_Service::remove_sink(std::string const& name) { | ||
m_presentation_sinks.remove_if([&name](auto const& entry) { return entry.name == name; }); | ||
for (auto& [key, list] : ep_sink_map) { | ||
list.remove(name); | ||
} | ||
return true; | ||
} | ||
|
||
bool ImagePresentation_Service::bind_sink_to_ep(std::string const& sink_name, std::string const& ep_name) { | ||
auto& sink_list = ep_sink_map[ep_name]; | ||
if (std::find(sink_list.begin(), sink_list.end(), sink_name) == sink_list.end()) { | ||
sink_list.push_back(sink_name); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool ImagePresentation_Service::unbind_sink_to_ep(std::string const& sink_name, std::string const& ep_name) { | ||
auto& sink_list = ep_sink_map[ep_name]; | ||
sink_list.remove(sink_name); | ||
|
||
return true; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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.