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>
606 if (
w->autoFillBackground()) {
608 if (
w->format().hasAlpha()) {
609 f->glClearColor(0, 0, 0, 0);
611 QColor c =
w->palette().brush(
w->backgroundRole()).color();
615 f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
657#define GL_SRGB 0x8C40
660#define GL_SRGB8 0x8C41
663#define GL_SRGB_ALPHA 0x8C42
665#ifndef GL_SRGB8_ALPHA8
666#define GL_SRGB8_ALPHA8 0x8C43
730 emit q->aboutToResize();
747 const QSize deviceSize =
q->size() *
q->devicePixelRatio();
791 const QSize deviceSize =
q->size() *
q->devicePixelRatio();
801 qWarning(
"QOpenGLWidget: Failed to create wrapper texture");
815 emit q->aboutToCompose();
821 emit q->frameSwapped();
846 qWarning(
"The top-level window is not using OpenGL for composition, '%s' is not compatible with QOpenGLWidget",
865 qWarning(
"QOpenGLWidget: Failed to create context");
875 qWarning(
"QOpenGLWidget: Failed to make context current");
915 q->makeCurrent(targetBuffer);
933 qWarning(
"QOpenGLWidget: No current context, cannot render");
938 qWarning(
"QOpenGLWidget: No fbo, cannot render");
944 static bool warningGiven =
false;
946 qWarning(
"QOpenGLWidget: Stereo is enabled, but no right buffer. Using only left buffer");
964 f->
glViewport(0, 0,
q->width() *
q->devicePixelRatio(),
q->height() *
q->devicePixelRatio());
968 f->glDepthMask(GL_TRUE);
975 f->glEnable(GL_BLEND);
1010 f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1064 if (!
fbos[targetBuffer])
1076 const bool hasAlpha =
q->format().hasAlpha();
1078 res.setDevicePixelRatio(
q->devicePixelRatio());
1095 q->setAutoFillBackground(
true);
1104 return q->format().stereo();
1135 qWarning(
"QOpenGLWidget is not supported on this platform.");
1137 d->setRenderToTexture();
1186 return d->updateBehavior;
1210 qWarning(
"QOpenGLWidget: Already initialized, setting the format has no effect");
1236 return d->initialized ?
d->context->format() :
d->requestedFormat;
1259 qWarning(
"QOpenGLWidget: Already initialized, setting the internal texture format has no effect");
1263 d->textureFormat = texFormat;
1277 return d->textureFormat;
1288 return d->initialized &&
d->context->isValid();
1304 if (!
d->initialized)
1307 d->context->makeCurrent(
d->surface);
1309 if (
d->fbos[
d->currentTargetBuffer])
1310 d->fbos[
d->currentTargetBuffer]->bind();
1331 if (!
d->initialized)
1338 d->setCurrentTargetBuffer(targetBuffer);
1351 if (!
d->initialized)
1354 d->context->doneCurrent();
1408 return d->fbos[targetBuffer] ?
d->fbos[targetBuffer]->handle() : 0;
1482 d->context->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1499 d->fakeHidden =
true;
1502 d->fakeHidden =
false;
1505 if (!
d->initialized)
1533 if (
d->initialized) {
1534 d->ensureRhiDependentResources();
1549 return d->grabFramebuffer();
1566 return d->grabFramebuffer(targetBuffer);
1582 return d->currentTargetBuffer;
1591 if (
d->inBackingStorePaint)
1611 return width() * 1000 / dpmx;
1616 return height() * 1000 / dpmy;
1623 return qRound(dpmx * 0.0254);
1628 return qRound(dpmy * 0.0254);
1633 return qRound(dpmx * 0.0254);
1638 return qRound(dpmy * 0.0254);
1655 if (
d->inBackingStorePaint)
1658 return d->paintDevice;
1670 if (
d->inBackingStorePaint)
1673 if (!
d->initialized)
1676 return d->paintDevice->paintEngine();
1699 switch (e->
type()) {
1701 d->resetRhiDependentResources();
1719 if (!
d->initialized && !
size().isEmpty()) {
1721 if (
d->initialized) {
1743#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
Type type() const
Returns the event type.
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.
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.
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 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.
const QSize & size() const
Returns the new size of the widget.
\variable QRhiGles2InitParams::format
void setPixelSize(const QSize &sz)
Sets the texture size, specified in pixels, to sz.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
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.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
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()
QOpenGLContext * qt_gl_global_share_context()
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
typedef GLsizei(GL_APIENTRYP PFNGLGETFRAMEBUFFERPIXELLOCALSTORAGESIZEEXTPROC)(GLuint target)
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)