Swift: cannot call 'init' with an argument list of type '($ t3, NSString)'

In the first function, I cannot understand what I am doing wrong. It returns an error in a string, return compileShader (GLenum (GL_VERTEX_SHADER), ShaderCode) Error Unable to call 'init' using argument list of type '($ 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;
    }
+4
source share
1 answer

The problem here is not the init method, but as the return type in compileVertexShader and compileShader, while one returns GLInt and the other returns GLuint. If you change them to match, your error should disappear.

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

. , .

+5

All Articles