forked from remogatto/mandala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_android.go
48 lines (40 loc) · 1.33 KB
/
window_android.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// +build android
package mandala
import (
"unsafe"
"github.com/remogatto/egl"
"github.com/remogatto/egl/platform"
)
// #include <android/native_window.h>
import "C"
type window struct {
window unsafe.Pointer
eglState *platform.EGLState
}
// SwapBuffers swaps the surface with the display actually showing the
// result of rendering.
func (win *window) SwapBuffers() {
egl.SwapBuffers(win.eglState.Display, win.eglState.Surface)
}
// MakeContextCurrent bind the OpenGL context to the current thread.
func (win *window) MakeContextCurrent() {
if ok := egl.MakeCurrent(
win.eglState.Display,
win.eglState.Surface,
win.eglState.Surface,
win.eglState.Context); !ok {
Fatalf("%s", egl.NewError(egl.GetError()))
}
}
// GetSize returns the dimension of the rendering surface.
func (win *window) GetSize() (int, int) {
win.eglState.SurfaceWidth = int(C.ANativeWindow_getWidth((*C.ANativeWindow)(win.window)))
win.eglState.SurfaceHeight = int(C.ANativeWindow_getHeight((*C.ANativeWindow)(win.window)))
return win.eglState.SurfaceWidth, win.eglState.SurfaceHeight
}
func (win *window) resize(androidWin unsafe.Pointer) {
width := int(C.ANativeWindow_getWidth((*C.ANativeWindow)(androidWin)))
height := int(C.ANativeWindow_getHeight((*C.ANativeWindow)(androidWin)))
win.eglState.SurfaceWidth = width
win.eglState.SurfaceHeight = height
}