6#include <QtCore/QVarLengthArray>
7#include <QtCore/QElapsedTimer>
8#include <QtCore/QtMath>
10#include <QtGui/QWindow>
12#include <private/qqmlglobal_p.h>
13#include <private/qsgdefaultrendercontext_p.h>
14#include <private/qsgtexture_p.h>
15#include <private/qsgcompressedtexture_p.h>
16#include <private/qsgcompressedatlastexture_p.h>
37 const int widthHint =
qMax(1, surfacePixelSize.
width());
38 const int heightHint =
qMax(1, surfacePixelSize.
height());
54 qCDebug(QSG_LOG_INFO,
"rhi texture atlas dimensions: %dx%d",
w,
h);
72 while (
i != m_atlases.
end()) {
73 i.value()->invalidate();
74 i.value()->deleteLater();
83 if (
image.width() < m_atlas_size_limit &&
image.height() < m_atlas_size_limit) {
85 m_atlas =
new Atlas(m_rc, m_atlas_size);
87 if (
t && !hasAlphaChannel &&
t->hasAlphaChannel())
96 if (!qsgEnableCompressedAtlas() || !
factory->textureData()->isValid())
99 unsigned int format =
factory->textureData()->glInternalFormat();
105 if (
size.width() < m_atlas_size_limit &&
size.height() < m_atlas_size_limit) {
107 if (
i == m_atlases.
cend()) {
142 qWarning(
"QSGTextureAtlas: Failed to create texture");
155 QRect atlasRect =
t->atlasSubRect();
171 m_atlas_transient_image_threshold =
qt_sg_envInt(
"QSG_ATLAS_TRANSIENT_IMAGE_THRESHOLD", 0);
182 if (
rect.width() > 0 &&
rect.height() > 0) {
217 if (m_debug_overlay) {
223 const int iw =
image.width();
224 const int ih =
image.height();
225 const int bpl =
image.bytesPerLine() / 4;
227 const int tmpBitsSize = tmpBits.
size() * 4;
235 dst[1 + iw] =
src[iw - 1];
244 const quint32 *lastRow =
src + bpl * (ih - 1);
246 memcpy(
dst + 1, lastRow, iw *
sizeof(
quint32));
247 dst[1 + iw] = lastRow[iw - 1];
256 for (
int i = 0;
i < ih; ++
i)
267 for (
int i = 0;
i < ih; ++
i)
279 int ey = sy +
r.height() - 2;
280 entries.
reserve(4 + (ey - sy));
281 for (
int y = sy;
y < ey; ++
y) {
299 const QSize textureSize =
t->textureSize();
300 if (textureSize.
width() > m_atlas_transient_image_threshold || textureSize.
height() > m_atlas_transient_image_threshold)
303 qCDebug(QSG_LOG_TIME_TEXTURE,
"atlastexture upload enqueued in: %lldms (%dx%d)",
305 t->textureSize().width(),
306 t->textureSize().height());
311 , m_allocated_rect(textureRect)
351 , m_has_alpha(
image.hasAlphaChannel())
356 m_texture_coords_rect =
QRectF(nopad.
x() /
w,
364 if (m_nonatlas_texture)
365 delete m_nonatlas_texture;
370 if (!m_nonatlas_texture) {
373 m_nonatlas_texture->
setImage(m_image);
382 if (extractTex->
create()) {
383 bool ownResUpd =
false;
390 desc.setSourceTopLeft(
r.topLeft());
391 desc.setPixelSize(
r.size());
406 return m_nonatlas_texture;
413#include "moc_qsgrhiatlastexture_p.cpp"
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
const_iterator cend() const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
@ Format_RGBA8888_Premultiplied
void deleteLater()
\threadsafe
The QPainter class performs low-level painting on widgets and other paint devices.
@ CompositionMode_SourceAtop
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates)
Sometimes committing resource updates is necessary or just more convenient without starting a render ...
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
Enqueues uploading the image data for one or more mip levels in one or more layers of the texture tex...
void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc=QRhiTextureCopyDescription())
Enqueues a texture-to-texture copy operation from src into dst as described by desc.
void setDestinationTopLeft(const QPoint &p)
Sets the destination top-left position p.
void setSourceSize(const QSize &size)
Sets the source size in pixels.
virtual bool create()=0
Creates the corresponding native graphics resources.
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags={}) const
int resourceLimit(ResourceLimit limit) const
bool isRecordingFrame() const
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
QRect allocate(const QSize &size)
bool deallocate(const QRect &rect)
static FormatInfo formatInfo(quint32 glTextureFormat)
QRhiCommandBuffer * currentFrameCommandBuffer() const
void setTextureSize(const QSize &size)
void setImage(const QImage &image)
void setTexture(QRhiTexture *texture)
void setOwnsTexture(bool owns)
void setHasAlphaChannel(bool alpha)
AtlasBase(QSGDefaultRenderContext *rc, const QSize &size)
QSGAreaAllocator m_allocator
QRhiTexture * texture() const
void commitTextureOperations(QRhiResourceUpdateBatch *resourceUpdates)
virtual void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates)=0
void remove(TextureBase *t)
virtual bool generateTexture()=0
QVector< TextureBase * > m_pending_uploads
QSGDefaultRenderContext * renderContext() const
Texture * create(const QImage &image)
Atlas(QSGDefaultRenderContext *rc, const QSize &size)
bool generateTexture() override
void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) override
Manager(QSGDefaultRenderContext *rc, const QSize &surfacePixelSize, QSurface *maybeSurface)
QSGTexture * create(const QImage &image, bool hasAlphaChannel)
TextureBase(AtlasBase *atlas, const QRect &textureRect)
qint64 comparisonKey() const override
Returns a key suitable for comparing textures.
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...
Texture(Atlas *atlas, const QRect &textureRect, const QImage &image)
QRect atlasSubRectWithoutPadding() const
QSGTexture * removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const override
This function returns a copy of the current texture which is removed from its atlas.
QRect atlasSubRect() const
void setHasAlphaChannel(bool alpha)
const QImage & image() const
QSGTexture::Filtering mipmapFiltering() const
Returns whether mipmapping should be used when sampling from this texture.
void setFiltering(Filtering filter)
Sets the sampling mode to filter.
QSGTexture::Filtering filtering() const
Returns the sampling mode to be used for this texture.
void setMipmapFiltering(Filtering filter)
Sets the mipmap sampling mode to filter.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
SurfaceClass surfaceClass() const
Returns the surface class of this surface.
QByteArrayView getDataView(int level=0, int face=0) const
constexpr size_type size() const noexcept
const_iterator cbegin() const noexcept
const_iterator cend() const noexcept
void reserve(qsizetype sz)
Combined button and popup list for selecting options.
#define qCDebug(category,...)
constexpr quint32 qNextPowerOfTwo(quint32 v)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
#define DEFINE_BOOL_CONFIG_OPTION(name, var)
int qt_sg_envInt(const char *name, int defaultValue)
QT_BEGIN_NAMESPACE int qt_sg_envInt(const char *name, int defaultValue)
static QElapsedTimer qsg_renderer_timer
QVideoFrameFormat::PixelFormat fmt
QItemEditorFactory * factory