src/video/windows/SDL_windowsopengles.c
changeset 8021 f96e12e0ade9
child 8026 27a998fdc771
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/windows/SDL_windowsopengles.c	Fri Nov 22 13:24:53 2013 -0300
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 +Simple DirectMedia Layer
     1.6 +Copyright (C) 1997-2013 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_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
    1.27 +
    1.28 +#include "SDL_windowsvideo.h"
    1.29 +#include "SDL_windowsopengles.h"
    1.30 +#include "SDL_windowsopengl.h"
    1.31 +#include "SDL_log.h"
    1.32 +
    1.33 +/* EGL implementation of SDL OpenGL support */
    1.34 +
    1.35 +int
    1.36 +WIN_GLES_LoadLibrary(_THIS, const char *path) {
    1.37 +
    1.38 +    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
    1.39 +
    1.40 +    /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
    1.41 +    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    1.42 +#if SDL_VIDEO_OPENGL_WGL
    1.43 +        WIN_GLES_UnloadLibrary(_this);
    1.44 +        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
    1.45 +        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
    1.46 +        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
    1.47 +        _this->GL_CreateContext = WIN_GL_CreateContext;
    1.48 +        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
    1.49 +        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
    1.50 +        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
    1.51 +        _this->GL_SwapWindow = WIN_GL_SwapWindow;
    1.52 +        _this->GL_DeleteContext = WIN_GL_DeleteContext;
    1.53 +        return WIN_GL_LoadLibrary(_this, path);
    1.54 +#else
    1.55 +        return SDL_SetError("SDL not configured with OpenGL/WGL support");
    1.56 +#endif
    1.57 +    }
    1.58 +    
    1.59 +    if (_this->egl_data == NULL) {
    1.60 +        return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY);
    1.61 +    }
    1.62 +
    1.63 +    return 0;
    1.64 +}
    1.65 +
    1.66 +SDL_GLContext
    1.67 +WIN_GLES_CreateContext(_THIS, SDL_Window * window)
    1.68 +{
    1.69 +    SDL_GLContext context;
    1.70 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    1.71 +
    1.72 +    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    1.73 +        /* Switch to WGL based functions */
    1.74 +        WIN_GLES_UnloadLibrary(_this);
    1.75 +        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
    1.76 +        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
    1.77 +        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
    1.78 +        _this->GL_CreateContext = WIN_GL_CreateContext;
    1.79 +        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
    1.80 +        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
    1.81 +        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
    1.82 +        _this->GL_SwapWindow = WIN_GL_SwapWindow;
    1.83 +        _this->GL_DeleteContext = WIN_GL_DeleteContext;
    1.84 +
    1.85 +        if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
    1.86 +            return NULL;
    1.87 +        }
    1.88 +
    1.89 +        return WIN_GL_CreateContext(_this, window);
    1.90 +    }
    1.91 +
    1.92 +    context = SDL_EGL_CreateContext(_this, data->egl_surface);
    1.93 +    return context;
    1.94 +}
    1.95 +
    1.96 +void
    1.97 +WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
    1.98 +{
    1.99 +    SDL_EGL_DeleteContext(_this, context);
   1.100 +    WIN_GLES_UnloadLibrary(_this);
   1.101 +}
   1.102 +
   1.103 +SDL_EGL_SwapWindow_impl(WIN)
   1.104 +SDL_EGL_MakeCurrent_impl(WIN)
   1.105 +
   1.106 +int
   1.107 +WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
   1.108 +{
   1.109 +    /* The current context is lost in here; save it and reset it. */
   1.110 +    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
   1.111 +    SDL_Window *current_win = SDL_GL_GetCurrentWindow();
   1.112 +    SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
   1.113 +
   1.114 +
   1.115 +    if (_this->egl_data == NULL) {
   1.116 +        if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY) < 0) {
   1.117 +            return -1;
   1.118 +        }
   1.119 +    }
   1.120 +  
   1.121 +    /* Create the GLES window surface */
   1.122 +    windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
   1.123 +
   1.124 +    if (windowdata->egl_surface == EGL_NO_SURFACE) {
   1.125 +        return SDL_SetError("Could not create GLES window surface");
   1.126 +    }
   1.127 +
   1.128 +    return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);    
   1.129 +}
   1.130 +
   1.131 +int
   1.132 +WIN_GLES_SetSwapInterval(_THIS, int interval)
   1.133 +{
   1.134 +    /* FIXME: This should call SDL_EGL_SetSwapInterval, but ANGLE has a bug that prevents this
   1.135 +     * from working if we do (the window contents freeze and don't swap properly). So, we ignore
   1.136 +     * the request for now.
   1.137 +     */
   1.138 +    SDL_Log("WARNING: Ignoring SDL_GL_SetSwapInterval call due to ANGLE bug");
   1.139 +    return 0;
   1.140 +}
   1.141 +
   1.142 +#endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
   1.143 +
   1.144 +/* vi: set ts=4 sw=4 expandtab: */