Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qopenglpaintengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOPENGLPAINTENGINE_P_H
5#define QOPENGLPAINTENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QDebug>
19
20#include <qopenglpaintdevice.h>
21
22#include <private/qpaintengineex_p.h>
23#include <private/qopenglengineshadermanager_p.h>
24#include <private/qopengl2pexvertexarray_p.h>
25#include <private/qfontengine_p.h>
26#include <private/qdatabuffer_p.h>
27#include <private/qtriangulatingstroker_p.h>
28
29#include <private/qopenglextensions_p.h>
30
31#include <QOpenGLVertexArrayObject>
32#include <QOpenGLBuffer>
33
41
43
44#define GL_STENCIL_HIGH_BIT GLuint(0x80)
45#define QT_UNKNOWN_TEXTURE_UNIT GLuint(-1)
46#define QT_DEFAULT_TEXTURE_UNIT GLuint(0)
47#define QT_BRUSH_TEXTURE_UNIT GLuint(0)
48#define QT_IMAGE_TEXTURE_UNIT GLuint(0) //Can be the same as brush texture unit
49#define QT_MASK_TEXTURE_UNIT GLuint(1)
50#define QT_BACKGROUND_TEXTURE_UNIT GLuint(2)
51
53
74
75class Q_OPENGL_EXPORT QOpenGL2PaintEngineEx : public QPaintEngineEx
76{
77 Q_DECLARE_PRIVATE(QOpenGL2PaintEngineEx)
78public:
81
82 bool begin(QPaintDevice *device) override;
83 void ensureActive();
84 bool end() override;
85
86 virtual void clipEnabledChanged() override;
87 virtual void penChanged() override;
88 virtual void brushChanged() override;
89 virtual void brushOriginChanged() override;
90 virtual void opacityChanged() override;
91 virtual void compositionModeChanged() override;
92 virtual void renderHintsChanged() override;
93 virtual void transformChanged() override;
94
95 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
96 virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
97 QPainter::PixmapFragmentHints hints) override;
98 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
99 Qt::ImageConversionFlags flags = Qt::AutoColor) override;
100 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
101 virtual void fill(const QVectorPath &path, const QBrush &brush) override;
102 virtual void stroke(const QVectorPath &path, const QPen &pen) override;
103 virtual void clip(const QVectorPath &path, Qt::ClipOperation op) override;
104
105 virtual void drawStaticTextItem(QStaticTextItem *textItem) override;
106
107 bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr);
108
109 Type type() const override { return OpenGL2; }
110
111 virtual void setState(QPainterState *s) override;
112 virtual QPainterState *createState(QPainterState *orig) const override;
114 return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
115 }
116 inline const QOpenGL2PaintEngineState *state() const {
117 return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
118 }
119
120 void beginNativePainting() override;
121 void endNativePainting() override;
122
123 void invalidateState();
124
126
127 bool isNativePaintingActive() const;
128 bool requiresPretransformedGlyphPositions(QFontEngine *, const QTransform &) const override { return false; }
129 bool shouldDrawCachedGlyphs(QFontEngine *, const QTransform &) const override;
130
131private:
132 Q_DISABLE_COPY_MOVE(QOpenGL2PaintEngineEx)
133
135};
136
137// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's
138// all the GL2 engine uses:
139#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT 3
140
142{
143 Q_DECLARE_PUBLIC(QOpenGL2PaintEngineEx)
144public:
148 TriStripStrokeFillMode
149 };
150
152 q(q_ptr),
153 shaderManager(nullptr),
154 width(0), height(0),
155 ctx(nullptr),
156 useSystemClip(true),
157 elementIndicesVBOId(0),
158 opacityArray(0),
159 snapToPixelGrid(false),
160 nativePaintingActive(false),
161 inverseScale(1),
162 lastTextureUnitUsed(QT_UNKNOWN_TEXTURE_UNIT),
163 vertexBuffer(QOpenGLBuffer::VertexBuffer),
164 texCoordBuffer(QOpenGLBuffer::VertexBuffer),
165 opacityBuffer(QOpenGLBuffer::VertexBuffer),
166 indexBuffer(QOpenGLBuffer::IndexBuffer)
167 { }
168
170
171 void updateBrushTexture();
172 void updateBrushUniforms();
173 void updateMatrix();
174 void updateCompositionMode();
175
176 enum TextureUpdateMode { UpdateIfNeeded, ForceUpdate };
177 template<typename T>
178 void updateTexture(GLenum textureUnit, const T &texture, GLenum wrapMode, GLenum filterMode, TextureUpdateMode updateMode = UpdateIfNeeded);
179 template<typename T>
180 GLuint bindTexture(const T &texture, bool *newTextureCreated);
181 void activateTextureUnit(GLenum textureUnit);
182
183 void resetGLState();
184
185 // fill, stroke, drawTexture, drawPixmaps & drawCachedGlyphs are the main rendering entry-points,
186 // however writeClip can also be thought of as en entry point as it does similar things.
187 void fill(const QVectorPath &path);
188 void stroke(const QVectorPath &path, const QPen &pen);
189 void drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false);
190 void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
191 QPainter::PixmapFragmentHints hints);
192 void drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, QStaticTextItem *staticTextItem);
193
194 // Calls glVertexAttributePointer if the pointer has changed
195 inline void uploadData(unsigned int arrayIndex, const GLfloat *data, GLuint count);
196 inline bool uploadIndexData(const void *data, GLenum indexValueType, GLuint count);
197
198 // draws whatever is in the vertex array:
199 void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive);
200 void drawVertexArrays(QOpenGL2PEXVertexArray &vertexArray, GLenum primitive) {
201 drawVertexArrays((const float *) vertexArray.data(), vertexArray.stops(), vertexArray.stopCount(), primitive);
202 }
203
204 // Composites the bounding rect onto dest buffer:
205 void composite(const QOpenGLRect& boundingRect);
206
207 // Calls drawVertexArrays to render into stencil buffer:
208 void fillStencilWithVertexArray(const float *data, int count, int *stops, int stopCount, const QOpenGLRect &bounds, StencilFillMode mode);
209 void fillStencilWithVertexArray(QOpenGL2PEXVertexArray& vertexArray, bool useWindingFill) {
210 fillStencilWithVertexArray((const float *) vertexArray.data(), 0, vertexArray.stops(), vertexArray.stopCount(),
211 vertexArray.boundingRect(),
212 useWindingFill ? WindingFillMode : OddEvenFillMode);
213 }
214
215 void setBrush(const QBrush& brush);
216 void transferMode(EngineMode newMode);
217 bool prepareForDraw(bool srcPixelsAreOpaque); // returns true if the program has changed
218 bool prepareForCachedGlyphDraw(const QFontEngineGlyphCache &cache);
219 inline void useSimpleShader();
221 return shaderManager->getUniformLocation(uniform);
222 }
223
224 void clearClip(uint value);
225 void writeClip(const QVectorPath &path, uint value);
226 void resetClipIfNeeded();
227
228 void updateClipScissorTest();
229 void setScissor(const QRect &rect);
230 void regenerateClip();
231 void systemStateChanged() override;
232
233 void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
234 void syncGlState();
235
238 static void cleanupVectorPath(QPaintEngineEx *engine, void *data);
239
241
249
250 bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT];
251
252 // Dirty flags
253 bool matrixDirty; // Implies matrix uniforms are also dirty
259
260 bool stencilClean; // Has the stencil not been used for clipping so far?
265
266 QBrush currentBrush; // May not be the state's brush!
268
270
273 QList<GLushort> elementIndices;
275 QDataBuffer<GLfloat> opacityArray;
276 GLfloat staticVertexCoordinateArray[8];
277 GLfloat staticTextureCoordinateArray[8];
278
281 GLfloat pmvMatrix[3][3];
283
286
292
295
298
299 QVarLengthArray<GLuint, 8> unusedVBOSToClean;
300 QVarLengthArray<GLuint, 8> unusedIBOSToClean;
301
302 const GLfloat *vertexAttribPointers[3];
303};
304
305
307{
308 Q_ASSERT(arrayIndex < 3);
309
310 if (arrayIndex == QT_VERTEX_COORDS_ATTR) {
311 vertexBuffer.bind();
312 vertexBuffer.allocate(data, count * sizeof(float));
313 }
314 if (arrayIndex == QT_TEXTURE_COORDS_ATTR) {
315 texCoordBuffer.bind();
316 texCoordBuffer.allocate(data, count * sizeof(float));
317 }
318 if (arrayIndex == QT_OPACITY_ATTR) {
319 opacityBuffer.bind();
320 opacityBuffer.allocate(data, count * sizeof(float));
321
322 funcs.glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
323 } else {
324 funcs.glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
325 }
326}
327
329{
330 Q_ASSERT(indexValueType == GL_UNSIGNED_SHORT || indexValueType == GL_UNSIGNED_INT);
331 indexBuffer.bind();
332 indexBuffer.allocate(
333 data,
334 count * (indexValueType == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32)));
335 return true;
336}
337
339
340#endif
IOBluetoothDevice * device
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtGui
Definition qimage.h:37
QOpenGLEngineShaderManager * shaderManager
void drawVertexArrays(QOpenGL2PEXVertexArray &vertexArray, GLenum primitive)
bool uploadIndexData(const void *data, GLenum indexValueType, GLuint count)
QOpenGL2PaintEngineExPrivate(QOpenGL2PaintEngineEx *q_ptr)
QOpenGL2PEXVertexArray vertexCoordinateArray
QFontEngine::GlyphFormat glyphCacheFormat
QVarLengthArray< GLuint, 8 > unusedVBOSToClean
GLuint bindTexture(const T &texture, bool *newTextureCreated)
QOpenGL2PEXVertexArray textureCoordinateArray
void drawTexture(const QOpenGLRect &dest, const QOpenGLRect &src, const QSize &textureSize, bool opaque, bool pattern=false)
static QOpenGLEngineShaderManager * shaderManagerForEngine(QOpenGL2PaintEngineEx *engine)
void uploadData(unsigned int arrayIndex, const GLfloat *data, GLuint count)
void fillStencilWithVertexArray(QOpenGL2PEXVertexArray &vertexArray, bool useWindingFill)
QDataBuffer< GLfloat > opacityArray
GLuint location(const QOpenGLEngineShaderManager::Uniform uniform)
static QOpenGL2PaintEngineExPrivate * getData(QOpenGL2PaintEngineEx *engine)
QVarLengthArray< GLuint, 8 > unusedIBOSToClean
Type type() const override
Reimplement this function to return the paint engine \l{Type}.
void setRenderTextActive(bool)
bool requiresPretransformedGlyphPositions(QFontEngine *, const QTransform &) const override
QOpenGL2PaintEngineState * state()
const QOpenGL2PaintEngineState * state() const
The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects.
\inmodule QtGui
The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter.
The QOpenGLVertexArrayObject class wraps an OpenGL Vertex Array Object.
QPainterState * state()
This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a ...
Definition qpainter.h:64
\inmodule QtGui
Definition qpen.h:28
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\inmodule QtGui
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
EGLContext ctx
static VulkanServerBufferGlFunctions * funcs
QCache< int, Employee > cache
[0]
rect
[4]
Combined button and popup list for selecting options.
@ AutoColor
Definition qnamespace.h:478
ClipOperation
Definition brush.cpp:5
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static const GLuint QT_TEXTURE_COORDS_ATTR
static const GLuint QT_OPACITY_ATTR
static QT_BEGIN_NAMESPACE const GLuint QT_VERTEX_COORDS_ATTR
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
GLenum mode
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLuint GLuint end
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum src
GLint GLsizei width
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLbitfield flags
GLenum GLuint texture
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
GLubyte * pattern
#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT
@ ImageOpacityArrayDrawingMode
@ ImageArrayDrawingMode
@ TextDrawingMode
@ BrushDrawingMode
@ ImageDrawingMode
#define QT_UNKNOWN_TEXTURE_UNIT
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define GLuint
#define GL_FLOAT
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
unsigned int uint
Definition qtypes.h:34
p drawImage(offset, thumbnail)
QObject::connect nullptr
ba fill(true)
QSharedPointer< T > other(t)
[5]
widget render & pixmap
QJSEngine engine
[0]
Definition moc.h:23