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