5#include <QtGui/QOpenGLContext>
6#include <QtGui/QOffscreenSurface>
7#include <QtGui/QOpenGLFunctions>
8#include <QtGui/QWindow>
9#include <QtGui/QGuiApplication>
10#include <QtGui/QScreen>
11#include <QtGui/qpa/qplatformwindow.h>
12#include <QtGui/qpa/qplatformintegration.h>
13#include <QtOpenGL/QOpenGLFramebufferObject>
14#include <QtOpenGL/QOpenGLPaintDevice>
16#include <QtGui/private/qguiapplication_p.h>
17#include <QtGui/private/qopenglextensions_p.h>
18#include <QtGui/private/qfont_p.h>
19#include <QtGui/private/qopenglcontext_p.h>
20#include <QtOpenGL/private/qopenglframebufferobject_p.h>
21#include <QtOpenGL/private/qopenglpaintdevice_p.h>
23#include <QtWidgets/private/qwidget_p.h>
24#include <QtWidgets/private/qwidgetrepaintmanager_p.h>
601 if (
w->autoFillBackground()) {
603 if (
w->format().hasAlpha()) {
606 QColor c =
w->palette().brush(
w->backgroundRole()).color();
610 f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
652#define GL_SRGB 0x8C40
655#define GL_SRGB8 0x8C41
658#define GL_SRGB_ALPHA 0x8C42
660#ifndef GL_SRGB8_ALPHA8
661#define GL_SRGB8_ALPHA8 0x8C43
725 emit q->aboutToResize();
742 const QSize deviceSize =
q->size() *
q->devicePixelRatio();
784 rhi = repaintManager->rhi();
788 const QSize deviceSize =
q->size() *
q->devicePixelRatio();
798 qWarning(
"QOpenGLWidget: Failed to create wrapper texture");
812 emit q->aboutToCompose();
818 emit q->frameSwapped();
841 rhi = repaintManager->rhi();
846 qWarning(
"The top-level window is not using OpenGL for composition, '%s' is not compatible with QOpenGLWidget",
858 if (contextFromRhi) {
863 qWarning(
"QOpenGLWidget: Failed to create context");
873 qWarning(
"QOpenGLWidget: Failed to make context current");
913 q->makeCurrent(targetBuffer);
931 qWarning(
"QOpenGLWidget: No current context, cannot render");
936 qWarning(
"QOpenGLWidget: No fbo, cannot render");
942 static bool warningGiven =
false;
944 qWarning(
"QOpenGLWidget: Stereo is enabled, but no right buffer. Using only left buffer");
962 f->
glViewport(0, 0,
q->width() *
q->devicePixelRatio(),
q->height() *
q->devicePixelRatio());
966 f->glDepthMask(GL_TRUE);
987 const int gl_color_attachment0 = 0x8CE0;
988 const int gl_depth_attachment = 0x8D00;
989 const int gl_stencil_attachment = 0x8D20;
993 const int gl_depth_stencil_attachment = 0x821A;
996 gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment, gl_depth_stencil_attachment
1000 gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment
1005 f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1042 if (!
fbos[targetBuffer])
1054 const bool hasAlpha =
q->format().hasAlpha();
1056 res.setDevicePixelRatio(
q->devicePixelRatio());
1073 q->setAutoFillBackground(
true);
1082 return q->format().stereo();
1113 qWarning(
"QOpenGLWidget is not supported on this platform.");
1115 d->setRenderToTexture();
1164 return d->updateBehavior;
1188 qWarning(
"QOpenGLWidget: Already initialized, setting the format has no effect");
1214 return d->initialized ?
d->context->format() :
d->requestedFormat;
1237 qWarning(
"QOpenGLWidget: Already initialized, setting the internal texture format has no effect");
1241 d->textureFormat = texFormat;
1255 return d->textureFormat;
1266 return d->initialized &&
d->context->isValid();
1282 if (!
d->initialized)
1285 d->context->makeCurrent(
d->surface);
1287 if (
d->fbos[
d->currentTargetBuffer])
1288 d->fbos[
d->currentTargetBuffer]->bind();
1309 if (!
d->initialized)
1316 d->setCurrentTargetBuffer(targetBuffer);
1329 if (!
d->initialized)
1332 d->context->doneCurrent();
1386 return d->fbos[targetBuffer] ?
d->fbos[targetBuffer]->handle() : 0;
1469 if (
e->size().isEmpty()) {
1470 d->fakeHidden =
true;
1473 d->fakeHidden =
false;
1476 if (!
d->initialized)
1504 if (
d->initialized) {
1505 d->ensureRhiDependentResources();
1520 return d->grabFramebuffer();
1537 return d->grabFramebuffer(targetBuffer);
1553 return d->currentTargetBuffer;
1562 if (
d->inBackingStorePaint)
1582 return width() * 1000 / dpmx;
1587 return height() * 1000 / dpmy;
1594 return qRound(dpmx * 0.0254);
1599 return qRound(dpmy * 0.0254);
1604 return qRound(dpmx * 0.0254);
1609 return qRound(dpmy * 0.0254);
1626 if (
d->inBackingStorePaint)
1629 return d->paintDevice;
1641 if (
d->inBackingStorePaint)
1644 if (!
d->initialized)
1647 return d->paintDevice->paintEngine();
1670 switch (
e->type()) {
1672 d->resetRhiDependentResources();
1690 if (!
d->initialized && !
size().isEmpty() && repaintManager->rhi()) {
1692 if (
d->initialized) {
1714#include "moc_qopenglwidget.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
float alphaF() const noexcept
Returns the alpha color component of this color.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
@ WindowAboutToChangeInternal
static QPlatformIntegration * platformIntegration()
QScreen * primaryScreen
the primary (or default) screen of the application.
void setScreen(QScreen *screen)
Sets the screen to which the offscreen surface is connected.
void create()
Allocates the platform resources associated with the offscreen surface.
void setFormat(const QSurfaceFormat &format)
Sets the offscreen surface format.
GLuint defaultFboRedirect
static QOpenGLContextPrivate * get(QOpenGLContext *context)
bool create()
Attempts to create the OpenGL context with the current configuration.
void setScreen(QScreen *screen)
Sets the screen the OpenGL context should be valid for.
bool makeCurrent(QSurface *surface)
Makes the context current in the current thread, against the given surface.
QSurfaceFormat format() const
Returns the format of the underlying platform context, if create() has been called.
void setShareContext(QOpenGLContext *shareContext)
Makes this context share textures, shaders, and other OpenGL resources with shareContext.
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,...
QScreen * screen() const
Returns the screen the context was created for.
QOpenGLFunctions * functions() const
Get the QOpenGLFunctions instance for this context.
bool hasOpenGLExtension(QOpenGLExtensions::OpenGLExtension extension) const
Returns true if extension is present on this system's OpenGL implementation; false otherwise.
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers, GLenum filter, int readColorAttachmentIndex, int drawColorAttachmentIndex, FramebufferRestorePolicy restorePolicy)
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...
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
Convenience function that calls glClearColor(red, green, blue, alpha).
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
Convenience function that calls glViewport(x, y, width, height).
void glClear(GLbitfield mask)
Convenience function that calls glClear(mask).
The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter.
QScopedPointer< QOpenGLPaintDevicePrivate > d_ptr
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.
qreal devicePixelRatio() const
@ PdmDevicePixelRatioScaled
The QPaintEvent class contains event parameters for paint events.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
The QResizeEvent class contains event parameters for resize events.
\variable QRhiGles2InitParams::format
void setPixelSize(const QSize &sz)
Sets the texture size, specified in pixels, to sz.
Implementation backend() const
const char * backendName() const
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
const QRhiNativeHandles * nativeHandles()
T * data() const noexcept
Returns the value of the pointer referenced by this object.
The QScreen class is used to query screen properties. \inmodule QtGui.
qreal logicalDotsPerInchY
the number of logical dots or pixels per inch in the vertical direction
qreal logicalDotsPerInchX
the number of logical dots or pixels per inch in the horizontal direction
QSizeF physicalSize
the screen's physical size (in millimeters)
QRect geometry
the screen's geometry in pixels
qreal physicalDotsPerInchY
the number of physical dots or pixels per inch in the vertical direction
qreal physicalDotsPerInchX
the number of physical dots or pixels per inch in the horizontal direction
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
QSurfaceFormat format() const override
Returns the actual format of this window.
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiY()
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLsizei const GLenum * attachments
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
const GLintptr const GLsizei const GLuint const GLuint * fbos
GLdouble GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat alpha
static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, bool include_alpha, bool flip)
static bool hasAlpha(const QImage &image)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent