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
qopengltexturecache_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
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14// Qt-Security score:significant reason:default
15
16#ifndef QOPENGLTEXTURECACHE_P_H
17#define QOPENGLTEXTURECACHE_P_H
18
19#include <QtOpenGL/qtopenglglobal.h>
20#include <QHash>
21#include <QObject>
22#include <QCache>
23#include <private/qopenglcontext_p.h>
24#include <private/qopengltextureuploader_p.h>
25#include <QtCore/qmutex.h>
26
27QT_BEGIN_NAMESPACE
28
29class QOpenGLCachedTexture;
30
31class Q_OPENGL_EXPORT QOpenGLTextureCache : public QOpenGLSharedResource
32{
33public:
34 static QOpenGLTextureCache *cacheForContext(QOpenGLContext *context);
35
36 QOpenGLTextureCache(QOpenGLContext *);
37 ~QOpenGLTextureCache();
38
39 enum class BindResultFlag : quint8 {
40 NewTexture = 0x01
41 };
42 Q_DECLARE_FLAGS(BindResultFlags, BindResultFlag)
43
44 struct BindResult {
45 GLuint id;
46 BindResultFlags flags;
47 };
48
49 BindResult bindTexture(QOpenGLContext *context, const QPixmap &pixmap,
50 QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption);
51 BindResult bindTexture(QOpenGLContext *context, const QImage &image,
52 QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption);
53
54 void invalidate(qint64 key);
55
56 void invalidateResource() override;
57 void freeResource(QOpenGLContext *ctx) override;
58
59private:
60 BindResult bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options);
61
62 QMutex m_mutex;
63 QCache<quint64, QOpenGLCachedTexture> m_cache;
64};
65
66Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLTextureCache::BindResultFlags)
67
68class QOpenGLCachedTexture
69{
70public:
71 QOpenGLCachedTexture(GLuint id, QOpenGLTextureUploader::BindOptions options, QOpenGLContext *context);
72 ~QOpenGLCachedTexture() { m_resource->free(); }
73
74 GLuint id() const { return m_resource->id(); }
75 QOpenGLTextureUploader::BindOptions options() const { return m_options; }
76
77private:
78 QOpenGLSharedResourceGuard *m_resource;
79 QOpenGLTextureUploader::BindOptions m_options;
80};
81
82QT_END_NAMESPACE
83
84#endif
static void cleanupTexturesForPixmapData(QPlatformPixmap *pmd)
QOpenGLTextureCache * cacheForContext(QOpenGLContext *context)
static void cleanupTexturesForCacheKey(qint64 key)
Combined button and popup list for selecting options.
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_exit)
static void freeTexture(QOpenGLFunctions *funcs, GLuint id)