src/video/windows/SDL_windowsopengles.c
author Gabriel Jacobo <gabomdq@gmail.com>
Fri, 22 Nov 2013 13:24:53 -0300
changeset 8021 f96e12e0ade9
child 8026 27a998fdc771
permissions -rw-r--r--
OpenGL ES support for Windows
gabomdq@8021
     1
/*
gabomdq@8021
     2
Simple DirectMedia Layer
gabomdq@8021
     3
Copyright (C) 1997-2013 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
*/
gabomdq@8021
    21
#include "SDL_config.h"
gabomdq@8021
    22
gabomdq@8021
    23
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
gabomdq@8021
    24
gabomdq@8021
    25
#include "SDL_windowsvideo.h"
gabomdq@8021
    26
#include "SDL_windowsopengles.h"
gabomdq@8021
    27
#include "SDL_windowsopengl.h"
gabomdq@8021
    28
#include "SDL_log.h"
gabomdq@8021
    29
gabomdq@8021
    30
/* EGL implementation of SDL OpenGL support */
gabomdq@8021
    31
gabomdq@8021
    32
int
gabomdq@8021
    33
WIN_GLES_LoadLibrary(_THIS, const char *path) {
gabomdq@8021
    34
gabomdq@8021
    35
    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
gabomdq@8021
    36
gabomdq@8021
    37
    /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
gabomdq@8021
    38
    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
gabomdq@8021
    39
#if SDL_VIDEO_OPENGL_WGL
gabomdq@8021
    40
        WIN_GLES_UnloadLibrary(_this);
gabomdq@8021
    41
        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
gabomdq@8021
    42
        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
gabomdq@8021
    43
        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
gabomdq@8021
    44
        _this->GL_CreateContext = WIN_GL_CreateContext;
gabomdq@8021
    45
        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
gabomdq@8021
    46
        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
gabomdq@8021
    47
        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
gabomdq@8021
    48
        _this->GL_SwapWindow = WIN_GL_SwapWindow;
gabomdq@8021
    49
        _this->GL_DeleteContext = WIN_GL_DeleteContext;
gabomdq@8021
    50
        return WIN_GL_LoadLibrary(_this, path);
gabomdq@8021
    51
#else
gabomdq@8021
    52
        return SDL_SetError("SDL not configured with OpenGL/WGL support");
gabomdq@8021
    53
#endif
gabomdq@8021
    54
    }
gabomdq@8021
    55
    
gabomdq@8021
    56
    if (_this->egl_data == NULL) {
gabomdq@8021
    57
        return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY);
gabomdq@8021
    58
    }
gabomdq@8021
    59
gabomdq@8021
    60
    return 0;
gabomdq@8021
    61
}
gabomdq@8021
    62
gabomdq@8021
    63
SDL_GLContext
gabomdq@8021
    64
WIN_GLES_CreateContext(_THIS, SDL_Window * window)
gabomdq@8021
    65
{
gabomdq@8021
    66
    SDL_GLContext context;
gabomdq@8021
    67
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
gabomdq@8021
    68
gabomdq@8021
    69
    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
gabomdq@8021
    70
        /* Switch to WGL based functions */
gabomdq@8021
    71
        WIN_GLES_UnloadLibrary(_this);
gabomdq@8021
    72
        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
gabomdq@8021
    73
        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
gabomdq@8021
    74
        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
gabomdq@8021
    75
        _this->GL_CreateContext = WIN_GL_CreateContext;
gabomdq@8021
    76
        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
gabomdq@8021
    77
        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
gabomdq@8021
    78
        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
gabomdq@8021
    79
        _this->GL_SwapWindow = WIN_GL_SwapWindow;
gabomdq@8021
    80
        _this->GL_DeleteContext = WIN_GL_DeleteContext;
gabomdq@8021
    81
gabomdq@8021
    82
        if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
gabomdq@8021
    83
            return NULL;
gabomdq@8021
    84
        }
gabomdq@8021
    85
gabomdq@8021
    86
        return WIN_GL_CreateContext(_this, window);
gabomdq@8021
    87
    }
gabomdq@8021
    88
gabomdq@8021
    89
    context = SDL_EGL_CreateContext(_this, data->egl_surface);
gabomdq@8021
    90
    return context;
gabomdq@8021
    91
}
gabomdq@8021
    92
gabomdq@8021
    93
void
gabomdq@8021
    94
WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
gabomdq@8021
    95
{
gabomdq@8021
    96
    SDL_EGL_DeleteContext(_this, context);
gabomdq@8021
    97
    WIN_GLES_UnloadLibrary(_this);
gabomdq@8021
    98
}
gabomdq@8021
    99
gabomdq@8021
   100
SDL_EGL_SwapWindow_impl(WIN)
gabomdq@8021
   101
SDL_EGL_MakeCurrent_impl(WIN)
gabomdq@8021
   102
gabomdq@8021
   103
int
gabomdq@8021
   104
WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
gabomdq@8021
   105
{
gabomdq@8021
   106
    /* The current context is lost in here; save it and reset it. */
gabomdq@8021
   107
    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
gabomdq@8021
   108
    SDL_Window *current_win = SDL_GL_GetCurrentWindow();
gabomdq@8021
   109
    SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
gabomdq@8021
   110
gabomdq@8021
   111
gabomdq@8021
   112
    if (_this->egl_data == NULL) {
gabomdq@8021
   113
        if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY) < 0) {
gabomdq@8021
   114
            return -1;
gabomdq@8021
   115
        }
gabomdq@8021
   116
    }
gabomdq@8021
   117
  
gabomdq@8021
   118
    /* Create the GLES window surface */
gabomdq@8021
   119
    windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
gabomdq@8021
   120
gabomdq@8021
   121
    if (windowdata->egl_surface == EGL_NO_SURFACE) {
gabomdq@8021
   122
        return SDL_SetError("Could not create GLES window surface");
gabomdq@8021
   123
    }
gabomdq@8021
   124
gabomdq@8021
   125
    return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);    
gabomdq@8021
   126
}
gabomdq@8021
   127
gabomdq@8021
   128
int
gabomdq@8021
   129
WIN_GLES_SetSwapInterval(_THIS, int interval)
gabomdq@8021
   130
{
gabomdq@8021
   131
    /* FIXME: This should call SDL_EGL_SetSwapInterval, but ANGLE has a bug that prevents this
gabomdq@8021
   132
     * from working if we do (the window contents freeze and don't swap properly). So, we ignore
gabomdq@8021
   133
     * the request for now.
gabomdq@8021
   134
     */
gabomdq@8021
   135
    SDL_Log("WARNING: Ignoring SDL_GL_SetSwapInterval call due to ANGLE bug");
gabomdq@8021
   136
    return 0;
gabomdq@8021
   137
}
gabomdq@8021
   138
gabomdq@8021
   139
#endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
gabomdq@8021
   140
gabomdq@8021
   141
/* vi: set ts=4 sw=4 expandtab: */