Beispiel #1
0
func (me *glPack) makeAllFiles() (err error) {
	me.makeAllSources()
	if !cfg.altTryFile.only {
		for name, src := range me.sources {
			if err = ufs.WriteTextFile(filepath.Join(cfg.outDirPath, "gl-"+name+".go"), "package gl\n\n"+string(src)); err != nil {
				return
			}
		}
	}
	if len(cfg.altTryFile.funcs) > 0 {
		var (
			src glPackSrc
			fun *glFunc
		)
		src.addLn(`package %s

import (
	gl "github.com/go3d/go-opengl/core"
)

//	Used only for the exported package-global variable 'Try'.
//	Provides methods that each wrap a GL function call and immediately check for GL errors to be returned as Go errors.
type GlTry struct {
}
`, cfg.altTryFile.pkgName)
		for _, try := range cfg.altTryFile.funcs {
			if fun = me.funcs[try]; fun != nil {
				me.makeTryFunc(&src, fun, "gl.", "Util.")
			}
		}
		err = ufs.WriteTextFile(cfg.altTryFile.outPath, string(src))
	}
	return
}
Beispiel #2
0
func main() {
	ugo.MaxProcs()
	var srcTimeGlsl, srcTimeEmbeds time.Time
	force := false
	nginePath = os.Args[1]
	outFilePath = filepath.Join(nginePath, "core", "-gen-embed.go")
	if fileInfo, err := os.Stat(outFilePath); err == nil {
		outFileTime = fileInfo.ModTime()
	} else {
		force = true
	}
	if outFileTime.IsZero() {
		force = true
	}

	srcDirPathEmbeds := filepath.Join(nginePath, "core", "_embed")
	if !force {
		if errs := ufs.NewDirWalker(false, nil, newWalkerVisitor_IsNewerThan(outFileTime, &srcTimeGlsl)).Walk(srcDirPathEmbeds); len(errs) > 0 {
			panic(errs[0])
		}
	}

	if force || srcTimeGlsl.UnixNano() > outFileTime.UnixNano() || srcTimeEmbeds.UnixNano() > outFileTime.UnixNano() {
		fmt.Printf("Re-generating %s...\n", outFilePath)
		wait.Add(2)
		go makeShaders(srcDirPathEmbeds)
		go makeEmbeds(srcDirPathEmbeds)
		wait.Wait()
		ufs.WriteTextFile(outFilePath, fmt.Sprintf("package core\n\n//\tGenerated by ng-buildrun\nfunc init() {\n%s\n%s\n}", newSrc.shaders, newSrc.embeds))
	}
}
Beispiel #3
0
//	Attempts to xml.Unmarshal() all files in the "infiles" sub-directory of the specified directory path into the interface{} structure returned by the specified constructor.
//	For each such input file, then attempts to xml.MarshalIndent() said structure back into a new output XML file with the same name, in the "outfiles" sub-directory of the specified directory path.
func TestViaRemarshal(dirPath string, makeEmptyDoc func() interface{}) {
	var dirPathInFiles = filepath.Join(dirPath, "infiles")
	var dirPathOutFiles = filepath.Join(dirPath, "outfiles")
	var loadXmlDocFile = func(filename string) bool {
		log.Printf("Loading %s", filename)
		doc, dataOrig := makeEmptyDoc(), ufs.ReadBinaryFile(filename, true)
		err := xml.Unmarshal(dataOrig, doc)
		if err != nil {
			panic(err)
		}
		if OnDocLoaded != nil {
			OnDocLoaded(doc)
		}
		outFileName := filepath.Join(dirPathOutFiles, filepath.Base(filename))
		log.Printf("Writing %s", outFileName)
		dataFaks, err := xml.MarshalIndent(doc, "", "\t")
		if err != nil {
			panic(err)
		}
		ufs.WriteTextFile(outFileName, strings.Trim(string(dataFaks), " \r\n\t"))
		log.Printf("Verifying...")
		if errs := verifyDocs(dataOrig, dataFaks); len(errs) > 0 {
			for _, err = range errs {
				log.Printf("%v", err)
			}
		}
		return true
	}
	if errs := ufs.NewDirWalker(false, nil, loadXmlDocFile).Walk(dirPathInFiles); len(errs) > 0 {
		panic(errs[0])
	}
}
Beispiel #4
0
func (me *Schema) MakeGoPkgSrcFile() (goOutFilePath string, err error) {
	var goOutDirPath = filepath.Join(filepath.Dir(me.loadLocalPath), goPkgPrefix+filepath.Base(me.loadLocalPath)+goPkgSuffix)
	goOutFilePath = filepath.Join(goOutDirPath, path.Base(me.loadUri)+".go")
	var bag = newPkgBag(me)
	for _, inc := range me.XMLIncludedSchemas {
		bag.Schema = inc
		inc.makePkg(bag)
	}
	bag.Schema = me
	me.hasElemAnnotation.makePkg(bag)
	bag.appendFmt(true, "")
	me.makePkg(bag)
	if err = ufs.EnsureDirExists(filepath.Dir(goOutFilePath)); err == nil {
		err = ufs.WriteTextFile(goOutFilePath, bag.assembleSource())
	}
	return
}
Beispiel #5
0
func (_ *glMan) makeProgs(forceAll bool, forceSome ...string) (dur time.Duration, err error) {
	var progsMade []bool
	dur, progsMade, err = ogl.progs.MakeProgramsFromRawSources(nil, forceAll, forceSome...)
	if len(Options.AppDir.Temp.ShaderSources) > 0 {
		writeSrc := func(i int, ext, src string) {
			if len(src) > 0 {
				ufs.WriteTextFile(Core.fileIO.resolveLocalFilePath(path.Join(Options.AppDir.Temp.BaseName, Options.AppDir.Temp.ShaderSources, ogl.progs.All[i].Name+ext)), src)
			}
		}
		for i := 0; i < len(ogl.progs.All); i++ {
			if progsMade[i] {
				writeSrc(i, ".glcs", ogl.progs.All[i].Sources.Out.Compute)
				writeSrc(i, ".glfs", ogl.progs.All[i].Sources.Out.Fragment)
				writeSrc(i, ".glgs", ogl.progs.All[i].Sources.Out.Geometry)
				writeSrc(i, ".glhs", ogl.progs.All[i].Sources.Out.TessCtl)
				writeSrc(i, ".glds", ogl.progs.All[i].Sources.Out.TessEval)
				writeSrc(i, ".glvs", ogl.progs.All[i].Sources.Out.Vertex)
			}
		}
	}
	return
}