src/video/SDL_egl.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 11 May 2016 21:10:41 +0200
changeset 10169 e8062c7fa8b8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
EGL: Fixed SDL_GL_GetSwapInterval() returning -1 on error. It should return 0 as a safe default on errors. -1 is returned for late swaps.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     1
/*
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     2
 *  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9827
diff changeset
     3
 *  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     4
 * 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     5
 *  This software is provided 'as-is', without any express or implied
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     6
 *  warranty.  In no event will the authors be held liable for any damages
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     7
 *  arising from the use of this software.
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     8
 * 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     9
 *  Permission is granted to anyone to use this software for any purpose,
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    10
 *  including commercial applications, and to alter it and redistribute it
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    11
 *  freely, subject to the following restrictions:
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    12
 * 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    13
 *  1. The origin of this software must not be misrepresented; you must not
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    14
 *     claim that you wrote the original software. If you use this software
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    15
 *     in a product, an acknowledgment in the product documentation would be
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    16
 *     appreciated but is not required.
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    17
 *  2. Altered source versions must be plainly marked as such, and must not be
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    18
 *     misrepresented as being the original software.
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    19
 *  3. This notice may not be removed or altered from any source distribution.
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    20
 */
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8062
diff changeset
    21
#include "../SDL_internal.h"
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    22
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    23
#if SDL_VIDEO_OPENGL_EGL
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    24
8734
cb61954403ca Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 8733
diff changeset
    25
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
cb61954403ca Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 8733
diff changeset
    26
#include "../core/windows/SDL_windows.h"
cb61954403ca Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 8733
diff changeset
    27
#endif
cb61954403ca Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 8733
diff changeset
    28
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    29
#include "SDL_sysvideo.h"
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    30
#include "SDL_egl_c.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    31
#include "SDL_loadso.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    32
#include "SDL_hints.h"
7782
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    33
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    34
#ifdef EGL_KHR_create_context
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    35
/* EGL_OPENGL_ES3_BIT_KHR was added in version 13 of the extension. */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    36
#ifndef EGL_OPENGL_ES3_BIT_KHR
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    37
#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    38
#endif
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    39
#endif /* EGL_KHR_create_context */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    40
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    41
#if SDL_VIDEO_DRIVER_RPI
7782
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    42
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    43
#define DEFAULT_EGL "/opt/vc/lib/libEGL.so"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    44
#define DEFAULT_OGL_ES2 "/opt/vc/lib/libGLESv2.so"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    45
#define DEFAULT_OGL_ES_PVR "/opt/vc/lib/libGLES_CM.so"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    46
#define DEFAULT_OGL_ES "/opt/vc/lib/libGLESv1_CM.so"
7782
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    47
9164
494876610c49 Expanded the iMX6 video driver into a general Vivante video driver that works across multiple SoCs
Sam Lantinga <slouken@libsdl.org>
parents: 9162
diff changeset
    48
#elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
7782
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    49
/* Android */
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    50
#define DEFAULT_EGL "libEGL.so"
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    51
#define DEFAULT_OGL_ES2 "libGLESv2.so"
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    52
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    53
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    54
8545
7cf4f8916997 WinRT: got the SDL-official OpenGL ES 2 changes working, in an experimental state
David Ludwig <dludwig@pobox.com>
parents: 8543
diff changeset
    55
#elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    56
/* EGL AND OpenGL ES support via ANGLE */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    57
#define DEFAULT_EGL "libEGL.dll"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    58
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    59
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    60
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
    61
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    62
#else
7782
e4ed6e54101e Fix EGL/OpenGL ES paths
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7753
diff changeset
    63
/* Desktop Linux */
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
    64
#define DEFAULT_OGL "libGL.so.1"
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    65
#define DEFAULT_EGL "libEGL.so.1"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    66
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    67
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    68
#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
    69
#endif /* SDL_VIDEO_DRIVER_RPI */
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    70
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    71
#define LOAD_FUNC(NAME) \
9162
69856cdc9da6 Fixed bug where EGL function pointers wouldn't get saved in optimized gcc builds
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
    72
