| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QTEXTUREGLYPHCACHE_GL_P_H
|
|---|
| 43 | #define QTEXTUREGLYPHCACHE_GL_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 50 | // of the QLibrary class. This header file may change from
|
|---|
| 51 | // version to version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include <private/qtextureglyphcache_p.h>
|
|---|
| 57 | #include <private/qgl_p.h>
|
|---|
| 58 | #include <qglshaderprogram.h>
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | QT_BEGIN_NAMESPACE
|
|---|
| 62 |
|
|---|
| 63 | class QGL2PaintEngineExPrivate;
|
|---|
| 64 |
|
|---|
| 65 | class Q_OPENGL_EXPORT QGLTextureGlyphCache : public QObject, public QImageTextureGlyphCache
|
|---|
| 66 | {
|
|---|
| 67 | Q_OBJECT
|
|---|
| 68 | public:
|
|---|
| 69 | QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix);
|
|---|
| 70 | ~QGLTextureGlyphCache();
|
|---|
| 71 |
|
|---|
| 72 | virtual void createTextureData(int width, int height);
|
|---|
| 73 | virtual void resizeTextureData(int width, int height);
|
|---|
| 74 | virtual void fillTexture(const Coord &c, glyph_t glyph);
|
|---|
| 75 | virtual int glyphPadding() const;
|
|---|
| 76 | virtual int maxTextureWidth() const;
|
|---|
| 77 | virtual int maxTextureHeight() const;
|
|---|
| 78 |
|
|---|
| 79 | inline GLuint texture() const { return m_texture; }
|
|---|
| 80 |
|
|---|
| 81 | inline int width() const { return m_width; }
|
|---|
| 82 | inline int height() const { return m_height; }
|
|---|
| 83 |
|
|---|
| 84 | inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; }
|
|---|
| 85 |
|
|---|
| 86 | enum FilterMode {
|
|---|
| 87 | Nearest,
|
|---|
| 88 | Linear
|
|---|
| 89 | };
|
|---|
| 90 | FilterMode filterMode() const { return m_filterMode; }
|
|---|
| 91 | void setFilterMode(FilterMode m) { m_filterMode = m; }
|
|---|
| 92 |
|
|---|
| 93 | void setContext(QGLContext *context);
|
|---|
| 94 | QGLContext *context() const { return ctx; }
|
|---|
| 95 |
|
|---|
| 96 | public Q_SLOTS:
|
|---|
| 97 | void contextDestroyed(const QGLContext *context) {
|
|---|
| 98 | if (context == ctx) {
|
|---|
| 99 | const QGLContext *nextCtx = qt_gl_transfer_context(ctx);
|
|---|
| 100 | if (!nextCtx) {
|
|---|
| 101 | // the context may not be current, so we cannot directly
|
|---|
| 102 | // destroy the fbo and texture here, but since the context
|
|---|
| 103 | // is about to be destroyed, the GL server will do the
|
|---|
| 104 | // clean up for us anyway. We reset everything, so that the
|
|---|
| 105 | // glyph cache object can be reused later by setting a new
|
|---|
| 106 | // context on it.
|
|---|
| 107 | m_fbo = 0;
|
|---|
| 108 | m_texture = 0;
|
|---|
| 109 | ctx = 0;
|
|---|
| 110 | m_width = 0;
|
|---|
| 111 | m_height = 0;
|
|---|
| 112 | m_w = 0;
|
|---|
| 113 | m_h = 0;
|
|---|
| 114 | m_cx = 0;
|
|---|
| 115 | m_cy = 0;
|
|---|
| 116 | m_currentRowHeight = 0;
|
|---|
| 117 | coords.clear();
|
|---|
| 118 | } else {
|
|---|
| 119 | // since the context holding the texture is shared, and
|
|---|
| 120 | // about to be destroyed, we have to transfer ownership
|
|---|
| 121 | // of the texture to one of the share contexts
|
|---|
| 122 | ctx = const_cast<QGLContext *>(nextCtx);
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | void clear();
|
|---|
| 128 |
|
|---|
| 129 | private:
|
|---|
| 130 | QGLContext *ctx;
|
|---|
| 131 |
|
|---|
| 132 | QGL2PaintEngineExPrivate *pex;
|
|---|
| 133 |
|
|---|
| 134 | GLuint m_texture;
|
|---|
| 135 | GLuint m_fbo;
|
|---|
| 136 |
|
|---|
| 137 | int m_width;
|
|---|
| 138 | int m_height;
|
|---|
| 139 |
|
|---|
| 140 | QGLShaderProgram *m_program;
|
|---|
| 141 |
|
|---|
| 142 | FilterMode m_filterMode;
|
|---|
| 143 | };
|
|---|
| 144 |
|
|---|
| 145 | QT_END_NAMESPACE
|
|---|
| 146 |
|
|---|
| 147 | #endif
|
|---|
| 148 |
|
|---|