func (program Program) GetUniformLocation(name string) UniformLocation { cname := glString(name) defer freeString(cname) return UniformLocation(C.glGetUniformLocation(C.GLuint(program), cname)) }
// Link links the attached shader objects func (p *Program) Link() error { var val, val2 C.GLint C.glLinkProgram(p.i) C.glGetProgramiv(p.i, LINK_STATUS, &val) if val != TRUE { C.glGetProgramiv(p.i, INFO_LOG_LENGTH, &val) buf := make([]C.GLchar, val+1) C.glGetProgramInfoLog(p.i, C.GLsizei(val), nil, &buf[0]) return errors.New(C.GoString((*C.char)(&buf[0]))) } p.attr = make(map[string]C.GLuint) C.glGetProgramiv(p.i, ACTIVE_ATTRIBUTES, &val) C.glGetProgramiv(p.i, ACTIVE_ATTRIBUTE_MAX_LENGTH, &val2) buf := make([]C.char, val2) for i := C.GLuint(0); i < C.GLuint(val); i++ { C.glGetActiveAttrib(p.i, i, C.GLsizei(val2), nil, nil, nil, (*C.GLchar)(&buf[0])) p.attr[C.GoString(&buf[0])] = C.GLuint(C.glGetAttribLocation(p.i, (*C.GLchar)(&buf[0]))) } p.uni = make(map[string]C.GLint) C.glGetProgramiv(p.i, ACTIVE_UNIFORMS, &val) C.glGetProgramiv(p.i, ACTIVE_UNIFORM_MAX_LENGTH, &val2) buf = make([]C.char, val2) for i := C.GLuint(0); i < C.GLuint(val); i++ { C.glGetActiveUniform(p.i, i, C.GLsizei(val2), nil, nil, nil, (*C.GLchar)(&buf[0])) p.uni[C.GoString(&buf[0])] = C.glGetUniformLocation(p.i, (*C.GLchar)(&buf[0])) } return nil }
func (program *Program) GetUniform(name string) Uniform { cname := (*C.GLchar)(C.CString(name)) defer C.free(unsafe.Pointer(cname)) loc := C.GLint(C.glGetUniformLocation(program.id, cname)) if loc < 0 { panic(fmt.Errorf("not an active uniform: %s", name)) } datatype := C.GLenum(0) length := C.GLsizei(0) size := C.GLint(0) uname := [32]byte{} C.glGetActiveUniform(program.id, C.GLuint(loc), C.GLsizei(len(uname)), &length, &size, &datatype, (*C.GLchar)(unsafe.Pointer(&uname[0]))) switch datatype { case C.GL_FLOAT: return Uniform1f{uniformBase{loc}} case C.GL_FLOAT_VEC2: return Uniform2f{uniformBase{loc}} case C.GL_FLOAT_VEC3: return Uniform3f{uniformBase{loc}} case C.GL_FLOAT_VEC4: return Uniform4f{uniformBase{loc}} case C.GL_INT: return Uniform1i{uniformBase{loc}} case C.GL_INT_VEC2: return Uniform2i{uniformBase{loc}} case C.GL_INT_VEC3: return Uniform3i{uniformBase{loc}} case C.GL_INT_VEC4: return Uniform4i{uniformBase{loc}} case C.GL_BOOL: return Uniform1i{uniformBase{loc}} case C.GL_BOOL_VEC2: return Uniform2i{uniformBase{loc}} case C.GL_BOOL_VEC3: return Uniform3i{uniformBase{loc}} case C.GL_BOOL_VEC4: return Uniform4i{uniformBase{loc}} case C.GL_FLOAT_MAT2: return UniformMatrix2f{uniformBase{loc}} case C.GL_FLOAT_MAT3: return UniformMatrix3f{uniformBase{loc}} case C.GL_FLOAT_MAT4: return UniformMatrix4f{uniformBase{loc}} case C.GL_SAMPLER_2D: return Uniform1i{uniformBase{loc}} case C.GL_SAMPLER_CUBE: return Uniform1i{uniformBase{loc}} default: panic(fmt.Errorf("unsupported uniform type: %#x", datatype)) } }
func uniformLocation(prog C.GLuint, name string) int { nameC := C.CString(name) defer C.free(unsafe.Pointer(nameC)) attrib := int(C.glGetUniformLocation(C.GLuint(prog), (*C.GLchar)(unsafe.Pointer(nameC)))) checkGLError() if attrib == -1 { panic(fmt.Errorf("Failed to find attrib position for %v", name)) } return attrib }
func GetUniformLocation(p Program, name string) (r0 Uniform) { defer func() { errstr := errDrain() r0.name = name log.Printf("gl.GetUniformLocation(%v, %v) %v%v", p, name, r0, errstr) }() str := C.CString(name) defer C.free((unsafe.Pointer)(str)) return Uniform{Value: int32(C.glGetUniformLocation(p.c(), (*C.GLchar)(str)))} }
func GetUniformLocation(p Program, name string) Uniform { str := unsafe.Pointer(C.CString(name)) defer C.free(str) return Uniform{Value: int32(C.glGetUniformLocation(p.c(), (*C.GLchar)(str)))} }
func GetUniformLocation(program uint32, name string) uintptr { s := glString(name) return uintptr(C.glGetUniformLocation( C.GLuint(program), s)) }
// GetUniformLocation returns the location of a uniform variable. func (p Program) GetUniformLocation(name string) Uniform { cstr := C.CString(name) defer C.free(unsafe.Pointer(cstr)) l := C.glGetUniformLocation(C.GLuint(p), (*C.GLchar)(cstr)) return Uniform(l) }
func GetUniformLocation(program uint, name string) int { s := CString(name) defer C.free(unsafe.Pointer(s)) return int(C.glGetUniformLocation(C.GLuint(program), s)) }