_this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    73
if (!_this->egl_data->NAME) \
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    74
{ \
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    75
    return SDL_SetError("Could not retrieve EGL function " #NAME); \
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    76
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    77
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    78
/* EGL implementation of SDL OpenGL ES support */
8976
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
    79
#ifdef EGL_KHR_create_context        
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    80
static int SDL_EGL_HasExtension(_THIS, const char *ext)
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    81
{
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    82
    int i;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    83
    int len = 0;
9821
c1d91866a968 Trivial integer truncation warning fixes.
Sam Lantinga <slouken@libsdl.org>
parents: 9772
diff changeset
    84
    size_t ext_len;
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    85
    const char *exts;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    86
    const char *ext_word;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    87
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    88
    ext_len = SDL_strlen(ext);
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    89
    exts = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    90
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    91
    if (exts) {
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    92
        ext_word = exts;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    93
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    94
        for (i = 0; exts[i] != 0; i++) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    95
            if (exts[i] == ' ') {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
    96
                if (ext_len == len && !SDL_strncmp(ext_word, ext, len)) {
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    97
                    return 1;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    98
                }
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
    99
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   100
                len = 0;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   101
                ext_word = &exts[i + 1];
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   102
            } else {
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   103
                len++;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   104
            }
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   105
        }
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   106
    }
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   107
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   108
    return 0;
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   109
}
8976
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   110
#endif /* EGL_KHR_create_context */
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   111
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
void *
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
SDL_EGL_GetProcAddress(_THIS, const char *proc)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
{
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
    static char procname[1024];
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
    void *retval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
    /* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
8753
497e72bba21b eglGetProcAddress fails the same way on MIR as ANDROID does on arm. Thanks Sylvain Becker for the patch!
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 8740
diff changeset
   119
#if !defined(SDL_VIDEO_DRIVER_ANDROID) && !defined(SDL_VIDEO_DRIVER_MIR) 
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
    if (_this->egl_data->eglGetProcAddress) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
        retval = _this->egl_data->eglGetProcAddress(proc);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   122
        if (retval) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   123
            return retval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   124
        }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
#endif
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
    
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   128
    retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   129
    if (!retval && SDL_strlen(proc) <= 1022) {
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
        procname[0] = '_';
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   131
        SDL_strlcpy(procname + 1, proc, 1022);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   132
        retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
    return retval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   137
void
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   138
SDL_EGL_UnloadLibrary(_THIS)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   139
{
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   140
    if (_this->egl_data) {
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   141
        if (_this->egl_data->egl_display) {
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   142
            _this->egl_data->eglTerminate(_this->egl_data->egl_display);
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   143
            _this->egl_data->egl_display = NULL;
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   144
        }
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   145
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   146
        if (_this->egl_data->dll_handle) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   147
            SDL_UnloadObject(_this->egl_data->dll_handle);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   148
            _this->egl_data->dll_handle = NULL;
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   149
        }
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   150
        if (_this->egl_data->egl_dll_handle) {
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   151
            SDL_UnloadObject(_this->egl_data->egl_dll_handle);
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   152
            _this->egl_data->egl_dll_handle = NULL;
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   153
        }
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   154
        
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   155
        SDL_free(_this->egl_data);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   156
        _this->egl_data = NULL;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   157
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   158
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   159
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   160
int
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   161
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   162
{
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   163
    void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   164
    char *path = NULL;
8545
7cf4f8916997 WinRT: got the SDL-official OpenGL ES 2 changes working, in an experimental state
David Ludwig <dludwig@pobox.com>
parents: 8543
diff changeset
   165
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   166
    const char *d3dcompiler;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   167
#endif
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   168
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   169
    if (_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   170
        return SDL_SetError("OpenGL ES context already created");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   171
    }
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   172
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   173
    _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   174
    if (!_this->egl_data) {
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   175
        return SDL_OutOfMemory();
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   176
    }
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   177
8545
7cf4f8916997 WinRT: got the SDL-official OpenGL ES 2 changes working, in an experimental state
David Ludwig <dludwig@pobox.com>
parents: 8543
diff changeset
   178
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   179
    d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   180
    if (!d3dcompiler) {
8733
02b7b0448811 Don't try to load d3dcompiler_46.dll on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 8663
diff changeset
   181
        if (WIN_IsWindowsVistaOrGreater()) {
02b7b0448811 Don't try to load d3dcompiler_46.dll on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 8663
diff changeset
   182
            d3dcompiler = "d3dcompiler_46.dll";
02b7b0448811 Don't try to load d3dcompiler_46.dll on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 8663
diff changeset
   183
        } else {
8740
fbe394d76273 Better compiler for Windows XP systems
Sam Lantinga <slouken@libsdl.org>
parents: 8734
diff changeset
   184
            d3dcompiler = "d3dcompiler_43.dll";
8733
02b7b0448811 Don't try to load d3dcompiler_46.dll on Windows XP
Sam Lantinga <slouken@libsdl.org>
parents: 8663
diff changeset
   185
        }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   186
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   187
    if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   188
        SDL_LoadObject(d3dcompiler);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   189
    }
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   190
#endif
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   191
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   192
    /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   193
    path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   194
    if (path != NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   195
        egl_dll_handle = SDL_LoadObject(path);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   196
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   197
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   198
    if (egl_dll_handle == NULL) {
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   199
        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   200
            if (_this->gl_config.major_version > 1) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   201
                path = DEFAULT_OGL_ES2;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   202
                egl_dll_handle = SDL_LoadObject(path);
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   203
            } else {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   204
                path = DEFAULT_OGL_ES;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   205
                egl_dll_handle = SDL_LoadObject(path);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   206
                if (egl_dll_handle == NULL) {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   207
                    path = DEFAULT_OGL_ES_PVR;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   208
                    egl_dll_handle = SDL_LoadObject(path);
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   209
                }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   210
            }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   211
        }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   212
#ifdef DEFAULT_OGL         
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   213
        else {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   214
            path = DEFAULT_OGL;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   215
            egl_dll_handle = SDL_LoadObject(path);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   216
        }
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   217
#endif        
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   218
    }
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   219
    _this->egl_data->egl_dll_handle = egl_dll_handle;
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   220
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   221
    if (egl_dll_handle == NULL) {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   222
        return SDL_SetError("Could not initialize OpenGL / GLES library");
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   223
    }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   224
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   225
    /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   226
    if (egl_path != NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   227
        dll_handle = SDL_LoadObject(egl_path);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   228
    }   
8105
f74bf1bbe472 Make EGL loading more resilient.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8093
diff changeset
   229
    /* Try loading a EGL symbol, if it does not work try the default library paths */
8872
5a6375d96834 Fixes #2583, clean up EGL initialization
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8763
diff changeset
   230
    if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   231
        if (dll_handle != NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   232
            SDL_UnloadObject(dll_handle);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   233
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   234
        path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   235
        if (path == NULL) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   236
            path = DEFAULT_EGL;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   237
        }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   238
        dll_handle = SDL_LoadObject(path);
8872
5a6375d96834 Fixes #2583, clean up EGL initialization
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8763
diff changeset
   239
        if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
5a6375d96834 Fixes #2583, clean up EGL initialization
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8763
diff changeset
   240
            if (dll_handle != NULL) {
5a6375d96834 Fixes #2583, clean up EGL initialization
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8763
diff changeset
   241
                SDL_UnloadObject(dll_handle);
5a6375d96834 Fixes #2583, clean up EGL initialization
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8763
diff changeset
   242
            }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   243
            return SDL_SetError("Could not load EGL library");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   244
        }
8763
a8ef3ac69e3d Fixes #2519, clear error if using the default library path for EGL succeeds.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8753
diff changeset
   245
        SDL_ClearError();
7753
e4c38f17bfad Raspberry Pi support (also unified UDEV and EVDEV support)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7702
diff changeset
   246
    }
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   247
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   248
    _this->egl_data->dll_handle = dll_handle;
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   249
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   250
    /* Load new function pointers */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   251
    LOAD_FUNC(eglGetDisplay);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   252
    LOAD_FUNC(eglInitialize);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   253
    LOAD_FUNC(eglTerminate);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   254
    LOAD_FUNC(eglGetProcAddress);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   255
    LOAD_FUNC(eglChooseConfig);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   256
    LOAD_FUNC(eglGetConfigAttrib);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   257
    LOAD_FUNC(eglCreateContext);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   258
    LOAD_FUNC(eglDestroyContext);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   259
    LOAD_FUNC(eglCreateWindowSurface);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   260
    LOAD_FUNC(eglDestroySurface);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   261
    LOAD_FUNC(eglMakeCurrent);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   262
    LOAD_FUNC(eglSwapBuffers);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   263
    LOAD_FUNC(eglSwapInterval);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   264
    LOAD_FUNC(eglWaitNative);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   265
    LOAD_FUNC(eglWaitGL);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   266
    LOAD_FUNC(eglBindAPI);
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   267
    LOAD_FUNC(eglQueryString);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   268
    
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8583
diff changeset
   269
