summaryrefslogtreecommitdiffstats
path: root/examples/widgets/painting/shared/fbopaintdevice.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-10-24 17:41:51 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-10-27 16:22:59 +0200
commit7c59c5ed13dd796b4a77a56cb7badc34aead1adb (patch)
tree82e80c50bb3c3cdee77b0b1cdd486ccd43b629fd /examples/widgets/painting/shared/fbopaintdevice.cpp
parent333650c596890fb5117c3ab5c4295838600248f2 (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/shared/fbopaintdevice.cpp')
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.cpp75
1 files changed, 0 insertions, 75 deletions
diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp
deleted file mode 100644
index 5875e6574b..0000000000
--- a/examples/widgets/painting/shared/fbopaintdevice.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "fbopaintdevice.h"
-
-#include <QOffscreenSurface>
-#include <QOpenGLFunctions>
-
-QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit,
- QOpenGLFramebufferObject::Attachment attachment)
- : QOpenGLPaintDevice(size)
-{
- QOpenGLFramebufferObjectFormat format;
- format.setAttachment(attachment);
- format.setSamples(4);
- m_framebufferObject = new QOpenGLFramebufferObject(size, format);
- QOffscreenSurface *surface = new QOffscreenSurface();
- surface->create();
- m_surface = surface;
- setPaintFlipped(flipped);
- if (clearOnInit) {
- m_framebufferObject->bind();
-
- context()->functions()->glClearColor(0, 0, 0, 0);
- context()->functions()->glClear(GL_COLOR_BUFFER_BIT);
- }
- m_resolvedFbo = new QOpenGLFramebufferObject(m_framebufferObject->size(), m_framebufferObject->attachment());
-}
-
-QFboPaintDevice::~QFboPaintDevice()
-{
- delete m_framebufferObject;
- delete m_resolvedFbo;
- delete m_surface;
-}
-
-void QFboPaintDevice::ensureActiveTarget()
-{
- if (QOpenGLContext::currentContext() != context())
- context()->makeCurrent(m_surface);
-
- m_framebufferObject->bind();
-}
-
-GLuint QFboPaintDevice::texture()
-{
- m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
- QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
- return m_resolvedFbo->texture();
-}
-
-GLuint QFboPaintDevice::takeTexture()
-{
- m_resolvedFbo->bind(); // to get the backing texture recreated if it was taken (in takeTexture) previously
- // We have multisamples so we can't just forward takeTexture(), have to resolve first.
- QOpenGLFramebufferObject::blitFramebuffer(m_resolvedFbo, m_framebufferObject);
- return m_resolvedFbo->takeTexture();
-}
-
-QImage QFboPaintDevice::toImage() const
-{
- QOpenGLContext *currentContext = QOpenGLContext::currentContext();
- QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr;
-
- context()->makeCurrent(m_surface);
-
- QImage image = m_framebufferObject->toImage(!paintFlipped());
-
- if (currentContext)
- currentContext->makeCurrent(currentSurface);
- else
- context()->doneCurrent();
-
- return image;
-}