diff --git a/src/appleseed.studio/CMakeLists.txt b/src/appleseed.studio/CMakeLists.txt index 11cebbd8d7..6073da93eb 100644 --- a/src/appleseed.studio/CMakeLists.txt +++ b/src/appleseed.studio/CMakeLists.txt @@ -250,12 +250,12 @@ set (mainwindow_rendering_sources mainwindow/rendering/cameracontroller.h mainwindow/rendering/glscenelayer.h mainwindow/rendering/glscenelayer.cpp - # mainwindow/rendering/lightpathspickinghandler.cpp - # mainwindow/rendering/lightpathspickinghandler.h - # mainwindow/rendering/lightpathsviewportmanager.cpp - # mainwindow/rendering/lightpathsviewportmanager.h - # mainwindow/rendering/lightpathslayer.cpp - # mainwindow/rendering/lightpathslayer.h + mainwindow/rendering/lightpathspickinghandler.cpp + mainwindow/rendering/lightpathspickinghandler.h + mainwindow/rendering/lightpathsviewportmanager.cpp + mainwindow/rendering/lightpathsviewportmanager.h + mainwindow/rendering/lightpathslayer.cpp + mainwindow/rendering/lightpathslayer.h mainwindow/rendering/materialdrophandler.cpp mainwindow/rendering/materialdrophandler.h mainwindow/rendering/pixelcolortracker.cpp @@ -271,12 +271,12 @@ set (mainwindow_rendering_sources mainwindow/rendering/renderingmanager.cpp mainwindow/rendering/renderingmanager.h mainwindow/rendering/renderingtimer.h - mainwindow/rendering/renderregionhandler.cpp - mainwindow/rendering/renderregionhandler.h mainwindow/rendering/renderlayer.cpp mainwindow/rendering/renderlayer.h mainwindow/rendering/scenepickinghandler.cpp mainwindow/rendering/scenepickinghandler.h + mainwindow/rendering/viewportregionselectionhandler.cpp + mainwindow/rendering/viewportregionselectionhandler.h mainwindow/rendering/viewporttab.cpp mainwindow/rendering/viewporttab.h mainwindow/rendering/viewportwidget.h diff --git a/src/appleseed.studio/mainwindow/mainwindow.cpp b/src/appleseed.studio/mainwindow/mainwindow.cpp index c3363e702d..d6980c6c5f 100644 --- a/src/appleseed.studio/mainwindow/mainwindow.cpp +++ b/src/appleseed.studio/mainwindow/mainwindow.cpp @@ -742,17 +742,17 @@ void MainWindow::update_workspace() update_pause_resume_checkbox(false); m_ui->attribute_editor_scrollarea_contents->setEnabled(true); - // Add/remove light paths tab. + // Enable/disable light paths if (m_project_manager.is_project_open() && m_project_manager.get_project()->get_light_path_recorder().get_light_path_count() > 0) { for (const_each i = m_viewport_tabs; i; ++i) - i->second->enable_light_paths_toggle(); + i->second->set_light_paths_enabled(true); } else { for (const_each i = m_viewport_tabs; i; ++i) - i->second->disable_light_paths_toggle(); + i->second->set_light_paths_enabled(false); } } @@ -894,7 +894,7 @@ void MainWindow::set_rendering_widgets_enabled(const bool is_enabled, const Rend // Rendering -> Render Settings. m_ui->action_rendering_rendering_settings->setEnabled(allow_start); - // Render tab buttons. + // Viewport tab buttons. const int current_tab_index = m_ui->tab_render_channels->currentIndex(); if (current_tab_index != -1) { @@ -982,7 +982,8 @@ void MainWindow::add_viewport_tab(const QString& label) *m_project_explorer, *m_project_manager.get_project(), m_rendering_manager, - m_ocio_config); + m_ocio_config, + m_application_settings); // Connect the render tab to the main window and the rendering manager. connect( @@ -1218,8 +1219,7 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode) // Darken render widgets. for (const_each i = m_viewport_tabs; i; ++i) { - i->second->get_viewport_widget()->get_render_layer()->darken(); - i->second->update(); + i->second->render_began(); } // Retrieve the appropriate rendering configuration. diff --git a/src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp b/src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp index c1d3f89d3b..58ab4e115b 100644 --- a/src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp +++ b/src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp @@ -458,7 +458,7 @@ namespace { } } -void GLSceneLayer::initialize(QSurfaceFormat format) +void GLSceneLayer::init_gl(QSurfaceFormat format) { // If there was already previous data, clean up GLSceneLayer::cleanup_gl_data(); @@ -511,11 +511,6 @@ void GLSceneLayer::initialize(QSurfaceFormat format) m_initialized = true; } -bool GLSceneLayer::is_initialized() -{ - return m_initialized; -} - void GLSceneLayer::cleanup_gl_data() { if (!m_scene_object_vaos.empty()) diff --git a/src/appleseed.studio/mainwindow/rendering/glscenelayer.h b/src/appleseed.studio/mainwindow/rendering/glscenelayer.h index c3cdbcf2a7..6345a7a067 100644 --- a/src/appleseed.studio/mainwindow/rendering/glscenelayer.h +++ b/src/appleseed.studio/mainwindow/rendering/glscenelayer.h @@ -79,17 +79,15 @@ class GLSceneLayer const size_t width, const size_t height); + void init_gl( + QSurfaceFormat format); + void set_transform( const foundation::Transformd& transform); void set_gl_functions( QOpenGLFunctions_3_3_Core* functions); - void initialize( - QSurfaceFormat format); - - bool is_initialized(); - void draw(); void draw_depth_only(); diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp b/src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp index e6fe60571a..afafce1605 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp +++ b/src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp @@ -142,11 +142,17 @@ void LightPathsLayer::set_gl_functions(QOpenGLFunctions_3_3_Core* functions) m_gl = functions; } +void LightPathsLayer::update_render_camera_transform() +{ + const float time = m_camera.get_shutter_middle_time(); + m_render_camera_matrix = m_camera.transform_sequence().evaluate(time).get_parent_to_local(); + m_gl_render_view_matrix = transpose(m_render_camera_matrix); +} + void LightPathsLayer::set_transform(const Transformd& transform) { m_camera_matrix = transform.get_parent_to_local(); m_gl_view_matrix = transpose(m_camera_matrix); - m_camera_position = Vector3f(m_camera_matrix.extract_translation()); } void LightPathsLayer::set_light_paths(const LightPathArray& light_paths) @@ -365,23 +371,18 @@ void LightPathsLayer::init_gl(QSurfaceFormat format) // If there was already previous data, clean up LightPathsLayer::cleanup_gl_data(); - bool manual_srgb_conversion = false; - if (format.colorSpace() != QSurfaceFormat::sRGBColorSpace) - { - manual_srgb_conversion = true; - RENDERER_LOG_WARNING( - "opengl: srgb framebuffer extensions not supported, using slower manual conversion."); - } - glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + auto vertex_shader = load_gl_shader("lightpaths.vert"); + auto fragment_shader = load_gl_shader("lightpaths.frag"); + create_shader_program( m_gl, m_light_paths_shader_program, - load_gl_shader("lightpaths.vert"), - load_gl_shader("lightpaths.frag")); + vertex_shader, + fragment_shader); m_light_paths_view_mat_location = m_gl->glGetUniformLocation(m_light_paths_shader_program, "u_view"); m_light_paths_proj_mat_location = m_gl->glGetUniformLocation(m_light_paths_shader_program, "u_proj"); @@ -447,23 +448,40 @@ void LightPathsLayer::cleanup_gl_data() } } -void LightPathsLayer::draw() +void LightPathsLayer::draw_render_camera() const +{ + auto gl_view_matrix = const_cast(&m_gl_render_view_matrix[0]); + render_scene(gl_view_matrix); +} + +void LightPathsLayer::draw() const +{ + auto gl_view_matrix = const_cast(&m_gl_view_matrix[0]); + render_scene(gl_view_matrix); +} + +void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const { if (!m_gl_initialized) return; if (m_backface_culling_enabled) - glEnable(GL_CULL_FACE); - else glDisable(GL_CULL_FACE); + m_gl->glEnable(GL_CULL_FACE); + else m_gl->glDisable(GL_CULL_FACE); + + m_gl->glDepthMask(GL_TRUE); + m_gl->glEnable(GL_DEPTH_TEST); + m_gl->glDepthFunc(GL_LEQUAL); if (m_light_paths_index_offsets.size() > 1) { m_gl->glUseProgram(m_light_paths_shader_program); + m_gl->glUniformMatrix4fv( m_light_paths_view_mat_location, 1, false, - const_cast(&m_gl_view_matrix[0])); + gl_view_matrix); m_gl->glUniformMatrix4fv( m_light_paths_proj_mat_location, 1, diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathslayer.h b/src/appleseed.studio/mainwindow/rendering/lightpathslayer.h index 9c611dbe53..62ce3e00ce 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathslayer.h +++ b/src/appleseed.studio/mainwindow/rendering/lightpathslayer.h @@ -67,7 +67,7 @@ namespace studio { // A widget providing an hardware-accelerated visualization of recorded light paths. // -class LightPathsLayer +class LightPathsLayer: public QObject { Q_OBJECT @@ -77,6 +77,9 @@ class LightPathsLayer const size_t width, const size_t height); + + void update_render_camera_transform(); + void set_transform( const foundation::Transformd& transform); @@ -91,7 +94,9 @@ class LightPathsLayer void init_gl(QSurfaceFormat format); - void draw(); + void draw() const; + + void draw_render_camera() const; signals: void signal_light_path_selection_changed( @@ -109,7 +114,7 @@ class LightPathsLayer const renderer::Project& m_project; renderer::Camera& m_camera; foundation::Matrix4d m_camera_matrix; - foundation::Vector3f m_camera_position; + foundation::Matrix4d m_render_camera_matrix; bool m_backface_culling_enabled; @@ -124,6 +129,7 @@ class LightPathsLayer GLuint m_light_paths_shader_program; GLint m_light_paths_view_mat_location; GLint m_light_paths_proj_mat_location; + foundation::Matrix4f m_gl_render_view_matrix; foundation::Matrix4f m_gl_view_matrix; foundation::Matrix4f m_gl_proj_matrix; bool m_gl_initialized; @@ -131,6 +137,8 @@ class LightPathsLayer void cleanup_gl_data(); void load_light_paths_data(); + void render_scene(const GLfloat* gl_view_matrix) const; + void dump_selected_light_path() const; }; diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.cpp b/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.cpp index 4e9715a312..3f8e1cf8bd 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.cpp +++ b/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.cpp @@ -30,7 +30,8 @@ #include "lightpathspickinghandler.h" // appleseed.studio headers. -#include "mainwindow/rendering/lightpathswidget.h" +#include "mainwindow/rendering/lightpathslayer.h" +#include "mainwindow/rendering/viewportwidget.h" #include "utility/mousecoordinatestracker.h" // appleseed.renderer headers. @@ -57,20 +58,13 @@ namespace appleseed { namespace studio { LightPathsPickingHandler::LightPathsPickingHandler( - LightPathsLayer* light_paths_widget, + ViewportWidget* viewport_widget, const MouseCoordinatesTracker& mouse_tracker, const Project& project) - : m_light_paths_widget(light_paths_widget) - , m_mouse_tracker(mouse_tracker) - , m_project(project) + : m_project(project) , m_enabled(true) + , m_viewport_widget(viewport_widget) { - m_light_paths_widget->installEventFilter(this); -} - -LightPathsPickingHandler::~LightPathsPickingHandler() -{ - m_light_paths_widget->removeEventFilter(this); } void LightPathsPickingHandler::set_enabled(const bool enabled) @@ -108,8 +102,8 @@ void LightPathsPickingHandler::pick(const Vector2i& pixel) const pixel.y); } - m_light_paths_widget->set_light_paths(light_paths); - m_light_paths_widget->update(); + m_viewport_widget->get_light_paths_layer()->set_light_paths(light_paths); + m_viewport_widget->update(); } } @@ -156,31 +150,10 @@ void LightPathsPickingHandler::pick(const AABB2i& rect) const final_rect.max.y); } - m_light_paths_widget->set_light_paths(light_paths); - m_light_paths_widget->update(); + m_viewport_widget->get_light_paths_layer()->set_light_paths(light_paths); + m_viewport_widget->update(); } } -bool LightPathsPickingHandler::eventFilter(QObject* object, QEvent* event) -{ - if (m_enabled) - { - if (event->type() == QEvent::MouseButtonPress) - { - const QMouseEvent* mouse_event = static_cast(event); - if (!(mouse_event->modifiers() & (Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier))) - { - if (mouse_event->button() == Qt::LeftButton) - { - pick(m_mouse_tracker.widget_to_pixel(mouse_event->pos())); - return true; - } - } - } - } - - return QObject::eventFilter(object, event); -} - } // namespace studio } // namespace appleseed diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.h b/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.h index 215780c8a9..736c7eac29 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.h +++ b/src/appleseed.studio/mainwindow/rendering/lightpathspickinghandler.h @@ -38,6 +38,7 @@ // Forward declarations. namespace appleseed { namespace studio { class LightPathsLayer; } } namespace appleseed { namespace studio { class MouseCoordinatesTracker; } } +namespace appleseed { namespace studio { class ViewportWidget; } } namespace renderer { class Project; } class QEvent; @@ -51,24 +52,19 @@ class LightPathsPickingHandler public: LightPathsPickingHandler( - LightPathsLayer* light_paths_widget, + ViewportWidget* viewport_widget, const MouseCoordinatesTracker& mouse_tracker, const renderer::Project& project); - ~LightPathsPickingHandler() override; - void set_enabled(const bool enabled); void pick(const foundation::Vector2i& pixel) const; void pick(const foundation::AABB2i& rect) const; private: - LightPathsLayer* m_light_paths_widget; - const MouseCoordinatesTracker& m_mouse_tracker; + ViewportWidget* m_viewport_widget; const renderer::Project& m_project; bool m_enabled; - - bool eventFilter(QObject* object, QEvent* event) override; }; } // namespace studio diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.cpp b/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.cpp index 9fbf91a653..ab67077b70 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.cpp +++ b/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.cpp @@ -32,6 +32,8 @@ // appleseed.studio headers. #include "mainwindow/rendering/lightpathspickinghandler.h" #include "mainwindow/rendering/lightpathslayer.h" +#include "mainwindow/rendering/viewporttab.h" +#include "mainwindow/rendering/viewportwidget.h" #include "utility/miscellaneous.h" #include "utility/settingskeys.h" @@ -73,18 +75,45 @@ namespace studio { // LightPathsViewportManager class implementation. // -LightPathsViewportManager::LightPathsViewportManager(Project& project, ParamArray& settings) - : m_project(project) +LightPathsViewportManager::LightPathsViewportManager( + ViewportTab* viewport_tab, + Project& project, + ParamArray& settings) + : m_enabled(false) + , m_project(project) , m_settings(settings) + , m_viewport_tab(viewport_tab) { - create_light_paths_widget(); + LightPathsLayer* light_paths_layer = m_viewport_tab->get_viewport_widget()->get_light_paths_layer(); + connect( + light_paths_layer, SIGNAL(signal_light_path_selection_changed(const int, const int)), + SLOT(slot_light_path_selection_changed)); + create_toolbar(); recreate_handlers(); } +void LightPathsViewportManager::set_enabled(const bool enabled) +{ + m_enabled = enabled; + if (enabled) + m_toolbar->show(); + else + m_toolbar->hide(); + m_toolbar->setDisabled(!enabled); + m_screen_space_paths_picking_handler->set_enabled(enabled); +} + +QToolBar* LightPathsViewportManager::toolbar() const +{ + return m_toolbar; +} + void LightPathsViewportManager::slot_entity_picked(const ScenePicker::PickingResult& result) { + if (!m_enabled) return; + const CanvasProperties& props = m_project.get_frame()->image().properties(); m_screen_space_paths_picking_handler->pick( @@ -93,8 +122,15 @@ void LightPathsViewportManager::slot_entity_picked(const ScenePicker::PickingRes result.m_ndc[1] * static_cast(props.m_canvas_height))); } +void LightPathsViewportManager::slot_light_paths_display_toggled(const bool active) +{ + set_enabled(active); +} + void LightPathsViewportManager::slot_rectangle_selection(const QRect& rect) { + if (!m_enabled) return; + m_screen_space_paths_picking_handler->pick( AABB2i( Vector2i(rect.x(), rect.y()), @@ -117,21 +153,11 @@ void LightPathsViewportManager::slot_light_path_selection_changed( } } -void LightPathsViewportManager::slot_context_menu(const QPoint& point) -{ - if (!(QApplication::keyboardModifiers() & Qt::ShiftModifier)) - return; - - QMenu* menu = new QMenu(this); - - menu->exec(m_light_paths_layer->mapToGlobal(point)); -} - void LightPathsViewportManager::slot_save_light_paths() { QString filepath = get_save_filename( - this, + m_viewport_tab, "Save Light Paths As...", "Light Paths Files (*.aspaths);;All Files (*.*)", m_settings, @@ -151,37 +177,26 @@ void LightPathsViewportManager::slot_save_light_paths() void LightPathsViewportManager::slot_camera_changed() { - m_light_paths_layer->set_transform(m_camera_controller->get_transform()); - m_light_paths_layer->update(); -} - -void LightPathsViewportManager::create_light_paths_widget() -{ - // Create the OpenGL widget. - const CanvasProperties& props = m_project.get_frame()->image().properties(); - m_light_paths_widget = - new LightPathsLayer( - m_project, - props.m_canvas_width, - props.m_canvas_height); - - // Enable context menu on the OpenGL widget. - m_light_paths_widget->setContextMenuPolicy(Qt::CustomContextMenu); - connect( - m_light_paths_widget, SIGNAL(signal_light_path_selection_changed(const int, const int)), - SLOT(slot_light_path_selection_changed(const int, const int))); - connect( - m_light_paths_widget, SIGNAL(customContextMenuRequested(const QPoint&)), - SLOT(slot_context_menu(const QPoint&))); + if (!m_enabled) return; } void LightPathsViewportManager::create_toolbar() { + LightPathsLayer* light_paths_layer = m_viewport_tab->get_viewport_widget()->get_light_paths_layer(); + // Create the render toolbar. m_toolbar = new QToolBar(); m_toolbar->setObjectName("render_toolbar"); m_toolbar->setIconSize(QSize(18, 18)); + //// Pick paths button + //QToolButton* m_pick_paths_button = new QToolButton(); + //m_pick_paths_button->setText("Pick Light Paths"); + //m_pick_paths_button->setToolTip("Pick Light Paths"); + //connect( + // m_pick_paths_button, SIGNAL(clicked()), + // SIGNAL(slot_light_paths_pick_button_clicked)); + // Save Light Paths button. QToolButton* save_light_paths_button = new QToolButton(); save_light_paths_button->setIcon(load_icons("lightpathstab_save_light_paths")); @@ -204,7 +219,7 @@ void LightPathsViewportManager::create_toolbar() m_prev_path_button->setEnabled(false); connect( m_prev_path_button, SIGNAL(clicked()), - m_light_paths_widget, SLOT(slot_display_previous_light_path())); + light_paths_layer, SLOT(slot_display_previous_light_path())); m_toolbar->addWidget(m_prev_path_button); // Next Light Path button. @@ -214,7 +229,7 @@ void LightPathsViewportManager::create_toolbar() m_next_path_button->setEnabled(false); connect( m_next_path_button, SIGNAL(clicked()), - m_light_paths_widget, SLOT(slot_display_next_light_path())); + light_paths_layer, SLOT(slot_display_next_light_path())); m_toolbar->addWidget(m_next_path_button); m_toolbar->addSeparator(); @@ -226,8 +241,8 @@ void LightPathsViewportManager::create_toolbar() backface_culling_button->setCheckable(true); backface_culling_button->setChecked(false); connect( - backface_culling_button, SIGNAL(toggled(bool)), - m_light_paths_widget, SLOT(slot_toggle_backface_culling(const bool))); + backface_culling_button, SIGNAL(toggled()), + light_paths_layer, SLOT(slot_toggle_backface_culling())); m_toolbar->addWidget(backface_culling_button); // Synchronize Camera button. @@ -236,7 +251,7 @@ void LightPathsViewportManager::create_toolbar() sync_camera_button->setToolTip("Synchronize the rendering camera with this camera"); connect( sync_camera_button, SIGNAL(clicked()), - m_light_paths_widget, SLOT(slot_synchronize_camera())); + light_paths_layer, SLOT(slot_synchronize_camera())); m_toolbar->addWidget(sync_camera_button); // Add stretchy spacer. @@ -249,48 +264,17 @@ void LightPathsViewportManager::create_toolbar() m_info_label = new QLabel(); m_info_label->setObjectName("info_label"); m_toolbar->addWidget(m_info_label); -} -void LightPathsViewportManager::create_scrollarea() -{ - // Encapsulate the OpenGL widget into another widget that adds a margin around it. - QWidget* gl_widget_wrapper = new QWidget(); - gl_widget_wrapper->setObjectName("render_widget_wrapper"); - gl_widget_wrapper->setLayout(new QGridLayout()); - gl_widget_wrapper->layout()->setSizeConstraint(QLayout::SetFixedSize); - gl_widget_wrapper->layout()->setContentsMargins(20, 20, 20, 20); - gl_widget_wrapper->layout()->addWidget(m_light_paths_widget); - - // Wrap the OpenGL widget in a scroll area. - m_scroll_area = new QScrollArea(); - m_scroll_area->setObjectName(QString::fromUtf8("render_widget_scrollarea")); - m_scroll_area->setAlignment(Qt::AlignCenter); - m_scroll_area->setWidget(gl_widget_wrapper); + m_toolbar->setDisabled(true); + m_toolbar->hide(); } void LightPathsViewportManager::recreate_handlers() { - // Handler for zooming the render widget in and out with the keyboard or the mouse wheel. - m_zoom_handler.reset( - new WidgetZoomHandler( - m_scroll_area, - m_light_paths_widget)); - - // Handler for panning the render widget with the mouse. - m_pan_handler.reset( - new ScrollAreaPanHandler( - m_scroll_area)); - - // Handler for tracking and displaying mouse coordinates. - m_mouse_tracker.reset( - new MouseCoordinatesTracker( - m_light_paths_widget, - m_info_label)); - // The screen-space paths picking handler is used to pick paths from the render widget. m_screen_space_paths_picking_handler.reset( new LightPathsPickingHandler( - m_light_paths_widget, + m_viewport_tab->get_viewport_widget(), *m_mouse_tracker.get(), m_project)); m_screen_space_paths_picking_handler->set_enabled(false); @@ -304,21 +288,10 @@ void LightPathsViewportManager::recreate_handlers() // m_project)); // Camera handler. - m_light_paths_widget->setMouseTracking(true); - m_camera_controller.reset( - new CameraController( - m_light_paths_widget, - m_project, - m_project.get_uncached_active_camera())); - connect( - m_camera_controller.get(), SIGNAL(signal_camera_changed()), - SLOT(slot_camera_changed())); - - // Clipboard handler. - m_clipboard_handler.reset(new RenderClipboardHandler(m_light_paths_widget, m_light_paths_widget)); + m_viewport_tab->get_viewport_widget()->setMouseTracking(true); } } // namespace studio } // namespace appleseed -#include "mainwindow/rendering/moc_cpp_lightpathstab.cxx" +//#include "mainwindow/rendering/moc_cpp_lightpathsviewportmanager.cxx" diff --git a/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.h b/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.h index d3f1452529..692b989760 100644 --- a/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.h +++ b/src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.h @@ -47,7 +47,7 @@ #include // Forward declarations. -namespace appleseed { namespace studio { class LightPathsLayer; } } +namespace appleseed { namespace studio { class ViewportTab; } } namespace renderer { class ParamArray; } namespace renderer { class Project; } class QLabel; @@ -71,42 +71,44 @@ class LightPathsViewportManager public: LightPathsViewportManager( + ViewportTab* viewport_tab, renderer::Project& project, renderer::ParamArray& settings); + QToolBar* toolbar() const; + + void set_enabled(const bool enabled); + public slots: void slot_entity_picked(const renderer::ScenePicker::PickingResult& result); void slot_rectangle_selection(const QRect& rect); + void slot_light_paths_display_toggled(const bool active); private slots: void slot_light_path_selection_changed( const int selected_light_path_index, const int total_light_paths) const; - void slot_context_menu(const QPoint& point); void slot_save_light_paths(); void slot_camera_changed(); private: + bool m_enabled; + renderer::Project& m_project; renderer::ParamArray& m_settings; - LightPathsLayer* m_light_paths_layer; - QScrollArea* m_scroll_area; + ViewportTab* m_viewport_tab; QToolBar* m_toolbar; + //QToolButton* m_pick_paths_button; QToolButton* m_prev_path_button; QToolButton* m_next_path_button; QLabel* m_info_label; - std::unique_ptr m_zoom_handler; std::unique_ptr m_pan_handler; std::unique_ptr m_mouse_tracker; - std::unique_ptr m_camera_controller; std::unique_ptr m_screen_space_paths_picking_handler; std::unique_ptr m_world_space_paths_picking_handler; - std::unique_ptr m_clipboard_handler; - void create_light_paths_widget(); void create_toolbar(); - void create_scrollarea(); void recreate_handlers(); }; diff --git a/src/appleseed.studio/mainwindow/rendering/renderingmanager.cpp b/src/appleseed.studio/mainwindow/rendering/renderingmanager.cpp index a92e7e2b34..97c0b40165 100644 --- a/src/appleseed.studio/mainwindow/rendering/renderingmanager.cpp +++ b/src/appleseed.studio/mainwindow/rendering/renderingmanager.cpp @@ -192,6 +192,11 @@ RenderingManager::~RenderingManager() clear_sticky_actions(); } +RenderingManager::RenderingMode RenderingManager::get_rendering_mode() const +{ + return m_rendering_mode; +} + void RenderingManager::start_rendering( Project* project, const ParamArray& params, diff --git a/src/appleseed.studio/mainwindow/rendering/renderingmanager.h b/src/appleseed.studio/mainwindow/rendering/renderingmanager.h index 9dfa7038a7..13032d7c7c 100644 --- a/src/appleseed.studio/mainwindow/rendering/renderingmanager.h +++ b/src/appleseed.studio/mainwindow/rendering/renderingmanager.h @@ -90,6 +90,9 @@ class RenderingManager const RenderingMode rendering_mode, ViewportTab* viewport_tab); + // Get current rendering mode + RenderingMode get_rendering_mode() const; + // Return true if currently rendering, false otherwise. bool is_rendering() const; diff --git a/src/appleseed.studio/mainwindow/rendering/renderregionhandler.cpp b/src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.cpp similarity index 91% rename from src/appleseed.studio/mainwindow/rendering/renderregionhandler.cpp rename to src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.cpp index f014235fbc..6750d8eeee 100644 --- a/src/appleseed.studio/mainwindow/rendering/renderregionhandler.cpp +++ b/src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.cpp @@ -28,7 +28,7 @@ // // Interface header. -#include "renderregionhandler.h" +#include "viewportregionselectionhandler.h" // appleseed.studio headers. #include "utility/mousecoordinatestracker.h" @@ -54,7 +54,7 @@ using namespace std; namespace appleseed { namespace studio { -RenderRegionHandler::RenderRegionHandler( +ViewportRegionSelectionHandler::ViewportRegionSelectionHandler( QWidget* widget, const MouseCoordinatesTracker& mouse_tracker) : m_widget(widget) @@ -66,22 +66,22 @@ RenderRegionHandler::RenderRegionHandler( m_widget->installEventFilter(this); } -RenderRegionHandler::~RenderRegionHandler() +ViewportRegionSelectionHandler::~ViewportRegionSelectionHandler() { m_widget->removeEventFilter(this); } -void RenderRegionHandler::set_enabled(const bool enabled) +void ViewportRegionSelectionHandler::set_enabled(const bool enabled) { m_enabled = enabled; } -void RenderRegionHandler::set_mode(const Mode mode) +void ViewportRegionSelectionHandler::set_mode(const Mode mode) { m_mode = mode; } -bool RenderRegionHandler::eventFilter(QObject* object, QEvent* event) +bool ViewportRegionSelectionHandler::eventFilter(QObject* object, QEvent* event) { if (m_enabled) { diff --git a/src/appleseed.studio/mainwindow/rendering/renderregionhandler.h b/src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.h similarity index 95% rename from src/appleseed.studio/mainwindow/rendering/renderregionhandler.h rename to src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.h index 2ad7f77a1e..574a7517a9 100644 --- a/src/appleseed.studio/mainwindow/rendering/renderregionhandler.h +++ b/src/appleseed.studio/mainwindow/rendering/viewportregionselectionhandler.h @@ -43,18 +43,18 @@ class QWidget; namespace appleseed { namespace studio { -class RenderRegionHandler +class ViewportRegionSelectionHandler : public QObject { Q_OBJECT public: // Default mode is RectangleSelectionMode. - RenderRegionHandler( + ViewportRegionSelectionHandler( QWidget* widget, const MouseCoordinatesTracker& mouse_tracker); - ~RenderRegionHandler() override; + ~ViewportRegionSelectionHandler() override; void set_enabled(const bool enabled); diff --git a/src/appleseed.studio/mainwindow/rendering/viewporttab.cpp b/src/appleseed.studio/mainwindow/rendering/viewporttab.cpp index 2017f441d6..37ff7f796c 100644 --- a/src/appleseed.studio/mainwindow/rendering/viewporttab.cpp +++ b/src/appleseed.studio/mainwindow/rendering/viewporttab.cpp @@ -32,6 +32,8 @@ // appleseed.studio headers. #include "mainwindow/project/projectexplorer.h" +#include "mainwindow/rendering/lightpathsviewportmanager.h" +#include "mainwindow/rendering/renderingmanager.h" #include "mainwindow/rendering/viewportwidget.h" #include "utility/miscellaneous.h" @@ -77,8 +79,10 @@ ViewportTab::ViewportTab( ProjectExplorer& project_explorer, Project& project, RenderingManager& rendering_manager, - OCIO::ConstConfigRcPtr ocio_config) - : m_project_explorer(project_explorer) + OCIO::ConstConfigRcPtr ocio_config, + renderer::ParamArray application_settings) + : m_application_settings(application_settings) + , m_project_explorer(project_explorer) , m_project(project) , m_rendering_manager(rendering_manager) , m_ocio_config(ocio_config) @@ -89,21 +93,17 @@ ViewportTab::ViewportTab( layout()->setMargin(0); create_viewport_widget(); + create_light_paths_manager(m_application_settings); create_toolbar(); create_scrollarea(); layout()->addWidget(m_toolbar); + layout()->addWidget(m_light_paths_manager->toolbar()); layout()->addWidget(m_scroll_area); recreate_handlers(); } -void ViewportTab::enable_light_paths_toggle() -{} - -void ViewportTab::disable_light_paths_toggle() -{} - ViewportWidget* ViewportTab::get_viewport_widget() const { return m_viewport_widget; @@ -130,6 +130,14 @@ void ViewportTab::set_render_region_buttons_enabled(const bool enabled) m_clear_render_region_button->setEnabled(enabled); } +void ViewportTab::render_began() +{ + get_viewport_widget()->get_render_layer()->darken(); + get_viewport_widget()->get_light_paths_layer()->update_render_camera_transform(); + set_light_paths_enabled(false); + update(); +} + void ViewportTab::reset_zoom() { m_zoom_handler->reset_zoom(); @@ -168,18 +176,48 @@ void ViewportTab::load_state(const State& state) m_pan_handler->load_state(state.m_pan_handler_state); } -void ViewportTab::slot_viewport_widget_context_menu(const QPoint& point) +void ViewportTab::set_light_paths_enabled(const bool enabled) { - emit signal_viewport_widget_context_menu(m_viewport_widget->mapToGlobal(point)); + m_light_paths_toggle_button->setDisabled(!enabled); + m_light_paths_manager->set_enabled(enabled); +} + +void ViewportTab::slot_base_layer_changed(int index) +{ + assert(index < ViewportWidget::BaseLayer::BASE_LAYER_MAX_VALUE); + auto base_layer = static_cast(index); + + switch (base_layer) + { + case ViewportWidget::BaseLayer::FinalRender: + if (m_rendering_manager.is_rendering() + && m_rendering_manager.get_rendering_mode() == RenderingManager::RenderingMode::InteractiveRendering) + m_camera_controller.get()->set_enabled(true); + else + m_camera_controller.get()->set_enabled(false); + break; + + case ViewportWidget::BaseLayer::OpenGL: + m_camera_controller.get()->set_enabled(true); + break; + } +} + +void ViewportTab::slot_camera_changed() +{ + + m_viewport_widget->get_light_paths_layer()->set_transform(get_camera_controller()->get_transform()); + m_viewport_widget->get_gl_scene_layer()->set_transform(get_camera_controller()->get_transform()); + update(); } void ViewportTab::slot_toggle_render_region(const bool checked) { m_scene_picking_handler->set_enabled(!checked); - m_render_region_handler->set_mode( + m_viewport_selection_handler->set_mode( checked - ? RenderRegionHandler::RenderRegionMode - : RenderRegionHandler::RectangleSelectionMode); + ? ViewportRegionSelectionHandler::RenderRegionMode + : ViewportRegionSelectionHandler::RectangleSelectionMode); } void ViewportTab::slot_set_render_region(const QRect& rect) @@ -194,6 +232,11 @@ void ViewportTab::slot_toggle_pixel_inspector(const bool checked) m_pixel_inspector_handler->update_tooltip_visibility(); } +void ViewportTab::slot_viewport_widget_context_menu(const QPoint& point) +{ + emit signal_viewport_widget_context_menu(m_viewport_widget->mapToGlobal(point)); +} + void ViewportTab::create_viewport_widget() { const CanvasProperties& props = m_project.get_frame()->image().properties(); @@ -215,6 +258,14 @@ void ViewportTab::create_viewport_widget() m_viewport_widget->setMouseTracking(true); } +void ViewportTab::create_light_paths_manager(renderer::ParamArray application_settings) +{ + m_light_paths_manager = new LightPathsViewportManager( + this, + m_project, + application_settings); +} + void ViewportTab::create_toolbar() { // Create the render toolbar. @@ -238,6 +289,10 @@ void ViewportTab::create_toolbar() m_base_layer_combo, SIGNAL(activated(int)), m_viewport_widget, SLOT(slot_base_layer_changed(int)) ); + connect( + m_base_layer_combo, SIGNAL(activated(int)), + SLOT(slot_base_layer_changed(int)) + ); m_light_paths_toggle_button = new QToolButton(); m_light_paths_toggle_button->setText("Display Light Paths Overlay"); @@ -247,6 +302,10 @@ void ViewportTab::create_toolbar() m_light_paths_toggle_button, SIGNAL(toggled(bool)), m_viewport_widget, SLOT(slot_light_paths_toggled(bool)) ); + connect( + m_light_paths_toggle_button, SIGNAL(toggled(bool)), + m_light_paths_manager, SLOT(slot_light_paths_display_toggled(bool)) + ); m_toolbar->addSeparator(); @@ -475,6 +534,9 @@ void ViewportTab::recreate_handlers() connect( m_camera_controller.get(), SIGNAL(signal_camera_changed()), SIGNAL(signal_camera_changed())); + connect( + m_camera_controller.get(), SIGNAL(signal_camera_changed()), + SLOT(slot_camera_changed())); connect( &m_project_explorer, SIGNAL(signal_frame_modified()), m_camera_controller.get(), SLOT(slot_frame_modified())); @@ -493,17 +555,23 @@ void ViewportTab::recreate_handlers() connect( m_scene_picking_handler.get(), SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)), m_camera_controller.get(), SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult))); + connect( + m_scene_picking_handler.get(), SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)), + m_light_paths_manager, SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult))); // Handler for setting render regions with the mouse. - m_render_region_handler.reset( - new RenderRegionHandler( + m_viewport_selection_handler.reset( + new ViewportRegionSelectionHandler( m_viewport_widget, *m_mouse_tracker.get())); connect( - m_render_region_handler.get(), SIGNAL(signal_rectangle_selection(const QRect&)), + m_viewport_selection_handler.get(), SIGNAL(signal_rectangle_selection(const QRect&)), SIGNAL(signal_rectangle_selection(const QRect&))); connect( - m_render_region_handler.get(), SIGNAL(signal_render_region(const QRect&)), + m_viewport_selection_handler.get(), SIGNAL(signal_rectangle_selection(const QRect&)), + m_light_paths_manager, SLOT(slot_rectangle_selection(const QRect&))); + connect( + m_viewport_selection_handler.get(), SIGNAL(signal_render_region(const QRect&)), SLOT(slot_set_render_region(const QRect&))); // Clipboard handler. diff --git a/src/appleseed.studio/mainwindow/rendering/viewporttab.h b/src/appleseed.studio/mainwindow/rendering/viewporttab.h index 6c358d1d56..a15230904e 100644 --- a/src/appleseed.studio/mainwindow/rendering/viewporttab.h +++ b/src/appleseed.studio/mainwindow/rendering/viewporttab.h @@ -35,8 +35,8 @@ #include "mainwindow/rendering/pixelcolortracker.h" #include "mainwindow/rendering/pixelinspectorhandler.h" #include "mainwindow/rendering/renderclipboardhandler.h" -#include "mainwindow/rendering/renderregionhandler.h" #include "mainwindow/rendering/scenepickinghandler.h" +#include "mainwindow/rendering/viewportregionselectionhandler.h" #include "utility/mousecoordinatestracker.h" #include "utility/scrollareapanhandler.h" #include "utility/widgetzoomhandler.h" @@ -53,6 +53,7 @@ namespace OCIO = OCIO_NAMESPACE; #include // Forward declarations. +namespace appleseed { namespace studio { class LightPathsViewportManager; } } namespace appleseed { namespace studio { class ProjectExplorer; } } namespace appleseed { namespace studio { class ViewportWidget; } } namespace renderer { class Entity; } @@ -83,18 +84,18 @@ class ViewportTab ProjectExplorer& project_explorer, renderer::Project& project, RenderingManager& rendering_manager, - OCIO::ConstConfigRcPtr ocio_config); + OCIO::ConstConfigRcPtr ocio_config, + renderer::ParamArray application_settings); ViewportWidget* get_viewport_widget() const; CameraController* get_camera_controller() const; ScenePickingHandler* get_scene_picking_handler() const; - void enable_light_paths_toggle(); - void disable_light_paths_toggle(); - + void set_light_paths_enabled(const bool enabled); void set_clear_frame_button_enabled(const bool enabled); void set_render_region_buttons_enabled(const bool enabled); + void render_began(); void reset_zoom(); void update(); @@ -126,48 +127,54 @@ class ViewportTab void signal_rectangle_selection(const QRect& rect); private slots: - void slot_viewport_widget_context_menu(const QPoint& point); - void slot_toggle_render_region(const bool checked); + void slot_camera_changed(); + void slot_base_layer_changed(int index); void slot_set_render_region(const QRect& rect); void slot_toggle_pixel_inspector(const bool checked); + void slot_toggle_render_region(const bool checked); + void slot_viewport_widget_context_menu(const QPoint& point); private: - ViewportWidget* m_viewport_widget; - QScrollArea* m_scroll_area; - QToolBar* m_toolbar; - QToolButton* m_set_render_region_button; - QToolButton* m_clear_render_region_button; - QToolButton* m_clear_frame_button; - QToolButton* m_light_paths_toggle_button; - QComboBox* m_picking_mode_combo; - QComboBox* m_display_transform_combo; - QComboBox* m_base_layer_combo; - QLabel* m_info_label; - QLabel* m_r_label; - QLabel* m_g_label; - QLabel* m_b_label; - QLabel* m_a_label; - - ProjectExplorer& m_project_explorer; - renderer::Project& m_project; - RenderingManager& m_rendering_manager; - - std::unique_ptr m_zoom_handler; - std::unique_ptr m_pan_handler; - std::unique_ptr m_material_drop_handler; - std::unique_ptr m_mouse_tracker; - std::unique_ptr m_pixel_color_tracker; - std::unique_ptr m_pixel_inspector_handler; - std::unique_ptr m_camera_controller; - std::unique_ptr m_scene_picking_handler; - std::unique_ptr m_render_region_handler; - std::unique_ptr m_clipboard_handler; - - OCIO::ConstConfigRcPtr m_ocio_config; - - void create_viewport_widget(); - void create_toolbar(); + ViewportWidget* m_viewport_widget; + LightPathsViewportManager* m_light_paths_manager; + + QScrollArea* m_scroll_area; + QToolBar* m_toolbar; + QToolButton* m_set_render_region_button; + QToolButton* m_clear_render_region_button; + QToolButton* m_clear_frame_button; + QToolButton* m_light_paths_toggle_button; + QComboBox* m_picking_mode_combo; + QComboBox* m_display_transform_combo; + QComboBox* m_base_layer_combo; + QLabel* m_info_label; + QLabel* m_r_label; + QLabel* m_g_label; + QLabel* m_b_label; + QLabel* m_a_label; + + ProjectExplorer& m_project_explorer; + renderer::Project& m_project; + RenderingManager& m_rendering_manager; + renderer::ParamArray m_application_settings; + + std::unique_ptr m_zoom_handler; + std::unique_ptr m_pan_handler; + std::unique_ptr m_material_drop_handler; + std::unique_ptr m_mouse_tracker; + std::unique_ptr m_pixel_color_tracker; + std::unique_ptr m_pixel_inspector_handler; + std::unique_ptr m_camera_controller; + std::unique_ptr m_scene_picking_handler; + std::unique_ptr m_viewport_selection_handler; + std::unique_ptr m_clipboard_handler; + + OCIO::ConstConfigRcPtr m_ocio_config; + + void create_light_paths_manager(renderer::ParamArray application_settings); void create_scrollarea(); + void create_toolbar(); + void create_viewport_widget(); void recreate_handlers(); }; diff --git a/src/appleseed.studio/mainwindow/rendering/viewportwidget.cpp b/src/appleseed.studio/mainwindow/rendering/viewportwidget.cpp index 068ec97681..2c2797d7c5 100644 --- a/src/appleseed.studio/mainwindow/rendering/viewportwidget.cpp +++ b/src/appleseed.studio/mainwindow/rendering/viewportwidget.cpp @@ -85,7 +85,7 @@ ViewportWidget::ViewportWidget( create_render_layer(ocio_config); create_gl_scene_layer(); - //create_light_paths_layer(); + create_light_paths_layer(); resize(width, height); @@ -120,26 +120,26 @@ void ViewportWidget::create_gl_scene_layer() m_width, m_height)); } -// -//void ViewportWidget::create_light_paths_layer() -//{ -// m_light_paths_layer = -// std::unique_ptr(new LightPathsLayer( -// m_project, -// m_width, -// m_height)); -//} + +void ViewportWidget::create_light_paths_layer() +{ + m_light_paths_layer = + std::unique_ptr(new LightPathsLayer( + m_project, + m_width, + m_height)); +} RenderLayer* ViewportWidget::get_render_layer() { return m_render_layer.get(); } -//LightPathsLayer* ViewportWidget::get_light_paths_layer() -//{ -// return m_light_paths_layer.get(); -//} -// +LightPathsLayer* ViewportWidget::get_light_paths_layer() +{ + return m_light_paths_layer.get(); +} + GLSceneLayer* ViewportWidget::get_gl_scene_layer() { return m_gl_scene_layer.get(); @@ -168,8 +168,9 @@ void ViewportWidget::initializeGL() { } m_gl_scene_layer->set_gl_functions(m_gl); - //m_light_paths_layer->set_gl_functions(m_gl); - //m_light_paths_layer->init_gl(qs_format); + m_gl_scene_layer->init_gl(qs_format); + m_light_paths_layer->set_gl_functions(m_gl); + m_light_paths_layer->init_gl(qs_format); } void ViewportWidget::resize( @@ -179,11 +180,14 @@ void ViewportWidget::resize( m_render_layer->resize(width, height); } -void ViewportWidget::paintGL() +void ViewportWidget::set_draw_light_paths_enabled(const bool enabled) { - if (!m_gl_scene_layer->is_initialized()) - m_gl_scene_layer->initialize(format()); + m_draw_light_paths = enabled; + update(); +} +void ViewportWidget::paintGL() +{ if (m_active_base_layer == BaseLayer::FinalRender) { m_painter.begin(this); @@ -199,8 +203,13 @@ void ViewportWidget::paintGL() if (m_active_base_layer == BaseLayer::OpenGL) m_gl_scene_layer->draw(); - //if (m_draw_light_paths) - // m_light_paths_layer->draw(); + if (m_draw_light_paths) + { + if (m_active_base_layer == BaseLayer::FinalRender) + m_light_paths_layer->draw_render_camera(); + else + m_light_paths_layer->draw(); + } } void ViewportWidget::dragEnterEvent(QDragEnterEvent* event) @@ -238,8 +247,7 @@ void ViewportWidget::slot_base_layer_changed(int index) void ViewportWidget::slot_light_paths_toggled(bool checked) { - m_draw_light_paths = checked; - update(); + set_draw_light_paths_enabled(checked); } } // namespace studio diff --git a/src/appleseed.studio/mainwindow/rendering/viewportwidget.h b/src/appleseed.studio/mainwindow/rendering/viewportwidget.h index 8147d3ba5d..eec1ff6810 100644 --- a/src/appleseed.studio/mainwindow/rendering/viewportwidget.h +++ b/src/appleseed.studio/mainwindow/rendering/viewportwidget.h @@ -30,9 +30,10 @@ // appleseed.studio headers. #include "mainwindow/rendering/lightpathslayer.h" +#include "mainwindow/rendering/glscenelayer.h" #include "mainwindow/rendering/renderclipboardhandler.h" #include "mainwindow/rendering/renderlayer.h" -#include "mainwindow/rendering/glscenelayer.h" + // appleseed.foundation headers. #include "foundation/image/image.h" @@ -104,7 +105,9 @@ class ViewportWidget RenderLayer* get_render_layer(); GLSceneLayer* get_gl_scene_layer(); - //LightPathsLayer* get_light_paths_layer(); + LightPathsLayer* get_light_paths_layer(); + + void set_draw_light_paths_enabled(const bool enabled); signals: void signal_material_dropped( @@ -125,14 +128,14 @@ class ViewportWidget std::unique_ptr m_render_layer; std::unique_ptr m_gl_scene_layer; - //std::unique_ptr m_light_paths_layer; + std::unique_ptr m_light_paths_layer; bool m_draw_light_paths; BaseLayer m_active_base_layer; - void create_render_layer(OCIO::ConstConfigRcPtr ocio_config); + void create_light_paths_layer(); void create_gl_scene_layer(); - //void create_light_paths_layer(); + void create_render_layer(OCIO::ConstConfigRcPtr ocio_config); void initializeGL() override; void paintGL() override;