4#include <QtOpenGL/QOpenGLFramebufferObject>
5#include <QtGui/QOpenGLContext>
6#include <QtGui/QWindow>
8#include <qpa/qplatformbackingstore.h>
43QOpenGLCompositor::QOpenGLCompositor()
49 m_updateTimer.setSingleShot(
true);
50 m_updateTimer.setInterval(0);
54QOpenGLCompositor::~QOpenGLCompositor()
64 m_nativeTargetGeometry = nativeTargetGeometry;
76 m_rotationMatrix.
rotate(degrees, 0, 0, 1);
82 m_updateTimer.
start();
87 Q_ASSERT(m_context && m_targetWindow);
90 renderAll(fbo.
data());
91 return fbo->toImage();
94void QOpenGLCompositor::handleRenderAllRequest()
96 Q_ASSERT(m_context && m_targetWindow);
106 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
107 glViewport(0, 0, m_nativeTargetGeometry.
width(), m_nativeTargetGeometry.
height());
114 for (
int i = 0;
i < m_windows.
size(); ++
i)
117 for (
int i = 0;
i < m_windows.
size(); ++
i)
118 render(m_windows.
at(
i));
126 for (
int i = 0;
i < m_windows.
size(); ++
i)
139 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
160 const QRect &targetWindowRect,
178 const uint textureId =
textures->texture(idx)->nativeTexture().object;
188 const QRect targetWindowRect(
QPoint(0, 0), m_targetWindow->geometry().
size());
189 float currentOpacity = 1.0f;
191 const QRect sourceWindowRect =
window->sourceWindow()->geometry();
194 const float opacity =
window->sourceWindow()->opacity();
195 if (opacity != currentOpacity) {
196 currentOpacity = opacity;
207 }
else if (
textures->count() == 1) {
209 const bool translucent =
window->sourceWindow()->requestedFormat().alphaBufferSize() > 0;
210 blend.
set(translucent);
249 ensureCorrectZOrder();
271 ensureCorrectZOrder();
280 if (idx != -1 && idx != newIdx) {
281 m_windows.
move(idx, newIdx);
282 ensureCorrectZOrder();
288void QOpenGLCompositor::ensureCorrectZOrder()
290 const auto originalOrder = m_windows;
292 std::sort(m_windows.
begin(), m_windows.
end(),
294 QWindow *w1 = cw1->sourceWindow();
295 QWindow *w2 = cw2->sourceWindow();
299 if (w1 == m_targetWindow || w2 == m_targetWindow)
300 return w1 == m_targetWindow;
303 if (w2->isAncestorOf(w1)) {
308 if (
w1->isAncestorOf(
w2)) {
327 if (isPurePopup1 != isPurePopup2)
328 return !isPurePopup1;
331 if (isTool1 != isTool2)
335 return originalOrder.indexOf(cw1) < originalOrder.indexOf(cw2);
341#include "moc_qopenglcompositor_p.cpp"
qsizetype size() const noexcept
bool isEmpty() const noexcept
const T & constLast() const noexcept
bool removeOne(const AT &t)
const_reference at(qsizetype i) const noexcept
void move(qsizetype from, qsizetype to)
void append(parameter_type t)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void rotate(float angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
void setToIdentity()
Sets this matrix to the identity.
virtual void endCompositing()
virtual void beginCompositing()
A generic OpenGL-based compositor.
void setTargetContext(QOpenGLContext *context)
void removeWindow(QOpenGLCompositorWindow *window)
static QOpenGLCompositor * instance()
void setTargetWindow(QWindow *window, const QRect &nativeTargetGeometry)
void moveToTop(QOpenGLCompositorWindow *window)
void setRotation(int degrees)
QOpenGLContext * context() const
QWindow * targetWindow() const
void topWindowChanged(QOpenGLCompositorWindow *window)
void addWindow(QOpenGLCompositorWindow *window)
void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx)
bool makeCurrent(QSurface *surface)
Makes the context current in the current thread, against the given surface.
void swapBuffers(QSurface *surface)
Swap the back and front buffers of surface.
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
The QOpenGLTextureBlitter class provides a convenient way to draw textured quads via OpenGL.
bool create()
Initializes the graphics resources used by the blitter.
void destroy()
Frees all graphics resources held by the blitter.
void setOpacity(float opacity)
Changes the opacity to opacity.
void blit(GLuint texture, const QMatrix4x4 &targetTransform, Origin sourceOrigin)
Performs the blit with the source texture texture.
static QMatrix3x3 sourceTransform(const QRectF &subTexture, const QSize &textureSize, Origin origin)
Calculates a 3x3 matrix suitable as the input to blit().
void release()
Unbinds the graphics resources used by the blitter.
static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport)
Calculates a target transform suitable for blit().
void bind(GLenum target=GL_TEXTURE_2D)
Binds the graphics resources used by the blitter.
\inmodule QtCore\reentrant
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Combined button and popup list for selecting options.
static QOpenGLCompositor * compositor
static QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &sourceWindowRect, const QRect &targetWindowRect, QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix)
GLuint const GLuint GLuint const GLuint * textures
GLbitfield GLuint64 timeout
[4]
GLsizei GLsizei GLchar * source
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
if(qFloatDistance(a, b)<(1<< 7))
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept