func (shader *Shader) loadVolatile() bool { vert := compileCode(gl.VERTEX_SHADER, shader.vertex_code) frag := compileCode(gl.FRAGMENT_SHADER, shader.pixel_code) shader.program = gl.CreateProgram() shader.texUnitPool = make(map[string]int) shader.activeTexUnits = make([]gl.Texture, maxTextureUnits) gl.AttachShader(shader.program, vert) gl.AttachShader(shader.program, frag) gl.BindAttribLocation(shader.program, attrib_pos, "VertexPosition") gl.BindAttribLocation(shader.program, attrib_texcoord, "VertexTexCoord") gl.BindAttribLocation(shader.program, attrib_color, "VertexColor") gl.BindAttribLocation(shader.program, attrib_constantcolor, "ConstantColor") gl.LinkProgram(shader.program) gl.DeleteShader(vert) gl.DeleteShader(frag) if gl.GetProgrami(shader.program, gl.LINK_STATUS) == 0 { gl.DeleteProgram(shader.program) panic(fmt.Errorf("shader link error: %s", gl.GetProgramInfoLog(shader.program))) } shader.mapUniforms() return true }
func (shader *Shader) mapUniforms() { // Built-in uniform locations default to -1 (nonexistent.) shader.uniforms = map[string]uniform{} for i := 0; i < gl.GetProgrami(shader.program, gl.ACTIVE_UNIFORMS); i++ { u := uniform{} u.Name, u.Count, u.Type = gl.GetActiveUniform(shader.program, uint32(i)) u.Location = gl.GetUniformLocation(shader.program, u.Name) u.CalculateTypeInfo() // glGetActiveUniform appends "[0]" to the end of array uniform names... if len(u.Name) > 3 { if strings.Contains(u.Name, "[0]") { u.Name = u.Name[:len(u.Name)-3] } } if u.Location.Value != -1 { shader.uniforms[u.Name] = u } } }