在第一个函数中,我无法弄清楚我做错了什么。它返回行中的错误, 返回compileShader(GLenum(GL_VERTEX_SHADER),ShaderCode)错误是无法调用' init'使用类型'($ t3,NSString)'
的参数列表class ShaderHelper{
class func compileVertexShader(ShaderCode: NSString) ->GLint{
return compileShader(GLenum(GL_VERTEX_SHADER), ShaderCode)
}
class func compileShader(type: GLenum, shaderCode: NSString) -> GLuint{
var shaderObjectId = glCreateShader(type);
if(shaderObjectId == 0){
if(LoggerConfig.props.On){
println("Could not create new shader!")
}
return 0
}
var shaderStringUTF8 = shaderCode.cStringUsingEncoding(NSUTF8StringEncoding)
var shaderStringLength: GLint = GLint(Int32(shaderCode.length));
glShaderSource(shaderObjectId, 1, &shaderStringUTF8, &shaderStringLength)
glCompileShader(shaderObjectId)
var compileStatus = GLint()
glGetShaderiv(shaderObjectId, GLenum(GL_COMPILE_STATUS), &compileStatus)
if(compileStatus == 0){
if(LoggerConfig.props.On){
println("Compilation of shader failed.")
}
glDeleteShader(shaderObjectId)
return 0
}else if (compileStatus == 1){
if(LoggerConfig.props.On){
println("Compilation Successful")
}
}
return shaderObjectId;
}
答案 0 :(得分:5)
这里的问题不在于init方法而是在compileVertexShader和compileShader中的返回类型,而一个返回GLInt而其他返回GLuint。如果你改变那些匹配,你的错误应该消失。
class ShaderHelper{
class func compileVertexShader(ShaderCode: NSString) ->GLuint{
return compileShader(GLenum(GL_VERTEX_SHADER), shaderCode: ShaderCode)
}
class func compileShader(type: GLenum, shaderCode: NSString) -> GLuint{
var shaderObjectId = glCreateShader(type);
if(shaderObjectId == 0){
if(LoggerConfig.props.On){
println("Could not create new shader!")
}
return 0
}
var shaderStringUTF8 = shaderCode.cStringUsingEncoding(NSUTF8StringEncoding)
var shaderStringLength: GLint = GLint(Int32(shaderCode.length));
glShaderSource(shaderObjectId, 1, &shaderStringUTF8, &shaderStringLength)
glCompileShader(shaderObjectId)
var compileStatus = GLint()
glGetShaderiv(shaderObjectId, GLenum(GL_COMPILE_STATUS), &compileStatus)
if(compileStatus == 0){
if(LoggerConfig.props.On){
println("Compilation of shader failed.")
}
glDeleteShader(shaderObjectId)
return 0
}else if (compileStatus == 1){
if(LoggerConfig.props.On){
println("Compilation Successful")
}
}
return shaderObjectId;
}
错误swift提供了很多调试时没有意义。你应该仔细选择参数类型和返回类型,它应该没问题。