Пример #1
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
}
Пример #2
0
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))
	}
}
Пример #3
0
func GetActiveUniform(program, index uint, bufsize int) (size int32, type_ uint32, name string) {
	cs := CString(name)
	defer C.free(unsafe.Pointer(cs))
	C.glGetActiveUniform(C.GLuint(program), C.GLuint(index),
		C.GLsizei(bufsize), nil, (*C.GLint)(&size), (*C.GLenum)(&type_), cs)
	name = GoString(cs)
	return

}
Пример #4
0
func GetActiveUniform(p Program, index uint32) (name string, size int, ty Enum) {
	bufSize := GetProgrami(p, ACTIVE_UNIFORM_MAX_LENGTH)
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)

	var cSize C.GLint
	var cType C.GLenum

	C.glGetActiveUniform(p.c(), C.GLuint(index), C.GLsizei(bufSize), nil, &cSize, &cType, (*C.GLchar)(buf))
	return C.GoString((*C.char)(buf)), int(cSize), Enum(cType)
}
Пример #5
0
func (program Program) GetActiveUniform(index UniformLocation) (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.glGetActiveUniform(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)
}
Пример #6
0
func GetActiveUniform(p Program, u Uniform) (name string, size int, ty Enum) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.GetActiveUniform(%v, %v) (%v, %v, %v) %v", p, u, name, size, ty, errstr)
	}()
	bufSize := GetProgrami(p, ACTIVE_UNIFORM_MAX_LENGTH)
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)
	var cSize C.GLint
	var cType C.GLenum
	C.glGetActiveUniform(p.c(), C.GLuint(u.Value), C.GLsizei(bufSize), nil, &cSize, &cType, (*C.GLchar)(buf))
	return C.GoString((*C.char)(buf)), int(cSize), Enum(cType)
}
Пример #7
0
func GetActiveUniform(
	program uint32, index uint32, bufsize Sizei,
	length *Sizei, size *int32, type_ *Enum, name *string) {
	s := glString(*name)
	C.glGetActiveUniform(
		C.GLuint(program),
		C.GLuint(index),
		C.GLsizei(bufsize),
		(*C.GLsizei)(length),
		(*C.GLint)(size),
		(*C.GLenum)(type_),
		s)
	name = goString(s)
}
Пример #8
0
// glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
func (program Program) GetActiveUniform(index int) (
	Size int, Type GLenum, Name string) {
	// Maximum length of active uniform name in program
	bufSize := program.Get(ACTIVE_UNIFORM_MAX_LENGTH)
	nameBuf := C.malloc(C.size_t(bufSize))
	defer C.free(nameBuf)
	var size C.GLint
	C.glGetActiveUniform(
		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
}