Teacherbot
31 Jan, 15:15:16
)
glDetachShader(shaderProgram, vertShader)
glDetachShader(shaderProgram, fragShader)
return shaderProgram }
func obtainUniform(_ shaderProgram: GLuint, _ uniformName: String) -> GLint {
let uniformLocation = glGetUniformLocation(shaderProgram, uniformName)
if uniformLocation == -1 {
return -1
}
return uniformLocation
}
func setXYZUniform(_ shaderProgram: GLuint, _ unifromName: String, _ x: GLfloat, _ y: GLfloat, _ z: GLfloat) {
let xyzLocation = obtainUniform(shaderProgram, unifromName)
glUniform3f(xyzLocation, x, y, z)
}
func setMat4Uniform(_ shaderProgram: GLuint, _ unifromName: String, _ mat4x4: [GLfloat]) {
let mat4Location = obtainUniform(shaderProgram, unifromName)
glUniformMatrix4fv(mat4Location, 1, GLboolean(GL_FALSE), mat4x4)
}
func set1fUniform(_ shaderProgram: GLuint, _ unifromName: String, _ v: GLfloat) {
let location = obtainUniform(shaderProgram, unifromName)
glUniform1f(location, v)
}
func set3fUniform(_ shaderProgram: GLuint, _ unifromName: String, _ v1: GLfloat, _ v2: GLfloat, _ v3: GLfloat) {
let location = obtainUniform(shaderProgram, unifromName)
glUniform3f(location, v1, v2, v3)
}
func setVec3Uniform(_ shaderProgram: GLuint, _ unifromName: String, _ xyz: [GLfloat]) {
let vec3Location = obtainUniform(shaderProgram, unifromName)
glUniform3f(vec3Location, xyz[0], xyz[1], xyz[2])
}
func set1iUniform(_ shaderProgram: GLuint, _ unifromName: String, _ v: GLint) {
let location = obtainUniform(shaderProgram, unifromName)
glUniform1i(location, v)
}
}
Loading...