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
qsgrhiatlastexture_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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#ifndef QSGRHIATLASTEXTURE_P_H
5#define QSGRHIATLASTEXTURE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QSize>
19#include <QtQuick/private/qsgplaintexture_p.h>
20#include <QtQuick/private/qsgareaallocator_p.h>
21#include <QtGui/QSurface>
22#include <rhi/qrhi.h>
23
25
26class QSGDefaultRenderContext;
27
29 class Atlas;
30}
31class QSGCompressedTextureFactory;
32
33namespace QSGRhiAtlasTexture
34{
35
36class Texture;
37class TextureBase;
38class Atlas;
39
40class Manager : public QObject
41{
43
44public:
46 ~Manager();
47
48 QSGTexture *create(const QImage &image, bool hasAlphaChannel);
49 QSGTexture *create(const QSGCompressedTextureFactory *factory);
50 void invalidate();
51
52private:
53 QSGDefaultRenderContext *m_rc;
54 QRhi *m_rhi;
55 Atlas *m_atlas = nullptr;
56 // set of atlases for different compressed formats
57 QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*> m_atlases;
58
59 QSize m_atlas_size;
60 int m_atlas_size_limit;
61};
62
63class AtlasBase : public QObject
64{
66public:
68 ~AtlasBase();
69
70 void invalidate();
71 void commitTextureOperations(QRhiResourceUpdateBatch *resourceUpdates);
72 void remove(TextureBase *t);
73
74 QSGDefaultRenderContext *renderContext() const { return m_rc; }
75 QRhi *rhi() const { return m_rhi; }
76 QRhiTexture *texture() const { return m_texture; }
77 QSize size() const { return m_size; }
78
79protected:
80 virtual bool generateTexture() = 0;
81 virtual void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) = 0;
82
83protected:
84 QSGDefaultRenderContext *m_rc;
85 QRhi *m_rhi;
87 QRhiTexture *m_texture = nullptr;
90 friend class TextureBase;
91 friend class TextureBasePrivate;
92
93private:
94 bool m_allocated = false;
95};
96
97class Atlas : public AtlasBase
98{
99public:
100 Atlas(QSGDefaultRenderContext *rc, const QSize &size);
101 ~Atlas();
102
103 bool generateTexture() override;
104 void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) override;
105
106 Texture *create(const QImage &image);
107
108 QRhiTexture::Format format() const { return m_format; }
109
110private:
111 QRhiTexture::Format m_format;
112 int m_atlas_transient_image_threshold = 0;
113
114 uint m_debug_overlay : 1;
115};
116
118{
120public:
122 ~TextureBase();
123
124 qint64 comparisonKey() const override;
125 QRhiTexture *rhiTexture() const override;
126 void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
127
128 bool isAtlasTexture() const override { return true; }
129 QRect atlasSubRect() const { return m_allocated_rect; }
130
131protected:
134};
135
136class Texture : public TextureBase
137{
139public:
140 Texture(Atlas *atlas, const QRect &textureRect, const QImage &image);
141 ~Texture();
142
143 QSize textureSize() const override { return atlasSubRectWithoutPadding().size(); }
144 void setHasAlphaChannel(bool alpha) { m_has_alpha = alpha; }
145 bool hasAlphaChannel() const override { return m_has_alpha; }
146 bool hasMipmaps() const override { return false; }
147
148 QRectF normalizedTextureSubRect() const override { return m_texture_coords_rect; }
149
150 QRect atlasSubRect() const { return m_allocated_rect; }
151 QRect atlasSubRectWithoutPadding() const { return m_allocated_rect.adjusted(1, 1, -1, -1); }
152
153 QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const override;
154
155 void releaseImage() { m_image = QImage(); }
156 const QImage &image() const { return m_image; }
157
158private:
159 QRectF m_texture_coords_rect;
160 QImage m_image;
161 mutable QSGPlainTexture *m_nonatlas_texture = nullptr;
162 bool m_has_alpha;
163};
164
165}
166
167QT_END_NAMESPACE
168
169#endif
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:744
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:661
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:721
void commitTextureOperations(QRhiResourceUpdateBatch *resourceUpdates)
virtual void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates)=0
QSGDefaultRenderContext * m_rc
virtual bool generateTexture()=0
QVector< TextureBase * > m_pending_uploads
QSGDefaultRenderContext * renderContext() const
Texture * create(const QImage &image)
Atlas(QSGDefaultRenderContext *rc, const QSize &size)
void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiTexture::Format format() const
QSGTexture * create(const QSGCompressedTextureFactory *factory)
QSGTexture * create(const QImage &image, bool hasAlphaChannel)
qint64 comparisonKey() const override
Returns a key suitable for comparing textures.
bool isAtlasTexture() const override
Returns whether this texture is part of an atlas or not.
QRhiTexture * rhiTexture() const override
void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override
Call this function to enqueue image upload operations to resourceUpdates, in case there are any pendi...
bool hasAlphaChannel() const override
Returns true if the texture data contains an alpha channel.
QRectF normalizedTextureSubRect() const override
Returns the rectangle inside textureSize() that this texture represents in normalized coordinates.
QSGTexture * removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const override
This function returns a copy of the current texture which is removed from its atlas.
QSize textureSize() const override
Returns the size of the texture in pixels.
bool hasMipmaps() const override
Returns true if the texture data contains mipmap levels.
QT_BEGIN_NAMESPACE int qt_sg_envInt(const char *name, int defaultValue)
static QElapsedTimer qsg_renderer_timer
DEFINE_BOOL_CONFIG_OPTION(forceDiskCache, QML_FORCE_DISK_CACHE)