From ee69b022fc880145384e1b33717c415eecd04ee0 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 1 Mar 2022 13:31:19 +0600 Subject: [PATCH] qt: OpenGL ES 3.0 support --- src/qt/qt_mainwindow.cpp | 2 ++ src/qt/qt_opengloptions.cpp | 28 ++++++++++++++++++++++++++-- src/qt/qt_opengloptions.hpp | 1 + src/qt/qt_openglrenderer.cpp | 3 ++- src/qt/qt_openglrenderer.hpp | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index e9e7548cf..0c1d88fb8 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -231,6 +231,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->actionHardware_Renderer_OpenGL_ES->setVisible(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES); if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGLES && vid_api == 2) vid_api = 1; #endif + ui->actionHardware_Renderer_OpenGL->setVisible(QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGLES); + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES && vid_api == 1) vid_api = 0; if (QApplication::platformName().contains("eglfs") && vid_api >= 1) { fprintf(stderr, "OpenGL renderers are unsupported on EGLFS.\n"); diff --git a/src/qt/qt_opengloptions.cpp b/src/qt/qt_opengloptions.cpp index 72f649b53..26b8f05fe 100644 --- a/src/qt/qt_opengloptions.cpp +++ b/src/qt/qt_opengloptions.cpp @@ -45,6 +45,25 @@ 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\ +in vec2 tex;\n\ +uniform sampler2D texsampler;\n\ +out vec4 color;\n\ +void main() {\n\ + color = texture(texsampler, tex);\n\ +}\n"; + OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig) : QObject(parent) { @@ -149,6 +168,11 @@ OpenGLOptions::addShader(const QString &path) shader_text.remove(version); } + 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"; + } auto shader = new QOpenGLShaderProgram(this); auto throw_shader_error = [path, shader](const QString &what) { @@ -175,8 +199,8 @@ void OpenGLOptions::addDefaultShader() { auto shader = new QOpenGLShaderProgram(this); - shader->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader); - shader->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader); + 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->link(); m_shaders << OpenGLShaderPass(shader, QString()); } diff --git a/src/qt/qt_opengloptions.hpp b/src/qt/qt_opengloptions.hpp index d28b388ba..45a11377a 100644 --- a/src/qt/qt_opengloptions.hpp +++ b/src/qt/qt_opengloptions.hpp @@ -19,6 +19,7 @@ #include #include +#include #include class OpenGLShaderPass { diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 077772a95..b1a911841 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -43,6 +43,7 @@ OpenGLRenderer::OpenGLRenderer(QWidget *parent) format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setMajorVersion(3); format.setMinorVersion(0); + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) format.setRenderableType(QSurfaceFormat::OpenGLES); setFormat(format); @@ -389,4 +390,4 @@ OpenGLRenderer::onBlit(int buf_idx, int x, int y, int w, int h) if (options->renderBehavior() == OpenGLOptions::SyncWithVideo) render(); -} \ No newline at end of file +} diff --git a/src/qt/qt_openglrenderer.hpp b/src/qt/qt_openglrenderer.hpp index bbd0c1f01..83490f293 100644 --- a/src/qt/qt_openglrenderer.hpp +++ b/src/qt/qt_openglrenderer.hpp @@ -23,7 +23,7 @@ #include #include #include -#ifndef Q_OS_MACOS +#if !defined Q_OS_MACOS && !(QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include #endif