func (s *gl32Shader) buildUniformList() { s.uniforms = make(Parameters, 4) s.PreRender(nil) var uniformCount gl.Int gl.GetProgramiv(s.program, gl.ACTIVE_UNIFORMS, &uniformCount) uniformName := gl.GLStringAlloc(128) defer gl.GLStringFree(uniformName) textureUnit := 0 for i := 0; i < int(uniformCount); i++ { var uniformType gl.Enum var uniformSize gl.Int var nameLength gl.Sizei gl.GetActiveUniform(s.program, gl.Uint(i), 128, &nameLength, &uniformSize, &uniformType, uniformName) // Ignore build in uniforms if !strings.HasPrefix(gl.GoString(uniformName), "gl_") { location := gl.GetUniformLocation(s.program, uniformName) if uniformType == gl.SAMPLER_2D { gl.Uniform1i(location, gl.Int(textureUnit)) textureUnit++ } if validUniformTypes[uniformType] { s.uniforms = append(s.uniforms, newGL32Uniform(location, glToUniform[uniformType], gl.GoStringN(uniformName, nameLength))) } } } }
func compileShader(code string, shaderType gl.Enum) (gl.Uint, error) { shader := gl.CreateShader(shaderType) glCode := gl.GLString(code) defer gl.GLStringFree(glCode) gl.ShaderSource(shader, 1, &glCode, nil) gl.CompileShader(shader) var status gl.Int gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status) if status == 0 { var logLength gl.Int gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength) msg := gl.GLStringAlloc(gl.Sizei(logLength)) defer gl.GLStringFree(msg) gl.GetShaderInfoLog(shader, gl.Sizei(logLength), nil, msg) gl.DeleteShader(shader) return 0, errors.New(gl.GoString(msg)) } return shader, nil }