Exemple #1
0
func (me *Program) locationAttr(attrName string) gl.Uint {
	s := gl.Util.CString(attrName)
	defer gl.Util.CStringFree(s)
	l := gl.GetAttribLocation(me.GlHandle, s)
	if l < 0 {
		return progAttrInvalidLoc
	}
	return gl.Uint(l)
}
Exemple #2
0
func (me *FxProc) setProcIndex(index int) {
	if index != me.procIndex {
		me.procIndex = index
		me.unifNames = map[[2]string]string{}
		if me.IsTex() {
			me.Tex.glUnitI = gl.Int(index)
			me.Tex.glUnitU = gl.Uint(index)
			me.Tex.glUnitE = gl.Enum(gl.TEXTURE0 + index)
		}
	}
}
Exemple #3
0
func compileShaders() (err error) {
	var glStatus gl.Int

	makeShader := func(stage gl.Enum, src string) (shader gl.Uint) {
		shader = gl.CreateShader(stage)
		logLastGlError("gl.CreateShader()")
		glStr := gl.Util.CStringArray(src)
		defer gl.Util.CStringArrayFree(glStr)
		gl.ShaderSource(shader, gl.Sizei(len(glStr)), &glStr[0], nil)
		logLastGlError("gl.ShaderSource()")
		gl.CompileShader(shader)
		if gl.GetShaderiv(shader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 {
			panic("Shader compilation failed: " + src)
		}
		return
	}

	glVertShader := makeShader(gl.VERTEX_SHADER, srcVertShader)
	defer gl.DeleteShader(glVertShader)
	glFragShader := makeShader(gl.FRAGMENT_SHADER, srcFragShader)
	defer gl.DeleteShader(glFragShader)

	shaderProg = gl.CreateProgram()
	for stageName, shader := range map[string]gl.Uint{"vert": glVertShader, "frag": glFragShader} {
		gl.AttachShader(shaderProg, shader)
		logLastGlError("gl.AttachShader " + stageName)
		defer gl.DetachShader(shaderProg, shader)
	}

	gl.LinkProgram(shaderProg)
	if gl.GetProgramiv(shaderProg, gl.LINK_STATUS, &glStatus); glStatus == 0 {
		panic("Program linking failed...")
	}

	glAttName := gl.Util.CString("aPos")
	defer gl.Util.CStringFree(glAttName)
	progPosAttrLoc = gl.Uint(gl.GetAttribLocation(shaderProg, glAttName))
	logLastGlError("gl.GetAttribLocation()")

	return
}
func setSupportInfos() {
	//	Extensions
	var num gl.Int
	gl.GetIntegerv(gl.NUM_EXTENSIONS, &num)
	Support.Extensions = make([]string, num)
	if num > 0 {
		for i := gl.Int(0); i < num; i++ {
			Support.Extensions[i] = Util.Stri(gl.EXTENSIONS, gl.Uint(i))
		}
	}

	//	Sampling limits, textures
	// Support.Textures.StreamUpdatesViaPixelBuffer = true
	if Util.Extension("texture_filter_anisotropic") {
		gl.GetFloatv(gl.MAX_TEXTURE_MAX_ANISOTROPY_EXT, &Support.Textures.MaxFilterAnisotropy)
	}
	gl.GetFloatv(gl.MAX_TEXTURE_LOD_BIAS, &Support.Textures.MaxMipLoadBias)
	Support.Textures.ImageUnits.MaxCombined = Util.Val(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS)
	Support.Textures.ImageUnits.MaxFragment = Util.Val(gl.MAX_TEXTURE_IMAGE_UNITS)
	Support.Textures.ImageUnits.MaxGeometry = Util.Val(gl.MAX_GEOMETRY_TEXTURE_IMAGE_UNITS)
	Support.Textures.ImageUnits.MaxVertex = Util.Val(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)

	//	GL version-specifics
	if Support.GlVersion.Is42 {
		Support.Buffers.AtomicCounter, Support.Textures.Immutable = true, true
	}
	if Support.GlVersion.Is43 {
		Support.Textures.ImageUnits.MaxCompute = Util.Val(gl.MAX_COMPUTE_TEXTURE_IMAGE_UNITS)
		Support.Buffers.DispatchIndirect, Support.Buffers.ShaderStorage = true, true
	}

	//	GLSL version-specifics
	if Support.Glsl.Version.Is400 {
		Support.Glsl.Shaders.TessellationStages = true
	}
	if Support.Glsl.Version.Is430 {
		Support.Glsl.Shaders.ComputeStage = true
	}

	Cache.onGlInit()
}