Skip to content

Commit

Permalink
split tabs into multiple files (opengl and finalrender)
Browse files Browse the repository at this point in the history
  • Loading branch information
oktomus committed Mar 19, 2020
1 parent 034440d commit cbdae0d
Show file tree
Hide file tree
Showing 39 changed files with 2,044 additions and 1,319 deletions.
5 changes: 5 additions & 0 deletions sandbox/settings/appleseed.studio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<parameter name="tile_ordering" value="spiral" />
</parameters>
<parameters name="ui">
<parameters name="file_dialog">
<parameters name="light_paths">
<parameter name="selected_filter" value="" />
</parameters>
</parameters>
<parameters name="render_region">
<parameter name="triggers_rendering" value="true" />
</parameters>
Expand Down
14 changes: 10 additions & 4 deletions src/appleseed.studio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,22 @@ source_group ("mainwindow\\pythonconsole" FILES
set (mainwindow_rendering_sources
mainwindow/rendering/cameracontroller.cpp
mainwindow/rendering/cameracontroller.h
mainwindow/rendering/finalrenderviewporttab.cpp
mainwindow/rendering/finalrenderviewporttab.h
mainwindow/rendering/glscenelayer.cpp
mainwindow/rendering/glscenelayer.h
mainwindow/rendering/lightpathslayer.cpp
mainwindow/rendering/lightpathslayer.h
mainwindow/rendering/lightpathsmanager.cpp
mainwindow/rendering/lightpathsmanager.h
mainwindow/rendering/lightpathspickinghandler.cpp
mainwindow/rendering/lightpathspickinghandler.h
mainwindow/rendering/lightpathsviewportmanager.cpp
mainwindow/rendering/lightpathsviewportmanager.h
mainwindow/rendering/lightpathsviewporttoolbar.cpp
mainwindow/rendering/lightpathsviewporttoolbar.h
mainwindow/rendering/materialdrophandler.cpp
mainwindow/rendering/materialdrophandler.h
mainwindow/rendering/openglviewporttab.cpp
mainwindow/rendering/openglviewporttab.h
mainwindow/rendering/pixelcolortracker.cpp
mainwindow/rendering/pixelcolortracker.h
mainwindow/rendering/pixelinspectorhandler.cpp
Expand All @@ -282,8 +288,8 @@ set (mainwindow_rendering_sources
mainwindow/rendering/viewportregionselectionhandler.h
mainwindow/rendering/viewporttab.cpp
mainwindow/rendering/viewporttab.h
mainwindow/rendering/viewportwidget.cpp
mainwindow/rendering/viewportwidget.h
mainwindow/rendering/viewportcanvas.cpp
mainwindow/rendering/viewportcanvas.h
)
list (APPEND appleseed.studio_sources
${mainwindow_rendering_sources}
Expand Down
185 changes: 125 additions & 60 deletions src/appleseed.studio/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
#include "mainwindow/project/attributeeditor.h"
#include "mainwindow/project/projectexplorer.h"
#include "mainwindow/pythonconsole/pythonconsolewidget.h"
#include "mainwindow/rendering/finalrenderviewporttab.h"
#include "mainwindow/rendering/lightpathsmanager.h"
#include "mainwindow/rendering/materialdrophandler.h"
#include "mainwindow/rendering/openglviewporttab.h"
#include "mainwindow/rendering/renderlayer.h"
#include "mainwindow/rendering/viewportwidget.h"
#include "mainwindow/rendering/viewportcanvas.h"
#include "utility/settingskeys.h"

// appleseed.qtcommon headers.
Expand Down Expand Up @@ -131,7 +134,6 @@ MainWindow::MainWindow(QWidget* parent)
, m_project_explorer(nullptr)
, m_attribute_editor(nullptr)
, m_project_file_watcher(nullptr)
, m_light_paths_tab(nullptr)
{
initialize_ocio();

Expand Down Expand Up @@ -728,6 +730,10 @@ void MainWindow::build_connections()
connect(
&m_rendering_manager, SIGNAL(signal_rendering_end()),
SLOT(slot_rendering_end()));

connect(
m_ui->tab_render_channels, &QTabWidget::currentChanged,
this, &MainWindow::slot_current_tab_changed);
}

void MainWindow::update_workspace()
Expand All @@ -741,14 +747,6 @@ void MainWindow::update_workspace()
set_diagnostics_widgets_enabled(true, RenderingMode::NotRendering);
update_pause_resume_checkbox(false);
m_ui->attribute_editor_scrollarea_contents->setEnabled(true);

// Enable/disable light paths
const bool enable_light_paths_toogle =
m_project_manager.is_project_open() &&
m_project_manager.get_project()->get_light_path_recorder().get_light_path_count() > 0;

for (const std::pair<std::string, ViewportTab*>& kvp : m_viewport_tabs)
kvp.second->set_light_paths_toggle_enabled(enable_light_paths_toogle);
}

void MainWindow::update_project_explorer()
Expand Down Expand Up @@ -890,23 +888,21 @@ void MainWindow::set_rendering_widgets_enabled(const bool is_enabled, const Rend
const int current_tab_index = m_ui->tab_render_channels->currentIndex();
if (current_tab_index != -1)
{
const auto viewport_tab_it = m_tab_index_to_viewport_tab.find(current_tab_index);
if (viewport_tab_it != m_tab_index_to_viewport_tab.end())
{
ViewportTab* viewport_tab = viewport_tab_it->second;
// Clear frame.
m_final_render_viewport_tab->set_clear_frame_button_enabled(
is_enabled && is_project_open && rendering_mode == RenderingMode::NotRendering);

// Clear frame.
viewport_tab->set_clear_frame_button_enabled(
is_enabled && is_project_open && rendering_mode == RenderingMode::NotRendering);
// Set/clear rendering region.
m_final_render_viewport_tab->set_render_region_buttons_enabled(
is_enabled && is_project_open && rendering_mode != RenderingMode::FinalRendering);

// Set/clear rendering region.
viewport_tab->set_render_region_buttons_enabled(
is_enabled && is_project_open && rendering_mode != RenderingMode::FinalRendering);
// Scene picker.
m_final_render_viewport_tab->get_scene_picking_handler()->set_enabled(
is_enabled && is_project_open && rendering_mode != RenderingMode::FinalRendering);

// Scene picker.
viewport_tab->get_scene_picking_handler()->set_enabled(
is_enabled && is_project_open && rendering_mode != RenderingMode::FinalRendering);
}
// Light paths overlay.
const bool enable_light_paths_overlay = is_enabled && is_project_open && rendering_mode == RenderingMode::NotRendering;
m_final_render_viewport_tab->set_light_paths_toggle_enabled(enable_light_paths_overlay);
}
}

Expand Down Expand Up @@ -952,76 +948,134 @@ void MainWindow::recreate_viewport_tabs()

if (m_project_manager.is_project_open())
{
add_viewport_tab("Beauty", ViewportWidget::BaseLayer::FinalRender);
add_viewport_tab("OpenGL", ViewportWidget::BaseLayer::OpenGL);
m_light_paths_manager.reset(
new LightPathsManager(
*m_project_manager.get_project(),
m_application_settings));

create_final_render_tab();
create_opengl_tab();

// Connect tabs together once they are all created.
connect_tabs();
}
}

void MainWindow::remove_viewport_tabs()
{
while (m_ui->tab_render_channels->count() > 0)
m_ui->tab_render_channels->removeTab(0);

for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
delete i->second;

m_viewport_tabs.clear();
m_tab_index_to_viewport_tab.clear();

while (m_ui->tab_render_channels->count() > 0)
m_ui->tab_render_channels->removeTab(0);
m_final_render_viewport_tab = 0;
m_opengl_viewport_tab = 0;
}

void MainWindow::add_viewport_tab(const QString& label, const ViewportWidget::BaseLayer base_layer)
void MainWindow::create_final_render_tab()
{
// Create render tab.
ViewportTab* viewport_tab =
new ViewportTab(
base_layer,
m_final_render_viewport_tab =
new FinalRenderViewportTab(
*m_project_explorer,
*m_project_manager.get_project(),
m_rendering_manager,
*m_light_paths_manager,
m_ocio_config,
m_application_settings);

// Connect the render tab to the main window and the rendering manager.
// Connect the beauty viewport tab to the main window and the rendering manager.
connect(
viewport_tab, SIGNAL(signal_viewport_widget_context_menu(const QPoint&)),
SLOT(slot_viewport_widget_context_menu(const QPoint&)));
connect(
viewport_tab, SIGNAL(signal_set_render_region(const QRect&)),
m_final_render_viewport_tab, SIGNAL(signal_set_render_region(const QRect&)),
SLOT(slot_set_render_region(const QRect&)));
connect(
viewport_tab, SIGNAL(signal_clear_render_region()),
m_final_render_viewport_tab, SIGNAL(signal_viewport_canvas_context_menu(const QPoint&)),
SLOT(slot_viewport_canvas_context_menu(const QPoint&)));
connect(
m_final_render_viewport_tab, SIGNAL(signal_clear_render_region()),
SLOT(slot_clear_render_region()));
connect(
viewport_tab, SIGNAL(signal_save_frame_and_aovs()),
m_final_render_viewport_tab, SIGNAL(signal_save_frame_and_aovs()),
SLOT(slot_save_frame_and_aovs()));
connect(
viewport_tab, SIGNAL(signal_quicksave_frame_and_aovs()),
m_final_render_viewport_tab, SIGNAL(signal_quicksave_frame_and_aovs()),
SLOT(slot_quicksave_frame_and_aovs()));
connect(
viewport_tab, SIGNAL(signal_reset_zoom()),
m_final_render_viewport_tab, SIGNAL(signal_reset_zoom()),
SLOT(slot_reset_zoom()));
connect(
viewport_tab, SIGNAL(signal_clear_frame()),
m_final_render_viewport_tab, SIGNAL(signal_clear_frame()),
SLOT(slot_clear_frame()));
connect(
viewport_tab, SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)),
m_final_render_viewport_tab, SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)),
SLOT(slot_clear_filter()));
connect(
viewport_tab, SIGNAL(signal_camera_change_begin()),
m_final_render_viewport_tab, SIGNAL(signal_camera_change_begin()),
&m_rendering_manager, SLOT(slot_camera_change_begin()));
connect(
viewport_tab, SIGNAL(signal_camera_change_end()),
m_final_render_viewport_tab, SIGNAL(signal_camera_change_end()),
&m_rendering_manager, SLOT(slot_camera_change_end()));
connect(
viewport_tab, SIGNAL(signal_camera_changed()),
m_final_render_viewport_tab, SIGNAL(signal_camera_changed()),
&m_rendering_manager, SLOT(slot_camera_changed()));

