示例#1
0
func MakeTextures(num gl.Sizei, glPtr []gl.Uint, dimensions uint8, texFormat gl.Enum, width, height, depth gl.Sizei) {
	var is3d, is2d = (dimensions == 3), (dimensions == 2)
	var texTarget gl.Enum = gltypes.Ife(is3d, gl.TEXTURE_3D, gltypes.Ife(is2d, gl.TEXTURE_2D, gl.TEXTURE_1D))
	gl.GenTextures(num, &glPtr[0])
	PanicIfErrors("MakeTextures.GenTextures(num=%v)", num)
	if width == 0 {
		panic("MakeTextures() needs at least width")
	}
	if height == 0 {
		height = width
	}
	if depth == 0 {
		depth = height
	}
	for i := 0; i < len(glPtr); i++ {
		gl.BindTexture(texTarget, glPtr[i])
		gl.TexParameteri(texTarget, gl.TEXTURE_MAG_FILTER, TexFilter)
		gl.TexParameteri(texTarget, gl.TEXTURE_MIN_FILTER, TexFilter)
		gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_R, TexWrap)
		gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_S, TexWrap)
		gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_T, TexWrap)
		if is3d {
			gl.TexStorage3D(texTarget, 1, texFormat, width, height, depth)
		} else if is2d {
			gl.TexStorage2D(texTarget, 1, texFormat, width, height)
		} else {
			gl.TexStorage1D(texTarget, 1, texFormat, width)
		}
		gl.BindTexture(texTarget, 0)
		PanicIfErrors("MakeTextures.Loop(i=%v dim=%v w=%v h=%v d=%v)", i, dimensions, width, height, depth)
	}
}
示例#2
0
func MakeTextureForTarget(glPtr *gl.Uint, dimensions uint8, width, height, depth gl.Sizei, texTarget gl.Enum, texFormat gl.Enum, panicIfErrors, reuseGlPtr bool) {
	var is3d, is2d = (dimensions == 3), (dimensions == 2)
	if texTarget == 0 {
		texTarget = gltypes.Ife(is3d, gl.TEXTURE_3D, gltypes.Ife(is2d, gl.TEXTURE_2D, gl.TEXTURE_1D))
	}
	if texFormat == 0 {
		texFormat = gl.RGBA8
	}
	if width == 0 {
		panic("MakeTextureForTarget() needs at least width")
	}
	if height == 0 {
		height = width
	}
	if depth == 0 {
		depth = height
	}
	if (!reuseGlPtr) || (*glPtr == 0) {
		gl.GenTextures(1, glPtr)
	}
	gl.BindTexture(texTarget, *glPtr)
	gl.TexParameteri(texTarget, gl.TEXTURE_MAG_FILTER, TexFilter)
	gl.TexParameteri(texTarget, gl.TEXTURE_MIN_FILTER, TexFilter)
	gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_S, TexWrap)
	if is2d || is3d {
		gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_T, TexWrap)
	}
	if is3d {
		gl.TexParameteri(texTarget, gl.TEXTURE_WRAP_R, TexWrap)
	}
	if is3d {
		gl.TexStorage3D(texTarget, 1, texFormat, width, height, depth)
	} else if is2d {
		gl.TexStorage2D(texTarget, 1, texFormat, width, height)
	} else {
		gl.TexStorage1D(texTarget, 1, texFormat, width)
	}
	gl.BindTexture(texTarget, 0)
	if panicIfErrors {
		PanicIfErrors("MakeTextureForTarget(dim=%v w=%v h=%v d=%v)", dimensions, width, height, depth)
	}
}