Esempio n. 1
0
func chooseEGLConfig(eglDisp egl.Display, configAttr []int32) egl.Config {
	var config egl.Config
	var num_configs int32
	if !egl.ChooseConfig(eglDisp, configAttr, &config, 1, &num_configs) {
		panic("Error: couldn't get an EGL visual config\n")
	}

	return config
}
Esempio n. 2
0
func (t *testInitEGLSuite) TestChooseConfig() {
	var (
		config    egl.Config
		numConfig int32
	)
	display := egl.GetDisplay(egl.DEFAULT_DISPLAY)
	t.True(egl.Initialize(display, nil, nil))
	t.True(egl.ChooseConfig(display, configAttr, &config, 1, &numConfig))
	t.Equal(numConfig, int32(1))
	t.True(config != 0)
}
Esempio n. 3
0
func Initialize(window egl.NativeWindowType, configAttr, contextAttr []int32) *platform.EGLState {
	var (
		config        egl.Config
		numConfig     int32
		visualId      int32
		width, height int32
	)
	display := egl.GetDisplay(egl.DEFAULT_DISPLAY)
	if ok := egl.Initialize(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])
	surface := egl.CreateWindowSurface(display, config, window, nil)

	var val int32
	if ok := egl.QuerySurface(display, surface, egl.WIDTH, &width); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.QuerySurface(display, surface, egl.HEIGHT, &height); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(display, config, egl.SURFACE_TYPE, &val); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(display, config, egl.SURFACE_TYPE, &val); !ok {
		egl.LogError(egl.GetError())
	}
	if (val & egl.WINDOW_BIT) == 0 {
		panic("No WINDOW_BIT")
	}
	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),
	}
}
Esempio n. 4
0
func chooseEGLConfig(eglDisp egl.Display) egl.Config {
	eglAttribs := []int32{
		egl.RED_SIZE, 4,
		egl.GREEN_SIZE, 4,
		egl.BLUE_SIZE, 4,
		//C.EGL_DEPTH_SIZE, 1,
		egl.RENDERABLE_TYPE, egl.OPENGL_ES2_BIT,
		egl.SURFACE_TYPE, egl.WINDOW_BIT,
		egl.NONE,
	}

	var config egl.Config
	var num_configs int32
	if !egl.ChooseConfig(eglDisp, eglAttribs, &config, 1, &num_configs) {
		panic("Error: couldn't get an EGL visual config\n")
	}

	return config
}
Esempio n. 5
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),
	}
}
Esempio n. 6
0
func (t *testCreateEGLContextSuite) BeforeAll() {
	t.display = egl.GetDisplay(egl.DEFAULT_DISPLAY)
	egl.Initialize(t.display, nil, nil)
	egl.ChooseConfig(t.display, configAttr, &t.config, 1, &t.numConfig)
	initPlatform()
}