示例#1
0
文件: darwin_arm.go 项目: Miaque/mojo
//export drawgl
func drawgl(ctx uintptr) {
	// The call to lockContext loads the OpenGL context into
	// thread-local storage for use by the underlying GL calls
	// done in the user's Draw function. We need to stay on
	// the same thread throughout Draw, so we LockOSThread.
	runtime.LockOSThread()
	C.setContext(unsafe.Pointer(ctx))

	initGLOnce.Do(initGL)

	// TODO not here?
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	if cb.Draw != nil {
		cb.Draw()
	}

	// TODO
	//C.unlockContext(ctx)

	// This may unlock the original main thread, but that's OK,
	// because by the time it does the thread has already entered
	// C.runApp, which won't give the thread up.
	runtime.UnlockOSThread()
}
示例#2
0
//export drawgl
func drawgl(ctx uintptr) {
	if glctx == nil {
		C.setContext(unsafe.Pointer(ctx))

		glctx, worker = gl.NewContext()
		workAvailable = worker.WorkAvailable()

		// TODO(crawshaw): not just on process start.
		theApp.sendLifecycle(lifecycle.StageFocused)
	}

	// TODO(crawshaw): don't send a paint.Event unconditionally. Only send one
	// if the window actually needs redrawing.
	theApp.eventsIn <- paint.Event{}

	for {
		select {
		case <-workAvailable:
			worker.DoWork()
		case <-theApp.publish:
			theApp.publishResult <- PublishResult{}
			return
		}
	}
}
示例#3
0
//export drawgl
func drawgl(ctx uintptr) {
	if !startedgl {
		startedgl = true
		C.setContext(unsafe.Pointer(ctx))
		// TODO(crawshaw): not just on process start.
		sendLifecycle(lifecycle.StageFocused)
	}

	eventsIn <- paint.Event{}

	for {
		select {
		case <-gl.WorkAvailable:
			gl.DoWork()
		case <-endDraw:
			return
		}
	}
}
示例#4
0
//export drawgl
func drawgl(ctx uintptr) {
	if !startedgl {
		startedgl = true
		C.setContext(unsafe.Pointer(ctx))
		// TODO(crawshaw): not just on process start.
		sendLifecycle(lifecycle.StageFocused)
	}

	// TODO(crawshaw): don't send a paint.Event unconditionally. Only send one
	// if the window actually needs redrawing.
	eventsIn <- paint.Event{}

	for {
		select {
		case <-gl.WorkAvailable:
			gl.DoWork()
		case <-publish:
			publishResult <- PublishResult{}
			return
		}
	}
}