// Add the render tab to the tab bar.
const int tab_index = m_ui->tab_render_channels->addTab(viewport_tab, label);
m_final_render_viewport_tab_index = add_viewport_tab(m_final_render_viewport_tab, "Beauty");
}

void MainWindow::create_opengl_tab()
{
m_opengl_viewport_tab =
new OpenGLViewportTab(
*m_project_explorer,
*m_project_manager.get_project(),
m_rendering_manager,
*m_light_paths_manager,
m_ocio_config,
m_application_settings);

// Connect the opengl viewport tab to the main window and the rendering manager.
connect(
m_opengl_viewport_tab, SIGNAL(signal_viewport_canvas_context_menu(const QPoint&)),
SLOT(slot_viewport_canvas_context_menu(const QPoint&)));
connect(
m_opengl_viewport_tab, SIGNAL(signal_reset_zoom()),
SLOT(slot_reset_zoom()));

m_opengl_viewport_tab_index = add_viewport_tab(m_opengl_viewport_tab, "OpenGL");
}

int MainWindow::add_viewport_tab(ViewportTab* viewport_tab, const QString& label)
{
const int tab_index = static_cast<int>(m_viewport_tabs.size());

// Update mappings.
// Update mappings before inserting the tab.
// When inserting a tab, it may show the tab and
// trigger QTabWidget::currentChanged signal.
// We want to make sure our mappings are ready
// before running our slots.
m_viewport_tabs[label.toStdString()] = viewport_tab;
m_tab_index_to_viewport_tab[tab_index] = viewport_tab;

// Add the viewport tab to the tab bar.
const int final_tab_index = m_ui->tab_render_channels->insertTab(tab_index, viewport_tab, label);

assert(final_tab_index == tab_index);

return final_tab_index;
}

void MainWindow::connect_tabs()
{
assert(m_final_render_viewport_tab);
assert(m_opengl_viewport_tab);

// Connect final render tab light paths selection to opengl tab.
//connect(
//m_final_render_viewport_tab, &FinalRenderViewportTab::signal_entity_picked,
//m_opengl_viewport_tab, &OpenGLViewportTab::slot_entity_picked);
}

ParamArray MainWindow::get_project_params(const char* configuration_name) const
Expand Down Expand Up @@ -1193,6 +1247,9 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode)

m_false_colors_window.reset();

// Switch to the final render viewport tab.
m_ui->tab_render_channels->setCurrentIndex(m_final_render_viewport_tab_index);

// Enable/disable menus and widgets appropriately.
set_file_widgets_enabled(false, rendering_mode);
set_project_explorer_enabled(rendering_mode == RenderingMode::InteractiveRendering);
Expand All @@ -1210,6 +1267,7 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode)
Project* project = m_project_manager.get_project();
Frame* frame = project->get_frame();

project->get_light_path_recorder().clear();
frame->clear_main_and_aov_images();

// Darken render widgets.
Expand All @@ -1230,7 +1288,7 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode)
rendering_mode == RenderingMode::InteractiveRendering
? RenderingManager::RenderingMode::InteractiveRendering
: RenderingManager::RenderingMode::FinalRendering,
m_viewport_tabs["Beauty"]);
m_final_render_viewport_tab);
}

void MainWindow::apply_false_colors_settings()
Expand Down Expand Up @@ -1270,8 +1328,8 @@ void MainWindow::apply_false_colors_settings()
// Blit the regular frame into the render widget.
for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
{
i->second->get_viewport_widget()->get_render_layer()->blit_frame(*frame);
i->second->get_viewport_widget()->get_render_layer()->update();
i->second->get_viewport_canvas()->get_render_layer()->blit_frame(*frame);
i->second->get_viewport_canvas()->get_render_layer()->update();
}
}
}
Expand All @@ -1293,8 +1351,8 @@ void MainWindow::apply_post_processing_stage(
// Blit the frame copy into the render widget.
for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
{
i->second->get_viewport_widget()->get_render_layer()->blit_frame(working_frame);
i->second->get_viewport_widget()->get_render_layer()->update();
i->second->get_viewport_canvas()->get_render_layer()->blit_frame(working_frame);
i->second->get_viewport_canvas()->get_render_layer()->update();
}
}
}
Expand Down Expand Up @@ -1898,7 +1956,7 @@ void MainWindow::slot_set_render_region(const QRect& rect)
}
}

void MainWindow::slot_viewport_widget_context_menu(const QPoint& point)
void MainWindow::slot_viewport_canvas_context_menu(const QPoint& point)
{
if (!(QApplication::keyboardModifiers() & Qt::ShiftModifier))
return;
Expand Down Expand Up @@ -2038,7 +2096,7 @@ void MainWindow::slot_save_render_widget_content()
return;

// todo: this is sketchy. The render tab should be retrieved from the signal.
m_viewport_tabs["Beauty"]->get_viewport_widget()->get_render_layer()->capture().save(filepath);
m_viewport_tabs["Beauty"]->get_viewport_canvas()->get_render_layer()->capture().save(filepath);

RENDERER_LOG_INFO("wrote image file %s.", filepath.toStdString().c_str());
}
Expand All @@ -2051,9 +2109,7 @@ void MainWindow::slot_clear_frame()
// Clear all render widgets to black.
for (const std::pair<std::string, ViewportTab*>& kvp : m_viewport_tabs)
{
const auto viewport_widget = kvp.second->get_viewport_widget();
viewport_widget->get_render_layer()->clear();
viewport_widget->repaint();
kvp.second->clear();
}
}

Expand Down Expand Up @@ -2116,6 +2172,15 @@ void MainWindow::slot_check_fullscreen()
m_action_fullscreen->setChecked(is_fullscreen);
}

void MainWindow::slot_current_tab_changed(int index)
{
if (index == -1) return;

ViewportTab* tab = m_tab_index_to_viewport_tab[index];

tab->on_tab_selected();
}

void MainWindow::slot_show_application_settings_window()
{
if (m_application_settings_window.get() == nullptr)
Expand Down
Loading

0 comments on commit cbdae0d

Please sign in to comment.