qt: OpenGL ES 3.0 support
This commit is contained in:
@@ -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");
|
||||
|
@@ -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());
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
||||
class OpenGLShaderPass {
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#ifndef Q_OS_MACOS
|
||||
#if !defined Q_OS_MACOS && !(QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
# include <QtOpenGLExtensions/QOpenGLExtensions>
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user