|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
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 { |
|
68 ImageDrawingMode, |
|
69 TextDrawingMode, |
|
70 BrushDrawingMode, |
|
71 ImageArrayDrawingMode |
|
72 }; |
|
73 |
|
74 QT_BEGIN_NAMESPACE |
|
75 |
|
76 class QGL2PaintEngineExPrivate; |
|
77 |
|
78 |
|
79 class QOpenGL2PaintEngineState : public QPainterState |
|
80 { |
|
81 public: |
|
82 QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other); |
|
83 QOpenGL2PaintEngineState(); |
|
84 ~QOpenGL2PaintEngineState(); |
|
85 |
|
86 uint isNew : 1; |
|
87 uint needsClipBufferClear : 1; |
|
88 uint clipTestEnabled : 1; |
|
89 uint canRestoreClip : 1; |
|
90 uint matrixChanged : 1; |
|
91 uint compositionModeChanged : 1; |
|
92 uint opacityChanged : 1; |
|
93 uint renderHintsChanged : 1; |
|
94 uint clipChanged : 1; |
|
95 uint currentClip : 8; |
|
96 |
|
97 QRect rectangleClip; |
|
98 }; |
|
99 |
|
100 class Q_OPENGL_EXPORT QGL2PaintEngineEx : public QPaintEngineEx |
|
101 { |
|
102 Q_DECLARE_PRIVATE(QGL2PaintEngineEx) |
|
103 public: |
|
104 QGL2PaintEngineEx(); |
|
105 ~QGL2PaintEngineEx(); |
|
106 |
|
107 bool begin(QPaintDevice *device); |
|
108 bool end(); |
|
109 |
|
110 void ensureActive(); |
|
111 |
|
112 virtual void fill(const QVectorPath &path, const QBrush &brush); |
|
113 virtual void stroke(const QVectorPath &path, const QPen &pen); |
|
114 virtual void clip(const QVectorPath &path, Qt::ClipOperation op); |
|
115 |
|
116 virtual void clipEnabledChanged(); |
|
117 virtual void penChanged(); |
|
118 virtual void brushChanged(); |
|
119 virtual void brushOriginChanged(); |
|
120 virtual void opacityChanged(); |
|
121 virtual void compositionModeChanged(); |
|
122 virtual void renderHintsChanged(); |
|
123 virtual void transformChanged(); |
|
124 |
|
125 |
|
126 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); |
|
127 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, |
|
128 Qt::ImageConversionFlags flags = Qt::AutoColor); |
|
129 virtual void drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr); |
|
130 |
|
131 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem); |
|
132 |
|
133 virtual void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints); |
|
134 |
|
135 Type type() const { return OpenGL2; } |
|
136 |
|
137 void setState(QPainterState *s); |
|
138 QPainterState *createState(QPainterState *orig) const; |
|
139 inline QOpenGL2PaintEngineState *state() { |
|
140 return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
|
141 } |
|
142 inline const QOpenGL2PaintEngineState *state() const { |
|
143 return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
|
144 } |
|
145 |
|
146 void beginNativePainting(); |
|
147 void endNativePainting(); |
|
148 |
|
149 const QGLContext* context(); |
|
150 |
|
151 QPixmapFilter *pixmapFilter(int type, const QPixmapFilter *prototype); |
|
152 |
|
153 void setRenderTextActive(bool); |
|
154 |
|
155 private: |
|
156 Q_DISABLE_COPY(QGL2PaintEngineEx) |
|
157 }; |
|
158 |
|
159 |
|
160 class QGL2PaintEngineExPrivate : public QPaintEngineExPrivate |
|
161 { |
|
162 Q_DECLARE_PUBLIC(QGL2PaintEngineEx) |
|
163 public: |
|
164 enum StencilFillMode { |
|
165 OddEvenFillMode, |
|
166 WindingFillMode, |
|
167 TriStripStrokeFillMode |
|
168 }; |
|
169 |
|
170 QGL2PaintEngineExPrivate(QGL2PaintEngineEx *q_ptr) : |
|
171 q(q_ptr), |
|
172 width(0), height(0), |
|
173 ctx(0), |
|
174 currentBrush(0), |
|
175 inverseScale(1), |
|
176 shaderManager(0), |
|
177 inRenderText(false) |
|
178 { } |
|
179 |
|
180 ~QGL2PaintEngineExPrivate(); |
|
181 |
|
182 void updateBrushTexture(); |
|
183 void updateBrushUniforms(); |
|
184 void updateMatrix(); |
|
185 void updateCompositionMode(); |
|
186 void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id = -1); |
|
187 |
|
188 void setBrush(const QBrush* brush); |
|
189 |
|
190 void transferMode(EngineMode newMode); |
|
191 void resetGLState(); |
|
192 |
|
193 // fill, drawOutline, drawTexture & drawCachedGlyphs are the rendering entry points: |
|
194 void fill(const QVectorPath &path); |
|
195 void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); |
|
196 void drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, const QTextItemInt &ti); |
|
197 |
|
198 void drawVertexArrays(const float *data, const QVector<int> *stops, GLenum primitive); |
|
199 void drawVertexArrays(QGL2PEXVertexArray &vertexArray, GLenum primitive) { |
|
200 drawVertexArrays((const float *) vertexArray.data(), &vertexArray.stops(), primitive); |
|
201 } |
|
202 |
|
203 // ^ draws whatever is in the vertex array |
|
204 void composite(const QGLRect& boundingRect); |
|
205 // ^ Composites the bounding rect onto dest buffer |
|
206 |
|
207 void fillStencilWithVertexArray(const float *data, int count, const QVector<int> *stops, const QGLRect &bounds, StencilFillMode mode); |
|
208 void fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill) { |
|
209 fillStencilWithVertexArray((const float *) vertexArray.data(), 0, &vertexArray.stops(), |
|
210 vertexArray.boundingRect(), |
|
211 useWindingFill ? WindingFillMode : OddEvenFillMode); |
|
212 } |
|
213 // ^ Calls drawVertexArrays to render into stencil buffer |
|
214 |
|
215 bool prepareForDraw(bool srcPixelsAreOpaque); |
|
216 // ^ returns whether the current program changed or not |
|
217 |
|
218 inline void useSimpleShader(); |
|
219 |
|
220 void prepareDepthRangeForRenderText(); |
|
221 void restoreDepthRangeForRenderText(); |
|
222 |
|
223 static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; } |
|
224 |
|
225 QGL2PaintEngineEx* q; |
|
226 QGLPaintDevice* device; |
|
227 int width, height; |
|
228 QGLContext *ctx; |
|
229 EngineMode mode; |
|
230 QFontEngineGlyphCache::Type glyphCacheType; |
|
231 |
|
232 // Dirty flags |
|
233 bool matrixDirty; // Implies matrix uniforms are also dirty |
|
234 bool compositionModeDirty; |
|
235 bool brushTextureDirty; |
|
236 bool brushUniformsDirty; |
|
237 bool simpleShaderMatrixUniformDirty; |
|
238 bool shaderMatrixUniformDirty; |
|
239 bool opacityUniformDirty; |
|
240 |
|
241 bool stencilClean; // Has the stencil not been used for clipping so far? |
|
242 QRegion dirtyStencilRegion; |
|
243 QRect currentScissorBounds; |
|
244 uint maxClip; |
|
245 |
|
246 const QBrush* currentBrush; // May not be the state's brush! |
|
247 |
|
248 GLfloat inverseScale; |
|
249 |
|
250 QGL2PEXVertexArray vertexCoordinateArray; |
|
251 QGL2PEXVertexArray textureCoordinateArray; |
|
252 QDataBuffer<GLfloat> opacityArray; |
|
253 |
|
254 GLfloat staticVertexCoordinateArray[8]; |
|
255 GLfloat staticTextureCoordinateArray[8]; |
|
256 |
|
257 GLfloat pmvMatrix[4][4]; |
|
258 |
|
259 QGLEngineShaderManager* shaderManager; |
|
260 |
|
261 void clearClip(uint value); |
|
262 void writeClip(const QVectorPath &path, uint value); |
|
263 void resetClipIfNeeded(); |
|
264 |
|
265 void updateClipScissorTest(); |
|
266 void setScissor(const QRect &rect); |
|
267 void regenerateClip(); |
|
268 void systemStateChanged(); |
|
269 uint use_system_clip : 1; |
|
270 |
|
271 uint location(QGLEngineShaderManager::Uniform uniform) |
|
272 { |
|
273 return shaderManager->getUniformLocation(uniform); |
|
274 } |
|
275 |
|
276 GLuint lastTexture; |
|
277 |
|
278 bool needsSync; |
|
279 bool inRenderText; |
|
280 |
|
281 GLfloat depthRange[2]; |
|
282 |
|
283 float textureInvertedY; |
|
284 |
|
285 QTriangulatingStroker stroker; |
|
286 QDashedStrokeProcessor dasher; |
|
287 QTransform temporaryTransform; |
|
288 |
|
289 QScopedPointer<QPixmapFilter> convolutionFilter; |
|
290 QScopedPointer<QPixmapFilter> colorizeFilter; |
|
291 QScopedPointer<QPixmapFilter> blurFilter; |
|
292 QScopedPointer<QPixmapFilter> fastBlurFilter; |
|
293 QScopedPointer<QPixmapFilter> dropShadowFilter; |
|
294 QScopedPointer<QPixmapFilter> fastDropShadowFilter; |
|
295 }; |
|
296 |
|
297 QT_END_NAMESPACE |
|
298 |
|
299 #endif |