summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@jollamobile.com>2014-01-30 19:21:59 +0100
committerGunnar Sletta <gunnar.sletta@jollamobile.com>2014-01-30 19:24:59 +0100
commit96fff79274a3ff0922fdc2e253725bbe832866de (patch)
treeb9bac7c335b36991ac5c88c2d1dc9eb3296ed826
parent6379165f6ae63c3a73a62b8fa3845cc299449827 (diff)
Make customcontext work with updated 5.2.0 API.
Change-Id: I3560282009b762759f96d77db40c86610cb54e62 Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
-rw-r--r--customcontext/context.cpp60
-rw-r--r--customcontext/context.h44
-rw-r--r--customcontext/customcontext.pro144
3 files changed, 153 insertions, 95 deletions
diff --git a/customcontext/context.cpp b/customcontext/context.cpp
index 45cce7f..9762f5b 100644
--- a/customcontext/context.cpp
+++ b/customcontext/context.cpp
@@ -81,11 +81,29 @@
#include <private/qsgdefaultrectanglenode_p.h>
#endif
-
+#if QT_VERSION >= 0x050200
+#define CONTEXT_CLASS RenderContext
+#define CONTEXT_CLASS_BASE QSGRenderContext
+#else
+#define CONTEXT_CLASS Context
+#define CONTEXT_CLASS_BASE QSGContext
+#endif
namespace CustomContext
{
+#if QT_VERSION >= 0x050200
+RenderContext::RenderContext(QSGContext *ctx)
+ : QSGRenderContext(ctx)
+{
+#ifdef CUSTOMCONTEXT_DITHER
+ m_dither = qgetenv("CUSTOMCONTEXT_NO_DITHER").isEmpty();
+ m_ditherProgram = 0;
+ qDebug(" - ordered 2x2 dither: %s", m_dither ? "yes" : "no");
+#endif
+}
+#endif
+
Context::Context(QObject *parent)
: QSGContext(parent)
, m_sampleCount(0)
@@ -127,11 +145,6 @@ Context::Context(QObject *parent)
m_macTexture = qgetenv("CUSTOMCONTEXT_NO_MACTEXTURE").isEmpty();
#endif
-#ifdef CUSTOMCONTEXT_DITHER
- m_dither= qgetenv("CUSTOMCONTEXT_NO_DITHER").isEmpty();
- m_ditherProgram = 0;
-#endif
-
#ifdef CUSTOMCONTEXT_THREADUPLOADTEXTURE
m_threadUploadTexture = qgetenv("CUSTOMCONTEXT_NO_THREADUPLOADTEXTURE").isEmpty();
connect(this, SIGNAL(invalidated()), &m_threadUploadManager, SLOT(invalidated()), Qt::DirectConnection);
@@ -146,8 +159,12 @@ Context::Context(QObject *parent)
m_defaultRectangleNodes = qEnvironmentVariableIsSet("CUSTOMCONTEXT_DEFAULT_RECTANGLENODES");
#endif
-
-
+#if QT_VERSION < 0x050200
+#ifdef CUSTOMCONTEXT_DITHER
+ m_dither = qgetenv("CUSTOMCONTEXT_NO_DITHER").isEmpty();
+ m_ditherProgram = 0;
+#endif
+#endif
#ifdef CUSTOMCONTEXT_DEBUG
qDebug("CustomContext created:");
@@ -179,9 +196,11 @@ Context::Context(QObject *parent)
qDebug(" - non preserved textures: %s", m_nonPreservedTexture ? "yes" : "no");
#endif
+#if QT_VERSION < 0x050200
#ifdef CUSTOMCONTEXT_DITHER
qDebug(" - ordered 2x2 dither: %s", m_dither ? "yes" : "no");
#endif
+#endif
#ifdef CUSTOMCONTEXT_NO_DFGLYPHS
qDebug(" - distance fields disabled");
@@ -198,7 +217,7 @@ Context::Context(QObject *parent)
-void Context::initialize(QOpenGLContext *context)
+void CONTEXT_CLASS::initialize(QOpenGLContext *context)
{
#ifdef CUSTOMCONTEXT_DITHER
@@ -278,6 +297,7 @@ void Context::initialize(QOpenGLContext *context)
if (m_materialPreloading)
qDebug(" - Standard materials compiled in: %d ms", (int) prepareTimer.elapsed());
#endif
+#if QT_VERSION < 0x050200
qDebug(" - OpenGL extensions: %s", glGetString(GL_EXTENSIONS));
qDebug(" - OpenGL Vendor: %s", glGetString(GL_VENDOR));
qDebug(" - OpenGL Version: %s", glGetString(GL_VERSION));
@@ -287,14 +307,14 @@ void Context::initialize(QOpenGLContext *context)
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &textureSize);
qDebug(" - GL Max Texture Size: %d", textureSize);
#endif
+#endif
-
- QSGContext::initialize(context);
+ CONTEXT_CLASS_BASE::initialize(context);
}
-void Context::invalidate()
+void CONTEXT_CLASS::invalidate()
{
- QSGContext::invalidate();
+ CONTEXT_CLASS_BASE::invalidate();
#ifdef CUSTOMCONTEXT_DITHER
delete m_ditherProgram;
@@ -327,7 +347,7 @@ QSurfaceFormat Context::defaultSurfaceFormat() const
-QSGTexture *Context::createTexture(const QImage &image) const
+QSGTexture *CONTEXT_CLASS::createTexture(const QImage &image) const
{
#ifdef CUSTOMCONTEXT_ATLASTEXTURE
if (m_atlasTexture) {
@@ -342,12 +362,12 @@ QSGTexture *Context::createTexture(const QImage &image) const
return new MacTexture(image);
#endif
- return QSGContext::createTexture(image);
+ return CONTEXT_CLASS_BASE::createTexture(image);
}
-QSGRenderer *Context::createRenderer()
+QSGRenderer *CONTEXT_CLASS::createRenderer()
{
#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
if (m_overlapRenderer) {
@@ -357,7 +377,7 @@ QSGRenderer *Context::createRenderer()
return renderer;
}
#endif
- return QSGContext::createRenderer();
+ return CONTEXT_CLASS_BASE::createRenderer();
}
@@ -397,13 +417,13 @@ QQuickTextureFactory *Context::createTextureFactory(const QImage &image)
-void Context::renderNextFrame(QSGRenderer *renderer, GLuint fbo)
+void CONTEXT_CLASS::renderNextFrame(QSGRenderer *renderer, GLuint fbo)
{
- QSGContext::renderNextFrame(renderer, fbo);
+ CONTEXT_CLASS_BASE::renderNextFrame(renderer, fbo);
#ifdef CUSTOMCONTEXT_DITHER
if (m_dither) {
- QSurface *s = glContext()->surface();
+ QSurface *s = QOpenGLContext::currentContext()->surface();
QSize size = static_cast<QWindow *>(s)->size();
m_ditherProgram->prepare();
m_ditherProgram->draw(size.width(), size.height());
diff --git a/customcontext/context.h b/customcontext/context.h
index 8dbd025..9169eb5 100644
--- a/customcontext/context.h
+++ b/customcontext/context.h
@@ -62,7 +62,23 @@
namespace CustomContext
{
+#if QT_VERSION >= 0x050200
+class RenderContext : public QSGRenderContext
+{
+public:
+ RenderContext(QSGContext *ctx);
+ void initialize(QOpenGLContext *context);
+ void invalidate();
+ void renderNextFrame(QSGRenderer *renderer, GLuint fbo);
+ QSGTexture *createTexture(const QImage &image) const;
+ QSGRenderer *createRenderer();
+#ifdef CUSTOMCONTEXT_DITHER
+ bool m_dither;
+ OrderedDither2x2 *m_ditherProgram;
+#endif
+};
+#endif
class Context : public QSGContext
{
@@ -70,16 +86,20 @@ class Context : public QSGContext
public:
explicit Context(QObject *parent = 0);
+#if QT_VERSION >= 0x050200
+ QSGRenderContext *createRenderContext() { return new RenderContext(this); }
+#else
void initialize(QOpenGLContext *context);
void invalidate();
void renderNextFrame(QSGRenderer *renderer, GLuint fbo);
+ QSGTexture *createTexture(const QImage &image) const;
+ QSGRenderer *createRenderer();
+#endif
QAnimationDriver *createAnimationDriver(QObject *parent);
- QSGRenderer *createRenderer();
#ifdef CUSTOMCONTEXT_SURFACEFORMAT
QSurfaceFormat defaultSurfaceFormat() const;
#endif
- QSGTexture *createTexture(const QImage &image) const;
QQuickTextureFactory *createTextureFactory(const QImage &image);
#ifdef CUSTOMCONTEXT_MSAA
@@ -101,6 +121,8 @@ private:
bool m_materialPreloading;
#endif
+#if QT_VERSION < 0x50200
+
#ifdef CUSTOMCONTEXT_DITHER
bool m_dither;
OrderedDither2x2 *m_ditherProgram;
@@ -112,14 +134,6 @@ private:
int m_clipMatrixID;
#endif
-#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
- bool m_animationDriver;
-#endif
-
-#ifdef CUSTOMCONTEXT_SWAPLISTENINGANIMATIONDRIVER
- bool m_swapListeningAnimationDriver;
-#endif
-
#ifdef CUSTOMCONTEXT_ATLASTEXTURE
TextureAtlasManager m_atlasManager;
bool m_atlasTexture;
@@ -139,6 +153,16 @@ private:
friend class NonPreservedTextureFactory;
#endif
+#endif // Qt < 5.2.0
+
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+ bool m_animationDriver;
+#endif
+
+#ifdef CUSTOMCONTEXT_SWAPLISTENINGANIMATIONDRIVER
+ bool m_swapListeningAnimationDriver;
+#endif
+
#ifdef CUSTOMCONTEXT_MSAA
bool m_defaultRectangleNodes;
bool m_defaultImageNodes;
diff --git a/customcontext/customcontext.pro b/customcontext/customcontext.pro
index 6675dc0..aae5660 100644
--- a/customcontext/customcontext.pro
+++ b/customcontext/customcontext.pro
@@ -3,7 +3,15 @@ TARGET=customcontext
CONFIG += plugin
-QT += gui-private core-private quick-private qml-private v8-private
+contains(QT_VERSION, ^5\\.[2-9]\\..*) {
+ message("Using Qt 5.2 or later")
+ CONFIG += customcontext_qt520
+}
+
+QT += gui-private core-private quick-private qml-private
+!customcontext_qt520:{
+ QT += v8-private
+}
message("")
@@ -16,7 +24,6 @@ verbose:{
-
############################################################
#
# Rendering hooks
@@ -38,47 +45,48 @@ dither:{
# Textures
#
-atlastexture:{
- message("atlastexture .............: yes")
- DEFINES += CUSTOMCONTEXT_ATLASTEXTURE
- SOURCES += texture/atlastexture.cpp
- HEADERS += texture/atlastexture.h
- INCLUDEPATH += texture
-} else {
- message("atlastexture .............: no")
+!customcontext_qt520:{
+ atlastexture:{
+ message("atlastexture .............: yes")
+ DEFINES += CUSTOMCONTEXT_ATLASTEXTURE
+ SOURCES += texture/atlastexture.cpp
+ HEADERS += texture/atlastexture.h
+ INCLUDEPATH += texture
+ } else {
+ message("atlastexture .............: no")
+ }
+
+ threaduploadtexture:{
+ message("threaduploadtexture ......: yes")
+ DEFINES += CUSTOMCONTEXT_THREADUPLOADTEXTURE
+ SOURCES += texture/threaduploadtexture.cpp
+ HEADERS += texture/threaduploadtexture.h
+ INCLUDEPATH += texture
+ } else {
+ message("threaduploadtexture ......: no")
+ }
+
+ mactexture:{
+ message("mactexture ...............: yes")
+ DEFINES += CUSTOMCONTEXT_MACTEXTURE
+ SOURCES += texture/mactexture.cpp
+ HEADERS += texture/mactexture.h
+ INCLUDEPATH += texture
+ } else {
+ message("mactexture ...............: no")
+ }
+
+ nonpreservedtexture:{
+ message("nonpreservedtexture ......: yes")
+ DEFINES += CUSTOMCONTEXT_NONPRESERVEDTEXTURE
+ SOURCES += texture/nonpreservedtexture.cpp
+ HEADERS += texture/nonpreservedtexture.h
+ INCLUDEPATH += texture
+ } else {
+ message("nonpreservedtexture ......: no")
+ }
}
-threaduploadtexture:{
- message("threaduploadtexture ......: yes")
- DEFINES += CUSTOMCONTEXT_THREADUPLOADTEXTURE
- SOURCES += texture/threaduploadtexture.cpp
- HEADERS += texture/threaduploadtexture.h
- INCLUDEPATH += texture
-} else {
- message("threaduploadtexture ......: no")
-}
-
-mactexture:{
- message("mactexture ...............: yes")
- DEFINES += CUSTOMCONTEXT_MACTEXTURE
- SOURCES += texture/mactexture.cpp
- HEADERS += texture/mactexture.h
- INCLUDEPATH += texture
-} else {
- message("mactexture ...............: no")
-}
-
-nonpreservedtexture:{
- message("nonpreservedtexture ......: yes")
- DEFINES += CUSTOMCONTEXT_NONPRESERVEDTEXTURE
- SOURCES += texture/nonpreservedtexture.cpp
- HEADERS += texture/nonpreservedtexture.h
- INCLUDEPATH += texture
-} else {
- message("nonpreservedtexture ......: no")
-}
-
-
############################################################
#
@@ -110,13 +118,15 @@ swaplistenanimationdriver:{
# Renderers
#
-overlaprenderer:{
- message("overlaprenderer ..........: yes")
- DEFINES += CUSTOMCONTEXT_OVERLAPRENDERER
- SOURCES += renderer/overlaprenderer.cpp
- HEADERS += renderer/overlaprenderer.h
-} else {
- message("overlaprenderer ..........: no")
+!customcontext_qt520:{
+ overlaprenderer:{
+ message("overlaprenderer ..........: yes")
+ DEFINES += CUSTOMCONTEXT_OVERLAPRENDERER
+ SOURCES += renderer/overlaprenderer.cpp
+ HEADERS += renderer/overlaprenderer.h
+ } else {
+ message("overlaprenderer ..........: no")
+ }
}
@@ -126,26 +136,30 @@ overlaprenderer:{
# Other stuff
#
-materialpreload:{
- message("materialpreload ..........: yes")
- DEFINES += CUSTOMCONTEXT_MATERIALPRELOAD
-} else {
- message("materialpreload ..........: no")
+!customcontext_qt520:{
+ materialpreload:{
+ message("materialpreload ..........: yes")
+ DEFINES += CUSTOMCONTEXT_MATERIALPRELOAD
+ } else {
+ message("materialpreload ..........: no")
+ }
+
+ nodfglyphs:{
+ message("nodfglyphs ...............: yes")
+ DEFINES += CUSTOMCONTEXT_NO_DFGLYPHS
+ } else {
+ message("nodfglyphs ...............: no")
+ }
+
+ msaa:{
+ message("msaa .....................: yes")
+ DEFINES += CUSTOMCONTEXT_MSAA
+ } else {
+ message("msaa .....................: no")
+ }
}
-nodfglyphs:{
- message("nodfglyphs ...............: yes")
- DEFINES += CUSTOMCONTEXT_NO_DFGLYPHS
-} else {
- message("nodfglyphs ...............: no")
-}
-msaa:{
- message("msaa .....................: yes")
- DEFINES += CUSTOMCONTEXT_MSAA
-} else {
- message("msaa .....................: no")
-}
surfaceformat:{
message("surfaceformat ............: yes")