diff --git a/sandboxes/opencsg/GLScene.cpp b/sandboxes/opencsg/GLScene.cpp index 5f4a20532..60eb0ce03 100644 --- a/sandboxes/opencsg/GLScene.cpp +++ b/sandboxes/opencsg/GLScene.cpp @@ -454,7 +454,14 @@ void Display::on_moved_to(long x, long y) m_mouse_pos = {x, y}; } -void CSGSettings::set_csg_algo(OpenCSG::Algorithm alg) { m_csgalg = alg; } +void Display::apply_csgsettings(const CSGSettings &settings) +{ + using namespace OpenCSG; + m_csgsettings = settings; + setOption(AlgorithmSetting, m_csgsettings.get_algo()); + setOption(DepthComplexitySetting, m_csgsettings.get_depth_algo()); + setOption(DepthBoundsOptimization, m_csgsettings.get_optimization()); +} void Display::on_scene_updated() { diff --git a/sandboxes/opencsg/GLScene.hpp b/sandboxes/opencsg/GLScene.hpp index 411b0db71..6beecb79a 100644 --- a/sandboxes/opencsg/GLScene.hpp +++ b/sandboxes/opencsg/GLScene.hpp @@ -220,8 +220,17 @@ public: class CSGSettings { OpenCSG::Algorithm m_csgalg = OpenCSG::Algorithm::Automatic; + OpenCSG::DepthComplexityAlgorithm m_depth_algo = OpenCSG::DepthComplexityAlgorithm::NoDepthComplexitySampling; + OpenCSG::Optimization m_optim = OpenCSG::Optimization::OptimizationDefault; public: - void set_csg_algo(OpenCSG::Algorithm alg); + int get_algo() const { return int(m_csgalg); } + void set_algo(OpenCSG::Algorithm alg) { m_csgalg = alg; } + + int get_depth_algo() const { return int(m_depth_algo); } + void set_depth_algo(OpenCSG::DepthComplexityAlgorithm alg) { m_depth_algo = alg; } + + int get_optimization() const { return int(m_optim); } + void set_optimization(OpenCSG::Optimization o) { m_optim = o; } }; class Display : public std::enable_shared_from_this, @@ -265,8 +274,8 @@ public: void move_clip_plane(double z) { m_camera->set_clip_z(z); } - const CSGSettings & csgsettings() const { return m_csgsettings; } - void csgsettings(const CSGSettings &settings) { m_csgsettings = settings; } + const CSGSettings & get_csgsettings() const { return m_csgsettings; } + void apply_csgsettings(const CSGSettings &settings); virtual void on_scene_updated(); virtual void clear_screen(); diff --git a/sandboxes/opencsg/main.cpp b/sandboxes/opencsg/main.cpp index f2e9dc6c1..8c106fa85 100644 --- a/sandboxes/opencsg/main.cpp +++ b/sandboxes/opencsg/main.cpp @@ -100,8 +100,8 @@ public: // drivers would most likely work with some alpha plane, but // glReadPixels would not return the alpha channel on NVIDIA if // not requested when the GL context is created. - WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8, WX_GL_SAMPLE_BUFFERS, - GL_TRUE, WX_GL_SAMPLES, 4, 0}; + WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8, + WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0}; m_canvas = std::make_shared(this, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, @@ -111,17 +111,33 @@ public: auto controlsizer = new wxBoxSizer(wxHORIZONTAL); auto slider_sizer = new wxBoxSizer(wxVERTICAL); auto console_sizer = new wxBoxSizer(wxVERTICAL); - + auto slider = new wxSlider(control_panel, wxID_ANY, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL); - auto toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling"); - wxString algorithms [] = {"Default", "Different"}; - auto alg_select = new wxComboBox(control_panel, wxID_ANY, "Default", wxDefaultPosition, wxDefaultSize, 2, algorithms); - slider_sizer->Add(slider, 1, wxEXPAND); - console_sizer->Add(toggle, 0, wxALL, 5); - console_sizer->Add(alg_select, 0, wxALL, 5); + + auto toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling"); + console_sizer->Add(toggle, 0, wxALL | wxEXPAND, 5); + + auto add_combobox = [control_panel, console_sizer] + (const wxString &label, std::vector &&list) { + auto widget = new wxComboBox(control_panel, wxID_ANY, list[0], + wxDefaultPosition, wxDefaultSize, + int(list.size()), list.data()); + auto sz = new wxBoxSizer(wxHORIZONTAL); + sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0, wxALL | wxALIGN_CENTER, 5); + sz->Add(widget, 1, wxALL | wxEXPAND, 5); + console_sizer->Add(sz, 0, wxEXPAND); + return widget; + }; + + auto alg_select = add_combobox("Algorithm", {"Auto", "Goldfeather", "SCS"}); + auto depth_select = add_combobox("Depth Complexity", {"Off", "OcclusionQuery", "On"}); + depth_select->Disable(); + auto optimization_select = add_combobox("Optimization", { "Default", "ForceOn", "On", "Off" }); + controlsizer->Add(slider_sizer, 0, wxEXPAND); controlsizer->Add(console_sizer, 1, wxEXPAND); + control_panel->SetSizer(controlsizer); auto sizer = new wxBoxSizer(wxHORIZONTAL); @@ -141,6 +157,31 @@ public: m_canvas->repaint(); }, toggle->GetId()); + Bind(wxEVT_COMBOBOX, [this, alg_select, depth_select](wxCommandEvent &) + { + int sel = alg_select->GetSelection(); + depth_select->Enable(sel > 0); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_algo(OpenCSG::Algorithm(sel)); + m_canvas->apply_csgsettings(settings); + }, alg_select->GetId()); + + Bind(wxEVT_COMBOBOX, [this, depth_select](wxCommandEvent &) + { + int sel = depth_select->GetSelection(); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(sel)); + m_canvas->apply_csgsettings(settings); + }, depth_select->GetId()); + + Bind(wxEVT_COMBOBOX, [this, optimization_select](wxCommandEvent &) + { + int sel = optimization_select->GetSelection(); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_optimization(OpenCSG::Optimization(sel)); + m_canvas->apply_csgsettings(settings); + }, depth_select->GetId()); + m_canvas->set_scene(std::make_shared()); }