mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Fix mipmapping
This commit is contained in:
@ -37,8 +37,7 @@ void YACReaderComicFlow3D::updateImageData()
|
|||||||
|
|
||||||
// Create QRhiTexture from the loaded image
|
// Create QRhiTexture from the loaded image
|
||||||
if (m_rhi) {
|
if (m_rhi) {
|
||||||
QRhiTexture *texture = m_rhi->newTexture(QRhiTexture::BGRA8, img.size(), 1,
|
QRhiTexture *texture = m_rhi->newTexture(QRhiTexture::BGRA8, img.size(), 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips);
|
||||||
(performance == high || performance == ultraHigh) ? QRhiTexture::MipMapped : QRhiTexture::UsedAsTransferSource);
|
|
||||||
|
|
||||||
if (texture->create()) {
|
if (texture->create()) {
|
||||||
PendingTextureUpload upload;
|
PendingTextureUpload upload;
|
||||||
@ -48,8 +47,7 @@ void YACReaderComicFlow3D::updateImageData()
|
|||||||
upload.y = 1 * (float(img.height()) / img.width());
|
upload.y = 1 * (float(img.height()) / img.width());
|
||||||
pendingTextureUploads.append(upload);
|
pendingTextureUploads.append(upload);
|
||||||
|
|
||||||
QString s = "cover";
|
replace(texture, upload.x, upload.y, idx);
|
||||||
replace(s.toLocal8Bit().data(), texture, upload.x, upload.y, idx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,9 +121,10 @@ void YACReaderFlow3D::initialize(QRhiCommandBuffer *cb)
|
|||||||
if (!scene.defaultTexture) {
|
if (!scene.defaultTexture) {
|
||||||
QImage defaultImage(":/images/defaultCover.png");
|
QImage defaultImage(":/images/defaultCover.png");
|
||||||
|
|
||||||
scene.defaultTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, defaultImage.size(), 1, QRhiTexture::MipMapped));
|
scene.defaultTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, defaultImage.size(), 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
|
||||||
scene.defaultTexture->create();
|
scene.defaultTexture->create();
|
||||||
getResourceBatch()->uploadTexture(scene.defaultTexture.get(), defaultImage);
|
getResourceBatch()->uploadTexture(scene.defaultTexture.get(), defaultImage);
|
||||||
|
getResourceBatch()->generateMips(scene.defaultTexture.get());
|
||||||
qDebug() << "YACReaderFlow3D: Created defaultTexture" << defaultImage.size();
|
qDebug() << "YACReaderFlow3D: Created defaultTexture" << defaultImage.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,18 +133,20 @@ void YACReaderFlow3D::initialize(QRhiCommandBuffer *cb)
|
|||||||
if (!scene.markTexture) {
|
if (!scene.markTexture) {
|
||||||
QImage markImage(":/images/readRibbon.png");
|
QImage markImage(":/images/readRibbon.png");
|
||||||
if (!markImage.isNull()) {
|
if (!markImage.isNull()) {
|
||||||
scene.markTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, markImage.size(), 1, QRhiTexture::MipMapped));
|
scene.markTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, markImage.size(), 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
|
||||||
scene.markTexture->create();
|
scene.markTexture->create();
|
||||||
getResourceBatch()->uploadTexture(scene.markTexture.get(), markImage);
|
getResourceBatch()->uploadTexture(scene.markTexture.get(), markImage);
|
||||||
|
getResourceBatch()->generateMips(scene.markTexture.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scene.readingTexture) {
|
if (!scene.readingTexture) {
|
||||||
QImage readingImage(":/images/readingRibbon.png");
|
QImage readingImage(":/images/readingRibbon.png");
|
||||||
if (!readingImage.isNull()) {
|
if (!readingImage.isNull()) {
|
||||||
scene.readingTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, readingImage.size(), 1, QRhiTexture::MipMapped));
|
scene.readingTexture.reset(m_rhi->newTexture(QRhiTexture::BGRA8, readingImage.size(), 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
|
||||||
scene.readingTexture->create();
|
scene.readingTexture->create();
|
||||||
getResourceBatch()->uploadTexture(scene.readingTexture.get(), readingImage);
|
getResourceBatch()->uploadTexture(scene.readingTexture.get(), readingImage);
|
||||||
|
getResourceBatch()->generateMips(scene.readingTexture.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -178,13 +181,12 @@ void YACReaderFlow3D::initialize(QRhiCommandBuffer *cb)
|
|||||||
scene.alignedUniformSize = m_rhi->ubufAligned(sizeof(UniformData));
|
scene.alignedUniformSize = m_rhi->ubufAligned(sizeof(UniformData));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create sampler
|
// Create sampler with trilinear filtering (like the OpenGL version)
|
||||||
if (!scene.sampler) {
|
if (!scene.sampler) {
|
||||||
// Use no mipmap sampling to avoid LOD changes with camera Z
|
|
||||||
scene.sampler.reset(m_rhi->newSampler(
|
scene.sampler.reset(m_rhi->newSampler(
|
||||||
QRhiSampler::Linear,
|
QRhiSampler::Linear, // mag filter
|
||||||
QRhiSampler::Linear,
|
QRhiSampler::Linear, // min filter
|
||||||
QRhiSampler::None,
|
QRhiSampler::Linear, // mipmap filter (trilinear)
|
||||||
QRhiSampler::ClampToEdge,
|
QRhiSampler::ClampToEdge,
|
||||||
QRhiSampler::ClampToEdge));
|
QRhiSampler::ClampToEdge));
|
||||||
scene.sampler->create();
|
scene.sampler->create();
|
||||||
@ -498,6 +500,7 @@ void YACReaderFlow3D::render(QRhiCommandBuffer *cb)
|
|||||||
for (const auto &upload : std::as_const(pendingTextureUploads)) {
|
for (const auto &upload : std::as_const(pendingTextureUploads)) {
|
||||||
if (upload.index >= 0 && upload.index < images.size() && images[upload.index].texture) {
|
if (upload.index >= 0 && upload.index < images.size() && images[upload.index].texture) {
|
||||||
batch->uploadTexture(images[upload.index].texture, upload.image);
|
batch->uploadTexture(images[upload.index].texture, upload.image);
|
||||||
|
batch->generateMips(images[upload.index].texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pendingTextureUploads.clear();
|
pendingTextureUploads.clear();
|
||||||
@ -824,11 +827,10 @@ void YACReaderFlow3D::updatePositions()
|
|||||||
stopAnimationTimer();
|
stopAnimationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderFlow3D::insert(char *name, QRhiTexture *texture, float x, float y, int item)
|
void YACReaderFlow3D::insert(QRhiTexture *texture, float x, float y, int item)
|
||||||
{
|
{
|
||||||
startAnimationTimer();
|
startAnimationTimer();
|
||||||
|
|
||||||
Q_UNUSED(name)
|
|
||||||
if (item == -1) {
|
if (item == -1) {
|
||||||
images.push_back(YACReader3DImageRHI());
|
images.push_back(YACReader3DImageRHI());
|
||||||
item = numObjects;
|
item = numObjects;
|
||||||
@ -883,7 +885,6 @@ void YACReaderFlow3D::add(int item)
|
|||||||
{
|
{
|
||||||
float x = 1;
|
float x = 1;
|
||||||
float y = 1 * (700.f / 480.0f);
|
float y = 1 * (700.f / 480.0f);
|
||||||
QString s = "cover";
|
|
||||||
|
|
||||||
images.insert(item, YACReader3DImageRHI());
|
images.insert(item, YACReader3DImageRHI());
|
||||||
loaded.insert(item, false);
|
loaded.insert(item, false);
|
||||||
@ -894,7 +895,7 @@ void YACReaderFlow3D::add(int item)
|
|||||||
images[i].index++;
|
images[i].index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
insert(s.toLocal8Bit().data(), scene.defaultTexture.get(), x, y, item);
|
insert(scene.defaultTexture.get(), x, y, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
YACReader3DImageRHI YACReaderFlow3D::getCurrentSelected()
|
YACReader3DImageRHI YACReaderFlow3D::getCurrentSelected()
|
||||||
@ -902,11 +903,10 @@ YACReader3DImageRHI YACReaderFlow3D::getCurrentSelected()
|
|||||||
return images[currentSelected];
|
return images[currentSelected];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderFlow3D::replace(char *name, QRhiTexture *texture, float x, float y, int item)
|
void YACReaderFlow3D::replace(QRhiTexture *texture, float x, float y, int item)
|
||||||
{
|
{
|
||||||
startAnimationTimer();
|
startAnimationTimer();
|
||||||
|
|
||||||
Q_UNUSED(name)
|
|
||||||
if (images[item].index == item) {
|
if (images[item].index == item) {
|
||||||
images[item].texture = texture;
|
images[item].texture = texture;
|
||||||
images[item].width = x;
|
images[item].width = x;
|
||||||
@ -928,8 +928,7 @@ void YACReaderFlow3D::populate(int n)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
QString s = "cover";
|
insert(scene.defaultTexture.get(), x, y);
|
||||||
insert(s.toLocal8Bit().data(), scene.defaultTexture.get(), x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = QVector<bool>(n, false);
|
loaded = QVector<bool>(n, false);
|
||||||
|
|||||||
@ -266,10 +266,10 @@ public:
|
|||||||
void cleanupAnimation();
|
void cleanupAnimation();
|
||||||
void draw();
|
void draw();
|
||||||
void updatePositions();
|
void updatePositions();
|
||||||
void insert(char *name, QRhiTexture *texture, float x, float y, int item = -1);
|
void insert(QRhiTexture *texture, float x, float y, int item = -1);
|
||||||
virtual void remove(int item);
|
virtual void remove(int item);
|
||||||
void add(int item);
|
void add(int item);
|
||||||
void replace(char *name, QRhiTexture *texture, float x, float y, int item);
|
void replace(QRhiTexture *texture, float x, float y, int item);
|
||||||
void populate(int n);
|
void populate(int n);
|
||||||
YACReader3DImageRHI getCurrentSelected();
|
YACReader3DImageRHI getCurrentSelected();
|
||||||
|
|
||||||
|
|||||||
@ -40,8 +40,7 @@ void YACReaderPageFlow3D::updateImageData()
|
|||||||
|
|
||||||
// Create QRhiTexture from the loaded image and queue the pixel upload
|
// Create QRhiTexture from the loaded image and queue the pixel upload
|
||||||
if (m_rhi) {
|
if (m_rhi) {
|
||||||
QRhiTexture *texture = m_rhi->newTexture(QRhiTexture::BGRA8, img.size(), 1,
|
QRhiTexture *texture = m_rhi->newTexture(QRhiTexture::BGRA8, img.size(), 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips);
|
||||||
(performance == high || performance == ultraHigh) ? QRhiTexture::MipMapped : QRhiTexture::UsedAsTransferSource);
|
|
||||||
|
|
||||||
if (texture->create()) {
|
if (texture->create()) {
|
||||||
// Queue the image upload so it happens together with other resource updates
|
// Queue the image upload so it happens together with other resource updates
|
||||||
@ -52,8 +51,7 @@ void YACReaderPageFlow3D::updateImageData()
|
|||||||
upload.y = 1 * (float(img.height()) / img.width());
|
upload.y = 1 * (float(img.height()) / img.width());
|
||||||
pendingTextureUploads.append(upload);
|
pendingTextureUploads.append(upload);
|
||||||
|
|
||||||
QString s = "cover";
|
replace(texture, upload.x, upload.y, idx);
|
||||||
replace(s.toLocal8Bit().data(), texture, upload.x, upload.y, idx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user