Usable OpenGL ES
This commit is contained in:
+31
-13
@@ -16,6 +16,7 @@
|
||||
#include <QElapsedTimer>
|
||||
|
||||
int FILTERING = 1;
|
||||
bool OpenGLES = false;
|
||||
|
||||
struct RawImageType
|
||||
{
|
||||
@@ -50,6 +51,13 @@ RawImageType getRawImageType(const RawImage *img)
|
||||
type.textureFormat = QOpenGLTexture::R32F;
|
||||
type.dataType = QOpenGLTexture::Float32;
|
||||
break;
|
||||
case RawImage::FLOAT16:
|
||||
if(img->channels() >= 3)
|
||||
type.textureFormat = QOpenGLTexture::RGBA16F;
|
||||
else
|
||||
type.textureFormat = QOpenGLTexture::R16F;
|
||||
type.dataType = QOpenGLTexture::Float16;
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Invalid format" << img->type();
|
||||
break;
|
||||
@@ -128,9 +136,11 @@ void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
|
||||
m_image->allocateStorage();
|
||||
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
||||
m_image->setWrapMode(QOpenGLTexture::ClampToEdge);
|
||||
m_image->setBorderColor(0, 0, 0, 0);
|
||||
m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, (const void*)image->data(), m_transferOptions.get());
|
||||
m_image->generateMipMaps();
|
||||
//m_image->setBorderColor(0, 0, 0, 0);
|
||||
m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, (const void*)image->data());
|
||||
//m_image->generateMipMaps();
|
||||
m_image->bind();
|
||||
f->glGenerateMipmap(GL_TEXTURE_2D);
|
||||
qDebug() << "setImage" << timer.elapsed();
|
||||
|
||||
m_unit_scale[0] = 1.0f;
|
||||
@@ -203,7 +213,7 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
|
||||
|
||||
m_thumbnailTexture->destroy();
|
||||
m_thumbnailTexture->create();
|
||||
m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
|
||||
m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16F);
|
||||
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
|
||||
m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers));
|
||||
m_thumbnailTexture->allocateStorage();
|
||||
@@ -301,7 +311,7 @@ void ImageWidget::thumbnailLoaded(const Image *image)
|
||||
makeCurrent();
|
||||
const RawImage *raw = image->thumbnail();
|
||||
if(!raw || !raw->valid())return;
|
||||
m_thumbnailTexture->setData(0, image->number(), QOpenGLTexture::RGBA, QOpenGLTexture::UInt16, raw->data(), m_transferOptions.get());
|
||||
m_thumbnailTexture->setData(0, image->number(), QOpenGLTexture::RGBA, QOpenGLTexture::Float16, raw->data());
|
||||
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_sizesDirty = true;
|
||||
@@ -355,6 +365,7 @@ void ImageWidget::paintGL()
|
||||
mvp.ortho(rect());
|
||||
m_thumbnailProgram->setUniformValue("mvp", mvp);
|
||||
fx->glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_thumbnailCount);
|
||||
m_vaoThumb->release();
|
||||
|
||||
QPainter painter(this);
|
||||
const int w = width()/THUMB_SIZE_BORDER;
|
||||
@@ -417,6 +428,7 @@ void ImageWidget::paintGL()
|
||||
m_program->setUniformValue("srgb", m_srgb);
|
||||
#endif
|
||||
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
m_vao->release();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -439,19 +451,24 @@ void ImageWidget::initializeGL()
|
||||
if(fx == nullptr)
|
||||
QMessageBox::critical(this, tr("OpenGL error"), tr("Could not initialize OpenGL 3.3 context. Ensure that proper GPU driver is installed."));
|
||||
|
||||
OpenGLES = context()->isOpenGLES();
|
||||
|
||||
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
|
||||
if(OpenGLES)
|
||||
{
|
||||
src = "#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"precision highp sampler2DArray;\n"
|
||||
"#line 1\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
src = "#version 330\n#line 1\n";
|
||||
}
|
||||
src.append(fr.readAll());
|
||||
return src;
|
||||
};
|
||||
@@ -551,6 +568,7 @@ void ImageWidget::initializeGL()
|
||||
m_thumbnailProgram->enableAttributeArray("imageSize_num");
|
||||
fx->glVertexAttribIPointer(m_thumbnailProgram->attributeLocation("imageSize_num"), 3, GL_INT, 0, nullptr);
|
||||
fx->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);
|
||||
m_vaoThumb->release();
|
||||
|
||||
m_image = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2D));
|
||||
m_image->setFormat(QOpenGLTexture::RGB8U);
|
||||
|
||||
Reference in New Issue
Block a user