Пример #1
0
func (shader *Shader) loadVolatile() bool {
	vert := compileCode(gl.VERTEX_SHADER, shader.vertex_code)
	frag := compileCode(gl.FRAGMENT_SHADER, shader.pixel_code)
	shader.program = gl.CreateProgram()
	shader.texUnitPool = make(map[string]int)
	shader.activeTexUnits = make([]gl.Texture, maxTextureUnits)

	gl.AttachShader(shader.program, vert)
	gl.AttachShader(shader.program, frag)

	gl.BindAttribLocation(shader.program, attrib_pos, "VertexPosition")
	gl.BindAttribLocation(shader.program, attrib_texcoord, "VertexTexCoord")
	gl.BindAttribLocation(shader.program, attrib_color, "VertexColor")
	gl.BindAttribLocation(shader.program, attrib_constantcolor, "ConstantColor")

	gl.LinkProgram(shader.program)
	gl.DeleteShader(vert)
	gl.DeleteShader(frag)

	if gl.GetProgrami(shader.program, gl.LINK_STATUS) == 0 {
		gl.DeleteProgram(shader.program)
		panic(fmt.Errorf("shader link error: %s", gl.GetProgramInfoLog(shader.program)))
	}

	shader.mapUniforms()

	return true
}
Пример #2
0
func compileCode(shaderType gl.Enum, src string) gl.Shader {
	shader := gl.CreateShader(shaderType)
	if !shader.Valid() {
		panic(fmt.Errorf("could not create shader (type %v)", shaderType))
	}
	gl.ShaderSource(shader, src)
	gl.CompileShader(shader)
	if gl.GetShaderi(shader, gl.COMPILE_STATUS) == 0 {
		defer gl.DeleteShader(shader)
		panic(fmt.Errorf("shader compile: %s", gl.GetShaderInfoLog(shader)))
	}
	return shader
}