Skip to content

Commit

Permalink
WinRT: added experimental OpenGL ES 2.0 support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DavidLudwig committed Nov 5, 2013
1 parent 7cc0951 commit 749117a
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 35 deletions.
25 changes: 19 additions & 6 deletions VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
Expand Up @@ -145,6 +145,7 @@
<ClCompile Include="..\..\src\video\SDL_blit_slow.c" />
<ClCompile Include="..\..\src\video\SDL_bmp.c" />
<ClCompile Include="..\..\src\video\SDL_clipboard.c" />
<ClCompile Include="..\..\src\video\SDL_egl.c" />
<ClCompile Include="..\..\src\video\SDL_fillrect.c" />
<ClCompile Include="..\..\src\video\SDL_pixels.c" />
<ClCompile Include="..\..\src\video\SDL_rect.c" />
Expand Down Expand Up @@ -177,6 +178,14 @@
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtopengles.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
Expand Down Expand Up @@ -224,6 +233,7 @@
<ClInclude Include="..\..\include\SDL_mouse.h" />
<ClInclude Include="..\..\include\SDL_mutex.h" />
<ClInclude Include="..\..\include\SDL_name.h" />
<ClInclude Include="..\..\include\SDL_opengles2.h" />
<ClInclude Include="..\..\include\SDL_pixels.h" />
<ClInclude Include="..\..\include\SDL_platform.h" />
<ClInclude Include="..\..\include\SDL_power.h" />
Expand Down Expand Up @@ -299,13 +309,16 @@
<ClInclude Include="..\..\src\video\SDL_blit_auto.h" />
<ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
<ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
<ClInclude Include="..\..\src\video\SDL_egl.h" />
<ClInclude Include="..\..\src\video\SDL_pixels_c.h" />
<ClInclude Include="..\..\src\video\SDL_rect_c.h" />
<ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
<ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtegl.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
<ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -448,7 +461,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -462,7 +475,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -476,7 +489,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -490,7 +503,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -504,7 +517,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -518,7 +531,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\include;..\..\..\angleproject\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand Down
18 changes: 18 additions & 0 deletions VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
Expand Up @@ -279,6 +279,12 @@
<ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\video\SDL_egl.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\video\winrt\SDL_winrtopengles.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\begin_code.h">
Expand Down Expand Up @@ -617,6 +623,18 @@
<ClInclude Include="..\..\include\SDL_filesystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\video\SDL_egl.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\video\winrt\SDL_winrtegl.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_opengles2.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down
9 changes: 9 additions & 0 deletions include/SDL_config_winrt.h
Expand Up @@ -166,6 +166,15 @@ typedef unsigned int uintptr_t;
#define SDL_VIDEO_DRIVER_WINRT 1
#define SDL_VIDEO_DRIVER_DUMMY 1

/* Enable OpenGL ES 2.0 (via a modified ANGLE library) */
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP /* TODO, WinRT: try adding OpenGL ES 2 support for Windows Phone 8 */
/* Uncomment the following two #defines to enable experimental OpenGL ES 2 support
(via a WinRT port of the ANGLE library).
*/
//#define SDL_VIDEO_OPENGL_ES2 1
//#define SDL_VIDEO_OPENGL_EGL 1
#endif

// TODO, WinRT: Get a Direct3D 11 based renderer working in SDL.
/* Enable appropriate renderer(s) */
#define SDL_VIDEO_RENDER_D3D11 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_opengles2.h
Expand Up @@ -33,6 +33,8 @@
#include <GLES2/gl2ext.h>
#endif

#ifndef __WINRT__
#ifndef APIENTRY
#define APIENTRY
#endif
#endif
16 changes: 16 additions & 0 deletions src/video/SDL_egl.c
Expand Up @@ -40,6 +40,13 @@
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
#define DEFAULT_OGL_ES "libGLESv1_CM.so"