#if !defined(__WINRT__)
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   270
    _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   271
    if (!_this->egl_data->egl_display) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   272
        return SDL_SetError("Could not get EGL display");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   273
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   274
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   275
    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   276
        return SDL_SetError("Could not initialize EGL");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   277
    }
8663
308e74493106 WinRT: Got OpenGL ES 2 working with the latest version of ANGLE/WinRT.
David Ludwig <dludwig@pobox.com>
parents: 8583
diff changeset
   278
#endif
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   279
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   280
    _this->gl_config.driver_loaded = 1;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   281
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   282
    if (path) {
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   283
        SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   284
    } else {
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   285
        *_this->gl_config.driver_path = '\0';
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   286
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   287
    
8041
afd62b3fda31 Select EGL config when creating the EGL surface
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   288
    return 0;
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   289
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   290
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   291
int
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   292
SDL_EGL_ChooseConfig(_THIS) 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   293
{
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   294
    /* 64 seems nice. */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   295
    EGLint attribs[64];
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   296
    EGLint found_configs = 0, value;
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   297
    /* 128 seems even nicer here */
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   298
    EGLConfig configs[128];
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   299
    int i, j, best_bitdiff = -1, bitdiff;
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   300
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   301
    if (!_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   302
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   303
        return -1;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   304
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   305
  
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   306
    /* Get a valid EGL configuration */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   307
    i = 0;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   308
    attribs[i++] = EGL_RED_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   309
    attribs[i++] = _this->gl_config.red_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   310
    attribs[i++] = EGL_GREEN_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   311
    attribs[i++] = _this->gl_config.green_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   312
    attribs[i++] = EGL_BLUE_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   313
    attribs[i++] = _this->gl_config.blue_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   314
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   315
    if (_this->gl_config.alpha_size) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   316
        attribs[i++] = EGL_ALPHA_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   317
        attribs[i++] = _this->gl_config.alpha_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   318
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   319
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   320
    if (_this->gl_config.buffer_size) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   321
        attribs[i++] = EGL_BUFFER_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   322
        attribs[i++] = _this->gl_config.buffer_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   323
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   324
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   325
    attribs[i++] = EGL_DEPTH_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   326
    attribs[i++] = _this->gl_config.depth_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   327
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   328
    if (_this->gl_config.stencil_size) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   329
        attribs[i++] = EGL_STENCIL_SIZE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   330
        attribs[i++] = _this->gl_config.stencil_size;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   331
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   332
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   333
    if (_this->gl_config.multisamplebuffers) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   334
        attribs[i++] = EGL_SAMPLE_BUFFERS;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   335
        attribs[i++] = _this->gl_config.multisamplebuffers;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   336
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   337
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   338
    if (_this->gl_config.multisamplesamples) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   339
        attribs[i++] = EGL_SAMPLES;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   340
        attribs[i++] = _this->gl_config.multisamplesamples;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   341
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   342
9827
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   343
    if (_this->gl_config.framebuffer_srgb_capable) {
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   344
#ifdef EGL_KHR_gl_colorspace
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   345
        if (SDL_EGL_HasExtension(_this, "EGL_KHR_gl_colorspace")) {
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   346
            attribs[i++] = EGL_GL_COLORSPACE_KHR;
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   347
            attribs[i++] = EGL_GL_COLORSPACE_SRGB_KHR;
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   348
        } else
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   349
#endif
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   350
        {
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   351
            return SDL_SetError("EGL implementation does not support sRGB system framebuffers");
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   352
        }
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   353
    }
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   354
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   355
    attribs[i++] = EGL_RENDERABLE_TYPE;
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   356
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   357
#ifdef EGL_KHR_create_context
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   358
        if (_this->gl_config.major_version >= 3 &&
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   359
            SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   360
            attribs[i++] = EGL_OPENGL_ES3_BIT_KHR;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   361
        } else
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   362
#endif
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   363
        if (_this->gl_config.major_version >= 2) {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   364
            attribs[i++] = EGL_OPENGL_ES2_BIT;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   365
        } else {
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   366
            attribs[i++] = EGL_OPENGL_ES_BIT;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   367
        }
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   368
        _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   369
    } else {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   370
        attribs[i++] = EGL_OPENGL_BIT;
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   371
        _this->egl_data->eglBindAPI(EGL_OPENGL_API);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   372
    }
9827
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   373
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   374
    attribs[i++] = EGL_NONE;
9827
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   375
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   376
    if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   377
        attribs,
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   378
        configs, SDL_arraysize(configs),
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   379
        &found_configs) == EGL_FALSE ||
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   380
        found_configs == 0) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   381
        return SDL_SetError("Couldn't find matching EGL config");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   382
    }
