src/video/SDL_egl_c.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 09 Apr 2015 22:28:37 -0400
changeset 9541 cf8fab52e33b
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Merged Alex Szpakowski's iOS-improvement branch to default.

Fixes Bugzilla #2798.
Fixes Bugzilla #2212.
Fixes Bugzilla #2826.
Fixes Bugzilla #2661.
Fixes Bugzilla #1885.
Fixes Bugzilla #1578.
Fixes Bugzilla #2751.

(whew!)

Notable changes, from Alex's notes:

- The SDL_WINDOW_ALLOW_HIGHDPI flag is now needed (along with SDL_GL_GetDrawableSize or SDL_GetRendererOutputSize) to use Retina / high DPI resolutions, bringing SDL’s Retina-related behavior on iOS in line with Mac OS X. Window dimensions and display modes are now in the “points” (non-high DPI) coordinate system rather than pixels, whereas SDL_GL_GetDrawableSize is in pixels.

- Reworked the custom extended launch screen code:
- It now hides after the first SDL_PumpEvents call rather than SDL_CreateWindow, and it fades out in a similar manner to the system launch screen behavior.
- It now mirrors the system launch screen behavior when deciding which image to display: it falls back to using the Launch Images dictionary in Info.plist if the iOS 8+ launch screen nib isn’t available, and if the Launch Images dictionary doesn’t exist it uses the old standard launch image names.
- The extended launch screen can now be disabled via the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h.

- Added support for SDL_HINT_ACCELEROMETER_AS_JOYSTICK.

- Added access to a window view's renderbuffer and framebuffer to syswm.

- Added OpenGL ES debug labels for the Renderbuffer and Framebuffer Objects created with SDL_GL_CreateContext.

- Added support for sRGB OpenGL ES contexts on iOS 7+.

- Updated OpenGL ES contexts to support native-resolution rendering (when SDL_WINDOW_ALLOW_HIGHDPI is enabled) on the iPhone 6 Plus, i.e. 1080x1920 rather than 1242x2208.

- Updated SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext to be more robust.

- Updated SDL windows to display a UIView at all times, even when an OpenGL context is not active. This allows rotation, touch events, and other windowing-related events to work properly without an active OpenGL context. It also makes it easier to use SDL_GetWindowWMInfo after creating a SDL window.

- Updated the iOS-specific Objective-C code to use cleaner and more modern language features and APIs, including ARC instead of manual reference counting.

- Updated SDL_HINT_ORIENTATIONS to allow disabling custom orientations if the hint is set with no valid orientation names.

- Fixed several rotation and orientation bugs with windows and display modes, especially in iOS 8+.

- Fixed SDL_SetWindowFullscreen failing to update the status bar visibility on iOS 7+.

- Fixed the orientation of the offset applied to the window’s view when the onscreen keyboard is shown in iOS 8+.

- Fixed SDL_IsScreenKeyboardShown (patch by Phil Hassey.)

- Fixed several major memory leaks caused by missing autorelease pool blocks in the iOS-specific Objective-C code.

- Removed several dead code paths.

- The iOS 7 SDK (Xcode 5) or newer is now required to build SDL for iOS.
gabomdq@8021
     1
