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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
index e50293e..a7ffb4d 100644
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
@@ -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" />
@@ -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>
@@ -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" />
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
index 8a7f94d..82cbcb3 100644
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
@@ -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">
@@ -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">
diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h
index 712a914..210d1e6 100644
--- a/include/SDL_config_winrt.h
+++ b/include/SDL_config_winrt.h
@@ -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
diff --git a/include/SDL_opengles2.h b/include/SDL_opengles2.h
index 7697626..d090c8d 100644
--- a/include/SDL_opengles2.h
+++ b/include/SDL_opengles2.h
@@ -33,6 +33,8 @@
#include <GLES2/gl2ext.h>
#endif
+#ifndef __WINRT__
#ifndef APIENTRY
#define APIENTRY
#endif
+#endif
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index ccfb92e..6d4130b 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -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"
@@ -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;
@@ -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;
}
diff --git a/src/video/SDL_egl.h b/src/video/SDL_egl.h
index d613905..00bb26f 100644
--- a/src/video/SDL_egl.h
+++ b/src/video/SDL_egl.h
@@ -25,6 +25,18 @@
#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>
@@ -32,6 +44,8 @@
#define dlsym(x,y) dlsym(x, "_" y)
#endif
+#endif /* ! defined(__WINRT__) */
+
#include "SDL_sysvideo.h"
typedef struct SDL_EGL_VideoData
@@ -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 */
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 5c1c6d3..e255f4b 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -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"
diff --git a/src/video/winrt/SDL_winrtegl.h b/src/video/winrt/SDL_winrtegl.h
new file mode 100644
index 0000000..4ce55be
--- /dev/null
+++ b/src/video/winrt/SDL_winrtegl.h
@@ -0,0 +1,166 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#ifndef _SDL_winrtegl_h
+#define _SDL_winrtegl_h
+
+#include "SDL_hints.h"
+#include "SDL_loadso.h"
+
+#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
+
+/* Emulate various *nix functions that SDL_egl.c will call.
+ */
+#define dlsym SDL_LoadFunction
+#define dlclose SDL_UnloadObject
+#define dlopen(path, mode) ((path == NULL) ? NULL : SDL_LoadObject(path)) /* TODO, WinRT: create a separate function here, that sets dlerror on empty params */
+#define dlerror SDL_GetError
+#define getenv SDL_GetHint
+#define RTLD_LAZY 0
+
+
+/*
+** Copyright (c) 2007-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* EGL Types */
+/* EGLint is defined in eglplatform.h */
+typedef unsigned int EGLBoolean;
+typedef unsigned int EGLenum;
+typedef void *EGLConfig;
+typedef void *EGLContext;
+typedef void *EGLDisplay;
+typedef void *EGLSurface;
+typedef void *EGLClientBuffer;
+
+/* Platform-specific types */
+//typedef int EGLNativeDisplayType;
+typedef int NativeDisplayType;
+typedef void * NativeWindowType;
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY __stdcall
+#endif
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+ * all legal attribute names and values passed into and out of EGL, whether
+ * their type is boolean, bitmask, enumerant (symbolic constant), integer,
+ * handle, or other. While in general a 32-bit integer will suffice, if
+ * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+ * integer type.
+ */
+typedef int EGLint;
+
+/* EGL Enumerants. Bitmasks and other exceptional cases aside, most
+ * enums are assigned unique values starting at 0x3000.
+ */
+
+/* EGL aliases */
+#define EGL_FALSE 0
+#define EGL_TRUE 1
+
+/* Out-of-band handle values */
+#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
+#define EGL_NO_CONTEXT ((EGLContext)0)
+#define EGL_NO_DISPLAY ((EGLDisplay)0)
+#define EGL_NO_SURFACE ((EGLSurface)0)
+
+/* Config attributes */
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_RED_SIZE 0x3024
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_NONE 0x3038 /* Attrib list terminator */
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */
+#define EGL_CONFORMANT 0x3042
+
+/* Config attribute mask bits */
+#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */
+
+#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */
+
+/* CreateContext attributes */
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+
+
+#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* _SDL_winrtegl_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/winrt/SDL_winrtopengles.cpp b/src/video/winrt/SDL_winrtopengles.cpp
new file mode 100644
index 0000000..bbb73d7
--- /dev/null
+++ b/src/video/winrt/SDL_winrtopengles.cpp
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+// TODO: WinRT, make this file compile via C code
+
+#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
+
+/* EGL implementation of SDL OpenGL support */
+
+// TODO, WinRT: Try to include these here, or via something else (rather than redefining key parts of them)
+//#include <GLES2/gl2.h>
+//#include <EGL/egl.h>
+//#include <EGL/eglext.h>
+
+#include "SDL_winrtvideo_cpp.h"
+extern "C" {
+#include "SDL_winrtopengles.h"
+}
+
+#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
+
+extern "C" int
+WINRT_GLES_LoadLibrary(_THIS, const char *path) {
+ return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
+}
+
+extern "C" {
+SDL_EGL_CreateContext_impl(WINRT)
+SDL_EGL_SwapWindow_impl(WINRT)
+SDL_EGL_MakeCurrent_impl(WINRT)
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/video/winrt/SDL_winrtopengles.h b/src/video/winrt/SDL_winrtopengles.h
new file mode 100644
index 0000000..5c52e0c
--- /dev/null
+++ b/src/video/winrt/SDL_winrtopengles.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef _SDL_winrtopengles_h
+#define _SDL_winrtopengles_h
+
+#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl.h"
+
+/* OpenGLES functions */
+#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
+#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
+
+extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window);
+extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* _SDL_winrtopengles_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index c0b75c0..97358a9 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -42,6 +42,7 @@ extern "C" {
#include "../../events/SDL_events_c.h"
#include "../../render/SDL_sysrender.h"
#include "SDL_syswm.h"
+#include "SDL_winrtopengles.h"
}
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
@@ -111,6 +112,17 @@ WINRT_CreateDevice(int devindex)
device->SetDisplayMode = WINRT_SetDisplayMode;
device->PumpEvents = WINRT_PumpEvents;
device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
+#ifdef SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
+ device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
+ device->GL_CreateContext = WINRT_GLES_CreateContext;
+ device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
+ device->GL_SwapWindow = WINRT_GLES_SwapWindow;
+ device->GL_DeleteContext = WINRT_GLES_DeleteContext;
+#endif
device->free = WINRT_DeleteDevice;
WINRT_GlobalSDLVideoDevice = device;
@@ -247,6 +259,22 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
data->coreWindow = CoreWindow::GetForCurrentThread();
}
+#if SDL_VIDEO_OPENGL_EGL
+ /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ /* OpenGL ES 2 wasn't requested. Don't set up an EGL surface. */
+ data->egl_surface = EGL_NO_SURFACE;
+ } else {
+ /* OpenGL ES 2 was reuqested. Set up an EGL surface. */
+ IUnknown * nativeWindow = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
+ data->egl_surface = SDL_EGL_CreateSurface(_this, nativeWindow);
+ if (data->egl_surface == NULL) {
+ // TODO, WinRT: see if SDL_EGL_CreateSurface, or its callee(s), sets an error message. If so, attach it to the SDL error.
+ return SDL_SetError("SDL_EGL_CreateSurface failed");
+ }
+ }
+#endif
+
/* Make sure the window is considered to be positioned at {0,0},
and is considered fullscreen, shown, and the like.
*/
@@ -259,6 +287,12 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
SDL_WINDOW_MAXIMIZED |
SDL_WINDOW_INPUT_GRABBED;
+#if SDL_VIDEO_OPENGL_EGL
+ if (data->egl_surface) {
+ window->flags |= SDL_WINDOW_OPENGL;
+ }
+#endif
+
/* WinRT does not, as of this writing, appear to support app-adjustable
window sizes. Set the window size to whatever the native WinRT
CoreWindow is set at.
diff --git a/src/video/winrt/SDL_winrtvideo_cpp.h b/src/video/winrt/SDL_winrtvideo_cpp.h
index a36cc30..f3900ac 100644
--- a/src/video/winrt/SDL_winrtvideo_cpp.h
+++ b/src/video/winrt/SDL_winrtvideo_cpp.h
@@ -26,8 +26,14 @@
#endif
/* SDL includes: */
+#include "SDL_video.h"
#include "SDL_events.h"
+extern "C" {
+#include "../SDL_sysvideo.h"
+#include "SDL_winrtegl.h"
+}
+
/* The global, WinRT, SDL Window.
For now, SDL/WinRT only supports one window (due to platform limitations of
@@ -49,6 +55,9 @@ struct SDL_WindowData
{
SDL_Window *sdlWindow;
Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
+#ifdef SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
};
#endif // ifdef __cplusplus_winrt