Пример #1
0
//	Initializes go:ngine; this first attempts to initialize OpenGL and then open a window to your supplied specifications with a GL 3.3-or-higher profile.
func Init(fullscreen bool, ctx ngctx.CtxProvider) (err error) {
	var (
		glVerIndex         = len(ugl.KnownVersions) - 1
		badVer, tmpDirPath string
		glVer              float64
	)
	UserIO.ctx = ctx
	if err = ufs.EnsureDirExists(Core.fileIO.resolveLocalFilePath(Options.AppDir.Temp.BaseName)); err != nil {
		return
	}
	defer runtime.GC()
	if len(Options.AppDir.Temp.BaseName) > 0 {
		for _, diagTmpDirName := range []string{Options.AppDir.Temp.ShaderSources, Options.AppDir.Temp.CachedTextures} {
			tmpDirPath = Core.fileIO.resolveLocalFilePath(filepath.Join(Options.AppDir.Temp.BaseName, diagTmpDirName))
			if err = ufs.EnsureDirExists(tmpDirPath); err != nil {
				return
			}
		}
		for _, diagTmpDirName := range []string{Options.AppDir.Temp.ShaderSources} {
			tmpDirPath = Core.fileIO.resolveLocalFilePath(filepath.Join(Options.AppDir.Temp.BaseName, diagTmpDirName))
			if err = ufs.ClearDirectory(tmpDirPath); err != nil {
				return
			}
		}
	}
	if Options.Initialization.GlContext.CoreProfile.ForceFirst {
		for i, v := range ugl.KnownVersions {
			if v == Options.Initialization.GlContext.CoreProfile.VersionHint {
				glVerIndex = i
				break
			}
		}
	}
tryInit:
	glVer, UserIO.Window.fullscreen = ugl.KnownVersions[glVerIndex], fullscreen
	if err = UserIO.init(glVer); err == nil {
		if err, badVer = ogl.init(); err == nil && len(badVer) == 0 {
			Stats.reset()
			Loop.init()
			if err = Core.init(); err != nil {
				return
			}
			Diag.LogIfGlErr("INIT")
		} else if len(badVer) > 0 && !Options.Initialization.GlContext.CoreProfile.ForceFirst {
			Options.Initialization.GlContext.CoreProfile.ForceFirst = true
			UserIO.isCtxInit, UserIO.Window.isCreated = false, false
			goto tryInit
		}
	} else if Options.Initialization.GlContext.CoreProfile.ForceFirst && (glVerIndex > 0) {
		glVerIndex--
		UserIO.isCtxInit, UserIO.Window.isCreated = false, false
		goto tryInit
	} else {
		badVer = ogl.lastBadVer
	}
	if len(badVer) > 0 {
		err = errf(ogl.versionErrorMessage(glMinVerStr, badVer))
	}
	return
}
Пример #2
0
func LoadSchema(uri string, localCopy bool) (sd *Schema, err error) {
	var protocol, localPath string
	var rc io.ReadCloser

	if pos := strings.Index(uri, protSep); pos < 0 {
		protocol = "http" + protSep
	} else {
		protocol = uri[:pos+len(protSep)]
		uri = uri[pos+len(protSep):]
	}
	if localCopy {
		if localPath = filepath.Join(PkgGen.BaseCodePath, uri); !ufs.FileExists(localPath) {
			if err = ufs.EnsureDirExists(filepath.Dir(localPath)); err == nil {
				err = unet.DownloadFile(protocol+uri, localPath)
			}
		}
		if err == nil {
			if sd, err = loadSchemaFile(localPath, uri); sd != nil {
				sd.loadLocalPath = localPath
			}
		}
	} else if rc, err = unet.OpenRemoteFile(protocol + uri); err == nil {
		defer rc.Close()
		sd, err = loadSchema(rc, uri, "")
	}
	return
}
Пример #3
0
func main() {
	if false {
		cfg.altTryFile.only, cfg.altTryFile.pkgName = true, "glutil"
		cfg.altTryFile.funcs = []string{"AttachShader", "BufferData", "BufferSubData", "CreateProgram", "CreateShader", "GenBuffers", "GenerateMipmap", "GenTextures", "GenVertexArrays", "ShaderSource", "TexImage2D", "TexStorage2D", "TexSubImage2D"}
		cfg.altTryFile.outPath = ugo.GopathSrcGithub("go3d", "go-opengl", "util", "-gen-try.go")
	}
	flag.Parse()
	if cfg.minVer = parseVersion(*flagMinVer); cfg.minVer.major < 1 {
		panic("What kind of minver is that?")
	}
	if len(*flagGenExts) > 0 {
		if *flagGenExts == "*" {
			cfg.genExtsAll = true
		} else {
			cfg.genExts = strings.Split(*flagGenExts, " ")
		}
	}
	if err = specDoc.LoadFile(*flagSpecFile, nil); err != nil {
		panic(err)
	}
	cfg.outDirPath = filepath.Join(*flagOutDir, "core")
	if err = ufs.EnsureDirExists(cfg.outDirPath); err != nil {
		panic(err)
	}
	if cfg.genExtsAll {
		xmlWalkExts()
	}
	xmlWalkTypes()
	xmlWalkEnums()
	xmlWalkFuncs()
	if err = newGlPack().makeAllFiles(); err != nil {
		panic(err)
	}
}
Пример #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
}
Пример #5
0
// Mkdirs ensures that the directory is created.
func (fs OSUtil) Mkdirs(dir string) error {
	return ufs.EnsureDirExists(dir)
}