diff --git a/src/Gui/DlgSettings3DView.ui b/src/Gui/DlgSettings3DView.ui index bf3f7401d6..4f6d633fe7 100644 --- a/src/Gui/DlgSettings3DView.ui +++ b/src/Gui/DlgSettings3DView.ui @@ -7,26 +7,20 @@ 0 0 477 - 495 + 505 3D View - - - 11 - - - 6 - - + + 3D View settings - - + + Show coordinate system in the corner @@ -42,7 +36,7 @@ - + Show counter of frames per second @@ -55,7 +49,7 @@ - + true @@ -74,7 +68,7 @@ - + @@ -127,9 +121,51 @@ + + + + Anti-Aliasing + + + + + + + AntiAliasing + + + View + + + + None + + + + + Line Smoothing + + + + + MSAA 2x + + + + + MSAA 4x + + + + + MSAA 8x + + + + - + @@ -188,14 +224,14 @@ - + - - true - - + Invert zoom + + true + InvertZoom @@ -204,20 +240,7 @@ - - - - Enable anti-aliasing (slower) - - - UseAntialiasing - - - View - - - - + QFrame::HLine @@ -230,7 +253,7 @@ - + 6 @@ -272,7 +295,7 @@ - + 11 @@ -362,7 +385,7 @@ - + Camera type @@ -406,7 +429,7 @@ - + Qt::Vertical @@ -448,6 +471,11 @@ QCheckBox
Gui/PrefWidgets.h
+ + Gui::PrefComboBox + QComboBox +
Gui/PrefWidgets.h
+
Gui::PrefDoubleSpinBox QDoubleSpinBox @@ -464,7 +492,6 @@ checkBoxZoomAtCursor spinBoxZoomStep checkBoxInvertZoom - checkBoxAntiAliasing FloatSpinBox_EyeDistance checkBoxBacklight backlightColor diff --git a/src/Gui/DlgSettings3DViewImp.cpp b/src/Gui/DlgSettings3DViewImp.cpp index 8a2309fd4c..e20794ca5a 100644 --- a/src/Gui/DlgSettings3DViewImp.cpp +++ b/src/Gui/DlgSettings3DViewImp.cpp @@ -31,6 +31,7 @@ #include "DlgSettings3DViewImp.h" #include "NavigationStyle.h" #include "PrefWidgets.h" +#include "View3DInventorViewer.h" #include "ui_MouseButtons.h" #include #include @@ -71,11 +72,13 @@ void DlgSettings3DViewImp::saveSettings() int index = comboOrbitStyle->currentIndex(); hGrp->SetInt("OrbitStyle", index); + + index = this->comboAliasing->currentIndex(); + hGrp->SetInt("AntiAliasing", index); checkBoxZoomAtCursor->onSave(); checkBoxInvertZoom->onSave(); spinBoxZoomStep->onSave(); - checkBoxAntiAliasing->onSave(); CheckBox_CornerCoordSystem->onSave(); CheckBox_ShowFPS->onSave(); CheckBox_UseAutoRotation->onSave(); @@ -92,7 +95,6 @@ void DlgSettings3DViewImp::loadSettings() checkBoxZoomAtCursor->onRestore(); checkBoxInvertZoom->onRestore(); spinBoxZoomStep->onRestore(); - checkBoxAntiAliasing->onRestore(); CheckBox_CornerCoordSystem->onRestore(); CheckBox_ShowFPS->onRestore(); CheckBox_UseAutoRotation->onRestore(); @@ -112,6 +114,10 @@ void DlgSettings3DViewImp::loadSettings() index = hGrp->GetInt("OrbitStyle", int(NavigationStyle::Trackball)); index = Base::clamp(index, 0, comboOrbitStyle->count()-1); comboOrbitStyle->setCurrentIndex(index); + + index = hGrp->GetInt("AntiAliasing", int(Gui::View3DInventorViewer::None)); + index = Base::clamp(index, 0, comboAliasing->count()-1); + comboAliasing->setCurrentIndex(index); } void DlgSettings3DViewImp::on_mouseButton_clicked() @@ -148,10 +154,12 @@ void DlgSettings3DViewImp::changeEvent(QEvent *e) if (e->type() == QEvent::LanguageChange) { int navigation = comboNavigationStyle->currentIndex(); int orbit = comboOrbitStyle->currentIndex(); + int aliasing = comboAliasing->currentIndex(); retranslateUi(this); retranslate(); comboNavigationStyle->setCurrentIndex(navigation); comboOrbitStyle->setCurrentIndex(orbit); + comboAliasing->setCurrentIndex(aliasing); } else { QWidget::changeEvent(e); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index c4d1372d44..90a27f7ecd 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -144,7 +144,7 @@ View3DInventor::View3DInventor(Gui::Document* pcDocument, QWidget* parent, Qt::W OnChange(*hGrp,"BackgroundColor3"); OnChange(*hGrp,"BackgroundColor4"); OnChange(*hGrp,"UseBackgroundColorMid"); - OnChange(*hGrp,"UseAntialiasing"); + OnChange(*hGrp,"AntiAliasing"); OnChange(*hGrp,"ShowFPS"); OnChange(*hGrp,"Orthographic"); OnChange(*hGrp,"HeadlightColor"); @@ -333,31 +333,8 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M else if (strcmp(Reason,"Gradient") == 0) { _viewer->setGradientBackground((rGrp.GetBool("Gradient",true))); } - else if (strcmp(Reason,"UseAntialiasing") == 0) { - _viewer->getGLRenderAction()->setSmoothing(rGrp.GetBool("UseAntialiasing",false)); - } - else if (strcmp(Reason,"SampleBuffers") == 0) { -#if SOQT_MAJOR_VERSION > 1 || (SOQT_MAJOR_VERSION == 1 && SOQT_MINOR_VERSION >= 5) - _viewer->setSampleBuffers(rGrp.GetInt("SampleBuffers",4)); -#else - // http://stackoverflow.com/questions/4207506/where-is-gl-multisample-defined - //int sb = rGrp.GetInt("SampleBuffers",4); - //QGLWidget* gl = static_cast(_viewer->getGLWidget()); - //QGLFormat fmt = gl->format(); - //if (sb > 0) { - // fmt.setSampleBuffers(true); - // fmt.setSamples(sb); - // gl->setFormat(fmt); - // gl->makeCurrent(); - // //glEnable(GL_MULTISAMPLE); - //} - //else { - // fmt.setSampleBuffers(false); - // gl->setFormat(fmt); - // gl->makeCurrent(); - // //glDisable(GL_MULTISAMPLE); - //} -#endif + else if (strcmp(Reason,"AntiAliasing") == 0) { + _viewer->setAntiAliasingMode(View3DInventorViewer::AntiAliasing(rGrp.GetInt("AntiAliasing",0))); } else if (strcmp(Reason,"ShowFPS") == 0) { _viewer->setEnabledFPSCounter(rGrp.GetBool("ShowFPS",false)); diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index e22c9b94c5..14d13c1dc0 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2312,3 +2312,60 @@ void View3DInventorViewer::turnDeltaDimensionsOff() { static_cast(dimensionRoot->getChild(1))->whichChild = SO_SWITCH_NONE; } + +void View3DInventorViewer::setAntiAliasingMode(View3DInventorViewer::AntiAliasing mode) +{ + getGLRenderAction()->setSmoothing(false); + int buffers = 0; + + switch( mode ) { + case Smoothing: + getGLRenderAction()->setSmoothing(true); + break; + case MSAA2x: + buffers = 2; + break; + case MSAA4x: + buffers = 4; + break; + case MSAA8x: + buffers = 8; + break; + case None: + default: + break; + }; + +#if SOQT_MAJOR_VERSION > 1 || (SOQT_MAJOR_VERSION == 1 && SOQT_MINOR_VERSION >= 5) + setSampleBuffers(buffers); +#else + if(buffers != 0) + Base::Console().Warning("Multisampling is not supported by SoQT < 1.5, this anti-aliasing mode is disabled"); +#endif +} + + +View3DInventorViewer::AntiAliasing View3DInventorViewer::getAntiAliasingMode() +{ + if(getGLRenderAction()->isSmoothing()) + return Smoothing; + +#if SOQT_MAJOR_VERSION > 1 || (SOQT_MAJOR_VERSION == 1 && SOQT_MINOR_VERSION >= 5) + int buffers = getSampleBuffers(); + switch(buffers) { + case 0: + return None; + case 2: + return MSAA2x; + case 4: + return MSAA4x; + case 8: + return MSAA8x; + default: + setSampleBuffers(0); + return None; + }; +#else + return None; +#endif +} diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 80916e39a8..fc07b8edc0 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -98,6 +98,22 @@ public: DisallowZooming=32,/**< switch of the zooming. */ }; //@} + + /** @name Anti-Aliasing modes of the rendered 3D scene + * Here you can switch between different methods for anti aliasing wich provide quite different results + * at different runtime impact. + * - Smoothing enables openGL line and vertex smoothing which is basicly deprecadet + * - MSAA is hardeware multi sampling (with 2, 4 or 8 passes), a quite commom and efficient AA technique + */ + //@{ + enum AntiAliasing { + None, + Smoothing, + MSAA2x, + MSAA4x, + MSAA8x + }; + //@} View3DInventorViewer (QWidget *parent, const char *name=NULL, SbBool embed=true, Type type= SoQtViewer::BROWSER, SbBool build=true); @@ -264,6 +280,15 @@ public: void addDimension3d(SoNode *node); void addDimensionDelta(SoNode *node); //@} + + /** @name Anti-Aliasing Control + * the anti-aliasing mode is controled by parameters through view3dinventor. + * don't call them directly. Instead set the parameter View/AntiAliasing. + */ + //@{ + void setAntiAliasingMode(AntiAliasing mode); + AntiAliasing getAntiAliasingMode(); + //@} /** * Set the camera's orientation. If isAnimationEnabled() returns