summaryrefslogtreecommitdiffstats
path: root/customcontext
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@digia.com>2013-02-01 12:39:03 +0100
committerGunnar Sletta <gunnar.sletta@digia.com>2013-02-04 09:21:49 +0100
commit933992bb6203677fa8459b120bb78836c6e4f9ee (patch)
treec28ff637c9ab7a47ffc6be787c9abd26af2c972d /customcontext
parentb2e1111f736e23e802ce9d26cb5e1ecccc306664 (diff)
Restructured the customcontext and made it slightly more pluggable.
Change-Id: I4f69b491bd34fbf866f3174437a1b12387d47677 Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'customcontext')
-rw-r--r--customcontext/animation/animationdriver.cpp (renamed from customcontext/animationdriver.cpp)0
-rw-r--r--customcontext/animation/animationdriver.h (renamed from customcontext/animationdriver.h)0
-rw-r--r--customcontext/context.cpp236
-rw-r--r--customcontext/context.h62
-rw-r--r--customcontext/customcontext.pro68
-rw-r--r--customcontext/renderer/overlaprenderer.cpp (renamed from customcontext/overlaprenderer.cpp)0
-rw-r--r--customcontext/renderer/overlaprenderer.h (renamed from customcontext/overlaprenderer.h)0
-rw-r--r--customcontext/renderhooks/ordereddither2x2.cpp78
-rw-r--r--customcontext/renderhooks/ordereddither2x2.h34
-rw-r--r--customcontext/texture/atlastexture.cpp (renamed from customcontext/atlastexture.cpp)0
-rw-r--r--customcontext/texture/atlastexture.h (renamed from customcontext/atlastexture.h)0
11 files changed, 301 insertions, 177 deletions
diff --git a/customcontext/animationdriver.cpp b/customcontext/animation/animationdriver.cpp
index 6cf2e59..6cf2e59 100644
--- a/customcontext/animationdriver.cpp
+++ b/customcontext/animation/animationdriver.cpp
diff --git a/customcontext/animationdriver.h b/customcontext/animation/animationdriver.h
index f91da8c..f91da8c 100644
--- a/customcontext/animationdriver.h
+++ b/customcontext/animation/animationdriver.h
diff --git a/customcontext/context.cpp b/customcontext/context.cpp
index 4f326a6..5da8474 100644
--- a/customcontext/context.cpp
+++ b/customcontext/context.cpp
@@ -40,129 +40,78 @@
****************************************************************************/
#include "context.h"
-#include "animationdriver.h"
-#include "overlaprenderer.h"
-#include "QtCore/qabstractanimation.h"
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qmath.h>
+#include <QtGui/QWindow>
+#include <QtGui/QOpenGLContext>
-#ifndef DESKTOP_BUILD
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+#include "animation/animationdriver.h"
#endif
-#include <QtGui>
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+#include "renderer/overlaprenderer.h"
+#endif
-namespace CustomContext
-{
-void DitherProgram::prepare()
-{
- if (prepared)
- return;
- prepared = true;
-
- program.addShaderFromSourceCode(QOpenGLShader::Vertex,
- "attribute highp vec2 pos;\n"
- "attribute highp vec2 texCoord;\n"
- "varying highp vec2 tex;\n"
- "void main() {\n"
- " gl_Position = vec4(pos.x, pos.y, 0, 1);\n"
- " tex = texCoord;\n"
- "}");
- program.addShaderFromSourceCode(QOpenGLShader::Fragment,
- "uniform lowp sampler2D texture;"
- "varying highp vec2 tex;\n"
- "void main() {\n"
- " gl_FragColor = texture2D(texture, tex);\n"
- "}\n");
-
- program.bindAttributeLocation("pos", 0);
- program.bindAttributeLocation("texCoord", 1);
-
- program.link();
- program.setUniformValue("texture", 0);
-
- glGenTextures(1, &id_texture);
- glBindTexture(GL_TEXTURE_2D, id_texture);
-
- int data[4] = {
- 0x00000000,
- 0x02020202,
- 0x03030303,
- 0x01010101
- };
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-}
-void DitherProgram::draw(int width, int height)
+namespace CustomContext
{
- program.bind();
- program.enableAttributeArray(0);
- program.enableAttributeArray(1);
-
- float posData[] = { -1, 1, 1, 1, -1, -1, 1, -1 };
- program.setAttributeArray(0, GL_FLOAT, posData, 2);
-
- float w = width/2;
- float h = height/2;
- float texData[] = { 0, 0, w, 0, 0, h, w, h };
- program.setAttributeArray(1, GL_FLOAT, texData, 2);
-
- context->functions()->glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, id_texture);
-
- glBlendFunc(GL_ONE, GL_ONE);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- program.disableAttributeArray(0);
- program.disableAttributeArray(1);
- program.release();
-}
-
-
Context::Context(QObject *parent)
: QSGContext(parent)
- , dither(0)
- , samples(0)
- , useCustomRenderer(false)
- , useCustomAnimationDriver(false)
- , useMultisampling(false)
+ , m_sampleCount(0)
+ , m_useMultisampling(false)
{
- useMultisampling = qgetenv("QML_NO_MULTISAMPLING").isEmpty();
- if (useMultisampling) {
- samples = 4;
- QByteArray overrideSamples = qgetenv("QML_MULTISAMPLE_COUNT");
+ m_useMultisampling = qgetenv("CUSTOMCONTEXT_NO_MULTISAMPLE").isEmpty();
+ if (m_useMultisampling) {
+ m_sampleCount= 4;
+ QByteArray overrideSamples = qgetenv("CUSTOMCONTEXT_MULTISAMPLE_COUNT");
bool ok;
int override = overrideSamples.toInt(&ok);
if (ok)
- samples = override;
+ m_sampleCount = override;
}
- useCustomRenderer = qgetenv("QML_DEFAULT_RENDERER").isEmpty();
- useCustomAnimationDriver = qgetenv("QML_DEFAULT_ANIMATION_DRIVER").isEmpty();
- useDefaultTextures = !qgetenv("QML_DEFAULT_TEXTURES").isEmpty();
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ m_overlapRenderer = qgetenv("CUSTOMCONTEXT_NO_OVERLAPRENDERER").isEmpty();
+#endif
- useDithering = !qgetenv("QML_FULLSCREEN_DITHER").isEmpty();
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+ m_animationDriver = qgetenv("CUSTOMCONTEXT_NO_ANIMATIONDRIVER").isEmpty();
+#endif
+
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ m_atlasTexture = qgetenv("CUSTOMCONTEXT_NO_ATLASTEXTURE").isEmpty();
+#endif
+
+#ifdef CUSTOMCONTEXT_DITHER
+ m_dither= qgetenv("CUSTOMCONTEXT_NO_DITHER").isEmpty();
+ m_ditherProgram = 0;
+#endif
connect(this, SIGNAL(invalidated()), this, SLOT(handleInvalidated()));
+
+
#ifdef CUSTOMCONTEXT_DEBUG
qDebug("CustomContext created:");
- qDebug(" - multisampling: %s, samples=%d", useMultisampling ? "yes" : "no", samples);
- qDebug(" - renderer: %s", useCustomRenderer ? "overlap" : "default");
- qDebug(" - animation driver: %s", useCustomAnimationDriver ? "custom" : "default");
- qDebug(" - textures: %s", useDefaultTextures ? "default" : "atlas" );
- qDebug(" - dithering: %s", useDithering ? "yes" : "no");
+ qDebug(" - multisampling: %s, samples=%d", m_useMultisampling ? "enabled" : "disabled", m_sampleCount);
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ qDebug(" - overlaprenderer: %s", m_overlapRenderer ? "enabled" : "disabled");
+#endif
+
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+ qDebug(" - custom animation driver: %s", m_animationDriver ? "enabled" : "disabled");
+#endif
+
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ qDebug(" - atlas textures: %s", m_atlasTexture ? "enabled" : "disabled" );
+#endif
+
+#ifdef CUSTOMCONTEXT_DITHER
+ qDebug(" - ordered 2x2 dither: %s", m_dither ? "enabled" : "disabled");
+#endif
#endif
}
@@ -172,22 +121,14 @@ Context::Context(QObject *parent)
void Context::initialize(QOpenGLContext *context)
{
- dither = new DitherProgram(context);
-
-#if defined(EGL_WL_request_client_buffer_format) && !defined(DESKTOP_BUILD)
- EGLDisplay display = eglGetCurrentDisplay();
- const char *extensions = eglQueryString(display, EGL_EXTENSIONS);
- if (strstr(extensions, "EGL_WL_request_client_buffer_format") != 0) {
- eglRegisterBufferFormatCallbackWL(display, bufferFormatChanged, this);
- }
+#ifdef CUSTOMCONTEXT_DITHER
+ if (m_dither)
+ m_ditherProgram = new OrderedDither2x2(context);
#endif
#ifdef CUSTOMCONTEXT_DEBUG
qDebug("CustomContext: initialized..");
qDebug(" - OpenGL extensions: %s", glGetString(GL_EXTENSIONS));
-#if defined(EGL_WL_request_client_buffer_format) && !defined(DESKTOP_BUILD)
- qDebug(" - EGL extensions: %s\n", extensions);
-#endif
#endif
QSGContext::initialize(context);
@@ -197,73 +138,94 @@ void Context::invalidate()
{
QSGContext::invalidate();
- delete dither;
- dither = 0;
+#ifdef CUSTOMCONTEXT_DITHER
+ delete m_ditherProgram;
+ m_ditherProgram = 0;
+#endif
- m_atlas_manager.invalidate();
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ m_atlasManager.invalidate();
+#endif
}
-void Context::setDitherEnabled(bool enabled)
-{
- useDithering = enabled;
-}
-QSGTexture *Context::createTexture(const QImage &image) const
-{
- if (useDefaultTextures)
- return QSGContext::createTexture(image);
- else
- return const_cast<Context *>(this)->m_atlas_manager.create(image);
-}
-
QSurfaceFormat Context::defaultSurfaceFormat() const
{
QSurfaceFormat format;
format.setStencilBufferSize(8);
- if (useMultisampling)
- format.setSamples(samples);
+ if (m_useMultisampling)
+ format.setSamples(m_sampleCount);
+
+ qDebug() << "returning surface format...";
+
return format;
}
+
+
+QSGTexture *Context::createTexture(const QImage &image) const
+{
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ if (m_atlasTexture)
+ return const_cast<Context *>(this)->m_atlasManager.create(image);
+#endif
+ return QSGContext::createTexture(image);
+}
+
+
+
QSGRenderer *Context::createRenderer()
{
- if (useCustomRenderer)
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ if (m_overlapRenderer)
return new OverlapRenderer::Renderer(this);
+#endif
return QSGContext::createRenderer();
}
+
QAnimationDriver *Context::createAnimationDriver(QObject *parent)
{
- if (useCustomAnimationDriver)
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+ if (m_animationDriver)
return new AnimationDriver();
- else
- return QSGContext::createAnimationDriver(parent);
+#endif
+ return QSGContext::createAnimationDriver(parent);
}
+
QQuickTextureFactory *Context::createTextureFactory(const QImage &image)
{
+ Q_UNUSED(image);
return 0;
}
+
void Context::renderNextFrame(QSGRenderer *renderer, GLuint fbo)
{
QSGContext::renderNextFrame(renderer, fbo);
- if (useDithering) {
+#ifdef CUSTOMCONTEXT_DITHER
+ if (m_dither) {
QSurface *s = glContext()->surface();
QSize size = static_cast<QWindow *>(s)->size();
- dither->prepare();
- dither->draw(size.width(), size.height());
+ m_ditherProgram->prepare();
+ m_ditherProgram->draw(size.width(), size.height());
}
+#endif
}
+
+
void Context::handleInvalidated()
{
- m_atlas_manager.invalidate();
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ m_atlasManager.invalidate();
+#endif
}
-}; // namespace
+} // namespace
diff --git a/customcontext/context.h b/customcontext/context.h
index 7d3ca33..89be93e 100644
--- a/customcontext/context.h
+++ b/customcontext/context.h
@@ -45,31 +45,20 @@
#include <private/qsgcontext_p.h>
#include <QtGui/QOpenGLShaderProgram>
-#include "atlastexture.h"
+#ifdef CUSTOMCONTEXT_DITHER
+#include "renderhooks/ordereddither2x2.h"
+#endif
+
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+#include "texture/atlastexture.h"
+#endif
+
+
namespace CustomContext
{
-struct DitherProgram
-{
- DitherProgram(QOpenGLContext *context)
- : context(context)
- , id_size(0)
- , id_texture(0)
- , prepared(false)
- {
- }
-
- void prepare();
- void draw(int width, int height);
-
- QOpenGLShaderProgram program;
- QOpenGLContext *context;
- int id_size;
- GLuint id_texture;
- uint prepared : 1;
-};
class Context : public QSGContext
{
@@ -83,28 +72,35 @@ public:
QAnimationDriver *createAnimationDriver(QObject *parent);
QSGRenderer *createRenderer();
-
QSurfaceFormat defaultSurfaceFormat() const;
QSGTexture *createTexture(const QImage &image) const;
QQuickTextureFactory *createTextureFactory(const QImage &image);
- void setDitherEnabled(bool enabled);
-
public slots:
void handleInvalidated();
private:
- TextureAtlasManager m_atlas_manager;
- DitherProgram *dither;
- int samples;
- uint useCustomRenderer : 1;
- uint useCustomAnimationDriver : 1;
- uint useDefaultRectangles : 1;
- uint useMultisampling : 1;
- uint useDefaultTextures : 1;
- uint isCompositor : 1;
- uint useDithering : 1;
+ int m_sampleCount;
+ uint m_useMultisampling : 1;
+
+#ifdef CUSTOMCONTEXT_DITHER
+ bool m_dither;
+ OrderedDither2x2 *m_ditherProgram;
+#endif
+
+#ifdef CUSTOMCONTEXT_OVERLAPRENDERER
+ bool m_overlapRenderer;
+#endif
+
+#ifdef CUSTOMCONTEXT_ANIMATIONDRIVER
+ bool m_animationDriver;
+#endif
+
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ TextureAtlasManager m_atlasManager;
+ bool m_atlasTexture;
+#endif
};
} // namespace
diff --git a/customcontext/customcontext.pro b/customcontext/customcontext.pro
index f4269ec..2ce0ef3 100644
--- a/customcontext/customcontext.pro
+++ b/customcontext/customcontext.pro
@@ -5,18 +5,73 @@ CONFIG += plugin
QT += gui-private core-private quick-private qml-private v8-private
+
+
+verbose:{
+ message("verbose: enabled")
+ DEFINES+=CUSTOMCONTEXT_DEBUG
+} else {
+ message("verbose: disabled")
+}
+
+
+dither:{
+ message("dither: enabled")
+ DEFINES += CUSTOMCONTEXT_DITHER
+ SOURCES += renderhooks/ordereddither2x2.cpp
+ HEADERS += renderhooks/ordereddither2x2.h
+} else {
+ message("dither: disabled")
+}
+
+
+
+atlastexture:{
+ message("atlastexture: enabled")
+ DEFINES += CUSTOMCONTEXT_ATLASTEXTURE
+ SOURCES += texture/atlastexture.cpp
+ HEADERS += texture/atlastexture.h
+} else {
+ message("atlastexture: disabled")
+}
+
+
+
+animationdriver:{
+ message("animationdriver: enabled")
+ DEFINES += CUSTOMCONTEXT_ANIMATIONDRIVER
+ SOURCES += animation/animationdriver.cpp
+ HEADERS += animation/animationdriver.h
+} else {
+ message("animationdriver: disabled")
+}
+
+
+
+overlaprenderer:{
+ message("overlaprenderer: enabled")
+ DEFINES += CUSTOMCONTEXT_OVERLAPRENDERER
+ SOURCES += renderer/overlaprenderer.cpp
+ HEADERS += renderer/overlaprenderer.h
+} else {
+ message("overlaprenderer: disabled")
+}
+
+
+
+message("");
+message("Enable the above features by adding them to the qmake config, for instance:")
+message(" > qmake \"CONFIG+=verbose atlastexture dither\"");
+message("");
+
+
+
SOURCES += \
- animationdriver.cpp \
- atlastexture.cpp \
context.cpp \
- overlaprenderer.cpp \
pluginmain.cpp
HEADERS += \
- animationdriver.h \
- atlastexture.h \
context.h \
- overlaprenderer.h \
pluginmain.h
OTHER_FILES += customcontext.json
@@ -36,4 +91,3 @@ arm_build {
DEFINES += DESKTOP_BUILD
}
-verbose:DEFINES+=CUSTOMCONTEXT_DEBUG
diff --git a/customcontext/overlaprenderer.cpp b/customcontext/renderer/overlaprenderer.cpp
index 89da330..89da330 100644
--- a/customcontext/overlaprenderer.cpp
+++ b/customcontext/renderer/overlaprenderer.cpp
diff --git a/customcontext/overlaprenderer.h b/customcontext/renderer/overlaprenderer.h
index dd21eae..dd21eae 100644
--- a/customcontext/overlaprenderer.h
+++ b/customcontext/renderer/overlaprenderer.h
diff --git a/customcontext/renderhooks/ordereddither2x2.cpp b/customcontext/renderhooks/ordereddither2x2.cpp
new file mode 100644
index 0000000..30b94f6
--- /dev/null
+++ b/customcontext/renderhooks/ordereddither2x2.cpp
@@ -0,0 +1,78 @@
+#include "ordereddither2x2.h"
+
+#include <QOpenGLFunctions>
+
+namespace CustomContext {
+
+void OrderedDither2x2::prepare()
+{
+ if (prepared)
+ return;
+ prepared = true;
+
+ program.addShaderFromSourceCode(QOpenGLShader::Vertex,
+ "attribute highp vec2 pos;\n"
+ "attribute highp vec2 texCoord;\n"
+ "varying highp vec2 tex;\n"
+ "void main() {\n"
+ " gl_Position = vec4(pos.x, pos.y, 0, 1);\n"
+ " tex = texCoord;\n"
+ "}");
+ program.addShaderFromSourceCode(QOpenGLShader::Fragment,
+ "uniform lowp sampler2D texture;"
+ "varying highp vec2 tex;\n"
+ "void main() {\n"
+ " gl_FragColor = texture2D(texture, tex);\n"
+ "}\n");
+
+ program.bindAttributeLocation("pos", 0);
+ program.bindAttributeLocation("texCoord", 1);
+
+ program.link();
+ program.setUniformValue("texture", 0);
+
+ glGenTextures(1, &id_texture);
+ glBindTexture(GL_TEXTURE_2D, id_texture);
+
+ int data[4] = {
+ 0x00000000,
+ 0x02020202,
+ 0x03030303,
+ 0x01010101
+ };
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+void OrderedDither2x2::draw(int width, int height)
+{
+ program.bind();
+ program.enableAttributeArray(0);
+ program.enableAttributeArray(1);
+
+ float posData[] = { -1, 1, 1, 1, -1, -1, 1, -1 };
+ program.setAttributeArray(0, GL_FLOAT, posData, 2);
+
+ float w = width/2;
+ float h = height/2;
+ float texData[] = { 0, 0, w, 0, 0, h, w, h };
+ program.setAttributeArray(1, GL_FLOAT, texData, 2);
+
+ context->functions()->glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, id_texture);
+
+ glBlendFunc(GL_ONE, GL_ONE);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ program.disableAttributeArray(0);
+ program.disableAttributeArray(1);
+ program.release();
+}
+
+} // end of namespace
diff --git a/customcontext/renderhooks/ordereddither2x2.h b/customcontext/renderhooks/ordereddither2x2.h
new file mode 100644
index 0000000..8f2ffcf
--- /dev/null
+++ b/customcontext/renderhooks/ordereddither2x2.h
@@ -0,0 +1,34 @@
+#ifndef ORDEREDDITHER2X2_H
+#define ORDEREDDITHER2X2_H
+
+#include <QOpenGLContext>
+#include <QOpenGLShaderProgram>
+
+namespace CustomContext
+{
+
+class OrderedDither2x2
+{
+public:
+ OrderedDither2x2(QOpenGLContext *context)
+ : context(context)
+ , id_size(0)
+ , id_texture(0)
+ , prepared(false)
+ {
+ }
+
+ void prepare();
+ void draw(int width, int height);
+
+private:
+ QOpenGLShaderProgram program;
+ QOpenGLContext *context;
+ int id_size;
+ GLuint id_texture;
+ uint prepared : 1;
+};
+
+}
+
+#endif // ORDEREDDITHER2X2_H
diff --git a/customcontext/atlastexture.cpp b/customcontext/texture/atlastexture.cpp
index 8384d53..8384d53 100644
--- a/customcontext/atlastexture.cpp
+++ b/customcontext/texture/atlastexture.cpp
diff --git a/customcontext/atlastexture.h b/customcontext/texture/atlastexture.h
index 4e9b329..4e9b329 100644
--- a/customcontext/atlastexture.h
+++ b/customcontext/texture/atlastexture.h