我正在尝试将 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.
关于c - 整数不作为对 Swift 中函数的引用传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29753783/