diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 3c35560..be91887 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -51,7 +51,7 @@ void FrameBuffer::init() glBindFramebuffer(GL_FRAMEBUFFER, framebufferid_); // take settings into account: no multisampling for level 0 - use_multi_sampling_ &= Settings::application.render_multisampling > 0; + use_multi_sampling_ &= Settings::application.render.multisampling > 0; if (use_multi_sampling_){ @@ -60,7 +60,7 @@ void FrameBuffer::init() glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, intermediate_textureid_); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, Settings::application.render_multisampling, + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, Settings::application.render.multisampling, use_alpha_ ? GL_RGBA : GL_RGB, attrib_.viewport.x, attrib_.viewport.y, GL_TRUE); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 45fc560..2b64b0e 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -286,7 +286,7 @@ void ImGuiVisitor::visit (MediaSource& s) else { ImGui::Text("Video File"); if ( ImGui::Button(IMGUI_TITLE_MEDIAPLAYER, ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) - Settings::application.media_player = true; + Settings::application.widget.media_player = true; } ImGuiToolkit::ButtonOpenUrl( SystemToolkit::path_filename(s.path()).c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0) ); } @@ -306,7 +306,7 @@ void ImGuiVisitor::visit (RenderSource& s) { ImGui::Text("Rendering Output"); if ( ImGui::Button(IMGUI_TITLE_PREVIEW, ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) - Settings::application.preview = true; + Settings::application.widget.preview = true; } void ImGuiVisitor::visit (CloneSource& s) diff --git a/RenderingManager.cpp b/RenderingManager.cpp index 755a94f..07dd723 100644 --- a/RenderingManager.cpp +++ b/RenderingManager.cpp @@ -135,7 +135,7 @@ bool Rendering::init() // // OpenGL Multisampling main window // - glfwWindowHint(GLFW_SAMPLES, Settings::application.render_multisampling); + glfwWindowHint(GLFW_SAMPLES, Settings::application.render.multisampling); main_.init(0); // set application icon main_.setIcon("images/vimix_256x256.png"); @@ -594,7 +594,7 @@ bool RenderingWindow::init(int id, GLFWwindow *share) // if not main window if ( master_ != NULL ) { // Disable vsync - glfwSwapInterval(Settings::application.render_vsync); + glfwSwapInterval(Settings::application.render.vsync); // no need for multisampling glDisable(GL_MULTISAMPLE); // clear to black @@ -606,7 +606,7 @@ bool RenderingWindow::init(int id, GLFWwindow *share) // Enable vsync on main window glfwSwapInterval(0); // enable Antialiasing multisampling - if (Settings::application.render_multisampling > 0) { + if (Settings::application.render.multisampling > 0) { glEnable(GL_MULTISAMPLE); glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); } @@ -665,7 +665,7 @@ void RenderingWindow::draw(FrameBuffer *fb) glClear(GL_COLOR_BUFFER_BIT); // blit framebuffer - if (Settings::application.render_blit) { + if (Settings::application.render.blit) { if ( textureid_ != fb->texture()) { diff --git a/Settings.cpp b/Settings.cpp index 52d7ec0..7d05cd1 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -51,28 +51,37 @@ void Settings::Save() pRoot->InsertEndChild(windowsNode); } + // General application preferences XMLElement *applicationNode = xmlDoc.NewElement( "Application" ); applicationNode->SetAttribute("scale", application.scale); applicationNode->SetAttribute("accent_color", application.accent_color); - applicationNode->SetAttribute("preview", application.preview); - applicationNode->SetAttribute("media_player", application.media_player); - applicationNode->SetAttribute("shader_editor", application.shader_editor); applicationNode->SetAttribute("pannel_stick", application.pannel_stick); - applicationNode->SetAttribute("stats", application.stats); - applicationNode->SetAttribute("stats_corner", application.stats_corner); - applicationNode->SetAttribute("logs", application.logs); - applicationNode->SetAttribute("toolbox", application.toolbox); - applicationNode->SetAttribute("framebuffer_ar", application.framebuffer_ar); - applicationNode->SetAttribute("framebuffer_h", application.framebuffer_h); - applicationNode->SetAttribute("render_vsync", application.render_vsync); - applicationNode->SetAttribute("render_multisampling", application.render_multisampling); - applicationNode->SetAttribute("render_blit", application.render_blit); pRoot->InsertEndChild(applicationNode); + // Widgets + XMLElement *widgetsNode = xmlDoc.NewElement( "Widgets" ); + widgetsNode->SetAttribute("preview", application.widget.preview); + widgetsNode->SetAttribute("media_player", application.widget.media_player); + widgetsNode->SetAttribute("shader_editor", application.widget.shader_editor); + widgetsNode->SetAttribute("stats", application.widget.stats); + widgetsNode->SetAttribute("stats_corner", application.widget.stats_corner); + widgetsNode->SetAttribute("logs", application.widget.logs); + widgetsNode->SetAttribute("toolbox", application.widget.toolbox); + pRoot->InsertEndChild(widgetsNode); + + // Render + XMLElement *RenderNode = xmlDoc.NewElement( "Render" ); + RenderNode->SetAttribute("vsync", application.render.vsync); + RenderNode->SetAttribute("multisampling", application.render.multisampling); + RenderNode->SetAttribute("blit", application.render.blit); + pRoot->InsertEndChild(RenderNode); + // bloc views { XMLElement *viewsNode = xmlDoc.NewElement( "Views" ); viewsNode->SetAttribute("current", application.current_view); + viewsNode->SetAttribute("render_view_ar", application.render_view_ar); + viewsNode->SetAttribute("render_view_h", application.render_view_h); map::iterator iter; for (iter=application.views.begin(); iter != application.views.end(); iter++) @@ -157,23 +166,32 @@ void Settings::Load() // different root name return; - XMLElement * pElement = pRoot->FirstChildElement("Application"); - if (pElement == nullptr) return; - pElement->QueryFloatAttribute("scale", &application.scale); - pElement->QueryIntAttribute("accent_color", &application.accent_color); - pElement->QueryBoolAttribute("preview", &application.preview); - pElement->QueryBoolAttribute("media_player", &application.media_player); - pElement->QueryBoolAttribute("shader_editor", &application.shader_editor); - pElement->QueryBoolAttribute("pannel_stick", &application.pannel_stick); - pElement->QueryBoolAttribute("stats", &application.stats); - pElement->QueryBoolAttribute("logs", &application.logs); - pElement->QueryBoolAttribute("toolbox", &application.toolbox); - pElement->QueryIntAttribute("stats_corner", &application.stats_corner); - pElement->QueryIntAttribute("framebuffer_ar", &application.framebuffer_ar); - pElement->QueryIntAttribute("framebuffer_h", &application.framebuffer_h); - pElement->QueryIntAttribute("render_vsync", &application.render_vsync); - pElement->QueryIntAttribute("render_multisampling", &application.render_multisampling); - pElement->QueryBoolAttribute("render_blit", &application.render_blit); + XMLElement * applicationNode = pRoot->FirstChildElement("Application"); + if (applicationNode != nullptr) { + applicationNode->QueryFloatAttribute("scale", &application.scale); + applicationNode->QueryIntAttribute("accent_color", &application.accent_color); + applicationNode->QueryBoolAttribute("pannel_stick", &application.pannel_stick); + } + + // Widgets + XMLElement * widgetsNode = pRoot->FirstChildElement("Widgets"); + if (widgetsNode != nullptr) { + widgetsNode->QueryBoolAttribute("preview", &application.widget.preview); + widgetsNode->QueryBoolAttribute("media_player", &application.widget.media_player); + widgetsNode->QueryBoolAttribute("shader_editor", &application.widget.shader_editor); + widgetsNode->QueryBoolAttribute("stats", &application.widget.stats); + widgetsNode->QueryIntAttribute("stats_corner", &application.widget.stats_corner); + widgetsNode->QueryBoolAttribute("logs", &application.widget.logs); + widgetsNode->QueryBoolAttribute("toolbox", &application.widget.toolbox); + } + + // Render + XMLElement * rendernode = pRoot->FirstChildElement("Render"); + if (rendernode != nullptr) { + rendernode->QueryIntAttribute("vsync", &application.render.vsync); + rendernode->QueryIntAttribute("multisampling", &application.render.multisampling); + rendernode->QueryBoolAttribute("blit", &application.render.blit); + } // bloc windows { @@ -206,6 +224,8 @@ void Settings::Load() if (pElement) { pElement->QueryIntAttribute("current", &application.current_view); + pElement->QueryIntAttribute("render_view_ar", &application.render_view_ar); + pElement->QueryIntAttribute("render_view_h", &application.render_view_h); XMLElement* viewNode = pElement->FirstChildElement("View"); for( ; viewNode ; viewNode=viewNode->NextSiblingElement()) diff --git a/Settings.h b/Settings.h index aa0c641..bc206bf 100644 --- a/Settings.h +++ b/Settings.h @@ -11,6 +11,27 @@ namespace Settings { +struct WidgetsConfig +{ + bool stats; + int stats_corner; + bool logs; + bool preview; + bool media_player; + bool shader_editor; + bool toolbox; + + WidgetsConfig() { + stats = false; + stats_corner = 1; + logs = false; + preview = false; + media_player = false; + shader_editor = false; + toolbox = false; + } +}; + struct WindowConfig { std::string name; @@ -55,6 +76,19 @@ struct History } }; +struct RenderConfig +{ + int vsync; + int multisampling; + bool blit; + + RenderConfig() { + vsync = 1; // todo GUI selection + multisampling = 2; // todo GUI selection + blit = false; + } +}; + struct Application { // Verification @@ -63,23 +97,19 @@ struct Application // Global settings Application interface float scale; int accent_color; - bool stats; - int stats_corner; - bool logs; - bool preview; - bool media_player; - bool shader_editor; bool pannel_stick; - bool toolbox; + + // Settings of widgets + WidgetsConfig widget; // Settings of Views int current_view; + int render_view_ar; + int render_view_h; std::map views; - int framebuffer_ar; - int framebuffer_h; - int render_vsync; - int render_multisampling; - bool render_blit; + + // settings render + RenderConfig render; // multiple windows handling std::vector windows; @@ -91,21 +121,12 @@ struct Application Application() : name(APP_NAME){ scale = 1.f; accent_color = 0; - stats = false; - stats_corner = 1; - logs = false; - preview = false; - media_player = false; - shader_editor = false; pannel_stick = false; - toolbox = false; + current_view = 1; - framebuffer_ar = 3; - framebuffer_h = 1; - render_vsync = 1; // todo GUI selection - render_multisampling = 2; // todo GUI selection - render_blit = false; - std::vector second (4,100); + render_view_ar = 3; + render_view_h = 1; + windows = std::vector(3); windows[0].name = APP_NAME APP_TITLE; windows[0].w = 1600; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index d158110..8c76d5e 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -235,19 +235,19 @@ void UserInterface::handleKeyboard() } else if (ImGui::IsKeyPressed( GLFW_KEY_L )) { // Logs - Settings::application.logs = !Settings::application.logs; + Settings::application.widget.logs = !Settings::application.widget.logs; } else if (ImGui::IsKeyPressed( GLFW_KEY_T )) { // Logs - Settings::application.toolbox = !Settings::application.toolbox; + Settings::application.widget.toolbox = !Settings::application.widget.toolbox; } else if (ImGui::IsKeyPressed( GLFW_KEY_P )) { // Logs - Settings::application.preview = !Settings::application.preview; + Settings::application.widget.preview = !Settings::application.widget.preview; } else if (ImGui::IsKeyPressed( GLFW_KEY_M )) { // Logs - Settings::application.media_player = !Settings::application.media_player; + Settings::application.widget.media_player = !Settings::application.widget.media_player; } else if (ImGui::IsKeyPressed( GLFW_KEY_A )) { // select all @@ -536,18 +536,18 @@ void UserInterface::Render() Log::Render(); // windows - if (Settings::application.toolbox) + if (Settings::application.widget.toolbox) toolbox.Render(); - if (Settings::application.preview) + if (Settings::application.widget.preview) RenderPreview(); - if (Settings::application.media_player) + if (Settings::application.widget.media_player) RenderMediaPlayer(); - if (Settings::application.shader_editor) + if (Settings::application.widget.shader_editor) RenderShaderEditor(); - if (Settings::application.stats) - ImGuiToolkit::ShowStats(&Settings::application.stats, &Settings::application.stats_corner); - if (Settings::application.logs) - Log::ShowLogWindow(&Settings::application.logs); + if (Settings::application.widget.stats) + ImGuiToolkit::ShowStats(&Settings::application.widget.stats, &Settings::application.widget.stats_corner); + if (Settings::application.widget.logs) + Log::ShowLogWindow(&Settings::application.widget.logs); // about if (show_about) @@ -582,9 +582,9 @@ void UserInterface::showMenuFile() navigator.hidePannel(); } ImGui::SetNextItemWidth( ImGui::GetContentRegionAvail().x ); - ImGui::Combo("##AR", &Settings::application.framebuffer_ar, FrameBuffer::aspect_ratio_name, IM_ARRAYSIZE(FrameBuffer::aspect_ratio_name) ); + ImGui::Combo("##AR", &Settings::application.render_view_ar, FrameBuffer::aspect_ratio_name, IM_ARRAYSIZE(FrameBuffer::aspect_ratio_name) ); ImGui::SetNextItemWidth( ImGui::GetContentRegionAvail().x ); - ImGui::Combo("##HEIGHT", &Settings::application.framebuffer_h, FrameBuffer::resolution_name, IM_ARRAYSIZE(FrameBuffer::resolution_name) ); + ImGui::Combo("##HEIGHT", &Settings::application.render_view_h, FrameBuffer::resolution_name, IM_ARRAYSIZE(FrameBuffer::resolution_name) ); ImGui::Separator(); @@ -672,7 +672,7 @@ void ToolBox::Render() ImGui::SetNextWindowPos(ImVec2(40, 40), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(400, 300), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSizeConstraints(ImVec2(350, 300), ImVec2(FLT_MAX, FLT_MAX)); - if ( !ImGui::Begin(IMGUI_TITLE_TOOLBOX, &Settings::application.toolbox, ImGuiWindowFlags_MenuBar) ) + if ( !ImGui::Begin(IMGUI_TITLE_TOOLBOX, &Settings::application.widget.toolbox, ImGuiWindowFlags_MenuBar) ) { ImGui::End(); return; @@ -686,8 +686,8 @@ void ToolBox::Render() if ( ImGui::MenuItem( ICON_FA_CAMERA_RETRO " Screenshot") ) UserInterface::manager().StartScreenshot(); - ImGui::MenuItem("Blit", nullptr, &Settings::application.render_blit); - ImGui::MenuItem("Multisampling", nullptr, (Settings::application.render_multisampling > 0), false); + ImGui::MenuItem("Blit", nullptr, &Settings::application.render.blit); + ImGui::MenuItem("Multisampling", nullptr, (Settings::application.render.multisampling > 0), false); ImGui::EndMenu(); } @@ -714,8 +714,8 @@ void ToolBox::Render() const GLFWvidmode* mode = glfwGetVideoMode(Rendering::manager().outputWindow().monitor()); refresh_rate = float(mode->refreshRate); - if (Settings::application.render_vsync > 0) - refresh_rate /= Settings::application.render_vsync; + if (Settings::application.render.vsync > 0) + refresh_rate /= Settings::application.render.vsync; else refresh_rate = 0.f; max_fps = refresh_rate + 5.f; @@ -787,7 +787,7 @@ void UserInterface::RenderPreview() ImGui::SetNextWindowPos(ImVec2(1180, 20), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(400, 260), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSizeConstraints(ImVec2(300, 200), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, &ar); - ImGui::Begin(ICON_FA_LAPTOP " Preview", &Settings::application.preview, ImGuiWindowFlags_NoScrollbar); + ImGui::Begin(ICON_FA_LAPTOP " Preview", &Settings::application.widget.preview, ImGuiWindowFlags_NoScrollbar); float width = ImGui::GetContentRegionAvail().x; ImVec2 imagesize ( width, width / ar); @@ -829,7 +829,7 @@ void UserInterface::RenderMediaPlayer() ImGui::SetNextWindowPos(ImVec2(1180, 400), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSizeConstraints(ImVec2(350, 300), ImVec2(FLT_MAX, FLT_MAX)); - if ( !ImGui::Begin(IMGUI_TITLE_MEDIAPLAYER, &Settings::application.media_player, ImGuiWindowFlags_NoScrollbar ) || !show) + if ( !ImGui::Begin(IMGUI_TITLE_MEDIAPLAYER, &Settings::application.widget.media_player, ImGuiWindowFlags_NoScrollbar ) || !show) { ImGui::End(); return; @@ -986,7 +986,7 @@ void UserInterface::RenderShaderEditor() { static bool show_statusbar = true; - ImGui::Begin(IMGUI_TITLE_SHADEREDITOR, &Settings::application.shader_editor, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar); + ImGui::Begin(IMGUI_TITLE_SHADEREDITOR, &Settings::application.widget.shader_editor, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar); ImGui::SetWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver); if (ImGui::BeginMenuBar()) { @@ -1495,14 +1495,14 @@ void Navigator::RenderMainPannel() ImGui::Text(" "); ImGui::Text("Windows"); - ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_PREVIEW, &Settings::application.preview, CTRL_MOD "P"); - ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_MEDIAPLAYER, &Settings::application.media_player, CTRL_MOD "M"); + ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_PREVIEW, &Settings::application.widget.preview, CTRL_MOD "P"); + ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_MEDIAPLAYER, &Settings::application.widget.media_player, CTRL_MOD "M"); #ifndef NDEBUG ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_SHADEREDITOR, &Settings::application.shader_editor); ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_TOOLBOX, &Settings::application.toolbox, CTRL_MOD "T"); #endif - ImGuiToolkit::ButtonSwitch( ICON_FA_LIST " Logs", &Settings::application.logs, CTRL_MOD "L"); - ImGuiToolkit::ButtonSwitch( ICON_FA_TACHOMETER_ALT " Metrics", &Settings::application.stats); + ImGuiToolkit::ButtonSwitch( ICON_FA_LIST " Logs", &Settings::application.widget.logs, CTRL_MOD "L"); + ImGuiToolkit::ButtonSwitch( ICON_FA_TACHOMETER_ALT " Metrics", &Settings::application.widget.stats); ImGui::Text(" "); ImGui::Text("Appearance"); diff --git a/View.cpp b/View.cpp index 66921fe..f90c035 100644 --- a/View.cpp +++ b/View.cpp @@ -306,7 +306,7 @@ RenderView::~RenderView() void RenderView::setResolution(glm::vec3 resolution) { if (resolution.x < 128.f || resolution.y < 128.f) - resolution = FrameBuffer::getResolutionFromParameters(Settings::application.framebuffer_ar, Settings::application.framebuffer_h); + resolution = FrameBuffer::getResolutionFromParameters(Settings::application.render_view_ar, Settings::application.render_view_h); if (frame_buffer_) delete frame_buffer_;