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
+12 -6
View File
@@ -53,12 +53,6 @@ set(TENMON_SRC
stretchtoolbar.cpp stretchtoolbar.h stretchtoolbar.cpp stretchtoolbar.h
) )
option(COLOR_MANAGMENT "Enable sRGB framebuffer support for gamma correct images and color profiles support" ON)
if(COLOR_MANAGMENT)
add_compile_definitions("COLOR_MANAGMENT")
endif(COLOR_MANAGMENT)
qt_add_resources(TENMON_SRC resources/resources.qrc) qt_add_resources(TENMON_SRC resources/resources.qrc)
qt_add_resources(TENMON_SRC shaders/shaders.qrc) qt_add_resources(TENMON_SRC shaders/shaders.qrc)
qt_add_resources(TENMON_SRC scripts/scripts.qrc) qt_add_resources(TENMON_SRC scripts/scripts.qrc)
@@ -81,6 +75,18 @@ qt_add_executable(tenmon WIN32 MACOSX_BUNDLE ${tenmon_ICON} ${TENMON_SRC})
find_path(FITS_INCLUDE fitsio2.h PATH_SUFFIXES cfitsio REQUIRED) find_path(FITS_INCLUDE fitsio2.h PATH_SUFFIXES cfitsio REQUIRED)
target_include_directories(tenmon PRIVATE ${FITS_INCLUDE} ${CMAKE_BINARY_DIR} ${libXISF_SOURCE_DIR}) target_include_directories(tenmon PRIVATE ${FITS_INCLUDE} ${CMAKE_BINARY_DIR} ${libXISF_SOURCE_DIR})
option(COLOR_MANAGMENT "Enable sRGB framebuffer support for gamma correct images and color profiles support" ON)
if(COLOR_MANAGMENT)
target_compile_definitions(tenmon PRIVATE "COLOR_MANAGMENT")
endif(COLOR_MANAGMENT)
# not ready yet
#option(USE_OPENGLES ON)
if(USE_OPENGLES)
target_compile_definitions(tenmon PRIVATE "NOU_GLES_CONTEXT")
endif(USE_OPENGLES)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
target_include_directories(tenmon PRIVATE ${GIO_INCLUDE_DIRS}) target_include_directories(tenmon PRIVATE ${GIO_INCLUDE_DIRS})
endif() endif()
+30 -13
View File
@@ -203,7 +203,7 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
m_thumbnailTexture->destroy(); m_thumbnailTexture->destroy();
m_thumbnailTexture->create(); m_thumbnailTexture->create();
m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm); m_thumbnailTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE); m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers)); m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers));
m_thumbnailTexture->allocateStorage(); m_thumbnailTexture->allocateStorage();
@@ -354,7 +354,7 @@ void ImageWidget::paintGL()
QMatrix4x4 mvp; QMatrix4x4 mvp;
mvp.ortho(rect()); mvp.ortho(rect());
m_thumbnailProgram->setUniformValue("mvp", mvp); 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); QPainter painter(this);
const int w = width()/THUMB_SIZE_BORDER; const int w = width()/THUMB_SIZE_BORDER;
@@ -433,12 +433,29 @@ void ImageWidget::resizeGL(int w, int h)
void ImageWidget::initializeGL() void ImageWidget::initializeGL()
{ {
f = context()->functions(); f = context()->functions();
fx = context()->extraFunctions();
f->glClearColor(0.5f, 0.5f, 0.5f, 1.0f); 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.")); 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_vao = std::unique_ptr<QOpenGLVertexArrayObject>(new QOpenGLVertexArrayObject);
m_vaoThumb = std::unique_ptr<QOpenGLVertexArrayObject>(new QOpenGLVertexArrayObject); m_vaoThumb = std::unique_ptr<QOpenGLVertexArrayObject>(new QOpenGLVertexArrayObject);
m_vao->create(); m_vao->create();
@@ -477,8 +494,8 @@ void ImageWidget::initializeGL()
// f->glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float)*4, 0); // f->glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float)*4, 0);
m_program = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram); m_program = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/image.vert"); m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/image.vert"));
m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/image.frag"); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/image.frag"));
if(!m_program->link()) if(!m_program->link())
{ {
@@ -494,8 +511,8 @@ void ImageWidget::initializeGL()
m_program->setUniformValue("scale", 1.0f, 0.0f); m_program->setUniformValue("scale", 1.0f, 0.0f);
m_debayerProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram); m_debayerProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_debayerProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/debayer.vert"); m_debayerProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/debayer.vert"));
m_debayerProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/debayer.frag"); m_debayerProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/debayer.frag"));
m_debayerProgram->bind(); m_debayerProgram->bind();
m_debayerProgram->enableAttributeArray("qt_Vertex"); m_debayerProgram->enableAttributeArray("qt_Vertex");
@@ -511,8 +528,8 @@ void ImageWidget::initializeGL()
m_vaoThumb->bind(); m_vaoThumb->bind();
m_thumbnailProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram); m_thumbnailProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
m_thumbnailProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/thumb.vert"); m_thumbnailProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShader(":/thumb.vert"));
m_thumbnailProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/thumb.frag"); m_thumbnailProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShader(":/thumb.frag"));
m_thumbnailProgram->bind(); m_thumbnailProgram->bind();
m_thumbnailProgram->enableAttributeArray("qt_Vertex"); m_thumbnailProgram->enableAttributeArray("qt_Vertex");
@@ -532,8 +549,8 @@ void ImageWidget::initializeGL()
m_bufferSizes->allocate(12); m_bufferSizes->allocate(12);
m_thumbnailProgram->enableAttributeArray("imageSize_num"); m_thumbnailProgram->enableAttributeArray("imageSize_num");
f3->glVertexAttribIPointer(m_thumbnailProgram->attributeLocation("imageSize_num"), 3, GL_INT, 0, nullptr); fx->glVertexAttribIPointer(m_thumbnailProgram->attributeLocation("imageSize_num"), 3, GL_INT, 0, nullptr);
f3->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1); fx->glVertexAttribDivisor(m_thumbnailProgram->attributeLocation("imageSize_num"), 1);
m_image = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2D)); m_image = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2D));
m_image->setFormat(QOpenGLTexture::RGB8U); m_image->setFormat(QOpenGLTexture::RGB8U);
@@ -543,7 +560,7 @@ void ImageWidget::initializeGL()
m_image->setMagnificationFilter(QOpenGLTexture::Linear); m_image->setMagnificationFilter(QOpenGLTexture::Linear);
m_thumbnailTexture = std::unique_ptr<QOpenGLTexture>(new QOpenGLTexture(QOpenGLTexture::Target2DArray)); 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->setSize(THUMB_SIZE, THUMB_SIZE);
m_thumbnailTexture->setLayers(1); m_thumbnailTexture->setLayers(1);
m_thumbnailTexture->allocateStorage(); m_thumbnailTexture->allocateStorage();
+3 -2
View File
@@ -4,7 +4,6 @@
#include <memory> #include <memory>
#include <QObject> #include <QObject>
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QOpenGLTexture> #include <QOpenGLTexture>
@@ -15,6 +14,8 @@
#include "imageringlist.h" #include "imageringlist.h"
#include "database.h" #include "database.h"
#include "stretchtoolbar.h" #include "stretchtoolbar.h"
#include <QOpenGLFunctions>
#include <QOpenGLExtraFunctions>
struct ImageThumb struct ImageThumb
{ {
@@ -29,7 +30,7 @@ class ImageWidget : public QOpenGLWidget
{ {
Q_OBJECT Q_OBJECT
QOpenGLFunctions *f = nullptr; QOpenGLFunctions *f = nullptr;
QOpenGLFunctions_3_3_Core *f3 = nullptr; QOpenGLExtraFunctions *fx = nullptr;
QTimer *m_updateTimer = nullptr; QTimer *m_updateTimer = nullptr;
std::unique_ptr<QOpenGLShaderProgram> m_program; std::unique_ptr<QOpenGLShaderProgram> m_program;
std::unique_ptr<QOpenGLShaderProgram> m_thumbnailProgram; std::unique_ptr<QOpenGLShaderProgram> m_thumbnailProgram;
+9 -1
View File
@@ -3,7 +3,6 @@
#include <QSurfaceFormat> #include <QSurfaceFormat>
#include <QTranslator> #include <QTranslator>
#include <stdlib.h> #include <stdlib.h>
#include "libxisf.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -12,10 +11,19 @@ int main(int argc, char *argv[])
#endif #endif
QSurfaceFormat format; QSurfaceFormat format;
#ifdef NOU_GLES_CONTEXT
format.setMajorVersion(3);
format.setMinorVersion(0);
format.setRenderableType(QSurfaceFormat::OpenGLES);
printf("OpenGL ES\n");
qDebug() << "Requesting OpenGL ES";
#else
format.setMajorVersion(3); format.setMajorVersion(3);
format.setMinorVersion(3); format.setMinorVersion(3);
//format.setOption(QSurfaceFormat::DebugContext); //format.setOption(QSurfaceFormat::DebugContext);
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
printf("OpenGL\n");
#endif
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
QApplication a(argc, argv); QApplication a(argc, argv);
-2
View File
@@ -1,5 +1,3 @@
#version 330
uniform sampler2D qt_Texture0; uniform sampler2D qt_Texture0;
uniform ivec2 firstRed; uniform ivec2 firstRed;
in vec2 qt_TexCoord0; in vec2 qt_TexCoord0;
-2
View File
@@ -1,5 +1,3 @@
#version 330
uniform sampler2D qt_Texture0; uniform sampler2D qt_Texture0;
in vec2 qt_Vertex; in vec2 qt_Vertex;
in vec2 qt_MultiTexCoord0; in vec2 qt_MultiTexCoord0;
+3 -5
View File
@@ -1,5 +1,3 @@
#version 330
uniform sampler2D qt_Texture0; uniform sampler2D qt_Texture0;
uniform vec3 mtf_param[3]; uniform vec3 mtf_param[3];
uniform vec2 unit_scale; uniform vec2 unit_scale;
@@ -22,7 +20,7 @@ vec4 MTF(vec4 x, vec4 low, vec4 mid, vec4 high)
{ {
x = (x - low) / (high - low); x = (x - low) / (high - low);
x = clamp(x, vec4(0.0), vec4(1.0)); x = clamp(x, vec4(0.0), vec4(1.0));
return ((mid - 1) * x) / ((2 * mid - 1) * x - mid); return ((mid - 1.0) * x) / ((2.0 * mid - 1.0) * x - mid);
} }
vec3 falsecolor(float color) vec3 falsecolor(float color)
@@ -59,7 +57,7 @@ vec4 cubic(float v)
vec4 textureBicubic(sampler2D sampler, vec2 texCoords) vec4 textureBicubic(sampler2D sampler, vec2 texCoords)
{ {
vec2 texSize = textureSize(sampler, 0); vec2 texSize = vec2(textureSize(sampler, 0));
vec2 invTexSize = 1.0 / texSize; vec2 invTexSize = 1.0 / texSize;
texCoords = texCoords * texSize - 0.5; texCoords = texCoords * texSize - 0.5;
@@ -133,7 +131,7 @@ void main(void)
switch(filtering) switch(filtering)
{ {
case 0://nearest case 0://nearest
color = texelFetch(qt_Texture0, ivec2(qt_TexCoord0 * textureSize(qt_Texture0, 0)), 0); color = texelFetch(qt_Texture0, ivec2(qt_TexCoord0 * vec2(textureSize(qt_Texture0, 0))), 0);
break; break;
default: default:
case 1://bilinear case 1://bilinear
-2
View File
@@ -1,5 +1,3 @@
#version 330
uniform sampler2D qt_Texture0; uniform sampler2D qt_Texture0;
in vec2 qt_Vertex; in vec2 qt_Vertex;
in vec2 qt_MultiTexCoord0; in vec2 qt_MultiTexCoord0;
+1 -3
View File
@@ -1,5 +1,3 @@
#version 330
uniform sampler2DArray qt_Texture0; uniform sampler2DArray qt_Texture0;
uniform vec3 mtf_param[3]; uniform vec3 mtf_param[3];
uniform bool invert; uniform bool invert;
@@ -10,7 +8,7 @@ vec4 MTF(vec4 x, vec4 low, vec4 mid, vec4 high)
{ {
x = (x - low) / (high - low); x = (x - low) / (high - low);
x = clamp(x, vec4(0.0), vec4(1.0)); x = clamp(x, vec4(0.0), vec4(1.0));
return ((mid - 1) * x) / ((2 * mid - 1) * x - mid); return ((mid - 1.0) * x) / ((2.0 * mid - 1.0) * x - mid);
} }
void main(void) void main(void)
+3 -5
View File
@@ -1,5 +1,3 @@
#version 330
in vec2 qt_Vertex; in vec2 qt_Vertex;
in vec2 qt_MultiTexCoord0; in vec2 qt_MultiTexCoord0;
in ivec3 imageSize_num; in ivec3 imageSize_num;
@@ -13,9 +11,9 @@ void main(void)
{ {
vec2 pos = qt_Vertex * 0.5; vec2 pos = qt_Vertex * 0.5;
pos.y *= -1.0; pos.y *= -1.0;
pos = pos * imageSize_num.xy + thumb_size.x; pos = pos * vec2(imageSize_num.xy) + float(thumb_size.x);
ivec2 off = ivec2(imageSize_num.z % viewport_row.z, imageSize_num.z / viewport_row.z) * thumb_size.yz; ivec2 off = ivec2(imageSize_num.z % viewport_row.z, imageSize_num.z / viewport_row.z) * thumb_size.yz;
gl_Position = mvp * vec4(pos - offset + off, 0.0, 1.0); gl_Position = mvp * vec4(pos - offset + vec2(off), 0.0, 1.0);
qt_TexCoord0 = vec3(qt_MultiTexCoord0, imageSize_num.z + 0.1); qt_TexCoord0 = vec3(qt_MultiTexCoord0, float(imageSize_num.z) + 0.1);
} }