예제 #1
0
파일: shader.go 프로젝트: jackscan/go-gles3
func (program *Program) GetAttrib(name string) VertexAttrib {

	cname := (*C.GLchar)(C.CString(name))
	defer C.free(unsafe.Pointer(cname))

	iloc := C.glGetAttribLocation(program.id, cname)
	if iloc < 0 {
		panic(fmt.Errorf("not an active attribute: %s", name))
	}

	loc := C.GLuint(iloc)

	datatype := C.GLenum(0)
	length := C.GLsizei(0)
	size := C.GLint(0)

	aname := [32]byte{}

	C.glGetActiveAttrib(program.id, C.GLuint(loc), C.GLsizei(len(aname)), &length, &size, &datatype, (*C.GLchar)(unsafe.Pointer(&aname[0])))

	switch datatype {
	case C.GL_FLOAT:
		return FloatAttrib{vattrib{loc}}
	case C.GL_FLOAT_VEC2:
		return Vec2Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC3:
		return Vec3Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC4:
		return Vec4Attrib{FloatAttrib{vattrib{loc}}}
	default:
		panic(fmt.Errorf("unsupported attribute type: %#x", datatype))
	}
}
예제 #2
0
파일: gl.go 프로젝트: extrame/gl
// 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
}
예제 #3
0
파일: program.go 프로젝트: kanelbulle/gl
func (program Program) GetAttribLocation(name string) AttribLocation {

	cname := glString(name)
	defer freeString(cname)

	return AttribLocation(C.glGetAttribLocation(C.GLuint(program), cname))
}
예제 #4
0
파일: shader.go 프로젝트: jackscan/go-gles2
func (program *Program) GetAttrib(name string) VertexAttrib {

	cname := (*C.GLchar)(C.CString(name))
	defer C.free(unsafe.Pointer(cname))

	iloc := C.glGetAttribLocation(program.id, cname)
	if iloc < 0 {
		panic(fmt.Errorf("not an active uniform: %s", name))
	}

	loc := C.GLuint(iloc)

	datatype := C.GLenum(0)
	C.glGetActiveAttrib(program.id, C.GLuint(loc), 0, nil, nil, &datatype, nil)

	switch datatype {
	case C.GL_FLOAT:
		return FloatAttrib{vattrib{loc}}
	case C.GL_FLOAT_VEC2:
		return Vec2Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC3:
		return Vec3Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC4:
		return Vec4Attrib{FloatAttrib{vattrib{loc}}}
	default:
		panic(fmt.Errorf("unsupported attribute type: %#x", datatype))
	}
}
예제 #5
0
func attribLocation(prog C.GLuint, name string) int {
	nameC := C.CString(name)
	defer C.free(unsafe.Pointer(nameC))
	attrib := int(C.glGetAttribLocation(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
}
예제 #6
0
파일: gldebug.go 프로젝트: Miaque/mojo
func GetAttribLocation(p Program, name string) (r0 Attrib) {
	defer func() {
		errstr := errDrain()
		r0.name = name
		log.Printf("gl.GetAttribLocation(%v, %v) %v%v", p, name, r0, errstr)
	}()
	str := unsafe.Pointer(C.CString(name))
	defer C.free(str)
	return Attrib{Value: uint(C.glGetAttribLocation(p.c(), (*C.GLchar)(str)))}
}
예제 #7
0
파일: gl_opengles.go 프로젝트: tanema/amore
func GetAttribLocation(p Program, name string) Attrib {
	str := unsafe.Pointer(C.CString(name))
	defer C.free(str)
	return Attrib{Value: uint(C.glGetAttribLocation(p.c(), (*C.GLchar)(str)))}
}
예제 #8
0
파일: gles2.go 프로젝트: remogatto/egles
func GetAttribLocation(program uint32, name *string) uintptr {
	s := glString(*name)
	return uintptr(C.glGetAttribLocation(
		C.GLuint(program),
		s))
}
예제 #9
0
func GetAttribLocation(program uint32, name string) int {
	s := glString(name)
	return int(C.glGetAttribLocation(
		C.GLuint(program),
		s))
}
예제 #10
0
파일: shader.go 프로젝트: eaburns/gl
// GetAttribLocation returns the location of an attribute variable.
func (p Program) GetAttribLocation(name string) VertexAttribArray {
	cstr := C.CString(name)
	defer C.free(unsafe.Pointer(cstr))
	l := C.glGetAttribLocation(C.GLuint(p), (*C.GLchar)(cstr))
	return VertexAttribArray(l)
}
예제 #11
0
파일: es2.go 프로젝트: nick-fedesna/egles
func GetAttribLocation(program uint, name string) int {
	s := CString(name)
	defer C.free(unsafe.Pointer(s))
	return int(C.glGetAttribLocation(C.GLuint(program), s))
}