我找不到我的 GLSL 代码哪里错了?

I can't find where is wrong of my GLSL code?

我是一名 iOS 开发人员,使用 Xcode 编译一些 GLSL 代码。 shaderv.vsh 代码如下:

attribute vec4 position;
attribute vec4 positionColor;
attribute vec2 textCoordinate;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
varying lowp vec2 varyTextCoord;
varying lowp vec4 varyColor;

void main() {
    varyTextCoord = textCoordinate;
    varyColor = positionColor;

    vec4 vPos;
    vPos = projectionMatrix * modelViewMatrix * position;
    gl_Position = vPos;
}

shaderf.fsh 代码如下:

precision lowp float;

varying lowp vec2 varyTextCoord;
varying lowp vec4 varyColor;
uniform sampler2D colorMap;

void main() {
    vec4 cs = texture2D(colorMap,varyTextCoord);
    vec4 cd = varyColor;
    float s = 0.2;
    float d = 0.5;
    vec4 color = (cs * s) + (cd * d);
    gl_FragColor = color;
}

编译这段代码时,会出现一些错误:

ERROR: 0:15: 'premature EOF' : syntax error syntax error

ERROR: 0:5: 'premature EOF' : syntax error syntax error

我找不到哪里错了。困扰我很久了。帮帮我!

我已经解决了这个问题。我的 shader 代码是正确的。一个swift函数我用错了

let content = try? String(contentsOfFile: file, encoding: String.Encoding.utf8)
var source = UnsafePointer<GLchar>(content)
shader = glCreateShader(type)

glShaderSource(shader, 1,&source, nil)

当编译 shader 字符串时,我应该将它转换为 cString。

let content = try? String(contentsOfFile: file, encoding: String.Encoding.utf8)
let contentCString = content?.cString(using: .utf8)
var source = UnsafePointer<GLchar>(contentCString)

感谢大家指点我