Codify qt qml version in one header

This commit is contained in:
Zach Pomerantz 2016-04-07 10:13:20 -07:00
parent d79d66c34e
commit be489e8728
4 changed files with 11 additions and 4 deletions

View file

@ -12,11 +12,12 @@ const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() {
// Qt Quick may need a depth and stencil buffer. Always make sure these are available. // Qt Quick may need a depth and stencil buffer. Always make sure these are available.
format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS); format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS);
format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS); format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS);
format.setVersion(4, 5); setGLFormatVersion(format);
#ifdef DEBUG #ifdef DEBUG
format.setOption(QSurfaceFormat::DebugContext); format.setOption(QSurfaceFormat::DebugContext);
#endif #endif
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
}); });
return format; return format;
} }
@ -27,11 +28,12 @@ const QGLFormat& getDefaultGLFormat() {
static QGLFormat glFormat; static QGLFormat glFormat;
static std::once_flag once; static std::once_flag once;
std::call_once(once, [] { std::call_once(once, [] {
glFormat.setVersion(4, 5); setGLFormatVersion(glFormat);
glFormat.setProfile(QGLFormat::CoreProfile); // Requires >=Qt-4.8.0 glFormat.setProfile(QGLFormat::CoreProfile); // Requires >=Qt-4.8.0
glFormat.setSampleBuffers(false); glFormat.setSampleBuffers(false);
glFormat.setDepth(false); glFormat.setDepth(false);
glFormat.setStencil(false); glFormat.setStencil(false);
QGLFormat::setDefaultFormat(glFormat);
}); });
return glFormat; return glFormat;
} }

View file

@ -19,6 +19,9 @@
class QSurfaceFormat; class QSurfaceFormat;
class QGLFormat; class QGLFormat;
template<class F>
void setGLFormatVersion(F& format, int major = 4, int minor = 5) { format.setVersion(major, minor); }
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat(); const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
const QGLFormat& getDefaultGLFormat(); const QGLFormat& getDefaultGLFormat();
#endif #endif

View file

@ -34,6 +34,7 @@
#include <gl/QOpenGLContextWrapper.h> #include <gl/QOpenGLContextWrapper.h>
#include <gl/QOpenGLDebugLoggerWrapper.h> #include <gl/QOpenGLDebugLoggerWrapper.h>
#include <gl/GLHelpers.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <PathUtils.h> #include <PathUtils.h>
@ -141,7 +142,7 @@ public:
// Qt Quick may need a depth and stencil buffer. Always make sure these are available. // Qt Quick may need a depth and stencil buffer. Always make sure these are available.
format.setDepthBufferSize(16); format.setDepthBufferSize(16);
format.setStencilBufferSize(8); format.setStencilBufferSize(8);
format.setVersion(4, 3); setGLFormatVersion(format);
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
format.setOption(QSurfaceFormat::DebugContext); format.setOption(QSurfaceFormat::DebugContext);
format.setSwapInterval(0); format.setSwapInterval(0);

View file

@ -16,6 +16,7 @@
#include <gl/QOpenGLContextWrapper.h> #include <gl/QOpenGLContextWrapper.h>
#include <gl/QOpenGLDebugLoggerWrapper.h> #include <gl/QOpenGLDebugLoggerWrapper.h>
#include <gl/GLHelpers.h>
#include <QDir> #include <QDir>
#include <QElapsedTimer> #include <QElapsedTimer>
@ -98,7 +99,7 @@ public:
// Qt Quick may need a depth and stencil buffer. Always make sure these are available. // Qt Quick may need a depth and stencil buffer. Always make sure these are available.
format.setDepthBufferSize(16); format.setDepthBufferSize(16);
format.setStencilBufferSize(8); format.setStencilBufferSize(8);
format.setVersion(4, 1); setGLFormatVersion(format);
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
format.setOption(QSurfaceFormat::DebugContext); format.setOption(QSurfaceFormat::DebugContext);