Example #1
0
//	Experimental.
func toggleBatching() {
	if RearView.View != nil {
		RearView.View.Technique_Scene().ToggleBatching()
	}
	if SceneView != nil {
		rts := SceneView.Technique_Scene()
		rts.ToggleBatching()
		winTitle.batched = ugo.Ifi(rts.Batch.Enabled, 1, 0)
	}
}
Example #2
0
//	Returns the first `string` in `vals` to match the specified `predicate`.
//
//	`step`: 1 to test all values, a higher value to skip n values after each test, negative for reverse slice traversal, or use 0 to get stuck in an infinite loop.
func First(predicate func(s string) bool, step int, vals ...string) string {
	l := len(vals)
	reverse := step < 0
	for i := ugo.Ifi(reverse, l-1, 0); ugo.Ifb(reverse, i >= 0, i < l); i += step {
		if predicate(vals[i]) {
			return vals[i]
		}
	}
	return ""
}
Example #3
0
//	Called by each example-app's func main(). Initializes go:ngine, calls the specified setupExampleScene function, then enters The Loop.
func Main(setupExampleScene, onAppThread, onWinThread func()) {
	//	by design, go:ngine doesn't do this for you automagically:
	runtime.LockOSThread()
	ugo.MaxProcs()
	spew.Config.DisableMethods = true

	//	can set window options before it is created
	win := &ng.UserIO.Window
	//	release apps shouldn't do this, but during dev/test we want to observe max fps:
	win.SetSwapInterval(0)
	win.SetSize(1366, 768)
	winTitle.appName = filepath.Base(os.Args[0])
	win.SetTitle(fmt.Sprintf("Loading \"%s\" example app... (%v CPU cores)", winTitle.appName, runtime.GOMAXPROCS(0)))

	opt := &ng.Options

	//	While the default for this (true on Macs only) is reasonable for release apps at present,
	//	here we force core profile to verify all of go:ngine's GL code is fully core-profile compliant
	opt.Initialization.GlContext.CoreProfile.ForceFirst = true

	//	Release apps shouldn't do this, but here we're verifying everything runs in the oldest-supported GL version:
	opt.Initialization.GlContext.CoreProfile.VersionHint = 3.3
	opt.Initialization.DefaultCanvas.GammaViaShader = true

	//	Worth toggling this every once in a while just to see whether it makes a perf diff at all...
	opt.Loop.GcEvery.Frame = true

	opt.AppDir.BasePath = AppDirBasePath()
	opt.AppDir.Temp.BaseName = filepath.Join("_tmp", filepath.Base(os.Args[0]))
	opt.AppDir.Temp.ShaderSources, opt.AppDir.Temp.CachedTextures = "glsl", "tex"
	// but for now, we don't need separate per-app tmp dirs:
	opt.AppDir.Temp.BaseName = "_tmp"

	if compressCachedTextures := true; compressCachedTextures {
		opt.Textures.Storage.DiskCache.Compressor = func(w io.WriteCloser) (wc io.WriteCloser) {
			var err error
			if wc, err = flate.NewWriter(w, 9); err != nil {
				panic(err)
			}
			return
		}
		opt.Textures.Storage.DiskCache.Decompressor = func(r io.ReadCloser) io.ReadCloser {
			return flate.NewReader(r)
		}
	}

	//	STEP 1: init go:ngine
	err := ng.Init(WinFullscreen, newGlCtx())
	if err != nil {
		fmt.Printf("ABORT:\n%v\n", err)
	} else {
		//	STEP 2: post-init, pre-loop setup
		ng.Loop.On.EverySec, ng.Loop.On.AppThread, ng.Loop.On.WinThread = onSec, onAppThread, onWinThread

		PostFxCanvas = ng.Core.Render.Canvases[0]
		PostFxView = PostFxCanvas.Views[0]
		PostFxView.RenderStates.ClearColor.Set(0.9, 0.6, 0.3, 1)

		if setupExampleScene != nil {
			SceneCanvas = ng.Core.Render.Canvases.AddNew(true, 1, 1)
			SceneView = SceneCanvas.AddNewView("Scene")
			rts := SceneView.Technique_Scene()
			SceneCam, winTitle.batched = &rts.Camera, ugo.Ifi(rts.Batch.Enabled, 1, 0)
			SceneView.RenderStates.ClearColor.Set(0.5, 0.6, 0.85, 1)
			setupExampleScene()
			if err = ng.Core.Libs.Meshes.GpuSync(); err != nil {
				panic(err)
			} else {
				for m := 0; m < len(ng.Core.Libs.Meshes); m++ {
					ng.Core.Libs.Meshes[m].Unload()
				}
			}
			ng.Core.GpuSyncImageLibs()
		}
		time.Sleep(ArtificialSplashScreenDelay)
		numCgo.preLoop = runtime.NumCgoCall()

		//	STEP 3: enter... Da Loop.
		ng.Loop.Run()
		numCgo.postLoop = runtime.NumCgoCall()
		PrintPostLoopSummary() // don't wanna defer this: useless when exit-on-panic
		ng.Dispose()           // don't wanna defer this: unpredictable state when exit-on-panic
	}
}
Example #4
0
func (_ *NgUserIO) recreateWin() (err error) {
	winInit := &Options.Initialization.Window
	if UserIO.Window.isCreated {
		glfw.CloseWindow()
	}
	if UserIO.Window.isCreated, err = false, glfw.OpenWindow(UserIO.Window.width, UserIO.Window.height, winInit.Rbits, winInit.Gbits, winInit.Bbits, winInit.Abits, winInit.DepthBits, winInit.StencilBits, ugo.Ifi(UserIO.Window.fullscreen, glfw.Fullscreen, glfw.Windowed)); err == nil {
		UserIO.Window.width, UserIO.Window.height = glfw.WindowSize()
		UserIO.Window.isCreated = true
		UserIO.Window.SetTitle(UserIO.Window.title)
		UserIO.Window.SetSwapInterval(UserIO.Window.swap)
		glfw.SetWindowCloseCallback(glfwOnWindowClose)
		glfw.SetWindowSizeCallback(glfwOnWindowResize)
		// glfw.Disable(glfw.MouseCursor)
		glfw.Disable(glfw.AutoPollEvents)
		glfw.Disable(glfw.StickyKeys)
	}
	return
}
Example #5
0
func Mathf_Mini(a, b int) int {
	return ugo.Ifi(b < a, b, a)
}
Example #6
0
func Mathf_Maxi(a, b int) int {
	return ugo.Ifi(b > a, b, a)
}
Example #7
0
func xv(xn *xmlx.Node) (val interface{}) {
	if xn != nil {
		if strings.HasPrefix(xn.Name.Local, "sampler") {
			val = obj_FxSampler(xn, "")
		} else {
			switch xn.Name.Local {
			case "array":
				if l := xau64(xn, "length"); (l > 0) && (len(xn.Children) > 0) {
					sl := make([]interface{}, l)
					for i := 0; i < int(l); i++ {
						sl[i] = xv(xn.Children[ugo.Ifi(i >= len(xn.Children), 0, i)])
					}
					val = sl
				}
			case "bool":
				val = xb(xn, "")
			case "bool2":
				if v := obj_Bool2(xn, ""); v != nil {
					val = *v
				}
			case "bool3":
				if v := obj_Bool3(xn, ""); v != nil {
					val = *v
				}
			case "bool4":
				if v := obj_Bool4(xn, ""); v != nil {
					val = *v
				}
			case "float":
				val = xf64(xn, "")
			case "float2", "float2x1":
				if v := obj_Float2(xn, ""); v != nil {
					val = *v
				}
			case "float3", "float3x1":
				if v := obj_Float3(xn, ""); v != nil {
					val = *v
				}
			case "float4", "float4x1":
				if v := obj_Float4(xn, ""); v != nil {
					val = *v
				}
			case "float2x2":
				if v := obj_Float2x2(xn, ""); v != nil {
					val = *v
				}
			case "float2x3":
				if v := obj_Float2x3(xn, ""); v != nil {
					val = *v
				}
			case "float2x4":
				if v := obj_Float2x4(xn, ""); v != nil {
					val = *v
				}
			case "float3x2":
				if v := obj_Float3x2(xn, ""); v != nil {
					val = *v
				}
			case "float3x3":
				if v := obj_Float3x3(xn, ""); v != nil {
					val = *v
				}
			case "float3x4":
				if v := obj_Float3x4(xn, ""); v != nil {
					val = *v
				}
			case "float4x2":
				if v := obj_Float4x2(xn, ""); v != nil {
					val = *v
				}
			case "float4x3":
				if v := obj_Float4x3(xn, ""); v != nil {
					val = *v
				}
			case "float4x4":
				if v := obj_Float4x4(xn, ""); v != nil {
					val = *v
				}
			case "int":
				val = xi64(xn, "")
			case "int2":
				if v := obj_Int2(xn, ""); v != nil {
					val = *v
				}
			case "int3":
				if v := obj_Int3(xn, ""); v != nil {
					val = *v
				}
			case "int4":
				if v := obj_Int4(xn, ""); v != nil {
					val = *v
				}
			case "sampler_image":
				val = obj_FxSamplerImage(xn, "")
			case "sampler_states":
				val = obj_FxSamplerStates(xn, "")
			case "SIDREF", "sidref":
				val = cdom.NewRefSid(xn.Value)
			default:
				val = xn.Value
			}
		}
	}
	return
}