author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
/* |
|
43 |
When the active program changes, we need to update it's uniforms. |
|
44 |
We could track state for each program and only update stale uniforms |
|
45 |
- Could lead to lots of overhead if there's a lot of programs |
|
46 |
We could update all the uniforms when the program changes |
|
47 |
- Could end up updating lots of uniforms which don't need updating |
|
48 |
||
49 |
Updating uniforms should be cheap, so the overhead of updating up-to-date |
|
50 |
uniforms should be minimal. It's also less complex. |
|
51 |
||
52 |
Things which _may_ cause a different program to be used: |
|
53 |
- Change in brush/pen style |
|
54 |
- Change in painter opacity |
|
55 |
- Change in composition mode |
|
56 |
||
57 |
Whenever we set a mode on the shader manager - it needs to tell us if it had |
|
58 |
to switch to a different program. |
|
59 |
||
60 |
The shader manager should only switch when we tell it to. E.g. if we set a new |
|
61 |
brush style and then switch to transparent painter, we only want it to compile |
|
62 |
and use the correct program when we really need it. |
|
63 |
*/ |
|
64 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
// #define QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
67 |
#include "qglgradientcache_p.h" |
0 | 68 |
#include "qpaintengineex_opengl2_p.h" |
69 |
||
70 |
#include <string.h> //for memcpy |
|
71 |
#include <qmath.h> |
|
72 |
||
73 |
#include <private/qgl_p.h> |
|
74 |
#include <private/qmath_p.h> |
|
75 |
#include <private/qpaintengineex_p.h> |
|
76 |
#include <QPaintEngine> |
|
77 |
#include <private/qpainter_p.h> |
|
78 |
#include <private/qfontengine_p.h> |
|
79 |
#include <private/qpixmapdata_gl_p.h> |
|
80 |
#include <private/qdatabuffer_p.h> |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
81 |
#include <private/qstatictext_p.h> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
82 |
#include <private/qtriangulator_p.h> |
0 | 83 |
|
84 |
#include "qglengineshadermanager_p.h" |
|
85 |
#include "qgl2pexvertexarray_p.h" |
|
86 |
#include "qtriangulatingstroker_p.h" |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
87 |
#include "qtextureglyphcache_gl_p.h" |
0 | 88 |
|
89 |
#include <QDebug> |
|
90 |
||
91 |
QT_BEGIN_NAMESPACE |
|
92 |
||
93 |
//#define QT_GL_NO_SCISSOR_TEST |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
94 |
#if defined(Q_WS_WIN) |
0 | 95 |
extern Q_GUI_EXPORT bool qt_cleartype_enabled; |
96 |
#endif |
|
97 |
||
98 |
extern QImage qt_imageForBrush(int brushStyle, bool invert); |
|
99 |
||
100 |
////////////////////////////////// Private Methods ////////////////////////////////////////// |
|
101 |
||
102 |
QGL2PaintEngineExPrivate::~QGL2PaintEngineExPrivate() |
|
103 |
{ |
|
104 |
delete shaderManager; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
while (pathCaches.size()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
QVectorPath::CacheEntry *e = *(pathCaches.constBegin()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
e->cleanup(e->engine, e->data); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
e->data = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
e->engine = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
112 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
113 |
if (elementIndicesVBOId != 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
114 |
glDeleteBuffers(1, &elementIndicesVBOId); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
115 |
elementIndicesVBOId = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
116 |
} |
0 | 117 |
} |
118 |
||
119 |
void QGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id) |
|
120 |
{ |
|
121 |
// glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); //### Is it always this texture unit? |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
122 |
if (id != GLuint(-1) && id == lastTextureUsed) |
0 | 123 |
return; |
124 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
125 |
lastTextureUsed = id; |
0 | 126 |
|
127 |
if (smoothPixmapTransform) { |
|
128 |
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
129 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
130 |
} else { |
|
131 |
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
132 |
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
133 |
} |
|
134 |
glTexParameterf(target, GL_TEXTURE_WRAP_S, wrapMode); |
|
135 |
glTexParameterf(target, GL_TEXTURE_WRAP_T, wrapMode); |
|
136 |
} |
|
137 |
||
138 |
||
139 |
inline QColor qt_premultiplyColor(QColor c, GLfloat opacity) |
|
140 |
{ |
|
141 |
qreal alpha = c.alphaF() * opacity; |
|
142 |
c.setAlphaF(alpha); |
|
143 |
c.setRedF(c.redF() * alpha); |
|
144 |
c.setGreenF(c.greenF() * alpha); |
|
145 |
c.setBlueF(c.blueF() * alpha); |
|
146 |
return c; |
|
147 |
} |
|
148 |
||
149 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
void QGL2PaintEngineExPrivate::setBrush(const QBrush& brush) |
0 | 151 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
if (qbrush_fast_equals(currentBrush, brush)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
155 |
const Qt::BrushStyle newStyle = qbrush_style(brush); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
156 |
Q_ASSERT(newStyle != Qt::NoBrush); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
158 |
currentBrush = brush; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
159 |
brushUniformsDirty = true; // All brushes have at least one uniform |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
160 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
161 |
if (newStyle > Qt::SolidPattern) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
162 |
brushTextureDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
163 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
if (currentBrush.style() == Qt::TexturePattern |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
&& qHasPixmapTexture(brush) && brush.texture().isQBitmap()) |
0 | 166 |
{ |
167 |
shaderManager->setSrcPixelType(QGLEngineShaderManager::TextureSrcWithPattern); |
|
168 |
} else { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
169 |
shaderManager->setSrcPixelType(newStyle); |
0 | 170 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
171 |
shaderManager->optimiseForBrushTransform(currentBrush.transform().type()); |
0 | 172 |
} |
173 |
||
174 |
||
175 |
void QGL2PaintEngineExPrivate::useSimpleShader() |
|
176 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
177 |
shaderManager->useSimpleProgram(); |
0 | 178 |
|
179 |
if (matrixDirty) |
|
180 |
updateMatrix(); |
|
181 |
} |
|
182 |
||
183 |
void QGL2PaintEngineExPrivate::updateBrushTexture() |
|
184 |
{ |
|
185 |
Q_Q(QGL2PaintEngineEx); |
|
186 |
// qDebug("QGL2PaintEngineExPrivate::updateBrushTexture()"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
Qt::BrushStyle style = currentBrush.style(); |
0 | 188 |
|
189 |
if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) { |
|
190 |
// Get the image data for the pattern |
|
191 |
QImage texImage = qt_imageForBrush(style, false); |
|
192 |
||
193 |
glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
194 |
ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, QGLContext::InternalBindOption); |
0 | 195 |
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); |
196 |
} |
|
197 |
else if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { |
|
198 |
// Gradiant brush: All the gradiants use the same texture |
|
199 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
const QGradient* g = currentBrush.gradient(); |
0 | 201 |
|
202 |
// We apply global opacity in the fragment shaders, so we always pass 1.0 |
|
203 |
// for opacity to the cache. |
|
204 |
GLuint texId = QGL2GradientCache::cacheForContext(ctx)->getBuffer(*g, 1.0); |
|
205 |
||
206 |
glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); |
|
207 |
glBindTexture(GL_TEXTURE_2D, texId); |
|
208 |
||
209 |
if (g->spread() == QGradient::RepeatSpread || g->type() == QGradient::ConicalGradient) |
|
210 |
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); |
|
211 |
else if (g->spread() == QGradient::ReflectSpread) |
|
212 |
updateTextureFilter(GL_TEXTURE_2D, GL_MIRRORED_REPEAT_IBM, q->state()->renderHints & QPainter::SmoothPixmapTransform); |
|
213 |
else |
|
214 |
updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, q->state()->renderHints & QPainter::SmoothPixmapTransform); |
|
215 |
} |
|
216 |
else if (style == Qt::TexturePattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
const QPixmap& texPixmap = currentBrush.texture(); |
0 | 218 |
|
219 |
glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
220 |
QGLTexture *tex = ctx->d_func()->bindTexture(texPixmap, GL_TEXTURE_2D, GL_RGBA, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
221 |
QGLContext::InternalBindOption | |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
222 |
QGLContext::CanFlipNativePixmapBindOption); |
0 | 223 |
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); |
224 |
textureInvertedY = tex->options & QGLContext::InvertedYBindOption ? -1 : 1; |
|
225 |
} |
|
226 |
brushTextureDirty = false; |
|
227 |
} |
|
228 |
||
229 |
||
230 |
void QGL2PaintEngineExPrivate::updateBrushUniforms() |
|
231 |
{ |
|
232 |
// qDebug("QGL2PaintEngineExPrivate::updateBrushUniforms()"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
Qt::BrushStyle style = currentBrush.style(); |
0 | 234 |
|
235 |
if (style == Qt::NoBrush) |
|
236 |
return; |
|
237 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
QTransform brushQTransform = currentBrush.transform(); |
0 | 239 |
|
240 |
if (style == Qt::SolidPattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); |
0 | 242 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::FragmentColor), col); |
243 |
} |
|
244 |
else { |
|
245 |
// All other brushes have a transform and thus need the translation point: |
|
246 |
QPointF translationPoint; |
|
247 |
||
248 |
if (style <= Qt::DiagCrossPattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); |
0 | 250 |
|
251 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); |
|
252 |
||
253 |
QVector2D halfViewportSize(width*0.5, height*0.5); |
|
254 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); |
|
255 |
} |
|
256 |
else if (style == Qt::LinearGradientPattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
const QLinearGradient *g = static_cast<const QLinearGradient *>(currentBrush.gradient()); |
0 | 258 |
|
259 |
QPointF realStart = g->start(); |
|
260 |
QPointF realFinal = g->finalStop(); |
|
261 |
translationPoint = realStart; |
|
262 |
||
263 |
QPointF l = realFinal - realStart; |
|
264 |
||
265 |
QVector3D linearData( |
|
266 |
l.x(), |
|
267 |
l.y(), |
|
268 |
1.0f / (l.x() * l.x() + l.y() * l.y()) |
|
269 |
); |
|
270 |
||
271 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::LinearData), linearData); |
|
272 |
||
273 |
QVector2D halfViewportSize(width*0.5, height*0.5); |
|
274 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); |
|
275 |
} |
|
276 |
else if (style == Qt::ConicalGradientPattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
const QConicalGradient *g = static_cast<const QConicalGradient *>(currentBrush.gradient()); |
0 | 278 |
translationPoint = g->center(); |
279 |
||
280 |
GLfloat angle = -(g->angle() * 2 * Q_PI) / 360.0; |
|
281 |
||
282 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Angle), angle); |
|
283 |
||
284 |
QVector2D halfViewportSize(width*0.5, height*0.5); |
|
285 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); |
|
286 |
} |
|
287 |
else if (style == Qt::RadialGradientPattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
const QRadialGradient *g = static_cast<const QRadialGradient *>(currentBrush.gradient()); |
0 | 289 |
QPointF realCenter = g->center(); |
290 |
QPointF realFocal = g->focalPoint(); |
|
291 |
qreal realRadius = g->radius(); |
|
292 |
translationPoint = realFocal; |
|
293 |
||
294 |
QPointF fmp = realCenter - realFocal; |
|
295 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp), fmp); |
|
296 |
||
297 |
GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius; |
|
298 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp2MRadius2), fmp2_m_radius2); |
|
299 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Inverse2Fmp2MRadius2), |
|
300 |
GLfloat(1.0 / (2.0*fmp2_m_radius2))); |
|
301 |
||
302 |
QVector2D halfViewportSize(width*0.5, height*0.5); |
|
303 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); |
|
304 |
} |
|
305 |
else if (style == Qt::TexturePattern) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
const QPixmap& texPixmap = currentBrush.texture(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
if (qHasPixmapTexture(currentBrush) && currentBrush.texture().isQBitmap()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); |
0 | 310 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); |
311 |
} |
|
312 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
QSizeF invertedTextureSize(1.0 / texPixmap.width(), 1.0 / texPixmap.height()); |
0 | 314 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::InvertedTextureSize), invertedTextureSize); |
315 |
||
316 |
QVector2D halfViewportSize(width*0.5, height*0.5); |
|
317 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); |
|
318 |
} |
|
319 |
else |
|
320 |
qWarning("QGL2PaintEngineEx: Unimplemented fill style"); |
|
321 |
||
322 |
const QPointF &brushOrigin = q->state()->brushOrigin; |
|
323 |
QTransform matrix = q->state()->matrix; |
|
324 |
matrix.translate(brushOrigin.x(), brushOrigin.y()); |
|
325 |
||
326 |
QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y()); |
|
327 |
QTransform gl_to_qt(1, 0, 0, -1, 0, height); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
QTransform inv_matrix; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
if (style == Qt::TexturePattern && textureInvertedY == -1) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
inv_matrix = gl_to_qt * (QTransform(1, 0, 0, -1, 0, currentBrush.texture().height()) * brushQTransform * matrix).inverted() * translate; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate; |
0 | 333 |
|
334 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTransform), inv_matrix); |
|
335 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTexture), QT_BRUSH_TEXTURE_UNIT); |
|
336 |
} |
|
337 |
brushUniformsDirty = false; |
|
338 |
} |
|
339 |
||
340 |
||
341 |
// This assumes the shader manager has already setup the correct shader program |
|
342 |
void QGL2PaintEngineExPrivate::updateMatrix() |
|
343 |
{ |
|
344 |
// qDebug("QGL2PaintEngineExPrivate::updateMatrix()"); |
|
345 |
||
346 |
const QTransform& transform = q->state()->matrix; |
|
347 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
348 |
// The projection matrix converts from Qt's coordinate system to GL's coordinate system |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
349 |
// * GL's viewport is 2x2, Qt's is width x height |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
350 |
// * GL has +y -> -y going from bottom -> top, Qt is the other way round |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
351 |
// * GL has [0,0] in the center, Qt has it in the top-left |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
352 |
// |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
353 |
// This results in the Projection matrix below, which is multiplied by the painter's |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
354 |
// transformation matrix, as shown below: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
355 |
// |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
356 |
// Projection Matrix Painter Transform |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
357 |
// ------------------------------------------------ ------------------------ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
358 |
// | 2.0 / width | 0.0 | -1.0 | | m11 | m21 | dx | |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
359 |
// | 0.0 | -2.0 / height | 1.0 | * | m12 | m22 | dy | |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
360 |
// | 0.0 | 0.0 | 1.0 | | m13 | m23 | m33 | |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
361 |
// ------------------------------------------------ ------------------------ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
362 |
// |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
363 |
// NOTE: The resultant matrix is also transposed, as GL expects column-major matracies |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
364 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
365 |
const GLfloat wfactor = 2.0f / width; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
366 |
const GLfloat hfactor = -2.0f / height; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
367 |
GLfloat dx = transform.dx(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
368 |
GLfloat dy = transform.dy(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
370 |
// Non-integer translates can have strange effects for some rendering operations such as |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
371 |
// anti-aliased text rendering. In such cases, we snap the translate to the pixel grid. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
372 |
if (snapToPixelGrid && transform.type() == QTransform::TxTranslate) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
373 |
// 0.50 needs to rounded down to 0.0 for consistency with raster engine: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
374 |
dx = ceilf(dx - 0.5f); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
375 |
dy = ceilf(dy - 0.5f); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
376 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
377 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
378 |
if (addOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
379 |
dx += 0.49f; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
380 |
dy += 0.49f; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
381 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
382 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
383 |
pmvMatrix[0][0] = (wfactor * transform.m11()) - transform.m13(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
384 |
pmvMatrix[1][0] = (wfactor * transform.m21()) - transform.m23(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
385 |
pmvMatrix[2][0] = (wfactor * dx) - transform.m33(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
386 |
pmvMatrix[0][1] = (hfactor * transform.m12()) + transform.m13(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
387 |
pmvMatrix[1][1] = (hfactor * transform.m22()) + transform.m23(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
388 |
pmvMatrix[2][1] = (hfactor * dy) + transform.m33(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
389 |
pmvMatrix[0][2] = transform.m13(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
390 |
pmvMatrix[1][2] = transform.m23(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
391 |
pmvMatrix[2][2] = transform.m33(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
// 1/10000 == 0.0001, so we have good enough res to cover curves |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
// that span the entire widget... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
qMax(qAbs(transform.m12()), qAbs(transform.m21())) ), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
qreal(0.0001)); |
0 | 398 |
|
399 |
matrixDirty = false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
400 |
matrixUniformDirty = true; |
0 | 401 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
402 |
// Set the PMV matrix attribute. As we use an attributes rather than uniforms, we only |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
403 |
// need to do this once for every matrix change and persists across all shader programs. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
404 |
glVertexAttrib3fv(QT_PMV_MATRIX_1_ATTR, pmvMatrix[0]); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
405 |
glVertexAttrib3fv(QT_PMV_MATRIX_2_ATTR, pmvMatrix[1]); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
406 |
glVertexAttrib3fv(QT_PMV_MATRIX_3_ATTR, pmvMatrix[2]); |
0 | 407 |
|
408 |
dasher.setInvScale(inverseScale); |
|
409 |
stroker.setInvScale(inverseScale); |
|
410 |
} |
|
411 |
||
412 |
||
413 |
void QGL2PaintEngineExPrivate::updateCompositionMode() |
|
414 |
{ |
|
415 |
// NOTE: The entire paint engine works on pre-multiplied data - which is why some of these |
|
416 |
// composition modes look odd. |
|
417 |
// qDebug() << "QGL2PaintEngineExPrivate::updateCompositionMode() - Setting GL composition mode for " << q->state()->composition_mode; |
|
418 |
switch(q->state()->composition_mode) { |
|
419 |
case QPainter::CompositionMode_SourceOver: |
|
420 |
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
421 |
break; |
|
422 |
case QPainter::CompositionMode_DestinationOver: |
|
423 |
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE); |
|
424 |
break; |
|
425 |
case QPainter::CompositionMode_Clear: |
|
426 |
glBlendFunc(GL_ZERO, GL_ZERO); |
|
427 |
break; |
|
428 |
case QPainter::CompositionMode_Source: |
|
429 |
glBlendFunc(GL_ONE, GL_ZERO); |
|
430 |
break; |
|
431 |
case QPainter::CompositionMode_Destination: |
|
432 |
glBlendFunc(GL_ZERO, GL_ONE); |
|
433 |
break; |
|
434 |
case QPainter::CompositionMode_SourceIn: |
|
435 |
glBlendFunc(GL_DST_ALPHA, GL_ZERO); |
|
436 |
break; |
|
437 |
case QPainter::CompositionMode_DestinationIn: |
|
438 |
glBlendFunc(GL_ZERO, GL_SRC_ALPHA); |
|
439 |
break; |
|
440 |
case QPainter::CompositionMode_SourceOut: |
|
441 |
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO); |
|
442 |
break; |
|
443 |
case QPainter::CompositionMode_DestinationOut: |
|
444 |
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); |
|
445 |
break; |
|
446 |
case QPainter::CompositionMode_SourceAtop: |
|
447 |
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
448 |
break; |
|
449 |
case QPainter::CompositionMode_DestinationAtop: |
|
450 |
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA); |
|
451 |
break; |
|
452 |
case QPainter::CompositionMode_Xor: |
|
453 |
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
454 |
break; |
|
455 |
case QPainter::CompositionMode_Plus: |
|
456 |
glBlendFunc(GL_ONE, GL_ONE); |
|
457 |
break; |
|
458 |
default: |
|
459 |
qWarning("Unsupported composition mode"); |
|
460 |
break; |
|
461 |
} |
|
462 |
||
463 |
compositionModeDirty = false; |
|
464 |
} |
|
465 |
||
466 |
static inline void setCoords(GLfloat *coords, const QGLRect &rect) |
|
467 |
{ |
|
468 |
coords[0] = rect.left; |
|
469 |
coords[1] = rect.top; |
|
470 |
coords[2] = rect.right; |
|
471 |
coords[3] = rect.top; |
|
472 |
coords[4] = rect.right; |
|
473 |
coords[5] = rect.bottom; |
|
474 |
coords[6] = rect.left; |
|
475 |
coords[7] = rect.bottom; |
|
476 |
} |
|
477 |
||
478 |
void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern) |
|
479 |
{ |
|
480 |
// Setup for texture drawing |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
481 |
currentBrush = noBrush; |
0 | 482 |
shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
483 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
484 |
if (addOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
485 |
addOffset = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
486 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
487 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
488 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
489 |
if (snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
490 |
snapToPixelGrid = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
491 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
492 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
493 |
|
0 | 494 |
if (prepareForDraw(opaque)) |
495 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT); |
|
496 |
||
497 |
if (pattern) { |
|
498 |
QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); |
|
499 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); |
|
500 |
} |
|
501 |
||
502 |
GLfloat dx = 1.0 / textureSize.width(); |
|
503 |
GLfloat dy = 1.0 / textureSize.height(); |
|
504 |
||
505 |
QGLRect srcTextureRect(src.left*dx, src.top*dy, src.right*dx, src.bottom*dy); |
|
506 |
||
507 |
setCoords(staticVertexCoordinateArray, dest); |
|
508 |
setCoords(staticTextureCoordinateArray, srcTextureRect); |
|
509 |
||
510 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
|
511 |
} |
|
512 |
||
513 |
void QGL2PaintEngineEx::beginNativePainting() |
|
514 |
{ |
|
515 |
Q_D(QGL2PaintEngineEx); |
|
516 |
ensureActive(); |
|
517 |
d->transferMode(BrushDrawingMode); |
|
518 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
519 |
d->nativePaintingActive = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
520 |
|
0 | 521 |
QGLContext *ctx = d->ctx; |
522 |
glUseProgram(0); |
|
523 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
524 |
// Disable all the vertex attribute arrays: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
525 |
for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
526 |
glDisableVertexAttribArray(i); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
527 |
|
0 | 528 |
#ifndef QT_OPENGL_ES_2 |
529 |
// be nice to people who mix OpenGL 1.x code with QPainter commands |
|
530 |
// by setting modelview and projection matrices to mirror the GL 1 |
|
531 |
// paint engine |
|
532 |
const QTransform& mtx = state()->matrix; |
|
533 |
||
534 |
float mv_matrix[4][4] = |
|
535 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
536 |
{ float(mtx.m11()), float(mtx.m12()), 0, float(mtx.m13()) }, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
537 |
{ float(mtx.m21()), float(mtx.m22()), 0, float(mtx.m23()) }, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
538 |
{ 0, 0, 1, 0 }, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
539 |
{ float(mtx.dx()), float(mtx.dy()), 0, float(mtx.m33()) } |
0 | 540 |
}; |
541 |
||
542 |
const QSize sz = d->device->size(); |
|
543 |
||
544 |
glMatrixMode(GL_PROJECTION); |
|
545 |
glLoadIdentity(); |
|
546 |
glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999); |
|
547 |
||
548 |
glMatrixMode(GL_MODELVIEW); |
|
549 |
glLoadMatrixf(&mv_matrix[0][0]); |
|
550 |
#else |
|
551 |
Q_UNUSED(ctx); |
|
552 |
#endif |
|
553 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
554 |
d->lastTextureUsed = GLuint(-1); |
0 | 555 |
d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); |
556 |
d->resetGLState(); |
|
557 |
||
558 |
d->shaderManager->setDirty(); |
|
559 |
||
560 |
d->needsSync = true; |
|
561 |
} |
|
562 |
||
563 |
void QGL2PaintEngineExPrivate::resetGLState() |
|
564 |
{ |
|
565 |
glDisable(GL_BLEND); |
|
566 |
glActiveTexture(GL_TEXTURE0); |
|
567 |
glDisable(GL_STENCIL_TEST); |
|
568 |
glDisable(GL_DEPTH_TEST); |
|
569 |
glDisable(GL_SCISSOR_TEST); |
|
570 |
glDepthMask(true); |
|
571 |
glDepthFunc(GL_LESS); |
|
572 |
glClearDepth(1); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
573 |
glStencilMask(0xff); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
574 |
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
575 |
glStencilFunc(GL_ALWAYS, 0, 0xff); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
576 |
ctx->d_func()->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
577 |
ctx->d_func()->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
578 |
ctx->d_func()->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
579 |
#ifndef QT_OPENGL_ES_2 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
580 |
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // color may have been changed by glVertexAttrib() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
581 |
#endif |
0 | 582 |
} |
583 |
||
584 |
void QGL2PaintEngineEx::endNativePainting() |
|
585 |
{ |
|
586 |
Q_D(QGL2PaintEngineEx); |
|
587 |
d->needsSync = true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
588 |
d->nativePaintingActive = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
589 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
590 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
591 |
bool QGL2PaintEngineEx::isNativePaintingActive() const { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
592 |
Q_D(const QGL2PaintEngineEx); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
593 |
return d->nativePaintingActive; |
0 | 594 |
} |
595 |
||
596 |
void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode) |
|
597 |
{ |
|
598 |
if (newMode == mode) |
|
599 |
return; |
|
600 |
||
601 |
if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
602 |
lastTextureUsed = GLuint(-1); |
0 | 603 |
} |
604 |
||
605 |
if (newMode == TextDrawingMode) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
606 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
607 |
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data()); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
608 |
shaderManager->setHasComplexGeometry(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
609 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
610 |
shaderManager->setHasComplexGeometry(false); |
0 | 611 |
} |
612 |
||
613 |
if (newMode == ImageDrawingMode) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
614 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
615 |
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray); |
0 | 616 |
} |
617 |
||
618 |
if (newMode == ImageArrayDrawingMode) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
619 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
620 |
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
621 |
setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data()); |
0 | 622 |
} |
623 |
||
624 |
// This needs to change when we implement high-quality anti-aliasing... |
|
625 |
if (newMode != TextDrawingMode) |
|
626 |
shaderManager->setMaskType(QGLEngineShaderManager::NoMask); |
|
627 |
||
628 |
mode = newMode; |
|
629 |
} |
|
630 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
struct QGL2PEVectorPathCache |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
GLuint vbo; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
635 |
GLuint ibo; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
636 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
float *vertices; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
638 |
quint32 *indices; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
int vertexCount; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
641 |
int indexCount; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
GLenum primitiveType; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
qreal iscale; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
644 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
646 |
void QGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
QGL2PEVectorPathCache *c = (QGL2PEVectorPathCache *) data; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
650 |
Q_ASSERT(engine->type() == QPaintEngine::OpenGL2); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
651 |
static_cast<QGL2PaintEngineEx *>(engine)->d_func()->unusedVBOSToClean << c->vbo; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
652 |
if (c->ibo) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
653 |
d->unusedIBOSToClean << c->ibo; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
#else |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
655 |
Q_UNUSED(engine); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
qFree(c->vertices); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
657 |
qFree(c->indices); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
delete c; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
|
0 | 662 |
// Assumes everything is configured for the brush you want to use |
663 |
void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) |
|
664 |
{ |
|
665 |
transferMode(BrushDrawingMode); |
|
666 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
667 |
const QOpenGL2PaintEngineState *s = q->state(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
668 |
const bool newAddOffset = !(s->renderHints & QPainter::Antialiasing) && |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
669 |
(qbrush_style(currentBrush) == Qt::SolidPattern) && |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
670 |
!multisamplingAlwaysEnabled; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
671 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
672 |
if (addOffset != newAddOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
673 |
addOffset = newAddOffset; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
674 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
675 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
676 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
677 |
if (snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
678 |
snapToPixelGrid = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
679 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
680 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
681 |
|
0 | 682 |
// Might need to call updateMatrix to re-calculate inverseScale |
683 |
if (matrixDirty) |
|
684 |
updateMatrix(); |
|
685 |
||
686 |
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); |
|
687 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
688 |
// ### Remove before release... |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
689 |
static bool do_vectorpath_cache = qgetenv("QT_OPENGL_NO_PATH_CACHE").isEmpty(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
690 |
|
0 | 691 |
// Check to see if there's any hints |
692 |
if (path.shape() == QVectorPath::RectangleHint) { |
|
693 |
QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
694 |
prepareForDraw(currentBrush.isOpaque()); |
0 | 695 |
composite(rect); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
} else if (path.isConvex()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
if (path.isCacheable()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
QVectorPath::CacheEntry *data = path.lookupCacheData(q); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
QGL2PEVectorPathCache *cache; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
702 |
bool updateCache = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
703 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
if (data) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
cache = (QGL2PEVectorPathCache *) data->data; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
// Check if scale factor is exceeded for curved paths and generate curves if so... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
if (path.isCurved()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
qreal scaleFactor = cache->iscale / inverseScale; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
if (scaleFactor < 0.5 || scaleFactor > 2.0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
711 |
glDeleteBuffers(1, &cache->vbo); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
712 |
cache->vbo = 0; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
713 |
Q_ASSERT(cache->ibo == 0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
qFree(cache->vertices); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
716 |
Q_ASSERT(cache->indices == 0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
718 |
updateCache = true; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
719 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
720 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
cache = new QGL2PEVectorPathCache; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
723 |
data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
724 |
updateCache = true; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
// Flatten the path at the current scale factor and fill it into the cache struct. |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
728 |
if (updateCache) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
vertexCoordinateArray.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
vertexCoordinateArray.addPath(path, inverseScale, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
int vertexCount = vertexCoordinateArray.vertexCount(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
732 |
int floatSizeInBytes = vertexCount * 2 * sizeof(float); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
cache->vertexCount = vertexCount; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
734 |
cache->indexCount = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
735 |
cache->primitiveType = GL_TRIANGLE_FAN; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
736 |
cache->iscale = inverseScale; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
737 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
glGenBuffers(1, &cache->vbo); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
glBufferData(GL_ARRAY_BUFFER, floatSizeInBytes, vertexCoordinateArray.data(), GL_STATIC_DRAW); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
741 |
cache->ibo = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
742 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
743 |
cache->vertices = (float *) qMalloc(floatSizeInBytes); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
744 |
memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
745 |
cache->indices = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
prepareForDraw(currentBrush.isOpaque()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
751 |
glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
752 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
#else |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
754 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
glDrawArrays(cache->primitiveType, 0, cache->vertexCount); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
// printf(" - Marking path as cachable...\n"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
// Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
if (do_vectorpath_cache) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
path.makeCacheable(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
vertexCoordinateArray.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
vertexCoordinateArray.addPath(path, inverseScale, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
prepareForDraw(currentBrush.isOpaque()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
|
0 | 769 |
} else { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
770 |
bool useCache = path.isCacheable(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
771 |
if (useCache) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
772 |
QRectF bbox = path.controlPointRect(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
773 |
// If the path doesn't fit within these limits, it is possible that the triangulation will fail. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
774 |
useCache &= (bbox.left() > -0x8000 * inverseScale) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
775 |
&& (bbox.right() < 0x8000 * inverseScale) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
776 |
&& (bbox.top() > -0x8000 * inverseScale) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
777 |
&& (bbox.bottom() < 0x8000 * inverseScale); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
778 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
779 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
780 |
if (useCache) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
781 |
QVectorPath::CacheEntry *data = path.lookupCacheData(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
782 |
QGL2PEVectorPathCache *cache; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
783 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
784 |
bool updateCache = false; |
0 | 785 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
786 |
if (data) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
787 |
cache = (QGL2PEVectorPathCache *) data->data; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
788 |
// Check if scale factor is exceeded for curved paths and generate curves if so... |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
789 |
if (path.isCurved()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
790 |
qreal scaleFactor = cache->iscale / inverseScale; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
791 |
if (scaleFactor < 0.5 || scaleFactor > 2.0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
792 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
793 |
glDeleteBuffers(1, &cache->vbo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
794 |
glDeleteBuffers(1, &cache->ibo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
795 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
796 |
qFree(cache->vertices); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
797 |
qFree(cache->indices); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
798 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
799 |
updateCache = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
800 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
801 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
802 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
803 |
cache = new QGL2PEVectorPathCache; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
804 |
data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
805 |
updateCache = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
806 |
} |
0 | 807 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
808 |
// Flatten the path at the current scale factor and fill it into the cache struct. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
809 |
if (updateCache) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
810 |
QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
811 |
cache->vertexCount = polys.vertices.size() / 2; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
812 |
cache->indexCount = polys.indices.size(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
813 |
cache->primitiveType = GL_TRIANGLES; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
814 |
cache->iscale = inverseScale; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
815 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
816 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
817 |
glGenBuffers(1, &cache->vbo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
818 |
glGenBuffers(1, &cache->ibo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
819 |
glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
820 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
821 |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint32) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); |
0 | 822 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
823 |
QVarLengthArray<float> vertices(polys.vertices.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
824 |
for (int i = 0; i < polys.vertices.size(); ++i) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
825 |
vertices[i] = float(inverseScale * polys.vertices.at(i)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
826 |
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
827 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
828 |
cache->vertices = (float *) qMalloc(sizeof(float) * polys.vertices.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
829 |
cache->indices = (quint32 *) qMalloc(sizeof(quint32) * polys.indices.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
830 |
memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
831 |
for (int i = 0; i < polys.vertices.size(); ++i) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
832 |
cache->vertices[i] = float(inverseScale * polys.vertices.at(i)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
833 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
834 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
835 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
836 |
prepareForDraw(currentBrush.isOpaque()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
837 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
838 |
glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
839 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
840 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
841 |
glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
842 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
843 |
glBindBuffer(GL_ARRAY_BUFFER, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
844 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
845 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
846 |
glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, cache->indices); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
847 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
848 |
|
0 | 849 |
} else { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
850 |
// printf(" - Marking path as cachable...\n"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
851 |
// Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
852 |
if (do_vectorpath_cache) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
853 |
path.makeCacheable(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
854 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
855 |
// The path is too complicated & needs the stencil technique |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
856 |
vertexCoordinateArray.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
857 |
vertexCoordinateArray.addPath(path, inverseScale, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
858 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
859 |
fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
860 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
861 |
glStencilMask(0xff); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
862 |
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); |
0 | 863 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
864 |
if (q->state()->clipTestEnabled) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
865 |
// Pass when high bit is set, replace stencil value with current clip |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
866 |
glStencilFunc(GL_NOTEQUAL, q->state()->currentClip, GL_STENCIL_HIGH_BIT); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
867 |
} else if (path.hasWindingFill()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
868 |
// Pass when any bit is set, replace stencil value with 0 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
869 |
glStencilFunc(GL_NOTEQUAL, 0, 0xff); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
870 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
871 |
// Pass when high bit is set, replace stencil value with 0 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
872 |
glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
873 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
874 |
prepareForDraw(currentBrush.isOpaque()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
875 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
876 |
// Stencil the brush onto the dest buffer |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
877 |
composite(vertexCoordinateArray.boundingRect()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
878 |
glStencilMask(0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
879 |
updateClipScissorTest(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
880 |
} |
0 | 881 |
} |
882 |
} |
|
883 |
||
884 |
||
885 |
void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data, |
|
886 |
int count, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
887 |
int *stops, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
888 |
int stopCount, |
0 | 889 |
const QGLRect &bounds, |
890 |
StencilFillMode mode) |
|
891 |
{ |
|
892 |
Q_ASSERT(count || stops); |
|
893 |
||
894 |
// qDebug("QGL2PaintEngineExPrivate::fillStencilWithVertexArray()"); |
|
895 |
glStencilMask(0xff); // Enable stencil writes |
|
896 |
||
897 |
if (dirtyStencilRegion.intersects(currentScissorBounds)) { |
|
898 |
QVector<QRect> clearRegion = dirtyStencilRegion.intersected(currentScissorBounds).rects(); |
|
899 |
glClearStencil(0); // Clear to zero |
|
900 |
for (int i = 0; i < clearRegion.size(); ++i) { |
|
901 |
#ifndef QT_GL_NO_SCISSOR_TEST |
|
902 |
setScissor(clearRegion.at(i)); |
|
903 |
#endif |
|
904 |
glClear(GL_STENCIL_BUFFER_BIT); |
|
905 |
} |
|
906 |
||
907 |
dirtyStencilRegion -= currentScissorBounds; |
|
908 |
||
909 |
#ifndef QT_GL_NO_SCISSOR_TEST |
|
910 |
updateClipScissorTest(); |
|
911 |
#endif |
|
912 |
} |
|
913 |
||
914 |
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes |
|
915 |
useSimpleShader(); |
|
916 |
glEnable(GL_STENCIL_TEST); // For some reason, this has to happen _after_ the simple shader is use()'d |
|
917 |
||
918 |
if (mode == WindingFillMode) { |
|
919 |
Q_ASSERT(stops && !count); |
|
920 |
if (q->state()->clipTestEnabled) { |
|
921 |
// Flatten clip values higher than current clip, and set high bit to match current clip |
|
922 |
glStencilFunc(GL_LEQUAL, GL_STENCIL_HIGH_BIT | q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); |
|
923 |
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); |
|
924 |
composite(bounds); |
|
925 |
||
926 |
glStencilFunc(GL_EQUAL, GL_STENCIL_HIGH_BIT, GL_STENCIL_HIGH_BIT); |
|
927 |
} else if (!stencilClean) { |
|
928 |
// Clear stencil buffer within bounding rect |
|
929 |
glStencilFunc(GL_ALWAYS, 0, 0xff); |
|
930 |
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); |
|
931 |
composite(bounds); |
|
932 |
} |
|
933 |
||
934 |
// Inc. for front-facing triangle |
|
935 |
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_INCR_WRAP); |
|
936 |
// Dec. for back-facing "holes" |
|
937 |
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_DECR_WRAP); |
|
938 |
glStencilMask(~GL_STENCIL_HIGH_BIT); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
939 |
drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN); |
0 | 940 |
|
941 |
if (q->state()->clipTestEnabled) { |
|
942 |
// Clear high bit of stencil outside of path |
|
943 |
glStencilFunc(GL_EQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); |
|
944 |
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); |
|
945 |
glStencilMask(GL_STENCIL_HIGH_BIT); |
|
946 |
composite(bounds); |
|
947 |
} |
|
948 |
} else if (mode == OddEvenFillMode) { |
|
949 |
glStencilMask(GL_STENCIL_HIGH_BIT); |
|
950 |
glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
951 |
drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN); |
0 | 952 |
|
953 |
} else { // TriStripStrokeFillMode |
|
954 |
Q_ASSERT(count && !stops); // tristrips generated directly, so no vertexArray or stops |
|
955 |
glStencilMask(GL_STENCIL_HIGH_BIT); |
|
956 |
#if 0 |
|
957 |
glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
958 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); |
0 | 959 |
glDrawArrays(GL_TRIANGLE_STRIP, 0, count); |
960 |
#else |
|
961 |
||
962 |
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); |
|
963 |
if (q->state()->clipTestEnabled) { |
|
964 |
glStencilFunc(GL_LEQUAL, q->state()->currentClip | GL_STENCIL_HIGH_BIT, |
|
965 |
~GL_STENCIL_HIGH_BIT); |
|
966 |
} else { |
|
967 |
glStencilFunc(GL_ALWAYS, GL_STENCIL_HIGH_BIT, 0xff); |
|
968 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
969 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); |
0 | 970 |
glDrawArrays(GL_TRIANGLE_STRIP, 0, count); |
971 |
#endif |
|
972 |
} |
|
973 |
||
974 |
// Enable color writes & disable stencil writes |
|
975 |
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
|
976 |
} |
|
977 |
||
978 |
/* |
|
979 |
If the maximum value in the stencil buffer is GL_STENCIL_HIGH_BIT - 1, |
|
980 |
restore the stencil buffer to a pristine state. The current clip region |
|
981 |
is set to 1, and the rest to 0. |
|
982 |
*/ |
|
983 |
void QGL2PaintEngineExPrivate::resetClipIfNeeded() |
|
984 |
{ |
|
985 |
if (maxClip != (GL_STENCIL_HIGH_BIT - 1)) |
|
986 |
return; |
|
987 |
||
988 |
Q_Q(QGL2PaintEngineEx); |
|
989 |
||
990 |
useSimpleShader(); |
|
991 |
glEnable(GL_STENCIL_TEST); |
|
992 |
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
|
993 |
||
994 |
QRectF bounds = q->state()->matrix.inverted().mapRect(QRectF(0, 0, width, height)); |
|
995 |
QGLRect rect(bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); |
|
996 |
||
997 |
// Set high bit on clip region |
|
998 |
glStencilFunc(GL_LEQUAL, q->state()->currentClip, 0xff); |
|
999 |
glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT); |
|
1000 |
glStencilMask(GL_STENCIL_HIGH_BIT); |
|
1001 |
composite(rect); |
|
1002 |
||
1003 |
// Reset clipping to 1 and everything else to zero |
|
1004 |
glStencilFunc(GL_NOTEQUAL, 0x01, GL_STENCIL_HIGH_BIT); |
|
1005 |
glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE); |
|
1006 |
glStencilMask(0xff); |
|
1007 |
composite(rect); |
|
1008 |
||
1009 |
q->state()->currentClip = 1; |
|
1010 |
q->state()->canRestoreClip = false; |
|
1011 |
||
1012 |
maxClip = 1; |
|
1013 |
||
1014 |
glStencilMask(0x0); |
|
1015 |
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
|
1016 |
} |
|
1017 |
||
1018 |
bool QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque) |
|
1019 |
{ |
|
1020 |
if (brushTextureDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode) |
|
1021 |
updateBrushTexture(); |
|
1022 |
||
1023 |
if (compositionModeDirty) |
|
1024 |
updateCompositionMode(); |
|
1025 |
||
1026 |
if (matrixDirty) |
|
1027 |
updateMatrix(); |
|
1028 |
||
1029 |
const bool stateHasOpacity = q->state()->opacity < 0.99f; |
|
1030 |
if (q->state()->composition_mode == QPainter::CompositionMode_Source |
|
1031 |
|| (q->state()->composition_mode == QPainter::CompositionMode_SourceOver |
|
1032 |
&& srcPixelsAreOpaque && !stateHasOpacity)) |
|
1033 |
{ |
|
1034 |
glDisable(GL_BLEND); |
|
1035 |
} else { |
|
1036 |
glEnable(GL_BLEND); |
|
1037 |
} |
|
1038 |
||
1039 |
QGLEngineShaderManager::OpacityMode opacityMode; |
|
1040 |
if (mode == ImageArrayDrawingMode) { |
|
1041 |
opacityMode = QGLEngineShaderManager::AttributeOpacity; |
|
1042 |
} else { |
|
1043 |
opacityMode = stateHasOpacity ? QGLEngineShaderManager::UniformOpacity |
|
1044 |
: QGLEngineShaderManager::NoOpacity; |
|
1045 |
if (stateHasOpacity && (mode != ImageDrawingMode)) { |
|
1046 |
// Using a brush |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1047 |
bool brushIsPattern = (currentBrush.style() >= Qt::Dense1Pattern) && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1048 |
(currentBrush.style() <= Qt::DiagCrossPattern); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1049 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1050 |
if ((currentBrush.style() == Qt::SolidPattern) || brushIsPattern) |
0 | 1051 |
opacityMode = QGLEngineShaderManager::NoOpacity; // Global opacity handled by srcPixel shader |
1052 |
} |
|
1053 |
} |
|
1054 |
shaderManager->setOpacityMode(opacityMode); |
|
1055 |
||
1056 |
bool changed = shaderManager->useCorrectShaderProg(); |
|
1057 |
// If the shader program needs changing, we change it and mark all uniforms as dirty |
|
1058 |
if (changed) { |
|
1059 |
// The shader program has changed so mark all uniforms as dirty: |
|
1060 |
brushUniformsDirty = true; |
|
1061 |
opacityUniformDirty = true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1062 |
matrixUniformDirty = true; |
0 | 1063 |
} |
1064 |
||
1065 |
if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode) |
|
1066 |
updateBrushUniforms(); |
|
1067 |
||
1068 |
if (opacityMode == QGLEngineShaderManager::UniformOpacity && opacityUniformDirty) { |
|
1069 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::GlobalOpacity), (GLfloat)q->state()->opacity); |
|
1070 |
opacityUniformDirty = false; |
|
1071 |
} |
|
1072 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1073 |
if (matrixUniformDirty && shaderManager->hasComplexGeometry()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1074 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Matrix), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1075 |
pmvMatrix); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1076 |
matrixUniformDirty = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1077 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1078 |
|
0 | 1079 |
return changed; |
1080 |
} |
|
1081 |
||
1082 |
void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect) |
|
1083 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1084 |
setCoords(staticVertexCoordinateArray, boundingRect); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1085 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); |
0 | 1086 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
1087 |
} |
|
1088 |
||
1089 |
// Draws the vertex array as a set of <vertexArrayStops.size()> triangle fans. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1090 |
void QGL2PaintEngineExPrivate::drawVertexArrays(const float *data, int *stops, int stopCount, |
0 | 1091 |
GLenum primitive) |
1092 |
{ |
|
1093 |
// Now setup the pointer to the vertex array: |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1094 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)data); |
0 | 1095 |
|
1096 |
int previousStop = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
for (int i=0; i<stopCount; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1098 |
int stop = stops[i]; |
0 | 1099 |
/* |
1100 |
qDebug("Drawing triangle fan for vertecies %d -> %d:", previousStop, stop-1); |
|
1101 |
for (int i=previousStop; i<stop; ++i) |
|
1102 |
qDebug(" %02d: [%.2f, %.2f]", i, vertexArray.data()[i].x, vertexArray.data()[i].y); |
|
1103 |
*/ |
|
1104 |
glDrawArrays(primitive, previousStop, stop - previousStop); |
|
1105 |
previousStop = stop; |
|
1106 |
} |
|
1107 |
} |
|
1108 |
||
1109 |
/////////////////////////////////// Public Methods ////////////////////////////////////////// |
|
1110 |
||
1111 |
QGL2PaintEngineEx::QGL2PaintEngineEx() |
|
1112 |
: QPaintEngineEx(*(new QGL2PaintEngineExPrivate(this))) |
|
1113 |
{ |
|
1114 |
} |
|
1115 |
||
1116 |
QGL2PaintEngineEx::~QGL2PaintEngineEx() |
|
1117 |
{ |
|
1118 |
} |
|
1119 |
||
1120 |
void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush) |
|
1121 |
{ |
|
1122 |
Q_D(QGL2PaintEngineEx); |
|
1123 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1124 |
if (qbrush_style(brush) == Qt::NoBrush) |
0 | 1125 |
return; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1126 |
ensureActive(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1127 |
d->setBrush(brush); |
0 | 1128 |
d->fill(path); |
1129 |
} |
|
1130 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1131 |
extern Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1133 |
|
0 | 1134 |
void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) |
1135 |
{ |
|
1136 |
Q_D(QGL2PaintEngineEx); |
|
1137 |
||
1138 |
const QBrush &penBrush = qpen_brush(pen); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1139 |
if (qpen_style(pen) == Qt::NoPen || qbrush_style(penBrush) == Qt::NoBrush) |
0 | 1140 |
return; |
1141 |
||
1142 |
QOpenGL2PaintEngineState *s = state(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
if (pen.isCosmetic() && !qt_scaleForTransform(s->transform(), 0)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1144 |
// QTriangulatingStroker class is not meant to support cosmetically sheared strokes. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1145 |
QPaintEngineEx::stroke(path, pen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
} |
0 | 1148 |
|
1149 |
ensureActive(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1150 |
d->setBrush(penBrush); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1151 |
d->stroke(path, pen); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1152 |
} |
0 | 1153 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1154 |
void QGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &pen) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1155 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1156 |
const QOpenGL2PaintEngineState *s = q->state(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1157 |
const bool newAddOffset = !(s->renderHints & QPainter::Antialiasing) && !multisamplingAlwaysEnabled; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1158 |
if (addOffset != newAddOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1159 |
addOffset = newAddOffset; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1160 |
matrixDirty = true; |
0 | 1161 |
} |
1162 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1163 |
if (snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1164 |
snapToPixelGrid = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1165 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1166 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1167 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1168 |
const Qt::PenStyle penStyle = qpen_style(pen); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1169 |
const QBrush &penBrush = qpen_brush(pen); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1170 |
const bool opaque = penBrush.isOpaque() && s->opacity > 0.99; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1171 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1172 |
transferMode(BrushDrawingMode); |
0 | 1173 |
|
1174 |
// updateMatrix() is responsible for setting the inverse scale on |
|
1175 |
// the strokers, so we need to call it here and not wait for |
|
1176 |
// prepareForDraw() down below. |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1177 |
updateMatrix(); |
0 | 1178 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1179 |
QRectF clip = q->state()->matrix.inverted().mapRect(q->state()->clipEnabled |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1180 |
? q->state()->rectangleClip |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1181 |
: QRectF(0, 0, width, height)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1182 |
|
0 | 1183 |
if (penStyle == Qt::SolidLine) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1184 |
stroker.process(path, pen, clip); |
0 | 1185 |
|
1186 |
} else { // Some sort of dash |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1187 |
dasher.process(path, pen, clip); |
0 | 1188 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1189 |
QVectorPath dashStroke(dasher.points(), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1190 |
dasher.elementCount(), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1191 |
dasher.elementTypes()); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1192 |
stroker.process(dashStroke, pen, clip); |
0 | 1193 |
} |
1194 |
||
1195 |
if (opaque) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1196 |
prepareForDraw(opaque); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1197 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1198 |
glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2); |
0 | 1199 |
|
1200 |
// QBrush b(Qt::green); |
|
1201 |
// d->setBrush(&b); |
|
1202 |
// d->prepareForDraw(true); |
|
1203 |
// glDrawArrays(GL_LINE_STRIP, 0, d->stroker.vertexCount() / 2); |
|
1204 |
||
1205 |
} else { |
|
1206 |
qreal width = qpen_widthf(pen) / 2; |
|
1207 |
if (width == 0) |
|
1208 |
width = 0.5; |
|
1209 |
qreal extra = pen.joinStyle() == Qt::MiterJoin |
|
1210 |
? qMax(pen.miterLimit() * width, width) |
|
1211 |
: width; |
|
1212 |
||
1213 |
if (pen.isCosmetic()) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1214 |
extra = extra * inverseScale; |
0 | 1215 |
|
1216 |
QRectF bounds = path.controlPointRect().adjusted(-extra, -extra, extra, extra); |
|
1217 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1218 |
fillStencilWithVertexArray(stroker.vertices(), stroker.vertexCount() / 2, |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1219 |
0, 0, bounds, QGL2PaintEngineExPrivate::TriStripStrokeFillMode); |
0 | 1220 |
|
1221 |
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); |
|
1222 |
||
1223 |
// Pass when any bit is set, replace stencil value with 0 |
|
1224 |
glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1225 |
prepareForDraw(false); |
0 | 1226 |
|
1227 |
// Stencil the brush onto the dest buffer |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1228 |
composite(bounds); |
0 | 1229 |
|
1230 |
glStencilMask(0); |
|
1231 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1232 |
updateClipScissorTest(); |
0 | 1233 |
} |
1234 |
} |
|
1235 |
||
1236 |
void QGL2PaintEngineEx::penChanged() { } |
|
1237 |
void QGL2PaintEngineEx::brushChanged() { } |
|
1238 |
void QGL2PaintEngineEx::brushOriginChanged() { } |
|
1239 |
||
1240 |
void QGL2PaintEngineEx::opacityChanged() |
|
1241 |
{ |
|
1242 |
// qDebug("QGL2PaintEngineEx::opacityChanged()"); |
|
1243 |
Q_D(QGL2PaintEngineEx); |
|
1244 |
state()->opacityChanged = true; |
|
1245 |
||
1246 |
Q_ASSERT(d->shaderManager); |
|
1247 |
d->brushUniformsDirty = true; |
|
1248 |
d->opacityUniformDirty = true; |
|
1249 |
} |
|
1250 |
||
1251 |
void QGL2PaintEngineEx::compositionModeChanged() |
|
1252 |
{ |
|
1253 |
// qDebug("QGL2PaintEngineEx::compositionModeChanged()"); |
|
1254 |
Q_D(QGL2PaintEngineEx); |
|
1255 |
state()->compositionModeChanged = true; |
|
1256 |
d->compositionModeDirty = true; |
|
1257 |
} |
|
1258 |
||
1259 |
void QGL2PaintEngineEx::renderHintsChanged() |
|
1260 |
{ |
|
1261 |
state()->renderHintsChanged = true; |
|
1262 |
||
1263 |
#if !defined(QT_OPENGL_ES_2) |
|
1264 |
if ((state()->renderHints & QPainter::Antialiasing) |
|
1265 |
|| (state()->renderHints & QPainter::HighQualityAntialiasing)) |
|
1266 |
glEnable(GL_MULTISAMPLE); |
|
1267 |
else |
|
1268 |
glDisable(GL_MULTISAMPLE); |
|
1269 |
#endif |
|
1270 |
||
1271 |
Q_D(QGL2PaintEngineEx); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1272 |
d->lastTextureUsed = GLuint(-1); |
0 | 1273 |
d->brushTextureDirty = true; |
1274 |
// qDebug("QGL2PaintEngineEx::renderHintsChanged() not implemented!"); |
|
1275 |
} |
|
1276 |
||
1277 |
void QGL2PaintEngineEx::transformChanged() |
|
1278 |
{ |
|
1279 |
Q_D(QGL2PaintEngineEx); |
|
1280 |
d->matrixDirty = true; |
|
1281 |
state()->matrixChanged = true; |
|
1282 |
} |
|
1283 |
||
1284 |
||
1285 |
void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src) |
|
1286 |
{ |
|
1287 |
Q_D(QGL2PaintEngineEx); |
|
1288 |
ensureActive(); |
|
1289 |
d->transferMode(ImageDrawingMode); |
|
1290 |
||
1291 |
QGLContext *ctx = d->ctx; |
|
1292 |
glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); |
|
1293 |
QGLTexture *texture = |
|
1294 |
ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, |
|
1295 |
QGLContext::InternalBindOption |
|
1296 |
| QGLContext::CanFlipNativePixmapBindOption); |
|
1297 |
||
1298 |
GLfloat top = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.top()) : src.top(); |
|
1299 |
GLfloat bottom = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.bottom()) : src.bottom(); |
|
1300 |
QGLRect srcRect(src.left(), top, src.right(), bottom); |
|
1301 |
||
1302 |
bool isBitmap = pixmap.isQBitmap(); |
|
1303 |
bool isOpaque = !isBitmap && !pixmap.hasAlphaChannel(); |
|
1304 |
||
1305 |
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, |
|
1306 |
state()->renderHints & QPainter::SmoothPixmapTransform, texture->id); |
|
1307 |
d->drawTexture(dest, srcRect, pixmap.size(), isOpaque, isBitmap); |
|
1308 |
} |
|
1309 |
||
1310 |
void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src, |
|
1311 |
Qt::ImageConversionFlags) |
|
1312 |
{ |
|
1313 |
Q_D(QGL2PaintEngineEx); |
|
1314 |
ensureActive(); |
|
1315 |
d->transferMode(ImageDrawingMode); |
|
1316 |
||
1317 |
QGLContext *ctx = d->ctx; |
|
1318 |
glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); |
|
1319 |
QGLTexture *texture = ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, QGLContext::InternalBindOption); |
|
1320 |
GLuint id = texture->id; |
|
1321 |
||
1322 |
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, |
|
1323 |
state()->renderHints & QPainter::SmoothPixmapTransform, id); |
|
1324 |
d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel()); |
|
1325 |
} |
|
1326 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1327 |
void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) |
0 | 1328 |
{ |
1329 |
Q_D(QGL2PaintEngineEx); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1330 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1331 |
ensureActive(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1332 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1333 |
QFontEngineGlyphCache::Type glyphType = textItem->fontEngine->glyphFormat >= 0 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1334 |
? QFontEngineGlyphCache::Type(textItem->fontEngine->glyphFormat) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1335 |
: d->glyphCacheType; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1336 |
if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1337 |
if (d->device->alphaRequested() || state()->matrix.type() > QTransform::TxTranslate |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1338 |
|| (state()->composition_mode != QPainter::CompositionMode_Source |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1339 |
&& state()->composition_mode != QPainter::CompositionMode_SourceOver)) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1340 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1341 |
glyphType = QFontEngineGlyphCache::Raster_A8; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1342 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1343 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1344 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1345 |
d->drawCachedGlyphs(glyphType, textItem); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1346 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1347 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1348 |
bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1349 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1350 |
Q_D(QGL2PaintEngineEx); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1351 |
if (!d->shaderManager) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1352 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1353 |
|
0 | 1354 |
ensureActive(); |
1355 |
d->transferMode(ImageDrawingMode); |
|
1356 |
||
1357 |
#ifndef QT_OPENGL_ES_2 |
|
1358 |
QGLContext *ctx = d->ctx; |
|
1359 |
#endif |
|
1360 |
glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); |
|
1361 |
glBindTexture(GL_TEXTURE_2D, textureId); |
|
1362 |
||
1363 |
QGLRect srcRect(src.left(), src.bottom(), src.right(), src.top()); |
|
1364 |
||
1365 |
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, |
|
1366 |
state()->renderHints & QPainter::SmoothPixmapTransform, textureId); |
|
1367 |
d->drawTexture(dest, srcRect, size, false); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1368 |
return true; |
0 | 1369 |
} |
1370 |
||
1371 |
void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem) |
|
1372 |
{ |
|
1373 |
Q_D(QGL2PaintEngineEx); |
|
1374 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1375 |
ensureActive(); |
0 | 1376 |
QOpenGL2PaintEngineState *s = state(); |
1377 |
||
1378 |
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); |
|
1379 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1380 |
QTransform::TransformationType txtype = s->matrix.type(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1382 |
float det = s->matrix.determinant(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1383 |
bool drawCached = txtype < QTransform::TxProject; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1384 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
// don't try to cache huge fonts or vastly transformed fonts |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1386 |
const qreal pixelSize = ti.fontEngine->fontDef.pixelSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1387 |
if (pixelSize * pixelSize * qAbs(det) >= 64 * 64 || det < 0.25f || det > 4.f) |
0 | 1388 |
drawCached = false; |
1389 |
||
1390 |
QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 |
|
1391 |
? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) |
|
1392 |
: d->glyphCacheType; |
|
1393 |
||
1394 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1395 |
if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1396 |
if (d->device->alphaRequested() || txtype > QTransform::TxTranslate |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1397 |
|| (state()->composition_mode != QPainter::CompositionMode_Source |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1398 |
&& state()->composition_mode != QPainter::CompositionMode_SourceOver)) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1399 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1400 |
glyphType = QFontEngineGlyphCache::Raster_A8; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1401 |
} |
0 | 1402 |
} |
1403 |
||
1404 |
if (drawCached) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1405 |
QVarLengthArray<QFixedPoint> positions; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1406 |
QVarLengthArray<glyph_t> glyphs; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1407 |
QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1408 |
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1409 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1410 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1411 |
QStaticTextItem staticTextItem; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1412 |
staticTextItem.chars = const_cast<QChar *>(ti.chars); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1413 |
staticTextItem.fontEngine = ti.fontEngine; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1414 |
staticTextItem.glyphs = glyphs.data(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1415 |
staticTextItem.numChars = ti.num_chars; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1416 |
staticTextItem.numGlyphs = glyphs.size(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1417 |
staticTextItem.glyphPositions = positions.data(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1418 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1419 |
d->drawCachedGlyphs(glyphType, &staticTextItem); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1420 |
} |
0 | 1421 |
return; |
1422 |
} |
|
1423 |
||
1424 |
QPaintEngineEx::drawTextItem(p, ti); |
|
1425 |
} |
|
1426 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1427 |
namespace { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1428 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1429 |
class QOpenGLStaticTextUserData: public QStaticTextUserData |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1430 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1431 |
public: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1432 |
QOpenGLStaticTextUserData() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1433 |
: QStaticTextUserData(OpenGLUserData) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1434 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1435 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1436 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1437 |
~QOpenGLStaticTextUserData() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1438 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1439 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1440 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1441 |
QGL2PEXVertexArray vertexCoordinateArray; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1442 |
QGL2PEXVertexArray textureCoordinateArray; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1443 |
}; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1444 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1445 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1446 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1447 |
// #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1448 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1449 |
void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1450 |
QStaticTextItem *staticTextItem) |
0 | 1451 |
{ |
1452 |
Q_Q(QGL2PaintEngineEx); |
|
1453 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1454 |
QOpenGL2PaintEngineState *s = q->state(); |
0 | 1455 |
|
1456 |
QGLTextureGlyphCache *cache = |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1457 |
(QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, QTransform()); |
0 | 1458 |
if (!cache || cache->cacheType() != glyphType) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1459 |
cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform()); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1460 |
staticTextItem->fontEngine->setGlyphCache(ctx, cache); |
0 | 1461 |
} |
1462 |
||
1463 |
cache->setPaintEnginePrivate(this); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1464 |
cache->populate(staticTextItem->fontEngine, staticTextItem->numGlyphs, staticTextItem->glyphs, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1465 |
staticTextItem->glyphPositions); |
0 | 1466 |
|
1467 |
if (cache->width() == 0 || cache->height() == 0) |
|
1468 |
return; |
|
1469 |
||
1470 |
transferMode(TextDrawingMode); |
|
1471 |
||
1472 |
int margin = cache->glyphMargin(); |
|
1473 |
||
1474 |
GLfloat dx = 1.0 / cache->width(); |
|
1475 |
GLfloat dy = 1.0 / cache->height(); |
|
1476 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1477 |
bool recreateVertexArrays = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1478 |
if (staticTextItem->userDataNeedsUpdate) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1479 |
recreateVertexArrays = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1480 |
else if (staticTextItem->userData == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1481 |
recreateVertexArrays = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1482 |
else if (staticTextItem->userData->type != QStaticTextUserData::OpenGLUserData) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1483 |
recreateVertexArrays = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1484 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1485 |
// Use global arrays by default |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1486 |
QGL2PEXVertexArray *vertexCoordinates = &vertexCoordinateArray; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1487 |
QGL2PEXVertexArray *textureCoordinates = &textureCoordinateArray; |
0 | 1488 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1489 |
if (staticTextItem->useBackendOptimizations) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1490 |
QOpenGLStaticTextUserData *userData = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1491 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1492 |
if (staticTextItem->userData == 0 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1493 |
|| staticTextItem->userData->type != QStaticTextUserData::OpenGLUserData) { |
0 | 1494 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1495 |
userData = new QOpenGLStaticTextUserData(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1496 |
staticTextItem->setUserData(userData); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1497 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1498 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1499 |
userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1500 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1501 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1502 |
// Use cache if backend optimizations is turned on |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1503 |
vertexCoordinates = &userData->vertexCoordinateArray; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1504 |
textureCoordinates = &userData->textureCoordinateArray; |
0 | 1505 |
} |
1506 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1507 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1508 |
if (recreateVertexArrays) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1509 |
vertexCoordinates->clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1510 |
textureCoordinates->clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1511 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1512 |
for (int i=0; i<staticTextItem->numGlyphs; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1513 |
const QTextureGlyphCache::Coord &c = cache->coords.value(staticTextItem->glyphs[i]); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1514 |
int x = staticTextItem->glyphPositions[i].x.toInt() + c.baseLineX - margin; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1515 |
int y = staticTextItem->glyphPositions[i].y.toInt() - c.baseLineY - margin; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1516 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1517 |
vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1518 |
textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1519 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1520 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1521 |
staticTextItem->userDataNeedsUpdate = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1522 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1523 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1524 |
if (elementIndices.size() < staticTextItem->numGlyphs*6) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1525 |
Q_ASSERT(elementIndices.size() % 6 == 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1526 |
int j = elementIndices.size() / 6 * 4; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1527 |
while (j < staticTextItem->numGlyphs*4) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1528 |
elementIndices.append(j + 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1529 |
elementIndices.append(j + 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1530 |
elementIndices.append(j + 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1531 |
elementIndices.append(j + 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1532 |
elementIndices.append(j + 3); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1533 |
elementIndices.append(j + 3); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1534 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1535 |
j += 4; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1536 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1537 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1538 |
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1539 |
if (elementIndicesVBOId == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1540 |
glGenBuffers(1, &elementIndicesVBOId); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1541 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1542 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1543 |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementIndices.size() * sizeof(GLushort), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1544 |
elementIndices.constData(), GL_STATIC_DRAW); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1545 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1546 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1547 |
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1548 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1549 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1550 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1551 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1552 |
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1553 |
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data()); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1554 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1555 |
if (addOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1556 |
addOffset = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1557 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1558 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1559 |
if (!snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1560 |
snapToPixelGrid = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1561 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1562 |
} |
0 | 1563 |
|
1564 |
QBrush pensBrush = q->state()->pen.brush(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1565 |
setBrush(pensBrush); |
0 | 1566 |
|
1567 |
if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
|
1568 |
||
1569 |
// Subpixel antialiasing without gamma correction |
|
1570 |
||
1571 |
QPainter::CompositionMode compMode = q->state()->composition_mode; |
|
1572 |
Q_ASSERT(compMode == QPainter::CompositionMode_Source |
|
1573 |
|| compMode == QPainter::CompositionMode_SourceOver); |
|
1574 |
||
1575 |
shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass1); |
|
1576 |
||
1577 |
if (pensBrush.style() == Qt::SolidPattern) { |
|
1578 |
// Solid patterns can get away with only one pass. |
|
1579 |
QColor c = pensBrush.color(); |
|
1580 |
qreal oldOpacity = q->state()->opacity; |
|
1581 |
if (compMode == QPainter::CompositionMode_Source) { |
|
1582 |
c = qt_premultiplyColor(c, q->state()->opacity); |
|
1583 |
q->state()->opacity = 1; |
|
1584 |
opacityUniformDirty = true; |
|
1585 |
} |
|
1586 |
||
1587 |
compositionModeDirty = false; // I can handle this myself, thank you very much |
|
1588 |
prepareForDraw(false); // Text always causes src pixels to be transparent |
|
1589 |
||
1590 |
// prepareForDraw() have set the opacity on the current shader, so the opacity state can now be reset. |
|
1591 |
if (compMode == QPainter::CompositionMode_Source) { |
|
1592 |
q->state()->opacity = oldOpacity; |
|
1593 |
opacityUniformDirty = true; |
|
1594 |
} |
|
1595 |
||
1596 |
glEnable(GL_BLEND); |
|
1597 |
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); |
|
1598 |
glBlendColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); |
|
1599 |
} else { |
|
1600 |
// Other brush styles need two passes. |
|
1601 |
||
1602 |
qreal oldOpacity = q->state()->opacity; |
|
1603 |
if (compMode == QPainter::CompositionMode_Source) { |
|
1604 |
q->state()->opacity = 1; |
|
1605 |
opacityUniformDirty = true; |
|
1606 |
pensBrush = Qt::white; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1607 |
setBrush(pensBrush); |
0 | 1608 |
} |
1609 |
||
1610 |
compositionModeDirty = false; // I can handle this myself, thank you very much |
|
1611 |
prepareForDraw(false); // Text always causes src pixels to be transparent |
|
1612 |
glEnable(GL_BLEND); |
|
1613 |
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); |
|
1614 |
||
1615 |
glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); |
|
1616 |
glBindTexture(GL_TEXTURE_2D, cache->texture()); |
|
1617 |
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); |
|
1618 |
||
1619 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1620 |
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1621 |
glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1622 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1623 |
glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1624 |
#endif |
0 | 1625 |
|
1626 |
shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass2); |
|
1627 |
||
1628 |
if (compMode == QPainter::CompositionMode_Source) { |
|
1629 |
q->state()->opacity = oldOpacity; |
|
1630 |
opacityUniformDirty = true; |
|
1631 |
pensBrush = q->state()->pen.brush(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1632 |
setBrush(pensBrush); |
0 | 1633 |
} |
1634 |
||
1635 |
compositionModeDirty = false; |
|
1636 |
prepareForDraw(false); // Text always causes src pixels to be transparent |
|
1637 |
glEnable(GL_BLEND); |
|
1638 |
glBlendFunc(GL_ONE, GL_ONE); |
|
1639 |
} |
|
1640 |
compositionModeDirty = true; |
|
1641 |
} else { |
|
1642 |
// Greyscale/mono glyphs |
|
1643 |
||
1644 |
shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); |
|
1645 |
prepareForDraw(false); // Text always causes src pixels to be transparent |
|
1646 |
} |
|
1647 |
//### TODO: Gamma correction |
|
1648 |
||
1649 |
glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1650 |
if (lastMaskTextureUsed != cache->texture()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1651 |
glBindTexture(GL_TEXTURE_2D, cache->texture()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1652 |
lastMaskTextureUsed = cache->texture(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1653 |
} |
29
b72c6db6890b
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1654 |
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, s->matrix.type() > QTransform::TxTranslate); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1655 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT); |
0 | 1656 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1657 |
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1658 |
glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1659 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1660 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1661 |
glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1662 |
#endif |
0 | 1663 |
} |
1664 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1665 |
void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1666 |
QPainter::PixmapFragmentHints hints) |
0 | 1667 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1668 |
Q_D(QGL2PaintEngineEx); |
0 | 1669 |
// Use fallback for extended composition modes. |
1670 |
if (state()->composition_mode > QPainter::CompositionMode_Plus) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1671 |
QPaintEngineEx::drawPixmapFragments(fragments, fragmentCount, pixmap, hints); |
0 | 1672 |
return; |
1673 |
} |
|
1674 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1675 |
ensureActive(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1676 |
d->drawPixmapFragments(fragments, fragmentCount, pixmap, hints); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1677 |
} |
0 | 1678 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1679 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1680 |
void QGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFragment *fragments, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1681 |
int fragmentCount, const QPixmap &pixmap, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1682 |
QPainter::PixmapFragmentHints hints) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1683 |
{ |
0 | 1684 |
GLfloat dx = 1.0f / pixmap.size().width(); |
1685 |
GLfloat dy = 1.0f / pixmap.size().height(); |
|
1686 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1687 |
vertexCoordinateArray.clear(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1688 |
textureCoordinateArray.clear(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1689 |
opacityArray.reset(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1690 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1691 |
if (addOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1692 |
addOffset = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1693 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1694 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1695 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1696 |
if (snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1697 |
snapToPixelGrid = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1698 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1699 |
} |
0 | 1700 |
|
1701 |
bool allOpaque = true; |
|
1702 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1703 |
for (int i = 0; i < fragmentCount; ++i) { |
0 | 1704 |
qreal s = 0; |
1705 |
qreal c = 1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1706 |
if (fragments[i].rotation != 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1707 |
s = qFastSin(fragments[i].rotation * Q_PI / 180); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1708 |
c = qFastCos(fragments[i].rotation * Q_PI / 180); |
0 | 1709 |
} |
1710 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1711 |
qreal right = 0.5 * fragments[i].scaleX * fragments[i].width; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1712 |
qreal bottom = 0.5 * fragments[i].scaleY * fragments[i].height; |
0 | 1713 |
QGLPoint bottomRight(right * c - bottom * s, right * s + bottom * c); |
1714 |
QGLPoint bottomLeft(-right * c - bottom * s, -right * s + bottom * c); |
|
1715 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1716 |
vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1717 |
vertexCoordinateArray.addVertex(-bottomLeft.x + fragments[i].x, -bottomLeft.y + fragments[i].y); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1718 |
vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1719 |
vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1720 |
vertexCoordinateArray.addVertex(bottomLeft.x + fragments[i].x, bottomLeft.y + fragments[i].y); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1721 |
vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); |
0 | 1722 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1723 |
QGLRect src(fragments[i].sourceLeft * dx, fragments[i].sourceTop * dy, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1724 |
(fragments[i].sourceLeft + fragments[i].width) * dx, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1725 |
(fragments[i].sourceTop + fragments[i].height) * dy); |
0 | 1726 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1727 |
textureCoordinateArray.addVertex(src.right, src.bottom); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1728 |
textureCoordinateArray.addVertex(src.right, src.top); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1729 |
textureCoordinateArray.addVertex(src.left, src.top); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1730 |
textureCoordinateArray.addVertex(src.left, src.top); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1731 |
textureCoordinateArray.addVertex(src.left, src.bottom); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1732 |
textureCoordinateArray.addVertex(src.right, src.bottom); |
0 | 1733 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1734 |
qreal opacity = fragments[i].opacity * q->state()->opacity; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1735 |
opacityArray << opacity << opacity << opacity << opacity << opacity << opacity; |
0 | 1736 |
allOpaque &= (opacity >= 0.99f); |
1737 |
} |
|
1738 |
||
1739 |
glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); |
|
1740 |
QGLTexture *texture = ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, |
|
1741 |
QGLContext::InternalBindOption |
|
1742 |
| QGLContext::CanFlipNativePixmapBindOption); |
|
1743 |
||
1744 |
if (texture->options & QGLContext::InvertedYBindOption) { |
|
1745 |
// Flip texture y-coordinate. |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1746 |
QGLPoint *data = textureCoordinateArray.data(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1747 |
for (int i = 0; i < 6 * fragmentCount; ++i) |
0 | 1748 |
data[i].y = 1 - data[i].y; |
1749 |
} |
|
1750 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1751 |
transferMode(ImageArrayDrawingMode); |
0 | 1752 |
|
1753 |
bool isBitmap = pixmap.isQBitmap(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1754 |
bool isOpaque = !isBitmap && (!pixmap.hasAlphaChannel() || (hints & QPainter::OpaqueHint)) && allOpaque; |
0 | 1755 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1756 |
updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1757 |
q->state()->renderHints & QPainter::SmoothPixmapTransform, texture->id); |
0 | 1758 |
|
1759 |
// Setup for texture drawing |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1760 |
currentBrush = noBrush; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1761 |
shaderManager->setSrcPixelType(isBitmap ? QGLEngineShaderManager::PatternSrc |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1762 |
: QGLEngineShaderManager::ImageSrc); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1763 |
if (prepareForDraw(isOpaque)) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1764 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT); |
0 | 1765 |
|
1766 |
if (isBitmap) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1767 |
QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1768 |
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); |
0 | 1769 |
} |
1770 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1771 |
glDrawArrays(GL_TRIANGLES, 0, 6 * fragmentCount); |
0 | 1772 |
} |
1773 |
||
1774 |
bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) |
|
1775 |
{ |
|
1776 |
Q_D(QGL2PaintEngineEx); |
|
1777 |
||
1778 |
// qDebug("QGL2PaintEngineEx::begin()"); |
|
1779 |
if (pdev->devType() == QInternal::OpenGL) |
|
1780 |
d->device = static_cast<QGLPaintDevice*>(pdev); |
|
1781 |
else |
|
1782 |
d->device = QGLPaintDevice::getDevice(pdev); |
|
1783 |
||
1784 |
if (!d->device) |
|
1785 |
return false; |
|
1786 |
||
1787 |
d->ctx = d->device->context(); |
|
1788 |
d->ctx->d_ptr->active_engine = this; |
|
1789 |
||
1790 |
const QSize sz = d->device->size(); |
|
1791 |
d->width = sz.width(); |
|
1792 |
d->height = sz.height(); |
|
1793 |
d->mode = BrushDrawingMode; |
|
1794 |
d->brushTextureDirty = true; |
|
1795 |
d->brushUniformsDirty = true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1796 |
d->matrixUniformDirty = true; |
0 | 1797 |
d->matrixDirty = true; |
1798 |
d->compositionModeDirty = true; |
|
1799 |
d->opacityUniformDirty = true; |
|
1800 |
d->needsSync = true; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1801 |
d->useSystemClip = !systemClip().isEmpty(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1802 |
d->currentBrush = QBrush(); |
0 | 1803 |
|
1804 |
d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); |
|
1805 |
d->stencilClean = true; |
|
1806 |
||
1807 |
// Calling begin paint should make the correct context current. So, any |
|
1808 |
// code which calls into GL or otherwise needs a current context *must* |
|
1809 |
// go after beginPaint: |
|
1810 |
d->device->beginPaint(); |
|
1811 |
||
1812 |
#if !defined(QT_OPENGL_ES_2) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1813 |
bool success = qt_resolve_version_2_0_functions(d->ctx) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1814 |
&& qt_resolve_buffer_extensions(d->ctx); |
0 | 1815 |
Q_ASSERT(success); |
1816 |
Q_UNUSED(success); |
|
1817 |
#endif |
|
1818 |
||
1819 |
d->shaderManager = new QGLEngineShaderManager(d->ctx); |
|
1820 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1821 |
glDisable(GL_STENCIL_TEST); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1822 |
glDisable(GL_DEPTH_TEST); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1823 |
glDisable(GL_SCISSOR_TEST); |
0 | 1824 |
|
1825 |
#if !defined(QT_OPENGL_ES_2) |
|
1826 |
glDisable(GL_MULTISAMPLE); |
|
1827 |
#endif |
|
1828 |
||
1829 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; |
|
1830 |
||
1831 |
#if !defined(QT_OPENGL_ES_2) |
|
1832 |
#if defined(Q_WS_WIN) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1833 |
if (qt_cleartype_enabled) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1834 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1835 |
d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; |
0 | 1836 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1837 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1838 |
#if defined(QT_OPENGL_ES_2) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1839 |
// OpenGL ES can't switch MSAA off, so if the gl paint device is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1840 |
// multisampled, it's always multisampled. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1841 |
d->multisamplingAlwaysEnabled = d->device->format().sampleBuffers(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1842 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1843 |
d->multisamplingAlwaysEnabled = false; |
0 | 1844 |
#endif |
1845 |
||
1846 |
return true; |
|
1847 |
} |
|
1848 |
||
1849 |
bool QGL2PaintEngineEx::end() |
|
1850 |
{ |
|
1851 |
Q_D(QGL2PaintEngineEx); |
|
1852 |
QGLContext *ctx = d->ctx; |
|
1853 |
||
1854 |
glUseProgram(0); |
|
1855 |
d->transferMode(BrushDrawingMode); |
|
1856 |
d->device->endPaint(); |
|
1857 |
||
1858 |
#if defined(Q_WS_X11) |
|
1859 |
// On some (probably all) drivers, deleting an X pixmap which has been bound to a texture |
|
1860 |
// before calling glFinish/swapBuffers renders garbage. Presumably this is because X deletes |
|
1861 |
// the pixmap behind the driver's back before it's had a chance to use it. To fix this, we |
|
1862 |
// reference all QPixmaps which have been bound to stop them being deleted and only deref |
|
1863 |
// them here, after swapBuffers, where they can be safely deleted. |
|
1864 |
ctx->d_func()->boundPixmaps.clear(); |
|
1865 |
#endif |
|
1866 |
d->ctx->d_ptr->active_engine = 0; |
|
1867 |
||
1868 |
d->resetGLState(); |
|
1869 |
||
1870 |
delete d->shaderManager; |
|
1871 |
d->shaderManager = 0; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1872 |
d->currentBrush = QBrush(); |
0 | 1873 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1874 |
#ifdef QT_OPENGL_CACHE_AS_VBOS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1875 |
if (!d->unusedVBOSToClean.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1876 |
glDeleteBuffers(d->unusedVBOSToClean.size(), d->unusedVBOSToClean.constData()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1877 |
d->unusedVBOSToClean.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1878 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1879 |
if (!d->unusedIBOSToClean.isEmpty()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1880 |
glDeleteBuffers(d->unusedIBOSToClean.size(), d->unusedIBOSToClean.constData()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1881 |
d->unusedIBOSToClean.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1882 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1883 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1884 |
|
0 | 1885 |
return false; |
1886 |
} |
|
1887 |
||
1888 |
void QGL2PaintEngineEx::ensureActive() |
|
1889 |
{ |
|
1890 |
Q_D(QGL2PaintEngineEx); |
|
1891 |
QGLContext *ctx = d->ctx; |
|
1892 |
||
1893 |
if (isActive() && ctx->d_ptr->active_engine != this) { |
|
1894 |
ctx->d_ptr->active_engine = this; |
|
1895 |
d->needsSync = true; |
|
1896 |
} |
|
1897 |
||
1898 |
d->device->ensureActiveTarget(); |
|
1899 |
||
1900 |
if (d->needsSync) { |
|
1901 |
d->transferMode(BrushDrawingMode); |
|
1902 |
glViewport(0, 0, d->width, d->height); |
|
1903 |
d->needsSync = false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1904 |
d->lastMaskTextureUsed = 0; |
0 | 1905 |
d->shaderManager->setDirty(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1906 |
d->ctx->d_func()->syncGlState(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1907 |
for (int i = 0; i < 3; ++i) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1908 |
d->vertexAttribPointers[i] = (GLfloat*)-1; // Assume the pointers are clobbered |
0 | 1909 |
setState(state()); |
1910 |
} |
|
1911 |
} |
|
1912 |
||
1913 |
void QGL2PaintEngineExPrivate::updateClipScissorTest() |
|
1914 |
{ |
|
1915 |
Q_Q(QGL2PaintEngineEx); |
|
1916 |
if (q->state()->clipTestEnabled) { |
|
1917 |
glEnable(GL_STENCIL_TEST); |
|
1918 |
glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); |
|
1919 |
} else { |
|
1920 |
glDisable(GL_STENCIL_TEST); |
|
1921 |
glStencilFunc(GL_ALWAYS, 0, 0xff); |
|
1922 |
} |
|
1923 |
||
1924 |
#ifdef QT_GL_NO_SCISSOR_TEST |
|
1925 |
currentScissorBounds = QRect(0, 0, width, height); |
|
1926 |
#else |
|
1927 |
QRect bounds = q->state()->rectangleClip; |
|
1928 |
if (!q->state()->clipEnabled) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1929 |
if (useSystemClip) |
0 | 1930 |
bounds = systemClip.boundingRect(); |
1931 |
else |
|
1932 |
bounds = QRect(0, 0, width, height); |
|
1933 |
} else { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1934 |
if (useSystemClip) |
0 | 1935 |
bounds = bounds.intersected(systemClip.boundingRect()); |
1936 |
else |
|
1937 |
bounds = bounds.intersected(QRect(0, 0, width, height)); |
|
1938 |
} |
|
1939 |
||
1940 |
currentScissorBounds = bounds; |
|
1941 |
||
1942 |
if (bounds == QRect(0, 0, width, height)) { |
|
1943 |
glDisable(GL_SCISSOR_TEST); |
|
1944 |
} else { |
|
1945 |
glEnable(GL_SCISSOR_TEST); |
|
1946 |
setScissor(bounds); |
|
1947 |
} |
|
1948 |
#endif |
|
1949 |
} |
|
1950 |
||
1951 |
void QGL2PaintEngineExPrivate::setScissor(const QRect &rect) |
|
1952 |
{ |
|
1953 |
const int left = rect.left(); |
|
1954 |
const int width = rect.width(); |
|
1955 |
const int bottom = height - (rect.top() + rect.height()); |
|
1956 |
const int height = rect.height(); |
|
1957 |
||
1958 |
glScissor(left, bottom, width, height); |
|
1959 |
} |
|
1960 |
||
1961 |
void QGL2PaintEngineEx::clipEnabledChanged() |
|
1962 |
{ |
|
1963 |
Q_D(QGL2PaintEngineEx); |
|
1964 |
||
1965 |
state()->clipChanged = true; |
|
1966 |
||
1967 |
if (painter()->hasClipping()) |
|
1968 |
d->regenerateClip(); |
|
1969 |
else |
|
1970 |
d->systemStateChanged(); |
|
1971 |
} |
|
1972 |
||
1973 |
void QGL2PaintEngineExPrivate::clearClip(uint value) |
|
1974 |
{ |
|
1975 |
dirtyStencilRegion -= currentScissorBounds; |
|
1976 |
||
1977 |
glStencilMask(0xff); |
|
1978 |
glClearStencil(value); |
|
1979 |
glClear(GL_STENCIL_BUFFER_BIT); |
|
1980 |
glStencilMask(0x0); |
|
1981 |
||
1982 |
q->state()->needsClipBufferClear = false; |
|
1983 |
} |
|
1984 |
||
1985 |
void QGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, uint value) |
|
1986 |
{ |
|
1987 |
transferMode(BrushDrawingMode); |
|
1988 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1989 |
if (addOffset) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1990 |
addOffset = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1991 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1992 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1993 |
if (snapToPixelGrid) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1994 |
snapToPixelGrid = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1995 |
matrixDirty = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1996 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1997 |
|
0 | 1998 |
if (matrixDirty) |
1999 |
updateMatrix(); |
|
2000 |
||
2001 |
stencilClean = false; |
|
2002 |
||
2003 |
const bool singlePass = !path.hasWindingFill() |
|
2004 |
&& (((q->state()->currentClip == maxClip - 1) && q->state()->clipTestEnabled) |
|
2005 |
|| q->state()->needsClipBufferClear); |
|
2006 |
const uint referenceClipValue = q->state()->needsClipBufferClear ? 1 : q->state()->currentClip; |
|
2007 |
||
2008 |
if (q->state()->needsClipBufferClear) |
|
2009 |
clearClip(1); |
|
2010 |
||
2011 |
if (path.isEmpty()) { |
|
2012 |
glEnable(GL_STENCIL_TEST); |
|
2013 |
glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT); |
|
2014 |
return; |
|
2015 |
} |
|
2016 |
||
2017 |
if (q->state()->clipTestEnabled) |
|
2018 |
glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); |
|
2019 |
else |
|
2020 |
glStencilFunc(GL_ALWAYS, 0, 0xff); |
|
2021 |
||
2022 |
vertexCoordinateArray.clear(); |
|
2023 |
vertexCoordinateArray.addPath(path, inverseScale, false); |
|
2024 |
||
2025 |
if (!singlePass) |
|
2026 |
fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); |
|
2027 |
||
2028 |
glColorMask(false, false, false, false); |
|
2029 |
glEnable(GL_STENCIL_TEST); |
|
2030 |
useSimpleShader(); |
|
2031 |
||
2032 |
if (singlePass) { |
|
2033 |
// Under these conditions we can set the new stencil value in a single |
|
2034 |
// pass, by using the current value and the "new value" as the toggles |
|
2035 |
||
2036 |
glStencilFunc(GL_LEQUAL, referenceClipValue, ~GL_STENCIL_HIGH_BIT); |
|
2037 |
glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT); |
|
2038 |
glStencilMask(value ^ referenceClipValue); |
|
2039 |
||
2040 |
drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN); |
|
2041 |
} else { |
|
2042 |
glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); |
|
2043 |
glStencilMask(0xff); |
|
2044 |
||
2045 |
if (!q->state()->clipTestEnabled && path.hasWindingFill()) { |
|
2046 |
// Pass when any clip bit is set, set high bit |
|
2047 |
glStencilFunc(GL_NOTEQUAL, GL_STENCIL_HIGH_BIT, ~GL_STENCIL_HIGH_BIT); |
|
2048 |
composite(vertexCoordinateArray.boundingRect()); |
|
2049 |
} |
|
2050 |
||
2051 |
// Pass when high bit is set, replace stencil value with new clip value |
|
2052 |
glStencilFunc(GL_NOTEQUAL, value, GL_STENCIL_HIGH_BIT); |
|
2053 |
||
2054 |
composite(vertexCoordinateArray.boundingRect()); |
|
2055 |
} |
|
2056 |
||
2057 |
glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT); |
|
2058 |
glStencilMask(0); |
|
2059 |
||
2060 |
glColorMask(true, true, true, true); |
|
2061 |
} |
|
2062 |
||
2063 |
void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op) |
|
2064 |
{ |
|
2065 |
// qDebug("QGL2PaintEngineEx::clip()"); |
|
2066 |
Q_D(QGL2PaintEngineEx); |
|
2067 |
||
2068 |
state()->clipChanged = true; |
|
2069 |
||
2070 |
ensureActive(); |
|
2071 |
||
2072 |
if (op == Qt::ReplaceClip) { |
|
2073 |
op = Qt::IntersectClip; |
|
2074 |
if (d->hasClipOperations()) { |
|
2075 |
d->systemStateChanged(); |
|
2076 |
state()->canRestoreClip = false; |
|
2077 |
} |
|
2078 |
} |
|
2079 |
||
2080 |
#ifndef QT_GL_NO_SCISSOR_TEST |
|
2081 |
if (!path.isEmpty() && op == Qt::IntersectClip && (path.shape() == QVectorPath::RectangleHint)) { |
|
2082 |
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); |
|
2083 |
QRectF rect(points[0], points[2]); |
|
2084 |
||
2085 |
if (state()->matrix.type() <= QTransform::TxScale) { |
|
2086 |
state()->rectangleClip = state()->rectangleClip.intersected(state()->matrix.mapRect(rect).toRect()); |
|
2087 |
d->updateClipScissorTest(); |
|
2088 |
return; |
|
2089 |
} |
|
2090 |
} |
|
2091 |
#endif |
|
2092 |
||
2093 |
const QRect pathRect = state()->matrix.mapRect(path.controlPointRect()).toAlignedRect(); |
|
2094 |
||
2095 |
switch (op) { |
|
2096 |
case Qt::NoClip: |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2097 |
if (d->useSystemClip) { |
0 | 2098 |
state()->clipTestEnabled = true; |
2099 |
state()->currentClip = 1; |
|
2100 |
} else { |
|
2101 |
state()->clipTestEnabled = false; |
|
2102 |
} |
|
2103 |
state()->rectangleClip = QRect(0, 0, d->width, d->height); |
|
2104 |
state()->canRestoreClip = false; |
|
2105 |
d->updateClipScissorTest(); |
|
2106 |
break; |
|
2107 |
case Qt::IntersectClip: |
|
2108 |
state()->rectangleClip = state()->rectangleClip.intersected(pathRect); |
|
2109 |
d->updateClipScissorTest(); |
|
2110 |
d->resetClipIfNeeded(); |
|
2111 |
++d->maxClip; |
|
2112 |
d->writeClip(path, d->maxClip); |
|
2113 |
state()->currentClip = d->maxClip; |
|
2114 |
state()->clipTestEnabled = true; |
|
2115 |
break; |
|
2116 |
case Qt::UniteClip: { |
|
2117 |
d->resetClipIfNeeded(); |
|
2118 |
++d->maxClip; |
|
2119 |
if (state()->rectangleClip.isValid()) { |
|
2120 |
QPainterPath path; |
|
2121 |
path.addRect(state()->rectangleClip); |
|
2122 |
||
2123 |
// flush the existing clip rectangle to the depth buffer |
|
2124 |
d->writeClip(qtVectorPathForPath(state()->matrix.inverted().map(path)), d->maxClip); |
|
2125 |
} |
|
2126 |
||
2127 |
state()->clipTestEnabled = false; |
|
2128 |
#ifndef QT_GL_NO_SCISSOR_TEST |
|
2129 |
QRect oldRectangleClip = state()->rectangleClip; |
|
2130 |
||
2131 |
state()->rectangleClip = state()->rectangleClip.united(pathRect); |
|
2132 |
d->updateClipScissorTest(); |
|
2133 |
||
2134 |
QRegion extendRegion = QRegion(state()->rectangleClip) - oldRectangleClip; |
|
2135 |
||
2136 |
if (!extendRegion.isEmpty()) { |
|
2137 |
QPainterPath extendPath; |
|
2138 |
extendPath.addRegion(extendRegion); |
|
2139 |
||
2140 |
// first clear the depth buffer in the extended region |
|
2141 |
d->writeClip(qtVectorPathForPath(state()->matrix.inverted().map(extendPath)), 0); |
|
2142 |
} |
|
2143 |
#endif |
|
2144 |
// now write the clip path |
|
2145 |
d->writeClip(path, d->maxClip); |
|
2146 |
state()->canRestoreClip = false; |
|
2147 |
state()->currentClip = d->maxClip; |
|
2148 |
state()->clipTestEnabled = true; |
|
2149 |
break; |
|
2150 |
} |
|
2151 |
default: |
|
2152 |
break; |
|
2153 |
} |
|
2154 |
} |
|
2155 |
||
2156 |
void QGL2PaintEngineExPrivate::regenerateClip() |
|
2157 |
{ |
|
2158 |
systemStateChanged(); |
|
2159 |
replayClipOperations(); |
|
2160 |
} |
|
2161 |
||
2162 |
void QGL2PaintEngineExPrivate::systemStateChanged() |
|
2163 |
{ |
|
2164 |
Q_Q(QGL2PaintEngineEx); |
|
2165 |
||
2166 |
q->state()->clipChanged = true; |
|
2167 |
||
2168 |
if (systemClip.isEmpty()) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2169 |
useSystemClip = false; |
0 | 2170 |
} else { |
2171 |
if (q->paintDevice()->devType() == QInternal::Widget && currentClipWidget) { |
|
2172 |
QWidgetPrivate *widgetPrivate = qt_widget_private(currentClipWidget->window()); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2173 |
useSystemClip = widgetPrivate->extra && widgetPrivate->extra->inRenderWithPainter; |
0 | 2174 |
} else { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2175 |
useSystemClip = true; |
0 | 2176 |
} |
2177 |
} |
|
2178 |
||
2179 |
q->state()->clipTestEnabled = false; |
|
2180 |
q->state()->needsClipBufferClear = true; |
|
2181 |
||
2182 |
q->state()->currentClip = 1; |
|
2183 |
maxClip = 1; |
|
2184 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2185 |
q->state()->rectangleClip = useSystemClip ? systemClip.boundingRect() : QRect(0, 0, width, height); |
0 | 2186 |
updateClipScissorTest(); |
2187 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2188 |
if (systemClip.rectCount() == 1) { |
0 | 2189 |
if (systemClip.boundingRect() == QRect(0, 0, width, height)) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2190 |
useSystemClip = false; |
0 | 2191 |
#ifndef QT_GL_NO_SCISSOR_TEST |
2192 |
// scissoring takes care of the system clip |
|
2193 |
return; |
|
2194 |
#endif |
|
2195 |
} |
|
2196 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2197 |
if (useSystemClip) { |
0 | 2198 |
clearClip(0); |
2199 |
||
2200 |
QPainterPath path; |
|
2201 |
path.addRegion(systemClip); |
|
2202 |
||
2203 |
q->state()->currentClip = 0; |
|
2204 |
writeClip(qtVectorPathForPath(q->state()->matrix.inverted().map(path)), 1); |
|
2205 |
q->state()->currentClip = 1; |
|
2206 |
q->state()->clipTestEnabled = true; |
|
2207 |
} |
|
2208 |
} |
|
2209 |
||
2210 |
void QGL2PaintEngineEx::setState(QPainterState *new_state) |
|
2211 |
{ |
|
2212 |
// qDebug("QGL2PaintEngineEx::setState()"); |
|
2213 |
||
2214 |
Q_D(QGL2PaintEngineEx); |
|
2215 |
||
2216 |
QOpenGL2PaintEngineState *s = static_cast<QOpenGL2PaintEngineState *>(new_state); |
|
2217 |
QOpenGL2PaintEngineState *old_state = state(); |
|
2218 |
||
2219 |
QPaintEngineEx::setState(s); |
|
2220 |
||
2221 |
if (s->isNew) { |
|
2222 |
// Newly created state object. The call to setState() |
|
2223 |
// will either be followed by a call to begin(), or we are |
|
2224 |
// setting the state as part of a save(). |
|
2225 |
s->isNew = false; |
|
2226 |
return; |
|
2227 |
} |
|
2228 |
||
2229 |
// Setting the state as part of a restore(). |
|
2230 |
||
2231 |
if (old_state == s || old_state->renderHintsChanged) |
|
2232 |
renderHintsChanged(); |
|
2233 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2234 |
if (old_state == s || old_state->matrixChanged) |
0 | 2235 |
d->matrixDirty = true; |
2236 |
||
2237 |
if (old_state == s || old_state->compositionModeChanged) |
|
2238 |
d->compositionModeDirty = true; |
|
2239 |
||
2240 |
if (old_state == s || old_state->opacityChanged) |
|
2241 |
d->opacityUniformDirty = true; |
|
2242 |
||
2243 |
if (old_state == s || old_state->clipChanged) { |
|
2244 |
if (old_state && old_state != s && old_state->canRestoreClip) { |
|
2245 |
d->updateClipScissorTest(); |
|
2246 |
glDepthFunc(GL_LEQUAL); |
|
2247 |
} else { |
|
2248 |
d->regenerateClip(); |
|
2249 |
} |
|
2250 |
} |
|
2251 |
} |
|
2252 |
||
2253 |
QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const |
|
2254 |
{ |
|
2255 |
if (orig) |
|
2256 |
const_cast<QGL2PaintEngineEx *>(this)->ensureActive(); |
|
2257 |
||
2258 |
QOpenGL2PaintEngineState *s; |
|
2259 |
if (!orig) |
|
2260 |
s = new QOpenGL2PaintEngineState(); |
|
2261 |
else |
|
2262 |
s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig)); |
|
2263 |
||
2264 |
s->matrixChanged = false; |
|
2265 |
s->compositionModeChanged = false; |
|
2266 |
s->opacityChanged = false; |
|
2267 |
s->renderHintsChanged = false; |
|
2268 |
s->clipChanged = false; |
|
2269 |
||
2270 |
return s; |
|
2271 |
} |
|
2272 |
||
2273 |
QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other) |
|
2274 |
: QPainterState(other) |
|
2275 |
{ |
|
2276 |
isNew = true; |
|
2277 |
needsClipBufferClear = other.needsClipBufferClear; |
|
2278 |
clipTestEnabled = other.clipTestEnabled; |
|
2279 |
currentClip = other.currentClip; |
|
2280 |
canRestoreClip = other.canRestoreClip; |
|
2281 |
rectangleClip = other.rectangleClip; |
|
2282 |
} |
|
2283 |
||
2284 |
QOpenGL2PaintEngineState::QOpenGL2PaintEngineState() |
|
2285 |
{ |
|
2286 |
isNew = true; |
|
2287 |
needsClipBufferClear = true; |
|
2288 |
clipTestEnabled = false; |
|
2289 |
canRestoreClip = true; |
|
2290 |
} |
|
2291 |
||
2292 |
QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState() |
|
2293 |
{ |
|
2294 |
} |
|
2295 |
||
2296 |
QT_END_NAMESPACE |