WinRT: added experimental OpenGL ES 2.0 support
authorDavid Ludwig <dludwig@pobox.com>
Mon, 04 Nov 2013 19:54:29 -0500
changeset 85410041edb891f3
parent 8540 724af2cd53b8
child 8542 97dcef41e4a7
WinRT: added experimental OpenGL ES 2.0 support

A port of the ANGLE library (OpenGL ES 2.0 for Direct3D) to WinRT, via https://github.com/stammen/angleproject, is used as a base.

To enable, clone 'angleproject' into the directory one above where SDL/WinRT is, open the file SDL/include/SDL_config_winrt.h, and uncomment the #defines that begin with 'SDL_VIDEO_OPENGL'. From there, apps can create an OpenGL capable SDL_Window via the flag, SDL_WINDOW_OPENGL, and an OpenGL ES 2 context via SDL_GL_CreateContext. The Direct3D 11.1 renderer cannot be used alongside SDL_WINDOW_OPENGL. Only Windows 8/8.1 is supported for now. Shaders may need to be precompiled, in some (all?) cases.
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
include/SDL_config_winrt.h
include/SDL_opengles2.h
src/video/SDL_egl.c
src/video/SDL_egl.h
src/video/SDL_video.c
src/video/winrt/SDL_winrtegl.h
src/video/winrt/SDL_winrtopengles.cpp
src/video/winrt/SDL_winrtopengles.h
src/video/winrt/SDL_winrtvideo.cpp
src/video/winrt/SDL_winrtvideo_cpp.h
     1.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Fri Nov 01 22:54:39 2013 -0400
     1.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Mon Nov 04 19:54:29 2013 -0500
     1.3 @@ -145,6 +145,7 @@
     1.4      <ClCompile Include="..\..\src\video\SDL_blit_slow.c" />
     1.5      <ClCompile Include="..\..\src\video\SDL_bmp.c" />
     1.6      <ClCompile Include="..\..\src\video\SDL_clipboard.c" />
     1.7 +    <ClCompile Include="..\..\src\video\SDL_egl.c" />
     1.8      <ClCompile Include="..\..\src\video\SDL_fillrect.c" />
     1.9      <ClCompile Include="..\..\src\video\SDL_pixels.c" />
    1.10      <ClCompile Include="..\..\src\video\SDL_rect.c" />
    1.11 @@ -177,6 +178,14 @@
    1.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.14      </ClCompile>
    1.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtopengles.cpp">
    1.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.20 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.21 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.22 +    </ClCompile>
    1.23      <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    1.24        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.25        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.26 @@ -224,6 +233,7 @@
    1.27      <ClInclude Include="..\..\include\SDL_mouse.h" />
    1.28      <ClInclude Include="..\..\include\SDL_mutex.h" />
    1.29      <ClInclude Include="..\..\include\SDL_name.h" />
    1.30 +    <ClInclude Include="..\..\include\SDL_opengles2.h" />
    1.31      <ClInclude Include="..\..\include\SDL_pixels.h" />
    1.32      <ClInclude Include="..\..\include\SDL_platform.h" />
    1.33      <ClInclude Include="..\..\include\SDL_power.h" />
    1.34 @@ -299,13 +309,16 @@
    1.35      <ClInclude Include="..\..\src\video\SDL_blit_auto.h" />
    1.36      <ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
    1.37      <ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
    1.38 +    <ClInclude Include="..\..\src\video\SDL_egl.h" />
    1.39      <ClInclude Include="..\..\src\video\SDL_pixels_c.h" />
    1.40      <ClInclude Include="..\..\src\video\SDL_rect_c.h" />
    1.41      <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
    1.42      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
    1.43      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
    1.44 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtegl.h" />
    1.45      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
    1.46      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
    1.47 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
    1.48      <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h" />
    1.49    </ItemGroup>
    1.50    <ItemGroup>
    1.51 @@ -448,7 +461,7 @@
    1.52      <ClCompile>
    1.53        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.54        <CompileAsWinRT>false</CompileAsWinRT>
    1.55 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.56 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.57        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.58      </ClCompile>
    1.59      <Link>
    1.60 @@ -462,7 +475,7 @@
    1.61      <ClCompile>
    1.62        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.63        <CompileAsWinRT>false</CompileAsWinRT>
    1.64 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.65 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.66        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.67      </ClCompile>
    1.68      <Link>
    1.69 @@ -476,7 +489,7 @@
    1.70      <ClCompile>
    1.71        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.72        <CompileAsWinRT>false</CompileAsWinRT>
    1.73 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.74 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.75        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.76      </ClCompile>
    1.77      <Link>
    1.78 @@ -490,7 +503,7 @@
    1.79      <ClCompile>
    1.80        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.81        <CompileAsWinRT>false</CompileAsWinRT>
    1.82 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.83 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.84        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.85      </ClCompile>
    1.86      <Link>
    1.87 @@ -504,7 +517,7 @@
    1.88      <ClCompile>
    1.89        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.90        <CompileAsWinRT>false</CompileAsWinRT>
    1.91 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.92 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    1.93        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.94      </ClCompile>
    1.95      <Link>
    1.96 @@ -518,7 +531,7 @@
    1.97      <ClCompile>
    1.98        <PrecompiledHeader>NotUsing</PrecompiledHeader>
    1.99        <CompileAsWinRT>false</CompileAsWinRT>
   1.100 -      <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
   1.101 +      <AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
   1.102        <PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   1.103      </ClCompile>
   1.104      <Link>
     2.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Fri Nov 01 22:54:39 2013 -0400
     2.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Mon Nov 04 19:54:29 2013 -0500
     2.3 @@ -279,6 +279,12 @@
     2.4      <ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClCompile>
     2.7 +    <ClCompile Include="..\..\src\video\SDL_egl.c">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClCompile>
    2.10 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtopengles.cpp">
    2.11 +      <Filter>Source Files</Filter>
    2.12 +    </ClCompile>
    2.13    </ItemGroup>
    2.14    <ItemGroup>
    2.15      <ClInclude Include="..\..\include\begin_code.h">
    2.16 @@ -617,6 +623,18 @@
    2.17      <ClInclude Include="..\..\include\SDL_filesystem.h">
    2.18        <Filter>Header Files</Filter>
    2.19      </ClInclude>
    2.20 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h">
    2.21 +      <Filter>Source Files</Filter>
    2.22 +    </ClInclude>
    2.23 +    <ClInclude Include="..\..\src\video\SDL_egl.h">
    2.24 +      <Filter>Source Files</Filter>
    2.25 +    </ClInclude>
    2.26 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtegl.h">
    2.27 +      <Filter>Source Files</Filter>
    2.28 +    </ClInclude>
    2.29 +    <ClInclude Include="..\..\include\SDL_opengles2.h">
    2.30 +      <Filter>Header Files</Filter>
    2.31 +    </ClInclude>
    2.32    </ItemGroup>
    2.33    <ItemGroup>
    2.34      <Filter Include="Header Files">
     3.1 --- a/include/SDL_config_winrt.h	Fri Nov 01 22:54:39 2013 -0400
     3.2 +++ b/include/SDL_config_winrt.h	Mon Nov 04 19:54:29 2013 -0500
     3.3 @@ -166,6 +166,15 @@
     3.4  #define SDL_VIDEO_DRIVER_WINRT	1
     3.5  #define SDL_VIDEO_DRIVER_DUMMY  1
     3.6  
     3.7 +/* Enable OpenGL ES 2.0 (via a modified ANGLE library) */
     3.8 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP    /* TODO, WinRT: try adding OpenGL ES 2 support for Windows Phone 8 */
     3.9 +/* Uncomment the following two #defines to enable experimental OpenGL ES 2 support
    3.10 +   (via a WinRT port of the ANGLE library).
    3.11 +*/
    3.12 +//#define SDL_VIDEO_OPENGL_ES2 1
    3.13 +//#define SDL_VIDEO_OPENGL_EGL 1
    3.14 +#endif
    3.15 +
    3.16  // TODO, WinRT: Get a Direct3D 11 based renderer working in SDL.
    3.17  /* Enable appropriate renderer(s) */
    3.18  #define SDL_VIDEO_RENDER_D3D11  1
     4.1 --- a/include/SDL_opengles2.h	Fri Nov 01 22:54:39 2013 -0400
     4.2 +++ b/include/SDL_opengles2.h	Mon Nov 04 19:54:29 2013 -0500
     4.3 @@ -33,6 +33,8 @@
     4.4  #include <GLES2/gl2ext.h>
     4.5  #endif
     4.6  
     4.7 +#ifndef __WINRT__
     4.8  #ifndef APIENTRY
     4.9  #define APIENTRY
    4.10  #endif
    4.11 +#endif
     5.1 --- a/src/video/SDL_egl.c	Fri Nov 01 22:54:39 2013 -0400
     5.2 +++ b/src/video/SDL_egl.c	Mon Nov 04 19:54:29 2013 -0500
     5.3 @@ -40,6 +40,13 @@
     5.4  #define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
     5.5  #define DEFAULT_OGL_ES "libGLESv1_CM.so"
     5.6  
     5.7 +#elif SDL_VIDEO_DRIVER_WINRT
     5.8 +/* WinRT (via a modified version of Google's ANGLE library) */
     5.9 +#define DEFAULT_EGL "libEGL.dll"
    5.10 +#define DEFAULT_OGL_ES2 "libGLESv2.dll"
    5.11 +#define DEFAULT_OGL_ES_PVR NULL
    5.12 +#define DEFAULT_OGL_ES NULL
    5.13 +
    5.14  #else
    5.15  /* Desktop Linux */
    5.16  #define DEFAULT_EGL "libEGL.so.1"
    5.17 @@ -134,8 +141,13 @@
    5.18  #endif
    5.19  
    5.20      /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
    5.21 +#ifdef __WINRT__
    5.22 +    path = NULL;
    5.23 +    egl_dll_handle = NULL;
    5.24 +#else
    5.25      path = getenv("SDL_VIDEO_GL_DRIVER");
    5.26      egl_dll_handle = dlopen(path, dlopen_flags);
    5.27 +#endif
    5.28      if ((path == NULL) | (egl_dll_handle == NULL)) {
    5.29          if (_this->gl_config.major_version > 1) {
    5.30              path = DEFAULT_OGL_ES2;
    5.31 @@ -160,7 +172,11 @@
    5.32      /* Catch the case where the application isn't linked with EGL */
    5.33      if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
    5.34          dlclose(dll_handle);
    5.35 +#ifdef __WINRT__
    5.36 +        path = NULL;
    5.37 +#else
    5.38          path = getenv("SDL_VIDEO_EGL_DRIVER");
    5.39 +#endif
    5.40          if (path == NULL) {
    5.41              path = DEFAULT_EGL;
    5.42          }
     6.1 --- a/src/video/SDL_egl.h	Fri Nov 01 22:54:39 2013 -0400
     6.2 +++ b/src/video/SDL_egl.h	Mon Nov 04 19:54:29 2013 -0500
     6.3 @@ -25,6 +25,18 @@
     6.4  
     6.5  #if SDL_VIDEO_OPENGL_EGL
     6.6  
     6.7 +#if defined(__WINRT__)
     6.8 +
     6.9 +// DavidL: including this here leads to a compiler error:
    6.10 +// C2016: C requires that a struct or union has at least one member
    6.11 +// The error originates from a WinRT header file itself, roapi.h.
    6.12 +//
    6.13 +// Instead of including that file (EGL/egl.h), a subset of its contents is
    6.14 +// made available as part of winrt/SDL_winrtegl.h
    6.15 +//#include <EGL/egl.h>
    6.16 +#include "winrt/SDL_winrtegl.h"
    6.17 +
    6.18 +#else
    6.19  #include <EGL/egl.h>
    6.20  
    6.21  #include <dlfcn.h>
    6.22 @@ -32,6 +44,8 @@
    6.23  #define dlsym(x,y) dlsym(x, "_" y)
    6.24  #endif
    6.25  
    6.26 +#endif /* ! defined(__WINRT__) */
    6.27 +
    6.28  #include "SDL_sysvideo.h"
    6.29  
    6.30  typedef struct SDL_EGL_VideoData
    6.31 @@ -41,46 +55,46 @@
    6.32      EGLConfig egl_config;
    6.33      int egl_swapinterval;
    6.34      
    6.35 -    EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
    6.36 -    EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
    6.37 -                                EGLint * minor);
    6.38 -    EGLBoolean(*eglTerminate) (EGLDisplay dpy);
    6.39 +    EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
    6.40 +    EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
    6.41 +                                            EGLint * minor);
    6.42 +    EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
    6.43      
    6.44 -    void *(*eglGetProcAddress) (const char * procName);
    6.45 +    void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
    6.46      
    6.47 -    EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
    6.48 -                                  const EGLint * attrib_list,
    6.49 -                                  EGLConfig * configs,
    6.50 -                                  EGLint config_size, EGLint * num_config);
    6.51 +    EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
    6.52 +                                              const EGLint * attrib_list,
    6.53 +                                              EGLConfig * configs,
    6.54 +                                              EGLint config_size, EGLint * num_config);
    6.55      
    6.56 -    EGLContext(*eglCreateContext) (EGLDisplay dpy,
    6.57 -                                   EGLConfig config,
    6.58 -                                   EGLContext share_list,
    6.59 -                                   const EGLint * attrib_list);
    6.60 +    EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
    6.61 +                                               EGLConfig config,
    6.62 +                                               EGLContext share_list,
    6.63 +                                               const EGLint * attrib_list);
    6.64      
    6.65 -    EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
    6.66 +    EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
    6.67      
    6.68 -    EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
    6.69 -                                         EGLConfig config,
    6.70 -                                         NativeWindowType window,
    6.71 -                                         const EGLint * attrib_list);
    6.72 -    EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
    6.73 +    EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
    6.74 +                                                     EGLConfig config,
    6.75 +                                                     NativeWindowType window,
    6.76 +                                                     const EGLint * attrib_list);
    6.77 +    EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
    6.78      
    6.79 -    EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
    6.80 -                                 EGLSurface read, EGLContext ctx);
    6.81 +    EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
    6.82 +                                             EGLSurface read, EGLContext ctx);
    6.83      
    6.84 -    EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
    6.85 +    EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
    6.86      
    6.87 -    EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
    6.88 +    EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
    6.89      
    6.90 -    const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
    6.91 +    const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
    6.92      
    6.93 -    EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
    6.94 -                                     EGLint attribute, EGLint * value);
    6.95 +    EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
    6.96 +                                                 EGLint attribute, EGLint * value);
    6.97      
    6.98 -    EGLBoolean(*eglWaitNative) (EGLint  engine);
    6.99 +    EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint  engine);
   6.100  
   6.101 -    EGLBoolean(*eglWaitGL)(void);   
   6.102 +    EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);   
   6.103  } SDL_EGL_VideoData;
   6.104  
   6.105  /* OpenGLES functions */
     7.1 --- a/src/video/SDL_video.c	Fri Nov 01 22:54:39 2013 -0400
     7.2 +++ b/src/video/SDL_video.c	Mon Nov 04 19:54:29 2013 -0500
     7.3 @@ -41,7 +41,7 @@
     7.4  
     7.5  /* GL and GLES2 headers conflict on Linux 32 bits */
     7.6  #if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
     7.7 -#include "SDL_opengles2.h"
     7.8 +#include "SDL_opengles2.h" 
     7.9  #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
    7.10  
    7.11  #include "SDL_syswm.h"
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/winrt/SDL_winrtegl.h	Mon Nov 04 19:54:29 2013 -0500
     8.3 @@ -0,0 +1,166 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#ifndef _SDL_winrtegl_h
    8.28 +#define _SDL_winrtegl_h
    8.29 +
    8.30 +#include "SDL_hints.h"
    8.31 +#include "SDL_loadso.h"
    8.32 +
    8.33 +#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
    8.34 +
    8.35 +/* Emulate various *nix functions that SDL_egl.c will call.
    8.36 + */
    8.37 +#define dlsym SDL_LoadFunction
    8.38 +#define dlclose SDL_UnloadObject
    8.39 +#define dlopen(path, mode) ((path == NULL) ? NULL : SDL_LoadObject(path))  /* TODO, WinRT: create a separate function here, that sets dlerror on empty params */
    8.40 +#define dlerror SDL_GetError
    8.41 +#define getenv SDL_GetHint
    8.42 +#define RTLD_LAZY 0
    8.43 +
    8.44 +
    8.45 +/*
    8.46 +** Copyright (c) 2007-2009 The Khronos Group Inc.
    8.47 +**
    8.48 +** Permission is hereby granted, free of charge, to any person obtaining a
    8.49 +** copy of this software and/or associated documentation files (the
    8.50 +** "Materials"), to deal in the Materials without restriction, including
    8.51 +** without limitation the rights to use, copy, modify, merge, publish,
    8.52 +** distribute, sublicense, and/or sell copies of the Materials, and to
    8.53 +** permit persons to whom the Materials are furnished to do so, subject to
    8.54 +** the following conditions:
    8.55 +**
    8.56 +** The above copyright notice and this permission notice shall be included
    8.57 +** in all copies or substantial portions of the Materials.
    8.58 +**
    8.59 +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    8.60 +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    8.61 +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    8.62 +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    8.63 +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    8.64 +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    8.65 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    8.66 +*/
    8.67 +
    8.68 +/* EGL Types */
    8.69 +/* EGLint is defined in eglplatform.h */
    8.70 +typedef unsigned int EGLBoolean;
    8.71 +typedef unsigned int EGLenum;
    8.72 +typedef void *EGLConfig;
    8.73 +typedef void *EGLContext;
    8.74 +typedef void *EGLDisplay;
    8.75 +typedef void *EGLSurface;
    8.76 +typedef void *EGLClientBuffer;
    8.77 +
    8.78 +/* Platform-specific types */
    8.79 +//typedef int EGLNativeDisplayType;
    8.80 +typedef int NativeDisplayType;
    8.81 +typedef void * NativeWindowType;
    8.82 +
    8.83 +#ifndef EGLAPIENTRY
    8.84 +#define EGLAPIENTRY  __stdcall
    8.85 +#endif
    8.86 +
    8.87 +
    8.88 +/* Define EGLint. This must be a signed integral type large enough to contain
    8.89 + * all legal attribute names and values passed into and out of EGL, whether
    8.90 + * their type is boolean, bitmask, enumerant (symbolic constant), integer,
    8.91 + * handle, or other.  While in general a 32-bit integer will suffice, if
    8.92 + * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
    8.93 + * integer type.
    8.94 + */
    8.95 +typedef int EGLint;
    8.96 +
    8.97 +/* EGL Enumerants. Bitmasks and other exceptional cases aside, most
    8.98 + * enums are assigned unique values starting at 0x3000.
    8.99 + */
   8.100 +
   8.101 +/* EGL aliases */
   8.102 +#define EGL_FALSE			0
   8.103 +#define EGL_TRUE			1
   8.104 +
   8.105 +/* Out-of-band handle values */
   8.106 +#define EGL_DEFAULT_DISPLAY		((EGLNativeDisplayType)0)
   8.107 +#define EGL_NO_CONTEXT			((EGLContext)0)
   8.108 +#define EGL_NO_DISPLAY			((EGLDisplay)0)
   8.109 +#define EGL_NO_SURFACE			((EGLSurface)0)
   8.110 +
   8.111 +/* Config attributes */
   8.112 +#define EGL_BUFFER_SIZE			0x3020
   8.113 +#define EGL_ALPHA_SIZE			0x3021
   8.114 +#define EGL_BLUE_SIZE			0x3022
   8.115 +#define EGL_GREEN_SIZE			0x3023
   8.116 +#define EGL_RED_SIZE			0x3024
   8.117 +#define EGL_DEPTH_SIZE			0x3025
   8.118 +#define EGL_STENCIL_SIZE		0x3026
   8.119 +#define EGL_CONFIG_CAVEAT		0x3027
   8.120 +#define EGL_CONFIG_ID			0x3028
   8.121 +#define EGL_LEVEL			0x3029
   8.122 +#define EGL_MAX_PBUFFER_HEIGHT		0x302A
   8.123 +#define EGL_MAX_PBUFFER_PIXELS		0x302B
   8.124 +#define EGL_MAX_PBUFFER_WIDTH		0x302C
   8.125 +#define EGL_NATIVE_RENDERABLE		0x302D
   8.126 +#define EGL_NATIVE_VISUAL_ID		0x302E
   8.127 +#define EGL_NATIVE_VISUAL_TYPE		0x302F
   8.128 +#define EGL_SAMPLES			0x3031
   8.129 +#define EGL_SAMPLE_BUFFERS		0x3032
   8.130 +#define EGL_SURFACE_TYPE		0x3033
   8.131 +#define EGL_TRANSPARENT_TYPE		0x3034
   8.132 +#define EGL_TRANSPARENT_BLUE_VALUE	0x3035
   8.133 +#define EGL_TRANSPARENT_GREEN_VALUE	0x3036
   8.134 +#define EGL_TRANSPARENT_RED_VALUE	0x3037
   8.135 +#define EGL_NONE			0x3038	/* Attrib list terminator */
   8.136 +#define EGL_BIND_TO_TEXTURE_RGB		0x3039
   8.137 +#define EGL_BIND_TO_TEXTURE_RGBA	0x303A
   8.138 +#define EGL_MIN_SWAP_INTERVAL		0x303B
   8.139 +#define EGL_MAX_SWAP_INTERVAL		0x303C
   8.140 +#define EGL_LUMINANCE_SIZE		0x303D
   8.141 +#define EGL_ALPHA_MASK_SIZE		0x303E
   8.142 +#define EGL_COLOR_BUFFER_TYPE		0x303F
   8.143 +#define EGL_RENDERABLE_TYPE		0x3040
   8.144 +#define EGL_MATCH_NATIVE_PIXMAP		0x3041	/* Pseudo-attribute (not queryable) */
   8.145 +#define EGL_CONFORMANT			0x3042
   8.146 +
   8.147 +/* Config attribute mask bits */
   8.148 +#define EGL_PBUFFER_BIT			0x0001	/* EGL_SURFACE_TYPE mask bits */
   8.149 +#define EGL_PIXMAP_BIT			0x0002	/* EGL_SURFACE_TYPE mask bits */
   8.150 +#define EGL_WINDOW_BIT			0x0004	/* EGL_SURFACE_TYPE mask bits */
   8.151 +#define EGL_VG_COLORSPACE_LINEAR_BIT	0x0020	/* EGL_SURFACE_TYPE mask bits */
   8.152 +#define EGL_VG_ALPHA_FORMAT_PRE_BIT	0x0040	/* EGL_SURFACE_TYPE mask bits */
   8.153 +#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200	/* EGL_SURFACE_TYPE mask bits */
   8.154 +#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400	/* EGL_SURFACE_TYPE mask bits */
   8.155 +
   8.156 +#define EGL_OPENGL_ES_BIT		0x0001	/* EGL_RENDERABLE_TYPE mask bits */
   8.157 +#define EGL_OPENVG_BIT			0x0002	/* EGL_RENDERABLE_TYPE mask bits */
   8.158 +#define EGL_OPENGL_ES2_BIT		0x0004	/* EGL_RENDERABLE_TYPE mask bits */
   8.159 +#define EGL_OPENGL_BIT			0x0008	/* EGL_RENDERABLE_TYPE mask bits */
   8.160 +
   8.161 +/* CreateContext attributes */
   8.162 +#define EGL_CONTEXT_CLIENT_VERSION	0x3098
   8.163 +
   8.164 +
   8.165 +#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
   8.166 +
   8.167 +#endif /* _SDL_winrtegl_h */
   8.168 +
   8.169 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/winrt/SDL_winrtopengles.cpp	Mon Nov 04 19:54:29 2013 -0500
     9.3 @@ -0,0 +1,55 @@
     9.4 +/*
     9.5 +  Simple DirectMedia Layer
     9.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     9.7 +
     9.8 +  This software is provided 'as-is', without any express or implied
     9.9 +  warranty.  In no event will the authors be held liable for any damages
    9.10 +  arising from the use of this software.
    9.11 +
    9.12 +  Permission is granted to anyone to use this software for any purpose,
    9.13 +  including commercial applications, and to alter it and redistribute it
    9.14 +  freely, subject to the following restrictions:
    9.15 +
    9.16 +  1. The origin of this software must not be misrepresented; you must not
    9.17 +     claim that you wrote the original software. If you use this software
    9.18 +     in a product, an acknowledgment in the product documentation would be
    9.19 +     appreciated but is not required.
    9.20 +  2. Altered source versions must be plainly marked as such, and must not be
    9.21 +     misrepresented as being the original software.
    9.22 +  3. This notice may not be removed or altered from any source distribution.
    9.23 +*/
    9.24 +#include "SDL_config.h"
    9.25 +
    9.26 +// TODO: WinRT, make this file compile via C code
    9.27 +
    9.28 +#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
    9.29 +
    9.30 +/* EGL implementation of SDL OpenGL support */
    9.31 +
    9.32 +// TODO, WinRT: Try to include these here, or via something else (rather than redefining key parts of them)
    9.33 +//#include <GLES2/gl2.h>
    9.34 +//#include <EGL/egl.h>
    9.35 +//#include <EGL/eglext.h>
    9.36 +
    9.37 +#include "SDL_winrtvideo_cpp.h"
    9.38 +extern "C" {
    9.39 +#include "SDL_winrtopengles.h"
    9.40 +}
    9.41 +
    9.42 +#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
    9.43 +
    9.44 +extern "C" int
    9.45 +WINRT_GLES_LoadLibrary(_THIS, const char *path) {
    9.46 +    return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
    9.47 +}
    9.48 +
    9.49 +extern "C" {
    9.50 +SDL_EGL_CreateContext_impl(WINRT)
    9.51 +SDL_EGL_SwapWindow_impl(WINRT)
    9.52 +SDL_EGL_MakeCurrent_impl(WINRT)
    9.53 +}
    9.54 +
    9.55 +#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
    9.56 +
    9.57 +/* vi: set ts=4 sw=4 expandtab: */
    9.58 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/winrt/SDL_winrtopengles.h	Mon Nov 04 19:54:29 2013 -0500
    10.3 @@ -0,0 +1,48 @@
    10.4 +/*
    10.5 +  Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    10.7 +
    10.8 +  This software is provided 'as-is', without any express or implied
    10.9 +  warranty.  In no event will the authors be held liable for any damages
   10.10 +  arising from the use of this software.
   10.11 +
   10.12 +  Permission is granted to anyone to use this software for any purpose,
   10.13 +  including commercial applications, and to alter it and redistribute it
   10.14 +  freely, subject to the following restrictions:
   10.15 +
   10.16 +  1. The origin of this software must not be misrepresented; you must not
   10.17 +     claim that you wrote the original software. If you use this software
   10.18 +     in a product, an acknowledgment in the product documentation would be
   10.19 +     appreciated but is not required.
   10.20 +  2. Altered source versions must be plainly marked as such, and must not be
   10.21 +     misrepresented as being the original software.
   10.22 +  3. This notice may not be removed or altered from any source distribution.
   10.23 +*/
   10.24 +#include "SDL_config.h"
   10.25 +
   10.26 +#ifndef _SDL_winrtopengles_h
   10.27 +#define _SDL_winrtopengles_h
   10.28 +
   10.29 +#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
   10.30 +
   10.31 +#include "../SDL_sysvideo.h"
   10.32 +#include "../SDL_egl.h"
   10.33 +
   10.34 +/* OpenGLES functions */
   10.35 +#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
   10.36 +#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
   10.37 +#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
   10.38 +#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
   10.39 +#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
   10.40 +#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
   10.41 +
   10.42 +extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
   10.43 +extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window);
   10.44 +extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window);
   10.45 +extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
   10.46 +
   10.47 +#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
   10.48 +
   10.49 +#endif /* _SDL_winrtopengles_h */
   10.50 +
   10.51 +/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Fri Nov 01 22:54:39 2013 -0400
    11.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Mon Nov 04 19:54:29 2013 -0500
    11.3 @@ -42,6 +42,7 @@
    11.4  #include "../../events/SDL_events_c.h"
    11.5  #include "../../render/SDL_sysrender.h"
    11.6  #include "SDL_syswm.h"
    11.7 +#include "SDL_winrtopengles.h"
    11.8  }
    11.9  
   11.10  #include "../../core/winrt/SDL_winrtapp_direct3d.h"
   11.11 @@ -111,6 +112,17 @@
   11.12      device->SetDisplayMode = WINRT_SetDisplayMode;
   11.13      device->PumpEvents = WINRT_PumpEvents;
   11.14      device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
   11.15 +#ifdef SDL_VIDEO_OPENGL_EGL
   11.16 +    device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
   11.17 +    device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
   11.18 +    device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
   11.19 +    device->GL_CreateContext = WINRT_GLES_CreateContext;
   11.20 +    device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
   11.21 +    device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
   11.22 +    device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
   11.23 +    device->GL_SwapWindow = WINRT_GLES_SwapWindow;
   11.24 +    device->GL_DeleteContext = WINRT_GLES_DeleteContext;
   11.25 +#endif
   11.26      device->free = WINRT_DeleteDevice;
   11.27      WINRT_GlobalSDLVideoDevice = device;
   11.28  
   11.29 @@ -247,6 +259,22 @@
   11.30          data->coreWindow = CoreWindow::GetForCurrentThread();
   11.31      }
   11.32  
   11.33 +#if SDL_VIDEO_OPENGL_EGL
   11.34 +    /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
   11.35 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
   11.36 +        /* OpenGL ES 2 wasn't requested.  Don't set up an EGL surface. */
   11.37 +        data->egl_surface = EGL_NO_SURFACE;
   11.38 +    } else {
   11.39 +        /* OpenGL ES 2 was reuqested.  Set up an EGL surface. */
   11.40 +        IUnknown * nativeWindow = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
   11.41 +        data->egl_surface = SDL_EGL_CreateSurface(_this, nativeWindow);
   11.42 +        if (data->egl_surface == NULL) {
   11.43 +            // TODO, WinRT: see if SDL_EGL_CreateSurface, or its callee(s), sets an error message.  If so, attach it to the SDL error.
   11.44 +            return SDL_SetError("SDL_EGL_CreateSurface failed");
   11.45 +        }
   11.46 +    }
   11.47 +#endif
   11.48 +
   11.49      /* Make sure the window is considered to be positioned at {0,0},
   11.50         and is considered fullscreen, shown, and the like.
   11.51      */
   11.52 @@ -259,6 +287,12 @@
   11.53          SDL_WINDOW_MAXIMIZED |
   11.54          SDL_WINDOW_INPUT_GRABBED;
   11.55  
   11.56 +#if SDL_VIDEO_OPENGL_EGL
   11.57 +    if (data->egl_surface) {
   11.58 +        window->flags |= SDL_WINDOW_OPENGL;
   11.59 +    }
   11.60 +#endif
   11.61 +
   11.62      /* WinRT does not, as of this writing, appear to support app-adjustable
   11.63         window sizes.  Set the window size to whatever the native WinRT
   11.64         CoreWindow is set at.
    12.1 --- a/src/video/winrt/SDL_winrtvideo_cpp.h	Fri Nov 01 22:54:39 2013 -0400
    12.2 +++ b/src/video/winrt/SDL_winrtvideo_cpp.h	Mon Nov 04 19:54:29 2013 -0500
    12.3 @@ -26,8 +26,14 @@
    12.4  #endif
    12.5  
    12.6  /* SDL includes: */
    12.7 +#include "SDL_video.h"
    12.8  #include "SDL_events.h"
    12.9  
   12.10 +extern "C" {
   12.11 +#include "../SDL_sysvideo.h"
   12.12 +#include "SDL_winrtegl.h"
   12.13 +}
   12.14 +
   12.15  
   12.16  /* The global, WinRT, SDL Window.
   12.17     For now, SDL/WinRT only supports one window (due to platform limitations of
   12.18 @@ -49,6 +55,9 @@
   12.19  {
   12.20      SDL_Window *sdlWindow;
   12.21      Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
   12.22 +#ifdef SDL_VIDEO_OPENGL_EGL
   12.23 +    EGLSurface egl_surface;
   12.24 +#endif
   12.25  };
   12.26  
   12.27  #endif // ifdef __cplusplus_winrt