整数未作为对 Swift 中函数的引用传递

Integer not passing as reference to a function in Swift

我正在尝试将 C 库与 Swift 一起使用。我正在使用 C 函数,所需的参数似乎是一个指针。但它给出了类型无效的错误。

代码如下:

    let shaderString = tempShaderString! as NSString
    let shaderCString = shaderString.UTF8String as UnsafePointer<GLchar>
    var shaderStringLength = GLint(shaderString.length)

    shaderHandle = glCreateShader(GLenum(type))
    glShaderSource(shaderHandle, 1, shaderCString, &shaderStringLength)

我收到此错误:

Cannot invoke glShaderSource with an argument list of type '(GLuint)', Int, UnsafePointer<GLchar>, inout Int32.

请注意 GLint 是 Xcode 中的 Int32

在 C 中,函数参数定义为

(GLuint shader, GLsizei count, const GLchar **string, const GLint *length)

我认为第三个参数 (string) 会有问题。也许您还应该通过 & 传递它以获得双重引用。

注意:

string
Specifies an array of pointers to strings containing the source code to be loaded into the shader.