GLSL 给出奇怪的错误:仅在 Mac 上"#version required and missing"



我有一个奇怪的,非常令人沮丧的问题。我有一个在Windows和Linux上运行良好的着色器。当我把它搬到我的mac电脑上时,它会出现严重的错误和黑屏。

// Vertex - THIS COMMENT DOES NOT EXIST IN ACTUAL SHADER. ACTUAL STARTS AT #version 150 
#version 410
in highp vec4 vertex;
in mediump vec3 normal;
uniform mediump mat4 matrix; // MVP
uniform mediump vec3 col; // The color in question
uniform highp vec4 lightPosition;
uniform highp vec3 La; // Ambient
uniform highp vec3 Ld; // diffuse
uniform highp vec3 Ls; // Specular
uniform highp vec3 Ka; // Ambient Reflectivity
uniform highp vec3 Kd; // Diffuse Reflectivity
uniform highp vec3 Ks; // Specular Reflectivity
uniform float Shininess; // Specular Shininess factor
uniform mediump mat4 ModelViewMatrix;
uniform mediump mat3 NormalMatrix;
out mediump vec3 LightIntensity;
out mediump vec4 color;
void main()
{
    color = vec4(col * 0.2 + col * 0.8, 1.0);
    color = clamp(color, 0.0, 1.0);
    vec3 tnorm = normalize( NormalMatrix * normal);
    vec4 eyeCoords = ModelViewMatrix * vertex;
    vec3 s = normalize(vec3(lightPosition - eyeCoords));
    vec3 v = normalize(-eyeCoords.xyz);
    vec3 r = reflect( -s, tnorm );
    float sDotN = max( dot(s,tnorm), 0.0 );
    vec3 ambient = La * Ka;
    vec3 diffuse = Ld * Kd * sDotN;
    vec3 spec = vec3(0.0);
    if( sDotN > 0.0 )
       spec = Ls * Ks *
           pow( max( dot(r,v), 0.0 ), Shininess );
    LightIntensity = ambient + diffuse + spec;
    gl_Position = matrix * vertex;
}
//fragment
#version 410
in mediump vec4 color;
in mediump vec3 LightIntensity;
out vec4 out_Color;
void main(void)
{
    out_Color =  vec4(LightIntensity, 1.0) * color;
}

// error
QGLShader::compile(Vertex): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:11: 'attribute' : syntax error syntax error
Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile
QGLShader::compile(Fragment): ERROR: 0:1: '' :  #version required and missing.
Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile
QGLShader::link: "ERROR: One or more attached shaders not successfully compiled
"
Errors linking simple shader: ERROR: One or more attached shaders not successfully compiled
QGLShader::compile(Vertex): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:5: 'attribute' : syntax error syntax error
Vertex shader for blitShaderProg (MainWithTexCoordsVertexShader & UntransformedPositionVertexShader) failed to compile
QGLShader::compile(Fragment): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:11: 'varying' : syntax error syntax error
Fragment shader for blitShaderProg (MainFragmentShader & ImageSrcFragmentShader) failed to compile
QGLShader::link: "ERROR: One or more attached shaders not successfully compiled
"
Errors linking blit shader: ERROR: One or more attached shaders not successfully compiled

// C++
QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);

    vshader1->compileSourceFile(":shaders/vert1.vert");
    QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
    fshader1->compileSourceFile(":shaders/frag1.frag");
    program1.addShader(vshader1);
    program1.addShader(fshader1);
    program1.link();

如果我输入version #version 150或#version 410它会报错没有指定#version。如果我指定#version 130或#version 350,它会抱怨我请求的是无效版本(它不应该恢复到可用版本吗?)

知道是怎么回事吗?这尤其令人恼火,因为我指定了一个#version,并且没有使用变量关键字。

我相信#version 150 core应该出现在着色器文件的顶部,在它之后有一个空行,并参考core, legacyes

相关内容

最新更新