summaryrefslogtreecommitdiffstats
path: root/customcontext
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2014-02-11 08:55:20 -0600
committerMichael Brasser <michael.brasser@live.com>2014-02-17 17:05:40 +0100
commita3ef03417ce1eb041c8f7878f8de69fc8efb1759 (patch)
treef714d57389df6e999f69b43ac2c6f866a007ee4d /customcontext
parentfd35b9d7b6af8874d96bde5026f747de48f508bc (diff)
Make overlaprenderer and materialpreload work with Qt 5.2
When building with Qt 5.2 or higher, a warning will be printed when using the overlaprenderer, as the default batchrenderer should typically be a better alternative. materialpreload will be relevant only if the overlaprenderer is used. Change-Id: I4899f8b4f45210c03fe08b1bb0940763683c99b3 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'customcontext')
-rw-r--r--customcontext/context.cpp71
-rw-r--r--customcontext/context.h22
-rw-r--r--customcontext/customcontext.pro25
-rw-r--r--customcontext/renderer/overlaprenderer.cpp42
-rw-r--r--customcontext/renderer/overlaprenderer.h5
5 files changed, 140 insertions, 25 deletions
diff --git a/customcontext/context.cpp b/customcontext/context.cpp
index 2e9d04f..f8ac063 100644
--- a/customcontext/context.cpp
+++ b/customcontext/context.cpp
@@ -89,6 +89,12 @@
#define CONTEXT_CLASS_BASE QSGContext
#endif
+#if QT_VERSION >= 0x050200
+#ifndef QSG_NO_RENDERER_TIMING
+static bool qsg_render_timing = !qgetenv("QSG_RENDER_TIMING").isEmpty();
+#endif
+#endif
+
namespace CustomContext
{
@@ -101,9 +107,45 @@ RenderContext::RenderContext(QSGContext *ctx)
m_ditherProgram = 0;
qDebug(" - ordered 2x2 dither: %s", m_dither ? "yes" : "no");
#endif
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ m_overlapRenderer = qgetenv("CUSTOMCONTEXT_NO_OVERLAPRENDERER").isEmpty();
+ m_clipProgram = 0;
+ qDebug(" - overlaprenderer: %s", m_overlapRenderer ? "yes" : "no");
+#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
+ qDebug(" - material preload: %s", m_materialPreloading ? "yes" : "no");
+#endif
+#endif
}
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+QSGMaterialShader *RenderContext::prepareMaterial(QSGMaterial *material)
+{
+ QSGMaterialType *type = material->type();
+ QSGMaterialShader *shader = m_materials.value(type);
+ if (shader)
+ return shader;
+
+#ifndef QSG_NO_RENDER_TIMING
+ if (qsg_render_timing)
+ qsg_renderer_timer.start();
+#endif
+
+ shader = material->createShader();
+ compile(shader, material);
+ QSGRenderContext::initialize(shader);
+ m_materials[type] = shader;
+
+#ifndef QSG_NO_RENDER_TIMING
+ if (qsg_render_timing)
+ printf(" - compiling material: %dms\n", (int) qsg_renderer_timer.elapsed());
#endif
+ return shader;
+}
+#endif //CUSTOMCONTEXT_OVERLAPRENDERER
+#endif //QT_VERSION >= 0x050200
+
Context::Context(QObject *parent)
: QSGContext(parent)
, m_sampleCount(0)
@@ -119,16 +161,8 @@ Context::Context(QObject *parent)
m_sampleCount = override;
}
-#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
- m_materialPreloading = qgetenv("CUSTOMCONTEXT_NO_MATERIAL_PRELOADING").isEmpty();
-#endif
m_depthBuffer = qgetenv("CUSTOMCONTEXT_NO_DEPTH_BUFFER").isEmpty();
-#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
- m_overlapRenderer = qgetenv("CUSTOMCONTEXT_NO_OVERLAPRENDERER").isEmpty();
- m_clipProgram = 0;
-#endif
-
#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
m_animationDriver = qgetenv("CUSTOMCONTEXT_NO_ANIMATIONDRIVER").isEmpty();
#endif
@@ -164,7 +198,16 @@ Context::Context(QObject *parent)
m_dither = qgetenv("CUSTOMCONTEXT_NO_DITHER").isEmpty();
m_ditherProgram = 0;
#endif
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ m_overlapRenderer = qgetenv("CUSTOMCONTEXT_NO_OVERLAPRENDERER").isEmpty();
+ m_clipProgram = 0;
+#endif
+
+#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
+ m_materialPreloading = qgetenv("CUSTOMCONTEXT_NO_MATERIAL_PRELOADING").isEmpty();
#endif
+#endif //QT_VERSION < 0x050200
#ifdef CUSTOMCONTEXT_DEBUG
qDebug("CustomContext created:");
@@ -175,12 +218,6 @@ Context::Context(QObject *parent)
qDebug(" - program binary: yes");
#endif
-#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
- qDebug(" - material preload: %s", m_materialPreloading ? "yes" : "no");
-#endif
-#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
- qDebug(" - overlaprenderer: %s", m_overlapRenderer ? "yes" : "no");
-#endif
#ifdef CUSTOMCONTEXT_SWAPLISTENINGANIMATIONDRIVER
qDebug(" - swap listening animation driver: %s", m_swapListeningAnimationDriver ? "yes" : "no");
#endif
@@ -204,7 +241,13 @@ Context::Context(QObject *parent)
#ifdef CUSTOMCONTEXT_DITHER
qDebug(" - ordered 2x2 dither: %s", m_dither ? "yes" : "no");
#endif
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ qDebug(" - overlaprenderer: %s", m_overlapRenderer ? "yes" : "no");
+#endif
+#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
+ qDebug(" - material preload: %s", m_materialPreloading ? "yes" : "no");
#endif
+#endif //QT_VERSION < 0x050200
#ifdef CUSTOMCONTEXT_NO_DFGLYPHS
qDebug(" - distance fields disabled");
diff --git a/customcontext/context.h b/customcontext/context.h
index ac018e3..2a2a3da 100644
--- a/customcontext/context.h
+++ b/customcontext/context.h
@@ -44,6 +44,7 @@
#define CONTEXT_H
#include <private/qsgcontext_p.h>
+#include <QtCore/QElapsedTimer>
#include <QtGui/QOpenGLShaderProgram>
#ifdef CUSTOMCONTEXT_DITHER
@@ -59,6 +60,9 @@
#endif
+#if QT_VERSION >= 0x050200
+struct QSGMaterialType;
+#endif
namespace CustomContext
{
@@ -82,6 +86,20 @@ public:
bool m_dither;
OrderedDither2x2 *m_ditherProgram;
#endif
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ bool m_overlapRenderer;
+ QOpenGLShaderProgram *m_clipProgram;
+ int m_clipMatrixID;
+
+ QElapsedTimer qsg_renderer_timer;
+ QSGMaterialShader *prepareMaterial(QSGMaterial *material);
+ QHash<QSGMaterialType *, QSGMaterialShader *> m_materials;
+
+#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
+ bool m_materialPreloading;
+#endif
+#endif
};
#endif
@@ -122,12 +140,12 @@ private:
uint m_useMultisampling : 1;
uint m_depthBuffer : 1;
+#if QT_VERSION < 0x50200
+
#ifdef CUSTOMCONTEXT_MATERIALPRELOAD
bool m_materialPreloading;
#endif
-#if QT_VERSION < 0x50200
-
#ifdef CUSTOMCONTEXT_DITHER
bool m_dither;
OrderedDither2x2 *m_ditherProgram;
diff --git a/customcontext/customcontext.pro b/customcontext/customcontext.pro
index ce9de29..2660280 100644
--- a/customcontext/customcontext.pro
+++ b/customcontext/customcontext.pro
@@ -119,15 +119,24 @@ swaplistenanimationdriver:{
# Renderers
#
-!customcontext_qt520:{
- overlaprenderer:{
- message("overlaprenderer ..........: yes")
- DEFINES += CUSTOMCONTEXT_OVERLAPRENDERER
- SOURCES += renderer/overlaprenderer.cpp
- HEADERS += renderer/overlaprenderer.h
- } else {
- message("overlaprenderer ..........: no")
+overlaprenderer:{
+ message("overlaprenderer ..........: yes")
+ customcontext_qt520:{
+ message(" *** WARNING: you probably want to be using the default renderer in Qt 5.2 and higher")
+ message(" as it incorporates the optimizations of the overlaprenderer along with other optimizations ***")
+
+ materialpreload:{
+ message(" materialpreload ........: yes")
+ DEFINES += CUSTOMCONTEXT_MATERIALPRELOAD
+ } else {
+ message(" materialpreload ........: no")
+ }
}
+ DEFINES += CUSTOMCONTEXT_OVERLAPRENDERER
+ SOURCES += renderer/overlaprenderer.cpp
+ HEADERS += renderer/overlaprenderer.h
+} else {
+ message("overlaprenderer ..........: no")
}
diff --git a/customcontext/renderer/overlaprenderer.cpp b/customcontext/renderer/overlaprenderer.cpp
index 41a6c88..ea690af 100644
--- a/customcontext/renderer/overlaprenderer.cpp
+++ b/customcontext/renderer/overlaprenderer.cpp
@@ -42,8 +42,10 @@
#define GL_GLEXT_PROTOTYPES
#include "overlaprenderer.h"
+#include "context.h"
#include "qsgmaterial.h"
#include "private/qsgrendernode_p.h"
+#include "private/qsgnodeupdater_p.h"
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qpair.h>
@@ -749,7 +751,11 @@ void RenderBatch::build()
}
}
+#if QT_VERSION >= 0x050200
+Renderer::Renderer(QSGRenderContext *context)
+#else
Renderer::Renderer(QSGContext *context)
+#endif
: QSGRenderer(context)
{
}
@@ -845,6 +851,20 @@ void Renderer::nodeChanged(QSGNode *node, QSGNode::DirtyState flags)
if (flags & (QSGNode::DirtyMatrix | QSGNode::DirtyMaterial | QSGNode::DirtyOpacity | QSGNode::DirtyForceUpdate)) {
dirtyChildNodes_Transform(node);
}
+
+#if QT_VERSION >= 0x050200
+ QSGNode::DirtyState dirtyChain = flags & QSGNode::DirtyPropagationMask;
+ markNodeDirtyState(node, dirtyChain);
+
+ if (dirtyChain != 0) {
+ dirtyChain = QSGNode::DirtyState(dirtyChain << 16);
+ QSGNode *parent = node->parent();
+ while (parent) {
+ markNodeDirtyState(parent, dirtyChain);
+ parent = parent->parent();
+ }
+ }
+#endif
}
void Renderer::setClipProgram(QOpenGLShaderProgram *program, int matrixID)
@@ -1739,11 +1759,31 @@ void Renderer::drawBatches()
updates |= QSGMaterialShader::RenderState::DirtyOpacity;
m_current_determinant = bc->determinant;
+#if QT_VERSION < 0x050200
QSGMaterialShader *shader = m_context->prepareMaterial(bc->material);
+#else
+ QSGMaterialShader *shader = static_cast<CustomContext::RenderContext*>(m_context)->prepareMaterial(bc->material);
+#endif
if (shader != currentShader) {
Q_ASSERT(shader->program()->isLinked());
- if (currentShader)
+ if (currentShader) {
+#if QT_VERSION >= 0x050200
+ char const *const *attr = currentShader->attributeNames();
+ for (int j = 0; attr[j]; ++j) {
+ if (*attr[j])
+ currentShader->program()->disableAttributeArray(j);
+ }
+#endif
currentShader->deactivate();
+ }
+#if QT_VERSION >= 0x050200
+ shader->program()->bind();
+ char const *const *attr = shader->attributeNames();
+ for (int j = 0; attr[j]; ++j) {
+ if (*attr[j])
+ shader->program()->enableAttributeArray(j);
+ }
+#endif
shader->activate();
currentShader = shader;
}
diff --git a/customcontext/renderer/overlaprenderer.h b/customcontext/renderer/overlaprenderer.h
index 6fbf73f..e7ab466 100644
--- a/customcontext/renderer/overlaprenderer.h
+++ b/customcontext/renderer/overlaprenderer.h
@@ -326,7 +326,12 @@ class Renderer : public QSGRenderer
{
Q_OBJECT
public:
+#if QT_VERSION >= 0x050200
+ Renderer(QSGRenderContext *context);
+#else
Renderer(QSGContext *context);
+#endif
+
~Renderer();
void render();