Esempio n. 1
0
func ShaderSource(s Shader, src string) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.ShaderSource(%v, %v) %v", s, src, errstr)
	}()
	str := (*C.GLchar)(C.CString(src))
	defer C.free(unsafe.Pointer(str))
	C.glShaderSource(s.c(), 1, &str, nil)
}
Esempio n. 2
0
File: shader.go Progetto: vivicai/gl
func (shader Shader) Source(source string) {

	csource := glString(source)
	defer freeString(csource)

	var one C.GLint = C.GLint(len(source))

	C.glShaderSource(C.GLuint(shader), 1, &csource, &one)
}
Esempio n. 3
0
func ShaderSource(
	shader uint32, count Sizei,
	string_ *string, length *int32) {
	s := glString(*string_)
	C.glShaderSource(
		C.GLuint(shader),
		C.GLsizei(count),
		&s,
		(*C.GLint)(length))
	string_ = goString(s)
}
Esempio n. 4
0
File: shader.go Progetto: eaburns/gl
// Source replaces the source code in a shader object.
func (s Shader) Source(src ...string) {
	if len(src) == 0 {
		return
	}
	csrc := make([]*C.GLchar, len(src))
	for i, s := range src {
		csrc[i] = (*C.GLchar)(C.CString(s))
		defer C.free(unsafe.Pointer(csrc[i]))
	}
	C.glShaderSource(C.GLuint(s), C.GLsizei(len(src)), &csrc[0], nil)
}
Esempio n. 5
0
func (shader Shader) Source(source ...string) {
	count := C.GLsizei(len(source))
	cstrings := make([]*C.GLchar, count)
	length := make([]C.GLint, count)

	for i, s := range source {
		csource := glString(s)
		cstrings[i] = csource
		length[i] = C.GLint(len(s))
		defer freeString(csource)
	}

	C.glShaderSource(C.GLuint(shader), count, (**_Ctype_GLchar)(unsafe.Pointer(&cstrings[0])), (*_Ctype_GLint)(unsafe.Pointer(&length[0])))
}
Esempio n. 6
0
File: gl.go Progetto: extrame/gl
// NewShader creates a shader object of type typ, loads it with source code src and compiles it
func NewShader(typ int, src string) (Shader, error) {
	var val C.GLint
	shad := C.glCreateShader(C.GLenum(typ))
	s := (*C.GLchar)(C.CString(src))
	C.glShaderSource(shad, 1, &s, nil)
	C.glCompileShader(shad)
	C.glGetShaderiv(shad, COMPILE_STATUS, &val)
	if val != TRUE {
		C.glGetShaderiv(shad, INFO_LOG_LENGTH, &val)
		buf := make([]C.GLchar, val+1)
		C.glGetShaderInfoLog(shad, C.GLsizei(val), nil, &buf[0])
		C.glDeleteShader(shad)
		return Shader(0), errors.New(C.GoString((*C.char)(&buf[0])))
	}
	return Shader(shad), nil
}
Esempio n. 7
0
func loadShader(shaderType C.GLenum, source string) C.GLuint {
	handle := C.glCreateShader(shaderType)
	if handle == 0 {
		panic(fmt.Errorf("Failed to create shader of type %v", shaderType))
	}
	sourceC := C.CString(source)
	defer C.free(unsafe.Pointer(sourceC))
	C.glShaderSource(handle, 1, (**C.GLchar)(unsafe.Pointer(&sourceC)), (*C.GLint)(unsafe.Pointer(nil)))
	C.glCompileShader(handle)
	var compiled C.GLint
	C.glGetShaderiv(handle, C.GL_COMPILE_STATUS, &compiled)
	if compiled != C.GL_TRUE {
		log := GetShaderInfoLog(handle)
		panic(fmt.Errorf("Failed to compile shader: %v, shader: %v", log, source))
	}
	return handle
}
Esempio n. 8
0
func ShaderSource(s Shader, src string) {
	str := (*C.GLchar)(C.CString(src))
	defer C.free(unsafe.Pointer(str))
	C.glShaderSource(s.c(), 1, &str, nil)
}
Esempio n. 9
0
func (shader Shader) Source(src string) {
	cstr := (*C.GLchar)(C.CString(src))
	defer C.free(unsafe.Pointer(cstr))
	slen := C.GLint(len(src))
	C.glShaderSource(C.GLuint(shader), 1, &cstr, &slen)
}
Esempio n. 10
0
func ShaderSource(shader uint, s string) {
	cs := CString(s)
	defer C.free(unsafe.Pointer(cs))
	C.glShaderSource(C.GLuint(shader), C.GLsizei(1), &cs, nil)
}