Upload sizes to OpenGL only once per draw

Should fix MacOS issue
This commit is contained in:
2022-06-22 23:24:29 +02:00
parent 1682de4e1b
commit b4ea65b42a
2 changed files with 19 additions and 9 deletions
+18 -9
View File
@@ -67,6 +67,7 @@ ImageWidget::ImageWidget(Database *database, QWidget *parent) : QOpenGLWidget(pa
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(500);
m_updateTimer->setSingleShot(true);
m_sizesDirty = false;
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(update()));
setAcceptDrops(true);
QTimer::singleShot(1000, [this](){
@@ -147,11 +148,6 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
m_thumbnailTexture->setLayers(paths.size());
m_thumbnailTexture->allocateStorage();
m_bufferSizes->bind();
float *tmp = new float[count*3];
memset(tmp, 0, count * sizeof(float)*3);
m_bufferSizes->allocate(tmp, count * sizeof(float)*3);
delete [] tmp;
}
void ImageWidget::setMTFParams(float low, float mid, float high)
@@ -209,8 +205,7 @@ void ImageWidget::thumbnailLoaded(const Image *image)
m_thumbnailTexture->setData(0, image->number(), QOpenGLTexture::RGB, QOpenGLTexture::UInt16, raw->data(), m_transferOptions.get());
float a = raw->thumbAspect();
int sizes[3] = { std::max(1, a > 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE * a)), std::max(1, a < 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE / a)), image->number() };
m_bufferSizes->bind();
m_bufferSizes->write(image->number() * sizeof(sizes), sizes, sizeof(sizes));
m_sizesDirty = true;
m_thumnails[image->number()].size = QSize(sizes[0], sizes[1]);
if(!m_updateTimer->isActive())m_updateTimer->start();
}
@@ -237,12 +232,26 @@ void ImageWidget::paintGL()
{
m_vaoThumb->bind();
m_thumbnailTexture->bind(1);
if(m_sizesDirty)
{
m_bufferSizes->bind();
int i = 0;
std::vector<int> sizes(m_thumbnailCount*3);
for(auto &s : m_thumnails)
{
sizes[3*i] = s.size.width();
sizes[3*i+1] = s.size.height();
sizes[3*i+2] = i;
i++;
}
m_bufferSizes->allocate(&sizes[0], sizes.size()*sizeof(int));
m_sizesDirty = false;
}
m_thumbnailProgram->bind();
f->glUniform3i(m_thumbnailProgram->uniformLocation("viewport_row"), width(), height(), width()/THUMB_SIZE_BORDER);
m_thumbnailProgram->setUniformValue("mtf_param", m_low, m_mid, m_high);
m_thumbnailProgram->setUniformValue("invert", m_invert);
m_thumbnailProgram->setUniformValue("offset", 0, m_dy);
f3->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);
QMatrix4x4 mvp;
mvp.ortho(rect());
m_thumbnailProgram->setUniformValue("mvp", mvp);
@@ -378,8 +387,8 @@ void ImageWidget::initializeGL()
m_bufferSizes->setUsagePattern(QOpenGLBuffer::StaticDraw);
m_bufferSizes->create();
m_bufferSizes->bind();
m_bufferSizes->allocate(12);
m_thumbnailProgram->enableAttributeArray("imageSize_num");
m_thumbnailProgram->setAttributeBuffer("imageSize_num", GL_FLOAT, 0, 3);
f3->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);