diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-10-24 17:41:51 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-10-27 16:22:59 +0200 |
commit | 7c59c5ed13dd796b4a77a56cb7badc34aead1adb (patch) | |
tree | 82e80c50bb3c3cdee77b0b1cdd486ccd43b629fd /examples/widgets/painting/composition | |
parent | 333650c596890fb5117c3ab5c4295838600248f2 (diff) |
Examples: remove OpenGL code paths from painting examples
The extra code for using the OpenGL paint engine is significant enough
to be distracting from what the examples are supposed to show. If we
want to show how to use QPainter on an OpenGL widget, then we can make
dedicated and documented examples for that, in the OpenGL category. And
we have such examples in the Qt OpenGL module anyway.
As is, the examples feel more like manual tests of the OpenGL paint
engine; if we need more coverage there, then we can add it there.
Change-Id: I7b56ea6d08c02cd0a1050ab03991656a0538498d
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'examples/widgets/painting/composition')
-rw-r--r-- | examples/widgets/painting/composition/composition.cpp | 117 | ||||
-rw-r--r-- | examples/widgets/painting/composition/composition.h | 13 |
2 files changed, 13 insertions, 117 deletions
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp index b902498b2d..b4fb4fa3f7 100644 --- a/examples/widgets/painting/composition/composition.cpp +++ b/examples/widgets/painting/composition/composition.cpp @@ -10,11 +10,6 @@ #include <QMouseEvent> #include <qmath.h> -#if QT_CONFIG(opengl) -#include <QOpenGLFunctions> -#include <QOpenGLWindow> -#endif - const int animationInterval = 15; // update every 16 ms = ~60FPS CompositionWidget::CompositionWidget(QWidget *parent) @@ -94,12 +89,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) QPushButton *showSourceButton = new QPushButton(mainGroup); showSourceButton->setText(tr("Show Source")); -#if QT_CONFIG(opengl) - QPushButton *enableOpenGLButton = new QPushButton(mainGroup); - enableOpenGLButton->setText(tr("Use OpenGL")); - enableOpenGLButton->setCheckable(true); - enableOpenGLButton->setChecked(view->usesOpenGL()); -#endif QPushButton *whatsThisButton = new QPushButton(mainGroup); whatsThisButton->setText(tr("What's This?")); whatsThisButton->setCheckable(true); @@ -121,9 +110,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) mainGroupLayout->addWidget(animateButton); mainGroupLayout->addWidget(whatsThisButton); mainGroupLayout->addWidget(showSourceButton); -#if QT_CONFIG(opengl) - mainGroupLayout->addWidget(enableOpenGLButton); -#endif QGridLayout *modesLayout = new QGridLayout(modesGroup); modesLayout->addWidget(rbClear, 0, 0); @@ -165,9 +151,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled); connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked); connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource); -#if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL); -#endif connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled); circleColorSlider->setValue(270); @@ -217,10 +200,6 @@ CompositionRenderer::CompositionRenderer(QWidget *parent) m_circle_pos = QPoint(200, 100); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); -#if QT_CONFIG(opengl) - m_pbuffer_size = 1024; - m_base_tex = 0; -#endif } CompositionRenderer::~CompositionRenderer() @@ -313,89 +292,25 @@ void CompositionRenderer::drawSource(QPainter &p) void CompositionRenderer::paint(QPainter *painter) { -#if QT_CONFIG(opengl) - if (usesOpenGL() && glWindow()->isValid()) { - auto *funcs = QOpenGLContext::currentContext()->functions(); - - if (!m_blitter.isCreated()) - m_blitter.create(); - - int new_pbuf_size = m_pbuffer_size; - while (size().width() > new_pbuf_size || size().height() > new_pbuf_size) - new_pbuf_size *= 2; - - while (size().width() < new_pbuf_size/2 && size().height() < new_pbuf_size/2) - new_pbuf_size /= 2; - - if (!m_fbo || new_pbuf_size != m_pbuffer_size) { - m_fbo.reset(new QFboPaintDevice(QSize(new_pbuf_size, new_pbuf_size), false, false)); - m_pbuffer_size = new_pbuf_size; - } - - if (size() != m_previous_size) { - m_previous_size = size(); - QPainter p(m_fbo.get()); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(QRect(QPoint(0, 0), size()), Qt::transparent); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - drawBase(p); - p.end(); - if (m_base_tex) - funcs->glDeleteTextures(1, &m_base_tex); - m_base_tex = m_fbo->takeTexture(); - } - - painter->beginNativePainting(); - uint compositingTex; - { - QPainter p(m_fbo.get()); - p.beginNativePainting(); - m_blitter.bind(); - const QRect targetRect(QPoint(0, 0), m_fbo->size()); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size())); - m_blitter.blit(m_base_tex, target, QOpenGLTextureBlitter::OriginBottomLeft); - m_blitter.release(); - p.endNativePainting(); - drawSource(p); - p.end(); - compositingTex = m_fbo->texture(); - } - painter->endNativePainting(); - - painter->beginNativePainting(); - funcs->glEnable(GL_BLEND); - funcs->glBlendEquation(GL_FUNC_ADD); - funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - m_blitter.bind(); - const QRect targetRect(QPoint(0, 0), m_fbo->size()); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size())); - m_blitter.blit(compositingTex, target, QOpenGLTextureBlitter::OriginBottomLeft); - m_blitter.release(); - painter->endNativePainting(); - } else -#endif - { - // using a QImage - if (m_buffer.size() != size()) { - m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); - m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); + if (m_buffer.size() != size()) { + m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); + m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); - m_base_buffer.fill(0); + m_base_buffer.fill(0); - QPainter p(&m_base_buffer); + QPainter p(&m_base_buffer); - drawBase(p); - } - - memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes()); + drawBase(p); + } - { - QPainter p(&m_buffer); - drawSource(p); - } + memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes()); - painter->drawImage(0, 0, m_buffer); + { + QPainter p(&m_buffer); + drawSource(p); } + + painter->drawImage(0, 0, m_buffer); } void CompositionRenderer::mousePressEvent(QMouseEvent *e) @@ -443,12 +358,6 @@ void CompositionRenderer::setCirclePos(const QPointF &pos) const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect(); m_circle_pos = pos; const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect(); -#if QT_CONFIG(opengl) - if (usesOpenGL()) { - update(); - return; - } -#endif update(oldRect | newRect); } diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h index 0745eb41b9..6a5206da08 100644 --- a/examples/widgets/painting/composition/composition.h +++ b/examples/widgets/painting/composition/composition.h @@ -6,11 +6,6 @@ #include "arthurwidgets.h" -#if QT_CONFIG(opengl) -#include "fbopaintdevice.h" -#include <QOpenGLTextureBlitter> -#endif - #include <QPainter> #include <QEvent> @@ -143,14 +138,6 @@ private: ObjectType m_current_object; bool m_animation_enabled; int m_animationTimer; - -#if QT_CONFIG(opengl) - std::unique_ptr<QFboPaintDevice> m_fbo; - int m_pbuffer_size; // width==height==size of pbuffer - uint m_base_tex; - QSize m_previous_size; - QOpenGLTextureBlitter m_blitter; -#endif }; #endif // COMPOSITION_H |