Browse Source

Fixed compiler errors in the D3D11 renderer when building for WinRT

Still TODO: fix other build errors, especially linker errors, when building
SDL/WinRT, then fix any runtime errors that pop up.
David Ludwig 11 years ago
parent
commit
36e7c8d92d

+ 9 - 0
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj

@@ -97,6 +97,14 @@
     <ClCompile Include="..\..\src\joystick\winrt\SDL_xinputjoystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.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\render\opengles2\SDL_render_gles2.c" />
     <ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
     <ClCompile Include="..\..\src\render\SDL_render.c" />
@@ -277,6 +285,7 @@
     <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\opengles2\SDL_gles2funcs.h" />
     <ClInclude Include="..\..\src\render\opengles2\SDL_shaders_gles2.h" />

+ 6 - 0
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters

@@ -280,6 +280,9 @@
     <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\begin_code.h">
@@ -636,6 +639,9 @@
     <ClInclude Include="..\..\src\SDL_internal.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Header Files">

+ 28 - 93
src/render/direct3d11/SDL_render_d3d11.c

@@ -22,18 +22,6 @@
 
 #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
 
-#ifdef __WINRT__
-#include <windows.ui.core.h>
-#include <windows.foundation.h>
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-#include <windows.ui.xaml.media.dxinterop.h>
-#endif
-
-using namespace Windows::UI::Core;
-using namespace Windows::Graphics::Display;
-#endif  /* __WINRT__ */
-
 #define COBJMACROS
 #include "../../core/windows/SDL_windows.h"
 #include "SDL_hints.h"
@@ -45,6 +33,19 @@ using namespace Windows::Graphics::Display;
 #include <d3d11_1.h>
 
 
+#ifdef __WINRT__
+
+#include "SDL_render_d3d11_winrthelpers_cpp.h"
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
+extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
+#endif  /* WINAPI_FAMILY == WINAPI_FAMILY_APP */
+
+#endif  /* __WINRT__ */
+
+
 #define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
 
 
@@ -960,10 +961,11 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
     D3D11_SAMPLER_DESC samplerDesc;
     D3D11_RASTERIZER_DESC rasterDesc;
 
-#ifdef __WINRT__
-    CreateDXGIFactoryFunc = CreateDXGIFactory;
-    D3D11CreateDeviceFunc = D3D11CreateDevice;
-#else
+    // TODO, WinRT, Mar 11, 2014: once SDL/WinRT is back up and running, see if D3D11 init functions are loadable (via LoadPackagedLibrary/SDL_LoadObject, etc.)
+//#ifdef __WINRT__
+//    CreateDXGIFactoryFunc = CreateDXGIFactory;
+//    D3D11CreateDeviceFunc = D3D11CreateDevice;
+//#else
     data->hDXGIMod = SDL_LoadObject("dxgi.dll");
     if (!data->hDXGIMod) {
         result = E_FAIL;
@@ -987,7 +989,7 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
         result = E_FAIL;
         goto done;
     }
-#endif /* __WINRT__ */
+//#endif /* __WINRT__ */
 
     result = CreateDXGIFactoryFunc(&IID_IDXGIFactory2, &data->dxgiFactory);
     if (FAILED(result)) {
@@ -1269,79 +1271,7 @@ done:
     return result;
 }
 
-#ifdef __WINRT__
-
-#if WINAPI_FAMILY == WINAPI_FAMILY_APP
-/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
-extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
-#endif
-
-static IUnknown *
-D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
-{
-    SDL_Window * sdlWindow = renderer->window;
-    if (!renderer->window) {
-        return NULL;
-    }
-
-    SDL_SysWMinfo sdlWindowInfo;
-    SDL_VERSION(&sdlWindowInfo.version);
-    if (!SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo)) {
-        return NULL;
-    }
-
-    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
-        return NULL;
-    }
-
-    if (!sdlWindowInfo.info.winrt.window) {
-        return NULL;
-    }
-
-    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
-    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
-        return NULL;
-    }
-
-    IUnknown *coreWindowAsIUnknown = NULL;
-    coreWindow->QueryInterface(&coreWindowAsIUnknown);
-    coreWindow->Release();
-
-    return coreWindowAsIUnknown;
-}
-
-static DXGI_MODE_ROTATION
-D3D11_GetCurrentRotation()
-{
-    switch (DisplayProperties::CurrentOrientation) {
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
-        /* Windows Phone rotations */
-    case DisplayOrientations::Landscape:
-        return DXGI_MODE_ROTATION_ROTATE90;
-    case DisplayOrientations::Portrait:
-        return DXGI_MODE_ROTATION_IDENTITY;
-    case DisplayOrientations::LandscapeFlipped:
-        return DXGI_MODE_ROTATION_ROTATE270;
-    case DisplayOrientations::PortraitFlipped:
-        return DXGI_MODE_ROTATION_ROTATE180;
-#else
-        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
-    case DisplayOrientations::Landscape:
-        return DXGI_MODE_ROTATION_IDENTITY;
-    case DisplayOrientations::Portrait:
-        return DXGI_MODE_ROTATION_ROTATE270;
-    case DisplayOrientations::LandscapeFlipped:
-        return DXGI_MODE_ROTATION_ROTATE180;
-    case DisplayOrientations::PortraitFlipped:
-        return DXGI_MODE_ROTATION_ROTATE90;
-#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
-
-    default:
-        return DXGI_MODE_ROTATION_UNSPECIFIED;
-    }
-}
-
-#else
+#ifdef __WIN32__
 
 static DXGI_MODE_ROTATION
 D3D11_GetCurrentRotation()
