Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qopengltextureglyphcache_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QOPENGLTEXTUREGLYPHCACHE_P_H
6#define QOPENGLTEXTUREGLYPHCACHE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtOpenGL/qtopenglglobal.h>
20#include <private/qtextureglyphcache_p.h>
21#include <private/qopenglcontext_p.h>
22#include <qopenglshaderprogram.h>
23#include <qopenglfunctions.h>
24#include <qopenglbuffer.h>
25#include <qopenglvertexarrayobject.h>
26
27// #define QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
28
30
32
34{
35public:
36 explicit QOpenGLGlyphTexture(QOpenGLContext *ctx)
38 , m_width(0)
39 , m_height(0)
40 {
41 if (!ctx->d_func()->workaround_brokenFBOReadBack)
42 QOpenGLFunctions(ctx).glGenFramebuffers(1, &m_fbo);
43
44#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
45 qDebug(" -> QOpenGLGlyphTexture() %p for context %p.", this, ctx);
46#endif
47 }
48
49 void freeResource(QOpenGLContext *context) override
50 {
51 QOpenGLContext *ctx = context;
52#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
53 qDebug("~QOpenGLGlyphTexture() %p for context %p.", this, ctx);
54#endif
55 if (!ctx->d_func()->workaround_brokenFBOReadBack)
56 ctx->functions()->glDeleteFramebuffers(1, &m_fbo);
57 if (m_width || m_height)
58 ctx->functions()->glDeleteTextures(1, &m_texture);
59 }
60
62 {
63 m_texture = 0;
64 m_fbo = 0;
65 m_width = 0;
66 m_height = 0;
67 }
68
73};
74
75class Q_OPENGL_EXPORT QOpenGLTextureGlyphCache : public QImageTextureGlyphCache
76{
77public:
78 QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix, const QColor &color = QColor());
79 ~QOpenGLTextureGlyphCache();
80
81 virtual void createTextureData(int width, int height) override;
82 virtual void resizeTextureData(int width, int height) override;
83 virtual void fillTexture(const Coord &c,
84 glyph_t glyph,
85 const QFixedPoint &subPixelPosition) override;
86 virtual int glyphPadding() const override;
87 virtual int maxTextureWidth() const override;
88 virtual int maxTextureHeight() const override;
89
90 inline GLuint texture() const {
91 QOpenGLTextureGlyphCache *that = const_cast<QOpenGLTextureGlyphCache *>(this);
92 QOpenGLGlyphTexture *glyphTexture = that->m_textureResource;
93 return glyphTexture ? glyphTexture->m_texture : 0;
94 }
95
96 inline int width() const {
97 QOpenGLTextureGlyphCache *that = const_cast<QOpenGLTextureGlyphCache *>(this);
98 QOpenGLGlyphTexture *glyphTexture = that->m_textureResource;
99 return glyphTexture ? glyphTexture->m_width : 0;
100 }
101 inline int height() const {
102 QOpenGLTextureGlyphCache *that = const_cast<QOpenGLTextureGlyphCache *>(this);
103 QOpenGLGlyphTexture *glyphTexture = that->m_textureResource;
104 return glyphTexture ? glyphTexture->m_height : 0;
105 }
106
107 inline void setPaintEnginePrivate(QOpenGL2PaintEngineExPrivate *p) { pex = p; }
108
109 inline const QOpenGLContextGroup *contextGroup() const { return m_textureResource ? m_textureResource->group() : nullptr; }
110
111 inline int serialNumber() const { return m_serialNumber; }
112
113 enum FilterMode {
114 Nearest,
115 Linear
116 };
117 FilterMode filterMode() const { return m_filterMode; }
118 void setFilterMode(FilterMode m) { m_filterMode = m; }
119
120 void clear();
121
122 QOpenGL2PaintEngineExPrivate *paintEnginePrivate() const
123 {
124 return pex;
125 }
126
127private:
128 void setupVertexAttribs();
129
130 QOpenGLGlyphTexture *m_textureResource;
131
132 QOpenGL2PaintEngineExPrivate *pex;
133 QOpenGLShaderProgram *m_blitProgram;
134 FilterMode m_filterMode;
135
136 GLfloat m_vertexCoordinateArray[8];
137 GLfloat m_textureCoordinateArray[8];
138
139 int m_serialNumber;
140
141 QOpenGLBuffer m_buffer;
142 QOpenGLVertexArrayObject m_vao;
143};
144
145QT_END_NAMESPACE
146
147#endif // QOPENGLTEXTUREGLYPHCACHE_P_H
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
void freeResource(QOpenGLContext *context) override
QOpenGLGlyphTexture(QOpenGLContext *ctx)
Combined button and popup list for selecting options.
static void load_glyph_image_region_to_texture(QOpenGLContext *ctx, const QImage &srcImg, int x, int y, int w, int h, GLuint texture, int tx, int ty)
static void load_glyph_image_to_texture(QOpenGLContext *ctx, QImage &img, GLuint texture, int tx, int ty)
static QT_BEGIN_NAMESPACE int next_qopengltextureglyphcache_serial_number()
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:14
constexpr int qRed(QRgb rgb)
Definition qrgb.h:19
constexpr int qGreen(QRgb rgb)
Definition qrgb.h:22
constexpr QRgb qRgba(int r, int g, int b, int a)
Definition qrgb.h:34
constexpr int qBlue(QRgb rgb)
Definition qrgb.h:25
constexpr int qAlpha(QRgb rgb)
Definition qrgb.h:28