Commit 21b24403 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'featureOpenGLContextSettings' into 'master'

Feature open gl context settings

See merge request !79
parents 60f7b034 a2d0c5da
......@@ -10,6 +10,12 @@
* --no-splash : Disable splash screen\n
* --disable-stereo : Disable Stereo Mode\n
*
* OpenGL Options:\n
* -profile < compat | core > : request Compatibility or %Core context ( Default = %Core )\n
* -glVersion <int.int> : request specified OpenGL version (Default = 3.2)\n
* -samples <int> : request MSAA with <int> samples (Default = 16)\n
* \note The OpenGL command line parameters override stored settings temporarily. To permanently store an OpenGL setting, use the options dialog.
*
* Log options:\n
* --log-to-console ( -c ) : Write logger window contents to console\n
* \note On Window Systems, using the --log-to-console option causes the creation of a console if OpenFlipper was started without one.
......
......@@ -350,9 +350,14 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
QCommandLineOption coreProfileOption("core-profile",QCoreApplication::translate("main", "OpenGL Core Profile Mode"));
parser.addOption(coreProfileOption);
QCommandLineOption profileOption("profile",QCoreApplication::translate("main","Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate("main","<compat | core >"));
profileOption.setDefaultValue("compat");
QCommandLineOption glVersionOption("glVersion",QCoreApplication::translate("main","Request OpenGL version <major>.<minor> "),QCoreApplication::translate("main","< 1.0 | 1.1 | ... | 4.6 >"));
parser.addOption(glVersionOption);
QCommandLineOption samplesOption("samples",QCoreApplication::translate("main","Overwrite multisampling sample count"),QCoreApplication::translate("main","< 0 | 1 | 2 | ... | 16 >"));
parser.addOption(samplesOption);
QCommandLineOption profileOption("profile",QCoreApplication::translate("main","Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate("main","< compat | core >"));
parser.addOption(profileOption);
const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption versionOption = parser.addVersionOption();
......@@ -415,20 +420,30 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
std::cerr << "Got port option : " << port.toStdString() << std::endl;
OpenFlipper::Options::remoteControl(port.toInt());
}
if(parser.isSet("samples"))
OpenFlipper::Options::samples(parser.value("samples").toInt(),true);
if(parser.isSet("glVersion"))
{
QStringList values = parser.value("glVersion").split(".");
QPair<int,int> version(
values[0].toInt(),
values[1].toInt());
OpenFlipper::Options::glVersion(version,true);
}
if(parser.value(profileOption)=="core")
{
OpenFlipper::Options::coreProfile(true);
OpenFlipper::Options::coreProfile(true, true);
}
else
{
if(parser.value(profileOption)=="compat")
{
OpenFlipper::Options::coreProfile(false);
OpenFlipper::Options::coreProfile(false, true);
}
}
if(parser.isSet(coreProfileOption)) {
OpenFlipper::Options::coreProfile(true);
OpenFlipper::Options::coreProfile(true, true);
}
return CommandLineOk;
......@@ -514,7 +529,8 @@ int main(int argc, char **argv)
#if QT_VERSION >= 0x050500
QSurfaceFormat format;
format.setVersion(4, 4);
QPair<int,int> version = OpenFlipper::Options::glVersion();
format.setVersion(version.first, version.second);
if (OpenFlipper::Options::coreProfile())
{
......@@ -530,7 +546,6 @@ int main(int argc, char **argv)
format.setSamples(OpenFlipper::Options::samples());
QSurfaceFormat::setDefaultFormat(format);
QApplication app(argc, argv);
......
......@@ -138,6 +138,15 @@ static bool stereo_ = true;
/// Use opengl core profile mode?
static bool coreProfile_ = false;
static bool profileOverride_ = false;
/// Requested Opengl version
static QPair<int,int> version_ {4,6};
static bool versionOverride_ = false;
/// Requested OpenGL multisampling
static int samples_ = 4;
static bool samplesOverride_ = false;
/// Store the opengl stereo support
static bool glStereo_ = true;
......@@ -378,23 +387,69 @@ bool stereo( ) {
}
/// Store opengl core profile setting
void coreProfile( bool _enableCoreProfile ) {
coreProfile_ = _enableCoreProfile;
void coreProfile( bool _enableCoreProfile, bool _temporary ) {
if(_temporary)
{
profileOverride_ = true;
coreProfile_ = _enableCoreProfile;
}
else
OpenFlipperSettings().setValue("Core/OpenGL/CoreProfile",_enableCoreProfile);
}
/// get opengl core profile setting
bool coreProfile( ) {
return coreProfile_;
if(profileOverride_)
return coreProfile_;
else
return OpenFlipperSettings().value("Core/OpenGL/CoreProfile",true).toBool();
}
/// get opengl version setting
QPair<int,int> glVersion(){
if(versionOverride_)
return version_;
else
{
// unfortunately QVariant cant store QPair directly, we could try std::pair but its good for now
int major = OpenFlipperSettings().value("Core/OpenGL/VersionMajor", 4).value<int>();
int minor = OpenFlipperSettings().value("Core/OpenGL/VersionMinor", 6).value<int>();
return QPair<int, int>(major,minor);
}
}
/// Store opengl version setting
void glVersion(const QPair<int,int> & _version, bool _temporary)
{
//possible enhancement: check for validity
if(_temporary)
{
version_ = _version;
versionOverride_ = true;
}
else
{
OpenFlipperSettings().setValue("Core/OpenGL/VersionMajor",_version.first);
OpenFlipperSettings().setValue("Core/OpenGL/VersionMinor",_version.second);
}
}
/// Store opengl MSAA sample count
void samples(int _samples) {
OpenFlipperSettings().setValue("Core/OpenGL/Samples",_samples);
void samples(int _samples, bool _temporary) {
if(_temporary)
{
samples_ = _samples;
samplesOverride_ = true;
}
else
OpenFlipperSettings().setValue("Core/OpenGL/Samples",_samples);
}
/// Get opengl MSAA sample count
int samples() {
return OpenFlipperSettings().value("Core/OpenGL/Samples",4).toInt();
if(samplesOverride_)
return samples_;
else
return OpenFlipperSettings().value("Core/OpenGL/Samples",4).toInt();
}
/// Store opengl stereo mode setting
......
......@@ -417,15 +417,23 @@ QString helpDirStr();
/// Store opengl core profile setting
DLLEXPORT
void coreProfile(bool _enableCoreProfile);
void coreProfile(bool _enableCoreProfile, bool _temporary = false);
/// get opengl core profile setting
DLLEXPORT
bool coreProfile( );
/// get opengl version setting
DLLEXPORT
QPair<int,int> glVersion();
/// set opengl version setting
DLLEXPORT
void glVersion(const QPair<int, int>& _version, bool _teporary = false);
/// Store opengl MSAA sample count
DLLEXPORT
void samples(int _samples);
void samples(int _samples, bool _temporary = false);
/// Get opengl MSAA sample count
DLLEXPORT
......
......@@ -77,7 +77,29 @@ OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyB
// Files
connect(pbReloadShaders,SIGNAL(clicked()),this,SLOT(slotReloadShaders()));
// OpenGL versions
VersionComboBox->clear();
VersionComboBox->addItem("4.6",QVariant::fromValue(QPair<int, int>(4,6)));
VersionComboBox->addItem("4.5",QVariant::fromValue(QPair<int, int>(4,5)));
VersionComboBox->addItem("4.4",QVariant::fromValue(QPair<int, int>(4,4)));
VersionComboBox->addItem("4.3",QVariant::fromValue(QPair<int, int>(4,3)));
VersionComboBox->addItem("4.2",QVariant::fromValue(QPair<int, int>(4,2)));
VersionComboBox->addItem("4.1",QVariant::fromValue(QPair<int, int>(4,1)));
VersionComboBox->addItem("4.0",QVariant::fromValue(QPair<int, int>(4,0)));
VersionComboBox->addItem("3.3",QVariant::fromValue(QPair<int, int>(3,3)));
VersionComboBox->addItem("3.2",QVariant::fromValue(QPair<int, int>(3,2)));
VersionComboBox->addItem("3.1",QVariant::fromValue(QPair<int, int>(3,1)));
VersionComboBox->addItem("3.0",QVariant::fromValue(QPair<int, int>(3,0)));
VersionComboBox->addItem("2.1",QVariant::fromValue(QPair<int, int>(2,1)));
VersionComboBox->addItem("2.0",QVariant::fromValue(QPair<int, int>(2,0)));
VersionComboBox->addItem("1.5",QVariant::fromValue(QPair<int, int>(1,5)));
VersionComboBox->addItem("1.4",QVariant::fromValue(QPair<int, int>(1,4)));
VersionComboBox->addItem("1.3",QVariant::fromValue(QPair<int, int>(1,3)));
VersionComboBox->addItem("1.2",QVariant::fromValue(QPair<int, int>(1,2)));
VersionComboBox->addItem("1.1",QVariant::fromValue(QPair<int, int>(1,1)));
VersionComboBox->addItem("1.0",QVariant::fromValue(QPair<int, int>(1,0)));
// Viewer Settings
connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
connect( viewerList, SIGNAL(currentRowChanged(int)), this, SLOT(updateViewerSettings(int)) );
......@@ -270,6 +292,37 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
//OpenGL
samples_spinBox->setValue(OpenFlipper::Options::samples());
QPalette warning = samplesWarning->palette();
samplesWarning->setText(QString::number(QOpenGLContext::currentContext()->format().samples()));
if(OpenFlipper::Options::samples() != QOpenGLContext::currentContext()->format().samples())
warning.setColor(samplesWarning->foregroundRole(),Qt::red);
else
warning.setColor(samplesWarning->foregroundRole(),Qt::black);
samplesWarning->setPalette(warning);
VersionComboBox->setCurrentIndex( VersionComboBox->findData(QVariant::fromValue(OpenFlipper::Options::glVersion())));
QPalette version = versionWarning->palette();
versionWarning->setText(QString("%1.%2").arg(QOpenGLContext::currentContext()->format().version().first)
.arg(QOpenGLContext::currentContext()->format().version().second));
if(OpenFlipper::Options::glVersion() != QOpenGLContext::currentContext()->format().version())
version.setColor(versionWarning->foregroundRole(),Qt::red);
else
version.setColor(versionWarning->foregroundRole(),Qt::black);
versionWarning->setPalette(version);
QPalette profile = profileWarning->palette();
profileComboBox->setCurrentIndex(OpenFlipper::Options::coreProfile()?0:1);
if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile)
profileWarning->setText("Core");
if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CompatibilityProfile)
profileWarning->setText("Compatibility");
if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::NoProfile)
profileWarning->setText("None");
if(OpenFlipper::Options::coreProfile() && QOpenGLContext::currentContext()->format().profile() != QSurfaceFormat::CoreProfile)
profile.setColor(profileWarning->foregroundRole(),Qt::red);
else
profile.setColor(profileWarning->foregroundRole(),Qt::black);
profileWarning->setPalette(profile);
//Files
logFile->setText( OpenFlipperSettings().value("Core/Log/logFile").toString() );
......@@ -585,6 +638,8 @@ void OptionsWidget::slotApply() {
//OpenGL settings
OpenFlipperSettings().setValue("Core/OpenGL/Samples",samples_spinBox->value());
OpenFlipper::Options::glVersion(VersionComboBox->currentData().value<QPair<int,int>>());
OpenFlipper::Options::coreProfile(profileComboBox->currentIndex() == 0);
//Paths settings
OpenFlipperSettings().setValue("Core/File/MaxRecent",maxRecentBox->value() ) ;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment