Fixed compiler errors in the D3D11 renderer when building for WinRT
authorDavid Ludwig <dludwig@pobox.com>
Tue, 11 Mar 2014 12:40:31 -0400
changeset 8608c5d603f7094e
parent 8607 ef23c9d08eed
child 8609 d59f0f12bf07
child 8611 a762dfc67e1a
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.
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
src/render/direct3d11/SDL_render_d3d11.c
src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp
src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h
     1.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Mon Mar 10 22:53:03 2014 -0400
     1.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Tue Mar 11 12:40:31 2014 -0400
     1.3 @@ -97,6 +97,14 @@
     1.4      <ClCompile Include="..\..\src\joystick\winrt\SDL_xinputjoystick.c" />
     1.5      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     1.6      <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
     1.7 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.cpp">
     1.8 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     1.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.14 +    </ClCompile>
    1.15      <ClCompile Include="..\..\src\render\opengles2\SDL_render_gles2.c" />
    1.16      <ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
    1.17      <ClCompile Include="..\..\src\render\SDL_render.c" />
    1.18 @@ -277,6 +285,7 @@
    1.19      <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
    1.20      <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
    1.21      <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
    1.22 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h" />
    1.23      <ClInclude Include="..\..\src\render\mmx.h" />
    1.24      <ClInclude Include="..\..\src\render\opengles2\SDL_gles2funcs.h" />
    1.25      <ClInclude Include="..\..\src\render\opengles2\SDL_shaders_gles2.h" />
     2.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Mon Mar 10 22:53:03 2014 -0400
     2.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Tue Mar 11 12:40:31 2014 -0400
     2.3 @@ -280,6 +280,9 @@
     2.4      <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClCompile>
     2.7 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers.cpp">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClCompile>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClInclude Include="..\..\include\begin_code.h">
    2.13 @@ -636,6 +639,9 @@
    2.14      <ClInclude Include="..\..\src\SDL_internal.h">
    2.15        <Filter>Source Files</Filter>
    2.16      </ClInclude>
    2.17 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_winrthelpers_cpp.h">
    2.18 +      <Filter>Source Files</Filter>
    2.19 +    </ClInclude>
    2.20    </ItemGroup>
    2.21    <ItemGroup>
    2.22      <Filter Include="Header Files">
     3.1 --- a/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 10 22:53:03 2014 -0400
     3.2 +++ b/src/render/direct3d11/SDL_render_d3d11.c	Tue Mar 11 12:40:31 2014 -0400
     3.3 @@ -22,18 +22,6 @@
     3.4  
     3.5  #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
     3.6  
     3.7 -#ifdef __WINRT__
     3.8 -#include <windows.ui.core.h>
     3.9 -#include <windows.foundation.h>
    3.10 -
    3.11 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    3.12 -#include <windows.ui.xaml.media.dxinterop.h>
    3.13 -#endif
    3.14 -
    3.15 -using namespace Windows::UI::Core;
    3.16 -using namespace Windows::Graphics::Display;
    3.17 -#endif  /* __WINRT__ */
    3.18 -
    3.19  #define COBJMACROS
    3.20  #include "../../core/windows/SDL_windows.h"
    3.21  #include "SDL_hints.h"
    3.22 @@ -45,6 +33,19 @@
    3.23  #include <d3d11_1.h>
    3.24  
    3.25  
    3.26 +#ifdef __WINRT__
    3.27 +
    3.28 +#include "SDL_render_d3d11_winrthelpers_cpp.h"
    3.29 +
    3.30 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    3.31 +#include <windows.ui.xaml.media.dxinterop.h>
    3.32 +/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
    3.33 +extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
    3.34 +#endif  /* WINAPI_FAMILY == WINAPI_FAMILY_APP */
    3.35 +
    3.36 +#endif  /* __WINRT__ */
    3.37 +
    3.38 +
    3.39  #define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
    3.40  
    3.41  
    3.42 @@ -960,10 +961,11 @@
    3.43      D3D11_SAMPLER_DESC samplerDesc;
    3.44      D3D11_RASTERIZER_DESC rasterDesc;
    3.45  
    3.46 -#ifdef __WINRT__
    3.47 -    CreateDXGIFactoryFunc = CreateDXGIFactory;
    3.48 -    D3D11CreateDeviceFunc = D3D11CreateDevice;
    3.49 -#else
    3.50 +    // 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.)
    3.51 +//#ifdef __WINRT__
    3.52 +//    CreateDXGIFactoryFunc = CreateDXGIFactory;
    3.53 +//    D3D11CreateDeviceFunc = D3D11CreateDevice;
    3.54 +//#else
    3.55      data->hDXGIMod = SDL_LoadObject("dxgi.dll");
    3.56      if (!data->hDXGIMod) {
    3.57          result = E_FAIL;
    3.58 @@ -987,7 +989,7 @@
    3.59          result = E_FAIL;
    3.60          goto done;
    3.61      }
    3.62 -#endif /* __WINRT__ */
    3.63 +//#endif /* __WINRT__ */
    3.64  
    3.65      result = CreateDXGIFactoryFunc(&IID_IDXGIFactory2, &data->dxgiFactory);
    3.66      if (FAILED(result)) {
    3.67 @@ -1269,79 +1271,7 @@
    3.68      return result;
    3.69  }
    3.70  
    3.71 -#ifdef __WINRT__
    3.72 -
    3.73 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    3.74 -/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
    3.75 -extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
    3.76 -#endif
    3.77 -
    3.78 -static IUnknown *
    3.79 -D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
    3.80 -{
    3.81 -    SDL_Window * sdlWindow = renderer->window;
    3.82 -    if (!renderer->window) {
    3.83 -        return NULL;
    3.84 -    }
    3.85 -
    3.86 -    SDL_SysWMinfo sdlWindowInfo;
    3.87 -    SDL_VERSION(&sdlWindowInfo.version);
    3.88 -    if (!SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo)) {
    3.89 -        return NULL;
    3.90 -    }
    3.91 -
    3.92 -    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
    3.93 -        return NULL;
    3.94 -    }
    3.95 -
    3.96 -    if (!sdlWindowInfo.info.winrt.window) {
    3.97 -        return NULL;
    3.98 -    }
    3.99 -
   3.100 -    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
   3.101 -    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
   3.102 -        return NULL;
   3.103 -    }
   3.104 -
   3.105 -    IUnknown *coreWindowAsIUnknown = NULL;
   3.106 -    coreWindow->QueryInterface(&coreWindowAsIUnknown);
   3.107 -    coreWindow->Release();
   3.108 -
   3.109 -    return coreWindowAsIUnknown;
   3.110 -}
   3.111 -
   3.112 -static DXGI_MODE_ROTATION
   3.113 -D3D11_GetCurrentRotation()
   3.114 -{
   3.115 -    switch (DisplayProperties::CurrentOrientation) {
   3.116 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   3.117 -        /* Windows Phone rotations */
   3.118 -    case DisplayOrientations::Landscape:
   3.119 -        return DXGI_MODE_ROTATION_ROTATE90;
   3.120 -    case DisplayOrientations::Portrait:
   3.121 -        return DXGI_MODE_ROTATION_IDENTITY;
   3.122 -    case DisplayOrientations::LandscapeFlipped:
   3.123 -        return DXGI_MODE_ROTATION_ROTATE270;
   3.124 -    case DisplayOrientations::PortraitFlipped:
   3.125 -        return DXGI_MODE_ROTATION_ROTATE180;
   3.126 -#else
   3.127 -        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
   3.128 -    case DisplayOrientations::Landscape:
   3.129 -        return DXGI_MODE_ROTATION_IDENTITY;
   3.130 -    case DisplayOrientations::Portrait:
   3.131 -        return DXGI_MODE_ROTATION_ROTATE270;
   3.132 -    case DisplayOrientations::LandscapeFlipped:
   3.133 -        return DXGI_MODE_ROTATION_ROTATE180;
   3.134 -    case DisplayOrientations::PortraitFlipped:
   3.135 -        return DXGI_MODE_ROTATION_ROTATE90;
   3.136 -#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
   3.137 -
   3.138 -    default:
   3.139 -        return DXGI_MODE_ROTATION_UNSPECIFIED;
   3.140 -    }
   3.141 -}
   3.142 -
   3.143 -#else
   3.144 +#ifdef __WIN32__
   3.145  
   3.146  static DXGI_MODE_ROTATION
   3.147  D3D11_GetCurrentRotation()
   3.148 @@ -1350,7 +1280,7 @@
   3.149      return DXGI_MODE_ROTATION_IDENTITY;
   3.150  }
   3.151  
   3.152 -#endif /* __WINRT__ */
   3.153 +#endif /* __WIN32__ */
   3.154  
   3.155  static BOOL
   3.156  D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
   3.157 @@ -1460,7 +1390,7 @@
   3.158          }
   3.159  
   3.160  #if WINAPI_FAMILY == WINAPI_FAMILY_APP
   3.161 -        result = WINRT_GlobalSwapChainBackgroundPanelNative->SetSwapChain(data->swapChain);
   3.162 +        result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain);
   3.163          if (FAILED(result)) {
   3.164              WIN_SetErrorFromHRESULT(__FUNCTION__ ", ISwapChainBackgroundPanelNative::SetSwapChain", result);
   3.165              goto done;
   3.166 @@ -1471,6 +1401,7 @@
   3.167          goto done;
   3.168  #endif
   3.169      } else {
   3.170 +#ifdef __WIN32__
   3.171          SDL_SysWMinfo windowinfo;
   3.172          SDL_VERSION(&windowinfo.version);
   3.173          SDL_GetWindowWMInfo(renderer->window, &windowinfo);
   3.174 @@ -1487,6 +1418,10 @@
   3.175              WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory2::CreateSwapChainForHwnd", result);
   3.176              goto done;
   3.177          }
   3.178 +#else
   3.179 +        SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to");
   3.180 +        goto done;
   3.181 +#endif  /* ifdef __WIN32__ / else */
   3.182      }
   3.183      data->swapEffect = swapChainDesc.SwapEffect;
   3.184  
   3.185 @@ -2379,7 +2314,7 @@
   3.186  D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
   3.187  {
   3.188      D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
   3.189 -    ID3D11BlendState *blendState;
   3.190 +    ID3D11BlendState *blendState = NULL;
   3.191      switch (blendMode) {
   3.192      case SDL_BLENDMODE_BLEND:
   3.193          blendState = rendererData->blendModeBlend;
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers.cpp	Tue Mar 11 12:40:31 2014 -0400
     4.3 @@ -0,0 +1,109 @@
     4.4 +/*
     4.5 +  Simple DirectMedia Layer
     4.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4.7 +
     4.8 +  This software is provided 'as-is', without any express or implied
     4.9 +  warranty.  In no event will the authors be held liable for any damages
    4.10 +  arising from the use of this software.
    4.11 +
    4.12 +  Permission is granted to anyone to use this software for any purpose,
    4.13 +  including commercial applications, and to alter it and redistribute it
    4.14 +  freely, subject to the following restrictions:
    4.15 +
    4.16 +  1. The origin of this software must not be misrepresented; you must not
    4.17 +     claim that you wrote the original software. If you use this software
    4.18 +     in a product, an acknowledgment in the product documentation would be
    4.19 +     appreciated but is not required.
    4.20 +  2. Altered source versions must be plainly marked as such, and must not be
    4.21 +     misrepresented as being the original software.
    4.22 +  3. This notice may not be removed or altered from any source distribution.
    4.23 +*/
    4.24 +#include "../../SDL_internal.h"
    4.25 +
    4.26 +#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
    4.27 +
    4.28 +#include "SDL_syswm.h"
    4.29 +extern "C" {
    4.30 +#include "../SDL_sysrender.h"
    4.31 +}
    4.32 +
    4.33 +#include <windows.ui.core.h>
    4.34 +#include <windows.foundation.h>
    4.35 +
    4.36 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    4.37 +#include <windows.ui.xaml.media.dxinterop.h>
    4.38 +#endif
    4.39 +
    4.40 +using namespace Windows::UI::Core;
    4.41 +using namespace Windows::Graphics::Display;
    4.42 +
    4.43 +
    4.44 +extern "C" void *
    4.45 +D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
    4.46 +{
    4.47 +    SDL_Window * sdlWindow = renderer->window;
    4.48 +    if ( ! renderer->window ) {
    4.49 +        return NULL;
    4.50 +    }
    4.51 +
    4.52 +    SDL_SysWMinfo sdlWindowInfo;
    4.53 +    SDL_VERSION(&sdlWindowInfo.version);
    4.54 +    if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
    4.55 +        return NULL;
    4.56 +    }
    4.57 +
    4.58 +    if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
    4.59 +        return NULL;
    4.60 +    }
    4.61 +
    4.62 +    if (!sdlWindowInfo.info.winrt.window) {
    4.63 +        return NULL;
    4.64 +    }
    4.65 +
    4.66 +    ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
    4.67 +    if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
    4.68 +        return NULL;
    4.69 +    }
    4.70 +
    4.71 +    IUnknown *coreWindowAsIUnknown = NULL;
    4.72 +    coreWindow->QueryInterface(&coreWindowAsIUnknown);
    4.73 +    coreWindow->Release();
    4.74 +
    4.75 +    return coreWindowAsIUnknown;
    4.76 +}
    4.77 +
    4.78 +extern "C" DXGI_MODE_ROTATION
    4.79 +D3D11_GetCurrentRotation()
    4.80 +{
    4.81 +    switch (DisplayProperties::CurrentOrientation) {
    4.82 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    4.83 +        /* Windows Phone rotations */
    4.84 +        case DisplayOrientations::Landscape:
    4.85 +            return DXGI_MODE_ROTATION_ROTATE90;
    4.86 +        case DisplayOrientations::Portrait:
    4.87 +            return DXGI_MODE_ROTATION_IDENTITY;
    4.88 +        case DisplayOrientations::LandscapeFlipped:
    4.89 +            return DXGI_MODE_ROTATION_ROTATE270;
    4.90 +        case DisplayOrientations::PortraitFlipped:
    4.91 +            return DXGI_MODE_ROTATION_ROTATE180;
    4.92 +#else
    4.93 +        /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
    4.94 +        case DisplayOrientations::Landscape:
    4.95 +            return DXGI_MODE_ROTATION_IDENTITY;
    4.96 +        case DisplayOrientations::Portrait:
    4.97 +            return DXGI_MODE_ROTATION_ROTATE270;
    4.98 +        case DisplayOrientations::LandscapeFlipped:
    4.99 +            return DXGI_MODE_ROTATION_ROTATE180;
   4.100 +        case DisplayOrientations::PortraitFlipped:
   4.101 +            return DXGI_MODE_ROTATION_ROTATE90;
   4.102 +#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
   4.103 +
   4.104 +    default:
   4.105 +        return DXGI_MODE_ROTATION_UNSPECIFIED;
   4.106 +    }
   4.107 +}
   4.108 +
   4.109 +
   4.110 +#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
   4.111 +
   4.112 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/render/direct3d11/SDL_render_d3d11_winrthelpers_cpp.h	Tue Mar 11 12:40:31 2014 -0400
     5.3 @@ -0,0 +1,40 @@
     5.4 +/*
     5.5 +  Simple DirectMedia Layer
     5.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     5.7 +
     5.8 +  This software is provided 'as-is', without any express or implied
     5.9 +  warranty.  In no event will the authors be held liable for any damages
    5.10 +  arising from the use of this software.
    5.11 +
    5.12 +  Permission is granted to anyone to use this software for any purpose,
    5.13 +  including commercial applications, and to alter it and redistribute it
    5.14 +  freely, subject to the following restrictions:
    5.15 +
    5.16 +  1. The origin of this software must not be misrepresented; you must not
    5.17 +     claim that you wrote the original software. If you use this software
    5.18 +     in a product, an acknowledgment in the product documentation would be
    5.19 +     appreciated but is not required.
    5.20 +  2. Altered source versions must be plainly marked as such, and must not be
    5.21 +     misrepresented as being the original software.
    5.22 +  3. This notice may not be removed or altered from any source distribution.
    5.23 +*/
    5.24 +#include "../../SDL_internal.h"
    5.25 +
    5.26 +#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
    5.27 +
    5.28 +#include "SDL_render.h"
    5.29 +
    5.30 +#ifdef __cplusplus
    5.31 +extern "C" {
    5.32 +#endif
    5.33 +
    5.34 +void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
    5.35 +DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
    5.36 +
    5.37 +#ifdef __cplusplus
    5.38 +}
    5.39 +#endif
    5.40 +
    5.41 +#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
    5.42 +
    5.43 +/* vi: set ts=4 sw=4 expandtab: */