Qt 4.8
qpaintengineex_opengl2_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QGRAPHICSCONTEXT_OPENGL2_P_H
43 #define QGRAPHICSCONTEXT_OPENGL2_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QDebug>
57 
58 #include <private/qpaintengineex_p.h>
59 #include <private/qglengineshadermanager_p.h>
60 #include <private/qgl2pexvertexarray_p.h>
61 #include <private/qglpaintdevice_p.h>
62 #include <private/qglpixmapfilter_p.h>
63 #include <private/qfontengine_p.h>
64 #include <private/qdatabuffer_p.h>
65 #include <private/qtriangulatingstroker_p.h>
66 
67 enum EngineMode {
73 };
74 
76 
77 #define GL_STENCIL_HIGH_BIT GLuint(0x80)
78 #define QT_BRUSH_TEXTURE_UNIT GLuint(0)
79 #define QT_IMAGE_TEXTURE_UNIT GLuint(0) //Can be the same as brush texture unit
80 #define QT_MASK_TEXTURE_UNIT GLuint(1)
81 #define QT_BACKGROUND_TEXTURE_UNIT GLuint(2)
82 
84 
85 
87 {
88 public:
92 
93  uint isNew : 1;
103 
105 };
106 
108 {
110 public:
113 
114  bool begin(QPaintDevice *device);
115  void ensureActive();
116  bool end();
117 
118  virtual void clipEnabledChanged();
119  virtual void penChanged();
120  virtual void brushChanged();
121  virtual void brushOriginChanged();
122  virtual void opacityChanged();
123  virtual void compositionModeChanged();
124  virtual void renderHintsChanged();
125  virtual void transformChanged();
126 
127  virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
128  virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
129  QPainter::PixmapFragmentHints hints);
130  virtual void drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap,
131  QPainter::PixmapFragmentHints hints);
132  virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
133  Qt::ImageConversionFlags flags = Qt::AutoColor);
134  virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
135  virtual void fill(const QVectorPath &path, const QBrush &brush);
136  virtual void stroke(const QVectorPath &path, const QPen &pen);
137  virtual void clip(const QVectorPath &path, Qt::ClipOperation op);
138 
139  virtual void drawStaticTextItem(QStaticTextItem *textItem);
140 
141  bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr);
142 
143  Type type() const { return OpenGL2; }
144 
145  virtual void setState(QPainterState *s);
146  virtual QPainterState *createState(QPainterState *orig) const;
148  return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
149  }
150  inline const QOpenGL2PaintEngineState *state() const {
151  return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
152  }
153 
154  void beginNativePainting();
155  void endNativePainting();
156 
157  void invalidateState();
158 
159  QPixmapFilter *pixmapFilter(int type, const QPixmapFilter *prototype);
160 
161  void setRenderTextActive(bool);
162 
163  bool isNativePaintingActive() const;
164  bool supportsTransformations(qreal, const QTransform &) const { return true; }
165 private:
167 };
168 
170 {
172 public:
176  TriStripStrokeFillMode
177  };
178 
180  q(q_ptr),
181  shaderManager(0),
182  width(0), height(0),
183  ctx(0),
184  useSystemClip(true),
185  elementIndicesVBOId(0),
186  opacityArray(0),
187  snapToPixelGrid(false),
188  nativePaintingActive(false),
189  inverseScale(1),
190  lastMaskTextureUsed(0),
191  hasCompatibilityExtension(false)
192  { }
193 
195 
196  void updateBrushTexture();
197  void updateBrushUniforms();
198  void updateMatrix();
199  void updateCompositionMode();
200  void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id = -1);
201 
202  void resetGLState();
203 
204  // fill, stroke, drawTexture, drawPixmaps & drawCachedGlyphs are the main rendering entry-points,
205  // however writeClip can also be thought of as en entry point as it does similar things.
206  void fill(const QVectorPath &path);
207  void stroke(const QVectorPath &path, const QPen &pen);
208  void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false);
209  void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, const QSize &size,
210  QPainter::PixmapFragmentHints hints);
211  void drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap, const QSize &size,
212  QPainter::PixmapFragmentHints hints);
213  void drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem);
214 
215  // Calls glVertexAttributePointer if the pointer has changed
216  inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer);
217 
218  // draws whatever is in the vertex array:
219  void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive);
220  void drawVertexArrays(QGL2PEXVertexArray &vertexArray, GLenum primitive) {
221  drawVertexArrays((const float *) vertexArray.data(), vertexArray.stops(), vertexArray.stopCount(), primitive);
222  }
223 
224  // Composites the bounding rect onto dest buffer:
225  void composite(const QGLRect& boundingRect);
226 
227  // Calls drawVertexArrays to render into stencil buffer:
228  void fillStencilWithVertexArray(const float *data, int count, int *stops, int stopCount, const QGLRect &bounds, StencilFillMode mode);
229  void fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill) {
230  fillStencilWithVertexArray((const float *) vertexArray.data(), 0, vertexArray.stops(), vertexArray.stopCount(),
231  vertexArray.boundingRect(),
232  useWindingFill ? WindingFillMode : OddEvenFillMode);
233  }
234 
235  void setBrush(const QBrush& brush);
236  void transferMode(EngineMode newMode);
237  bool prepareForDraw(bool srcPixelsAreOpaque); // returns true if the program has changed
238  inline void useSimpleShader();
239  inline GLuint location(const QGLEngineShaderManager::Uniform uniform) {
240  return shaderManager->getUniformLocation(uniform);
241  }
242 
243  void clearClip(uint value);
244  void writeClip(const QVectorPath &path, uint value);
245  void resetClipIfNeeded();
246 
247  void updateClipScissorTest();
248  void setScissor(const QRect &rect);
249  void regenerateClip();
250  void systemStateChanged();
251 
252 
253  static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; }
254  static QGL2PaintEngineExPrivate *getData(QGL2PaintEngineEx *engine) { return engine->d_func(); }
255  static void cleanupVectorPath(QPaintEngineEx *engine, void *data);
256 
257 
261  int width, height;
266 
267  // Dirty flags
268  bool matrixDirty; // Implies matrix uniforms are also dirty
274 
275  bool stencilClean; // Has the stencil not been used for clipping so far?
280 
281  QBrush currentBrush; // May not be the state's brush!
283 
285 
291  GLfloat staticVertexCoordinateArray[8];
292  GLfloat staticTextureCoordinateArray[8];
293 
296  GLfloat pmvMatrix[3][3];
297  GLfloat inverseScale;
298 
301 
302  bool needsSync;
304 
305  GLfloat depthRange[2];
306 
308 
311 
316 
320 
321  const GLfloat *vertexAttribPointers[3];
322 
324 };
325 
326 
327 void QGL2PaintEngineExPrivate::setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer)
328 {
329  Q_ASSERT(arrayIndex < 3);
330  if (pointer == vertexAttribPointers[arrayIndex])
331  return;
332 
333  vertexAttribPointers[arrayIndex] = pointer;
334  if (arrayIndex == QT_OPACITY_ATTR)
335  glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, pointer);
336  else
337  glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, pointer);
338 }
339 
341 
342 #endif
QSet< QVectorPath::CacheEntry * > pathCaches
void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer)
static QGLEngineShaderManager * shaderManagerForEngine(QGL2PaintEngineEx *engine)
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QGL2PaintEngineExPrivate * getData(QGL2PaintEngineEx *engine)
QGLEngineShaderManager * shaderManager
#define Q_OPENGL_EXPORT
Definition: qglobal.h:1455
QGL2PEXVertexArray textureCoordinateArray
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define glVertexAttribPointer
Definition: glfunctions.h:71
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
GLuint location(const QGLEngineShaderManager::Uniform uniform)
static const GLuint QT_OPACITY_ATTR
static const QRectF boundingRect(const QPointF *points, int pointCount)
QFontEngineGlyphCache::Type glyphCacheType
QGL2PaintEngineExPrivate(QGL2PaintEngineEx *q_ptr)
#define GL_FALSE
QScopedPointer< QPixmapFilter > colorizeFilter
const QOpenGL2PaintEngineState * state() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QBrush brush() const
Returns the brush in the current paint engine state.
Definition: qpainter.cpp:9273
QScopedPointer< QPixmapFilter > dropShadowFilter
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawVertexArrays(QGL2PEXVertexArray &vertexArray, GLenum primitive)
QDataBuffer< GLfloat > opacityArray
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QGLRect boundingRect() const
QGL2PEXVertexArray vertexCoordinateArray
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
#define GL_FLOAT
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
QOpenGL2PaintEngineState * state()
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
unsigned int GLenum
Definition: main.cpp:50
This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a ...
Definition: qpainter.h:103
The QPixmapFilter class provides the basic functionality for pixmap filter classes.
static void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform)
#define ctx
Definition: qgl.cpp:6094
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QScopedPointer< QPixmapFilter > convolutionFilter
bool supportsTransformations(qreal, const QTransform &) const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
QScopedPointer< QPixmapFilter > blurFilter
static const KeyPair *const end
Type type() const
Reimplement this function to return the paint engine Type.
QPainterState * state()
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
ClipOperation
Definition: qnamespace.h:1495
void fillStencilWithVertexArray(QGL2PEXVertexArray &vertexArray, bool useWindingFill)