qt: Add fallback to default shader on load
This commit is contained in:
@@ -27,7 +27,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Default vertex shader. */
|
/* Default vertex shader. */
|
||||||
static const GLchar *vertex_shader = "#version 130\n\
|
static const GLchar *vertex_shader = "\
|
||||||
in vec2 VertexCoord;\n\
|
in vec2 VertexCoord;\n\
|
||||||
in vec2 TexCoord;\n\
|
in vec2 TexCoord;\n\
|
||||||
out vec2 tex;\n\
|
out vec2 tex;\n\
|
||||||
@@ -37,26 +37,7 @@ void main(){\n\
|
|||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
/* Default fragment shader. */
|
/* Default fragment shader. */
|
||||||
static const GLchar *fragment_shader = "#version 130\n\
|
static const GLchar *fragment_shader = "\
|
||||||
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\
|
|
||||||
in vec2 tex;\n\
|
in vec2 tex;\n\
|
||||||
uniform sampler2D texsampler;\n\
|
uniform sampler2D texsampler;\n\
|
||||||
out vec4 color;\n\
|
out vec4 color;\n\
|
||||||
@@ -84,10 +65,16 @@ OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig)
|
|||||||
|
|
||||||
QString shaderPath(video_shader);
|
QString shaderPath(video_shader);
|
||||||
|
|
||||||
if (shaderPath.isEmpty())
|
if (shaderPath.isEmpty()) {
|
||||||
addDefaultShader();
|
addDefaultShader();
|
||||||
else
|
} else {
|
||||||
addShader(shaderPath);
|
try {
|
||||||
|
addShader(shaderPath);
|
||||||
|
} catch (const std::runtime_error &) {
|
||||||
|
/* Fallback to default shader */
|
||||||
|
addDefaultShader();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -168,8 +155,7 @@ OpenGLOptions::addShader(const QString &path)
|
|||||||
shader_text.remove(version);
|
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) */
|
/* Force #version 300 es (the default of #version 100 es is too old and too limited) */
|
||||||
version_line = "#version 300 es";
|
version_line = "#version 300 es";
|
||||||
}
|
}
|
||||||
@@ -198,9 +184,13 @@ OpenGLOptions::addShader(const QString &path)
|
|||||||
void
|
void
|
||||||
OpenGLOptions::addDefaultShader()
|
OpenGLOptions::addDefaultShader()
|
||||||
{
|
{
|
||||||
|
QString version = QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES()
|
||||||
|
? "#version 300 es\n"
|
||||||
|
: "#version 130\n";
|
||||||
|
|
||||||
auto shader = new QOpenGLShaderProgram(this);
|
auto shader = new QOpenGLShaderProgram(this);
|
||||||
shader->addShaderFromSourceCode(QOpenGLShader::Vertex, QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES() ? vertex_shader_es3 : vertex_shader);
|
shader->addShaderFromSourceCode(QOpenGLShader::Vertex, version % vertex_shader);
|
||||||
shader->addShaderFromSourceCode(QOpenGLShader::Fragment, QOpenGLContext::currentContext() && QOpenGLContext::currentContext()->isOpenGLES() ? fragment_shader_es3 : fragment_shader);
|
shader->addShaderFromSourceCode(QOpenGLShader::Fragment, version % fragment_shader);
|
||||||
shader->link();
|
shader->link();
|
||||||
m_shaders << OpenGLShaderPass(shader, QString());
|
m_shaders << OpenGLShaderPass(shader, QString());
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ OpenGLOptionsDialog::accept()
|
|||||||
else
|
else
|
||||||
options->addDefaultShader();
|
options->addDefaultShader();
|
||||||
|
|
||||||
} catch (std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
delete options;
|
delete options;
|
||||||
|
|
||||||
QMessageBox msgBox(this);
|
QMessageBox msgBox(this);
|
||||||
|
Reference in New Issue
Block a user