0

From https://learnopengl.com/Getting-started/Shaders I read:

Shaders always begin with a version declaration, ...

But on OpenGL Window Example there is no version on shader code. What's the version then?

static const char *vertexShaderSource =
    "attribute highp vec4 posAttr;\n"
    "attribute lowp vec4 colAttr;\n"
    "varying lowp vec4 col;\n"
    "uniform highp mat4 matrix;\n"
    "void main() {\n"
    "   col = colAttr;\n"
    "   gl_Position = matrix * posAttr;\n"
    "}\n";

static const char *fragmentShaderSource =
    "varying lowp vec4 col;\n"
    "void main() {\n"
    "   gl_FragColor = col;\n"
    "}\n";

Following seems to be related: How to Convert GLSL #version 330 core to GLSL ES #version 100?

genpfault
  • 51,148
  • 11
  • 85
  • 139
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • I tried to add `#version 100` but then I got `version '100' is not supported`. Also tried `#version 330` which led to same result. Seems I should not set version? – KcFnMi Dec 04 '22 at 09:03
  • So looks like I should look for a good reference about OpenGL ES, would you recommend one? – KcFnMi Dec 04 '22 at 09:22
  • The [The OpenGL® Shading Language, Version 4.60.7](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html) is for GLSL and GLSL ES. Also see [Khronos OpenGL ES Registry](https://registry.khronos.org/OpenGL/index_es.php). – Rabbid76 Dec 04 '22 at 09:23
  • I'm not totally convinced Qt is stuck on `#version 100`, https://www.qt.io/blog/2015/09/09/cross-platform-opengl-es-3-apps-with-qt-5-6 – KcFnMi Dec 04 '22 at 09:50

1 Answers1

2

In qt 5.12.2 source file : qopenglshaderprogram.cpp

LINE 604:

bool QOpenGLShader::compileSourceCode(const char *source){

Q_D(QOpenGLShader);
// This method breaks the shader code into two parts:
// 1. Up to and including an optional #version directive.
// 2. The rest.
// If a #version directive exists, qualifierDefines and redefineHighp
// are inserted after. Otherwise they are inserted right at the start.
// In both cases a #line directive is appended in order to compensate
// for line number changes in case of compiler errors.

if (d->shaderGuard && d->shaderGuard->id() && source) {
    const QVersionDirectivePosition versionDirectivePosition = findVersionDirectivePosition(source);

    QVarLengthArray<const char *, 5> sourceChunks;
    QVarLengthArray<GLint, 5> sourceChunkLengths;
    QOpenGLContext *ctx = QOpenGLContext::currentContext();

    if (versionDirectivePosition.hasPosition()) {
        // Append source up to and including the #version directive
        sourceChunks.append(source);
        sourceChunkLengths.append(GLint(versionDirectivePosition.position));
    } else {
        // QTBUG-55733: Intel on Windows with Compatibility profile requires a #version always
        if (ctx->format().profile() == QSurfaceFormat::CompatibilityProfile) {
            const char *vendor = reinterpret_cast<const char *>(ctx->functions()->glGetString(GL_VENDOR));
            if (vendor && !strcmp(vendor, "Intel")) {
                static const char version110[] = "#version 110\n";
                sourceChunks.append(version110);
                sourceChunkLengths.append(GLint(sizeof(version110)) - 1);
            }
        }
    }

and

static QVersionDirectivePosition findVersionDirectivePosition(const char *source){
Q_ASSERT(source);

// According to the GLSL spec the #version directive must not be
// preceded by anything but whitespace and comments.
// In order to not get confused by #version directives within a
// multiline comment, we need to do some minimal comment parsing
// while searching for the directive.

If version is not available, "#version 110\n" will be added.

static const char version110[] = "#version 110\n";
sourceChunks.append(version110);
cfl997
  • 43
  • 7