5#include <QtGui/QOpenGLFunctions>
6#include <QtGui/private/qpaintdevicewindow_p.h>
7#include <QtGui/private/qopenglextensions_p.h>
8#include <QtGui/private/qopenglcontext_p.h>
9#include <QtGui/QMatrix4x4>
10#include <QtGui/QOffscreenSurface>
12#include <QtOpenGL/private/qopenglframebufferobject_p.h>
13#include <QtOpenGL/QOpenGLFramebufferObject>
14#include <QtOpenGL/QOpenGLTextureBlitter>
15#include <QtOpenGL/QOpenGLPaintDevice>
138#ifndef GL_READ_FRAMEBUFFER
139#define GL_READ_FRAMEBUFFER 0x8CA8
141#ifndef GL_DRAW_FRAMEBUFFER
142#define GL_DRAW_FRAMEBUFFER 0x8CA9
209 qWarning(
"Attempted to initialize QOpenGLWindow without a platform window");
215 qWarning(
"QOpenGLWindow::beginPaint: Failed to create context");
217 qWarning(
"QOpenGLWindow::beginPaint: Failed to make context current");
234 const int deviceWidth =
q->width() *
q->devicePixelRatio();
235 const int deviceHeight =
q->height() *
q->devicePixelRatio();
236 const QSize deviceSize(deviceWidth, deviceHeight);
241 const int samples =
q->requestedFormat().samples();
246 qWarning(
"QOpenGLWindow: PartialUpdateBlend does not support multisampling");
277 const int deviceWidth =
q->width() *
q->devicePixelRatio();
278 const int deviceHeight =
q->height() *
q->devicePixelRatio();
283 0, 0, deviceWidth, deviceHeight,
284 GL_COLOR_BUFFER_BIT, GL_NEAREST);
319 emit q->frameSwapped();
379 return d->updateBehavior;
390 return d->context &&
d->context->isValid();
423 d->context->makeCurrent(
this);
425 if (!
d->offscreenSurface) {
427 d->offscreenSurface->setFormat(
d->context->format());
428 d->offscreenSurface->create();
430 d->context->makeCurrent(
d->offscreenSurface.data());
452 d->context->doneCurrent();
461 return d->context.data();
470 return d->shareContext;
487 return d->fbo->handle();
489 return ctx->defaultFramebufferObject();
660 return d->paintDevice->depth();
675 return d->paintDevice.data();
681#include "moc_qopenglwindow.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
bool create()
Attempts to create the OpenGL context with the current configuration.
bool makeCurrent(QSurface *surface)
Makes the context current in the current thread, against the given surface.
void setShareContext(QOpenGLContext *shareContext)
Makes this context share textures, shaders, and other OpenGL resources with shareContext.
GLuint defaultFramebufferObject() const
Call this to get the default framebuffer object for the current surface.
void setFormat(const QSurfaceFormat &format)
Sets the format the OpenGL context should be compatible with.
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
QOpenGLFunctions * functions() const
Get the QOpenGLFunctions instance for this context.
void swapBuffers(QSurface *surface)
Swap the back and front buffers of surface.
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
static bool bindDefault()
Switches rendering back to the default, windowing system provided framebuffer.
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL {GL_EXT_framebuffer_blit} extension is present on this system; otherwise r...
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
GLuint handle() const
Returns the OpenGL framebuffer object handle for this framebuffer object (returned by the {glGenFrame...
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
void glBlendFunc(GLenum sfactor, GLenum dfactor)
Convenience function that calls glBlendFunc(sfactor, dfactor).
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
Convenience function that calls glViewport(x, y, width, height).
void glBindFramebuffer(GLenum target, GLuint framebuffer)
Convenience function that calls glBindFramebuffer(target, framebuffer).
void glDisable(GLenum cap)
Convenience function that calls glDisable(cap).
void glEnable(GLenum cap)
Convenience function that calls glEnable(cap).
The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter.
void setDevicePixelRatio(qreal devicePixelRatio)
Sets the device pixel ratio for the paint device to devicePixelRatio.
void setSize(const QSize &size)
Sets the pixel size of the paint device to size.
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 blit(GLuint texture, const QMatrix4x4 &targetTransform, Origin sourceOrigin)
Performs the blit with the source texture texture.
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.
QOpenGLWindowPaintDevice(QOpenGLWindow *window)
void ensureActiveTarget() override
This virtual method is provided as a callback to allow re-binding a target frame buffer object or con...
QScopedPointer< QOffscreenSurface > offscreenSurface
QOpenGLTextureBlitter blitter
QScopedPointer< QOpenGLContext > context
static QOpenGLWindowPrivate * get(QOpenGLWindow *w)
QScopedPointer< QOpenGLWindowPaintDevice > paintDevice
QScopedPointer< QOpenGLFramebufferObject > fbo
QOpenGLContext * shareContext
QOpenGLWindow::UpdateBehavior updateBehavior
void flush(const QRegion ®ion) override
void beginPaint(const QRegion ®ion) override
QOpenGLWindowPrivate(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior)
GLuint defaultFramebufferObject() const
The framebuffer object handle used by this window.
virtual void paintUnderGL()
The virtual function is called before each invocation of paintGL().
~QOpenGLWindow()
Destroys the QOpenGLWindow instance, freeing its resources.
virtual void initializeGL()
This virtual function is called once before the first call to paintGL() or resizeGL().
QOpenGLContext * shareContext() const
void resizeEvent(QResizeEvent *event) override
Resize event handler.
void paintEvent(QPaintEvent *event) override
Paint event handler.
QPaintDevice * redirected(QPoint *) const override
void makeCurrent()
Prepares for rendering OpenGL content for this window by making the corresponding context current and...
UpdateBehavior
This enum describes the update strategy of the QOpenGLWindow.
UpdateBehavior updateBehavior() const
int metric(PaintDeviceMetric metric) const override
virtual void paintGL()
This virtual function is called whenever the window contents needs to be painted.
virtual void paintOverGL()
This virtual function is called after each invocation of paintGL().
QOpenGLContext * context() const
virtual void resizeGL(int w, int h)
This virtual function is called whenever the widget has been resized.
void doneCurrent()
Releases the context.
QOpenGLWindow(UpdateBehavior updateBehavior=NoPartialUpdate, QWindow *parent=nullptr)
Constructs a new QOpenGLWindow with the given parent and updateBehavior.
QImage grabFramebuffer()
Returns a copy of the framebuffer.
int width
the width of the window's geometry
int metric(PaintDeviceMetric metric) const override
int height
the height of the window's geometry
qreal devicePixelRatio() const
The QPaintEvent class contains event parameters for paint events.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
The QResizeEvent class contains event parameters for resize events.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QSurfaceFormat format() const override
Returns the actual format of this window.
QSize size() const override
Returns the size of the window excluding any window frame.
Combined button and popup list for selecting options.
QOpenGLContext * qt_gl_global_share_context()
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, bool include_alpha, bool flip)
#define GL_DRAW_FRAMEBUFFER
#define GL_READ_FRAMEBUFFER
static bool hasAlpha(const QImage &image)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent