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" 28 #if SDL_VIDEO_DRIVER_ANDROID 29 #include <android/native_window.h> 38 #ifdef EGL_KHR_create_context 40 #ifndef EGL_OPENGL_ES3_BIT_KHR 41 #define EGL_OPENGL_ES3_BIT_KHR 0x00000040 45 #if SDL_VIDEO_DRIVER_RPI 47 #define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" ) 48 #define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" ) 49 #define ALT_EGL "libEGL.so" 50 #define ALT_OGL_ES2 "libGLESv2.so" 51 #define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so" ) 52 #define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so" ) 54 #elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE 56 #define DEFAULT_EGL "libEGL.so" 57 #define DEFAULT_OGL_ES2 "libGLESv2.so" 58 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so" 59 #define DEFAULT_OGL_ES "libGLESv1_CM.so" 61 #elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 63 #define DEFAULT_EGL "libEGL.dll" 64 #define DEFAULT_OGL_ES2 "libGLESv2.dll" 65 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dll" 66 #define DEFAULT_OGL_ES "libGLESv1_CM.dll" 68 #elif SDL_VIDEO_DRIVER_COCOA 70 #define DEFAULT_EGL "libEGL.dylib" 71 #define DEFAULT_OGL_ES2 "libGLESv2.dylib" 72 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dylib" //??? 73 #define DEFAULT_OGL_ES "libGLESv1_CM.dylib" //??? 77 #define DEFAULT_OGL "libGL.so.1" 78 #define DEFAULT_EGL "libEGL.so.1" 79 #define DEFAULT_OGL_ES2 "libGLESv2.so.2" 80 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1" 81 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1" 84 #ifdef SDL_VIDEO_STATIC_ANGLE 85 #define LOAD_FUNC(NAME) \ 86 _this->egl_data->NAME = (void *)NAME; 88 #define LOAD_FUNC(NAME) \ 89 _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \ 90 if (!_this->egl_data->NAME) \ 92 return SDL_SetError("Could not retrieve EGL function " #NAME); \ 96 static const char * SDL_EGL_GetErrorName(
EGLint eglErrorCode)
98 #define SDL_EGL_ERROR_TRANSLATE(e) case e: return #e; 99 switch (eglErrorCode) {
119 int SDL_EGL_SetErrorEx(
const char *
message,
const char * eglFunctionName,
EGLint eglErrorCode)
121 const char * errorText = SDL_EGL_GetErrorName(eglErrorCode);
122 char altErrorText[32];
123 if (errorText[0] ==
'\0') {
126 errorText = altErrorText;
128 return SDL_SetError(
"%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);
133 SDL_EGL_DISPLAY_EXTENSION,
134 SDL_EGL_CLIENT_EXTENSION
135 } SDL_EGL_ExtensionType;
137 static SDL_bool SDL_EGL_HasExtension(
_THIS, SDL_EGL_ExtensionType
type,
const char *ext)
140 const char *ext_override;
141 const char *egl_extstr;
142 const char *ext_start;
158 if (ext_override !=
NULL) {
159 int disable_ext =
SDL_atoi(ext_override);
160 if (disable_ext & 0x01 && type == SDL_EGL_DISPLAY_EXTENSION) {
162 }
else if (disable_ext & 0x02 && type == SDL_EGL_CLIENT_EXTENSION) {
169 case SDL_EGL_DISPLAY_EXTENSION:
172 case SDL_EGL_CLIENT_EXTENSION:
184 if (egl_extstr !=
NULL) {
185 ext_start = egl_extstr;
189 if (ext_start ==
NULL) {
193 if (ext_start == egl_extstr || *(ext_start - 1) ==
' ') {
194 if (ext_start[ext_len] ==
' ' || ext_start[ext_len] == 0) {
199 ext_start += ext_len;
200 while (*ext_start !=
' ' && *ext_start != 0) {
210 SDL_EGL_GetProcAddress(
_THIS,
const char *proc)
212 static char procname[1024];
216 #if !defined(SDL_VIDEO_DRIVER_ANDROID) 217 if (
_this->egl_data->eglGetProcAddress) {
218 retval =
_this->egl_data->eglGetProcAddress(proc);
235 SDL_EGL_UnloadLibrary(
_THIS)
237 if (
_this->egl_data) {
238 if (
_this->egl_data->egl_display) {
239 _this->egl_data->eglTerminate(
_this->egl_data->egl_display);
247 if (
_this->egl_data->egl_dll_handle) {
260 void *dll_handle =
NULL, *egl_dll_handle =
NULL;
262 int egl_version_major = 0, egl_version_minor = 0;
263 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 264 const char *d3dcompiler;
266 #if SDL_VIDEO_DRIVER_RPI 270 if (
_this->egl_data) {
274 _this->egl_data = (
struct SDL_EGL_VideoData *)
SDL_calloc(1,
sizeof(SDL_EGL_VideoData));
275 if (!
_this->egl_data) {
279 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT 283 d3dcompiler =
"d3dcompiler_46.dll";
285 d3dcompiler =
"d3dcompiler_43.dll";
295 #ifndef SDL_VIDEO_STATIC_ANGLE 302 if (egl_dll_handle ==
NULL) {
305 path = DEFAULT_OGL_ES2;
308 if (egl_dll_handle ==
NULL && !vc4) {
315 path = DEFAULT_OGL_ES;
317 if (egl_dll_handle ==
NULL) {
318 path = DEFAULT_OGL_ES_PVR;
322 if (egl_dll_handle ==
NULL && !vc4) {
336 _this->egl_data->egl_dll_handle = egl_dll_handle;
338 if (egl_dll_handle ==
NULL) {
339 return SDL_SetError(
"Could not initialize OpenGL / GLES library");
343 if (egl_path !=
NULL) {
348 if (dll_handle !=
NULL) {
358 if (dll_handle ==
NULL && !vc4) {
365 if (dll_handle !=
NULL) {
397 if (
_this->egl_data->eglQueryString) {
400 if (egl_version !=
NULL) {
401 if (
SDL_sscanf(egl_version,
"%d.%d", &egl_version_major, &egl_version_minor) != 2) {
402 egl_version_major = 0;
403 egl_version_minor = 0;
409 if (egl_version_major == 1 && egl_version_minor == 5) {
414 #if !defined(__WINRT__) 416 if (egl_version_major == 1 && egl_version_minor == 5) {
417 _this->egl_data->egl_display =
_this->egl_data->eglGetPlatformDisplay(platform, (
void *)(
size_t)native_display,
NULL);
419 if (SDL_EGL_HasExtension(
_this, SDL_EGL_CLIENT_EXTENSION,
"EGL_EXT_platform_base")) {
420 _this->egl_data->eglGetPlatformDisplayEXT = SDL_EGL_GetProcAddress(
_this,
"eglGetPlatformDisplayEXT");
421 if (
_this->egl_data->eglGetPlatformDisplayEXT) {
422 _this->egl_data->egl_display =
_this->egl_data->eglGetPlatformDisplayEXT(platform, (
void *)(
size_t)native_display,
NULL);
429 _this->egl_data->egl_display =
_this->egl_data->eglGetDisplay(native_display);
450 SDL_EGL_ChooseConfig(
_THIS)
455 #ifdef SDL_VIDEO_DRIVER_KMSDRM 463 int i,
j, best_bitdiff = -1, bitdiff;
465 if (!
_this->egl_data) {
509 #ifdef EGL_KHR_create_context 511 SDL_EGL_HasExtension(
_this, SDL_EGL_DISPLAY_EXTENSION,
"EGL_KHR_create_context")) {
526 if (
_this->egl_data->egl_surfacetype) {
528 attribs[i++] =
_this->egl_data->egl_surfacetype;
533 if (
_this->egl_data->eglChooseConfig(
_this->egl_data->egl_display,
537 found_configs == 0) {
538 return SDL_EGL_SetError(
"Couldn't find matching EGL config",
"eglChooseConfig");
544 for (i = 0; i < found_configs; i++ ) {
558 _this->egl_data->eglGetConfigAttrib(
_this->egl_data->egl_display, configs[i], attribs[j], &
value);
559 bitdiff +=
value - attribs[j + 1];
563 if (bitdiff < best_bitdiff || best_bitdiff == -1) {
564 _this->egl_data->egl_config = configs[
i];
566 best_bitdiff = bitdiff;
590 if (!
_this->egl_data) {
600 if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
602 (profile_mask == 0 || profile_es)) {
611 attribs[attr++] =
SDL_max(major_version, 1);
614 #ifdef EGL_KHR_create_context 618 if (SDL_EGL_HasExtension(
_this, SDL_EGL_DISPLAY_EXTENSION,
"EGL_KHR_create_context")) {
620 attribs[attr++] = major_version;
622 attribs[attr++] = minor_version;
627 attribs[attr++] = profile_mask;
638 SDL_SetError(
"Could not create EGL context (context attributes are not supported)");
644 #ifdef EGL_KHR_create_context_no_error 645 if (SDL_EGL_HasExtension(
_this, SDL_EGL_DISPLAY_EXTENSION,
"EGL_KHR_create_context_no_error")) {
651 SDL_SetError(
"EGL implementation does not support no_error contexts");
665 egl_context =
_this->egl_data->eglCreateContext(
_this->egl_data->egl_display,
666 _this->egl_data->egl_config,
667 share_context, attribs);
670 SDL_EGL_SetError(
"Could not create EGL context",
"eglCreateContext");
674 _this->egl_data->egl_swapinterval = 0;
676 if (SDL_EGL_MakeCurrent(
_this, egl_surface, egl_context) < 0) {
678 char errorText[1024];
682 SDL_EGL_DeleteContext(
_this, egl_context);
698 if (!
_this->egl_data) {
705 if (!egl_context || !egl_surface) {
708 if (!
_this->egl_data->eglMakeCurrent(
_this->egl_data->egl_display,
709 egl_surface, egl_surface, egl_context)) {
710 return SDL_EGL_SetError(
"Unable to make EGL context current",
"eglMakeCurrent");
718 SDL_EGL_SetSwapInterval(
_THIS,
int interval)
722 if (!
_this->egl_data) {
726 status =
_this->egl_data->eglSwapInterval(
_this->egl_data->egl_display, interval);
728 _this->egl_data->egl_swapinterval = interval;
732 return SDL_EGL_SetError(
"Unable to set the EGL swap interval",
"eglSwapInterval");
736 SDL_EGL_GetSwapInterval(
_THIS)
738 if (!
_this->egl_data) {
743 return _this->egl_data->egl_swapinterval;
749 if (!
_this->egl_data->eglSwapBuffers(
_this->egl_data->egl_display, egl_surface)) {
750 return SDL_EGL_SetError(
"unable to show color buffer in an OS-native window",
"eglSwapBuffers");
761 if (!
_this->egl_data) {
767 _this->egl_data->eglDestroyContext(
_this->egl_data->egl_display, egl_context);
781 if (SDL_EGL_ChooseConfig(
_this) != 0) {
785 #if SDL_VIDEO_DRIVER_ANDROID 791 _this->egl_data->eglGetConfigAttrib(
_this->egl_data->egl_display,
792 _this->egl_data->egl_config,
795 ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
799 #ifdef EGL_KHR_gl_colorspace 800 if (SDL_EGL_HasExtension(
_this, SDL_EGL_DISPLAY_EXTENSION,
"EGL_KHR_gl_colorspace")) {
806 SDL_SetError(
"EGL implementation does not support sRGB system framebuffers");
813 surface =
_this->egl_data->eglCreateWindowSurface(
814 _this->egl_data->egl_display,
815 _this->egl_data->egl_config,
818 SDL_EGL_SetError(
"unable to create an EGL window surface",
"eglCreateWindowSurface");
826 if (!
_this->egl_data) {
831 _this->egl_data->eglDestroySurface(
_this->egl_data->egl_display, egl_surface);
#define EGL_BAD_PARAMETER
#define EGL_CONTEXT_FLAGS_KHR
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
BOOL WIN_IsWindowsVistaOrGreater(void)
EGLAPI const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name)
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
GLuint GLsizei const GLchar * message
#define EGL_SAMPLE_BUFFERS
#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR
static screen_context_t context
EGLAPI EGLint EGLAPIENTRY eglGetError(void)
EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
#define EGL_OPENGL_ES_API
GLuint GLint GLboolean GLint GLenum access
#define EGL_BAD_CURRENT_SURFACE
#define EGL_NATIVE_VISUAL_ID
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
static SDL_VideoDevice * _this
#define SDL_HINT_VIDEO_WIN_D3DCOMPILER
A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries...
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define EGL_GL_COLORSPACE_SRGB_KHR
void * SDL_GLContext
An opaque handle to an OpenGL context.
#define EGL_OPENGL_ES_BIT
#define EGL_CONTEXT_CLIENT_VERSION
#define EGL_OPENGL_ES3_BIT_KHR
#define EGL_CONTEXT_MAJOR_VERSION_KHR
#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR
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)
#define EGL_CONTEXT_MINOR_VERSION_KHR
GLsizei const GLfloat * value
int framebuffer_srgb_capable
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
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void)
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
#define EGL_BAD_ATTRIBUTE
GLuint GLuint GLsizei GLenum type
#define SDL_arraysize(array)
EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine)
GLsizei const GLchar *const * path
struct SDL_VideoDevice::@34 gl_config
void * SDL_LoadFunction(void *handle, const char *name)
#define EGL_BAD_NATIVE_WINDOW
EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list)
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
#define EGL_BAD_NATIVE_PIXMAP
#define EGL_NOT_INITIALIZED
#define EGL_GL_COLORSPACE_KHR
#define EGL_RENDERABLE_TYPE
#define EGL_OPENGL_ES2_BIT
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)