Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
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 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj
index cb4fab6..b28a75b 100644
--- a/VisualC/SDL/SDL_VS2008.vcproj
+++ b/VisualC/SDL/SDL_VS2008.vcproj
@@ -415,16 +415,12 @@
RelativePath="..\..\include\SDL_cpuinfo.h"
>
</File>
- <File
- RelativePath="..\..\include\\SDL_egl.h"
- >
- </File>
- <File
- RelativePath="..\..\src\video\sdl_egl_c.h"
+ <File
+ RelativePath="..\..\include\SDL_egl.h"
>
</File>
- <File
- RelativePath="..\..\src\video\windows\SDL_windowsopengles.h"
+ <File
+ RelativePath="..\..\src\video\sdl_egl_c.h"
>
</File>
<File
@@ -587,6 +583,10 @@
RelativePath="..\..\include\SDL_video.h"
>
</File>
+ <File
+ RelativePath="..\..\src\video\windows\SDL_windowsopengles.h"
+ >
+ </File>
</Filter>
<File
RelativePath="..\..\src\events\blank_cursor.h"
@@ -809,6 +809,14 @@
>
</File>
<File
+ RelativePath="..\..\src\render\SDL_d3dmath.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\render\SDL_d3dmath.h"
+ >
+ </File>
+ <File
RelativePath="..\..\src\audio\directsound\SDL_directsound.c"
>
</File>
@@ -865,6 +873,26 @@
>
</File>
<File
+ RelativePath="..\..\src\dynapi\SDL_dynapi.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\dynapi\SDL_dynapi.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\dynapi\SDL_dynapi_overrides.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\dynapi\SDL_dynapi_procs.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\video\SDL_egl.c"
+ >
+ </File>
+ <File
RelativePath="..\..\src\SDL_error.c"
>
</File>
@@ -1021,11 +1049,11 @@
>
</File>
<File
- RelativePath="..\..\src\render\direct3d11\SDL_render_d3d11.c"
+ RelativePath="..\..\src\render\direct3d\SDL_render_d3d.c"
>
</File>
<File
- RelativePath="..\..\src\render\direct3d\SDL_render_d3d.c"
+ RelativePath="..\..\src\render\direct3d11\SDL_render_d3d11.c"
>
</File>
<File
@@ -1033,6 +1061,10 @@
>
</File>
<File
+ RelativePath="..\..\src\render\opengles2\SDL_render_gles2.c"
+ >
+ </File>
+ <File
RelativePath="..\..\src\render\software\SDL_render_sw.c"
>
</File>
@@ -1069,6 +1101,10 @@
>
</File>
<File
+ RelativePath="..\..\src\render\opengles2\SDL_shaders_gles2.c"
+ >
+ </File>
+ <File
RelativePath="..\..\src\video\SDL_shape.c"
>
</File>
@@ -1149,10 +1185,6 @@
>
</File>
<File
- RelativePath="..\..\src\thread\windows\SDL_systls.c"
- >
- </File>
- <File
RelativePath="..\..\src\thread\SDL_systhread.h"
>
</File>
@@ -1169,6 +1201,10 @@
>
</File>
<File
+ RelativePath="..\..\src\thread\windows\SDL_systls.c"
+ >
+ </File>
+ <File
RelativePath="..\..\src\video\SDL_sysvideo.h"
>
</File>
@@ -1229,22 +1265,6 @@
>
</File>
<File
- RelativePath="..\..\src\dynapi\SDL_dynapi.h"
- >
- </File>
- <File
- RelativePath="..\..\src\dynapi\SDL_dynapi_overrides.h"
- >
- </File>
- <File
- RelativePath="..\..\src\dynapi\SDL_dynapi_procs.h"
- >
- </File>
- <File
- RelativePath="..\..\src\dynapi\SDL_dynapi.c"
- >
- </File>
- <File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
>
</File>
@@ -1305,23 +1325,11 @@
>
</File>
<File
- RelativePath="..\..\src\render\opengles2\SDL_render_gles2.c"
- >
- </File>
- <File
- RelativePath="..\..\src\render\opengles2\SDL_shaders_gles2.c"
- >
- </File>
- <File
- RelativePath="..\..\src\video\SDL_egl.c"
- >
- </File>
- <File
- RelativePath="..\..\src\video\windows\SDL_windowsopengles.c"
+ RelativePath="..\..\src\video\windows\SDL_windowsopengl.h"
>
</File>
<File
- RelativePath="..\..\src\video\windows\SDL_windowsopengl.h"
+ RelativePath="..\..\src\video\windows\SDL_windowsopengles.c"
>
</File>
<File
diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj
index 1beb1f5..e381292 100644
--- a/VisualC/SDL/SDL_VS2010.vcxproj
+++ b/VisualC/SDL/SDL_VS2010.vcxproj
@@ -492,6 +492,7 @@
<ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\render\mmx.h" />
<ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" />
+ <ClInclude Include="..\..\src\render\SDL_d3dmath.h" />
<ClInclude Include="..\..\src\render\SDL_sysrender.h" />
<ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
@@ -585,6 +586,7 @@
<ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" />
+ <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
diff --git a/VisualC/SDL/SDL_VS2012.vcxproj b/VisualC/SDL/SDL_VS2012.vcxproj
index 191641a..d9971ff 100644
--- a/VisualC/SDL/SDL_VS2012.vcxproj
+++ b/VisualC/SDL/SDL_VS2012.vcxproj
@@ -283,6 +283,7 @@
<ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\render\mmx.h" />
<ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" />
+ <ClInclude Include="..\..\src\render\SDL_d3dmath.h" />
<ClInclude Include="..\..\src\render\SDL_sysrender.h" />
<ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
@@ -376,6 +377,7 @@
<ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" />
+ <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
diff --git a/VisualC/SDL/SDL_VS2013.vcxproj b/VisualC/SDL/SDL_VS2013.vcxproj
index e30f199..2ca83e4 100644
--- a/VisualC/SDL/SDL_VS2013.vcxproj
+++ b/VisualC/SDL/SDL_VS2013.vcxproj
@@ -286,6 +286,7 @@
<ClInclude Include="..\..\src\libm\math_private.h" />
<ClInclude Include="..\..\src\render\mmx.h" />
<ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" />
+ <ClInclude Include="..\..\src\render\SDL_d3dmath.h" />
<ClInclude Include="..\..\src\render\SDL_sysrender.h" />
<ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
@@ -380,6 +381,7 @@
<ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" />
<ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" />
+ <ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
diff --git a/src/render/SDL_d3dmath.c b/src/render/SDL_d3dmath.c
new file mode 100644
index 0000000..df1dc0b
--- /dev/null
+++ b/src/render/SDL_d3dmath.c
@@ -0,0 +1,131 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2014 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_internal.h"
+#include "SDL_stdinc.h"
+
+#include "SDL_d3dmath.h"
+
+/* Direct3D matrix math functions */
+
+Float4X4 MatrixIdentity()
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = 1.0f;
+ m._22 = 1.0f;
+ m._33 = 1.0f;
+ m._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
+{
+ Float4X4 m;
+ m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41;
+ m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42;
+ m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43;
+ m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44;
+ m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41;
+ m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42;
+ m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43;
+ m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44;
+ m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41;
+ m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42;
+ m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43;
+ m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44;
+ m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41;
+ m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42;
+ m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43;
+ m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44;
+ return m;
+}
+
+Float4X4 MatrixScaling(float x, float y, float z)
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = x;
+ m._22 = y;
+ m._33 = z;
+ m._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixTranslation(float x, float y, float z)
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = 1.0f;
+ m._22 = 1.0f;
+ m._33 = 1.0f;
+ m._44 = 1.0f;
+ m._41 = x;
+ m._42 = y;
+ m._43 = z;
+ return m;
+}
+
+Float4X4 MatrixRotationX(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = 1.0f;
+ m._22 = cosR;
+ m._23 = sinR;
+ m._32 = -sinR;
+ m._33 = cosR;
+ m._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixRotationY(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = cosR;
+ m._13 = -sinR;
+ m._22 = 1.0f;
+ m._31 = sinR;
+ m._33 = cosR;
+ m._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixRotationZ(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m._11 = cosR;
+ m._12 = sinR;
+ m._21 = -sinR;
+ m._22 = cosR;
+ m._33 = 1.0f;
+ m._44 = 1.0f;
+ return m;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/render/SDL_d3dmath.h b/src/render/SDL_d3dmath.h
new file mode 100644
index 0000000..206c435
--- /dev/null
+++ b/src/render/SDL_d3dmath.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2014 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_internal.h"
+
+
+/* Direct3D matrix math functions */
+
+typedef struct
+{
+ float x;
+ float y;
+} Float2;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+} Float3;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+ float w;
+} Float4;
+
+typedef struct
+{
+ union {
+ struct {
+ float _11, _12, _13, _14;
+ float _21, _22, _23, _24;
+ float _31, _32, _33, _34;
+ float _41, _42, _43, _44;
+ };
+ float m[4][4];
+ };
+} Float4X4;
+
+
+Float4X4 MatrixIdentity();
+Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2);
+Float4X4 MatrixScaling(float x, float y, float z);
+Float4X4 MatrixTranslation(float x, float y, float z);
+Float4X4 MatrixRotationX(float r);
+Float4X4 MatrixRotationY(float r);
+Float4X4 MatrixRotationZ(float r);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 3357ed4..1547668 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -47,12 +47,12 @@
#if !SDL_RENDER_DISABLED
static const SDL_RenderDriver *render_drivers[] = {
-#if SDL_VIDEO_RENDER_D3D11
- &D3D11_RenderDriver,
-#endif
#if SDL_VIDEO_RENDER_D3D
&D3D_RenderDriver,
#endif
+#if SDL_VIDEO_RENDER_D3D11
+ &D3D11_RenderDriver,
+#endif
#if SDL_VIDEO_RENDER_OGL
&GL_RenderDriver,
#endif
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 3ef6d67..2448281 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -31,6 +31,7 @@
#include "SDL_loadso.h"
#include "SDL_syswm.h"
#include "../SDL_sysrender.h"
+#include "../SDL_d3dmath.h"
#include "../../video/windows/SDL_windowsvideo.h"
#if SDL_VIDEO_RENDER_D3D
@@ -39,89 +40,6 @@
#endif
-typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
-typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
-typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
-
-DEFINE_GUID(IID_ID3DXMatrixStack,
-0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
-
-#undef INTERFACE
-#define INTERFACE ID3DXMatrixStack
-
-DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD(Pop)(THIS) PURE;
- STDMETHOD(Push)(THIS) PURE;
- STDMETHOD(LoadIdentity)(THIS) PURE;
- STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
- STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
- STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
- STDMETHOD(RotateAxis)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
- STDMETHOD(RotateAxisLocal)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
- STDMETHOD(RotateYawPitchRoll)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
- STDMETHOD(RotateYawPitchRollLocal)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
- STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
- STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
- STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
- STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
- STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
-};
-
-#undef INTERFACE
-
-#if !defined(__cplusplus) || defined(CINTERFACE)
-#define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
-#define ID3DXMatrixStack_AddRef(p) (p)->lpVtbl->AddRef(p)
-#define ID3DXMatrixStack_Release(p) (p)->lpVtbl->Release(p)
-#define ID3DXMatrixStack_Pop(p) (p)->lpVtbl->Pop(p)
-#define ID3DXMatrixStack_Push(p) (p)->lpVtbl->Push(p)
-#define ID3DXMatrixStack_LoadIdentity(p) (p)->lpVtbl->LoadIdentity(p)
-#define ID3DXMatrixStack_LoadMatrix(p,a) (p)->lpVtbl->LoadMatrix(p,a)
-#define ID3DXMatrixStack_MultMatrix(p,a) (p)->lpVtbl->MultMatrix(p,a)
-#define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->lpVtbl->MultMatrixLocal(p,a)
-#define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->lpVtbl->RotateAxis(p,a,b)
-#define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->lpVtbl->RotateAxisLocal(p,a,b)
-#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
-#define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
-#define ID3DXMatrixStack_Scale(p,a,b,c) (p)->lpVtbl->Scale(p,a,b,c)
-#define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->lpVtbl->ScaleLocal(p,a,b,c)
-#define ID3DXMatrixStack_Translate(p,a,b,c) (p)->lpVtbl->Translate(p,a,b,c)
-#define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->lpVtbl->TranslateLocal(p,a,b,c)
-#define ID3DXMatrixStack_GetTop(p) (p)->lpVtbl->GetTop(p)
-#else
-#define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
-#define ID3DXMatrixStack_AddRef(p) (p)->AddRef()
-#define ID3DXMatrixStack_Release(p) (p)->Release()
-#define ID3DXMatrixStack_Pop(p) (p)->Pop()
-#define ID3DXMatrixStack_Push(p) (p)->Push()
-#define ID3DXMatrixStack_LoadIdentity(p) (p)->LoadIdentity()
-#define ID3DXMatrixStack_LoadMatrix(p,a) (p)->LoadMatrix(a)
-#define ID3DXMatrixStack_MultMatrix(p,a) (p)->MultMatrix(a)
-#define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->MultMatrixLocal(a)
-#define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->RotateAxis(a,b)
-#define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->RotateAxisLocal(a,b)
-#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->RotateYawPitchRollLocal(a,b,c)
-#define ID3DXMatrixStack_Scale(p,a,b,c) (p)->Scale(a,b,c)
-#define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->ScaleLocal(a,b,c)
-#define ID3DXMatrixStack_Translate(p,a,b,c) (p)->Translate(a,b,c)
-#define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->TranslateLocal(a,b,c)
-#define ID3DXMatrixStack_GetTop(p) (p)->GetTop()
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack);
-
-#ifdef __cplusplus
-}
-#endif
-
#ifdef ASSEMBLE_SHADER
/**************************************************************************
* ID3DXBuffer:
@@ -266,7 +184,6 @@ typedef struct
IDirect3DSurface9 *defaultRenderTarget;
IDirect3DSurface9 *currentRenderTarget;
void* d3dxDLL;
- ID3DXMatrixStack *matrixStack;
LPDIRECT3DPIXELSHADER9 ps_yuv;
} D3D_RenderData;
@@ -582,8 +499,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
Uint32 window_flags;
int w, h;
SDL_DisplayMode fullscreen_mode;
- int d3dxVersion;
- char d3dxDLLFile[50];
int displayIndex;
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
@@ -599,29 +514,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}
- if (D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
- for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
- LPTSTR dllName;
- SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion);
- dllName = WIN_UTF8ToString(d3dxDLLFile);
- data->d3dxDLL = (void *)LoadLibrary(dllName); /* not using SDL_LoadObject() as we want silently fail - no error message */
- SDL_free(dllName);
- if (data->d3dxDLL) {
- HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK* ppStack);
- D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack");
- if (D3DXCreateMatrixStack) {
- D3DXCreateMatrixStack(0, &data->matrixStack);
- break;
- }
- }
- }
-
- if (!data->matrixStack) {
- if (data->d3dxDLL) SDL_UnloadObject(data->d3dxDLL);
- }
- }
-
- if (!data->d3d || !data->matrixStack) {
+ if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
SDL_free(renderer);
SDL_free(data);
SDL_SetError("Unable to create Direct3D interface");
@@ -1697,6 +1590,7 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
float centerx, centery;
DWORD color;
Vertex vertices[4];
+ Float4X4 modelMatrix;
HRESULT result;
if (D3D_ActivateRenderer(renderer) < 0) {
@@ -1768,11 +1662,11 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_SetBlendMode(data, texture->blendMode);
/* Rotate and translate */
- ID3DXMatrixStack_Push(data->matrixStack);
- ID3DXMatrixStack_LoadIdentity(data->matrixStack);
- ID3DXMatrixStack_RotateYawPitchRoll(data->matrixStack, 0.0, 0.0, (float)(M_PI * (float) angle / 180.0f));
- ID3DXMatrixStack_Translate(data->matrixStack, (float)dstrect->x + centerx, (float)dstrect->y + centery, (float)0.0);
- IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)ID3DXMatrixStack_GetTop(data->matrixStack));
+ modelMatrix = MatrixMultiply(
+ MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
+ MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
+ );
+ IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
D3D_UpdateTextureScaleMode(data, texturedata, 0);
@@ -1822,11 +1716,9 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
return D3D_SetError("SetShader()", result);
}
}
- ID3DXMatrixStack_Pop(data->matrixStack);
- ID3DXMatrixStack_Push(data->matrixStack);
- ID3DXMatrixStack_LoadIdentity(data->matrixStack);
- IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)ID3DXMatrixStack_GetTop(data->matrixStack));
- ID3DXMatrixStack_Pop(data->matrixStack);
+
+ modelMatrix = MatrixIdentity();
+ IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
return 0;
}
@@ -1960,7 +1852,6 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
}
if (data->d3d) {
IDirect3D9_Release(data->d3d);
- ID3DXMatrixStack_Release(data->matrixStack);
SDL_UnloadObject(data->d3dDLL);
}
SDL_free(data);
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 548ab18..b9b3a3c 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -40,45 +40,13 @@ using namespace Windows::Graphics::Display;
#include "SDL_loadso.h"
#include "SDL_syswm.h"
#include "../SDL_sysrender.h"
+#include "../SDL_d3dmath.h"
#include <d3d11_1.h>
#define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
-typedef struct
-{
- float x;
- float y;
-} Float2;
-
-typedef struct
-{
- float x;
- float y;
- float z;
-} Float3;
-
-typedef struct
-{
- float x;
- float y;
- float z;
- float w;
-} Float4;
-
-typedef struct
-{
- union {
- struct {
- float _11, _12, _13, _14;
- float _21, _22, _23, _24;
- float _31, _32, _33, _34;
- float _41, _42, _43, _44;
- };
- float m[4][4];
- };
-} Float4X4;
/* Vertex shader, common values */
typedef struct
@@ -717,112 +685,6 @@ static const DWORD D3D11_VertexShader[] = {
#error "An appropriate vertex shader is not defined."
#endif
-/* Direct3D matrix math functions */
-
-static Float4X4 MatrixIdentity()
-{
- Float4X4 m;
- SDL_zero(m);
- m._11 = 1.0f;
- m._22 = 1.0f;
- m._33 = 1.0f;
- m._44 = 1.0f;
- return m;
-}
-
-static Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
-{
- Float4X4 m;
- SDL_zero(m);
- m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41;
- m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42;
- m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43;
- m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44;
- m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41;
- m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42;
- m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43;
- m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44;
- m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41;
- m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42;
- m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43;
- m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44;
- m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41;
- m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42;
- m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43;
- m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44;
- return m;
-}
-
-static Float4X4 MatrixScaling(float x, float y, float z)
-{
- Float4X4 m;
- SDL_zero(m);
- m._11 = x;
- m._22 = y;
- m._33 = z;
- m._44 = 1.0f;
- return m;
-}
-
-static Float4X4 MatrixTranslation(float x, float y, float z)
-{
- Float4X4 m;
- SDL_zero(m);
- m._11 = 1.0f;
- m._22 = 1.0f;
- m._33 = 1.0f;
- m._44 = 1.0f;
- m._41 = x;
- m._42 = y;
- m._43 = z;
- return m;
-}
-
-static Float4X4 MatrixRotationX(float r)
-{
- float sinR = SDL_sinf(r);
- float cosR = SDL_cosf(r);
- Float4X4 m;
- SDL_zero(m);
- m._11 = 1.0f;
- m._22 = cosR;
- m._23 = sinR;
- m._32 = -sinR;
- m._33 = cosR;
- m._44 = 1.0f;
- return m;
-}
-
-static Float4X4 MatrixRotationY(float r)
-{
- float sinR = SDL_sinf(r);
- float cosR = SDL_cosf(r);
- Float4X4 m;
- SDL_zero(m);
- m._11 = cosR;
- m._13 = -sinR;
- m._22 = 1.0f;
- m._31 = sinR;
- m._33 = cosR;
- m._44 = 1.0f;
- return m;
-}
-
-static Float4X4 MatrixRotationZ(float r)
-{
- float sinR = SDL_sinf(r);
- float cosR = SDL_cosf(r);
- Float4X4 m;
- SDL_zero(m);
- m._11 = cosR;
- m._12 = sinR;
- m._21 = -sinR;
- m._22 = cosR;
- m._33 = 1.0f;
- m._44 = 1.0f;
- return m;
-}
-
/* Direct3D 11.1 renderer implementation */
static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
@@ -2803,12 +2665,11 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
minv = tmp;
}
- Float4X4 oldModelMatrix = rendererData->vertexShaderConstantsData.model;
- Float4X4 newModelMatrix = MatrixMultiply(
+ Float4X4 modelMatrix = MatrixMultiply(
MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
);
- D3D11_SetModelMatrix(renderer, &newModelMatrix);
+ D3D11_SetModelMatrix(renderer, &modelMatrix);
const float minx = -center->x;
const float maxx = dstrect->w - center->x;
@@ -2849,7 +2710,7 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
- D3D11_SetModelMatrix(renderer, &oldModelMatrix);
+ D3D11_SetModelMatrix(renderer, NULL);
return 0;
}