9827
6f0b76fa61e7 EGL: Added support for sRGB system framebuffers, when the required EGL extension is present.
Alex Szpakowski <slime73@gmail.com>
parents: 9821
diff changeset
   383
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   384
    /* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   385
    /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   386
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   387
    for (i = 0; i < found_configs; i++ ) {
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   388
        bitdiff = 0;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8015
diff changeset
   389
        for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   390
            if (attribs[j] == EGL_NONE) {
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   391
               break;
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   392
            }
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   393
            
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   394
            if ( attribs[j+1] != EGL_DONT_CARE && (
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   395
                attribs[j] == EGL_RED_SIZE ||
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   396
                attribs[j] == EGL_GREEN_SIZE ||
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   397
                attribs[j] == EGL_BLUE_SIZE ||
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   398
                attribs[j] == EGL_ALPHA_SIZE ||
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   399
                attribs[j] == EGL_DEPTH_SIZE ||
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   400
                attribs[j] == EGL_STENCIL_SIZE)) {
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   401
                _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   402
                bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   403
            }
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   404
        }
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   405
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   406
        if (bitdiff < best_bitdiff || best_bitdiff == -1) {
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   407
            _this->egl_data->egl_config = configs[i];
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   408
            
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   409
            best_bitdiff = bitdiff;
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   410
        }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   411
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   412
        if (bitdiff == 0) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   413
            break; /* we found an exact match! */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   414
        }
