示例#1
0
文件: shader.go 项目: tanema/amore
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
文件: shader.go 项目: tanema/amore
func (shader *Shader) unloadVolatile() {
	// active texture list is probably invalid, clear it
	gl.DeleteProgram(shader.program)

	// decrement global texture id counters for texture units which had textures bound from this shader
	for i := 0; i < len(shader.activeTexUnits); i++ {
		if shader.activeTexUnits[i].Valid() {
			gl_state.textureCounters[i] = gl_state.textureCounters[i] - 1
		}
	}
}