cocoa: Added two missing files from hg changeset bc7ca7cfa6ca.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 06 Dec 2017 16:37:55 -0500
changeset 1172749f8fb4f6ce2
parent 11726 27d08f1aab80
child 11728 2f3ea7f5c671
cocoa: Added two missing files from hg changeset bc7ca7cfa6ca.

Fixes Bugzilla #3975.
src/video/cocoa/SDL_cocoaopengles.h
src/video/cocoa/SDL_cocoaopengles.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoaopengles.h	Wed Dec 06 16:37:55 2017 -0500
     1.3 @@ -0,0 +1,49 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "../../SDL_internal.h"
    1.25 +
    1.26 +#ifndef SDL_cocoaopengles_h_
    1.27 +#define SDL_cocoaopengles_h_
    1.28 +
    1.29 +#if SDL_VIDEO_OPENGL_EGL
    1.30 +
    1.31 +#include "../SDL_sysvideo.h"
    1.32 +#include "../SDL_egl_c.h"
    1.33 +
    1.34 +/* OpenGLES functions */
    1.35 +#define Cocoa_GLES_GetAttribute SDL_EGL_GetAttribute
    1.36 +#define Cocoa_GLES_GetProcAddress SDL_EGL_GetProcAddress
    1.37 +#define Cocoa_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
    1.38 +#define Cocoa_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
    1.39 +#define Cocoa_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
    1.40 +
    1.41 +extern int Cocoa_GLES_LoadLibrary(_THIS, const char *path);
    1.42 +extern SDL_GLContext Cocoa_GLES_CreateContext(_THIS, SDL_Window * window);
    1.43 +extern int Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window);
    1.44 +extern int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
    1.45 +extern void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context);
    1.46 +extern int Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window);
    1.47 +
    1.48 +#endif /* SDL_VIDEO_OPENGL_EGL */
    1.49 +
    1.50 +#endif /* SDL_cocoaopengles_h_ */
    1.51 +
    1.52 +/* vi: set ts=4 sw=4 expandtab: */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/cocoa/SDL_cocoaopengles.m	Wed Dec 06 16:37:55 2017 -0500
     2.3 @@ -0,0 +1,132 @@
     2.4 +/*
     2.5 +  Simple DirectMedia Layer
     2.6 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     2.7 +
     2.8 +  This software is provided 'as-is', without any express or implied
     2.9 +  warranty.  In no event will the authors be held liable for any damages
    2.10 +  arising from the use of this software.
    2.11 +
    2.12 +  Permission is granted to anyone to use this software for any purpose,
    2.13 +  including commercial applications, and to alter it and redistribute it
    2.14 +  freely, subject to the following restrictions:
    2.15 +
    2.16 +  1. The origin of this software must not be misrepresented; you must not
    2.17 +     claim that you wrote the original software. If you use this software
    2.18 +     in a product, an acknowledgment in the product documentation would be
    2.19 +     appreciated but is not required.
    2.20 +  2. Altered source versions must be plainly marked as such, and must not be
    2.21 +     misrepresented as being the original software.
    2.22 +  3. This notice may not be removed or altered from any source distribution.
    2.23 +*/
    2.24 +#include "../../SDL_internal.h"
    2.25 +
    2.26 +#if SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL
    2.27 +
    2.28 +#include "SDL_cocoavideo.h"
    2.29 +#include "SDL_cocoaopengles.h"
    2.30 +#include "SDL_cocoaopengl.h"
    2.31 +#include "SDL_log.h"
    2.32 +
    2.33 +/* EGL implementation of SDL OpenGL support */
    2.34 +
    2.35 +int
    2.36 +Cocoa_GLES_LoadLibrary(_THIS, const char *path) {
    2.37 +
    2.38 +    /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
    2.39 +    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    2.40 +#if SDL_VIDEO_OPENGL_CGL
    2.41 +        Cocoa_GLES_UnloadLibrary(_this);
    2.42 +        _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
    2.43 +        _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
    2.44 +        _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
    2.45 +        _this->GL_CreateContext = Cocoa_GL_CreateContext;
    2.46 +        _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
    2.47 +        _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
    2.48 +        _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
    2.49 +        _this->GL_SwapWindow = Cocoa_GL_SwapWindow;
    2.50 +        _this->GL_DeleteContext = Cocoa_GL_DeleteContext;
    2.51 +        return Cocoa_GL_LoadLibrary(_this, path);
    2.52 +#else
    2.53 +        return SDL_SetError("SDL not configured with OpenGL/CGL support");
    2.54 +#endif
    2.55 +    }
    2.56 +    
    2.57 +    if (_this->egl_data == NULL) {
    2.58 +        return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0);
    2.59 +    }
    2.60 +
    2.61 +    return 0;
    2.62 +}
    2.63 +
    2.64 +SDL_GLContext
    2.65 +Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
    2.66 +{
    2.67 +    SDL_GLContext context;
    2.68 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    2.69 +
    2.70 +#if SDL_VIDEO_OPENGL_CGL
    2.71 +    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    2.72 +        /* Switch to CGL based functions */
    2.73 +        Cocoa_GLES_UnloadLibrary(_this);
    2.74 +        _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
    2.75 +        _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
    2.76 +        _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
    2.77 +        _this->GL_CreateContext = Cocoa_GL_CreateContext;
    2.78 +        _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
    2.79 +        _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
    2.80 +        _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
    2.81 +        _this->GL_SwapWindow = Cocoa_GL_SwapWindow;
    2.82 +        _this->GL_DeleteContext = Cocoa_GL_DeleteContext;
    2.83 +
    2.84 +        if (Cocoa_GL_LoadLibrary(_this, NULL) != 0) {
    2.85 +            return NULL;
    2.86 +        }
    2.87 +
    2.88 +        return Cocoa_GL_CreateContext(_this, window);
    2.89 +    }
    2.90 +#endif
    2.91 +
    2.92 +    context = SDL_EGL_CreateContext(_this, data->egl_surface);
    2.93 +    return context;
    2.94 +}
    2.95 +
    2.96 +void
    2.97 +Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
    2.98 +{
    2.99 +    SDL_EGL_DeleteContext(_this, context);
   2.100 +    Cocoa_GLES_UnloadLibrary(_this);
   2.101 +}
   2.102 +
   2.103 +SDL_EGL_SwapWindow_impl(Cocoa)
   2.104 +SDL_EGL_MakeCurrent_impl(Cocoa)
   2.105 +
   2.106 +int
   2.107 +Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
   2.108 +{
   2.109 +    /* The current context is lost in here; save it and reset it. */
   2.110 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   2.111 +    SDL_Window *current_win = SDL_GL_GetCurrentWindow();
   2.112 +    SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
   2.113 +
   2.114 +
   2.115 +    if (_this->egl_data == NULL) {
   2.116 +        if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
   2.117 +            SDL_EGL_UnloadLibrary(_this);
   2.118 +            return -1;
   2.119 +        }
   2.120 +    }
   2.121 +  
   2.122 +    /* Create the GLES window surface */
   2.123 +    NSView* v = windowdata->nswindow.contentView;
   2.124 +    windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)[v layer]);
   2.125 +
   2.126 +    if (windowdata->egl_surface == EGL_NO_SURFACE) {
   2.127 +        return SDL_SetError("Could not create GLES window surface");
   2.128 +    }
   2.129 +
   2.130 +    return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx);
   2.131 +}
   2.132 +
   2.133 +#endif /* SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL */
   2.134 +
   2.135 +/* vi: set ts=4 sw=4 expandtab: */