8015
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   415
    }
ba26f042e36d Find the best EGL config available between those returned by eglChooseConfig
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7986
diff changeset
   416
    
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   417
    return 0;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   418
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   419
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   420
SDL_GLContext
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   421
SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   422
{
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   423
    /* max 14 values plus terminator. */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   424
    EGLint attribs[15];
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   425
    int attr = 0;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   426
8061
a5f8137ccf01 Context sharing for EGL
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8045
diff changeset
   427
    EGLContext egl_context, share_context = EGL_NO_CONTEXT;
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   428
    EGLint profile_mask = _this->gl_config.profile_mask;
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   429
    EGLint major_version = _this->gl_config.major_version;
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   430
    EGLint minor_version = _this->gl_config.minor_version;
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   431
    SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   432
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   433
    if (!_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   434
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   435
        return NULL;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   436
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   437
8061
a5f8137ccf01 Context sharing for EGL
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8045
diff changeset
   438
    if (_this->gl_config.share_with_current_context) {
a5f8137ccf01 Context sharing for EGL
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8045
diff changeset
   439
        share_context = (EGLContext)SDL_GL_GetCurrentContext();
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   440
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   441
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   442
    /* Set the context version and other attributes. */
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   443
    if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   444
        _this->gl_config.flags == 0 &&
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   445
        (profile_mask == 0 || profile_es)) {
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   446
        /* Create a context without using EGL_KHR_create_context attribs.
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   447
         * When creating a GLES context without EGL_KHR_create_context we can
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   448
         * only specify the major version. When creating a desktop GL context
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   449
         * we can't specify any version, so we only try in that case when the
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   450
         * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   451
         */
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   452
        if (profile_es) {
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   453
            attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   454
            attribs[attr++] = SDL_max(major_version, 1);
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   455
        }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   456
    } else {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   457
#ifdef EGL_KHR_create_context
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   458
        /* The Major/minor version, context profiles, and context flags can
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   459
         * only be specified when this extension is available.
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   460
         */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   461
        if (SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   462
            attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   463
            attribs[attr++] = major_version;
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   464
            attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   465
            attribs[attr++] = minor_version;
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   466
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   467
            /* SDL profile bits match EGL profile bits. */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   468
            if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   469
                attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   470
                attribs[attr++] = profile_mask;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   471
            }
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   472
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   473
            /* SDL flags match EGL flags. */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   474
            if (_this->gl_config.flags != 0) {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   475
                attribs[attr++] = EGL_CONTEXT_FLAGS_KHR;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   476
                attribs[attr++] = _this->gl_config.flags;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   477
            }
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   478
        } else
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   479
#endif /* EGL_KHR_create_context */
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   480
        {
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   481
            SDL_SetError("Could not create EGL context (context attributes are not supported)");
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   482
            return NULL;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   483
        }
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   484
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   485
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   486
    attribs[attr++] = EGL_NONE;
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   487
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   488
    /* Bind the API */
9637
adf81fe554b9 EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   489
    if (profile_es) {
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   490
        _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   491
    } else {
8062
4fc5f66d63cc Wayland support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8061
diff changeset
   492
        _this->egl_data->eglBindAPI(EGL_OPENGL_API);
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   493
    }
8962
c593cbef6d7d SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
Knut Andre Tidemann <knut.tidemann@gmail.com>
parents: 8872
diff changeset
   494
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   495
    egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   496
                                      _this->egl_data->egl_config,
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   497
                                      share_context, attribs);
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   498
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   499
    if (egl_context == EGL_NO_CONTEXT) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   500
        SDL_SetError("Could not create EGL context");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   501
        return NULL;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   502
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   503
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   504
    _this->egl_data->egl_swapinterval = 0;
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   505
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   506
    if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   507
        SDL_EGL_DeleteContext(_this, egl_context);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   508
        SDL_SetError("Could not make EGL context current");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   509
        return NULL;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   510
    }
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   511
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   512
    return (SDL_GLContext) egl_context;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   513
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   514
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   515
int
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   516
SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   517
{
7679
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   518
    EGLContext egl_context = (EGLContext) context;
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   519
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   520
    if (!_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   521
        return SDL_SetError("OpenGL not initialized");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   522
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   523
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   524
    /* The android emulator crashes badly if you try to eglMakeCurrent 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   525
     * with a valid context and invalid surface, so we have to check for both here.
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   526
     */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   527
    if (!egl_context || !egl_surface) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   528
         _this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
9595
6027a65e8528 Refactored SDL_EGL_CreateContext: It now supports context flags and OpenGL ES 3+ contexts, and its behavior more closely matches the GLX and WGL context creation code.
Alex Szpakowski <slime73@gmail.com>
parents: 9164
diff changeset
   529
    } else {
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   530
        if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   531
            egl_surface, egl_surface, egl_context)) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   532
            return SDL_SetError("Unable to make EGL context current");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   533
        }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   534
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   535
      
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   536
    return 0;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   537
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   538
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   539
int
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   540
SDL_EGL_SetSwapInterval(_THIS, int interval)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   541
{
7679
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   542
    EGLBoolean status;
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   543
    
7702
83878644c8e6 Fixes typo in EGL code (thanks jmcfarlane!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7679
diff changeset
   544
    if (!_this->egl_data) {
83878644c8e6 Fixes typo in EGL code (thanks jmcfarlane!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7679
diff changeset
   545
        return SDL_SetError("EGL not initialized");
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   546
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   547
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   548
    status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   549
    if (status == EGL_TRUE) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   550
        _this->egl_data->egl_swapinterval = interval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   551
        return 0;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   552
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   553
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   554
    return SDL_SetError("Unable to set the EGL swap interval");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   555
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   556
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   557
int
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   558
SDL_EGL_GetSwapInterval(_THIS)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   559
{
7702
83878644c8e6 Fixes typo in EGL code (thanks jmcfarlane!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7679
diff changeset
   560
    if (!_this->egl_data) {
10169
e8062c7fa8b8 EGL: Fixed SDL_GL_GetSwapInterval() returning -1 on error.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9998
diff changeset
   561
        SDL_SetError("EGL not initialized");
e8062c7fa8b8 EGL: Fixed SDL_GL_GetSwapInterval() returning -1 on error.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9998
diff changeset
   562
        return 0;
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   563
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   564
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   565
    return _this->egl_data->egl_swapinterval;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   566
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   567
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   568
void
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   569
SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   570
{
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   571
    _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   572
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   573
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   574
void
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   575
SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   576
{
7679
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   577
    EGLContext egl_context = (EGLContext) context;
b1fe132bc6a4 Fixes for -Wdeclaration-after-statement
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   578
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   579
    /* Clean up GLES and EGL */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   580
    if (!_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   581
        return;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   582
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   583
    
7896
0bca3fe7c03f Fixes Bug #2191,incorrect test for egl_context validity
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   584
    if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   585
        SDL_EGL_MakeCurrent(_this, NULL, NULL);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   586
        _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   587
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   588
        
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   589
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   590
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   591
EGLSurface *
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   592
SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   593
{
8041
afd62b3fda31 Select EGL config when creating the EGL surface
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   594
    if (SDL_EGL_ChooseConfig(_this) != 0) {
8045
3c2694255705 Fixed error return value in SDL_EGL_CreateSurface(), thanks to Mike Kasprzak
Sam Lantinga <slouken@libsdl.org>
parents: 8041
diff changeset
   595
        return EGL_NO_SURFACE;
8041
afd62b3fda31 Select EGL config when creating the EGL surface
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   596
    }
afd62b3fda31 Select EGL config when creating the EGL surface
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   597
    
8971
c30e826412d1 Maybe fixes bug #2291 (red tinted screen on some Samsung Android devices)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8966
diff changeset
   598
#if __ANDROID__
8976
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   599
    {
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   600
        /* Android docs recommend doing this!
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   601
         * Ref: http://developer.android.com/reference/android/app/NativeActivity.html 
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   602
         */
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   603
        EGLint format;
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   604
        _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   605
                                            _this->egl_data->egl_config, 
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   606
                                            EGL_NATIVE_VISUAL_ID, &format);
8971
c30e826412d1 Maybe fixes bug #2291 (red tinted screen on some Samsung Android devices)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8966
diff changeset
   607
8976
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   608
        ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
1a5d959d7b32 Fixed mingw64 build and warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8971
diff changeset
   609
    }
8971
c30e826412d1 Maybe fixes bug #2291 (red tinted screen on some Samsung Android devices)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8966
diff changeset
   610
#endif    
c30e826412d1 Maybe fixes bug #2291 (red tinted screen on some Samsung Android devices)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8966
diff changeset
   611
    
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   612
    return _this->egl_data->eglCreateWindowSurface(
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   613
            _this->egl_data->egl_display,
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   614
            _this->egl_data->egl_config,
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   615
            nw, NULL);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   616
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   617
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   618
void
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   619
SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface) 
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   620
{
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   621
    if (!_this->egl_data) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   622
        return;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   623
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   624
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   625
    if (egl_surface != EGL_NO_SURFACE) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   626
        _this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   627
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   628
}
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   629
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   630
#endif /* SDL_VIDEO_OPENGL_EGL */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   631
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   632
/* vi: set ts=4 sw=4 expandtab: */
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7782
diff changeset
   633