mirror of
https://github.com/love2d/love-android.git
synced 2026-08-21 05:00:22 +02:00
Bumped SDL2 to the latest development version.
This commit is contained in:
@@ -18,13 +18,14 @@
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
#include "SDL_egl.h"
|
||||
|
||||
#include "SDL_egl_c.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_hints.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
|
||||
@@ -40,8 +41,16 @@
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
|
||||
|
||||
#elif SDL_VIDEO_DRIVER_WINDOWS
|
||||
/* EGL AND OpenGL ES support via ANGLE */
|
||||
#define DEFAULT_EGL "libEGL.dll"
|
||||
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
|
||||
|
||||
#else
|
||||
/* Desktop Linux */
|
||||
#define DEFAULT_OGL "libGL.so.1"
|
||||
#define DEFAULT_EGL "libEGL.so.1"
|
||||
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
|
||||
@@ -49,7 +58,7 @@
|
||||
#endif /* SDL_VIDEO_DRIVER_RPI */
|
||||
|
||||
#define LOAD_FUNC(NAME) \
|
||||
*((void**)&_this->egl_data->NAME) = dlsym(dll_handle, #NAME); \
|
||||
*((void**)&_this->egl_data->NAME) = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
|
||||
if (!_this->egl_data->NAME) \
|
||||
{ \
|
||||
return SDL_SetError("Could not retrieve EGL function " #NAME); \
|
||||
@@ -61,12 +70,10 @@ void *
|
||||
SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
||||
{
|
||||
static char procname[1024];
|
||||
void *handle;
|
||||
void *retval;
|
||||
|
||||
/* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
handle = _this->egl_data->egl_dll_handle;
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
if (_this->egl_data->eglGetProcAddress) {
|
||||
retval = _this->egl_data->eglGetProcAddress(proc);
|
||||
if (retval) {
|
||||
@@ -75,15 +82,11 @@ SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
||||
}
|
||||
#endif
|
||||
|
||||
handle = _this->gl_config.dll_handle;
|
||||
#if defined(__OpenBSD__) && !defined(__ELF__)
|
||||
#undef dlsym(x,y);
|
||||
#endif
|
||||
retval = dlsym(handle, proc);
|
||||
if (!retval && strlen(proc) <= 1022) {
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
|
||||
if (!retval && SDL_strlen(proc) <= 1022) {
|
||||
procname[0] = '_';
|
||||
strcpy(procname + 1, proc);
|
||||
retval = dlsym(handle, procname);
|
||||
SDL_strlcpy(procname + 1, proc, 1022);
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -97,12 +100,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
||||
_this->egl_data->egl_display = NULL;
|
||||
}
|
||||
|
||||
if (_this->gl_config.dll_handle) {
|
||||
dlclose(_this->gl_config.dll_handle);
|
||||
_this->gl_config.dll_handle = NULL;
|
||||
if (_this->egl_data->dll_handle) {
|
||||
SDL_UnloadObject(_this->egl_data->dll_handle);
|
||||
_this->egl_data->dll_handle = NULL;
|
||||
}
|
||||
if (_this->egl_data->egl_dll_handle) {
|
||||
dlclose(_this->egl_data->egl_dll_handle);
|
||||
SDL_UnloadObject(_this->egl_data->egl_dll_handle);
|
||||
_this->egl_data->egl_dll_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -114,10 +117,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
||||
int
|
||||
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
|
||||
{
|
||||
void *dll_handle, *egl_dll_handle; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path;
|
||||
int dlopen_flags;
|
||||
|
||||
void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path = NULL;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
const char *d3dcompiler;
|
||||
#endif
|
||||
|
||||
if (_this->egl_data) {
|
||||
return SDL_SetError("OpenGL ES context already created");
|
||||
}
|
||||
@@ -127,50 +132,71 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
#ifdef RTLD_GLOBAL
|
||||
dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
|
||||
#else
|
||||
dlopen_flags = RTLD_LAZY;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
|
||||
if (!d3dcompiler) {
|
||||
/* By default we load the Vista+ compatible compiler */
|
||||
d3dcompiler = "d3dcompiler_46.dll";
|
||||
}
|
||||
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
|
||||
SDL_LoadObject(d3dcompiler);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
|
||||
path = getenv("SDL_VIDEO_GL_DRIVER");
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
if ((path == NULL) | (egl_dll_handle == NULL)) {
|
||||
if (_this->gl_config.major_version > 1) {
|
||||
path = DEFAULT_OGL_ES2;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
} else {
|
||||
path = DEFAULT_OGL_ES;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
if (egl_dll_handle == NULL) {
|
||||
path = DEFAULT_OGL_ES_PVR;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
|
||||
if (path != NULL) {
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
if (_this->gl_config.major_version > 1) {
|
||||
path = DEFAULT_OGL_ES2;
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
else {
|
||||
path = DEFAULT_OGL_ES;
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
if (egl_dll_handle == NULL) {
|
||||
path = DEFAULT_OGL_ES_PVR;
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEFAULT_OGL
|
||||
else {
|
||||
path = DEFAULT_OGL;
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
return SDL_SetError("Could not initialize OpenGL ES library: %s", dlerror());
|
||||
return SDL_SetError("Could not initialize OpenGL / GLES library");
|
||||
}
|
||||
|
||||
|
||||
/* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
|
||||
dll_handle = dlopen(egl_path, dlopen_flags);
|
||||
if (egl_path != NULL) {
|
||||
dll_handle = SDL_LoadObject(egl_path);
|
||||
}
|
||||
/* Catch the case where the application isn't linked with EGL */
|
||||
if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
dlclose(dll_handle);
|
||||
path = getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
if ((SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
if (dll_handle != NULL) {
|
||||
SDL_UnloadObject(dll_handle);
|
||||
}
|
||||
path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
if (path == NULL) {
|
||||
path = DEFAULT_EGL;
|
||||
}
|
||||
dll_handle = dlopen(path, dlopen_flags);
|
||||
dll_handle = SDL_LoadObject(path);
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library");
|
||||
}
|
||||
}
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library: %s", dlerror());
|
||||
}
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
|
||||
/* Load new function pointers */
|
||||
LOAD_FUNC(eglGetDisplay);
|
||||
@@ -188,6 +214,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
||||
LOAD_FUNC(eglSwapInterval);
|
||||
LOAD_FUNC(eglWaitNative);
|
||||
LOAD_FUNC(eglWaitGL);
|
||||
LOAD_FUNC(eglBindAPI);
|
||||
|
||||
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
|
||||
if (!_this->egl_data->egl_display) {
|
||||
@@ -198,19 +225,16 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
||||
return SDL_SetError("Could not initialize EGL");
|
||||
}
|
||||
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
|
||||
if (path) {
|
||||
strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
} else {
|
||||
strcpy(_this->gl_config.driver_path, "");
|
||||
*_this->gl_config.driver_path = '\0';
|
||||
}
|
||||
|
||||
/* We need to select a config here to satisfy some video backends such as X11 */
|
||||
SDL_EGL_ChooseConfig(_this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -219,8 +243,10 @@ SDL_EGL_ChooseConfig(_THIS)
|
||||
{
|
||||
/* 64 seems nice. */
|
||||
EGLint attribs[64];
|
||||
EGLint found_configs = 0;
|
||||
int i;
|
||||
EGLint found_configs = 0, value;
|
||||
/* 128 seems even nicer here */
|
||||
EGLConfig configs[128];
|
||||
int i, j, best_bitdiff = -1, bitdiff;
|
||||
|
||||
if (!_this->egl_data) {
|
||||
/* The EGL library wasn't loaded, SDL_GetError() should have info */
|
||||
@@ -265,22 +291,60 @@ SDL_EGL_ChooseConfig(_THIS)
|
||||
}
|
||||
|
||||
attribs[i++] = EGL_RENDERABLE_TYPE;
|
||||
if (_this->gl_config.major_version == 2) {
|
||||
attribs[i++] = EGL_OPENGL_ES2_BIT;
|
||||
} else {
|
||||
attribs[i++] = EGL_OPENGL_ES_BIT;
|
||||
if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
if (_this->gl_config.major_version == 2) {
|
||||
attribs[i++] = EGL_OPENGL_ES2_BIT;
|
||||
} else {
|
||||
attribs[i++] = EGL_OPENGL_ES_BIT;
|
||||
}
|
||||
_this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
|
||||
}
|
||||
else {
|
||||
attribs[i++] = EGL_OPENGL_BIT;
|
||||
_this->egl_data->eglBindAPI(EGL_OPENGL_API);
|
||||
}
|
||||
|
||||
attribs[i++] = EGL_NONE;
|
||||
|
||||
|
||||
if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
|
||||
attribs,
|
||||
&_this->egl_data->egl_config, 1,
|
||||
configs, SDL_arraysize(configs),
|
||||
&found_configs) == EGL_FALSE ||
|
||||
found_configs == 0) {
|
||||
return SDL_SetError("Couldn't find matching EGL config");
|
||||
}
|
||||
|
||||
/* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
|
||||
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
|
||||
|
||||
for ( i=0; i<found_configs; i++ ) {
|
||||
bitdiff = 0;
|
||||
for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
|
||||
if (attribs[j] == EGL_NONE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( attribs[j+1] != EGL_DONT_CARE && (
|
||||
attribs[j] == EGL_RED_SIZE ||
|
||||
attribs[j] == EGL_GREEN_SIZE ||
|
||||
attribs[j] == EGL_BLUE_SIZE ||
|
||||
attribs[j] == EGL_ALPHA_SIZE ||
|
||||
attribs[j] == EGL_DEPTH_SIZE ||
|
||||
attribs[j] == EGL_STENCIL_SIZE)) {
|
||||
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
|
||||
bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
|
||||
}
|
||||
}
|
||||
|
||||
if (bitdiff < best_bitdiff || best_bitdiff == -1) {
|
||||
_this->egl_data->egl_config = configs[i];
|
||||
|
||||
best_bitdiff = bitdiff;
|
||||
}
|
||||
|
||||
if (bitdiff == 0) break; /* we found an exact match! */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -293,21 +357,34 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLContext egl_context;
|
||||
EGLContext egl_context, share_context = EGL_NO_CONTEXT;
|
||||
|
||||
if (!_this->egl_data) {
|
||||
/* The EGL library wasn't loaded, SDL_GetError() should have info */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_this->gl_config.major_version) {
|
||||
context_attrib_list[1] = _this->gl_config.major_version;
|
||||
if (_this->gl_config.share_with_current_context) {
|
||||
share_context = (EGLContext)SDL_GL_GetCurrentContext();
|
||||
}
|
||||
|
||||
/* Bind the API */
|
||||
if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
_this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
|
||||
if (_this->gl_config.major_version) {
|
||||
context_attrib_list[1] = _this->gl_config.major_version;
|
||||
}
|
||||
|
||||
egl_context =
|
||||
_this->egl_data->eglCreateContext(_this->egl_data->egl_display,
|
||||
_this->egl_data->egl_config,
|
||||
EGL_NO_CONTEXT, context_attrib_list);
|
||||
egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
|
||||
_this->egl_data->egl_config,
|
||||
share_context, context_attrib_list);
|
||||
}
|
||||
else {
|
||||
_this->egl_data->eglBindAPI(EGL_OPENGL_API);
|
||||
egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
|
||||
_this->egl_data->egl_config,
|
||||
share_context, NULL);
|
||||
}
|
||||
|
||||
if (egl_context == EGL_NO_CONTEXT) {
|
||||
SDL_SetError("Could not create EGL context");
|
||||
@@ -394,19 +471,20 @@ SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!egl_context && egl_context != EGL_NO_CONTEXT) {
|
||||
if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
|
||||
SDL_EGL_MakeCurrent(_this, NULL, NULL);
|
||||
_this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
|
||||
}
|
||||
|
||||
/* FIXME: This "crappy fix" comes from the X11 code,
|
||||
* it's required so you can create a GLX context, destroy it and create a EGL one */
|
||||
SDL_EGL_UnloadLibrary(_this);
|
||||
}
|
||||
|
||||
EGLSurface *
|
||||
SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
|
||||
{
|
||||
if (SDL_EGL_ChooseConfig(_this) != 0) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
return _this->egl_data->eglCreateWindowSurface(
|
||||
_this->egl_data->egl_display,
|
||||
_this->egl_data->egl_config,
|
||||
|
||||
Reference in New Issue
Block a user