Preparation for OpenGL ES

This commit is contained in:
2024-08-20 17:53:30 +02:00
parent 7ed38cf6d7
commit dd16a02045
10 changed files with 61 additions and 41 deletions
+30 -13
View File
@@ -203,7 +203,7 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
m_thumbnailTexture->destroy();
m_thumbnailTexture->create();
m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm);
m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers));
m_thumbnailTexture->allocateStorage();
@@ -354,7 +354,7 @@ void ImageWidget::paintGL()
QMatrix4x4 mvp;
mvp.ortho(rect());
m_thumbnailProgram->setUniformValue("mvp", mvp);
if(f3)f3->glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_thumbnailCount);
fx->glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_thumbnailCount);
QPainter painter(this);
const int w = width()/THUMB_SIZE_BORDER;
@@ -433,12 +433,29 @@ void ImageWidget::resizeGL(int w, int h)
void ImageWidget::initializeGL()
{
f = context()->functions();
fx = context()->extraFunctions();
f->glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
f3 = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_3_Core>(context());
if(f3 == nullptr)
if(fx == nullptr)
QMessageBox::critical(this, tr("OpenGL error"), tr("Could not initialize OpenGL 3.3 context. Ensure that proper GPU driver is installed."));
auto loadShader = [](const QString &file)
{
QFile fr(file);
fr.open(QIODevice::ReadOnly);
QByteArray src;
#ifdef NOU_GLES_CONTEXT
src = "#version 300 es\n"
"precision highp float;\n"
"precision highp sampler2DArray;\n"
"#line 1\n";
#else
src = "#version 330\n#line 1\n";
#endif
src.append(fr.readAll());
return src;
};
m_vao = std::unique_ptr<QOpenGLVertexArrayObject>(new QOpenGLVertexArrayObject);
m_vaoThumb = std::unique_ptr<QOpenGLVertexArrayObject>(new QOpenGLVertexArrayObject);
m_vao->create();
@@ -477,8 +494,8 @@ void ImageWidget::initializeGL()
// f->glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float)*4, 0);
m_program = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/image.vert");
m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/image.frag");
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/image.vert"));
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/image.frag"));
if(!m_program->link())
{
@@ -494,8 +511,8 @@ void ImageWidget::initializeGL()
m_program->setUniformValue("scale", 1.0f, 0.0f);
m_debayerProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_debayerProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/debayer.vert");
m_debayerProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/debayer.frag");
m_debayerProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/debayer.vert"));
m_debayerProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/debayer.frag"));
m_debayerProgram->bind();
m_debayerProgram->enableAttributeArray("qt_Vertex");
@@ -511,8 +528,8 @@ void ImageWidget::initializeGL()
m_vaoThumb->bind();
m_thumbnailProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_thumbnailProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/thumb.vert");
m_thumbnailProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/thumb.frag");
m_thumbnailProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/thumb.vert"));
m_thumbnailProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/thumb.frag"));
m_thumbnailProgram->bind();
m_thumbnailProgram->enableAttributeArray("qt_Vertex");
@@ -532,8 +549,8 @@ void ImageWidget::initializeGL()
m_bufferSizes->allocate(12);
m_thumbnailProgram->enableAttributeArray("imageSize_num");
f3->glVertexAttribIPointer(m_thumbnailProgram->attributeLocation("imageSize_num"), 3, GL_INT, 0, nullptr);
f3->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);
fx->glVertexAttribIPointer(m_thumbnailProgram->attributeLocation("imageSize_num"), 3, GL_INT, 0, nullptr);
fx->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);
m_image = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2D));
m_image->setFormat(QOpenGLTexture::RGB8U);
@@ -543,7 +560,7 @@ void ImageWidget::initializeGL()
m_image->setMagnificationFilter(QOpenGLTexture::Linear);
m_thumbnailTexture = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2DArray));
m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm);
m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
m_thumbnailTexture->setLayers(1);
m_thumbnailTexture->allocateStorage();