src/video/windows/SDL_windowsopengl.c
changeset 8021 f96e12e0ade9
parent 7865 f2a42ca4ddf0
child 8022 7396e3cc5337
     1.1 --- a/src/video/windows/SDL_windowsopengl.c	Fri Nov 22 10:26:28 2013 -0300
     1.2 +++ b/src/video/windows/SDL_windowsopengl.c	Fri Nov 22 13:24:53 2013 -0300
     1.3 @@ -25,6 +25,7 @@
     1.4  #include "SDL_assert.h"
     1.5  #include "SDL_loadso.h"
     1.6  #include "SDL_windowsvideo.h"
     1.7 +#include "SDL_windowsopengles.h"
     1.8  
     1.9  /* WGL implementation of SDL OpenGL support */
    1.10  
    1.11 @@ -323,11 +324,35 @@
    1.12      return SDL_FALSE;
    1.13  }
    1.14  
    1.15 -static void
    1.16 -WIN_GL_InitExtensions(_THIS, HDC hdc)
    1.17 +void
    1.18 +WIN_GL_InitExtensions(_THIS)
    1.19  {
    1.20      const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
    1.21      const char *extensions;
    1.22 +    HWND hwnd;
    1.23 +    HDC hdc;
    1.24 +    HGLRC hglrc;
    1.25 +    PIXELFORMATDESCRIPTOR pfd;
    1.26 +
    1.27 +    hwnd =
    1.28 +        CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
    1.29 +        10, 10, NULL, NULL, SDL_Instance, NULL);
    1.30 +    if (!hwnd) {
    1.31 +        return;
    1.32 +    }
    1.33 +    WIN_PumpEvents(_this);
    1.34 +
    1.35 +    hdc = GetDC(hwnd);
    1.36 +
    1.37 +    WIN_GL_SetupPixelFormat(_this, &pfd);
    1.38 +
    1.39 +    SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
    1.40 +
    1.41 +    hglrc = _this->gl_data->wglCreateContext(hdc);
    1.42 +    if (!hglrc) {
    1.43 +        return;
    1.44 +    }
    1.45 +    _this->gl_data->wglMakeCurrent(hdc, hglrc);
    1.46  
    1.47      wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
    1.48          _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
    1.49 @@ -369,6 +394,18 @@
    1.50          _this->gl_data->wglSwapIntervalEXT = NULL;
    1.51          _this->gl_data->wglGetSwapIntervalEXT = NULL;
    1.52      }
    1.53 +
    1.54 +    /* Check for WGL_EXT_create_context_es2_profile */
    1.55 +    _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
    1.56 +    if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
    1.57 +        _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
    1.58 +    }
    1.59 +
    1.60 +    _this->gl_data->wglMakeCurrent(hdc, NULL);
    1.61 +    _this->gl_data->wglDeleteContext(hglrc);
    1.62 +    ReleaseDC(hwnd, hdc);
    1.63 +    DestroyWindow(hwnd);
    1.64 +    WIN_PumpEvents(_this);
    1.65  }
    1.66  
    1.67  static int
    1.68 @@ -396,8 +433,6 @@
    1.69      if (hglrc) {
    1.70          _this->gl_data->wglMakeCurrent(hdc, hglrc);
    1.71  
    1.72 -        WIN_GL_InitExtensions(_this, hdc);
    1.73 -
    1.74          if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
    1.75              _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
    1.76                                                      1, &pixel_format,
    1.77 @@ -548,6 +583,27 @@
    1.78      HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
    1.79      HGLRC context, share_context;
    1.80  
    1.81 +    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
    1.82 +        !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
    1.83 +        /* Switch to EGL based functions */
    1.84 +        WIN_GL_UnloadLibrary(_this);
    1.85 +        _this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
    1.86 +        _this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
    1.87 +        _this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
    1.88 +        _this->GL_CreateContext = WIN_GLES_CreateContext;
    1.89 +        _this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
    1.90 +        _this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
    1.91 +        _this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
    1.92 +        _this->GL_SwapWindow = WIN_GLES_SwapWindow;
    1.93 +        _this->GL_DeleteContext = WIN_GLES_DeleteContext;
    1.94 +        
    1.95 +        if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
    1.96 +            return NULL;
    1.97 +        }
    1.98 +        
    1.99 +        return WIN_GLES_CreateContext(_this, window);
   1.100 +    }
   1.101 +
   1.102      if (_this->gl_config.share_with_current_context) {
   1.103          share_context = (HGLRC)SDL_GL_GetCurrentContext();
   1.104      } else {
   1.105 @@ -622,8 +678,6 @@
   1.106          return NULL;
   1.107      }
   1.108  
   1.109 -    WIN_GL_InitExtensions(_this, hdc);
   1.110 -
   1.111      return context;
   1.112  }
   1.113