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