Exemple #1
0
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))
	}
}
Exemple #2
0
Fichier : gl.go Projet : 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
}
Exemple #3
0
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))
	}
}
Exemple #4
0
func GetActiveAttrib(program, index uint, bufsize int) (size int32, type_ uint32, name string) {
	cs := CString(name)
	defer C.free(unsafe.Pointer(cs))
	C.glGetActiveAttrib(C.GLuint(program), C.GLuint(index),
		C.GLsizei(bufsize), nil, (*C.GLint)(&size), (*C.GLenum)(&type_), cs)
	name = GoString(cs)
	return

}
Exemple #5
0
func GetActiveAttrib(p Program, index uint32) (name string, size int, ty Enum) {
	bufSize := GetProgrami(p, ACTIVE_ATTRIBUTE_MAX_LENGTH)
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)

	var cSize C.GLint
	var cType C.GLenum
	C.glGetActiveAttrib(p.c(), C.GLuint(index), C.GLsizei(bufSize), nil, &cSize, &cType, (*C.GLchar)(buf))
	return C.GoString((*C.char)(buf)), int(cSize), Enum(cType)
}
Exemple #6
0
func (program Program) GetActiveAttrib(index AttribLocation) (string, GLenum, int) {
	var written C.GLsizei
	var size C.GLint
	var tp C.GLenum
	//Allocate a buffer of 64 characters to write variable names to
	var buffer *C.GLchar = (*C.GLchar)(C.malloc(64))
	defer freeString(buffer)

	C.glGetActiveAttrib(C.GLuint(program), C.GLuint(index), C.GLsizei(128), &written, &size, &tp, buffer)
	return C.GoStringN((*C.char)(buffer), C.int(written)), GLenum(tp), int(size)
}
Exemple #7
0
func GetActiveAttrib(p Program, a Attrib) (name string, size int, ty Enum) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.GetActiveAttrib(%v, %v) (%v, %v, %v) %v", p, a, name, size, ty, errstr)
	}()
	bufSize := GetProgrami(p, ACTIVE_ATTRIBUTE_MAX_LENGTH)
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)
	var cSize C.GLint
	var cType C.GLenum
	C.glGetActiveAttrib(p.c(), a.c(), C.GLsizei(bufSize), nil, &cSize, &cType, (*C.GLchar)(buf))
	return C.GoString((*C.char)(buf)), int(cSize), Enum(cType)
}
Exemple #8
0
func GetActiveAttrib(
	program uint32, index uint32, bufsize Sizei,
	length *Sizei, size *int32, type_ *Enum, name *string) {
	s := glString(*name)
	C.glGetActiveAttrib(
		C.GLuint(program),
		C.GLuint(index),
		C.GLsizei(bufsize),
		(*C.GLsizei)(length),
		(*C.GLint)(size),
		(*C.GLenum)(type_),
		s)
	name = goString(s)
}
Exemple #9
0
// glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
func (program Program) GetActiveAttrib(index int) (
	Size int, Type GLenum, Name string) {
	// Maximum length of active uniform name in program
	bufSize := program.Get(ACTIVE_ATTRIBUTE_MAX_LENGTH)
	nameBuf := C.malloc(C.size_t(bufSize))
	defer C.free(nameBuf)
	var size C.GLint
	C.glGetActiveAttrib(
		C.GLuint(program),
		C.GLuint(index),
		C.GLsizei(bufSize),
		nil, // length == len(Name)
		&size,
		(*C.GLenum)(&Type),
		(*C.GLchar)(nameBuf))
	Name = C.GoString((*C.char)(nameBuf))
	Size = int(size)
	return
}