Esempio n. 1
0
File: main.go Progetto: andrebq/exp
// Load the shader only if it have been modified
func loadShaders(oldProgram gl.Program, last *shaderInfo) (gl.Program, *shaderInfo, error) {
	if last != nil {
		newInfo, err := loadShaderInfoIfNew("sample", last.vertMod, last.fragMod)
		if err != nil {
			return oldProgram, last, err
		}
		if newInfo == nil {
			// nothing new, can reuse the old code
			return oldProgram, last, nil
		} else {
			newProgram, err := createProgram(newInfo)
			if err != nil {
				return oldProgram, last, err
			}
			oldProgram.Delete()
			return newProgram, newInfo, err
		}
	}
	last, err := loadShaderInfo("sample")
	if err != nil {
		return oldProgram, last, err
	}
	oldProgram, err = createProgram(last)

	return oldProgram, last, err
}
Esempio n. 2
0
func bufferSetUp(buffer bufferSetUpInt, program gl.Program) {
	buffer.gen()
	buffer.bind()
	// Collect the attrib locations for each attrib name.
	atts_names := buffer.names() // Expected GLSL variable names.
	atts := make([]gl.AttribLocation, len(atts_names))
	for i, att_name := range atts_names {
		atts[i] = program.GetAttribLocation(att_name)
		if err := CheckGlError(); err != nil {
			err.Description = fmt.Sprintf("program.GetAttribLocation(%#v)", att_name)
			panic(err)
		}
		if atts[i] == -1 {
			panic(fmt.Sprintf("attrib location %#v not found", att_name))
		}
	}
	// Now that the locations are known, we can relate them to vertex data.
	buffer.attribPointers(atts)
	buffer.unbind()
}
Esempio n. 3
0
func (unif *UniformsLocInstanced) SetUp(program gl.Program) {
	const L = len(unif.ubis)
	ubiNames := [L]string{"GlobalMatrices", "GlobalLights"}
	ubiPoints := [L]uint{CameraUboBindingPoint, LightUboBindingPoint}

	for i := 0; i < L; i++ {
		unif.ubis[i] = program.GetUniformBlockIndex(ubiNames[i])
		if err := CheckGlError(); err != nil {
			err.Description = fmt.Sprintf("GetUniformBlockIndex(%#v)", ubiNames[i])
			panic(err)
		}
		if unif.ubis[i] == gl.INVALID_INDEX {
			panic(fmt.Sprintf("GetUniformBlockIndex(%#v) returned INVALID_INDEX", ubiNames[i]))
		}

		program.UniformBlockBinding(unif.ubis[i], ubiPoints[i])
		if err := CheckGlError(); err != nil {
			err.Description = "UniformBlockBinding"
			panic(err)
		}
	}

	unif.textureLoc = program.GetUniformLocation("environment_map")
	if err := CheckGlError(); err != nil {
		err.Description = "GetUniformLocation(environment)"
		panic(err)
	}
	if unif.textureLoc == -1 {
		panic("environment uniform not found")
	}
}
Esempio n. 4
0
func (unif *UniformsLoc) SetUp(program gl.Program) {
	const modelLocName = "model_to_eye"
	const matricesUbiName = "GlobalMatrices"

	unif.modelLoc = program.GetUniformLocation(modelLocName)
	if err := CheckGlError(); err != nil {
		err.Description = fmt.Sprintf("program.GetUniformLocation(%#v)", modelLocName)
		panic(err)
	}
	if unif.modelLoc == -1 {
		panic(fmt.Sprintf("uniform %#v not found", modelLocName))
	}

	unif.globalMatricesUbi = program.GetUniformBlockIndex(matricesUbiName)
	if err := CheckGlError(); err != nil {
		err.Description = fmt.Sprintf("GetUniformBlockIndex(%#v)", matricesUbiName)
		panic(err)
	}
	if unif.globalMatricesUbi == gl.INVALID_INDEX {
		panic(fmt.Sprintf("GetUniformBlockIndex(%#v) returned INVALID_INDEX", matricesUbiName))
	}
	program.UniformBlockBinding(unif.globalMatricesUbi, CameraUboBindingPoint)
	if err := CheckGlError(); err != nil {
		err.Description = "UniformBlockBinding"
		panic(err)
	}
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
func validateProgram(program gl.Program) {
	program.Validate()
	if err := CheckGlError(); err != nil {
		err.Description = "program.Validate failed"
		panic(err)
	}
	status := program.Get(gl.VALIDATE_STATUS)
	if err := CheckGlError(); err != nil {
		err.Description = "program.Get(VALIDATE_STATUS) failed"
		panic(err)
	}
	if status == gl.FALSE {
		infolog := program.GetInfoLog()
		gl.GetError() // Clear error flag if infolog derped.
		panic(fmt.Errorf("program validation failed with log: %v", infolog))
	}
}
Esempio n. 6
0
// renderBuffered uses VBO's. This is the preferred mode for systems
// where shader support is not present or deemed necessary.
func (mb *MeshBuffer) renderBuffered(mode gl.GLenum, m Mesh, program gl.Program) {
	is, ic := m[mbIndexKey][0], m[mbIndexKey][1]

	program.Use()
	var attribLocation gl.AttribLocation
	for _, value := range mb.attr {
		if value.name == "index" {
			continue
		}
		value.bind()
		if value.Invalid() {
			value.buffer()
		}

		attribLocation = program.GetAttribLocation(value.name)
		attribLocation.EnableArray()
		attribLocation.AttribPointer(value.size, value.typ, false, 0, uintptr(0))
		value.unbind()
	}

	ia := mb.find(mbIndexKey)
	ia.bind()
	if ia.Invalid() {
		ia.buffer()
	}

	gl.DrawElements(mode, ic, ia.typ, uintptr(is*ia.stride))
	ia.unbind()

	for _, value := range mb.attr {
		if value.name == "index" {
			continue
		}
		attribLocation := program.GetAttribLocation(value.name)
		attribLocation.DisableArray()
	}

}