@@ -1350,7 +1280,7 @@ D3D11_GetCurrentRotation()
     return DXGI_MODE_ROTATION_IDENTITY;
 }
 
-#endif /* __WINRT__ */
+#endif /* __WIN32__ */
 
 static BOOL
 D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
@@ -1460,7 +1390,7 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
         }
 
 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
-        result = WINRT_GlobalSwapChainBackgroundPanelNative->SetSwapChain(data->swapChain);
+        result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain);
         if (FAILED(result)) {
             WIN_SetErrorFromHRESULT(__FUNCTION__ ", ISwapChainBackgroundPanelNative::SetSwapChain", result);
             goto done;
@@ -1471,6 +1401,7 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
         goto done;
 #endif
     } else {
+#ifdef __WIN32__
         SDL_SysWMinfo windowinfo;
         SDL_VERSION(&windowinfo.version);
         SDL_GetWindowWMInfo(renderer->window, &windowinfo);
@@ -1487,6 +1418,10 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
             WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForHwnd", result);
             goto done;
         }
+#else
+        SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to");
+        goto done;
+#endif  /* ifdef __WIN32__ / else */
     }
     data->swapEffect = swapChainDesc.SwapEffect;
 
@@ -2379,7 +2314,7 @@ static void
 D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
 {
     D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
-    ID3D11BlendState *blendState;
+    ID3D11BlendState *blendState = NULL;
     switch (blendMode) {
     case SDL_BLENDMODE_BLEND:
         blendState = rendererData->blendModeBlend;

+ 109 - 0
src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp

@@ -0,0 +1,109 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2012 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"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_syswm.h"
+extern "C" {
+#include "../SDL_sysrender.h"
+}
+
+#include <windows.ui.core.h>
+#include <windows.foundation.h>
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+#endif
+
+using namespace Windows::UI::Core;
+using namespace Windows::Graphics::Display;
+
+
+extern "C" void *
+D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
+{
+    SDL_Window * sdlWindow = renderer->window;
+    if ( ! renderer->window ) {
+        return NULL;
+    }
+
+    SDL_SysWMinfo sdlWindowInfo;
+    SDL_VERSION(&sdlWindowInfo.version);
+    if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
+        return NULL;
+    }
+
+    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
+        return NULL;
+    }
+
+    if (!sdlWindowInfo.info.winrt.window) {
+        return NULL;
+    }
+
+    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
+    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
+        return NULL;
+    }
+
+    IUnknown *coreWindowAsIUnknown = NULL;
+    coreWindow->QueryInterface(&coreWindowAsIUnknown);
+    coreWindow->Release();
+
+    return coreWindowAsIUnknown;
+}
+
+extern "C" DXGI_MODE_ROTATION
+D3D11_GetCurrentRotation()
+{
+    switch (DisplayProperties::CurrentOrientation) {
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+        /* Windows Phone rotations */
+        case DisplayOrientations::Landscape:
+            return DXGI_MODE_ROTATION_ROTATE90;
+        case DisplayOrientations::Portrait:
+            return DXGI_MODE_ROTATION_IDENTITY;
+        case DisplayOrientations::LandscapeFlipped:
+            return DXGI_MODE_ROTATION_ROTATE270;
+        case DisplayOrientations::PortraitFlipped:
+            return DXGI_MODE_ROTATION_ROTATE180;
+#else
+        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
+        case DisplayOrientations::Landscape:
+            return DXGI_MODE_ROTATION_IDENTITY;
+        case DisplayOrientations::Portrait:
+            return DXGI_MODE_ROTATION_ROTATE270;
+        case DisplayOrientations::LandscapeFlipped:
+            return DXGI_MODE_ROTATION_ROTATE180;
+        case DisplayOrientations::PortraitFlipped:
+            return DXGI_MODE_ROTATION_ROTATE90;
+#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
+
+    default:
+        return DXGI_MODE_ROTATION_UNSPECIFIED;
+    }
+}
+
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 40 - 0
src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h

@@ -0,0 +1,40 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2012 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"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_render.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
+DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */