22bool QSGOpaqueTextureMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *)
25 QByteArray *buf = state.uniformData();
26 const int matrixCount = qMin(state.projectionMatrixCount(), newMaterial->viewCount());
28 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
29 if (state.isMatrixDirty()) {
30 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
31 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
39void QSGOpaqueTextureMaterialRhiShader::updateSampledImage(RenderState &state,
int binding, QSGTexture **texture,
40 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
46 Q_UNUSED(oldMaterial);
48 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
49 QSGOpaqueTextureMaterial *tx =
static_cast<QSGOpaqueTextureMaterial *>(newMaterial);
50 QSGTexture *t = tx->texture();
56 t->setFiltering(tx->filtering());
57 t->setMipmapFiltering(tx->mipmapFiltering());
58 t->setAnisotropyLevel(tx->anisotropyLevel());
60 t->setHorizontalWrapMode(tx->horizontalWrapMode());
61 t->setVerticalWrapMode(tx->verticalWrapMode());
62 if (!state.rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat)) {
63 QSize size = t->textureSize();
64 const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
66 t->setHorizontalWrapMode(QSGTexture::ClampToEdge);
67 t->setVerticalWrapMode(QSGTexture::ClampToEdge);
68 t->setMipmapFiltering(QSGTexture::None);
72 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
122QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial()
124 , m_filtering(QSGTexture::Nearest)
125 , m_mipmap_filtering(QSGTexture::None)
126 , m_horizontal_wrap(QSGTexture::ClampToEdge)
127 , m_vertical_wrap(QSGTexture::ClampToEdge)
128 , m_anisotropy_level(QSGTexture::AnisotropyNone)
275int QSGOpaqueTextureMaterial::compare(
const QSGMaterial *o)
const
277 Q_ASSERT(o && type() == o->type());
278 const QSGOpaqueTextureMaterial *other =
static_cast<
const QSGOpaqueTextureMaterial *>(o);
280 Q_ASSERT(other->texture());
281 const qint64 diff = m_texture->comparisonKey() - other->texture()->comparisonKey();
283 return diff < 0 ? -1 : 1;
284 return int(m_filtering) -
int(other->m_filtering);
352 bool changed =
false;
353 QByteArray *buf = state.uniformData();
354 const int shaderMatrixCount = newMaterial->viewCount();
356 if (state.isOpacityDirty()) {
357 const float opacity = state.opacity();
358 memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4);
362 changed |= QSGOpaqueTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGTextureMaterialRhiShader(int viewCount)
static QT_BEGIN_NAMESPACE bool isPowerOfTwo(int x)