/*
gabomdq@8021
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
gabomdq@8021
     4
gabomdq@8021
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8021
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8021
     7
  arising from the use of this software.
gabomdq@8021
     8
gabomdq@8021
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8021
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8021
    11
  freely, subject to the following restrictions:
gabomdq@8021
    12
gabomdq@8021
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8021
    14
     claim that you wrote the original software. If you use this software
gabomdq@8021
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8021
    16
     appreciated but is not required.
gabomdq@8021
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8021
    18
     misrepresented as being the original software.
gabomdq@8021
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8021
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
gabomdq@8021
    22
gabomdq@8021
    23
#ifndef _SDL_egl_h
gabomdq@8021
    24
#define _SDL_egl_h
gabomdq@8021
    25
gabomdq@8021
    26
#if SDL_VIDEO_OPENGL_EGL
gabomdq@8021
    27
gabomdq@8021
    28
#include "SDL_egl.h"
gabomdq@8021
    29
gabomdq@8021
    30
#include "SDL_sysvideo.h"
gabomdq@8021
    31
gabomdq@8021
    32
typedef struct SDL_EGL_VideoData
gabomdq@8021
    33
{
gabomdq@8021
    34
    void *egl_dll_handle, *dll_handle;
gabomdq@8021
    35
    EGLDisplay egl_display;
gabomdq@8021
    36
    EGLConfig egl_config;
gabomdq@8021
    37
    int egl_swapinterval;
gabomdq@8021
    38
    
gabomdq@8021
    39
    EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
gabomdq@8021
    40
    EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
gabomdq@8021
    41
                                EGLint * minor);
gabomdq@8021
    42
    EGLBoolean(EGLAPIENTRY  *eglTerminate) (EGLDisplay dpy);
gabomdq@8021
    43
    
gabomdq@8021
    44
    void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
gabomdq@8021
    45
    
gabomdq@8021
    46
    EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
gabomdq@8021
    47
                                  const EGLint * attrib_list,
gabomdq@8021
    48
                                  EGLConfig * configs,
gabomdq@8021
    49
                                  EGLint config_size, EGLint * num_config);
gabomdq@8021
    50
    
gabomdq@8021
    51
    EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
gabomdq@8021
    52
                                   EGLConfig config,
gabomdq@8021
    53
                                   EGLContext share_list,
gabomdq@8021
    54
                                   const EGLint * attrib_list);
gabomdq@8021
    55
    
gabomdq@8021
    56
    EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
gabomdq@8021
    57
    
gabomdq@8021
    58
    EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
gabomdq@8021
    59
                                         EGLConfig config,
gabomdq@8021
    60
                                         NativeWindowType window,
gabomdq@8021
    61
                                         const EGLint * attrib_list);
gabomdq@8021
    62
    EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
gabomdq@8021
    63
    
gabomdq@8021
    64
    EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
gabomdq@8021
    65
                                 EGLSurface read, EGLContext ctx);
gabomdq@8021
    66
    
gabomdq@8021
    67
    EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
gabomdq@8021
    68
    
gabomdq@8021
    69
    EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
gabomdq@8021
    70
    
gabomdq@8021
    71
    const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
gabomdq@8021
    72
    
gabomdq@8021
    73
    EGLBoolean(EGLAPIENTRY  *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
gabomdq@8021
    74
                                     EGLint attribute, EGLint * value);
gabomdq@8021
    75
    
gabomdq@8021
    76
    EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint  engine);
gabomdq@8021
    77
gabomdq@8021
    78
    EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
gabomdq@8062
    79
    
gabomdq@8062
    80
    EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
gabomdq@8062
    81
gabomdq@8021
    82
} SDL_EGL_VideoData;
gabomdq@8021
    83
gabomdq@8021
    84
/* OpenGLES functions */
gabomdq@8021
    85
extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
gabomdq@8021
    86
extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display);
gabomdq@8021
    87
extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc);
gabomdq@8021
    88
extern void SDL_EGL_UnloadLibrary(_THIS);
gabomdq@8021
    89
extern int SDL_EGL_ChooseConfig(_THIS);
gabomdq@8021
    90
extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
gabomdq@8021
    91
extern int SDL_EGL_GetSwapInterval(_THIS);
gabomdq@8021
    92
extern void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
gabomdq@8021
    93
extern EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw);
gabomdq@8021
    94
extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
gabomdq@8021
    95
gabomdq@8021
    96
/* These need to be wrapped to get the surface for the window by the platform GLES implementation */
gabomdq@8021
    97
extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
gabomdq@8021
    98
extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
gabomdq@8021
    99
extern void SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
gabomdq@8021
   100
gabomdq@8021
   101
/* A few of useful macros */
gabomdq@8021
   102
gabomdq@8021
   103
#define SDL_EGL_SwapWindow_impl(BACKEND) void \
gabomdq@8021
   104
BACKEND ## _GLES_SwapWindow(_THIS, SDL_Window * window) \
gabomdq@8021
   105
{\
gabomdq@8021
   106
    SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
gabomdq@8021
   107
}
gabomdq@8021
   108
gabomdq@8021
   109
#define SDL_EGL_MakeCurrent_impl(BACKEND) int \
gabomdq@8021
   110
BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
gabomdq@8021
   111
{\
gabomdq@8021
   112
    if (window && context) { \
gabomdq@8021
   113
        return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); \
gabomdq@8021
   114
    }\
gabomdq@8021
   115
    else {\
gabomdq@8021
   116
        return SDL_EGL_MakeCurrent(_this, NULL, NULL);\
gabomdq@8021
   117
    }\
gabomdq@8021
   118
}
gabomdq@8021
   119
gabomdq@8021
   120
#define SDL_EGL_CreateContext_impl(BACKEND) SDL_GLContext \
gabomdq@8021
   121
BACKEND ## _GLES_CreateContext(_THIS, SDL_Window * window) \
gabomdq@8021
   122
{\
gabomdq@8021
   123
    return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
gabomdq@8021
   124
}
gabomdq@8021
   125
gabomdq@8021
   126
#endif /* SDL_VIDEO_OPENGL_EGL */
gabomdq@8021
   127
gabomdq@8021
   128
#endif /* _SDL_egl_h */
gabomdq@8021
   129
gabomdq@8021
   130
/* vi: set ts=4 sw=4 expandtab: */