Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:无法调用';初始';具有类型为';($t3,NSString)和#x27;_Ios_Opengl_Swift - Fatal编程技术网

Ios Swift:无法调用';初始';具有类型为';($t3,NSString)和#x27;

Ios Swift:无法调用';初始';具有类型为';($t3,NSString)和#x27;,ios,opengl,swift,Ios,Opengl,Swift,在第一个函数中,我无法找出我做错了什么。它在行中返回一个错误, 返回compileShader(GLenum(GL_VERTEX_SHADER),ShaderCode)错误是无法使用“($t3,NSString)”类型的参数列表调用“init” class ShaderHelper{ class func compileVertexShader(ShaderCode: NSString) ->GLint{ return compileShader(GLenum(G

在第一个函数中,我无法找出我做错了什么。它在行中返回一个错误, 返回compileShader(GLenum(GL_VERTEX_SHADER),ShaderCode)错误是无法使用“($t3,NSString)”类型的参数列表调用“init”

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;
    }

这里的问题不在于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提供了很多在调试时没有意义的信息。您应该仔细选择参数类型和返回类型,这应该没问题。

感谢
var compileStatus=GLint()
,这并不明显。