src/video/windows/SDL_windowsopengles.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 22 Jun 2014 09:48:46 -0700
changeset 8908 8333acde0b91
parent 8273 bdfea8962bcf
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Fixed bug 2579 - SDL fails to compile on Windows when only EGL+OpenGL ES defined

callow.mark

Compiling with SDL_VIDEO_RENDER_OGL=0, SDL_VIDEO_OPENGL=0, SDL_VIDEO_OPENGL_WGL=0, SDL_VIDEO_RENDER_OGL_ES2=1, SDL_VIDEO_OPENGL_ES2=1 and SDL_VIDEO_OPENGL_EGL=1 set in SDL_config_windows.h fails.

A patch is attached. See bug #2570 for reasons you might want to compile this way.
gabomdq@8021
     1
/*
philipp@8026
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
gabomdq@8021
     4
philipp@8026
     5
  This software is provided 'as-is', without any express or implied
philipp@8026
     6
  warranty.  In no event will the authors be held liable for any damages
philipp@8026
     7
  arising from the use of this software.
gabomdq@8021
     8
philipp@8026
     9
  Permission is granted to anyone to use this software for any purpose,
philipp@8026
    10
  including commercial applications, and to alter it and redistribute it
philipp@8026
    11
  freely, subject to the following restrictions:
gabomdq@8021
    12
philipp@8026
    13
  1. The origin of this software must not be misrepresented; you must not
philipp@8026
    14
     claim that you wrote the original software. If you use this software
philipp@8026
    15
     in a product, an acknowledgment in the product documentation would be
philipp@8026
    16
     appreciated but is not required.
philipp@8026
    17
  2. Altered source versions must be plainly marked as such, and must not be
philipp@8026
    18
     misrepresented as being the original software.
philipp@8026
    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
#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
    /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
gabomdq@8021
    36
    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
gabomdq@8021
    37
#if SDL_VIDEO_OPENGL_WGL
gabomdq@8021
    38
        WIN_GLES_UnloadLibrary(_this);
gabomdq@8021
    39
        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
gabomdq@8021
    40
        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
gabomdq@8021
    41
        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
gabomdq@8021
    42
        _this->GL_CreateContext = WIN_GL_CreateContext;
gabomdq@8021
    43
        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
gabomdq@8021
    44
        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
gabomdq@8021
    45
        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
gabomdq@8021
    46
        _this->GL_SwapWindow = WIN_GL_SwapWindow;
gabomdq@8021
    47
        _this->GL_DeleteContext = WIN_GL_DeleteContext;
gabomdq@8021
    48
        return WIN_GL_LoadLibrary(_this, path);
gabomdq@8021
    49
#else
gabomdq@8021
    50
        return SDL_SetError("SDL not configured with OpenGL/WGL support");
gabomdq@8021
    51
#endif
gabomdq@8021
    52
    }
gabomdq@8021
    53
    
gabomdq@8021
    54
    if (_this->egl_data == NULL) {
gabomdq@8021
    55
        return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY);
gabomdq@8021
    56
    }
gabomdq@8021
    57
gabomdq@8021
    58
    return 0;
gabomdq@8021
    59
}
gabomdq@8021
    60
gabomdq@8021
    61
SDL_GLContext
gabomdq@8021
    62
WIN_GLES_CreateContext(_THIS, SDL_Window * window)
gabomdq@8021
    63
{
gabomdq@8021
    64
    SDL_GLContext context;
gabomdq@8021
    65
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
gabomdq@8021
    66
slouken@8908
    67
#if SDL_VIDEO_OPENGL_WGL
gabomdq@8021
    68
    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
gabomdq@8021
    69
        /* Switch to WGL based functions */
gabomdq@8021
    70
        WIN_GLES_UnloadLibrary(_this);
gabomdq@8021
    71
        _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
gabomdq@8021
    72
        _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
gabomdq@8021
    73
        _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
gabomdq@8021
    74
        _this->GL_CreateContext = WIN_GL_CreateContext;
gabomdq@8021
    75
        _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
gabomdq@8021
    76
        _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
gabomdq@8021
    77
        _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
gabomdq@8021
    78
        _this->GL_SwapWindow = WIN_GL_SwapWindow;
gabomdq@8021
    79
        _this->GL_DeleteContext = WIN_GL_DeleteContext;
gabomdq@8021
    80
gabomdq@8021
    81
        if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
gabomdq@8021
    82
            return NULL;
gabomdq@8021
    83
        }
gabomdq@8021
    84
gabomdq@8021
    85
        return WIN_GL_CreateContext(_this, window);
gabomdq@8021
    86
    }
slouken@8908
    87
#endif
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: */