コード例 #1
0
ファイル: gl-funcs.go プロジェクト: LonelyPale/go-opengl
func (me *glFunc) makeCgo() {
	var (
		i  int
		fp *glFuncParam
	)
	me.clang.entry = sfmt("%s (APIENTRYP ptrgl%s)(", me.retType.c, me.name)
	for i, fp = range me.params {
		me.clang.entry += sfmt("%s %s", ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference"), fp.typeRef.c+"*", fp.typeRef.c), fp.name)
		if i < len(me.params)-1 {
			me.clang.entry += ", "
		}
	}
	me.clang.entry += ");"

	if *flagSupports {
		me.clang.supporter = sfmt("int cancall%s() { return ((ptrgl%s == NULL) ? 0 : 1); }", me.name, me.name)
	}

	me.clang.wrapper = sfmt("%s call%s(", me.retType.c, me.name)
	for i, fp = range me.params {
		me.clang.wrapper += sfmt("%s %s", ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference"), fp.typeRef.c+"*", fp.typeRef.c), fp.saneName)
		if i < len(me.params)-1 {
			me.clang.wrapper += ", "
		}
	}
	me.clang.wrapper += sfmt(") { %s (*ptrgl%s)(", ustr.Ifs(me.retType.c == "void", "", "return"), me.name)
	for i, fp = range me.params {
		me.clang.wrapper += fp.saneName
		if i < len(me.params)-1 {
			me.clang.wrapper += ", "
		}
	}
	me.clang.wrapper += "); }"
}
コード例 #2
0
ファイル: pack.go プロジェクト: LonelyPale/go-opengl
func (me *glPack) makeTryFunc(src *glPackSrc, fun *glFunc, glPrefix, errPrefix string) {
	src.addLn("//\tCalls %s%s() and yields the err returned by %sError(), if any.", glPrefix, fun.name, errPrefix)
	src.add("func (_ GlTry) %s(", fun.name)
	args, ret := "", ""
	for i, fp := range fun.params {
		fpgtPtr := strings.HasSuffix(fp.typeRef.g, "Ptr")
		tmp := strings.Replace(ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference") && !fpgtPtr, "*"+fp.typeRef.g, fp.typeRef.g), "***", "**", -1)
		if pos := strings.LastIndex(tmp, "*"); pos < 0 {
			tmp = glPrefix + tmp
		} else {
			tmp = tmp[:pos+1] + glPrefix + tmp[pos+1:]
		}
		src.add("%s %s", fp.saneName, tmp)
		args += fp.saneName
		if i < len(fun.params)-1 {
			src.add(", ")
			args += ", "
		}
	}
	src.add(") (err error")
	if len(fun.retType.g) > 0 {
		ret = "tryRetVal__ = "
		src.add(", tryRetVal__ %v", glPrefix+fun.retType.g)
	}
	src.add(") {")
	src.addLn(`
	%s%s(%s)
	err = %sLastError("%s()")
	return`, ret, glPrefix+fun.name, args, errPrefix, glPrefix+fun.name)
	src.addLn("}\n")
}
コード例 #3
0
ファイル: gl-enums.go プロジェクト: LonelyPale/go-opengl
func (me *glPack) makeEnums() {
	var src glPackSrc
	if *flagTry {
		src.addLn("import \"fmt\"")
	}
	for name, enum := range allEnums {
		if (!enum.legacy) && (len(enum.exts) == 0 || len(enum.ver) > 0 || uslice.StrHasAny(cfg.genExts, enum.exts...)) {
			me.enums[name] = enum
		}
	}
	src.addLn("const (")
	for _, enum := range me.enums {
		if len(enum.val) == 0 && me.enums[enum.ref] == nil {
			me.enums[enum.ref] = allEnums[enum.ref]
		}
	}
	for _, enum := range me.enums {
		src.addLn("\t%s = %s", enum.name, ustr.Ifs(len(enum.val) == 0, enum.ref, enum.val))
	}
	src.addLn(")\n")
	toUi := func(str string) (ui uint64) {
		ui, _ = strconv.ParseUint(str, 0, 64)
		return
	}
	enumsDone := map[uint64]bool{toUi("0xFFFFFFFFFFFFFFFF"): true}
	isEarlyEnum := func(name string) bool {
		return (strings.HasSuffix(name, "_SHADER") && strings.Count(name, "_") <= 2) || ustr.IsOneOf(name, "INVALID_ENUM", "INVALID_VALUE", "INVALID_OPERATION", "OUT_OF_MEMORY", "INVALID_FRAMEBUFFER_OPERATION", "STACK_OVERFLOW", "STACK_UNDERFLOW")
	}
	if *flagTry {
		src.addLn(`
//	Returns the name of the specified Enum. Not recommended in a real-time loop.
func (_ GlUtil) EnumName(enum Enum) (name string) {
	switch enum {`)
		for _, enum := range me.enums {
			if isEarlyEnum(enum.name) {
				enumsDone[toUi(enum.finalVal())] = true
				src.addLn("\tcase %s:\n\t\tname = \"GL_%s\"", enum.name, enum.name)
			}
		}
		for _, enum := range me.enums {
			if ui := toUi(enum.finalVal()); !enumsDone[ui] {
				enumsDone[ui] = true
				src.addLn("\tcase %s:\n\t\tname = \"GL_%s\"", enum.name, enum.name)
			}
		}
		src.addLn(`	default:
		name = fmt.Sprintf("GL_ENUM_%%v", enum)
	}
	return
}
`)
	}
	me.sources["enums"] = src
}
コード例 #4
0
ファイル: convert.go プロジェクト: go3d/go-collada
func processNode(xn *xmlx.Node) {
	if (!Force) && (xn.Name.Local == "COLLADA") {
		if _, ver := ugo.ParseVersion(attVal(xn, "version")); ver >= 1.5 {
			skipped = true
			return
		}
	}
	xn.Name.Space = ""
	for _, att := range xn.Attributes {
		att.Name.Space = ""
	}
	switch xn.Name.Local {
	case "COLLADA":
		setAttr(xn, "version", "1.5", false)
		setAttr(xn, "xmlns", "http://www.collada.org/2008/03/COLLADASchema", false)
	case "array":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "array", "newparam", "setparam") {
			delNode(xn)
		}
	case "argument", "texenv":
		delAttr(xn, "unit")
	case "cg_value_type", "connect_param", "generator", "tapered_capsule", "tapered_cylinder", "texture_unit":
		delNode(xn)
	case "code", "include":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "profile_CG", "profile_GLES2", "profile_GLSL") {
			delNode(xn)
		}
	case "color_target", "depth_target", "stencil_target":
		if val := surfaceImages[xn.Value]; len(val) == 0 {
			setAttr(ensureChild(xn, "param"), "ref", xn.Value, false)
		} else {
			setAttr(ensureChild(xn, "instance_image"), "url", "#"+val, false)
		}
		xn.Value = ""
	case "float_array":
		restrictAttr(xn, "digits", 1, 17)
		restrictAttr(xn, "magnitude", -324, 308)
	case "image":
		convertImage(xn)
	case "instance_effect":
		if xn.Parent.Name.Local == "render" {
			id := fmt.Sprintf("render_%v", time.Now().UnixNano())
			matNode := xmlx.NewNode(xn.Type)
			matNode.Name.Local = "material"
			setAttr(matNode, "id", id, false)
			matsLibNode := ensureChild(srcDoc.Root.Children[0], "library_materials")
			matsLibNode.AddChild(matNode)
			oldParent := xn.Parent
			_, pos := moveNode(xn, matNode, "")
			instNode := xmlx.NewNode(xn.Type)
			instNode.Name.Local = "instance_material"
			setAttr(instNode, "url", "#"+id, false)
			instNode.Parent = oldParent
			oldParent.Children[pos] = instNode
		}
	case "magfilter", "minfilter", "mipfilter":
		if (xn.Value == "NONE") && (xn.Name.Local != "mipfilter") {
			xn.Value = "NEAREST"
		} else {
			switch xn.Value {
			case "NEAREST_MIPMAP_NEAREST":
				ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "NEAREST"})
			case "LINEAR_MIPMAP_NEAREST":
				ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "NEAREST"})
			case "NEAREST_MIPMAP_LINEAR":
				ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "LINEAR"})
			case "LINEAR_MIPMAP_LINEAR":
				ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "LINEAR"})
			}
		}
	case "mipmap_bias":
		renameNode(xn, "mip_bias")
	case "mipmap_maxlevel":
		renameNode(xn, "mip_max_level")
	case "newparam":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "effect", "profile_CG", "profile_COMMON", "profile_GLSL", "profile_GLES", "profile_GLES2") {
			delNode(xn)
		}
	case "radius":
		if vals := ustr.Split(xn.Value, " "); (xn.Parent.Name.Local == "capsule") && (len(vals) > 0) && (len(vals) < 3) {
			for len(vals) < 3 {
				vals = append(vals, "1.0")
			}
			xn.Value = strings.Join(vals, " ")
		}
	case "setparam":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "instance_effect", "usertype") {
			delNode(xn)
		}
	case "shader":
		convertShader(xn)
	case "surface":
		convertSurface(xn)
	case "texture_pipeline":
		if xn.Parent.Name.Local != "states" {
			delNode(xn)
		}
	case "transparent":
		setAttr(xn, "opaque", "A_ONE", true)
	case "usertype":
		renameAttr(xn, "name", "typename")
		if !ustr.IsOneOf(xn.Parent.Name.Local, "newparam", "setparam", "array", "bind_uniform") {
			delNode(xn)
		} else {
			for _, sn := range xn.Children {
				if sn.Name.Local != "setparam" {
					delNode(sn)
				}
			}
		}
	default:
		if (xn.Parent != nil) && (xn.Parent.Name.Local == "pass") {
			switch xn.Name.Local {
			case "annotate", "extra", "evaluate", "states", "program":
				break
			case "color_target", "depth_target", "stencil_target", "color_clear", "depth_clear", "stencil_clear", "draw":
				moveNode(xn, ensureChild(xn.Parent, "evaluate"), "")
			case "shader":
				moveNode(xn, ensureChild(xn.Parent, "program"), "")
			default:
				moveNode(xn, ensureChild(xn.Parent, "states"), "")
			}
		}
		if strings.HasPrefix(xn.Name.Local, "wrap_") && (xn.Value == "NONE") {
			xn.Value = "BORDER"
		}
		if (xn.Name.Local != "sampler") && strings.HasPrefix(xn.Name.Local, "sampler") && !strings.HasPrefix(xn.Name.Local, "sampler_") {
			if sn := subNode(xn, "source"); sn != nil {
				sn.Name.Local = "instance_image"
				setAttr(sn, "url", "#"+surfaceImages[sn.Value], false)
				sn.Value = ""
			}
		}
	}
	for _, sn := range xn.Children {
		processNode(sn)
	}
}
コード例 #5
0
ファイル: gl-funcs.go プロジェクト: LonelyPale/go-opengl
func (me *glPack) makeFuncs() {
	var (
		i       int
		fpgtPtr bool
		src     glPackSrc
		fun     *glFunc
		fp      *glFuncParam
	)
	isBeast := func() bool {
		b := (!strings.HasPrefix(fun.cat, "VERSION_")) && (!strings.HasSuffix(fun.name, fun.cat[:strings.Index(fun.cat, "_")])) && !strings.HasSuffix(fun.name, "EXT")
		return b
	}
	for _, fun = range allFuncs {
		if strings.Contains(fun.cat, " ") {
			println(fun.cat)
		}
		if strings.HasPrefix(fun.cat, "VERSION_") || uslice.StrHas(cfg.genExts, fun.cat) || isBeast() {
			me.funcs[fun.name] = fun
			if uslice.StrHas(cfg.genExts, fun.cat) {
				println("EXT:" + fun.name)
			}
		}
	}

	for _, fun = range me.funcs {
		src.addLn("//\tGLAPI Wiki: http://www.opengl.org/wiki/GLAPI/gl%s", fun.name)
		src.addLn("//\tSDK doc: http://www.opengl.org/sdk/docs/man/xhtml/gl%s.xml", fun.name)
		src.add("func %s(", fun.name)
		for i, fp = range fun.params {
			fpgtPtr = strings.HasSuffix(fp.typeRef.g, "Ptr")
			src.add("%s %s", fp.saneName, strings.Replace(ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference") && !fpgtPtr, "*"+fp.typeRef.g, fp.typeRef.g), "***", "**", -1))
			if i < len(fun.params)-1 {
				src.add(", ")
			}
		}
		src.add(") %s {\n\t", fun.retType.g)
		if len(fun.retType.g) > 0 {
			src.add("return (%s)(", fun.retType.g)
		}
		src.add("C.call%s(", fun.name)
		for i, fp = range fun.params {
			fpgtPtr = fp.typeRef.g == "Ptr"
			if fp.typeRef.c == "GLchar* const" {
				src.add("(**C.GLchar)(unsafe.Pointer(%s))", fp.saneName)
			} else if fp.typeRef.c == "GLDEBUGPROC" {
				src.add("(*[0]byte)(%s)", fp.saneName)
			} else {
				src.add("(%s%s)(%s)", ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference") && !fpgtPtr, "*", ""), ustr.Ifs(strings.HasSuffix(fp.typeRef.g, "Ptr"), "unsafe.Pointer", "C."+fp.typeRef.c), fp.saneName)
			}
			if i < len(fun.params)-1 {
				src.add(", ")
			}
		}
		src.add(")")
		if len(fun.retType.g) > 0 {
			src.add(")")
		}
		src.addLn("\n}\n")
		fun.makeCgo()
	}
	me.sources["funcs"] = src
}