Add multisampling anti-aliasing

This commit is contained in:
Stefan Tröger
2014-05-08 22:00:16 +02:00
committed by wmayer
parent b281a9782d
commit e1a8bb1623
5 changed files with 161 additions and 67 deletions

View File

@@ -7,26 +7,20 @@
<x>0</x>
<y>0</y>
<width>477</width>
<height>495</height>
<height>505</height>
</rect>
</property>
<property name="windowTitle">
<string>3D View</string>
</property>
<layout class="QGridLayout" name="gridLayout3">
<property name="margin">
<number>11</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="GroupBox12">
<property name="title">
<string>3D View settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_CornerCoordSystem">
<property name="text">
<string>Show coordinate system in the corner</string>
@@ -42,7 +36,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_ShowFPS">
<property name="text">
<string>Show counter of frames per second</string>
@@ -55,7 +49,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_UseAutoRotation">
<property name="enabled">
<bool>true</bool>
@@ -74,7 +68,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item>
<layout class="QGridLayout" name="gridLayout2">
<item row="0" column="0">
<widget class="QLabel" name="navigationLabel">
@@ -127,9 +121,51 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="aliasingLAbel">
<property name="text">
<string>Anti-Aliasing</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefComboBox" name="comboAliasing">
<property name="prefEntry" stdset="0">
<cstring>AntiAliasing</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Line Smoothing</string>
</property>
</item>
<item>
<property name="text">
<string>MSAA 2x</string>
</property>
</item>
<item>
<property name="text">
<string>MSAA 4x</string>
</property>
</item>
<item>
<property name="text">
<string>MSAA 8x</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxZoomAtCursor">
@@ -188,14 +224,14 @@
</item>
</layout>
</item>
<item row="5" column="0">
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxInvertZoom">
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<property name="text">
<string>Invert zoom</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>InvertZoom</cstring>
</property>
@@ -204,20 +240,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxAntiAliasing">
<property name="text">
<string>Enable anti-aliasing (slower)</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>UseAntialiasing</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="7" column="0">
<item>
<widget class="Line" name="line1">
<property name="frameShape">
<enum>QFrame::HLine</enum>
@@ -230,7 +253,7 @@
</property>
</widget>
</item>
<item row="8" column="0">
<item>
<layout class="QHBoxLayout" name="eyedistanceLayout">
<property name="spacing">
<number>6</number>
@@ -272,7 +295,7 @@
</item>
</layout>
</item>
<item row="9" column="0">
<item>
<layout class="QGridLayout" name="backlightLayout">
<property name="margin">
<number>11</number>
@@ -362,7 +385,7 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QGroupBox" name="groupBoxCamera">
<property name="title">
<string>Camera type</string>
@@ -406,7 +429,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -448,6 +471,11 @@
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefComboBox</class>
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
@@ -464,7 +492,6 @@
<tabstop>checkBoxZoomAtCursor</tabstop>
<tabstop>spinBoxZoomStep</tabstop>
<tabstop>checkBoxInvertZoom</tabstop>
<tabstop>checkBoxAntiAliasing</tabstop>
<tabstop>FloatSpinBox_EyeDistance</tabstop>
<tabstop>checkBoxBacklight</tabstop>
<tabstop>backlightColor</tabstop>

View File

@@ -31,6 +31,7 @@
#include "DlgSettings3DViewImp.h"
#include "NavigationStyle.h"
#include "PrefWidgets.h"
#include "View3DInventorViewer.h"
#include "ui_MouseButtons.h"
#include <App/Application.h>
#include <Base/Console.h>
@@ -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);

View File

@@ -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<QGLWidget*>(_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));

View File

@@ -2312,3 +2312,60 @@ void View3DInventorViewer::turnDeltaDimensionsOff()
{
static_cast<SoSwitch *>(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
}

View File

@@ -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