diff options
author | Andy Nichols <andy.nichols@theqtcompany.com> | 2016-03-15 13:39:41 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-03-22 09:51:54 +0000 |
commit | 90d98e1330bd46b5defafd5d6b86fa8fe157b48d (patch) | |
tree | 722e2b1d371c6b58144d51b8167faa9d1c86e7f0 /src/quick/scenegraph/util | |
parent | e32fb877ec0662dfda41ce490d77d8bf35a377f1 (diff) |
Enable building Qt Quick module with QT_NO_OPENGL defined
Currently the Qt Quick module depends on either the OpenGL or OpenGLES
headers being available at build time. Since we are adding support for
adaptations that do not depend on OpenGL, it should be possible to build
Qt Quick in environments that do not have OpenGL development headers.
This does present many challenges though because in some cases GL types,
and classes that require OpenGL are part of the public APIs. However
since these classes were never available when QT_NO_OPENGL was defined,
it should be possible to redefine the function signatures under this
scenario, since it's not possible to break binary compatibility if there
never were any binaries to break compatibility with.
One of the bigger changes that was necessary to facilitate this change
is creating interfaces out of QSGContext and QSGRenderContext. Here the
default behavior was usage of OpenGL directly, even though subclasses
could override all OpenGL usage. Making them interfaces should bring
QSGContext and QSGRenderContext more in line with the other classes
present in the adaptation layer.
Change-Id: Iaa54dc0f6cfd18d2da1d059548abf509bd71f200
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture.cpp | 1 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture_p.h | 10 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultpainternode.cpp | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultpainternode_p.h | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdistancefieldutil.cpp | 4 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgengine.cpp | 19 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgflatcolormaterial.cpp | 16 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture.cpp | 26 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture_p.h | 8 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexturematerial.cpp | 24 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgvertexcolormaterial.cpp | 14 |
11 files changed, 95 insertions, 33 deletions
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 57468e5799..edf3739d6c 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -44,6 +44,7 @@ #include <QtCore/QtMath> #include <QtGui/QOpenGLContext> +#include <QtGui/QOpenGLFunctions> #include <QtGui/QGuiApplication> #include <QtGui/QScreen> #include <QtGui/QSurface> diff --git a/src/quick/scenegraph/util/qsgatlastexture_p.h b/src/quick/scenegraph/util/qsgatlastexture_p.h index c6f1e72a4d..da5acb3fea 100644 --- a/src/quick/scenegraph/util/qsgatlastexture_p.h +++ b/src/quick/scenegraph/util/qsgatlastexture_p.h @@ -104,17 +104,17 @@ public: QSize size() const { return m_size; } - GLuint internalFormat() const { return m_internalFormat; } - GLuint externalFormat() const { return m_externalFormat; } + uint internalFormat() const { return m_internalFormat; } + uint externalFormat() const { return m_externalFormat; } private: QSGAreaAllocator m_allocator; - GLuint m_texture_id; + unsigned int m_texture_id; QSize m_size; QList<Texture *> m_pending_uploads; - GLuint m_internalFormat; - GLuint m_externalFormat; + uint m_internalFormat; + uint m_externalFormat; uint m_allocated : 1; uint m_use_bgra_fallback: 1; diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp index 2deb993a6e..4dd60c76f5 100644 --- a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp @@ -41,6 +41,7 @@ #include <QtQuick/private/qquickpainteditem_p.h> +#include <QtQuick/private/qsgdefaultrendercontext_p.h> #include <QtQuick/private/qsgcontext_p.h> #include <private/qopenglextensions_p.h> #include <qopenglframebufferobject.h> @@ -96,7 +97,7 @@ QSGDefaultPainterNode::QSGDefaultPainterNode(QQuickPaintedItem *item) , m_dirtyRenderTarget(false) , m_dirtyTexture(false) { - m_context = static_cast<QQuickPaintedItemPrivate *>(QObjectPrivate::get(item))->sceneGraphRenderContext(); + m_context = static_cast<QSGDefaultRenderContext *>(static_cast<QQuickPaintedItemPrivate *>(QObjectPrivate::get(item))->sceneGraphRenderContext()); setMaterial(&m_materialO); setOpaqueMaterial(&m_material); diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h index 3cabe01511..069ef155b1 100644 --- a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE class QOpenGLFramebufferObject; class QOpenGLPaintDevice; +class QSGDefaultRenderContext; class Q_QUICK_PRIVATE_EXPORT QSGPainterTexture : public QSGPlainTexture { @@ -127,7 +128,7 @@ private: void updateRenderTarget(); void updateFBOSize(); - QSGRenderContext *m_context; + QSGDefaultRenderContext *m_context; QQuickPaintedItem::RenderTarget m_preferredRenderTarget; QQuickPaintedItem::RenderTarget m_actualRenderTarget; diff --git a/src/quick/scenegraph/util/qsgdistancefieldutil.cpp b/src/quick/scenegraph/util/qsgdistancefieldutil.cpp index 5eb6a6f593..65a6bcd52c 100644 --- a/src/quick/scenegraph/util/qsgdistancefieldutil.cpp +++ b/src/quick/scenegraph/util/qsgdistancefieldutil.cpp @@ -40,7 +40,9 @@ #include "qsgdistancefieldutil_p.h" #include <private/qsgadaptationlayer_p.h> -#include <QtGui/private/qopenglengineshadersource_p.h> +#ifndef QT_NO_OPENGL +# include <QtGui/private/qopenglengineshadersource_p.h> +#endif #include <QtQuick/private/qsgcontext_p.h> QT_BEGIN_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgengine.cpp b/src/quick/scenegraph/util/qsgengine.cpp index 1ef98d222d..da7a65cfec 100644 --- a/src/quick/scenegraph/util/qsgengine.cpp +++ b/src/quick/scenegraph/util/qsgengine.cpp @@ -44,6 +44,11 @@ #include <private/qsgrenderer_p.h> #include <private/qsgtexture_p.h> +#ifndef QT_NO_OPENGL +# include <QtGui/QOpenGLContext> +# include <private/qsgdefaultrendercontext_p.h> +#endif + QT_BEGIN_NAMESPACE @@ -83,7 +88,7 @@ QT_BEGIN_NAMESPACE QSGEnginePrivate::QSGEnginePrivate() : sgContext(QSGContext::createDefaultContext()) - , sgRenderContext(new QSGRenderContext(sgContext.data())) + , sgRenderContext(sgContext.data()->createRenderContext()) { } @@ -110,17 +115,23 @@ QSGEngine::~QSGEngine() */ void QSGEngine::initialize(QOpenGLContext *context) { +#ifndef QT_NO_OPENGL Q_D(QSGEngine); if (QOpenGLContext::currentContext() != context) { qWarning("WARNING: The context must be current before calling QSGEngine::initialize."); return; } - if (!d->sgRenderContext->isValid()) { - d->sgRenderContext->setAttachToGLContext(false); - d->sgRenderContext->initialize(context); + auto openGLRenderContext = static_cast<QSGDefaultRenderContext *>(d->sgRenderContext.data()); + + if (openGLRenderContext != nullptr && !openGLRenderContext->isValid()) { + openGLRenderContext->setAttachToGLContext(false); + openGLRenderContext->initialize(context); connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate); } +#else + Q_UNUSED(context) +#endif } /*! diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp index 005c7a043d..a3dfc555c4 100644 --- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp @@ -39,8 +39,9 @@ #include "qsgflatcolormaterial.h" #include <private/qsgmaterialshader_p.h> - -#include <qopenglshaderprogram.h> +#ifndef QT_NO_OPENGL +# include <qopenglshaderprogram.h> +#endif QT_BEGIN_NAMESPACE @@ -66,14 +67,16 @@ QSGMaterialType FlatColorMaterialShader::type; FlatColorMaterialShader::FlatColorMaterialShader() : QSGMaterialShader(*new QSGMaterialShaderPrivate) { +#ifndef QT_NO_OPENGL setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/flatcolor.vert")); setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/flatcolor.frag")); +#endif } void FlatColorMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) { +#ifndef QT_NO_OPENGL Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type()); - QSGFlatColorMaterial *oldMaterial = static_cast<QSGFlatColorMaterial *>(oldEffect); QSGFlatColorMaterial *newMaterial = static_cast<QSGFlatColorMaterial *>(newEffect); @@ -90,6 +93,11 @@ void FlatColorMaterialShader::updateState(const RenderState &state, QSGMaterial if (state.isMatrixDirty()) program()->setUniformValue(m_matrix_id, state.combinedMatrix()); +#else + Q_UNUSED(state) + Q_UNUSED(newEffect) + Q_UNUSED(oldEffect) +#endif } char const *const *FlatColorMaterialShader::attributeNames() const @@ -100,8 +108,10 @@ char const *const *FlatColorMaterialShader::attributeNames() const void FlatColorMaterialShader::initialize() { +#ifndef QT_NO_OPENGL m_matrix_id = program()->uniformLocation("matrix"); m_color_id = program()->uniformLocation("color"); +#endif } diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index 74390334c4..751406f12c 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qsgtexture_p.h" -#include <qopenglfunctions.h> #include <QtQuick/private/qsgcontext_p.h> #include <qthread.h> #include <qmath.h> @@ -46,9 +45,12 @@ #include <private/qqmlglobal_p.h> #include <QtGui/qguiapplication.h> #include <QtGui/qpa/qplatformnativeinterface.h> -#include <QtGui/qopenglcontext.h> -#include <QtGui/qopenglfunctions.h> - +#ifndef QT_NO_OPENGL +# include <qopenglfunctions.h> +# include <QtGui/qopenglcontext.h> +# include <QtGui/qopenglfunctions.h> +# include <private/qsgdefaultrendercontext_p.h> +#endif #include <private/qsgmaterialshader_p.h> #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && !defined(__UCLIBC__) @@ -278,6 +280,7 @@ Q_GLOBAL_STATIC(QMutex, qsg_valid_texture_mutex) bool qsg_safeguard_texture(QSGTexture *texture) { +#ifndef QT_NO_OPENGL QMutexLocker locker(qsg_valid_texture_mutex()); if (!qsg_valid_texture_set()->contains(texture)) { qWarning() << "Invalid texture accessed:" << (void *) texture; @@ -285,6 +288,7 @@ bool qsg_safeguard_texture(QSGTexture *texture) QOpenGLContext::currentContext()->functions()->glBindTexture(GL_TEXTURE_2D, 0); return false; } +#endif return true; } #endif @@ -517,6 +521,7 @@ QSGTexture::WrapMode QSGTexture::verticalWrapMode() const */ void QSGTexture::updateBindOptions(bool force) { +#ifndef QT_NO_OPENGL Q_D(QSGTexture); QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); force |= isAtlasTexture(); @@ -551,6 +556,9 @@ void QSGTexture::updateBindOptions(bool force) funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, d->verticalWrap == Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE); d->wrapChanged = false; } +#else + Q_UNUSED(force) +#endif } QSGPlainTexture::QSGPlainTexture() @@ -568,8 +576,10 @@ QSGPlainTexture::QSGPlainTexture() QSGPlainTexture::~QSGPlainTexture() { +#ifndef QT_NO_OPENGL if (m_texture_id && m_owns_texture && QOpenGLContext::currentContext()) QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id); +#endif } void qsg_swizzleBGRAToRGBA(QImage *image) @@ -601,8 +611,10 @@ int QSGPlainTexture::textureId() const // or ~QSGPlainTexture so just keep it minimal here. return 0; } else if (m_texture_id == 0){ +#ifndef QT_NO_OPENGL // Generate a texture id for use later and return it. QOpenGLContext::currentContext()->functions()->glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id); +#endif return m_texture_id; } } @@ -611,8 +623,10 @@ int QSGPlainTexture::textureId() const void QSGPlainTexture::setTextureId(int id) { +#ifndef QT_NO_OPENGL if (m_texture_id && m_owns_texture) QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id); +#endif m_texture_id = id; m_dirty_texture = false; @@ -623,6 +637,7 @@ void QSGPlainTexture::setTextureId(int id) void QSGPlainTexture::bind() { +#ifndef QT_NO_OPENGL QOpenGLContext *context = QOpenGLContext::currentContext(); QOpenGLFunctions *funcs = context->functions(); if (!m_dirty_texture) { @@ -684,7 +699,7 @@ void QSGPlainTexture::bind() // based on QSGTexture::textureSize which is updated after this, so that // should be ok. int max; - if (QSGRenderContext *rc = QSGRenderContext::from(context)) + if (auto rc = QSGDefaultRenderContext::from(context)) max = rc->maxTextureSize(); else funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); @@ -789,6 +804,7 @@ void QSGPlainTexture::bind() m_dirty_bind_options = false; if (!m_retain_image) m_image = QImage(); +#endif } diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgtexture_p.h index 5c358aecc3..a0d7eb41e3 100644 --- a/src/quick/scenegraph/util/qsgtexture_p.h +++ b/src/quick/scenegraph/util/qsgtexture_p.h @@ -53,9 +53,9 @@ #include <QtQuick/qtquickglobal.h> #include <private/qobject_p.h> - -#include <QtGui/qopengl.h> - +#ifndef QT_NO_OPENGL +# include <QtGui/qopengl.h> +#endif #include "qsgtexture.h" #include <QtQuick/private/qsgcontext_p.h> @@ -110,7 +110,7 @@ public: protected: QImage m_image; - GLuint m_texture_id; + uint m_texture_id; QSize m_texture_size; QRectF m_texture_rect; diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp index 4eb38842dc..35c5ace889 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.cpp +++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp @@ -39,9 +39,10 @@ #include "qsgtexturematerial_p.h" #include "qsgtexture_p.h" - -#include <QtGui/qopenglshaderprogram.h> -#include <QtGui/qopenglfunctions.h> +#ifndef QT_NO_OPENGL +# include <QtGui/qopenglshaderprogram.h> +# include <QtGui/qopenglfunctions.h> +#endif QT_BEGIN_NAMESPACE @@ -56,8 +57,10 @@ QSGMaterialType QSGOpaqueTextureMaterialShader::type; QSGOpaqueTextureMaterialShader::QSGOpaqueTextureMaterialShader() : QSGMaterialShader() { +#ifndef QT_NO_OPENGL setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/opaquetexture.vert")); setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/opaquetexture.frag")); +#endif } char const *const *QSGOpaqueTextureMaterialShader::attributeNames() const @@ -68,7 +71,9 @@ char const *const *QSGOpaqueTextureMaterialShader::attributeNames() const void QSGOpaqueTextureMaterialShader::initialize() { +#ifndef QT_NO_OPENGL m_matrix_id = program()->uniformLocation("qt_Matrix"); +#endif } void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) @@ -88,6 +93,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa t->setHorizontalWrapMode(tx->horizontalWrapMode()); t->setVerticalWrapMode(tx->verticalWrapMode()); +#ifndef QT_NO_OPENGL bool npotSupported = const_cast<QOpenGLContext *>(state.context()) ->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); if (!npotSupported) { @@ -98,16 +104,17 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa t->setVerticalWrapMode(QSGTexture::ClampToEdge); } } - +#endif t->setMipmapFiltering(tx->mipmapFiltering()); if (oldTx == 0 || oldTx->texture()->textureId() != t->textureId()) t->bind(); else t->updateBindOptions(); - +#ifndef QT_NO_OPENGL if (state.isMatrixDirty()) program()->setUniformValue(m_matrix_id, state.combinedMatrix()); +#endif } @@ -362,22 +369,27 @@ QSGMaterialShader *QSGTextureMaterial::createShader() const QSGTextureMaterialShader::QSGTextureMaterialShader() : QSGOpaqueTextureMaterialShader() { +#ifndef QT_NO_OPENGL setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/texture.frag")); +#endif } void QSGTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) { Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type()); +#ifndef QT_NO_OPENGL if (state.isOpacityDirty()) program()->setUniformValue(m_opacity_id, state.opacity()); - +#endif QSGOpaqueTextureMaterialShader::updateState(state, newEffect, oldEffect); } void QSGTextureMaterialShader::initialize() { QSGOpaqueTextureMaterialShader::initialize(); +#ifndef QT_NO_OPENGL m_opacity_id = program()->uniformLocation("opacity"); +#endif } QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp index 91d7ece90d..3897dfe4b2 100644 --- a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp @@ -38,9 +38,9 @@ ****************************************************************************/ #include "qsgvertexcolormaterial.h" - -#include <qopenglshaderprogram.h> - +#ifndef QT_NO_OPENGL +# include <qopenglshaderprogram.h> +#endif QT_BEGIN_NAMESPACE class QSGVertexColorMaterialShader : public QSGMaterialShader @@ -65,17 +65,23 @@ QSGMaterialType QSGVertexColorMaterialShader::type; QSGVertexColorMaterialShader::QSGVertexColorMaterialShader() : QSGMaterialShader() { +#ifndef QT_NO_OPENGL setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/vertexcolor.vert")); setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/vertexcolor.frag")); +#endif } void QSGVertexColorMaterialShader::updateState(const RenderState &state, QSGMaterial * /*newEffect*/, QSGMaterial *) { +#ifndef QT_NO_OPENGL if (state.isOpacityDirty()) program()->setUniformValue(m_opacity_id, state.opacity()); if (state.isMatrixDirty()) program()->setUniformValue(m_matrix_id, state.combinedMatrix()); +#else + Q_UNUSED(state) +#endif } char const *const *QSGVertexColorMaterialShader::attributeNames() const @@ -86,8 +92,10 @@ char const *const *QSGVertexColorMaterialShader::attributeNames() const void QSGVertexColorMaterialShader::initialize() { +#ifndef QT_NO_OPENGL m_matrix_id = program()->uniformLocation("matrix"); m_opacity_id = program()->uniformLocation("opacity"); +#endif } |