21 #include "../SDL_internal.h" 23 #if SDL_VIDEO_OPENGL_EGL 25 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 26 #include "../core/windows/SDL_windows.h" 34 #ifdef EGL_KHR_create_context 36 #ifndef EGL_OPENGL_ES3_BIT_KHR 37 #define EGL_OPENGL_ES3_BIT_KHR 0x00000040 41 #if SDL_VIDEO_DRIVER_RPI 43 #define DEFAULT_EGL "/opt/vc/lib/libEGL.so" 44 #define DEFAULT_OGL_ES2 "/opt/vc/lib/libGLESv2.so" 45 #define DEFAULT_OGL_ES_PVR "/opt/vc/lib/libGLES_CM.so" 46 #define DEFAULT_OGL_ES "/opt/vc/lib/libGLESv1_CM.so" 48 #elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE 50 #define DEFAULT_EGL "libEGL.so" 51 #define DEFAULT_OGL_ES2 "libGLESv2.so" 52 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so" 53 #define DEFAULT_OGL_ES "libGLESv1_CM.so" 55 #elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 57 #define DEFAULT_EGL "libEGL.dll" 58 #define DEFAULT_OGL_ES2 "libGLESv2.dll" 59 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dll" 60 #define DEFAULT_OGL_ES "libGLESv1_CM.dll" 64 #define DEFAULT_OGL "libGL.so.1" 65 #define DEFAULT_EGL "libEGL.so.1" 66 #define DEFAULT_OGL_ES2 "libGLESv2.so.2" 67 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1" 68 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1" 71 #define LOAD_FUNC(NAME) \ 72 _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \ 73 if (!_this->egl_data->NAME) \ 75 return SDL_SetError("Could not retrieve EGL function " #NAME); \ 79 #ifdef EGL_KHR_create_context 80 static int SDL_EGL_HasExtension(
_THIS,
const char *ext)
89 exts =
_this->egl_data->eglQueryString(
_this->egl_data->egl_display, EGL_EXTENSIONS);
94 for (i = 0; exts[
i] != 0; i++) {
96 if (ext_len == len && !
SDL_strncmp(ext_word, ext, len)) {
101 ext_word = &exts[i + 1];
113 SDL_EGL_GetProcAddress(
_THIS,
const char *proc)
115 static char procname[1024];
119 #if !defined(SDL_VIDEO_DRIVER_ANDROID) && !defined(SDL_VIDEO_DRIVER_MIR) 120 if (
_this->egl_data->eglGetProcAddress) {
121 retval =
_this->egl_data->eglGetProcAddress(proc);
138 SDL_EGL_UnloadLibrary(
_THIS)
140 if (
_this->egl_data) {
141 if (
_this->egl_data->egl_display) {
142 _this->egl_data->eglTerminate(
_this->egl_data->egl_display);
150 if (
_this->egl_data->egl_dll_handle) {
161 SDL_EGL_LoadLibrary(
_THIS,
const char *egl_path, NativeDisplayType native_display)
163 void *dll_handle =
NULL, *egl_dll_handle =
NULL;
165 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 166 const char *d3dcompiler;
169 if (
_this->egl_data) {
170 return SDL_SetError(
"OpenGL ES context already created");
173 _this->egl_data = (
struct SDL_EGL_VideoData *)
SDL_calloc(1,
sizeof(SDL_EGL_VideoData));
174 if (!
_this->egl_data) {
178 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 182 d3dcompiler =
"d3dcompiler_46.dll";
184 d3dcompiler =
"d3dcompiler_43.dll";
198 if (egl_dll_handle ==
NULL) {
201 path = DEFAULT_OGL_ES2;
204 path = DEFAULT_OGL_ES;
206 if (egl_dll_handle ==
NULL) {
207 path = DEFAULT_OGL_ES_PVR;
219 _this->egl_data->egl_dll_handle = egl_dll_handle;
221 if (egl_dll_handle ==
NULL) {
222 return SDL_SetError(
"Could not initialize OpenGL / GLES library");
226 if (egl_path !=
NULL) {
231 if (dll_handle !=
NULL) {
240 if (dll_handle !=
NULL) {
251 LOAD_FUNC(eglGetDisplay);
252 LOAD_FUNC(eglInitialize);
253 LOAD_FUNC(eglTerminate);
254 LOAD_FUNC(eglGetProcAddress);
255 LOAD_FUNC(eglChooseConfig);
256 LOAD_FUNC(eglGetConfigAttrib);
257 LOAD_FUNC(eglCreateContext);
258 LOAD_FUNC(eglDestroyContext);
259 LOAD_FUNC(eglCreateWindowSurface);
260 LOAD_FUNC(eglDestroySurface);
261 LOAD_FUNC(eglMakeCurrent);
262 LOAD_FUNC(eglSwapBuffers);
263 LOAD_FUNC(eglSwapInterval);
264 LOAD_FUNC(eglWaitNative);
265 LOAD_FUNC(eglWaitGL);
266 LOAD_FUNC(eglBindAPI);
267 LOAD_FUNC(eglQueryString);
269 #if !defined(__WINRT__) 270 _this->egl_data->egl_display =
_this->egl_data->eglGetDisplay(native_display);
271 if (!
_this->egl_data->egl_display) {
275 if (
_this->egl_data->eglInitialize(
_this->egl_data->egl_display,
NULL,
NULL) != EGL_TRUE) {
292 SDL_EGL_ChooseConfig(
_THIS)
296 EGLint found_configs = 0,
value;
298 EGLConfig configs[128];
299 int i,
j, best_bitdiff = -1, bitdiff;
301 if (!
_this->egl_data) {
308 attribs[i++] = EGL_RED_SIZE;
310 attribs[i++] = EGL_GREEN_SIZE;
312 attribs[i++] = EGL_BLUE_SIZE;
316 attribs[i++] = EGL_ALPHA_SIZE;
321 attribs[i++] = EGL_BUFFER_SIZE;
325 attribs[i++] = EGL_DEPTH_SIZE;
329 attribs[i++] = EGL_STENCIL_SIZE;
334 attribs[i++] = EGL_SAMPLE_BUFFERS;
339 attribs[i++] = EGL_SAMPLES;
344 #ifdef EGL_KHR_gl_colorspace 345 if (SDL_EGL_HasExtension(
_this,
"EGL_KHR_gl_colorspace")) {
346 attribs[i++] = EGL_GL_COLORSPACE_KHR;
347 attribs[i++] = EGL_GL_COLORSPACE_SRGB_KHR;
351 return SDL_SetError(
"EGL implementation does not support sRGB system framebuffers");
355 attribs[i++] = EGL_RENDERABLE_TYPE;
357 #ifdef EGL_KHR_create_context 359 SDL_EGL_HasExtension(
_this,
"EGL_KHR_create_context")) {
360 attribs[i++] = EGL_OPENGL_ES3_BIT_KHR;
364 attribs[i++] = EGL_OPENGL_ES2_BIT;
366 attribs[i++] = EGL_OPENGL_ES_BIT;
368 _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
370 attribs[i++] = EGL_OPENGL_BIT;
371 _this->egl_data->eglBindAPI(EGL_OPENGL_API);
374 attribs[i++] = EGL_NONE;
376 if (
_this->egl_data->eglChooseConfig(
_this->egl_data->egl_display,
379 &found_configs) == EGL_FALSE ||
380 found_configs == 0) {
381 return SDL_SetError(
"Couldn't find matching EGL config");
387 for (i = 0; i < found_configs; i++ ) {
390 if (attribs[j] == EGL_NONE) {
394 if ( attribs[j+1] != EGL_DONT_CARE && (
395 attribs[j] == EGL_RED_SIZE ||
396 attribs[j] == EGL_GREEN_SIZE ||
397 attribs[j] == EGL_BLUE_SIZE ||
398 attribs[j] == EGL_ALPHA_SIZE ||
399 attribs[j] == EGL_DEPTH_SIZE ||
400 attribs[j] == EGL_STENCIL_SIZE)) {
401 _this->egl_data->eglGetConfigAttrib(
_this->egl_data->egl_display, configs[i], attribs[j], &
value);
402 bitdiff +=
value - attribs[j + 1];
406 if (bitdiff < best_bitdiff || best_bitdiff == -1) {
407 _this->egl_data->egl_config = configs[
i];
409 best_bitdiff = bitdiff;
421 SDL_EGL_CreateContext(
_THIS, EGLSurface egl_surface)
427 EGLContext egl_context, share_context = EGL_NO_CONTEXT;
433 if (!
_this->egl_data) {
443 if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
445 (profile_mask == 0 || profile_es)) {
453 attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
454 attribs[attr++] =
SDL_max(major_version, 1);
457 #ifdef EGL_KHR_create_context 461 if (SDL_EGL_HasExtension(
_this,
"EGL_KHR_create_context")) {
462 attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
463 attribs[attr++] = major_version;
464 attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
465 attribs[attr++] = minor_version;
469 attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
470 attribs[attr++] = profile_mask;
475 attribs[attr++] = EGL_CONTEXT_FLAGS_KHR;
481 SDL_SetError(
"Could not create EGL context (context attributes are not supported)");
486 attribs[attr++] = EGL_NONE;
490 _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
492 _this->egl_data->eglBindAPI(EGL_OPENGL_API);
495 egl_context =
_this->egl_data->eglCreateContext(
_this->egl_data->egl_display,
496 _this->egl_data->egl_config,
497 share_context, attribs);
499 if (egl_context == EGL_NO_CONTEXT) {
504 _this->egl_data->egl_swapinterval = 0;
506 if (SDL_EGL_MakeCurrent(
_this, egl_surface, egl_context) < 0) {
507 SDL_EGL_DeleteContext(
_this, egl_context);
518 EGLContext egl_context = (EGLContext) context;
520 if (!
_this->egl_data) {
527 if (!egl_context || !egl_surface) {
528 _this->egl_data->eglMakeCurrent(
_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
530 if (!
_this->egl_data->eglMakeCurrent(
_this->egl_data->egl_display,
531 egl_surface, egl_surface, egl_context)) {
532 return SDL_SetError(
"Unable to make EGL context current");
540 SDL_EGL_SetSwapInterval(
_THIS,
int interval)
544 if (!
_this->egl_data) {
548 status =
_this->egl_data->eglSwapInterval(
_this->egl_data->egl_display, interval);
549 if (status == EGL_TRUE) {
550 _this->egl_data->egl_swapinterval = interval;
554 return SDL_SetError(
"Unable to set the EGL swap interval");
558 SDL_EGL_GetSwapInterval(
_THIS)
560 if (!
_this->egl_data) {
564 return _this->egl_data->egl_swapinterval;
568 SDL_EGL_SwapBuffers(
_THIS, EGLSurface egl_surface)
570 _this->egl_data->eglSwapBuffers(
_this->egl_data->egl_display, egl_surface);
576 EGLContext egl_context = (EGLContext) context;
579 if (!
_this->egl_data) {
583 if (egl_context !=
NULL && egl_context != EGL_NO_CONTEXT) {
585 _this->egl_data->eglDestroyContext(
_this->egl_data->egl_display, egl_context);
591 SDL_EGL_CreateSurface(
_THIS, NativeWindowType nw)
593 if (SDL_EGL_ChooseConfig(
_this) != 0) {
594 return EGL_NO_SURFACE;
603 _this->egl_data->eglGetConfigAttrib(
_this->egl_data->egl_display,
604 _this->egl_data->egl_config,
605 EGL_NATIVE_VISUAL_ID, &format);
607 ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
611 return _this->egl_data->eglCreateWindowSurface(
612 _this->egl_data->egl_display,
613 _this->egl_data->egl_config,
618 SDL_EGL_DestroySurface(
_THIS, EGLSurface egl_surface)
620 if (!
_this->egl_data) {
624 if (egl_surface != EGL_NO_SURFACE) {
625 _this->egl_data->eglDestroySurface(
_this->egl_data->egl_display, egl_surface);
BOOL WIN_IsWindowsVistaOrGreater()
static SDL_VideoDevice * _this
#define SDL_HINT_VIDEO_WIN_D3DCOMPILER
A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries...
void * SDL_calloc(size_t nmemb, size_t size)
void * SDL_GLContext
An opaque handle to an OpenGL context.
GLsizei const GLfloat * value
int framebuffer_srgb_capable
struct SDL_VideoDevice::@27 gl_config
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
int share_with_current_context
#define SDL_OutOfMemory()
#define SDL_GL_GetCurrentContext
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define SDL_arraysize(array)
GLsizei const GLchar *const * path
void * SDL_LoadFunction(void *handle, const char *name)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)