5 #define EGL_EGLEXT_PROTOTYPES
7 #include "EGL/eglext.h"
13 static EGLScreenMESA kms_screen
;
14 static EGLModeMESA kms_mode
;
15 static EGLint kms_width
, kms_height
;
18 _eglutNativeInitDisplay(void)
20 _eglut
->native_dpy
= EGL_DEFAULT_DISPLAY
;
21 _eglut
->surface_type
= EGL_SCREEN_BIT_MESA
;
25 _eglutNativeFiniDisplay(void)
36 EGLModeMESA modes
[MAX_MODES
];
37 EGLint num_screens
, num_modes
;
38 EGLint width
, height
, best_mode
;
41 if (!eglGetScreensMESA(_eglut
->dpy
, &kms_screen
, 1, &num_screens
) ||
43 _eglutFatal("eglGetScreensMESA failed\n");
45 if (!eglGetModesMESA(_eglut
->dpy
, kms_screen
,
46 modes
, MAX_MODES
, &num_modes
) || !num_modes
)
47 _eglutFatal("eglGetModesMESA failed!\n");
49 printf("Found %d modes:\n", num_modes
);
54 for (i
= 0; i
< num_modes
; i
++) {
56 eglGetModeAttribMESA(_eglut
->dpy
, modes
[i
], EGL_WIDTH
, &w
);
57 eglGetModeAttribMESA(_eglut
->dpy
, modes
[i
], EGL_HEIGHT
, &h
);
58 printf("%3d: %d x %d\n", i
, w
, h
);
59 if (w
> width
&& h
> height
) {
66 printf("Will use screen size: %d x %d\n", width
, height
);
68 kms_mode
= modes
[best_mode
];
74 _eglutNativeInitWindow(struct eglut_window
*win
, const char *title
,
75 int x
, int y
, int w
, int h
)
77 EGLint surf_attribs
[16];
81 exts
= eglQueryString(_eglut
->dpy
, EGL_EXTENSIONS
);
82 if (!exts
|| !strstr(exts
, "EGL_MESA_screen_surface"))
83 _eglutFatal("EGL_MESA_screen_surface is not supported\n");
88 surf_attribs
[i
++] = EGL_WIDTH
;
89 surf_attribs
[i
++] = kms_width
;
90 surf_attribs
[i
++] = EGL_HEIGHT
;
91 surf_attribs
[i
++] = kms_height
;
92 surf_attribs
[i
++] = EGL_NONE
;
95 win
->native
.u
.surface
= eglCreateScreenSurfaceMESA(_eglut
->dpy
,
96 win
->config
, surf_attribs
);
97 if (win
->native
.u
.surface
== EGL_NO_SURFACE
)
98 _eglutFatal("eglCreateScreenSurfaceMESA failed\n");
100 if (!eglShowScreenSurfaceMESA(_eglut
->dpy
, kms_screen
,
101 win
->native
.u
.surface
, kms_mode
))
102 _eglutFatal("eglShowScreenSurfaceMESA failed\n");
104 win
->native
.width
= kms_width
;
105 win
->native
.height
= kms_height
;
109 _eglutNativeFiniWindow(struct eglut_window
*win
)
111 eglShowScreenSurfaceMESA(_eglut
->dpy
,
112 kms_screen
, EGL_NO_SURFACE
, 0);
113 eglDestroySurface(_eglut
->dpy
, win
->native
.u
.surface
);
117 _eglutNativeEventLoop(void)
119 int start
= _eglutNow();
122 _eglut
->redisplay
= 1;
125 struct eglut_window
*win
= _eglut
->current
;
126 int now
= _eglutNow();
128 if (now
- start
> 5000) {
129 double elapsed
= (double) (now
- start
) / 1000.0;
131 printf("%d frames in %3.1f seconds = %6.3f FPS\n",
132 frames
, elapsed
, frames
/ elapsed
);
138 if (win
->keyboard_cb
)
139 win
->keyboard_cb(27);
145 if (_eglut
->redisplay
) {
146 _eglut
->redisplay
= 0;
150 eglSwapBuffers(_eglut
->dpy
, win
->surface
);