Commit f3b57a59 authored by Laszlo Agocs's avatar Laszlo Agocs

d3d: Fix mipmap loading for compressed textures

parent 64509cc5
......@@ -167,12 +167,13 @@ void Window::customInit()
QSize size;
int mipCount = 0;
d.compressedData = loadBC1(QLatin1String(":/qt.dds"), &size, &mipCount);
d.compressedData = loadBC1(QLatin1String(":/qt256_bc1_9mips.dds"), &size, &mipCount);
qDebug() << d.compressedData.count() << size << mipCount << m_r->mipLevelsForSize(size);
d.tex = m_r->newTexture(QRhiTexture::BC1, size, 0);
d.tex = m_r->newTexture(QRhiTexture::BC1, size, QRhiTexture::MipMapped);
d.tex->build();
d.sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
d.sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::Linear,
QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
d.sampler->build();
......@@ -264,9 +265,13 @@ void Window::customRender()
u->updateDynamicBuffer(d.ubuf, 64, 4, &flip);
}
if (!d.compressedData.isEmpty()) {
QRhiTextureUploadDescription::Layer::MipLevel image(d.compressedData[0]);
QRhiTextureUploadDescription desc;
desc.layers.append({ { image } });
QRhiTextureUploadDescription::Layer layer;
for (int i = 0; i < d.compressedData.count(); ++i) {
QRhiTextureUploadDescription::Layer::MipLevel image(d.compressedData[i]);
layer.mipImages.append(image);
}
desc.layers.append(layer);
u->uploadTexture(d.tex, desc);
d.compressedData.clear();
}
......
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>qt.dds</file>
<file alias="qt256_bc1_9mips.dds">../shared/qt256_bc1_9mips.dds</file>
<file alias="texture.vert.qsb">../shared/texture.vert.qsb</file>
<file alias="texture.frag.qsb">../shared/texture.frag.qsb</file>
</qresource>
......
......@@ -335,8 +335,8 @@ int QRhi::mipLevelsForSize(const QSize &size) const
QSize QRhi::sizeForMipLevel(int mipLevel, const QSize &baseLevelSize) const
{
const int w = qFloor(double(qMax(1, baseLevelSize.width() >> mipLevel)));
const int h = qFloor(double(qMax(1, baseLevelSize.height() >> mipLevel)));
const int w = qFloor(float(qMax(1, baseLevelSize.width() >> mipLevel)));
const int h = qFloor(float(qMax(1, baseLevelSize.height() >> mipLevel)));
return QSize(w, h);
}
......
......@@ -575,8 +575,10 @@ void QRhiD3D11::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates)
context->UpdateSubresource(texD->tex, subres, nullptr,
mipDesc.image.constBits(), mipDesc.image.bytesPerLine(), 0);
} else if (!mipDesc.compressedData.isEmpty() && isCompressedFormat(texD->m_format)) {
const int w = qFloor(float(qMax(1, texD->m_pixelSize.width() >> level)));
const int h = qFloor(float(qMax(1, texD->m_pixelSize.height() >> level)));
quint32 bpl = 0;
compressedFormatInfo(texD->m_format, texD->m_pixelSize, &bpl, nullptr);
compressedFormatInfo(texD->m_format, QSize(w, h), &bpl, nullptr);
context->UpdateSubresource(texD->tex, subres, nullptr,
mipDesc.compressedData.constData(), bpl, 0);
}
......
......@@ -1199,7 +1199,7 @@ bool QGles2Texture::build()
rhiD->f->glBindTexture(targetBase + layer, texture);
for (int level = 0; level != mipLevelCount; ++level) {
rhiD->f->glTexImage2D(targetBase + layer, level, glintformat,
qFloor(double(qMax(1, size.width() >> level))), qFloor(double(qMax(1, size.height() >> level))),
qFloor(float(qMax(1, size.width() >> level))), qFloor(float(qMax(1, size.height() >> level))),
0, glformat, gltype, nullptr);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment