diff options
Diffstat (limited to 'src/opengl')
42 files changed, 404 insertions, 153 deletions
diff --git a/src/opengl/CMakeLists.txt b/src/opengl/CMakeLists.txt index 8aec1c685b..825e4cb71b 100644 --- a/src/opengl/CMakeLists.txt +++ b/src/opengl/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from opengl.pro. - ##################################################################### ## OpenGL Module: ##################################################################### @@ -35,9 +33,13 @@ qt_internal_add_module(OpenGL qopenglvertexarrayobject.cpp qopenglvertexarrayobject.h qopenglvertexarrayobject_p.h qopenglwindow.cpp qopenglwindow.h qtopenglglobal.h + NO_UNITY_BUILD_SOURCES + qopengltextureblitter.cpp # qDebug()<< ambiguities DEFINES + QT_NO_CONTEXTLESS_CONNECT QT_NO_FOREACH QT_NO_USING_NAMESPACE + QT_USE_NODISCARD_FILE_OPEN LIBRARIES Qt::CorePrivate Qt::GuiPrivate @@ -53,6 +55,11 @@ qt_internal_add_module(OpenGL ## Scopes: ##################################################################### +qt_internal_extend_target(OpenGL CONDITION APPLE + NO_UNITY_BUILD_SOURCES + qopenglversionfunctionsfactory.cpp +) + qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_opengles2 SOURCES qopenglfunctions_es2.cpp qopenglfunctions_es2.h @@ -105,9 +112,12 @@ qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl qopenglcompositorbackingstore.cpp qopenglcompositorbackingstore_p.h ) - -qt_internal_create_tracepoints(OpenGL qtopengl.tracepoints) +qt_internal_generate_tracepoints(OpenGL opengl + SOURCES + qopenglframebufferobject.cpp + qopenglpaintengine.cpp + qopengltexturecache.cpp +) qt_internal_add_docs(OpenGL doc/qtopengl.qdocconf ) - diff --git a/src/opengl/doc/qtopengl.qdocconf b/src/opengl/doc/qtopengl.qdocconf index 58f16e7d2e..7af173aac8 100644 --- a/src/opengl/doc/qtopengl.qdocconf +++ b/src/opengl/doc/qtopengl.qdocconf @@ -15,18 +15,17 @@ project = QtOpenGL # <rootdir>/examples. # Paths are relative to the location of this file. -headerdirs += .. \ - ../../openglwidgets -sourcedirs += .. \ - ../../openglwidgets \ - ../../../examples/opengl/doc/src +{sourcedirs,headerdirs} += \ + .. \ + ../../openglwidgets + exampledirs += ../../../examples/opengl \ . \ snippets \ .. \ ../../gui/doc/snippets -imagedirs += images \ - ../../../examples/opengl/doc/images + +imagedirs += images depends += qtcore qtgui qtwidgets qtdoc qmake qtcmake qtquick @@ -65,5 +64,5 @@ qhp.QtOpenGL.subprojects.classes.sortPages = true navigation.landingpage = "Qt OpenGL" navigation.cppclassespage = "Qt OpenGL C++ Classes" -# Fail the documentation build if there are more warnings than the limit +# Enforce zero documentation warnings warninglimit = 0 diff --git a/src/opengl/doc/snippets/CMakeLists.txt b/src/opengl/doc/snippets/CMakeLists.txt index 6ee0eab722..419e0923e0 100644 --- a/src/opengl/doc/snippets/CMakeLists.txt +++ b/src/opengl/doc/snippets/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #! [cmake_use] find_package(Qt6 REQUIRED COMPONENTS OpenGL) diff --git a/src/opengl/doc/src/qt6-changes.qdoc b/src/opengl/doc/src/qt6-changes.qdoc index 1bde84fb62..e227476868 100644 --- a/src/opengl/doc/src/qt6-changes.qdoc +++ b/src/opengl/doc/src/qt6-changes.qdoc @@ -5,7 +5,7 @@ \page opengl-changes-qt6.html \title Changes to Qt OpenGL \ingroup changes-qt-5-to-6 - \brief Migrate Qt OpenGL to Qt 6. + \brief QOpenGL classes migrated, QOpenGLWidget class has been moved to Qt OpenGL Widgets. Qt 6 is a result of the conscious effort to make the framework more efficient and easy to use. diff --git a/src/opengl/doc/src/qtopengl-examples.qdoc b/src/opengl/doc/src/qtopengl-examples.qdoc index 4843407b0b..3a98c16c70 100644 --- a/src/opengl/doc/src/qtopengl-examples.qdoc +++ b/src/opengl/doc/src/qtopengl-examples.qdoc @@ -3,7 +3,7 @@ /*! \ingroup all-examples - \title OpenGL Examples from the Qt OpenGL module + \title Qt OpenGL Examples \brief Accessing OpenGL from Qt. \group examples-widgets-opengl diff --git a/src/opengl/doc/src/qtopengl-index.qdoc b/src/opengl/doc/src/qtopengl-index.qdoc index 0b0080edf0..7ea1635827 100644 --- a/src/opengl/doc/src/qtopengl-index.qdoc +++ b/src/opengl/doc/src/qtopengl-index.qdoc @@ -61,7 +61,7 @@ \section1 Examples \list - \li \l {OpenGL Window Example} + \li \l {Qt OpenGL Examples} \endlist \section1 Reference diff --git a/src/opengl/qopenglcompositor.cpp b/src/opengl/qopenglcompositor.cpp index 3e1b2aebed..3c5b1df905 100644 --- a/src/opengl/qopenglcompositor.cpp +++ b/src/opengl/qopenglcompositor.cpp @@ -4,7 +4,7 @@ #include <QtOpenGL/QOpenGLFramebufferObject> #include <QtGui/QOpenGLContext> #include <QtGui/QWindow> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <qpa/qplatformbackingstore.h> #include "qopenglcompositor_p.h" @@ -85,10 +85,23 @@ void QOpenGLCompositor::update() QImage QOpenGLCompositor::grab() { Q_ASSERT(m_context && m_targetWindow); + QOpenGLFramebufferObject fbo(m_nativeTargetGeometry.size()); + grabToFrameBufferObject(&fbo); + return fbo.toImage(); +} + +bool QOpenGLCompositor::grabToFrameBufferObject(QOpenGLFramebufferObject *fbo, GrabOrientation orientation) +{ + Q_ASSERT(fbo); + if (fbo->size() != m_nativeTargetGeometry.size() + || fbo->format().textureTarget() != GL_TEXTURE_2D) + return false; + m_context->makeCurrent(m_targetWindow); - QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_nativeTargetGeometry.size())); - renderAll(fbo.data()); - return fbo->toImage(); + renderAll(fbo, + orientation == Flipped ? QOpenGLTextureBlitter::OriginTopLeft + : QOpenGLTextureBlitter::OriginBottomLeft); + return true; } void QOpenGLCompositor::handleRenderAllRequest() @@ -98,7 +111,7 @@ void QOpenGLCompositor::handleRenderAllRequest() renderAll(0); } -void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) +void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo, QOpenGLTextureBlitter::Origin origin) { if (fbo) fbo->bind(); @@ -115,7 +128,7 @@ void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) m_windows.at(i)->beginCompositing(); for (int i = 0; i < m_windows.size(); ++i) - render(m_windows.at(i)); + render(m_windows.at(i), origin); m_blitter.release(); if (!fbo) @@ -156,9 +169,10 @@ static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) topLeftRect.width(), topLeftRect.height()); } -static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &sourceWindowRect, - const QRect &targetWindowRect, - QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix) +static void clippedBlit(const QPlatformTextureList *textures, int idx, + const QRect &sourceWindowRect, const QRect &targetWindowRect, + QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix, + QOpenGLTextureBlitter::Origin sourceOrigin) { const QRect clipRect = textures->clipRect(idx); if (clipRect.isEmpty()) @@ -173,13 +187,13 @@ static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRe target = *rotationMatrix * target; const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, rectInWindow.size(), - QOpenGLTextureBlitter::OriginBottomLeft); + sourceOrigin); const uint textureId = textures->texture(idx)->nativeTexture().object; blitter->blit(textureId, target, source); } -void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) +void QOpenGLCompositor::render(QOpenGLCompositorWindow *window, QOpenGLTextureBlitter::Origin origin) { const QPlatformTextureList *textures = window->textures(); if (!textures) @@ -189,6 +203,9 @@ void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) float currentOpacity = 1.0f; BlendStateBinder blend; const QRect sourceWindowRect = window->sourceWindow()->geometry(); + auto clippedBlitSourceOrigin = origin == QOpenGLTextureBlitter::OriginTopLeft + ? QOpenGLTextureBlitter::OriginBottomLeft + : QOpenGLTextureBlitter::OriginTopLeft; for (int i = 0; i < textures->count(); ++i) { const uint textureId = textures->texture(i)->nativeTexture().object; const float opacity = window->sourceWindow()->opacity(); @@ -203,7 +220,7 @@ void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); if (m_rotation) target = m_rotationMatrix * target; - m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); + m_blitter.blit(textureId, target, origin); } else if (textures->count() == 1) { // A regular QWidget window const bool translucent = window->sourceWindow()->requestedFormat().alphaBufferSize() > 0; @@ -211,18 +228,20 @@ void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); if (m_rotation) target = m_rotationMatrix * target; - m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); + m_blitter.blit(textureId, target, origin); } else if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { // Texture from an FBO belonging to a QOpenGLWidget or QQuickWidget blend.set(false); - clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); + clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, + m_rotation ? &m_rotationMatrix : nullptr, clippedBlitSourceOrigin); } } for (int i = 0; i < textures->count(); ++i) { if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { blend.set(true); - clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); + clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, + m_rotation ? &m_rotationMatrix : nullptr, clippedBlitSourceOrigin); } } diff --git a/src/opengl/qopenglcompositor_p.h b/src/opengl/qopenglcompositor_p.h index abe8d4959e..86229b13ca 100644 --- a/src/opengl/qopenglcompositor_p.h +++ b/src/opengl/qopenglcompositor_p.h @@ -29,6 +29,7 @@ class QOpenGLFramebufferObject; class QWindow; class QPlatformTextureList; +class QOpenGLCompositorBackingStore; class QOpenGLCompositorWindow { public: @@ -37,6 +38,8 @@ public: virtual const QPlatformTextureList *textures() const = 0; virtual void beginCompositing() { } virtual void endCompositing() { } + virtual void setBackingStore(QOpenGLCompositorBackingStore *backingStore) = 0; + virtual QOpenGLCompositorBackingStore *backingStore() const = 0; }; class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject @@ -44,6 +47,11 @@ class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject Q_OBJECT public: + enum GrabOrientation { + Flipped, + NotFlipped, + }; + static QOpenGLCompositor *instance(); static void destroy(); @@ -52,10 +60,13 @@ public: void setRotation(int degrees); QOpenGLContext *context() const { return m_context; } QWindow *targetWindow() const { return m_targetWindow; } + QRect nativeTargetGeometry() const { return m_nativeTargetGeometry; } void update(); QImage grab(); + bool grabToFrameBufferObject(QOpenGLFramebufferObject *fbo, GrabOrientation orientation = Flipped); + QList<QOpenGLCompositorWindow *> windows() const { return m_windows; } void addWindow(QOpenGLCompositorWindow *window); void removeWindow(QOpenGLCompositorWindow *window); @@ -72,8 +83,10 @@ private: QOpenGLCompositor(); ~QOpenGLCompositor(); - void renderAll(QOpenGLFramebufferObject *fbo); - void render(QOpenGLCompositorWindow *window); + void renderAll(QOpenGLFramebufferObject *fbo, + QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft); + void render(QOpenGLCompositorWindow *window, + QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft); void ensureCorrectZOrder(); QOpenGLContext *m_context; diff --git a/src/opengl/qopenglcompositorbackingstore.cpp b/src/opengl/qopenglcompositorbackingstore.cpp index a5cc391e48..371ca868f8 100644 --- a/src/opengl/qopenglcompositorbackingstore.cpp +++ b/src/opengl/qopenglcompositorbackingstore.cpp @@ -6,7 +6,7 @@ #include <QtGui/QPainter> #include <qpa/qplatformbackingstore.h> #include <private/qwindow_p.h> -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include "qopenglcompositorbackingstore_p.h" #include "qopenglcompositor_p.h" @@ -137,15 +137,14 @@ void QOpenGLCompositorBackingStore::updateTexture() void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) { // Called for ordinary raster windows. + auto *handle = dynamic_cast<QOpenGLCompositorWindow *>(window->handle()); + if (handle && !handle->backingStore()) + handle->setBackingStore(this); Q_UNUSED(region); Q_UNUSED(offset); - m_rhi = rhi(); - if (!m_rhi) { - setRhiConfig(QPlatformBackingStoreRhiConfig(QPlatformBackingStoreRhiConfig::OpenGL)); - m_rhi = rhi(); - } + m_rhi = rhi(window); Q_ASSERT(m_rhi); QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); @@ -181,11 +180,7 @@ QPlatformBackingStore::FlushResult QOpenGLCompositorBackingStore::rhiFlush(QWind Q_UNUSED(translucentBackground); Q_UNUSED(sourceDevicePixelRatio); - m_rhi = rhi(); - if (!m_rhi) { - setRhiConfig(QPlatformBackingStoreRhiConfig(QPlatformBackingStoreRhiConfig::OpenGL)); - m_rhi = rhi(); - } + m_rhi = rhi(window); Q_ASSERT(m_rhi); QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); @@ -246,6 +241,8 @@ void QOpenGLCompositorBackingStore::resize(const QSize &size, const QRegion &sta QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); QOpenGLContext *dstCtx = compositor->context(); + if (!dstCtx) + return; QWindow *dstWin = compositor->targetWindow(); if (!dstWin) return; diff --git a/src/opengl/qopenglcustomshaderstage.cpp b/src/opengl/qopenglcustomshaderstage.cpp index d26bebfd61..1be8d783d6 100644 --- a/src/opengl/qopenglcustomshaderstage.cpp +++ b/src/opengl/qopenglcustomshaderstage.cpp @@ -6,6 +6,8 @@ #include "qopenglpaintengine_p.h" #include <private/qpainter_p.h> +#include <QtCore/qpointer.h> + QT_BEGIN_NAMESPACE class QOpenGLCustomShaderStagePrivate diff --git a/src/opengl/qopenglframebufferobject.cpp b/src/opengl/qopenglframebufferobject.cpp index 64b07e661f..5c8f769d39 100644 --- a/src/opengl/qopenglframebufferobject.cpp +++ b/src/opengl/qopenglframebufferobject.cpp @@ -18,6 +18,15 @@ QT_BEGIN_NAMESPACE +Q_TRACE_PREFIX(qtopengl, + "#include <private/qopengl2pexvertexarray_p.h>" \ + "#include <private/qopengltextureuploader_p.h>" \ + "#include <qopenglframebufferobject.h>" +); +Q_TRACE_PARAM_REPLACE(GLenum, int); +Q_TRACE_PARAM_REPLACE(GLint, int); +Q_TRACE_METADATA(qtopengl, "ENUM { } QOpenGLFramebufferObject::Attachment; "); + #ifndef QT_NO_DEBUG #define QT_RESET_GLERROR() \ { \ @@ -452,10 +461,11 @@ namespace } } -void QOpenGLFramebufferObjectPrivate::init(QOpenGLFramebufferObject *qfbo, const QSize &size, - QOpenGLFramebufferObject::Attachment attachment, - GLenum texture_target, GLenum internal_format, - GLint samples, bool mipmap) +void Q_TRACE_INSTRUMENT(qtopengl) QOpenGLFramebufferObjectPrivate::init( + QOpenGLFramebufferObject *qfbo, const QSize &size, + QOpenGLFramebufferObject::Attachment attachment, + GLenum texture_target, GLenum internal_format, + GLint samples, bool mipmap) { Q_TRACE_SCOPE(QOpenGLFramebufferObjectPrivate_init, qfbo, size, attachment, texture_target, internal_format, samples, mipmap); Q_UNUSED(qfbo); @@ -540,8 +550,22 @@ void QOpenGLFramebufferObjectPrivate::initTexture(int idx) else if (color.internalFormat == GL_RGB16F || color.internalFormat == GL_RGBA16F) pixelType = GL_HALF_FLOAT; + bool isOpaque = false; + switch (color.internalFormat) { + case GL_RGB8: + case GL_RGB16: + case GL_RGB16F: + case GL_RGB32F: + isOpaque = true; + break; + case GL_RGB10: + // opaque but the pixel type (INT_2_10_10_10) has alpha and so requires RGBA texture format + break; + } + const GLuint textureFormat = isOpaque ? GL_RGB : GL_RGBA; + funcs.glTexImage2D(target, 0, color.internalFormat, color.size.width(), color.size.height(), 0, - GL_RGBA, pixelType, nullptr); + textureFormat, pixelType, nullptr); if (format.mipmap()) { int width = color.size.width(); int height = color.size.height(); @@ -550,8 +574,8 @@ void QOpenGLFramebufferObjectPrivate::initTexture(int idx) width = qMax(1, width >> 1); height = qMax(1, height >> 1); ++level; - funcs.glTexImage2D(target, level, color.internalFormat, width, height, 0, - GL_RGBA, pixelType, nullptr); + funcs.glTexImage2D(target, level, color.internalFormat, width, height, 0, textureFormat, + pixelType, nullptr); } } funcs.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + idx, @@ -1334,7 +1358,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ bool isOpenGL12orBetter = !context->isOpenGLES() && (context->format().majorVersion() >= 2 || context->format().minorVersion() >= 2); if (isOpenGL12orBetter) { QImage img(size, include_alpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); - funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits()); + if (!img.isNull()) + funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits()); return img; } @@ -1344,7 +1369,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ // BGRA capable impl would return BGRA from there) QImage rgbaImage(size, include_alpha ? QImage::Format_RGBA8888_Premultiplied : QImage::Format_RGBX8888); - funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits()); + if (!rgbaImage.isNull()) + funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits()); return rgbaImage; } @@ -1352,7 +1378,8 @@ static inline QImage qt_gl_read_framebuffer_rgb10a2(const QSize &size, bool incl { // We assume OpenGL 1.2+ or ES 3.0+ here. QImage img(size, include_alpha ? QImage::Format_A2BGR30_Premultiplied : QImage::Format_BGR30); - context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits()); + if (!img.isNull()) + context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits()); return img; } @@ -1360,7 +1387,8 @@ static inline QImage qt_gl_read_framebuffer_rgba16(const QSize &size, bool inclu { // We assume OpenGL 1.2+ or ES 3.0+ here. QImage img(size, include_alpha ? QImage::Format_RGBA64_Premultiplied : QImage::Format_RGBX64); - context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits()); + if (!img.isNull()) + context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits()); return img; } @@ -1368,14 +1396,16 @@ static inline QImage qt_gl_read_framebuffer_rgba16f(const QSize &size, bool incl { // We assume OpenGL (ES) 3.0+ here. QImage img(size, include_alpha ? QImage::Format_RGBA16FPx4_Premultiplied : QImage::Format_RGBX16FPx4); - context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits()); + if (!img.isNull()) + context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits()); return img; } static inline QImage qt_gl_read_framebuffer_rgba32f(const QSize &size, bool include_alpha, QOpenGLContext *context) { QImage img(size, include_alpha ? QImage::Format_RGBA32FPx4_Premultiplied : QImage::Format_RGBX32FPx4); - context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits()); + if (!img.isNull()) + context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits()); return img; } diff --git a/src/opengl/qopenglfunctions_2_0.cpp b/src/opengl/qopenglfunctions_2_0.cpp index 834136d3dd..0641f41390 100644 --- a/src/opengl/qopenglfunctions_2_0.cpp +++ b/src/opengl/qopenglfunctions_2_0.cpp @@ -44,7 +44,6 @@ QOpenGLFunctions_2_0::QOpenGLFunctions_2_0() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_2_0.h b/src/opengl/qopenglfunctions_2_0.h index f45a56b4f3..cca8d590e7 100644 --- a/src/opengl/qopenglfunctions_2_0.h +++ b/src/opengl/qopenglfunctions_2_0.h @@ -656,7 +656,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC }; // OpenGL 1.0 core functions diff --git a/src/opengl/qopenglfunctions_2_1.cpp b/src/opengl/qopenglfunctions_2_1.cpp index 984bb16d11..28f8b29dab 100644 --- a/src/opengl/qopenglfunctions_2_1.cpp +++ b/src/opengl/qopenglfunctions_2_1.cpp @@ -45,7 +45,6 @@ QOpenGLFunctions_2_1::QOpenGLFunctions_2_1() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_2_1.h b/src/opengl/qopenglfunctions_2_1.h index 249ede3608..3b192e3b62 100644 --- a/src/opengl/qopenglfunctions_2_1.h +++ b/src/opengl/qopenglfunctions_2_1.h @@ -667,7 +667,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC }; // OpenGL 1.0 core functions diff --git a/src/opengl/qopenglfunctions_3_0.cpp b/src/opengl/qopenglfunctions_3_0.cpp index 5fcf1c9b2c..b186ff2a9f 100644 --- a/src/opengl/qopenglfunctions_3_0.cpp +++ b/src/opengl/qopenglfunctions_3_0.cpp @@ -46,8 +46,6 @@ QOpenGLFunctions_3_0::QOpenGLFunctions_3_0() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) - , m_reserved_3_0_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_3_0.h b/src/opengl/qopenglfunctions_3_0.h index 5276fc730a..01d6ccefaf 100644 --- a/src/opengl/qopenglfunctions_3_0.h +++ b/src/opengl/qopenglfunctions_3_0.h @@ -756,8 +756,8 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC - void *m_reserved_3_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_3_0_Deprecated = nullptr; // To maintain BC }; // OpenGL 1.0 core functions diff --git a/src/opengl/qopenglfunctions_3_2_compatibility.cpp b/src/opengl/qopenglfunctions_3_2_compatibility.cpp index 6c90c569d7..c1b1806998 100644 --- a/src/opengl/qopenglfunctions_3_2_compatibility.cpp +++ b/src/opengl/qopenglfunctions_3_2_compatibility.cpp @@ -48,8 +48,6 @@ QOpenGLFunctions_3_2_Compatibility::QOpenGLFunctions_3_2_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) - , m_reserved_3_0_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_3_2_compatibility.h b/src/opengl/qopenglfunctions_3_2_compatibility.h index 416ceb2725..b01c232385 100644 --- a/src/opengl/qopenglfunctions_3_2_compatibility.h +++ b/src/opengl/qopenglfunctions_3_2_compatibility.h @@ -797,8 +797,8 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC - void *m_reserved_3_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_3_0_Deprecated = nullptr; // To maintain BC }; // OpenGL 1.0 core functions diff --git a/src/opengl/qopenglfunctions_3_3_compatibility.cpp b/src/opengl/qopenglfunctions_3_3_compatibility.cpp index 0c61516ca1..60ef10553b 100644 --- a/src/opengl/qopenglfunctions_3_3_compatibility.cpp +++ b/src/opengl/qopenglfunctions_3_3_compatibility.cpp @@ -49,7 +49,6 @@ QOpenGLFunctions_3_3_Compatibility::QOpenGLFunctions_3_3_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) , d_3_3_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_3_3_compatibility.h b/src/opengl/qopenglfunctions_3_3_compatibility.h index 92f6bd8bde..25490648f3 100644 --- a/src/opengl/qopenglfunctions_3_3_compatibility.h +++ b/src/opengl/qopenglfunctions_3_3_compatibility.h @@ -860,7 +860,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC QOpenGLFunctions_3_3_DeprecatedBackend* d_3_3_Deprecated; }; diff --git a/src/opengl/qopenglfunctions_4_0_compatibility.cpp b/src/opengl/qopenglfunctions_4_0_compatibility.cpp index c380e73cb5..7074de5bde 100644 --- a/src/opengl/qopenglfunctions_4_0_compatibility.cpp +++ b/src/opengl/qopenglfunctions_4_0_compatibility.cpp @@ -50,7 +50,6 @@ QOpenGLFunctions_4_0_Compatibility::QOpenGLFunctions_4_0_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) , d_3_3_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_4_0_compatibility.h b/src/opengl/qopenglfunctions_4_0_compatibility.h index ba725464af..b72d01305a 100644 --- a/src/opengl/qopenglfunctions_4_0_compatibility.h +++ b/src/opengl/qopenglfunctions_4_0_compatibility.h @@ -911,7 +911,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC QOpenGLFunctions_3_3_DeprecatedBackend* d_3_3_Deprecated; }; diff --git a/src/opengl/qopenglfunctions_4_1_compatibility.cpp b/src/opengl/qopenglfunctions_4_1_compatibility.cpp index 399fd5c990..035cc79276 100644 --- a/src/opengl/qopenglfunctions_4_1_compatibility.cpp +++ b/src/opengl/qopenglfunctions_4_1_compatibility.cpp @@ -51,7 +51,6 @@ QOpenGLFunctions_4_1_Compatibility::QOpenGLFunctions_4_1_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) , d_3_3_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_4_1_compatibility.h b/src/opengl/qopenglfunctions_4_1_compatibility.h index ee8ab6be44..08b7c05232 100644 --- a/src/opengl/qopenglfunctions_4_1_compatibility.h +++ b/src/opengl/qopenglfunctions_4_1_compatibility.h @@ -1004,7 +1004,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC QOpenGLFunctions_3_3_DeprecatedBackend* d_3_3_Deprecated; }; diff --git a/src/opengl/qopenglfunctions_4_2_compatibility.cpp b/src/opengl/qopenglfunctions_4_2_compatibility.cpp index 5bf2eedbaf..faf0ca845f 100644 --- a/src/opengl/qopenglfunctions_4_2_compatibility.cpp +++ b/src/opengl/qopenglfunctions_4_2_compatibility.cpp @@ -52,7 +52,6 @@ QOpenGLFunctions_4_2_Compatibility::QOpenGLFunctions_4_2_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) , d_3_3_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_4_2_compatibility.h b/src/opengl/qopenglfunctions_4_2_compatibility.h index ca5b4127db..2bc4f8b228 100644 --- a/src/opengl/qopenglfunctions_4_2_compatibility.h +++ b/src/opengl/qopenglfunctions_4_2_compatibility.h @@ -1027,7 +1027,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC QOpenGLFunctions_3_3_DeprecatedBackend* d_3_3_Deprecated; }; diff --git a/src/opengl/qopenglfunctions_4_3_compatibility.cpp b/src/opengl/qopenglfunctions_4_3_compatibility.cpp index c401a93189..c3a3d5d32b 100644 --- a/src/opengl/qopenglfunctions_4_3_compatibility.cpp +++ b/src/opengl/qopenglfunctions_4_3_compatibility.cpp @@ -53,7 +53,6 @@ QOpenGLFunctions_4_3_Compatibility::QOpenGLFunctions_4_3_Compatibility() , d_1_2_Deprecated(nullptr) , d_1_3_Deprecated(nullptr) , d_1_4_Deprecated(nullptr) - , m_reserved_2_0_Deprecated(nullptr) , d_3_3_Deprecated(nullptr) { } diff --git a/src/opengl/qopenglfunctions_4_3_compatibility.h b/src/opengl/qopenglfunctions_4_3_compatibility.h index e79cecb542..0370637653 100644 --- a/src/opengl/qopenglfunctions_4_3_compatibility.h +++ b/src/opengl/qopenglfunctions_4_3_compatibility.h @@ -1065,7 +1065,7 @@ private: QOpenGLFunctions_1_2_DeprecatedBackend* d_1_2_Deprecated; QOpenGLFunctions_1_3_DeprecatedBackend* d_1_3_Deprecated; QOpenGLFunctions_1_4_DeprecatedBackend* d_1_4_Deprecated; - void *m_reserved_2_0_Deprecated; // To maintain BC + Q_DECL_UNUSED_MEMBER void *m_reserved_2_0_Deprecated = nullptr; // To maintain BC QOpenGLFunctions_3_3_DeprecatedBackend* d_3_3_Deprecated; }; diff --git a/src/opengl/qopenglfunctions_4_5_compatibility.h b/src/opengl/qopenglfunctions_4_5_compatibility.h index 229a0b4288..cca3eae9e2 100644 --- a/src/opengl/qopenglfunctions_4_5_compatibility.h +++ b/src/opengl/qopenglfunctions_4_5_compatibility.h @@ -700,25 +700,52 @@ public: void glNamedFramebufferParameteri(GLuint framebuffer, GLenum pname, GLint param); void glNamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); void glCreateFramebuffers(GLsizei n, GLuint *framebuffers); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +#else void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, void *data); +#endif void glGetNamedBufferPointerv(GLuint buffer, GLenum pname, void * *params); void glGetNamedBufferParameteri64v(GLuint buffer, GLenum pname, GLint64 *params); void glGetNamedBufferParameteriv(GLuint buffer, GLenum pname, GLint *params); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length); +#else void glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length); +#endif GLboolean glUnmapNamedBuffer(GLuint buffer); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void * glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +#else void * glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access); +#endif void * glMapNamedBuffer(GLuint buffer, GLenum access); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +#else void glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizei size, GLenum format, GLenum type, const void *data); +#endif void glClearNamedBufferData(GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); + void glNamedBufferData(GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); + void glNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +#else void glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizei size); void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, const void *data); void glNamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage); void glNamedBufferStorage(GLuint buffer, GLsizei size, const void *data, GLbitfield flags); +#endif void glCreateBuffers(GLsizei n, GLuint *buffers); void glGetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index, GLint64 *param); void glGetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index, GLint *param); void glGetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint *param); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +#else void glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizei size); +#endif void glTransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer); void glCreateTransformFeedbacks(GLsizei n, GLuint *ids); void glClipControl(GLenum origin, GLenum depth); @@ -4381,7 +4408,11 @@ inline void QOpenGLFunctions_4_5_Compatibility::glCreateFramebuffers(GLsizei n, d_4_5_Core->f.CreateFramebuffers(n, framebuffers); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void *data) +#else inline void QOpenGLFunctions_4_5_Compatibility::glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, void *data) +#endif { d_4_5_Core->f.GetNamedBufferSubData(buffer, offset, size, data); } @@ -4401,7 +4432,11 @@ inline void QOpenGLFunctions_4_5_Compatibility::glGetNamedBufferParameteriv(GLui d_4_5_Core->f.GetNamedBufferParameteriv(buffer, pname, params); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length) +#else inline void QOpenGLFunctions_4_5_Compatibility::glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length) +#endif { d_4_5_Core->f.FlushMappedNamedBufferRange(buffer, offset, length); } @@ -4411,7 +4446,11 @@ inline GLboolean QOpenGLFunctions_4_5_Compatibility::glUnmapNamedBuffer(GLuint b return d_4_5_Core->f.UnmapNamedBuffer(buffer); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void * QOpenGLFunctions_4_5_Compatibility::glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access) +#else inline void * QOpenGLFunctions_4_5_Compatibility::glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access) +#endif { return d_4_5_Core->f.MapNamedBufferRange(buffer, offset, length, access); } @@ -4421,7 +4460,11 @@ inline void * QOpenGLFunctions_4_5_Compatibility::glMapNamedBuffer(GLuint buffer return d_4_5_Core->f.MapNamedBuffer(buffer, access); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data) +#else inline void QOpenGLFunctions_4_5_Compatibility::glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizei size, GLenum format, GLenum type, const void *data) +#endif { d_4_5_Core->f.ClearNamedBufferSubData(buffer, internalformat, offset, size, format, type, data); } @@ -4431,22 +4474,38 @@ inline void QOpenGLFunctions_4_5_Compatibility::glClearNamedBufferData(GLuint bu d_4_5_Core->f.ClearNamedBufferData(buffer, internalformat, format, type, data); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) +#else inline void QOpenGLFunctions_4_5_Compatibility::glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizei size) +#endif { d_4_5_Core->f.CopyNamedBufferSubData(readBuffer, writeBuffer, readOffset, writeOffset, size); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data) +#else inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, const void *data) +#endif { d_4_5_Core->f.NamedBufferSubData(buffer, offset, size, data); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferData(GLuint buffer, GLsizeiptr size, const void *data, GLenum usage) +#else inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage) +#endif { d_4_5_Core->f.NamedBufferData(buffer, size, data, usage); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags) +#else inline void QOpenGLFunctions_4_5_Compatibility::glNamedBufferStorage(GLuint buffer, GLsizei size, const void *data, GLbitfield flags) +#endif { d_4_5_Core->f.NamedBufferStorage(buffer, size, data, flags); } @@ -4471,7 +4530,11 @@ inline void QOpenGLFunctions_4_5_Compatibility::glGetTransformFeedbackiv(GLuint d_4_5_Core->f.GetTransformFeedbackiv(xfb, pname, param); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Compatibility::glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) +#else inline void QOpenGLFunctions_4_5_Compatibility::glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizei size) +#endif { d_4_5_Core->f.TransformFeedbackBufferRange(xfb, index, buffer, offset, size); } diff --git a/src/opengl/qopenglfunctions_4_5_core.h b/src/opengl/qopenglfunctions_4_5_core.h index 24ad0fd544..e3944f0741 100644 --- a/src/opengl/qopenglfunctions_4_5_core.h +++ b/src/opengl/qopenglfunctions_4_5_core.h @@ -700,25 +700,52 @@ public: void glNamedFramebufferParameteri(GLuint framebuffer, GLenum pname, GLint param); void glNamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); void glCreateFramebuffers(GLsizei n, GLuint *framebuffers); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +#else void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, void *data); +#endif void glGetNamedBufferPointerv(GLuint buffer, GLenum pname, void * *params); void glGetNamedBufferParameteri64v(GLuint buffer, GLenum pname, GLint64 *params); void glGetNamedBufferParameteriv(GLuint buffer, GLenum pname, GLint *params); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length); +#else void glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length); +#endif GLboolean glUnmapNamedBuffer(GLuint buffer); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void * glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +#else void * glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access); +#endif void * glMapNamedBuffer(GLuint buffer, GLenum access); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +#else void glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizei size, GLenum format, GLenum type, const void *data); +#endif void glClearNamedBufferData(GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); + void glNamedBufferData(GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); + void glNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +#else void glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizei size); void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, const void *data); void glNamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage); void glNamedBufferStorage(GLuint buffer, GLsizei size, const void *data, GLbitfield flags); +#endif void glCreateBuffers(GLsizei n, GLuint *buffers); void glGetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index, GLint64 *param); void glGetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index, GLint *param); void glGetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint *param); +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + void glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +#else void glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizei size); +#endif void glTransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer); void glCreateTransformFeedbacks(GLsizei n, GLuint *ids); void glClipControl(GLenum origin, GLenum depth); @@ -3914,7 +3941,11 @@ inline void QOpenGLFunctions_4_5_Core::glCreateFramebuffers(GLsizei n, GLuint *f d_4_5_Core->f.CreateFramebuffers(n, framebuffers); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void *data) +#else inline void QOpenGLFunctions_4_5_Core::glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, void *data) +#endif { d_4_5_Core->f.GetNamedBufferSubData(buffer, offset, size, data); } @@ -3934,7 +3965,11 @@ inline void QOpenGLFunctions_4_5_Core::glGetNamedBufferParameteriv(GLuint buffer d_4_5_Core->f.GetNamedBufferParameteriv(buffer, pname, params); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length) +#else inline void QOpenGLFunctions_4_5_Core::glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length) +#endif { d_4_5_Core->f.FlushMappedNamedBufferRange(buffer, offset, length); } @@ -3944,7 +3979,11 @@ inline GLboolean QOpenGLFunctions_4_5_Core::glUnmapNamedBuffer(GLuint buffer) return d_4_5_Core->f.UnmapNamedBuffer(buffer); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void * QOpenGLFunctions_4_5_Core::glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access) +#else inline void * QOpenGLFunctions_4_5_Core::glMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access) +#endif { return d_4_5_Core->f.MapNamedBufferRange(buffer, offset, length, access); } @@ -3954,7 +3993,11 @@ inline void * QOpenGLFunctions_4_5_Core::glMapNamedBuffer(GLuint buffer, GLenum return d_4_5_Core->f.MapNamedBuffer(buffer, access); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data) +#else inline void QOpenGLFunctions_4_5_Core::glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizei size, GLenum format, GLenum type, const void *data) +#endif { d_4_5_Core->f.ClearNamedBufferSubData(buffer, internalformat, offset, size, format, type, data); } @@ -3964,22 +4007,38 @@ inline void QOpenGLFunctions_4_5_Core::glClearNamedBufferData(GLuint buffer, GLe d_4_5_Core->f.ClearNamedBufferData(buffer, internalformat, format, type, data); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) +#else inline void QOpenGLFunctions_4_5_Core::glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizei size) +#endif { d_4_5_Core->f.CopyNamedBufferSubData(readBuffer, writeBuffer, readOffset, writeOffset, size); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data) +#else inline void QOpenGLFunctions_4_5_Core::glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, const void *data) +#endif { d_4_5_Core->f.NamedBufferSubData(buffer, offset, size, data); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glNamedBufferData(GLuint buffer, GLsizeiptr size, const void *data, GLenum usage) +#else inline void QOpenGLFunctions_4_5_Core::glNamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage) +#endif { d_4_5_Core->f.NamedBufferData(buffer, size, data, usage); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags) +#else inline void QOpenGLFunctions_4_5_Core::glNamedBufferStorage(GLuint buffer, GLsizei size, const void *data, GLbitfield flags) +#endif { d_4_5_Core->f.NamedBufferStorage(buffer, size, data, flags); } @@ -4004,7 +4063,11 @@ inline void QOpenGLFunctions_4_5_Core::glGetTransformFeedbackiv(GLuint xfb, GLen d_4_5_Core->f.GetTransformFeedbackiv(xfb, pname, param); } +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +inline void QOpenGLFunctions_4_5_Core::glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) +#else inline void QOpenGLFunctions_4_5_Core::glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizei size) +#endif { d_4_5_Core->f.TransformFeedbackBufferRange(xfb, index, buffer, offset, size); } diff --git a/src/opengl/qopenglpaintdevice.cpp b/src/opengl/qopenglpaintdevice.cpp index fbc54c46fb..aaee7f18fe 100644 --- a/src/opengl/qopenglpaintdevice.cpp +++ b/src/opengl/qopenglpaintdevice.cpp @@ -247,6 +247,10 @@ int QOpenGLPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const return d_ptr->devicePixelRatio; case PdmDevicePixelRatioScaled: return d_ptr->devicePixelRatio * QPaintDevice::devicePixelRatioFScale(); + case PdmDevicePixelRatioF_EncodedA: + Q_FALLTHROUGH(); + case PdmDevicePixelRatioF_EncodedB: + return QPaintDevice::encodeMetricF(metric, d_ptr->devicePixelRatio); default: qWarning("QOpenGLPaintDevice::metric() - metric %d not known", metric); diff --git a/src/opengl/qopenglpaintengine.cpp b/src/opengl/qopenglpaintengine.cpp index 8cdf08bdef..972e276370 100644 --- a/src/opengl/qopenglpaintengine.cpp +++ b/src/opengl/qopenglpaintengine.cpp @@ -160,10 +160,14 @@ template<typename T> void QOpenGL2PaintEngineExPrivate::updateTexture(GLenum textureUnit, const T &texture, GLenum wrapMode, GLenum filterMode, TextureUpdateMode updateMode) { static const GLenum target = GL_TEXTURE_2D; + bool newTextureCreated = false; activateTextureUnit(textureUnit); - GLuint textureId = bindTexture(texture); + GLuint textureId = bindTexture(texture, &newTextureCreated); + + if (newTextureCreated) + lastTextureUsed = GLuint(-1); if (updateMode == UpdateIfNeeded && textureId == lastTextureUsed) return; @@ -192,8 +196,11 @@ void QOpenGL2PaintEngineExPrivate::activateTextureUnit(GLenum textureUnit) } template<> -GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const GLuint &textureId) +GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const GLuint &textureId, bool *newTextureCreated) { + if (newTextureCreated) + *newTextureCreated = false; + if (textureId != lastTextureUsed) funcs.glBindTexture(GL_TEXTURE_2D, textureId); @@ -201,19 +208,25 @@ GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const GLuint &textureId) } template<> -GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QImage &image) +GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QImage &image, bool *newTextureCreated) { - return QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, image); + QOpenGLTextureCache::BindResult result = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, image); + if (newTextureCreated) + *newTextureCreated = result.flags.testFlag(QOpenGLTextureCache::BindResultFlag::NewTexture); + return result.id; } template<> -GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QPixmap &pixmap) +GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QPixmap &pixmap, bool *newTextureCreated) { - return QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, pixmap); + QOpenGLTextureCache::BindResult result = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, pixmap); + if (newTextureCreated) + *newTextureCreated = result.flags.testFlag(QOpenGLTextureCache::BindResultFlag::NewTexture); + return result.id; } template<> -GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QGradient &gradient) +GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QGradient &gradient, bool *newTextureCreated) { // We apply global opacity in the fragment shaders, so we always pass 1.0 // for opacity to the cache. @@ -223,7 +236,7 @@ GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const QGradient &gradient) // hasn't been cached yet, but will otherwise return an unbound texture id. To // be sure that the texture is bound, we unfortunately have to bind again, // which results in the initial generation of the texture doing two binds. - return bindTexture(textureId); + return bindTexture(textureId, newTextureCreated); } struct ImageWithBindOptions @@ -233,9 +246,14 @@ struct ImageWithBindOptions }; template<> -GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const ImageWithBindOptions &imageWithOptions) +GLuint QOpenGL2PaintEngineExPrivate::bindTexture(const ImageWithBindOptions &imageWithOptions, bool *newTextureCreated) { - return QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, imageWithOptions.image, imageWithOptions.options); + QOpenGLTextureCache::BindResult result = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, + imageWithOptions.image, + imageWithOptions.options); + if (newTextureCreated) + *newTextureCreated = result.flags.testFlag(QOpenGLTextureCache::BindResultFlag::NewTexture); + return result.id; } inline static bool isPowerOfTwo(int x) @@ -606,18 +624,10 @@ static inline void setCoords(GLfloat *coords, const QOpenGLRect &rect) coords[7] = rect.bottom; } -void QOpenGL2PaintEngineExPrivate::drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern) +void Q_TRACE_INSTRUMENT(qtopengl) QOpenGL2PaintEngineExPrivate::drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern) { - Q_TRACE_SCOPE(QOpenGL2PaintEngineExPrivate_drawTexture, - dest.left, - dest.top, - dest.right, - dest.bottom, - src.left, - src.top, - src.right, - src.bottom, - textureSize, opaque); + Q_TRACE_PARAM_REPLACE(QOpenGLRect, QRectF); + Q_TRACE_SCOPE(QOpenGL2PaintEngineExPrivate_drawTexture, dest, src, textureSize, opaque, pattern); // Setup for texture drawing currentBrush = noBrush; @@ -2141,6 +2151,10 @@ void QOpenGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFra transferMode(ImageOpacityArrayDrawingMode); + uploadData(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data(), vertexCoordinateArray.vertexCount() * 2); + uploadData(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data(), textureCoordinateArray.vertexCount() * 2); + uploadData(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data(), opacityArray.size()); + GLenum filterMode = q->state()->renderHints & QPainter::SmoothPixmapTransform ? GL_LINEAR : GL_NEAREST; updateTexture(QT_IMAGE_TEXTURE_UNIT, pixmap, GL_CLAMP_TO_EDGE, filterMode); diff --git a/src/opengl/qopenglpaintengine_p.h b/src/opengl/qopenglpaintengine_p.h index 5d2bbbeb11..df407444be 100644 --- a/src/opengl/qopenglpaintengine_p.h +++ b/src/opengl/qopenglpaintengine_p.h @@ -177,7 +177,7 @@ public: template<typename T> void updateTexture(GLenum textureUnit, const T &texture, GLenum wrapMode, GLenum filterMode, TextureUpdateMode updateMode = UpdateIfNeeded); template<typename T> - GLuint bindTexture(const T &texture); + GLuint bindTexture(const T &texture, bool *newTextureCreated); void activateTextureUnit(GLenum textureUnit); void resetGLState(); @@ -243,7 +243,7 @@ public: QOpenGLEngineShaderManager* shaderManager; QOpenGLPaintDevice* device; int width, height; - QOpenGLContext *ctx; + QPointer<QOpenGLContext> ctx; EngineMode mode; QFontEngine::GlyphFormat glyphCacheFormat; diff --git a/src/opengl/qopengltexture.cpp b/src/opengl/qopengltexture.cpp index 6700f0e383..3b8e14490b 100644 --- a/src/opengl/qopengltexture.cpp +++ b/src/opengl/qopengltexture.cpp @@ -2456,6 +2456,9 @@ QOpenGLTexture::QOpenGLTexture(Target target) This does create the underlying OpenGL texture object. Therefore, construction using this constructor does require a valid current OpenGL context. + + \note \a image is automatically converted to QImage::Format_RGBA8888 which + may have performance implications for large images with a different format. */ QOpenGLTexture::QOpenGLTexture(const QImage& image, MipMapGeneration genMipMaps) : QOpenGLTexture(QOpenGLTexture::Target2D) @@ -3610,6 +3613,9 @@ void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, The pixel data is contained in \a image. Mipmaps are generated by default. Set \a genMipMaps to \l DontGenerateMipMaps to turn off mipmap generation. + \note \a image is automatically converted to QImage::Format_RGBA8888 which + may have performance implications for large images with a different format. + \overload */ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) @@ -3625,6 +3631,12 @@ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) return; } + QImage glImage = image.convertToFormat(QImage::Format_RGBA8888); + if (glImage.isNull()) { + qWarning("QOpenGLTexture::setData() failed to convert image"); + return; + } + if (context->isOpenGLES() && context->format().majorVersion() < 3) setFormat(QOpenGLTexture::RGBAFormat); else @@ -3635,7 +3647,6 @@ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); // Upload pixel data and generate mipmaps - QImage glImage = image.convertToFormat(QImage::Format_RGBA8888); QOpenGLPixelTransferOptions uploadOptions; uploadOptions.setAlignment(1); setData(0, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, glImage.constBits(), &uploadOptions); diff --git a/src/opengl/qopengltextureblitter.cpp b/src/opengl/qopengltextureblitter.cpp index 2b43afc3b6..5f58876f32 100644 --- a/src/opengl/qopengltextureblitter.cpp +++ b/src/opengl/qopengltextureblitter.cpp @@ -169,14 +169,14 @@ static const GLfloat texture_buffer_data[] = { 1, 1 }; -class TextureBinder +class QBlitterTextureBinder { public: - TextureBinder(GLenum target, GLuint textureId) : m_target(target) + explicit QBlitterTextureBinder(GLenum target, GLuint textureId) : m_target(target) { QOpenGLContext::currentContext()->functions()->glBindTexture(m_target, textureId); } - ~TextureBinder() + ~QBlitterTextureBinder() { QOpenGLContext::currentContext()->functions()->glBindTexture(m_target, 0); } @@ -319,7 +319,7 @@ void QOpenGLTextureBlitterPrivate::blit(GLuint texture, const QMatrix4x4 &targetTransform, const QMatrix3x3 &sourceTransform) { - TextureBinder binder(currentTarget, texture); + QBlitterTextureBinder binder(currentTarget, texture); if (!prepareProgram(targetTransform)) return; @@ -336,7 +336,7 @@ void QOpenGLTextureBlitterPrivate::blit(GLuint texture, const QMatrix4x4 &targetTransform, QOpenGLTextureBlitter::Origin origin) { - TextureBinder binder(currentTarget, texture); + QBlitterTextureBinder binder(currentTarget, texture); if (!prepareProgram(targetTransform)) return; diff --git a/src/opengl/qopengltexturecache.cpp b/src/opengl/qopengltexturecache.cpp index 6d706325a5..64583c03a9 100644 --- a/src/opengl/qopengltexturecache.cpp +++ b/src/opengl/qopengltexturecache.cpp @@ -61,9 +61,19 @@ void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *p cleanupTexturesForCacheKey(pmd->cacheKey()); } +static quint64 cacheSize() +{ + bool ok = false; + const int envCacheSize = qEnvironmentVariableIntValue("QT_OPENGL_TEXTURE_CACHE_SIZE", &ok); + if (ok) + return envCacheSize; + + return 1024 * 1024; // 1024 MB cache default +} + QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx) : QOpenGLSharedResource(ctx->shareGroup()) - , m_cache(256 * 1024) // 256 MB cache + , m_cache(cacheSize()) { } @@ -71,10 +81,12 @@ QOpenGLTextureCache::~QOpenGLTextureCache() { } -GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &pixmap, QOpenGLTextureUploader::BindOptions options) +QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context, + const QPixmap &pixmap, + QOpenGLTextureUploader::BindOptions options) { if (pixmap.isNull()) - return 0; + return { 0, {} }; QMutexLocker locker(&m_mutex); qint64 key = pixmap.cacheKey(); @@ -83,21 +95,23 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap & QOpenGLCachedTexture *entry = m_cache.object(key); if (entry && entry->options() == options) { context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id()); - return entry->id(); + return { entry->id(), {} }; } } - GLuint id = bindTexture(context, key, pixmap.toImage(), options); - if (id > 0) + BindResult result = bindTexture(context, key, pixmap.toImage(), options); + if (result.id > 0) QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); - return id; + return result; } -GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image, QOpenGLTextureUploader::BindOptions options) +QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context, + const QImage &image, + QOpenGLTextureUploader::BindOptions options) { if (image.isNull()) - return 0; + return { 0, {} }; QMutexLocker locker(&m_mutex); qint64 key = image.cacheKey(); @@ -106,7 +120,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i QOpenGLCachedTexture *entry = m_cache.object(key); if (entry && entry->options() == options) { context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id()); - return entry->id(); + return { entry->id(), {} }; } } @@ -114,14 +128,20 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) options |= QOpenGLTextureUploader::PowerOfTwoBindOption; - GLuint id = bindTexture(context, key, img, options); - if (id > 0) + BindResult result = bindTexture(context, key, img, options); + if (result.id > 0) QImagePixmapCleanupHooks::enableCleanupHooks(image); - return id; + return result; } -GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options) +Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_entry, QOpenGLContext *context, qint64 key, const unsigned char *image, int options); +Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_exit); + +QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context, + qint64 key, + const QImage &image, + QOpenGLTextureUploader::BindOptions options) { Q_TRACE_SCOPE(QOpenGLTextureCache_bindTexture, context, key, image.bits(), options); @@ -134,7 +154,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con m_cache.insert(key, new QOpenGLCachedTexture(id, options, context), cost / 1024); - return id; + return { id, BindResultFlag::NewTexture }; } void QOpenGLTextureCache::invalidate(qint64 key) diff --git a/src/opengl/qopengltexturecache_p.h b/src/opengl/qopengltexturecache_p.h index afc12f0b38..b70520aa1c 100644 --- a/src/opengl/qopengltexturecache_p.h +++ b/src/opengl/qopengltexturecache_p.h @@ -35,10 +35,20 @@ public: QOpenGLTextureCache(QOpenGLContext *); ~QOpenGLTextureCache(); - GLuint bindTexture(QOpenGLContext *context, const QPixmap &pixmap, - QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption); - GLuint bindTexture(QOpenGLContext *context, const QImage &image, - QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption); + enum class BindResultFlag : quint8 { + NewTexture = 0x01 + }; + Q_DECLARE_FLAGS(BindResultFlags, BindResultFlag) + + struct BindResult { + GLuint id; + BindResultFlags flags; + }; + + BindResult bindTexture(QOpenGLContext *context, const QPixmap &pixmap, + QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption); + BindResult bindTexture(QOpenGLContext *context, const QImage &image, + QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption); void invalidate(qint64 key); @@ -46,12 +56,14 @@ public: void freeResource(QOpenGLContext *ctx) override; private: - GLuint bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options); + BindResult bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options); QMutex m_mutex; QCache<quint64, QOpenGLCachedTexture> m_cache; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLTextureCache::BindResultFlags) + class QOpenGLCachedTexture { public: diff --git a/src/opengl/qopenglversionfunctions.h b/src/opengl/qopenglversionfunctions.h index c1942548db..dc01b940bb 100644 --- a/src/opengl/qopenglversionfunctions.h +++ b/src/opengl/qopenglversionfunctions.h @@ -1179,25 +1179,25 @@ public: F(void, NamedFramebufferParameteri, (GLuint framebuffer, GLenum pname, GLint param)) \ F(void, NamedFramebufferRenderbuffer, (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)) \ F(void, CreateFramebuffers, (GLsizei n, GLuint *framebuffers)) \ - F(void, GetNamedBufferSubData, (GLuint buffer, GLintptr offset, GLsizei size, void *data)) \ + F(void, GetNamedBufferSubData, (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data)) \ F(void, GetNamedBufferPointerv, (GLuint buffer, GLenum pname, GLvoid* *params)) \ F(void, GetNamedBufferParameteri64v, (GLuint buffer, GLenum pname, GLint64 *params)) \ F(void, GetNamedBufferParameteriv, (GLuint buffer, GLenum pname, GLint *params)) \ - F(void, FlushMappedNamedBufferRange, (GLuint buffer, GLintptr offset, GLsizei length)) \ + F(void, FlushMappedNamedBufferRange, (GLuint buffer, GLintptr offset, GLsizeiptr length)) \ F(GLboolean, UnmapNamedBuffer, (GLuint buffer)) \ - F(GLvoid *, MapNamedBufferRange, (GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access)) \ + F(GLvoid *, MapNamedBufferRange, (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access)) \ F(GLvoid *, MapNamedBuffer, (GLuint buffer, GLenum access)) \ - F(void, ClearNamedBufferSubData, (GLuint buffer, GLenum internalformat, GLintptr offset, GLsizei size, GLenum format, GLenum type, const void *data)) \ + F(void, ClearNamedBufferSubData, (GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data)) \ F(void, ClearNamedBufferData, (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data)) \ - F(void, CopyNamedBufferSubData, (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizei size)) \ - F(void, NamedBufferSubData, (GLuint buffer, GLintptr offset, GLsizei size, const void *data)) \ - F(void, NamedBufferData, (GLuint buffer, GLsizei size, const void *data, GLenum usage)) \ - F(void, NamedBufferStorage, (GLuint buffer, GLsizei size, const void *data, GLbitfield flags)) \ + F(void, CopyNamedBufferSubData, (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)) \ + F(void, NamedBufferSubData, (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data)) \ + F(void, NamedBufferData, (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage)) \ + F(void, NamedBufferStorage, (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags)) \ F(void, CreateBuffers, (GLsizei n, GLuint *buffers)) \ F(void, GetTransformFeedbacki64_v,(GLuint xfb, GLenum pname, GLuint index, GLint64 *param)) \ F(void, GetTransformFeedbacki_v,(GLuint xfb, GLenum pname, GLuint index, GLint *param)) \ F(void, GetTransformFeedbackiv, (GLuint xfb, GLenum pname, GLint *param)) \ - F(void, TransformFeedbackBufferRange, (GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizei size)) \ + F(void, TransformFeedbackBufferRange, (GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)) \ F(void, TransformFeedbackBufferBase, (GLuint xfb, GLuint index, GLuint buffer)) \ F(void, CreateTransformFeedbacks, (GLsizei n, GLuint *ids)) \ F(void, ClipControl, (GLenum origin, GLenum depth)) \ diff --git a/src/opengl/qopenglversionfunctionsfactory.cpp b/src/opengl/qopenglversionfunctionsfactory.cpp index aad4971fd3..12d00c0554 100644 --- a/src/opengl/qopenglversionfunctionsfactory.cpp +++ b/src/opengl/qopenglversionfunctionsfactory.cpp @@ -135,7 +135,7 @@ static QAbstractOpenGLFunctions *createFunctions(const QOpenGLVersionProfile &ve */ /*! - \fn static T *QOpenGLVersionFunctionsFactory::get(QOpenGLContext *context) + \fn template <class T> static T *QOpenGLVersionFunctionsFactory::get(QOpenGLContext *context) \overload get() diff --git a/src/opengl/qopenglwindow.cpp b/src/opengl/qopenglwindow.cpp index 4c0e9323fa..a3677aa828 100644 --- a/src/opengl/qopenglwindow.cpp +++ b/src/opengl/qopenglwindow.cpp @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE immediately result in a call to paintGL(). Calling update() multiple times in a row will not change the behavior in any way. - This is a slot so it can be connected to a \l QTimer::timeout() signal to + This is a slot so it can be connected to a \l QChronoTimer::timeout() signal to perform animation. Note however that in the modern OpenGL world it is a much better choice to rely on synchronization to the vertical refresh rate of the display. See \l{QSurfaceFormat::setSwapInterval()}{setSwapInterval()} on a @@ -60,6 +60,23 @@ QT_BEGIN_NAMESPACE given OpenGL version and profile, or enabling depth and stencil buffers. + \note It is up to the application to ensure depth and stencil buffers are + requested from the underlying windowing system interface. Without requesting + a non-zero depth buffer size there is no guarantee that a depth buffer will + be available, and as a result depth testing related OpenGL operations may fail + to function as expected. + + Commonly used depth and stencil buffer size requests are 24 and 8, + respectively. For example, a QOpenGLWindow subclass could do this in its + constructor: + + \code + QSurfaceFormat format; + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + setFormat(format); + \endcode + Unlike QWindow, QOpenGLWindow allows opening a painter on itself and perform QPainter-based drawing. @@ -376,7 +393,7 @@ bool QOpenGLWindow::isValid() const /*! Prepares for rendering OpenGL content for this window by making the corresponding context current and binding the framebuffer object, if there is - one, in that context context. + one, in that context. It is not necessary to call this function in most cases, because it is called automatically before invoking paintGL(). It is provided nonetheless to support diff --git a/src/opengl/qtopengl.tracepoints b/src/opengl/qtopengl.tracepoints deleted file mode 100644 index d609e7c9ba..0000000000 --- a/src/opengl/qtopengl.tracepoints +++ /dev/null @@ -1,12 +0,0 @@ -{ -#include <private/qopengl2pexvertexarray_p.h> -#include <private/qopengltextureuploader_p.h> -#include <qopenglframebufferobject.h> -} - -QOpenGLFramebufferObjectPrivate_init_entry(QOpenGLFramebufferObject *qfbo, const QSize &size, int attachment, int texture_target, int internal_format, int samples, bool mipmap) -QOpenGLFramebufferObjectPrivate_init_exit() -QOpenGL2PaintEngineExPrivate_drawTexture_entry(float dl, float dt, float dr, float db, float sl, float st, float sr, float sb, const QSize &textureSize, bool opaque) -QOpenGL2PaintEngineExPrivate_drawTexture_exit() -QOpenGLTextureCache_bindTexture_entry(QOpenGLContext *context, qint64 key, const unsigned char *image, int options) -QOpenGLTextureCache_bindTexture_exit() |