src/video/windows/SDL_windowsopengl.c
changeset 8021 f96e12e0ade9
parent 7865 f2a42ca4ddf0
child 8022 7396e3cc5337
equal deleted inserted replaced
8020:1e390ba95c43 8021:f96e12e0ade9
    23 #if SDL_VIDEO_DRIVER_WINDOWS
    23 #if SDL_VIDEO_DRIVER_WINDOWS
    24 
    24 
    25 #include "SDL_assert.h"
    25 #include "SDL_assert.h"
    26 #include "SDL_loadso.h"
    26 #include "SDL_loadso.h"
    27 #include "SDL_windowsvideo.h"
    27 #include "SDL_windowsvideo.h"
       
    28 #include "SDL_windowsopengles.h"
    28 
    29 
    29 /* WGL implementation of SDL OpenGL support */
    30 /* WGL implementation of SDL OpenGL support */
    30 
    31 
    31 #if SDL_VIDEO_OPENGL_WGL
    32 #if SDL_VIDEO_OPENGL_WGL
    32 #include "SDL_opengl.h"
    33 #include "SDL_opengl.h"
   321         start = terminator;
   322         start = terminator;
   322     }
   323     }
   323     return SDL_FALSE;
   324     return SDL_FALSE;
   324 }
   325 }
   325 
   326 
   326 static void
   327 void
   327 WIN_GL_InitExtensions(_THIS, HDC hdc)
   328 WIN_GL_InitExtensions(_THIS)
   328 {
   329 {
   329     const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
   330     const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
   330     const char *extensions;
   331     const char *extensions;
       
   332     HWND hwnd;
       
   333     HDC hdc;
       
   334     HGLRC hglrc;
       
   335     PIXELFORMATDESCRIPTOR pfd;
       
   336 
       
   337     hwnd =
       
   338         CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
       
   339         10, 10, NULL, NULL, SDL_Instance, NULL);
       
   340     if (!hwnd) {
       
   341         return;
       
   342     }
       
   343     WIN_PumpEvents(_this);
       
   344 
       
   345     hdc = GetDC(hwnd);
       
   346 
       
   347     WIN_GL_SetupPixelFormat(_this, &pfd);
       
   348 
       
   349     SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
       
   350 
       
   351     hglrc = _this->gl_data->wglCreateContext(hdc);
       
   352     if (!hglrc) {
       
   353         return;
       
   354     }
       
   355     _this->gl_data->wglMakeCurrent(hdc, hglrc);
   331 
   356 
   332     wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
   357     wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
   333         _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
   358         _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
   334     if (wglGetExtensionsStringARB) {
   359     if (wglGetExtensionsStringARB) {
   335         extensions = wglGetExtensionsStringARB(hdc);
   360         extensions = wglGetExtensionsStringARB(hdc);
   367         }
   392         }
   368     } else {
   393     } else {
   369         _this->gl_data->wglSwapIntervalEXT = NULL;
   394         _this->gl_data->wglSwapIntervalEXT = NULL;
   370         _this->gl_data->wglGetSwapIntervalEXT = NULL;
   395         _this->gl_data->wglGetSwapIntervalEXT = NULL;
   371     }
   396     }
       
   397 
       
   398     /* Check for WGL_EXT_create_context_es2_profile */
       
   399     _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
       
   400     if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
       
   401         _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
       
   402     }
       
   403 
       
   404     _this->gl_data->wglMakeCurrent(hdc, NULL);
       
   405     _this->gl_data->wglDeleteContext(hglrc);
       
   406     ReleaseDC(hwnd, hdc);
       
   407     DestroyWindow(hwnd);
       
   408     WIN_PumpEvents(_this);
   372 }
   409 }
   373 
   410 
   374 static int
   411 static int
   375 WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
   412 WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
   376 {
   413 {
   393     SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
   430     SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
   394 
   431 
   395     hglrc = _this->gl_data->wglCreateContext(hdc);
   432     hglrc = _this->gl_data->wglCreateContext(hdc);
   396     if (hglrc) {
   433     if (hglrc) {
   397         _this->gl_data->wglMakeCurrent(hdc, hglrc);
   434         _this->gl_data->wglMakeCurrent(hdc, hglrc);
   398 
       
   399         WIN_GL_InitExtensions(_this, hdc);
       
   400 
   435 
   401         if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
   436         if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
   402             _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
   437             _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
   403                                                     1, &pixel_format,
   438                                                     1, &pixel_format,
   404                                                     &matching);
   439                                                     &matching);
   546 WIN_GL_CreateContext(_THIS, SDL_Window * window)
   581 WIN_GL_CreateContext(_THIS, SDL_Window * window)
   547 {
   582 {
   548     HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   583     HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   549     HGLRC context, share_context;
   584     HGLRC context, share_context;
   550 
   585 
       
   586     if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
       
   587         !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
       
   588         /* Switch to EGL based functions */
       
   589         WIN_GL_UnloadLibrary(_this);
       
   590         _this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
       
   591         _this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
       
   592         _this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
       
   593         _this->GL_CreateContext = WIN_GLES_CreateContext;
       
   594         _this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
       
   595         _this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
       
   596         _this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
       
   597         _this->GL_SwapWindow = WIN_GLES_SwapWindow;
       
   598         _this->GL_DeleteContext = WIN_GLES_DeleteContext;
       
   599         
       
   600         if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
       
   601             return NULL;
       
   602         }
       
   603         
       
   604         return WIN_GLES_CreateContext(_this, window);
       
   605     }
       
   606 
   551     if (_this->gl_config.share_with_current_context) {
   607     if (_this->gl_config.share_with_current_context) {
   552         share_context = (HGLRC)SDL_GL_GetCurrentContext();
   608         share_context = (HGLRC)SDL_GL_GetCurrentContext();
   553     } else {
   609     } else {
   554         share_context = 0;
   610         share_context = 0;
   555     }
   611     }
   619 
   675 
   620     if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
   676     if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
   621         WIN_GL_DeleteContext(_this, context);
   677         WIN_GL_DeleteContext(_this, context);
   622         return NULL;
   678         return NULL;
   623     }
   679     }
   624 
       
   625     WIN_GL_InitExtensions(_this, hdc);
       
   626 
   680 
   627     return context;
   681     return context;
   628 }
   682 }
   629 
   683 
   630 int
   684 int