diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-04-08 15:05:21 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-23 12:23:09 +0200 |
commit | e950557e1133e8aac65a453597ab35400a5b9a10 (patch) | |
tree | 835e04f12a584274cec65efaa6071001247417ee /src/quick/scenegraph | |
parent | 8a28462c13907800caf44c16580e0b2a2ee99f69 (diff) |
Avoid direct GL calls in Quick
Change-Id: I9b8673fb3292c9d5ad2f9e8e63f56dc661699be6
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/quick/scenegraph')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 14 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgmaterial.cpp | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrenderer.cpp | 4 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgcontext.cpp | 12 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp | 189 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 26 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp | 15 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture.cpp | 57 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture.cpp | 33 |
10 files changed, 185 insertions, 171 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index c9115f35fc..d6e2487a89 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -53,6 +53,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QOpenGLVertexArrayObject> +#include <QtGui/QOpenGLFunctions_1_0> #include <private/qquickprofiler_p.h> @@ -2195,8 +2196,11 @@ void Renderer::renderUnmergedBatch(const Batch *batch) if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES) glLineWidth(g->lineWidth()); #if !defined(QT_OPENGL_ES_2) - else if (!QOpenGLContext::currentContext()->isOpenGLES() && g->drawingMode() == GL_POINTS) - glPointSize(g->lineWidth()); + else if (!QOpenGLContext::currentContext()->isOpenGLES() && g->drawingMode() == GL_POINTS) { + QOpenGLFunctions_1_0 *gl1funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_1_0>(); + gl1funcs->initializeOpenGLFunctions(); + gl1funcs->glPointSize(g->lineWidth()); + } #endif if (g->indexCount()) @@ -2227,11 +2231,7 @@ void Renderer::renderBatches() glClearColor(clearColor().redF(), clearColor().greenF(), clearColor().blueF(), clearColor().alphaF()); if (m_useDepthBuffer) { -#if defined(QT_OPENGL_ES) - glClearDepthf(1); -#else - glClearDepth(1); -#endif + glClearDepthf(1); // calls glClearDepth() under the hood for desktop OpenGL glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthMask(true); diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.cpp b/src/quick/scenegraph/coreapi/qsgmaterial.cpp index 22fe29959e..c4800a5cac 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterial.cpp +++ b/src/quick/scenegraph/coreapi/qsgmaterial.cpp @@ -346,7 +346,8 @@ void QSGMaterialShader::compile() char const *const *attr = attributeNames(); #ifndef QT_NO_DEBUG int maxVertexAttribs = 0; - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); for (int i = 0; attr[i]; ++i) { if (i >= maxVertexAttribs) { qFatal("List of attribute names is either too long or not null-terminated.\n" diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp index cc8793c0cf..4a26eae6cd 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp @@ -76,13 +76,13 @@ void QSGBindable::clear(QSGRenderer::ClearMode mode) const if (mode & QSGRenderer::ClearColorBuffer) bits |= GL_COLOR_BUFFER_BIT; if (mode & QSGRenderer::ClearDepthBuffer) bits |= GL_DEPTH_BUFFER_BIT; if (mode & QSGRenderer::ClearStencilBuffer) bits |= GL_STENCIL_BUFFER_BIT; - glClear(bits); + QOpenGLContext::currentContext()->functions()->glClear(bits); } // Reactivate the color buffer after switching to the stencil. void QSGBindable::reactivate() const { - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + QOpenGLContext::currentContext()->functions()->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } QSGBindableFbo::QSGBindableFbo(QOpenGLFramebufferObject *fbo) : m_fbo(fbo) diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index 64506d1c26..99b52a65cb 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -207,13 +207,14 @@ void QSGContext::renderContextInitialized(QSGRenderContext *renderContext) if (!dumped && qEnvironmentVariableIsSet("QSG_INFO")) { dumped = true; QSurfaceFormat format = renderContext->openglContext()->format(); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); qDebug() << "R/G/B/A Buffers: " << format.redBufferSize() << format.greenBufferSize() << format.blueBufferSize() << format.alphaBufferSize(); qDebug() << "Depth Buffer: " << format.depthBufferSize(); qDebug() << "Stencil Buffer: " << format.stencilBufferSize(); qDebug() << "Samples: " << format.samples(); - qDebug() << "GL_VENDOR: " << (const char *) glGetString(GL_VENDOR); - qDebug() << "GL_RENDERER: " << (const char *) glGetString(GL_RENDERER); - qDebug() << "GL_VERSION: " << (const char *) glGetString(GL_VERSION); + qDebug() << "GL_VENDOR: " << (const char *) funcs->glGetString(GL_VENDOR); + qDebug() << "GL_RENDERER: " << (const char *) funcs->glGetString(GL_RENDERER); + qDebug() << "GL_VERSION: " << (const char *) funcs->glGetString(GL_VERSION); QSet<QByteArray> exts = renderContext->openglContext()->extensions(); QByteArray all; foreach (const QByteArray &e, exts) all += ' ' + e; qDebug() << "GL_EXTENSIONS: " << all.constData(); @@ -441,10 +442,11 @@ void QSGRenderContext::initialize(QOpenGLContext *context) m_sg->renderContextInitialized(this); #ifdef Q_OS_LINUX - const char *vendor = (const char *) glGetString(GL_VENDOR); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + const char *vendor = (const char *) funcs->glGetString(GL_VENDOR); if (strstr(vendor, "nouveau")) m_brokenIBOs = true; - const char *renderer = (const char *) glGetString(GL_RENDERER); + const char *renderer = (const char *) funcs->glGetString(GL_RENDERER); if (strstr(renderer, "llvmpipe")) m_serializedRender = true; if (strstr(vendor, "Hisilicon Technologies") && strstr(renderer, "Immersion.16")) diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp index 48b405467b..5257cfda3d 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp @@ -63,8 +63,9 @@ QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistance , m_blitProgram(0) , m_blitBuffer(QOpenGLBuffer::VertexBuffer) , m_fboGuard(0) + , m_funcs(c->functions()) #if !defined(QT_OPENGL_ES_2) - , m_funcs(0) + , m_coreFuncs(0) #endif { m_blitBuffer.create(); @@ -80,7 +81,7 @@ QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistance QSGDefaultDistanceFieldGlyphCache::~QSGDefaultDistanceFieldGlyphCache() { for (int i = 0; i < m_textures.count(); ++i) - glDeleteTextures(1, &m_textures[i].texture); + m_funcs->glDeleteTextures(1, &m_textures[i].texture); if (m_fboGuard != 0) m_fboGuard->free(); @@ -144,10 +145,10 @@ void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> QHash<TextureInfo *, QVector<glyph_t> > glyphTextures; GLint alignment = 4; // default value - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + m_funcs->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); // Distance field data is always tightly packed - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (int i = 0; i < glyphs.size(); ++i) { QDistanceField glyph = glyphs.at(i); @@ -156,7 +157,7 @@ void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> TextureInfo *texInfo = m_glyphsTexture.value(glyphIndex); resizeTexture(texInfo, texInfo->allocatedArea.width(), texInfo->allocatedArea.height()); - glBindTexture(GL_TEXTURE_2D, texInfo->texture); + m_funcs->glBindTexture(GL_TEXTURE_2D, texInfo->texture); glyphTextures[texInfo].append(glyphIndex); @@ -181,21 +182,21 @@ void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> #endif if (useTextureUploadWorkaround()) { for (int i = 0; i < glyph.height(); ++i) { - glTexSubImage2D(GL_TEXTURE_2D, 0, - c.x, c.y + i, glyph.width(),1, - format, GL_UNSIGNED_BYTE, - glyph.scanLine(i)); + m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, + c.x, c.y + i, glyph.width(),1, + format, GL_UNSIGNED_BYTE, + glyph.scanLine(i)); } } else { - glTexSubImage2D(GL_TEXTURE_2D, 0, - c.x, c.y, glyph.width(), glyph.height(), - format, GL_UNSIGNED_BYTE, - glyph.constBits()); + m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, + c.x, c.y, glyph.width(), glyph.height(), + format, GL_UNSIGNED_BYTE, + glyph.constBits()); } } // restore to previous alignment - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); + m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); QHash<TextureInfo *, QVector<glyph_t> >::const_iterator i; for (i = glyphTextures.constBegin(); i != glyphTextures.constEnd(); ++i) { @@ -221,18 +222,18 @@ void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo, int if (useTextureResizeWorkaround() && texInfo->image.isNull()) texInfo->image = QDistanceField(width, height); - while (glGetError() != GL_NO_ERROR) { } + while (m_funcs->glGetError() != GL_NO_ERROR) { } - glGenTextures(1, &texInfo->texture); - glBindTexture(GL_TEXTURE_2D, texInfo->texture); + m_funcs->glGenTextures(1, &texInfo->texture); + m_funcs->glBindTexture(GL_TEXTURE_2D, texInfo->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #if !defined(QT_OPENGL_ES_2) if (!QOpenGLContext::currentContext()->isOpenGLES()) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); const GLint internalFormat = isCoreProfile() ? GL_R8 : GL_ALPHA; const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA; #else @@ -240,14 +241,14 @@ void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo, int const GLenum format = GL_ALPHA; #endif - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, 0); + m_funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, 0); texInfo->size = QSize(width, height); - GLuint error = glGetError(); + GLuint error = m_funcs->glGetError(); if (error != GL_NO_ERROR) { - glBindTexture(GL_TEXTURE_2D, 0); - glDeleteTextures(1, &texInfo->texture); + m_funcs->glBindTexture(GL_TEXTURE_2D, 0); + m_funcs->glDeleteTextures(1, &texInfo->texture); texInfo->texture = 0; } @@ -281,42 +282,42 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int // For an OpenGL Core Profile we can use http://www.opengl.org/wiki/Framebuffer#Blitting // to efficiently copy the contents of the old texture to the new texture // TODO: Use ARB_copy_image if available of if we have >=4.3 context - if (!m_funcs) { - m_funcs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>(); - Q_ASSERT(m_funcs); - m_funcs->initializeOpenGLFunctions(); + if (!m_coreFuncs) { + m_coreFuncs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>(); + Q_ASSERT(m_coreFuncs); + m_coreFuncs->initializeOpenGLFunctions(); } // Create a framebuffer object to which we can attach our old and new textures (to // the first two color buffer attachment points) if (!m_fboGuard) { GLuint fbo; - m_funcs->glGenFramebuffers(1, &fbo); + m_coreFuncs->glGenFramebuffers(1, &fbo); m_fboGuard = new QOpenGLSharedResourceGuard(ctx, fbo, freeFramebufferFunc); } // Bind the FBO to both the GL_READ_FRAMEBUFFER? and GL_DRAW_FRAMEBUFFER targets - m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); + m_coreFuncs->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); // Bind the old texture to GL_COLOR_ATTACHMENT0 - m_funcs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + m_coreFuncs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, oldTexture, 0); // Bind the new texture to GL_COLOR_ATTACHMENT1 - m_funcs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, + m_coreFuncs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texInfo->texture, 0); // Set the source and destination buffers - m_funcs->glReadBuffer(GL_COLOR_ATTACHMENT0); - m_funcs->glDrawBuffer(GL_COLOR_ATTACHMENT1); + m_coreFuncs->glReadBuffer(GL_COLOR_ATTACHMENT0); + m_coreFuncs->glDrawBuffer(GL_COLOR_ATTACHMENT1); // Do the blit - m_funcs->glBlitFramebuffer(0, 0, oldWidth, oldHeight, + m_coreFuncs->glBlitFramebuffer(0, 0, oldWidth, oldHeight, 0, 0, oldWidth, oldHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); // Reset the default framebuffer - m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, 0); + m_coreFuncs->glBindFramebuffer(GL_FRAMEBUFFER, 0); return; } else if (useTextureResizeWorkaround()) { @@ -324,8 +325,8 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int if (useTextureResizeWorkaround()) { #endif GLint alignment = 4; // default value - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + m_funcs->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #if !defined(QT_OPENGL_ES_2) const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA; @@ -335,22 +336,22 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int if (useTextureUploadWorkaround()) { for (int i = 0; i < texInfo->image.height(); ++i) { - glTexSubImage2D(GL_TEXTURE_2D, 0, - 0, i, oldWidth, 1, - format, GL_UNSIGNED_BYTE, - texInfo->image.scanLine(i)); + m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, + 0, i, oldWidth, 1, + format, GL_UNSIGNED_BYTE, + texInfo->image.scanLine(i)); } } else { - glTexSubImage2D(GL_TEXTURE_2D, 0, - 0, 0, oldWidth, oldHeight, - format, GL_UNSIGNED_BYTE, - texInfo->image.constBits()); + m_funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, + 0, 0, oldWidth, oldHeight, + format, GL_UNSIGNED_BYTE, + texInfo->image.constBits()); } - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); // restore to previous value + m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); // restore to previous value texInfo->image = texInfo->image.copy(0, 0, width, height); - glDeleteTextures(1, &oldTexture); + m_funcs->glDeleteTextures(1, &oldTexture); return; } @@ -361,30 +362,30 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int if (!m_fboGuard) { GLuint fbo; - ctx->functions()->glGenFramebuffers(1, &fbo); + m_funcs->glGenFramebuffers(1, &fbo); m_fboGuard = new QOpenGLSharedResourceGuard(ctx, fbo, freeFramebufferFunc); } - ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); + m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); GLuint tmp_texture; - glGenTextures(1, &tmp_texture); - glBindTexture(GL_TEXTURE_2D, tmp_texture); - 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_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + m_funcs->glGenTextures(1, &tmp_texture); + m_funcs->glBindTexture(GL_TEXTURE_2D, tmp_texture); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #if !defined(QT_OPENGL_ES_2) if (!ctx->isOpenGLES()) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); #endif - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, 0); - ctx->functions()->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, tmp_texture, 0); + m_funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + m_funcs->glBindTexture(GL_TEXTURE_2D, 0); + m_funcs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, tmp_texture, 0); - ctx->functions()->glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, oldTexture); + m_funcs->glActiveTexture(GL_TEXTURE0); + m_funcs->glBindTexture(GL_TEXTURE_2D, oldTexture); // save current render states GLboolean stencilTestEnabled; @@ -393,19 +394,19 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int GLboolean blendEnabled; GLint viewport[4]; GLint oldProgram; - glGetBooleanv(GL_STENCIL_TEST, &stencilTestEnabled); - glGetBooleanv(GL_DEPTH_TEST, &depthTestEnabled); - glGetBooleanv(GL_SCISSOR_TEST, &scissorTestEnabled); - glGetBooleanv(GL_BLEND, &blendEnabled); - glGetIntegerv(GL_VIEWPORT, &viewport[0]); - glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgram); + m_funcs->glGetBooleanv(GL_STENCIL_TEST, &stencilTestEnabled); + m_funcs->glGetBooleanv(GL_DEPTH_TEST, &depthTestEnabled); + m_funcs->glGetBooleanv(GL_SCISSOR_TEST, &scissorTestEnabled); + m_funcs->glGetBooleanv(GL_BLEND, &blendEnabled); + m_funcs->glGetIntegerv(GL_VIEWPORT, &viewport[0]); + m_funcs->glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgram); - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - glDisable(GL_SCISSOR_TEST); - glDisable(GL_BLEND); + m_funcs->glDisable(GL_STENCIL_TEST); + m_funcs->glDisable(GL_DEPTH_TEST); + m_funcs->glDisable(GL_SCISSOR_TEST); + m_funcs->glDisable(GL_BLEND); - glViewport(0, 0, oldWidth, oldHeight); + m_funcs->glViewport(0, 0, oldWidth, oldHeight); const bool vaoInit = m_vao.isCreated(); if (isCoreProfile()) { @@ -425,35 +426,35 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR)); m_blitProgram->setUniformValue("imageTexture", GLuint(0)); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + m_funcs->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glBindTexture(GL_TEXTURE_2D, texInfo->texture); + m_funcs->glBindTexture(GL_TEXTURE_2D, texInfo->texture); if (useTextureUploadWorkaround()) { for (int i = 0; i < oldHeight; ++i) - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, 0, i, oldWidth, 1); + m_funcs->glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, 0, i, oldWidth, 1); } else { - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight); + m_funcs->glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight); } - ctx->functions()->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, 0); - glDeleteTextures(1, &tmp_texture); - glDeleteTextures(1, &oldTexture); + m_funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, 0); + m_funcs->glDeleteTextures(1, &tmp_texture); + m_funcs->glDeleteTextures(1, &oldTexture); - ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, 0); + m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, 0); // restore render states if (stencilTestEnabled) - glEnable(GL_STENCIL_TEST); + m_funcs->glEnable(GL_STENCIL_TEST); if (depthTestEnabled) - glEnable(GL_DEPTH_TEST); + m_funcs->glEnable(GL_DEPTH_TEST); if (scissorTestEnabled) - glEnable(GL_SCISSOR_TEST); + m_funcs->glEnable(GL_SCISSOR_TEST); if (blendEnabled) - glEnable(GL_BLEND); - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); - ctx->functions()->glUseProgram(oldProgram); + m_funcs->glEnable(GL_BLEND); + m_funcs->glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + m_funcs->glUseProgram(oldProgram); m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); @@ -479,7 +480,7 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const static bool set = false; static bool useWorkaround = false; if (!set) { - useWorkaround = qstrcmp(reinterpret_cast<const char*>(glGetString(GL_RENDERER)), + useWorkaround = qstrcmp(reinterpret_cast<const char*>(m_funcs->glGetString(GL_RENDERER)), "Mali-400 MP") == 0; set = true; } @@ -489,7 +490,7 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const int QSGDefaultDistanceFieldGlyphCache::maxTextureSize() const { if (!m_maxTextureSize) - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); + m_funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); return m_maxTextureSize; } diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h index e1be2105cd..b04b03acdf 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h @@ -139,8 +139,9 @@ private: QOpenGLVertexArrayObject m_vao; QOpenGLSharedResourceGuard *m_fboGuard; + QOpenGLFunctions *m_funcs; #if !defined(QT_OPENGL_ES_2) - QOpenGLFunctions_3_2_Core *m_funcs; + QOpenGLFunctions_3_2_Core *m_coreFuncs; #endif }; diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index cd462f2fb8..a69cbc54ea 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -125,13 +125,14 @@ void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEf || oldMaterial->texture()->textureId() != material->texture()->textureId()) { program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(), 1.0 / material->cacheTextureHeight())); - glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); // Set the mag/min filters to be nearest. We only need to do this when the texture // has been recreated. if (updated) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } } @@ -215,16 +216,18 @@ void QSG24BitTextMaskShader::initialize() void QSG24BitTextMaskShader::activate() { - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); if (m_useSRGB) - glEnable(GL_FRAMEBUFFER_SRGB); + funcs->glEnable(GL_FRAMEBUFFER_SRGB); } void QSG24BitTextMaskShader::deactivate() { - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if (m_useSRGB) - glDisable(GL_FRAMEBUFFER_SRGB); + funcs->glDisable(GL_FRAMEBUFFER_SRGB); } static inline qreal qt_sRGB_to_linear_RGB(qreal f) @@ -250,7 +253,7 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial * QVector4D color = material->color(); if (m_useSRGB) color = qt_sRGB_to_linear_RGB(color); - state.context()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w()); + QOpenGLContext::currentContext()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w()); color = qsg_premultiply(color, state.opacity()); program()->setUniformValue(m_color_id, color.w()); } @@ -313,13 +316,14 @@ void QSGStyledTextShader::updateState(const RenderState &state, || oldMaterial->texture()->textureId() != material->texture()->textureId()) { program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(), 1.0 / material->cacheTextureHeight())); - glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); // Set the mag/min filters to be linear. We only need to do this when the texture // has been recreated. if (updated) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } } diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp index 12a431246c..33cb8edf16 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -178,15 +178,16 @@ void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, Q updateTextureScale(QVector2D(1.0 / material->textureSize().width(), 1.0 / material->textureSize().height())); - glBindTexture(GL_TEXTURE_2D, material->texture()->textureId); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId); if (updated) { // Set the mag/min filters to be linear. We only need to do this when the texture // has been recreated. - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } } } @@ -511,13 +512,13 @@ void QSGHiQSubPixelDistanceFieldTextMaterialShader::initialize() void QSGHiQSubPixelDistanceFieldTextMaterialShader::activate() { QSGDistanceFieldTextMaterialShader::activate(); - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); + QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); } void QSGHiQSubPixelDistanceFieldTextMaterialShader::deactivate() { QSGDistanceFieldTextMaterialShader::deactivate(); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 90f4f36ac8..ae9390a74b 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -99,7 +99,7 @@ Manager::Manager() QSurface *surface = gl->surface(); QSize surfaceSize = surface->size(); int max; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); + gl->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); int w = qMin(max, qsg_envInt("QSG_ATLAS_WIDTH", qMax(512, qsg_powerOfTwo(surfaceSize.width())))); int h = qMin(max, qsg_envInt("QSG_ATLAS_HEIGHT", qMax(512, qsg_powerOfTwo(surfaceSize.height())))); @@ -171,7 +171,7 @@ Atlas::Atlas(const QSize &size) static bool wrongfullyReportsBgra8888Support = false; #endif // ANDROID - const char *ext = (const char *) glGetString(GL_EXTENSIONS); + const char *ext = (const char *) QOpenGLContext::currentContext()->functions()->glGetString(GL_EXTENSIONS); if (!wrongfullyReportsBgra8888Support && (strstr(ext, "GL_EXT_bgra") || strstr(ext, "GL_EXT_texture_format_BGRA8888") @@ -202,7 +202,7 @@ Atlas::~Atlas() void Atlas::invalidate() { if (m_texture_id && QOpenGLContext::currentContext()) - glDeleteTextures(1, &m_texture_id); + QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id); m_texture_id = 0; } @@ -223,7 +223,7 @@ int Atlas::textureId() const { if (!m_texture_id) { Q_ASSERT(QOpenGLContext::currentContext()); - glGenTextures(1, &const_cast<Atlas *>(this)->m_texture_id); + QOpenGLContext::currentContext()->functions()->glGenTextures(1, &const_cast<Atlas *>(this)->m_texture_id); } return m_texture_id; @@ -274,11 +274,14 @@ void Atlas::upload(Texture *texture) if (m_externalFormat == GL_RGBA) swizzleBGRAToRGBA(&tmp); - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), r.width(), r.height(), m_externalFormat, GL_UNSIGNED_BYTE, tmp.constBits()); + QOpenGLContext::currentContext()->functions()->glTexSubImage2D(GL_TEXTURE_2D, 0, + r.x(), r.y(), r.width(), r.height(), + m_externalFormat, GL_UNSIGNED_BYTE, tmp.constBits()); } void Atlas::uploadBgra(Texture *texture) { + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); const QRect &r = texture->atlasSubRect(); QImage image = texture->image(); @@ -304,48 +307,48 @@ void Atlas::uploadBgra(Texture *texture) dst[0] = src[0]; memcpy(dst + 1, src, iw * sizeof(quint32)); dst[1 + iw] = src[iw-1]; - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), iw + 2, 1, m_externalFormat, GL_UNSIGNED_BYTE, dst); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), iw + 2, 1, m_externalFormat, GL_UNSIGNED_BYTE, dst); // bottom row, padded corners const quint32 *lastRow = src + bpl * (ih - 1); dst[0] = lastRow[0]; memcpy(dst + 1, lastRow, iw * sizeof(quint32)); dst[1 + iw] = lastRow[iw-1]; - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y() + ih + 1, iw + 2, 1, m_externalFormat, GL_UNSIGNED_BYTE, dst); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y() + ih + 1, iw + 2, 1, m_externalFormat, GL_UNSIGNED_BYTE, dst); // left column for (int i=0; i<ih; ++i) dst[i] = src[i * bpl]; - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y() + 1, 1, ih, m_externalFormat, GL_UNSIGNED_BYTE, dst); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y() + 1, 1, ih, m_externalFormat, GL_UNSIGNED_BYTE, dst); // right column for (int i=0; i<ih; ++i) dst[i] = src[i * bpl + iw - 1]; - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x() + iw + 1, r.y() + 1, 1, ih, m_externalFormat, GL_UNSIGNED_BYTE, dst); + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, r.x() + iw + 1, r.y() + 1, 1, ih, m_externalFormat, GL_UNSIGNED_BYTE, dst); // Inner part of the image.... - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, m_externalFormat, GL_UNSIGNED_BYTE, src); - + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, m_externalFormat, GL_UNSIGNED_BYTE, src); } void Atlas::bind(QSGTexture::Filtering filtering) { + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); if (!m_allocated) { m_allocated = true; - while (glGetError() != GL_NO_ERROR) ; + while (funcs->glGetError() != GL_NO_ERROR) ; - glGenTextures(1, &m_texture_id); - glBindTexture(GL_TEXTURE_2D, m_texture_id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + funcs->glGenTextures(1, &m_texture_id); + funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #if !defined(QT_OPENGL_ES_2) if (!QOpenGLContext::currentContext()->isOpenGLES()) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); #endif - glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_size.width(), m_size.height(), 0, m_externalFormat, GL_UNSIGNED_BYTE, 0); + funcs->glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_size.width(), m_size.height(), 0, m_externalFormat, GL_UNSIGNED_BYTE, 0); #if 0 QImage pink(m_size.width(), m_size.height(), QImage::Format_ARGB32_Premultiplied); @@ -362,21 +365,21 @@ void Atlas::bind(QSGTexture::Filtering filtering) p.fillRect(0, 0, m_size.width(), m_size.height(), blueGrad); p.end(); - glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_size.width(), m_size.height(), 0, m_externalFormat, GL_UNSIGNED_BYTE, pink.constBits()); + funcs->glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_size.width(), m_size.height(), 0, m_externalFormat, GL_UNSIGNED_BYTE, pink.constBits()); #endif - GLenum errorCode = glGetError(); + GLenum errorCode = funcs->glGetError(); if (errorCode == GL_OUT_OF_MEMORY) { qDebug("QSGTextureAtlas: texture atlas allocation failed, out of memory"); - glDeleteTextures(1, &m_texture_id); + funcs->glDeleteTextures(1, &m_texture_id); m_texture_id = 0; } else if (errorCode != GL_NO_ERROR) { qDebug("QSGTextureAtlas: texture atlas allocation failed, code=%x", errorCode); - glDeleteTextures(1, &m_texture_id); + funcs->glDeleteTextures(1, &m_texture_id); m_texture_id = 0; } } else { - glBindTexture(GL_TEXTURE_2D, m_texture_id); + funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id); } if (m_texture_id == 0) @@ -416,8 +419,8 @@ void Atlas::bind(QSGTexture::Filtering filtering) } GLenum f = filtering == QSGTexture::Nearest ? GL_NEAREST : GL_LINEAR; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, f); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, f); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, f); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, f); m_pending_uploads.clear(); } diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index cd0b64fe49..882c78b361 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -496,6 +496,7 @@ QSGTexture::WrapMode QSGTexture::verticalWrapMode() const void QSGTexture::updateBindOptions(bool force) { Q_D(QSGTexture); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); force |= isAtlasTexture(); if (force || d->filteringChanged) { @@ -509,8 +510,8 @@ void QSGTexture::updateBindOptions(bool force) else if (d->mipmapMode == Linear) minFilter = linear ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_LINEAR; } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); d->filteringChanged = false; } @@ -524,8 +525,8 @@ void QSGTexture::updateBindOptions(bool force) qWarning("Scene Graph: This system does not support the REPEAT wrap mode for non-power-of-two textures."); } #endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, d->horizontalWrap == Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, d->verticalWrap == Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, d->horizontalWrap == Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, d->verticalWrap == Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE); d->wrapChanged = false; } } @@ -546,7 +547,7 @@ QSGPlainTexture::QSGPlainTexture() QSGPlainTexture::~QSGPlainTexture() { if (m_texture_id && m_owns_texture) - glDeleteTextures(1, &m_texture_id); + QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id); } void qsg_swizzleBGRAToRGBA(QImage *image) @@ -579,7 +580,7 @@ int QSGPlainTexture::textureId() const return 0; } else if (m_texture_id == 0){ // Generate a texture id for use later and return it. - glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id); + QOpenGLContext::currentContext()->functions()->glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id); return m_texture_id; } } @@ -589,7 +590,7 @@ int QSGPlainTexture::textureId() const void QSGPlainTexture::setTextureId(int id) { if (m_texture_id && m_owns_texture) - glDeleteTextures(1, &m_texture_id); + QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id); m_texture_id = id; m_dirty_texture = false; @@ -600,11 +601,12 @@ void QSGPlainTexture::setTextureId(int id) void QSGPlainTexture::bind() { + QOpenGLContext *context = QOpenGLContext::currentContext(); + QOpenGLFunctions *funcs = context->functions(); if (!m_dirty_texture) { - glBindTexture(GL_TEXTURE_2D, m_texture_id); + funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id); if (mipmapFiltering() != QSGTexture::None && !m_mipmaps_generated) { - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); + funcs->glGenerateMipmap(GL_TEXTURE_2D); m_mipmaps_generated = true; } updateBindOptions(m_dirty_bind_options); @@ -622,7 +624,7 @@ void QSGPlainTexture::bind() if (m_image.isNull()) { if (m_texture_id && m_owns_texture) { - glDeleteTextures(1, &m_texture_id); + funcs->glDeleteTextures(1, &m_texture_id); #ifndef QSG_NO_RENDER_TIMING if (qsg_render_timing) { qDebug(" - texture deleted in %dms (size: %dx%d)", @@ -642,8 +644,8 @@ void QSGPlainTexture::bind() } if (m_texture_id == 0) - glGenTextures(1, &m_texture_id); - glBindTexture(GL_TEXTURE_2D, m_texture_id); + funcs->glGenTextures(1, &m_texture_id); + funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id); #ifndef QSG_NO_RENDER_TIMING qint64 bindTime = 0; @@ -683,7 +685,6 @@ void QSGPlainTexture::bind() static bool wrongfullyReportsBgra8888Support = false; #endif - QOpenGLContext *context = QOpenGLContext::currentContext(); if (context->hasExtension(QByteArrayLiteral("GL_EXT_bgra"))) { externalFormat = GL_BGRA; #ifdef QT_OPENGL_ES @@ -711,7 +712,7 @@ void QSGPlainTexture::bind() if (profileFrames) swizzleTime = qsg_renderer_timer.nsecsElapsed(); #endif - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, externalFormat, GL_UNSIGNED_BYTE, tmp.constBits()); + funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, externalFormat, GL_UNSIGNED_BYTE, tmp.constBits()); #ifndef QSG_NO_RENDER_TIMING qint64 uploadTime = 0; @@ -721,7 +722,7 @@ void QSGPlainTexture::bind() if (mipmapFiltering() != QSGTexture::None) { - context->functions()->glGenerateMipmap(GL_TEXTURE_2D); + funcs->glGenerateMipmap(GL_TEXTURE_2D); m_mipmaps_generated = true; } |