Example #1
0
func initPlatform() {
	egl.BCMHostInit()
	screenWidth, screenHeight = egl.GraphicsGetDisplaySize(0)

	dstRect.X = 0
	dstRect.Y = 0
	dstRect.Width = int32(screenWidth)
	dstRect.Height = int32(screenHeight)

	srcRect.X = 0
	srcRect.Y = 0
	srcRect.Width = int32(screenWidth << 16)
	srcRect.Height = int32(screenHeight << 16)

	dispman_display := egl.VCDispmanxDisplayOpen(0 /* LCD */)
	dispman_update := egl.VCDispmanxUpdateStart(0)

	dispman_element := egl.VCDispmanxElementAdd(
		dispman_update,
		dispman_display,
		0, /*layer */
		&dstRect,
		0, /*src */
		&srcRect,
		egl.DISPMANX_PROTECTION_NONE,
		nil, /*alpha */
		nil, /*clamp */
		0 /*transform */)

	dispmanxTestWin.Element = dispman_element
	dispmanxTestWin.Width = int(screenWidth)
	dispmanxTestWin.Height = int(screenHeight)
	egl.VCDispmanxUpdateSubmitSync(dispman_update)
	testWin = egl.NativeWindowType(unsafe.Pointer(&dispmanxTestWin))
}
Example #2
0
func initPlatform() {
	var err error
	X, err = xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	testWin = egl.NativeWindowType(uintptr(openWin(X).Id))
}
Example #3
0
func initEGL(controlCh *controlCh, width, height int) *platform.EGLState {
	X, err := xgbutil.NewConn()
	if err != nil {
		panic(err)
	}
	mousebind.Initialize(X)
	keybind.Initialize(X)
	xWindow := newWindow(controlCh, X, width, height)
	go xevent.Main(X)
	return xorg.Initialize(
		egl.NativeWindowType(uintptr(xWindow.Id)),
		xorg.DefaultConfigAttributes,
		xorg.DefaultContextAttributes,
	)
}
Example #4
0
func Initialize(win unsafe.Pointer, configAttr, contextAttr []int32) *platform.EGLState {
	eglState := new(platform.EGLState)
	eglState.Display = getEGLDisp(egl.DEFAULT_DISPLAY)
	eglState.Config = chooseEGLConfig(eglState.Display, configAttr)
	eglState.VisualId = getEGLNativeVisualId(eglState.Display, eglState.Config)
	C.ANativeWindow_setBuffersGeometry((*[0]byte)(win), 0, 0, C.int32_t(eglState.VisualId))
	eglState.Surface = EGLCreateWindowSurface(eglState.Display, eglState.Config, egl.NativeWindowType(win))

	egl.BindAPI(egl.OPENGL_ES_API)
	eglState.Context = egl.CreateContext(eglState.Display, eglState.Config, egl.NO_CONTEXT, &contextAttr[0])

	eglState.SurfaceWidth = int(C.ANativeWindow_getWidth((*C.ANativeWindow)(win)))
	eglState.SurfaceHeight = int(C.ANativeWindow_getHeight((*C.ANativeWindow)(win)))

	return eglState
}
Example #5
0
//export onNativeWindowCreated
func onNativeWindowCreated(act *C.ANativeActivity, win unsafe.Pointer) {
	defer func() {
		handleCallbackError(act, recover())
	}()
	log.Printf("onNativeWindowCreated...\n")
	state := states[act]
	if state.renderState == nil {
		state.renderState = &renderState{
			disp: getEGLDisp(egl.NativeDisplayType(nil)),
		}
		state.renderState.conf = chooseEGLConfig(state.renderState.disp)
	}
	vid := getEGLNativeVisualId(state.renderState.disp, state.renderState.conf)
	C.ANativeWindow_setBuffersGeometry((*[0]byte)(win), 0, 0, C.int32_t(vid))
	state.renderState.surf = EGLCreateWindowSurface(state.renderState.disp, state.renderState.conf, egl.NativeWindowType(win))

	state.mLoop.UpdateRenderState(state.renderState)
	log.Printf("onNativeWindowCreated done\n")
}
Example #6
0
func Initialize(configAttr, contextAttr []int32) *platform.EGLState {
	var (
		config           egl.Config
		numConfig        int32
		visualId         int32
		width, height    int32
		dstRect, srcRect egl.VCRect
		nativeWindow     egl.EGLDispmanxWindow
	)
	display := egl.GetDisplay(egl.DEFAULT_DISPLAY)
	if ok := egl.Initialize(egl.Display, nil, nil); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.ChooseConfig(display, configAttr, &config, 1, &numConfig); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(display, config, egl.NATIVE_VISUAL_ID, &visualId); !ok {
		egl.LogError(egl.GetError())
	}
	egl.BindAPI(egl.OPENGL_ES_API)
	context := egl.CreateContext(display, config, egl.NO_CONTEXT, &contextAttr[0])

	width, height = egl.GraphicsGetDisplaySize(0)

	dstRect.X = 0
	dstRect.Y = 0
	dstRect.Width = int32(width)
	dstRect.Height = int32(height)

	srcRect.X = 0
	srcRect.Y = 0
	srcRect.Width = int32(width << 16)
	srcRect.Height = int32(height << 16)

	dispman_display := egl.VCDispmanxDisplayOpen(0)
	dispman_update := egl.VCDispmanxUpdateStart(0)
	dispman_element := egl.VCDispmanxElementAdd(
		dispman_update,
		dispman_display,
		0, /*layer */
		&dstRect,
		0, /*src */
		&srcRect,
		egl.DISPMANX_PROTECTION_NONE,
		nil, /*alpha */
		nil, /*clamp */
		0 /*transform */)

	nativeWindow.Element = dispman_element
	nativeWindow.Width = int(width)
	nativeWindow.Height = int(height)
	egl.VCDispmanxUpdateSubmitSync(dispman_update)

	surface := egl.CreateWindowSurface(
		display,
		config,
		egl.NativeWindowType(unsafe.Pointer(&nativeWindow)),
		nil)

	if surface == egl.NO_SURFACE {
		panic("Error in creating EGL surface")
	}

	return &platform.EGLState{
		Display:           display,
		Config:            config,
		Context:           context,
		Surface:           surface,
		NumConfig:         numConfig,
		VisualId:          visualId,
		ContextAttributes: contextAttr,
		ConfigAttributes:  configAttr,
		SurfaceWidth:      int(width),
		SurfaceHeight:     int(height),
	}
}