コード例 #1
0
ファイル: testlib.go プロジェクト: leonardyp/mandala
// Run runs renderLoop. The loop renders a frame and swaps the buffer
// at each tick received.
func (t *TestSuite) renderLoopFunc(control *renderLoopControl) loop.LoopFunc {
	return func(loop loop.Loop) error {

		// renderState stores rendering state variables such
		// as the EGL state
		renderState := new(renderState)

		// Lock/unlock the loop to the current OS thread. This is
		// necessary because OpenGL functions should be called from
		// the same thread.
		runtime.LockOSThread()
		defer runtime.UnlockOSThread()

		// Create an instance of ticker and immediately stop
		// it because we don't want to swap buffers before
		// initializing a rendering state.
		ticker := time.NewTicker(time.Duration(1e9 / int(FRAMES_PER_SECOND)))
		ticker.Stop()

		for {
			select {
			case window := <-control.window:
				ticker.Stop()
				renderState.init(window)
				ticker = time.NewTicker(time.Duration(1e9 / int(FRAMES_PER_SECOND)))

			// At each tick render a frame and swap buffers.
			case <-ticker.C:
				renderState.draw()
				t.testDraw <- Screenshot(renderState.window)
				renderState.window.SwapBuffers()

			case <-control.resizeViewport:

			case <-control.pause:
				// store something
				ticker.Stop()

			case <-control.resume:
				// resume something

			case <-loop.ShallStop():
				ticker.Stop()
				return nil
			}
		}
	}
}
コード例 #2
0
ファイル: game.go プロジェクト: remogatto/mandala-template
// Run runs renderLoop. The loop renders a frame and swaps the buffer
// at each tick received.
func renderLoopFunc(control *renderLoopControl) loop.LoopFunc {
	return func(loop loop.Loop) error {
		var window mandala.Window
		// Lock/unlock the loop to the current OS thread. This is
		// necessary because OpenGL functions should be called from
		// the same thread.
		runtime.LockOSThread()
		defer runtime.UnlockOSThread()

		// Create an instance of ticker and immediately stop
		// it because we don't want to swap buffers before
		// initializing a rendering state.
		ticker := time.NewTicker(time.Duration(1e9 / int(FRAMES_PER_SECOND)))
		ticker.Stop()

		for {
			select {
			case window = <-control.window:
				ticker.Stop()

				window.MakeContextCurrent()

				width, height := window.GetSize()
				gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))

				mandala.Logf("Restarting rendering loop...")
				ticker = time.NewTicker(time.Duration(1e9 / int(FRAMES_PER_SECOND)))

			// At each tick render a frame and swap buffers.
			case <-ticker.C:
				draw()
				window.SwapBuffers()

			case event := <-control.pause:
				ticker.Stop()
				event.Paused <- true

			case <-control.resume:

			case <-loop.ShallStop():
				ticker.Stop()
				return nil
			}
		}
	}
}
コード例 #3
0
ファイル: game.go プロジェクト: remogatto/mandala-examples
// Run runs renderLoop. The loop renders a frame and swaps the buffer
// at each tick received.
func renderLoopFunc(control *renderLoopControl) loop.LoopFunc {
	return func(loop loop.Loop) error {

		var state *lib.GameState

		// Lock/unlock the loop to the current OS thread. This is
		// necessary because OpenGL functions should be called from
		// the same thread.
		runtime.LockOSThread()
		defer runtime.UnlockOSThread()

		// Create an instance of ticker and immediately stop
		// it because we don't want to swap buffers before
		// initializing a rendering state.
		ticker := time.NewTicker(time.Duration(1e9 / int(FramesPerSecond)))
		ticker.Stop()

		fpsTicker := time.NewTicker(time.Duration(time.Second))
		fpsTicker.Stop()

		for {
			select {
			case init := <-control.init:
				window := init.window
				activity := init.activity

				ticker.Stop()

				state = lib.NewGameState(window)

				width, height := window.GetSize()
				gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))

				ShowAdPopup(activity)

				ticker = time.NewTicker(time.Duration(time.Second / time.Duration(FramesPerSecond)))
				fpsTicker = time.NewTicker(time.Duration(time.Second))

			case tap := <-control.tapEvent:
				state.World.Remove(tap[0], tap[1])

			// At each tick render a frame and swap buffers.
			case <-ticker.C:
				state.Frames++
				state.Draw()
				state.SwapBuffers()

			case <-fpsTicker.C:
				state.Fps = state.Frames
				state.Frames = 0

			case event := <-control.pause:
				ticker.Stop()
				fpsTicker.Stop()
				state.World.Destroy()
				event.Paused <- true

			case <-control.resume:

			case <-loop.ShallStop():
				ticker.Stop()
				return nil
			}
		}
	}
}