#elif SDL_VIDEO_DRIVER_WINRT
/* WinRT (via a modified version of Google's ANGLE library) */
#define DEFAULT_EGL "libEGL.dll"
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
#define DEFAULT_OGL_ES_PVR NULL
#define DEFAULT_OGL_ES NULL

#else
/* Desktop Linux */
#define DEFAULT_EGL "libEGL.so.1"
Expand Down Expand Up @@ -134,8 +141,13 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
#endif

/* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
#ifdef __WINRT__
path = NULL;
egl_dll_handle = NULL;
#else
path = getenv("SDL_VIDEO_GL_DRIVER");
egl_dll_handle = dlopen(path, dlopen_flags);
#endif
if ((path == NULL) | (egl_dll_handle == NULL)) {
if (_this->gl_config.major_version > 1) {
path = DEFAULT_OGL_ES2;
Expand All @@ -160,7 +172,11 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
/* Catch the case where the application isn't linked with EGL */
if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
dlclose(dll_handle);
#ifdef __WINRT__
path = NULL;
#else
path = getenv("SDL_VIDEO_EGL_DRIVER");
#endif
if (path == NULL) {
path = DEFAULT_EGL;
}
Expand Down
70 changes: 42 additions & 28 deletions src/video/SDL_egl.h
Expand Up @@ -25,13 +25,27 @@

#if SDL_VIDEO_OPENGL_EGL

#if defined(__WINRT__)

// DavidL: including this here leads to a compiler error:
// C2016: C requires that a struct or union has at least one member
// The error originates from a WinRT header file itself, roapi.h.
//
// Instead of including that file (EGL/egl.h), a subset of its contents is
// made available as part of winrt/SDL_winrtegl.h
//#include <EGL/egl.h>
#include "winrt/SDL_winrtegl.h"

#else
#include <EGL/egl.h>

#include <dlfcn.h>
#if defined(__OpenBSD__) && !defined(__ELF__)
#define dlsym(x,y) dlsym(x, "_" y)
#endif

#endif /* ! defined(__WINRT__) */

#include "SDL_sysvideo.h"

typedef struct SDL_EGL_VideoData
Expand All @@ -41,46 +55,46 @@ typedef struct SDL_EGL_VideoData
EGLConfig egl_config;
int egl_swapinterval;

EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
EGLint * minor);
EGLBoolean(*eglTerminate) (EGLDisplay dpy);
EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
EGLint * minor);
EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);

void *(*eglGetProcAddress) (const char * procName);
void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);

EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
const EGLint * attrib_list,
EGLConfig * configs,
EGLint config_size, EGLint * num_config);
EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
const EGLint * attrib_list,
EGLConfig * configs,
EGLint config_size, EGLint * num_config);

EGLContext(*eglCreateContext) (EGLDisplay dpy,
EGLConfig config,
EGLContext share_list,
const EGLint * attrib_list);
EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
EGLConfig config,
EGLContext share_list,
const EGLint * attrib_list);

EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);

EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
EGLConfig config,
NativeWindowType window,
const EGLint * attrib_list);
EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
EGLConfig config,
NativeWindowType window,
const EGLint * attrib_list);
EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);

EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx);
EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx);

EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);

EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);

const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);

EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
EGLint attribute, EGLint * value);
EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
EGLint attribute, EGLint * value);

EGLBoolean(*eglWaitNative) (EGLint engine);
EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);

EGLBoolean(*eglWaitGL)(void);
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
} SDL_EGL_VideoData;

/* OpenGLES functions */
Expand Down
2 changes: 1 addition & 1 deletion src/video/SDL_video.c
Expand Up @@ -41,7 +41,7 @@

/* GL and GLES2 headers conflict on Linux 32 bits */
#if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
#include "SDL_opengles2.h"
#include "SDL_opengles2.h"
#endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */

#include "SDL_syswm.h"
Expand Down

0 comments on commit 749117a

Please sign in to comment.