Beispiel #1
0
func setupShaders(gl *webgl.Context) *js.Object {
	vs := gl.CreateShader(gl.VERTEX_SHADER)
	gl.ShaderSource(vs, vsSource)
	gl.CompileShader(vs)

	if gl.GetShaderParameter(vs, gl.COMPILE_STATUS).Bool() == false {
		throw(errors.New(gl.GetShaderInfoLog(vs)))
	}

	ps := gl.CreateShader(gl.FRAGMENT_SHADER)
	gl.ShaderSource(ps, psSource)
	gl.CompileShader(ps)

	if gl.GetShaderParameter(ps, gl.COMPILE_STATUS).Bool() == false {
		throw(errors.New(gl.GetShaderInfoLog(ps)))
	}

	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, ps)

	gl.LinkProgram(program)
	gl.UseProgram(program)
	return program
}
Beispiel #2
0
func getShader(gl *webgl.Context, typ int, source string) (*js.Object, bool) {
	shader := gl.CreateShader(typ)

	gl.ShaderSource(shader, source)
	gl.CompileShader(shader)

	if !gl.GetShaderParameter(shader, gl.COMPILE_STATUS).Bool() {
		js.Global.Call("alert", gl.GetShaderInfoLog(shader))
		return nil, false
	}
	return shader, true
}