Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
27
29 class Atlas;
30}
32
33namespace QSGRhiAtlasTexture
34{
35
36class Texture;
37class TextureBase;
38class Atlas;
39
40class Manager : public QObject
41{
43
44public:
45 Manager(QSGDefaultRenderContext *rc, const QSize &surfacePixelSize, QSurface *maybeSurface);
46 ~Manager();
47
48 QSGTexture *create(const QImage &image, bool hasAlphaChannel);
50 void invalidate();
51
52private:
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();
72 void remove(TextureBase *t);
73
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:
89 QVector<TextureBase *> m_pending_uploads;
90 friend class TextureBase;
91 friend class TextureBasePrivate;
92
93private:
94 bool m_allocated = false;
95};
96
97class Atlas : public AtlasBase
98{
99public:
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:
121 TextureBase(AtlasBase *atlas, const QRect &textureRect);
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; }
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
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
168
169#endif
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:370
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
\inmodule QtGui
Definition qrhi.h:1731
\inmodule QtGui
Definition qrhi.h:895
Format
Specifies the texture format.
Definition qrhi.h:914
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
AtlasBase(QSGDefaultRenderContext *rc, const QSize &size)
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
Atlas(QSGDefaultRenderContext *rc, const QSize &size)
void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) override
QRhiTexture::Format format() const
Manager(QSGDefaultRenderContext *rc, const QSize &surfacePixelSize, QSurface *maybeSurface)
TextureBase(AtlasBase *atlas, const QRect &textureRect)
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.
\inmodule QtQuick
Definition qsgtexture.h:20
\inmodule QtCore
Definition qsize.h:25
\inmodule QtGui
Definition qsurface.h:21
Combined button and popup list for selecting options.
Definition image.cpp:4
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
QItemEditorFactory * factory
view create()