简体   繁体   中英

Why there is no version on Qt shader program?

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM