Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qtextureglyphcache_gl_p.h" | - | ||||||||||||||||||
35 | #include "qpaintengineex_opengl2_p.h" | - | ||||||||||||||||||
36 | #include "qglfunctions.h" | - | ||||||||||||||||||
37 | #include "private/qglengineshadersource_p.h" | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | - | |||||||||||||||||||
42 | QBasicAtomicInt qgltextureglyphcache_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1); | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | QGLTextureGlyphCache::QGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix) | - | ||||||||||||||||||
45 | : QImageTextureGlyphCache(format, matrix) | - | ||||||||||||||||||
46 | , m_textureResource(0) | - | ||||||||||||||||||
47 | , pex(0) | - | ||||||||||||||||||
48 | , m_blitProgram(0) | - | ||||||||||||||||||
49 | , m_filterMode(Nearest) | - | ||||||||||||||||||
50 | , m_serialNumber(qgltextureglyphcache_serial_number.fetchAndAddRelaxed(1)) | - | ||||||||||||||||||
51 | { | - | ||||||||||||||||||
52 | #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG | - | ||||||||||||||||||
53 | qDebug(" -> QGLTextureGlyphCache() %p for context %p.", this, QOpenGLContext::currentContext()); | - | ||||||||||||||||||
54 | #endif | - | ||||||||||||||||||
55 | m_vertexCoordinateArray[0] = -1.0f; | - | ||||||||||||||||||
56 | m_vertexCoordinateArray[1] = -1.0f; | - | ||||||||||||||||||
57 | m_vertexCoordinateArray[2] = 1.0f; | - | ||||||||||||||||||
58 | m_vertexCoordinateArray[3] = -1.0f; | - | ||||||||||||||||||
59 | m_vertexCoordinateArray[4] = 1.0f; | - | ||||||||||||||||||
60 | m_vertexCoordinateArray[5] = 1.0f; | - | ||||||||||||||||||
61 | m_vertexCoordinateArray[6] = -1.0f; | - | ||||||||||||||||||
62 | m_vertexCoordinateArray[7] = 1.0f; | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | m_textureCoordinateArray[0] = 0.0f; | - | ||||||||||||||||||
65 | m_textureCoordinateArray[1] = 0.0f; | - | ||||||||||||||||||
66 | m_textureCoordinateArray[2] = 1.0f; | - | ||||||||||||||||||
67 | m_textureCoordinateArray[3] = 0.0f; | - | ||||||||||||||||||
68 | m_textureCoordinateArray[4] = 1.0f; | - | ||||||||||||||||||
69 | m_textureCoordinateArray[5] = 1.0f; | - | ||||||||||||||||||
70 | m_textureCoordinateArray[6] = 0.0f; | - | ||||||||||||||||||
71 | m_textureCoordinateArray[7] = 1.0f; | - | ||||||||||||||||||
72 | } never executed: end of block | 0 | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | QGLTextureGlyphCache::~QGLTextureGlyphCache() | - | ||||||||||||||||||
75 | { | - | ||||||||||||||||||
76 | #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG | - | ||||||||||||||||||
77 | qDebug(" -> ~QGLTextureGlyphCache() %p.", this); | - | ||||||||||||||||||
78 | #endif | - | ||||||||||||||||||
79 | delete m_blitProgram; | - | ||||||||||||||||||
80 | if (m_textureResource)
| 0 | ||||||||||||||||||
81 | m_textureResource->free(); never executed: m_textureResource->free(); | 0 | ||||||||||||||||||
82 | } never executed: end of block | 0 | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | void QGLTextureGlyphCache::createTextureData(int width, int height) | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
87 | if (ctx == 0) {
| 0 | ||||||||||||||||||
88 | qWarning("QGLTextureGlyphCache::createTextureData: Called with no context"); | - | ||||||||||||||||||
89 | return; never executed: return; | 0 | ||||||||||||||||||
90 | } | - | ||||||||||||||||||
91 | QOpenGLFunctions *funcs = ctx->contextHandle()->functions(); | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | // create in QImageTextureGlyphCache baseclass is meant to be called | - | ||||||||||||||||||
94 | // only to create the initial image and does not preserve the content, | - | ||||||||||||||||||
95 | // so we don't call when this function is called from resize. | - | ||||||||||||||||||
96 | if ((!QGLFramebufferObject::hasOpenGLFramebufferObjects() || ctx->d_ptr->workaround_brokenFBOReadBack) && image().isNull())
| 0 | ||||||||||||||||||
97 | QImageTextureGlyphCache::createTextureData(width, height); never executed: QImageTextureGlyphCache::createTextureData(width, height); | 0 | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | // Make the lower glyph texture size 16 x 16. | - | ||||||||||||||||||
100 | if (width < 16)
| 0 | ||||||||||||||||||
101 | width = 16; never executed: width = 16; | 0 | ||||||||||||||||||
102 | if (height < 16)
| 0 | ||||||||||||||||||
103 | height = 16; never executed: height = 16; | 0 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | if (m_textureResource && !m_textureResource->m_texture) {
| 0 | ||||||||||||||||||
106 | delete m_textureResource; | - | ||||||||||||||||||
107 | m_textureResource = 0; | - | ||||||||||||||||||
108 | } never executed: end of block | 0 | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | if (!m_textureResource)
| 0 | ||||||||||||||||||
111 | m_textureResource = new QGLGlyphTexture(ctx); never executed: m_textureResource = new QGLGlyphTexture(ctx); | 0 | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | funcs->glGenTextures(1, &m_textureResource->m_texture); | - | ||||||||||||||||||
114 | funcs->glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | m_textureResource->m_width = width; | - | ||||||||||||||||||
117 | m_textureResource->m_height = height; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | if (m_format == QFontEngine::Format_A32) {
| 0 | ||||||||||||||||||
120 | QVarLengthArray<uchar> data(width * height * 4); | - | ||||||||||||||||||
121 | for (int i = 0; i < data.size(); ++i)
| 0 | ||||||||||||||||||
122 | data[i] = 0; never executed: data[i] = 0; | 0 | ||||||||||||||||||
123 | funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); | - | ||||||||||||||||||
124 | } else { never executed: end of block | 0 | ||||||||||||||||||
125 | QVarLengthArray<uchar> data(width * height); | - | ||||||||||||||||||
126 | for (int i = 0; i < data.size(); ++i)
| 0 | ||||||||||||||||||
127 | data[i] = 0; never executed: data[i] = 0; | 0 | ||||||||||||||||||
128 | funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]); | - | ||||||||||||||||||
129 | } never executed: end of block | 0 | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
132 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
133 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | - | ||||||||||||||||||
134 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | - | ||||||||||||||||||
135 | m_filterMode = Nearest; | - | ||||||||||||||||||
136 | } never executed: end of block | 0 | ||||||||||||||||||
137 | - | |||||||||||||||||||
138 | void QGLTextureGlyphCache::resizeTextureData(int width, int height) | - | ||||||||||||||||||
139 | { | - | ||||||||||||||||||
140 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
141 | if (ctx == 0) {
| 0 | ||||||||||||||||||
142 | qWarning("QGLTextureGlyphCache::resizeTextureData: Called with no context"); | - | ||||||||||||||||||
143 | return; never executed: return; | 0 | ||||||||||||||||||
144 | } | - | ||||||||||||||||||
145 | QOpenGLFunctions *funcs = ctx->contextHandle()->functions(); | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | int oldWidth = m_textureResource->m_width; | - | ||||||||||||||||||
148 | int oldHeight = m_textureResource->m_height; | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | // Make the lower glyph texture size 16 x 16. | - | ||||||||||||||||||
151 | if (width < 16)
| 0 | ||||||||||||||||||
152 | width = 16; never executed: width = 16; | 0 | ||||||||||||||||||
153 | if (height < 16)
| 0 | ||||||||||||||||||
154 | height = 16; never executed: height = 16; | 0 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | GLuint oldTexture = m_textureResource->m_texture; | - | ||||||||||||||||||
157 | createTextureData(width, height); | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | if (!QGLFramebufferObject::hasOpenGLFramebufferObjects() || ctx->d_ptr->workaround_brokenFBOReadBack) {
| 0 | ||||||||||||||||||
160 | QImageTextureGlyphCache::resizeTextureData(width, height); | - | ||||||||||||||||||
161 | Q_ASSERT(image().depth() == 8); | - | ||||||||||||||||||
162 | funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, oldHeight, GL_ALPHA, GL_UNSIGNED_BYTE, image().constBits()); | - | ||||||||||||||||||
163 | funcs->glDeleteTextures(1, &oldTexture); | - | ||||||||||||||||||
164 | return; never executed: return; | 0 | ||||||||||||||||||
165 | } | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | // ### the QTextureGlyphCache API needs to be reworked to allow | - | ||||||||||||||||||
168 | // ### resizeTextureData to fail | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | ctx->d_ptr->refreshCurrentFbo(); | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | funcs->glBindFramebuffer(GL_FRAMEBUFFER, m_textureResource->m_fbo); | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | GLuint tmp_texture; | - | ||||||||||||||||||
175 | funcs->glGenTextures(1, &tmp_texture); | - | ||||||||||||||||||
176 | funcs->glBindTexture(GL_TEXTURE_2D, tmp_texture); | - | ||||||||||||||||||
177 | funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0, | - | ||||||||||||||||||
178 | GL_RGBA, GL_UNSIGNED_BYTE, NULL); | - | ||||||||||||||||||
179 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
180 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
181 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | - | ||||||||||||||||||
182 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | - | ||||||||||||||||||
183 | m_filterMode = Nearest; | - | ||||||||||||||||||
184 | funcs->glBindTexture(GL_TEXTURE_2D, 0); | - | ||||||||||||||||||
185 | funcs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | - | ||||||||||||||||||
186 | GL_TEXTURE_2D, tmp_texture, 0); | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | funcs->glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||
189 | funcs->glBindTexture(GL_TEXTURE_2D, oldTexture); | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | if (pex != 0)
| 0 | ||||||||||||||||||
192 | pex->transferMode(BrushDrawingMode); never executed: pex->transferMode(BrushDrawingMode); | 0 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | funcs->glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||
195 | funcs->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||
196 | funcs->glDisable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
197 | funcs->glDisable(GL_BLEND); | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | funcs->glViewport(0, 0, oldWidth, oldHeight); | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | QGLShaderProgram *blitProgram = 0; | - | ||||||||||||||||||
202 | if (pex == 0) {
| 0 | ||||||||||||||||||
203 | if (m_blitProgram == 0) {
| 0 | ||||||||||||||||||
204 | m_blitProgram = new QGLShaderProgram(ctx); | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | { | - | ||||||||||||||||||
207 | QString source; | - | ||||||||||||||||||
208 | source.append(QLatin1String(qglslMainWithTexCoordsVertexShader)); | - | ||||||||||||||||||
209 | source.append(QLatin1String(qglslUntransformedPositionVertexShader)); | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | QGLShader *vertexShader = new QGLShader(QGLShader::Vertex, m_blitProgram); | - | ||||||||||||||||||
212 | vertexShader->compileSourceCode(source); | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | m_blitProgram->addShader(vertexShader); | - | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | QString source; | - | ||||||||||||||||||
219 | source.append(QLatin1String(qglslMainFragmentShader)); | - | ||||||||||||||||||
220 | source.append(QLatin1String(qglslImageSrcFragmentShader)); | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | QGLShader *fragmentShader = new QGLShader(QGLShader::Fragment, m_blitProgram); | - | ||||||||||||||||||
223 | fragmentShader->compileSourceCode(source); | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | m_blitProgram->addShader(fragmentShader); | - | ||||||||||||||||||
226 | } | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR); | - | ||||||||||||||||||
229 | m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR); | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | m_blitProgram->link(); | - | ||||||||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | funcs->glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_vertexCoordinateArray); | - | ||||||||||||||||||
235 | funcs->glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_textureCoordinateArray); | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | m_blitProgram->bind(); | - | ||||||||||||||||||
238 | m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); | - | ||||||||||||||||||
239 | m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); | - | ||||||||||||||||||
240 | m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR)); | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | blitProgram = m_blitProgram; | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | } else { never executed: end of block | 0 | ||||||||||||||||||
245 | pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray); | - | ||||||||||||||||||
246 | pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray); | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | pex->shaderManager->useBlitProgram(); | - | ||||||||||||||||||
249 | blitProgram = pex->shaderManager->blitProgram(); | - | ||||||||||||||||||
250 | } never executed: end of block | 0 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | blitProgram->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | funcs->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | funcs->glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | funcs->glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight); | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | - | ||||||||||||||||||
261 | GL_RENDERBUFFER, 0); | - | ||||||||||||||||||
262 | funcs->glDeleteTextures(1, &tmp_texture); | - | ||||||||||||||||||
263 | funcs->glDeleteTextures(1, &oldTexture); | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | funcs->glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_ptr->current_fbo); | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | if (pex != 0) {
| 0 | ||||||||||||||||||
268 | funcs->glViewport(0, 0, pex->width, pex->height); | - | ||||||||||||||||||
269 | pex->updateClipScissorTest(); | - | ||||||||||||||||||
270 | } never executed: end of block | 0 | ||||||||||||||||||
271 | } never executed: end of block | 0 | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition) | - | ||||||||||||||||||
274 | { | - | ||||||||||||||||||
275 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
276 | if (ctx == 0) {
| 0 | ||||||||||||||||||
277 | qWarning("QGLTextureGlyphCache::fillTexture: Called with no context"); | - | ||||||||||||||||||
278 | return; never executed: return; | 0 | ||||||||||||||||||
279 | } | - | ||||||||||||||||||
280 | QOpenGLFunctions *funcs = ctx->contextHandle()->functions(); | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | if (!QGLFramebufferObject::hasOpenGLFramebufferObjects() || ctx->d_ptr->workaround_brokenFBOReadBack) {
| 0 | ||||||||||||||||||
283 | QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition); | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | funcs->glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); | - | ||||||||||||||||||
286 | const QImage &texture = image(); | - | ||||||||||||||||||
287 | const uchar *bits = texture.constBits(); | - | ||||||||||||||||||
288 | bits += c.y * texture.bytesPerLine() + c.x; | - | ||||||||||||||||||
289 | for (int i=0; i<c.h; ++i) {
| 0 | ||||||||||||||||||
290 | funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, c.w, 1, GL_ALPHA, GL_UNSIGNED_BYTE, bits); | - | ||||||||||||||||||
291 | bits += texture.bytesPerLine(); | - | ||||||||||||||||||
292 | } never executed: end of block | 0 | ||||||||||||||||||
293 | return; never executed: return; | 0 | ||||||||||||||||||
294 | } | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | QImage mask = textureMapForGlyph(glyph, subPixelPosition); | - | ||||||||||||||||||
297 | const int maskWidth = mask.width(); | - | ||||||||||||||||||
298 | const int maskHeight = mask.height(); | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | if (mask.format() == QImage::Format_Mono) {
| 0 | ||||||||||||||||||
301 | mask = mask.convertToFormat(QImage::Format_Indexed8); | - | ||||||||||||||||||
302 | for (int y = 0; y < maskHeight; ++y) {
| 0 | ||||||||||||||||||
303 | uchar *src = (uchar *) mask.scanLine(y); | - | ||||||||||||||||||
304 | for (int x = 0; x < maskWidth; ++x)
| 0 | ||||||||||||||||||
305 | src[x] = -src[x]; // convert 0 and 1 into 0 and 255 never executed: src[x] = -src[x]; | 0 | ||||||||||||||||||
306 | } never executed: end of block | 0 | ||||||||||||||||||
307 | } else if (mask.depth() == 32) { never executed: end of block
| 0 | ||||||||||||||||||
308 | // Make the alpha component equal to the average of the RGB values. | - | ||||||||||||||||||
309 | // This is needed when drawing sub-pixel antialiased text on translucent targets. | - | ||||||||||||||||||
310 | for (int y = 0; y < maskHeight; ++y) {
| 0 | ||||||||||||||||||
311 | quint32 *src = (quint32 *) mask.scanLine(y); | - | ||||||||||||||||||
312 | for (int x = 0; x < maskWidth; ++x) {
| 0 | ||||||||||||||||||
313 | int r = qRed(src[x]); | - | ||||||||||||||||||
314 | int g = qGreen(src[x]); | - | ||||||||||||||||||
315 | int b = qBlue(src[x]); | - | ||||||||||||||||||
316 | int avg; | - | ||||||||||||||||||
317 | if (mask.format() == QImage::Format_RGB32)
| 0 | ||||||||||||||||||
318 | avg = (r + g + b + 1) / 3; // "+1" for rounding. never executed: avg = (r + g + b + 1) / 3; | 0 | ||||||||||||||||||
319 | else // Format_ARGB_Premultiplied | - | ||||||||||||||||||
320 | avg = qAlpha(src[x]); never executed: avg = qAlpha(src[x]); | 0 | ||||||||||||||||||
321 | if (ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
322 | // swizzle the bits to accommodate for the GL_RGBA upload. | - | ||||||||||||||||||
323 | src[x] = (avg << 24) | (r << 0) | (g << 8) | (b << 16); | - | ||||||||||||||||||
324 | } else { never executed: end of block | 0 | ||||||||||||||||||
325 | src[x] = (src[x] & 0x00ffffff) | (avg << 24); | - | ||||||||||||||||||
326 | } never executed: end of block | 0 | ||||||||||||||||||
327 | } | - | ||||||||||||||||||
328 | } never executed: end of block | 0 | ||||||||||||||||||
329 | } never executed: end of block | 0 | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | funcs->glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); | - | ||||||||||||||||||
332 | if (mask.depth() == 32) {
| 0 | ||||||||||||||||||
333 | GLenum format = GL_RGBA; | - | ||||||||||||||||||
334 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
335 | if (!ctx->contextHandle()->isOpenGLES())
| 0 | ||||||||||||||||||
336 | format = GL_BGRA; never executed: format = 0x80E1; | 0 | ||||||||||||||||||
337 | #endif | - | ||||||||||||||||||
338 | funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, format, GL_UNSIGNED_BYTE, mask.bits()); | - | ||||||||||||||||||
339 | } else { never executed: end of block | 0 | ||||||||||||||||||
340 | // glTexSubImage2D() might cause some garbage to appear in the texture if the mask width is | - | ||||||||||||||||||
341 | // not a multiple of four bytes. The bug appeared on a computer with 32-bit Windows Vista | - | ||||||||||||||||||
342 | // and nVidia GeForce 8500GT. GL_UNPACK_ALIGNMENT is set to four bytes, 'mask' has a | - | ||||||||||||||||||
343 | // multiple of four bytes per line, and most of the glyph shows up correctly in the | - | ||||||||||||||||||
344 | // texture, which makes me think that this is a driver bug. | - | ||||||||||||||||||
345 | // One workaround is to make sure the mask width is a multiple of four bytes, for instance | - | ||||||||||||||||||
346 | // by converting it to a format with four bytes per pixel. Another is to copy one line at a | - | ||||||||||||||||||
347 | // time. | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | if (!ctx->d_ptr->workaround_brokenAlphaTexSubImage_init) {
| 0 | ||||||||||||||||||
350 | // don't know which driver versions exhibit this bug, so be conservative for now | - | ||||||||||||||||||
351 | const QByteArray vendorString(reinterpret_cast<const char*>(funcs->glGetString(GL_VENDOR))); | - | ||||||||||||||||||
352 | ctx->d_ptr->workaround_brokenAlphaTexSubImage = vendorString.indexOf("NVIDIA") >= 0; | - | ||||||||||||||||||
353 | ctx->d_ptr->workaround_brokenAlphaTexSubImage_init = true; | - | ||||||||||||||||||
354 | } never executed: end of block | 0 | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | if (ctx->d_ptr->workaround_brokenAlphaTexSubImage) {
| 0 | ||||||||||||||||||
357 | for (int i = 0; i < maskHeight; ++i)
| 0 | ||||||||||||||||||
358 | funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, maskWidth, 1, GL_ALPHA, GL_UNSIGNED_BYTE, mask.scanLine(i)); never executed: funcs->glTexSubImage2D(0x0DE1, 0, c.x, c.y + i, maskWidth, 1, 0x1906, 0x1401, mask.scanLine(i)); | 0 | ||||||||||||||||||
359 | } else { never executed: end of block | 0 | ||||||||||||||||||
360 | funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits()); | - | ||||||||||||||||||
361 | } never executed: end of block | 0 | ||||||||||||||||||
362 | } | - | ||||||||||||||||||
363 | } | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | int QGLTextureGlyphCache::glyphPadding() const | - | ||||||||||||||||||
366 | { | - | ||||||||||||||||||
367 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
368 | } | - | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | int QGLTextureGlyphCache::maxTextureWidth() const | - | ||||||||||||||||||
371 | { | - | ||||||||||||||||||
372 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
373 | if (ctx == 0)
| 0 | ||||||||||||||||||
374 | return QImageTextureGlyphCache::maxTextureWidth(); never executed: return QImageTextureGlyphCache::maxTextureWidth(); | 0 | ||||||||||||||||||
375 | else | - | ||||||||||||||||||
376 | return ctx->d_ptr->maxTextureSize(); never executed: return ctx->d_ptr->maxTextureSize(); | 0 | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | int QGLTextureGlyphCache::maxTextureHeight() const | - | ||||||||||||||||||
380 | { | - | ||||||||||||||||||
381 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
382 | if (ctx == 0)
| 0 | ||||||||||||||||||
383 | return QImageTextureGlyphCache::maxTextureHeight(); never executed: return QImageTextureGlyphCache::maxTextureHeight(); | 0 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | if (ctx->d_ptr->workaround_brokenTexSubImage)
| 0 | ||||||||||||||||||
386 | return qMin(1024, ctx->d_ptr->maxTextureSize()); never executed: return qMin(1024, ctx->d_ptr->maxTextureSize()); | 0 | ||||||||||||||||||
387 | else | - | ||||||||||||||||||
388 | return ctx->d_ptr->maxTextureSize(); never executed: return ctx->d_ptr->maxTextureSize(); | 0 | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | void QGLTextureGlyphCache::clear() | - | ||||||||||||||||||
392 | { | - | ||||||||||||||||||
393 | m_textureResource->free(); | - | ||||||||||||||||||
394 | m_textureResource = 0; | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | m_w = 0; | - | ||||||||||||||||||
397 | m_h = 0; | - | ||||||||||||||||||
398 | m_cx = 0; | - | ||||||||||||||||||
399 | m_cy = 0; | - | ||||||||||||||||||
400 | m_currentRowHeight = 0; | - | ||||||||||||||||||
401 | coords.clear(); | - | ||||||||||||||||||
402 | } never executed: end of block | 0 | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |