Ejemplo n.º 1
0
func setVersion() {
	glVer, glslVer := &Support.GlVersion, &Support.Glsl.Version
	glVer.Num, glslVer.Num = 0.0, 0
	glVer.Is33, glVer.Is40, glVer.Is41, glVer.Is42, glVer.Is43 = false, false, false, false, false
	glslVer.Is330, glslVer.Is400, glslVer.Is410, glslVer.Is420, glslVer.Is430 = false, false, false, false, false
	if glVer.MajorMinor, glVer.Num = ugo.ParseVersion(Util.Str(gl.VERSION)); glVer.Num > 0 {
		if glVer.Num >= 3.3 {
			glVer.Is33, glslVer.Num, glslVer.Is330 = true, 330, true
		}
		if glVer.Num >= 4.0 {
			glVer.Is40, glslVer.Num, glslVer.Is400 = true, 400, true
		}
		if glVer.Num >= 4.1 {
			glVer.Is41, glslVer.Num, glslVer.Is410 = true, 410, true
		}
		if glVer.Num >= 4.2 {
			glVer.Is42, glslVer.Num, glslVer.Is420 = true, 420, true
		}
		if glVer.Num >= 4.3 {
			glVer.Is43, glslVer.Num, glslVer.Is430 = true, 430, true
		}
	}
}
Ejemplo n.º 2
0
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)
	}
}
Ejemplo n.º 3
0
func parseVersion(dotted string) (ver *version) {
	majmin, _ := ugo.ParseVersion(dotted)
	ver = &version{dotted: dotted, major: majmin[0], minor: majmin[1]}
	ver.underscored = sfmt("%v_%v", ver.major, ver.minor)
	return
}