Qt 4.8
qtextureglyphcache_gl_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 #include <qglframebufferobject.h>
60 
61 // #define QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
62 
64 
66 
68 {
70  : m_fbo(0)
71  , m_width(0)
72  , m_height(0)
73  {
76 
77 #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
78  qDebug(" -> QGLGlyphTexture() %p for context %p.", this, ctx);
79 #endif
80  }
81 
84 #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
85  qDebug("~QGLGlyphTexture() %p for context %p.", this, ctx);
86 #endif
87  // At this point, the context group is made current, so it's safe to
88  // release resources without a makeCurrent() call
89  if (ctx) {
90  if (m_fbo)
92  if (m_width || m_height)
93  glDeleteTextures(1, &m_texture);
94  }
95  }
96 
97  GLuint m_texture;
98  GLuint m_fbo;
99  int m_width;
100  int m_height;
101 };
102 
104 {
105 public:
108 
109  virtual void createTextureData(int width, int height);
110  virtual void resizeTextureData(int width, int height);
111  virtual void fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition);
112  virtual int glyphPadding() const;
113  virtual int maxTextureWidth() const;
114  virtual int maxTextureHeight() const;
115 
116  inline GLuint texture() const {
117  QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this);
118  QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx);
119  return glyphTexture ? glyphTexture->m_texture : 0;
120  }
121 
122  inline int width() const {
123  QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this);
124  QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx);
125  return glyphTexture ? glyphTexture->m_width : 0;
126  }
127  inline int height() const {
128  QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this);
129  QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx);
130  return glyphTexture ? glyphTexture->m_height : 0;
131  }
132 
133  inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; }
134 
135  void setContext(const QGLContext *context);
136  inline const QGLContext *context() const { return ctx; }
137 
138  inline int serialNumber() const { return m_serialNumber; }
139 
140  enum FilterMode {
142  Linear
143  };
144  FilterMode filterMode() const { return m_filterMode; }
145  void setFilterMode(FilterMode m) { m_filterMode = m; }
146 
147  void clear();
148 
149  void contextDeleted(const QGLContext *context) {
150  if (ctx == context)
151  ctx = 0;
152  }
153  void freeResource(void *) { ctx = 0; }
154 
155 private:
157 
158  const QGLContext *ctx;
162 
163  GLfloat m_vertexCoordinateArray[8];
164  GLfloat m_textureCoordinateArray[8];
165 
167 };
168 
170 
171 #endif
172 
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise r...
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
T * value(const QGLContext *context)
Definition: qgl_p.h:775
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_OPENGL_EXPORT
Definition: qglobal.h:1455
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
void setFilterMode(FilterMode m)
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
const QGLContext * context() const
Q_CORE_EXPORT void qDebug(const char *,...)
FilterMode filterMode() const
QGLContextGroupResource< QGLGlyphTexture > m_textureResource
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define glDeleteFramebuffers
#define glGenFramebuffers
void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p)
QGLGlyphTexture(const QGLContext *ctx)
QGLShaderProgram * m_blitProgram
#define ctx
Definition: qgl.cpp:6094
void contextDeleted(const QGLContext *context)
QGL2PaintEngineExPrivate * pex
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
unsigned int glyph_t
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
uint workaround_brokenFBOReadBack
Definition: qgl_p.h:432