Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
authorSam Lantinga <slouken@libsdl.org>
Mon, 10 Mar 2014 17:19:19 -0700
changeset 8599 532cd234e923
parent 8598 2e6b94600850
child 8600 092802455aed
Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
VisualC/SDL/SDL_VS2012.vcxproj
VisualC/SDL/SDL_VS2013.vcxproj
src/render/SDL_d3dmath.c
src/render/SDL_d3dmath.h
src/render/SDL_render.c
src/render/direct3d/SDL_render_d3d.c
src/render/direct3d11/SDL_render_d3d11.c
--- a/VisualC/SDL/SDL_VS2008.vcproj	Mon Mar 10 15:00:59 2014 -0700
+++ b/VisualC/SDL/SDL_VS2008.vcproj	Mon Mar 10 17:19:19 2014 -0700
@@ -415,16 +415,12 @@
 				RelativePath="..\..\include\SDL_cpuinfo.h"
 				>
 			</File>
-			<File 
-				RelativePath="..\..\include\\SDL_egl.h" 
+			<File
+				RelativePath="..\..\include\SDL_egl.h"
 				>
 			</File>
-			<File 
-				RelativePath="..\..\src\video\sdl_egl_c.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,15 +1049,19 @@
 			>
 		</File>
 		<File
+			RelativePath="..\..\src\render\direct3d\SDL_render_d3d.c"
+			>
+		</File>
+		<File
 			RelativePath="..\..\src\render\direct3d11\SDL_render_d3d11.c"
 			>
 		</File>
 		<File
-			RelativePath="..\..\src\render\direct3d\SDL_render_d3d.c"
+			RelativePath="..\..\src\render\opengl\SDL_render_gl.c"
 			>
 		</File>
 		<File
-			RelativePath="..\..\src\render\opengl\SDL_render_gl.c"
+			RelativePath="..\..\src\render\opengles2\SDL_render_gles2.c"
 			>
 		</File>
 		<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
--- a/VisualC/SDL/SDL_VS2010.vcxproj	Mon Mar 10 15:00:59 2014 -0700
+++ b/VisualC/SDL/SDL_VS2010.vcxproj	Mon Mar 10 17:19:19 2014 -0700
@@ -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" />
--- a/VisualC/SDL/SDL_VS2012.vcxproj	Mon Mar 10 15:00:59 2014 -0700
+++ b/VisualC/SDL/SDL_VS2012.vcxproj	Mon Mar 10 17:19:19 2014 -0700
@@ -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" />
--- a/VisualC/SDL/SDL_VS2013.vcxproj	Mon Mar 10 15:00:59 2014 -0700
+++ b/VisualC/SDL/SDL_VS2013.vcxproj	Mon Mar 10 17:19:19 2014 -0700
@@ -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" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/SDL_d3dmath.c	Mon Mar 10 17:19:19 2014 -0700
@@ -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: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/SDL_d3dmath.h	Mon Mar 10 17:19:19 2014 -0700
@@ -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: */
--- a/src/render/SDL_render.c	Mon Mar 10 15:00:59 2014 -0700
+++ b/src/render/SDL_render.c	Mon Mar 10 17:19:19 2014 -0700
@@ -47,12 +47,12 @@
 
 #if !SDL_RENDER_DISABLED
 static const SDL_RenderDriver *render_drivers[] = {
+#if SDL_VIDEO_RENDER_D3D
+    &D3D_RenderDriver,
+#endif
 #if SDL_VIDEO_RENDER_D3D11
     &D3D11_RenderDriver,
 #endif
-#if SDL_VIDEO_RENDER_D3D
-    &D3D_RenderDriver,
-#endif
 #if SDL_VIDEO_RENDER_OGL
     &GL_RenderDriver,
 #endif
--- a/src/render/direct3d/SDL_render_d3d.c	Mon Mar 10 15:00:59 2014 -0700
+++ b/src/render/direct3d/SDL_render_d3d.c	Mon Mar 10 17:19:19 2014 -0700
@@ -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 @@
     IDirect3DSurface9 *defaultRenderTarget;
     IDirect3DSurface9 *currentRenderTarget;
     void* d3dxDLL;
-    ID3DXMatrixStack *matrixStack;
     LPDIRECT3DPIXELSHADER9 ps_yuv;
 } D3D_RenderData;
 
@@ -582,8 +499,6 @@
     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 @@
         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 @@
     float centerx, centery;
     DWORD color;
     Vertex vertices[4];
+    Float4X4 modelMatrix;
     HRESULT result;
 
     if (D3D_ActivateRenderer(renderer) < 0) {
@@ -1768,11 +1662,11 @@
     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 @@
             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 @@
         }
         if (data->d3d) {
             IDirect3D9_Release(data->d3d);
-            ID3DXMatrixStack_Release(data->matrixStack);
             SDL_UnloadObject(data->d3dDLL);
         }
         SDL_free(data);
--- a/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 10 15:00:59 2014 -0700
+++ b/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 10 17:19:19 2014 -0700
@@ -40,45 +40,13 @@
 #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 @@
 #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 @@
         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_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
 
-    D3D11_SetModelMatrix(renderer, &oldModelMatrix);
+    D3D11_SetModelMatrix(renderer, NULL);
 
     return 0;
 }