Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsgcompressedatlastexture.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 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
#
include
"qsgcompressedatlastexture_p.h"
6
7
#
include
<
QtCore
/
QVarLengthArray
>
8
#
include
<
QtCore
/
QElapsedTimer
>
9
#
include
<
QtCore
/
QtMath
>
10
11
#
include
<
QtGui
/
QGuiApplication
>
12
#
include
<
QtGui
/
QScreen
>
13
#
include
<
QtGui
/
QSurface
>
14
#
include
<
QtGui
/
QWindow
>
15
#
include
<
QDebug
>
16
17
#
include
<
private
/
qqmlglobal_p
.
h
>
18
#
include
<
private
/
qquickprofiler_p
.
h
>
19
#
include
<
private
/
qsgtexture_p
.
h
>
20
#
include
<
private
/
qsgcompressedtexture_p
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
namespace
QSGCompressedAtlasTexture
25
{
26
27
Atlas
::
Atlas
(QSGDefaultRenderContext *rc,
const
QSize &size, uint format)
28
:
QSGRhiAtlasTexture
::
AtlasBase
(
rc
,
size
),
m_format
(
format
)
29
{
30
}
31
32
Atlas
::~
Atlas
()
33
{
34
}
35
36
Texture
*
Atlas
::
create
(QByteArrayView data,
const
QSize &size)
37
{
38
// Align reservation to 16x16, >= any compressed block size
39
QSize paddedSize(((size.width() + 15) / 16) * 16, ((size.height() + 15) / 16) * 16);
40
// No need to lock, as manager already locked it.
41
QRect rect = m_allocator.allocate(paddedSize);
42
if
(rect.width() > 0 && rect.height() > 0) {
43
Texture
*t =
new
Texture
(
this
, rect, data, size);
44
m_pending_uploads << t;
45
return
t;
46
}
47
return
nullptr
;
48
}
49
50
bool
Atlas
::
generateTexture
()
51
{
52
QSGCompressedTexture::FormatInfo fmt = QSGCompressedTexture::formatInfo(m_format);
53
QRhiTexture::Flags flags(QRhiTexture::UsedAsTransferSource | QRhiTexture::UsedAsCompressedAtlas);
54
flags.setFlag(QRhiTexture::sRGB, fmt.isSRGB);
55
m_texture = m_rhi->newTexture(fmt.rhiFormat, m_size, 1, flags);
56
if
(!m_texture)
57
return
false
;
58
59
if
(!m_texture->create()) {
60
delete
m_texture;
61
m_texture =
nullptr
;
62
return
false
;
63
}
64
65
qCDebug(QSG_LOG_TEXTUREIO,
"Created compressed atlas of size %dx%d for format 0x%x (rhi: %d)"
,
66
m_size.width(), m_size.height(), m_format, fmt.rhiFormat);
67
68
return
true
;
69
}
70
71
void
Atlas
::
enqueueTextureUpload
(QSGRhiAtlasTexture::TextureBase *t, QRhiResourceUpdateBatch *rcub)
72
{
73
Texture
*texture =
static_cast
<
Texture
*>(t);
74
75
const
QRect &r = texture->atlasSubRect();
76
77
QRhiTextureSubresourceUploadDescription subresDesc(texture->data().constData(),
78
texture
->
sizeInBytes
(
)
);
79
subresDesc.setSourceSize(texture->textureSize());
80
subresDesc.setDestinationTopLeft(r.topLeft());
81
82
QRhiTextureUploadDescription desc(QRhiTextureUploadEntry(0, 0, subresDesc));
83
rcub->uploadTexture(m_texture, desc);
84
85
qCDebug(QSG_LOG_TEXTUREIO,
"compressed atlastexture upload, size %dx%d format 0x%x"
,
86
t->textureSize().width(), t->textureSize().height(), m_format);
87
}
88
89
Texture
::Texture(
Atlas
*atlas,
const
QRect &textureRect, QByteArrayView data,
const
QSize &size)
90
: QSGRhiAtlasTexture::TextureBase(atlas, textureRect),
91
m_nonatlas_texture(
nullptr
),
92
m_data(data.toByteArray()),
93
m_size(size)
94
{
95
float
w = atlas->size().width();
96
float
h = atlas->size().height();
97
const
QRect &r = atlasSubRect();
98
// offset by half-pixel to prevent bleeding when scaling
99
m_texture_coords_rect = QRectF((r.x() + .5) / w,
100
(r.y() + .5) / h,
101
(size.width() - 1.) / w,
102
(size.height() - 1.) / h);
103
}
104
105
Texture
::~
Texture
()
106
{
107
delete
m_nonatlas_texture;
108
}
109
110
bool
Texture
::
hasAlphaChannel
()
const
111
{
112
return
!QSGCompressedTexture::formatIsOpaque(
static_cast
<Atlas*>(m_atlas)->format());
113
}
114
115
QSGTexture
*
Texture
::
removedFromAtlas
(QRhiResourceUpdateBatch *)
const
116
{
117
if
(m_nonatlas_texture) {
118
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
119
m_nonatlas_texture->setFiltering(filtering());
120
return
m_nonatlas_texture;
121
}
122
123
if
(!m_data.isEmpty()) {
124
QTextureFileData texData;
125
texData.setData(m_data);
126
texData.setSize(m_size);
127
texData.setGLInternalFormat(
static_cast
<Atlas*>(m_atlas)->format());
128
texData.setDataLength(m_data.size());
129
texData.setDataOffset(0);
130
m_nonatlas_texture =
new
QSGCompressedTexture(texData);
131
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
132
m_nonatlas_texture->setFiltering(filtering());
133
}
134
135
return
m_nonatlas_texture;
136
}
137
138
}
139
140
QT_END_NAMESPACE
141
142
#
include
"moc_qsgcompressedatlastexture_p.cpp"
QSGCompressedAtlasTexture::Atlas
Definition
qsgcompressedatlastexture_p.h:34
QSGCompressedAtlasTexture::Atlas::generateTexture
bool generateTexture() override
Definition
qsgcompressedatlastexture.cpp:50
QSGCompressedAtlasTexture::Atlas::create
Texture * create(QByteArrayView data, const QSize &size)
Definition
qsgcompressedatlastexture.cpp:36
QSGCompressedAtlasTexture::Atlas::~Atlas
~Atlas()
Definition
qsgcompressedatlastexture.cpp:32
QSGCompressedAtlasTexture::Atlas::enqueueTextureUpload
void enqueueTextureUpload(QSGRhiAtlasTexture::TextureBase *t, QRhiResourceUpdateBatch *rcub) override
Definition
qsgcompressedatlastexture.cpp:71
QSGCompressedAtlasTexture::Atlas::Atlas
Atlas(QSGDefaultRenderContext *rc, const QSize &size, uint format)
Definition
qsgcompressedatlastexture.cpp:27
QSGCompressedAtlasTexture::Texture
Definition
qsgcompressedatlastexture_p.h:52
QSGCompressedAtlasTexture::Texture::hasAlphaChannel
bool hasAlphaChannel() const override
Returns true if the texture data contains an alpha channel.
Definition
qsgcompressedatlastexture.cpp:110
QSGCompressedAtlasTexture::Texture::removedFromAtlas
QSGTexture * removedFromAtlas(QRhiResourceUpdateBatch *) const override
This function returns a copy of the current texture which is removed from its atlas.
Definition
qsgcompressedatlastexture.cpp:115
QSGCompressedAtlasTexture::Texture::~Texture
~Texture()
Definition
qsgcompressedatlastexture.cpp:105
QSGCompressedAtlasTexture::Texture::sizeInBytes
int sizeInBytes() const
Definition
qsgcompressedatlastexture_p.h:67
QSGCompressedAtlasTexture
Definition
qsgcompressedatlastexture.cpp:25
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quick
scenegraph
compressedtexture
qsgcompressedatlastexture.cpp
Generated on
for Qt by
1.18.0