23 #if SDL_VIDEO_OPENGL_EGL
28 #if SDL_VIDEO_DRIVER_RPI
29 #define DEFAULT_EGL "/opt/vc/lib/libEGL.so"
30 #define DEFAULT_OGL_ES2 "/opt/vc/lib/libGLESv2.so"
31 #define DEFAULT_OGL_ES_PVR "/opt/vc/lib/libGLES_CM.so"
32 #define DEFAULT_OGL_ES "/opt/vc/lib/libGLESv1_CM.so"
34 #define DEFAULT_EGL "libEGL.so.1"
35 #define DEFAULT_OGL_ES2 "libGLESv2.so.2"
36 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
37 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
40 #define LOAD_FUNC(NAME) \
41 *((void**)&_this->egl_data->NAME) = dlsym(dll_handle, #NAME); \
42 if (!_this->egl_data->NAME) \
44 return SDL_SetError("Could not retrieve EGL function " #NAME); \
50 SDL_EGL_GetProcAddress(
_THIS,
const char *proc)
52 static char procname[1024];
57 #if !defined(SDL_VIDEO_DRIVER_ANDROID)
58 handle =
_this->egl_data->egl_dll_handle;
59 if (
_this->egl_data->eglGetProcAddress) {
60 retval =
_this->egl_data->eglGetProcAddress(proc);
68 #if defined(__OpenBSD__) && !defined(__ELF__)
71 retval = dlsym(handle, proc);
72 if (!retval && strlen(proc) <= 1022) {
74 strcpy(procname + 1, proc);
75 retval = dlsym(handle, procname);
81 SDL_EGL_UnloadLibrary(
_THIS)
84 _this->egl_data->eglTerminate(
_this->egl_data->egl_display);
87 dlclose(
_this->egl_data->egl_dll_handle);
100 void *dll_handle, *egl_dll_handle;
104 if (
_this->egl_data) {
105 return SDL_SetError(
"OpenGL ES context already created");
109 SDL_EGL_UnloadLibrary(
_this);
112 dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
114 dlopen_flags = RTLD_LAZY;
118 path = getenv(
"SDL_VIDEO_GL_DRIVER");
119 egl_dll_handle = dlopen(path, dlopen_flags);
120 if ((path ==
NULL) | (egl_dll_handle ==
NULL)) {
122 path = DEFAULT_OGL_ES2;
123 egl_dll_handle = dlopen(path, dlopen_flags);
125 path = DEFAULT_OGL_ES;
126 egl_dll_handle = dlopen(path, dlopen_flags);
127 if (egl_dll_handle ==
NULL) {
128 path = DEFAULT_OGL_ES_PVR;
129 egl_dll_handle = dlopen(path, dlopen_flags);
134 if (egl_dll_handle ==
NULL) {
135 return SDL_SetError(
"Could not initialize OpenGL ES library: %s", dlerror());
139 dll_handle = dlopen(egl_path, dlopen_flags);
141 if ((dlsym(dll_handle,
"eglChooseConfig") ==
NULL) && (egl_path ==
NULL)) {
143 path = getenv(
"SDL_VIDEO_EGL_DRIVER");
147 dll_handle = dlopen(path, dlopen_flags);
150 if (dll_handle ==
NULL) {
151 return SDL_SetError(
"Could not load EGL library: %s", dlerror());
154 _this->egl_data = (
struct SDL_EGL_VideoData *)
SDL_calloc(1,
sizeof(SDL_EGL_VideoData));
155 if (!
_this->egl_data) {
176 _this->egl_data->egl_display =
_this->egl_data->eglGetDisplay(native_display);
178 if (!
_this->egl_data->egl_display) {
187 _this->egl_data->egl_dll_handle = egl_dll_handle;
197 SDL_EGL_ChooseConfig(
_this);
203 SDL_EGL_ChooseConfig(
_THIS)
210 if (!
_this->egl_data) {
261 if (
_this->egl_data->eglChooseConfig(
_this->egl_data->egl_display,
263 &
_this->egl_data->egl_config, 1,
265 found_configs == 0) {
266 return SDL_SetError(
"Couldn't find matching EGL config");
275 EGLint context_attrib_list[] = {
283 if (!
_this->egl_data) {
293 _this->egl_data->eglCreateContext(
_this->egl_data->egl_display,
294 _this->egl_data->egl_config,
302 _this->egl_data->egl_swapinterval = 0;
304 if (SDL_EGL_MakeCurrent(
_this, egl_surface, egl_context) < 0) {
305 SDL_EGL_DeleteContext(
_this, egl_context);
318 if (!
_this->egl_data) {
325 if (!egl_context || !egl_surface) {
329 if (!
_this->egl_data->eglMakeCurrent(
_this->egl_data->egl_display,
330 egl_surface, egl_surface, egl_context)) {
331 return SDL_SetError(
"Unable to make EGL context current");
339 SDL_EGL_SetSwapInterval(
_THIS,
int interval)
343 if (!
_this->egl_data) {
347 status =
_this->egl_data->eglSwapInterval(
_this->egl_data->egl_display, interval);
349 _this->egl_data->egl_swapinterval = interval;
353 return SDL_SetError(
"Unable to set the EGL swap interval");
357 SDL_EGL_GetSwapInterval(
_THIS)
359 if (!
_this->egl_data) {
363 return _this->egl_data->egl_swapinterval;
369 _this->egl_data->eglSwapBuffers(
_this->egl_data->egl_display, egl_surface);
378 if (!
_this->egl_data) {
384 _this->egl_data->eglDestroyContext(
_this->egl_data->egl_display, egl_context);
389 SDL_EGL_UnloadLibrary(
_this);
395 return _this->egl_data->eglCreateWindowSurface(
396 _this->egl_data->egl_display,
397 _this->egl_data->egl_config,
404 if (!
_this->egl_data) {
409 _this->egl_data->eglDestroySurface(
_this->egl_data->egl_display, egl_surface);
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
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)
#define EGL_SAMPLE_BUFFERS
DECLSPEC void SDLCALL SDL_free(void *mem)
void * SDL_GLContext
An opaque handle to an OpenGL context.
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
GLsizei const GLchar *const * path
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
static SDL_VideoDevice * _this
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
#define EGL_OPENGL_ES_BIT
#define EGL_CONTEXT_CLIENT_VERSION
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
#define SDL_OutOfMemory()
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)
EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine)
EGLImageKHR EGLint EGLint * handle
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
struct SDL_VideoDevice::@87 gl_config
#define EGL_RENDERABLE_TYPE
#define EGL_OPENGL_ES2_BIT
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)