From 109683300aee350d910d9f7bdd4e4e7624c2c59c Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Tue, 1 Mar 2022 22:20:19 +0200 Subject: [PATCH 1/2] qt: Add fallback to default shader on load --- src/qt/qt_opengloptions.cpp | 46 ++++++++++++------------------- src/qt/qt_opengloptionsdialog.cpp | 2 +- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/qt/qt_opengloptions.cpp b/src/qt/qt_opengloptions.cpp index 26b8f05fe..3222d940c 100644 --- a/src/qt/qt_opengloptions.cpp +++ b/src/qt/qt_opengloptions.cpp @@ -27,7 +27,7 @@ extern "C" { } /* Default vertex shader. */ -static const GLchar *vertex_shader = "#version 130\n\ +static const GLchar *vertex_shader = "\ in vec2 VertexCoord;\n\ in vec2 TexCoord;\n\ out vec2 tex;\n\ @@ -37,26 +37,7 @@ void main(){\n\ }\n"; /* Default fragment shader. */ -static const GLchar *fragment_shader = "#version 130\n\ -in vec2 tex;\n\ -uniform sampler2D texsampler;\n\ -out vec4 color;\n\ -void main() {\n\ - color = texture(texsampler, tex);\n\ -}\n"; - -/* Default vertex shader (OpenGL ES 3). */ -static const GLchar *vertex_shader_es3 = "#version 300 es\n\ -in vec2 VertexCoord;\n\ -in vec2 TexCoord;\n\ -out vec2 tex;\n\ -void main(){\n\ - gl_Position = vec4(VertexCoord, 0.0, 1.0);\n\ - tex = TexCoord;\n\ -}\n"; - -/* Default fragment shader (OpenGL ES 3). */ -static const GLchar *fragment_shader_es3 = "#version 300 es\n\ +static const GLchar *fragment_shader = "\ in vec2 tex;\n\ uniform sampler2D texsampler;\n\ out vec4 color;\n\ @@ -84,10 +65,16 @@ OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig) QString shaderPath(video_shader); - if (shaderPath.isEmpty()) + if (shaderPath.isEmpty()) { addDefaultShader(); - else - addShader(shaderPath); + } else { + try { + addShader(shaderPath); + } catch (const std::runtime_error &) { + /* Fallback to default shader */ + addDefaultShader(); + } + } } void @@ -168,8 +155,7 @@ OpenGLOptions::addShader(const QString &path) shader_text.remove(version); } - if (QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES()) - { + if (QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES()) { /* Force #version 300 es (the default of #version 100 es is too old and too limited) */ version_line = "#version 300 es"; } @@ -198,9 +184,13 @@ OpenGLOptions::addShader(const QString &path) void OpenGLOptions::addDefaultShader() { + QString version = QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES() + ? "#version 300 es\n" + : "#version 130\n"; + auto shader = new QOpenGLShaderProgram(this); - shader->addShaderFromSourceCode(QOpenGLShader::Vertex, QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES() ? vertex_shader_es3 : vertex_shader); - shader->addShaderFromSourceCode(QOpenGLShader::Fragment, QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES() ? fragment_shader_es3 : fragment_shader); + shader->addShaderFromSourceCode(QOpenGLShader::Vertex, version % vertex_shader); + shader->addShaderFromSourceCode(QOpenGLShader::Fragment, version % fragment_shader); shader->link(); m_shaders << OpenGLShaderPass(shader, QString()); } diff --git a/src/qt/qt_opengloptionsdialog.cpp b/src/qt/qt_opengloptionsdialog.cpp index 424b6468b..d996fbd3c 100644 --- a/src/qt/qt_opengloptionsdialog.cpp +++ b/src/qt/qt_opengloptionsdialog.cpp @@ -74,7 +74,7 @@ OpenGLOptionsDialog::accept() else options->addDefaultShader(); - } catch (std::runtime_error &e) { + } catch (const std::runtime_error &e) { delete options; QMessageBox msgBox(this); From f78a3f2c1029f1ca914f8b493a8e90b503cbff1b Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Tue, 1 Mar 2022 22:21:43 +0200 Subject: [PATCH 2/2] qt: try again to fix linux arm32 build error --- src/qt/qt_openglrenderer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 173e82448..f1e44f3a9 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,8 @@ OpenGLRenderer::OpenGLRenderer(QWidget *parent) format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setMajorVersion(3); format.setMinorVersion(0); - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) format.setRenderableType(QSurfaceFormat::OpenGLES); + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) + format.setRenderableType(QSurfaceFormat::OpenGLES); setFormat(format); @@ -146,7 +148,7 @@ OpenGLRenderer::initialize() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, INIT_WIDTH, INIT_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, QOpenGLTexture::RGBA8_UNorm, INIT_WIDTH, INIT_HEIGHT, 0, QOpenGLTexture::BGRA, QOpenGLTexture::UInt32_RGBA8_Rev, NULL); options = new OpenGLOptions(this, true); @@ -372,7 +374,7 @@ OpenGLRenderer::onBlit(int buf_idx, int x, int y, int w, int h) /* Resize the texture */ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, source.width(), source.height(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, QOpenGLTexture::RGBA8_UNorm, source.width(), source.height(), 0, QOpenGLTexture::BGRA, QOpenGLTexture::UInt32_RGBA8_Rev, NULL); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBufferID); } @@ -381,7 +383,7 @@ OpenGLRenderer::onBlit(int buf_idx, int x, int y, int w, int h) glPixelStorei(GL_UNPACK_SKIP_PIXELS, BUFFERPIXELS * buf_idx + y * ROW_LENGTH + x); glPixelStorei(GL_UNPACK_ROW_LENGTH, ROW_LENGTH); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, QOpenGLTexture::BGRA, QOpenGLTexture::UInt32_RGBA8_Rev, NULL); /* TODO: check if fence sync is implementable here and still has any benefit. */ glFinish();