103 public: |
109 public: |
104 QGL2PaintEngineEx(); |
110 QGL2PaintEngineEx(); |
105 ~QGL2PaintEngineEx(); |
111 ~QGL2PaintEngineEx(); |
106 |
112 |
107 bool begin(QPaintDevice *device); |
113 bool begin(QPaintDevice *device); |
|
114 void ensureActive(); |
108 bool end(); |
115 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 |
116 virtual void clipEnabledChanged(); |
117 virtual void clipEnabledChanged(); |
117 virtual void penChanged(); |
118 virtual void penChanged(); |
118 virtual void brushChanged(); |
119 virtual void brushChanged(); |
119 virtual void brushOriginChanged(); |
120 virtual void brushOriginChanged(); |
120 virtual void opacityChanged(); |
121 virtual void opacityChanged(); |
121 virtual void compositionModeChanged(); |
122 virtual void compositionModeChanged(); |
122 virtual void renderHintsChanged(); |
123 virtual void renderHintsChanged(); |
123 virtual void transformChanged(); |
124 virtual void transformChanged(); |
124 |
125 |
125 |
126 virtual void drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr); |
126 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); |
127 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); |
|
128 virtual void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints); |
127 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, |
129 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, |
128 Qt::ImageConversionFlags flags = Qt::AutoColor); |
130 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); |
131 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem); |
132 |
132 virtual void fill(const QVectorPath &path, const QBrush &brush); |
133 virtual void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints); |
133 virtual void stroke(const QVectorPath &path, const QPen &pen); |
|
134 virtual void clip(const QVectorPath &path, Qt::ClipOperation op); |
|
135 |
134 |
136 |
135 Type type() const { return OpenGL2; } |
137 Type type() const { return OpenGL2; } |
136 |
138 |
137 void setState(QPainterState *s); |
139 virtual void setState(QPainterState *s); |
138 QPainterState *createState(QPainterState *orig) const; |
140 virtual QPainterState *createState(QPainterState *orig) const; |
139 inline QOpenGL2PaintEngineState *state() { |
141 inline QOpenGL2PaintEngineState *state() { |
140 return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
142 return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
141 } |
143 } |
142 inline const QOpenGL2PaintEngineState *state() const { |
144 inline const QOpenGL2PaintEngineState *state() const { |
143 return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
145 return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state()); |
144 } |
146 } |
145 |
147 |
146 void beginNativePainting(); |
148 void beginNativePainting(); |
147 void endNativePainting(); |
149 void endNativePainting(); |
148 |
|
149 const QGLContext* context(); |
|
150 |
150 |
151 QPixmapFilter *pixmapFilter(int type, const QPixmapFilter *prototype); |
151 QPixmapFilter *pixmapFilter(int type, const QPixmapFilter *prototype); |
152 |
152 |
153 void setRenderTextActive(bool); |
153 void setRenderTextActive(bool); |
154 |
154 |
167 TriStripStrokeFillMode |
167 TriStripStrokeFillMode |
168 }; |
168 }; |
169 |
169 |
170 QGL2PaintEngineExPrivate(QGL2PaintEngineEx *q_ptr) : |
170 QGL2PaintEngineExPrivate(QGL2PaintEngineEx *q_ptr) : |
171 q(q_ptr), |
171 q(q_ptr), |
|
172 shaderManager(0), |
172 width(0), height(0), |
173 width(0), height(0), |
173 ctx(0), |
174 ctx(0), |
174 inverseScale(1), |
175 useSystemClip(true), |
175 shaderManager(0), |
176 snapToPixelGrid(false), |
176 inRenderText(false) |
177 addOffset(false), |
|
178 inverseScale(1) |
177 { } |
179 { } |
178 |
180 |
179 ~QGL2PaintEngineExPrivate(); |
181 ~QGL2PaintEngineExPrivate(); |
180 |
182 |
181 void updateBrushTexture(); |
183 void updateBrushTexture(); |
182 void updateBrushUniforms(); |
184 void updateBrushUniforms(); |
183 void updateMatrix(); |
185 void updateMatrix(); |
184 void updateCompositionMode(); |
186 void updateCompositionMode(); |
185 void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id = -1); |
187 void updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id = -1); |
186 |
188 |
187 void setBrush(const QBrush& brush); |
|
188 |
|
189 void transferMode(EngineMode newMode); |
|
190 void resetGLState(); |
189 void resetGLState(); |
191 |
190 |
192 // fill, drawOutline, drawTexture & drawCachedGlyphs are the rendering entry points: |
191 // fill, stroke, drawTexture, drawPixmaps & drawCachedGlyphs are the main rendering entry-points, |
|
192 // however writeClip can also be thought of as en entry point as it does similar things. |
193 void fill(const QVectorPath &path); |
193 void fill(const QVectorPath &path); |
|
194 void stroke(const QVectorPath &path, const QPen &pen); |
194 void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); |
195 void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); |
|
196 void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints); |
195 void drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, const QTextItemInt &ti); |
197 void drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, const QTextItemInt &ti); |
196 |
198 |
|
199 // Calls glVertexAttributePointer if the pointer has changed |
|
200 inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer); |
|
201 |
|
202 // draws whatever is in the vertex array: |
197 void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive); |
203 void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive); |
198 void drawVertexArrays(QGL2PEXVertexArray &vertexArray, GLenum primitive) { |
204 void drawVertexArrays(QGL2PEXVertexArray &vertexArray, GLenum primitive) { |
199 drawVertexArrays((const float *) vertexArray.data(), vertexArray.stops(), vertexArray.stopCount(), primitive); |
205 drawVertexArrays((const float *) vertexArray.data(), vertexArray.stops(), vertexArray.stopCount(), primitive); |
200 } |
206 } |
201 |
207 |
202 // ^ draws whatever is in the vertex array |
208 // Composites the bounding rect onto dest buffer: |
203 void composite(const QGLRect& boundingRect); |
209 void composite(const QGLRect& boundingRect); |
204 // ^ Composites the bounding rect onto dest buffer |
210 |
205 |
211 // Calls drawVertexArrays to render into stencil buffer: |
206 void fillStencilWithVertexArray(const float *data, int count, int *stops, int stopCount, const QGLRect &bounds, StencilFillMode mode); |
212 void fillStencilWithVertexArray(const float *data, int count, int *stops, int stopCount, const QGLRect &bounds, StencilFillMode mode); |
207 void fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill) { |
213 void fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill) { |
208 fillStencilWithVertexArray((const float *) vertexArray.data(), 0, vertexArray.stops(), vertexArray.stopCount(), |
214 fillStencilWithVertexArray((const float *) vertexArray.data(), 0, vertexArray.stops(), vertexArray.stopCount(), |
209 vertexArray.boundingRect(), |
215 vertexArray.boundingRect(), |
210 useWindingFill ? WindingFillMode : OddEvenFillMode); |
216 useWindingFill ? WindingFillMode : OddEvenFillMode); |
211 } |
217 } |
212 // ^ Calls drawVertexArrays to render into stencil buffer |
218 |
213 |
219 void setBrush(const QBrush& brush); |
214 bool prepareForDraw(bool srcPixelsAreOpaque); |
220 void transferMode(EngineMode newMode); |
215 // ^ returns whether the current program changed or not |
221 bool prepareForDraw(bool srcPixelsAreOpaque); // returns true if the program has changed |
216 |
|
217 inline void useSimpleShader(); |
222 inline void useSimpleShader(); |
218 |
223 inline GLuint location(const QGLEngineShaderManager::Uniform uniform) { |
219 void prepareDepthRangeForRenderText(); |
224 return shaderManager->getUniformLocation(uniform); |
220 void restoreDepthRangeForRenderText(); |
225 } |
|
226 |
|
227 void clearClip(uint value); |
|
228 void writeClip(const QVectorPath &path, uint value); |
|
229 void resetClipIfNeeded(); |
|
230 |
|
231 void updateClipScissorTest(); |
|
232 void setScissor(const QRect &rect); |
|
233 void regenerateClip(); |
|
234 void systemStateChanged(); |
|
235 |
221 |
236 |
222 static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; } |
237 static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; } |
223 static QGL2PaintEngineExPrivate *getData(QGL2PaintEngineEx *engine) { return engine->d_func(); } |
238 static QGL2PaintEngineExPrivate *getData(QGL2PaintEngineEx *engine) { return engine->d_func(); } |
|
239 static void cleanupVectorPath(QPaintEngineEx *engine, void *data); |
|
240 |
224 |
241 |
225 QGL2PaintEngineEx* q; |
242 QGL2PaintEngineEx* q; |
|
243 QGLEngineShaderManager* shaderManager; |
226 QGLPaintDevice* device; |
244 QGLPaintDevice* device; |
227 int width, height; |
245 int width, height; |
228 QGLContext *ctx; |
246 QGLContext *ctx; |
229 EngineMode mode; |
247 EngineMode mode; |
230 QFontEngineGlyphCache::Type glyphCacheType; |
248 QFontEngineGlyphCache::Type glyphCacheType; |
232 // Dirty flags |
250 // Dirty flags |
233 bool matrixDirty; // Implies matrix uniforms are also dirty |
251 bool matrixDirty; // Implies matrix uniforms are also dirty |
234 bool compositionModeDirty; |
252 bool compositionModeDirty; |
235 bool brushTextureDirty; |
253 bool brushTextureDirty; |
236 bool brushUniformsDirty; |
254 bool brushUniformsDirty; |
237 bool simpleShaderMatrixUniformDirty; |
|
238 bool shaderMatrixUniformDirty; |
|
239 bool opacityUniformDirty; |
255 bool opacityUniformDirty; |
240 |
256 |
241 bool stencilClean; // Has the stencil not been used for clipping so far? |
257 bool stencilClean; // Has the stencil not been used for clipping so far? |
|
258 bool useSystemClip; |
242 QRegion dirtyStencilRegion; |
259 QRegion dirtyStencilRegion; |
243 QRect currentScissorBounds; |
260 QRect currentScissorBounds; |
244 uint maxClip; |
261 uint maxClip; |
245 |
262 |
246 QBrush currentBrush; // May not be the state's brush! |
263 QBrush currentBrush; // May not be the state's brush! |
247 |
264 const QBrush noBrush; |
248 GLfloat inverseScale; |
|
249 |
265 |
250 QGL2PEXVertexArray vertexCoordinateArray; |
266 QGL2PEXVertexArray vertexCoordinateArray; |
251 QGL2PEXVertexArray textureCoordinateArray; |
267 QGL2PEXVertexArray textureCoordinateArray; |
252 QDataBuffer<GLfloat> opacityArray; |
268 QDataBuffer<GLfloat> opacityArray; |
253 |
|
254 GLfloat staticVertexCoordinateArray[8]; |
269 GLfloat staticVertexCoordinateArray[8]; |
255 GLfloat staticTextureCoordinateArray[8]; |
270 GLfloat staticTextureCoordinateArray[8]; |
256 |
271 |
257 GLfloat pmvMatrix[4][4]; |
272 bool snapToPixelGrid; |
258 |
273 bool addOffset; // When enabled, adds a 0.49,0.49 offset to matrix in updateMatrix |
259 QGLEngineShaderManager* shaderManager; |
274 GLfloat pmvMatrix[3][3]; |
260 |
275 GLfloat inverseScale; |
261 void clearClip(uint value); |
276 |
262 void writeClip(const QVectorPath &path, uint value); |
277 GLuint lastTextureUsed; |
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 |
278 bool needsSync; |
279 bool needsSync; |
279 bool inRenderText; |
|
280 bool multisamplingAlwaysEnabled; |
280 bool multisamplingAlwaysEnabled; |
281 |
281 |
282 GLfloat depthRange[2]; |
282 GLfloat depthRange[2]; |
283 |
283 |
284 float textureInvertedY; |
284 float textureInvertedY; |
285 |
285 |
286 QTriangulatingStroker stroker; |
286 QTriangulatingStroker stroker; |
287 QDashedStrokeProcessor dasher; |
287 QDashedStrokeProcessor dasher; |
288 QTransform temporaryTransform; |
|
289 |
288 |
290 QScopedPointer<QPixmapFilter> convolutionFilter; |
289 QScopedPointer<QPixmapFilter> convolutionFilter; |
291 QScopedPointer<QPixmapFilter> colorizeFilter; |
290 QScopedPointer<QPixmapFilter> colorizeFilter; |
292 QScopedPointer<QPixmapFilter> blurFilter; |
291 QScopedPointer<QPixmapFilter> blurFilter; |
293 QScopedPointer<QPixmapFilter> dropShadowFilter; |
292 QScopedPointer<QPixmapFilter> dropShadowFilter; |
294 |
293 |
295 QSet<QVectorPath::CacheEntry *> pathCaches; |
294 QSet<QVectorPath::CacheEntry *> pathCaches; |
296 QVector<GLuint> unusedVBOSToClean; |
295 QVector<GLuint> unusedVBOSToClean; |
|
296 |
|
297 const GLfloat *vertexAttribPointers[3]; |
297 }; |
298 }; |
298 |
299 |
|
300 |
|
301 void QGL2PaintEngineExPrivate::setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer) |
|
302 { |
|
303 Q_ASSERT(arrayIndex < 3); |
|
304 if (pointer == vertexAttribPointers[arrayIndex]) |
|
305 return; |
|
306 |
|
307 vertexAttribPointers[arrayIndex] = pointer; |
|
308 if (arrayIndex == QT_OPACITY_ATTR) |
|
309 glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, pointer); |
|
310 else |
|
311 glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, pointer); |
|
312 } |
|
313 |
299 QT_END_NAMESPACE |
314 QT_END_NAMESPACE |
300 |
315 |
301 #endif |
316 #endif |