WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
authorDavid Ludwig <dludwig@pobox.com>
Sat, 02 Feb 2013 19:32:44 -0500
changeset 84001315402d9028
parent 8399 1fa9dcfbeac5
child 8401 29ecd2eca4af
WinRT: started refactoring Direct3D 11.1 code into a new SDL_Renderer backend
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
include/SDL_config_windowsrt.h
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/direct3d11/SDL_render_d3d11.cpp
src/render/direct3d11/SDL_render_d3d11_cpp.h
src/video/windowsrt/SDL_WinRTApp.cpp
src/video/windowsrt/SDL_WinRTApp.h
src/video/windowsrt/SDL_winrtrenderer.cpp
src/video/windowsrt/SDL_winrtrenderer.h
src/video/windowsrt/SDL_winrtvideo.cpp
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Tue Jan 29 20:27:47 2013 -0500
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sat Feb 02 19:32:44 2013 -0500
     1.3 @@ -211,6 +211,7 @@
     1.4      <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
     1.5      <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     1.6      <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
     1.7 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h" />
     1.8      <ClInclude Include="..\..\src\render\mmx.h" />
     1.9      <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
    1.10      <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
    1.11 @@ -302,6 +303,7 @@
    1.12      <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
    1.13      <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
    1.14      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
    1.15 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
    1.16      <ClCompile Include="..\..\src\render\SDL_render.c" />
    1.17      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
    1.18      <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Tue Jan 29 20:27:47 2013 -0500
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Sat Feb 02 19:32:44 2013 -0500
     2.3 @@ -345,6 +345,9 @@
     2.4      <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClInclude>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.13 @@ -602,6 +605,9 @@
    2.14      <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.cpp">
    2.15        <Filter>Source Files</Filter>
    2.16      </ClCompile>
    2.17 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
    2.18 +      <Filter>Source Files</Filter>
    2.19 +    </ClCompile>
    2.20    </ItemGroup>
    2.21    <ItemGroup>
    2.22      <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Jan 29 20:27:47 2013 -0500
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sat Feb 02 19:32:44 2013 -0500
     3.3 @@ -78,6 +78,7 @@
     3.4      <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
     3.5      <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
     3.6      <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     3.7 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
     3.8      <ClCompile Include="..\..\src\render\SDL_render.c" />
     3.9      <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
    3.10      <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
    3.11 @@ -248,6 +249,7 @@
    3.12      <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
    3.13      <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
    3.14      <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
    3.15 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h" />
    3.16      <ClInclude Include="..\..\src\render\mmx.h" />
    3.17      <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
    3.18      <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Jan 29 20:27:47 2013 -0500
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Sat Feb 02 19:32:44 2013 -0500
     4.3 @@ -264,6 +264,9 @@
     4.4      <ClCompile Include="..\..\src\core\windowsrt\SDL_winrtpaths.cpp">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 +    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
     4.8 +      <Filter>Source Files</Filter>
     4.9 +    </ClCompile>
    4.10    </ItemGroup>
    4.11    <ItemGroup>
    4.12      <ClInclude Include="..\..\include\begin_code.h">
    4.13 @@ -599,6 +602,9 @@
    4.14      <ClInclude Include="..\..\include\SDL_system.h">
    4.15        <Filter>Header Files</Filter>
    4.16      </ClInclude>
    4.17 +    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
    4.18 +      <Filter>Source Files</Filter>
    4.19 +    </ClInclude>
    4.20    </ItemGroup>
    4.21    <ItemGroup>
    4.22      <Filter Include="Header Files">
     5.1 --- a/include/SDL_config_windowsrt.h	Tue Jan 29 20:27:47 2013 -0500
     5.2 +++ b/include/SDL_config_windowsrt.h	Sat Feb 02 19:32:44 2013 -0500
     5.3 @@ -159,6 +159,8 @@
     5.4  #define SDL_VIDEO_DRIVER_DUMMY  1
     5.5  
     5.6  // TODO, WinRT: Get a Direct3D 11 based renderer working in SDL.
     5.7 +/* Enable appropriate renderer(s) */
     5.8 +#define SDL_VIDEO_RENDER_D3D11  1
     5.9  
    5.10  /* Enable system power support */
    5.11  // TODO, WinRT: investigate system power support.  The Win32-based APIs don't work on WinRT.
     6.1 --- a/src/render/SDL_render.c	Tue Jan 29 20:27:47 2013 -0500
     6.2 +++ b/src/render/SDL_render.c	Sat Feb 02 19:32:44 2013 -0500
     6.3 @@ -49,6 +49,9 @@
     6.4  #if SDL_VIDEO_RENDER_D3D
     6.5      &D3D_RenderDriver,
     6.6  #endif
     6.7 +#if SDL_VIDEO_RENDER_D3D11
     6.8 +    &D3D11_RenderDriver,
     6.9 +#endif
    6.10  #if SDL_VIDEO_RENDER_OGL
    6.11      &GL_RenderDriver,
    6.12  #endif
     7.1 --- a/src/render/SDL_sysrender.h	Tue Jan 29 20:27:47 2013 -0500
     7.2 +++ b/src/render/SDL_sysrender.h	Sat Feb 02 19:32:44 2013 -0500
     7.3 @@ -161,6 +161,9 @@
     7.4  #if SDL_VIDEO_RENDER_D3D
     7.5  extern SDL_RenderDriver D3D_RenderDriver;
     7.6  #endif
     7.7 +#if SDL_VIDEO_RENDER_D3D11
     7.8 +extern SDL_RenderDriver D3D11_RenderDriver;
     7.9 +#endif
    7.10  #if SDL_VIDEO_RENDER_OGL
    7.11  extern SDL_RenderDriver GL_RenderDriver;
    7.12  #endif
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 02 19:32:44 2013 -0500
     8.3 @@ -0,0 +1,291 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
    8.28 +
    8.29 +extern "C" {
    8.30 +#include "../../core/windows/SDL_windows.h"
    8.31 +//#include "SDL_hints.h"
    8.32 +//#include "SDL_loadso.h"
    8.33 +#include "SDL_syswm.h"
    8.34 +#include "../SDL_sysrender.h"
    8.35 +//#include "stdio.h"
    8.36 +}
    8.37 +
    8.38 +#include "SDL_render_d3d11_cpp.h"
    8.39 +
    8.40 +/* Direct3D renderer implementation */
    8.41 +
    8.42 +static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
    8.43 +//static void D3D11_WindowEvent(SDL_Renderer * renderer,
    8.44 +//                            const SDL_WindowEvent *event);
    8.45 +//static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.46 +//static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.47 +//                             const SDL_Rect * rect, const void *pixels,
    8.48 +//                             int pitch);
    8.49 +//static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    8.50 +//                           const SDL_Rect * rect, void **pixels, int *pitch);
    8.51 +//static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    8.52 +//static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
    8.53 +static int D3D11_UpdateViewport(SDL_Renderer * renderer);
    8.54 +//static int D3D11_RenderClear(SDL_Renderer * renderer);
    8.55 +//static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
    8.56 +//                                const SDL_FPoint * points, int count);
    8.57 +//static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
    8.58 +//                               const SDL_FPoint * points, int count);
    8.59 +//static int D3D11_RenderFillRects(SDL_Renderer * renderer,
    8.60 +//                               const SDL_FRect * rects, int count);
    8.61 +//static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.62 +//                          const SDL_Rect * srcrect, const SDL_FRect * dstrect);
    8.63 +//static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
    8.64 +//                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
    8.65 +//                          const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
    8.66 +//static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.67 +//                                Uint32 format, void * pixels, int pitch);
    8.68 +//static void D3D11_RenderPresent(SDL_Renderer * renderer);
    8.69 +//static void D3D11_DestroyTexture(SDL_Renderer * renderer,
    8.70 +//                               SDL_Texture * texture);
    8.71 +//static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
    8.72 +
    8.73 +
    8.74 +extern "C" {
    8.75 +    SDL_RenderDriver D3D11_RenderDriver = {
    8.76 +    D3D11_CreateRenderer,
    8.77 +    {
    8.78 +     "direct3d",
    8.79 +     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
    8.80 +     1,
    8.81 +     {SDL_PIXELFORMAT_ARGB8888},
    8.82 +     0,
    8.83 +     0}
    8.84 +    };
    8.85 +}
    8.86 +
    8.87 +//typedef struct
    8.88 +//{
    8.89 +//    float x, y, z;
    8.90 +//    DWORD color;
    8.91 +//    float u, v;
    8.92 +//} Vertex;
    8.93 +
    8.94 +SDL_Renderer *
    8.95 +D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
    8.96 +{
    8.97 +    SDL_Renderer *renderer;
    8.98 +    D3D11_RenderData *data;
    8.99 +//    SDL_SysWMinfo windowinfo;
   8.100 + //   HRESULT result;
   8.101 + //   D3DPRESENT_PARAMETERS pparams;
   8.102 + //   IDirect3DSwapChain9 *chain;
   8.103 + //   D3DCAPS9 caps;
   8.104 + //   Uint32 window_flags;
   8.105 + //   int w, h;
   8.106 + //   SDL_DisplayMode fullscreen_mode;
   8.107 + //   D3DMATRIX matrix;
   8.108 + //   int d3dxVersion;
   8.109 +	//char d3dxDLLFile[50];
   8.110 +
   8.111 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   8.112 +    if (!renderer) {
   8.113 +        SDL_OutOfMemory();
   8.114 +        return NULL;
   8.115 +    }
   8.116 +    SDL_zerop(renderer);
   8.117 +
   8.118 +    data = new D3D11_RenderData;    // Use the C++ 'new' operator to make sure the struct's members initialize using C++ rules
   8.119 +    if (!data) {
   8.120 +        delete data;
   8.121 +        SDL_OutOfMemory();
   8.122 +        return NULL;
   8.123 +    }
   8.124 +
   8.125 +    // TODO: Create Direct3D Object(s)
   8.126 +
   8.127 +    //renderer->WindowEvent = D3D11_WindowEvent;
   8.128 +    //renderer->CreateTexture = D3D11_CreateTexture;
   8.129 +    //renderer->UpdateTexture = D3D11_UpdateTexture;
   8.130 +    //renderer->LockTexture = D3D11_LockTexture;
   8.131 +    //renderer->UnlockTexture = D3D11_UnlockTexture;
   8.132 +    //renderer->SetRenderTarget = D3D11_SetRenderTarget;
   8.133 +    renderer->UpdateViewport = D3D11_UpdateViewport;
   8.134 +    //renderer->RenderClear = D3D11_RenderClear;
   8.135 +    //renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
   8.136 +    //renderer->RenderDrawLines = D3D11_RenderDrawLines;
   8.137 +    //renderer->RenderFillRects = D3D11_RenderFillRects;
   8.138 +    //renderer->RenderCopy = D3D11_RenderCopy;
   8.139 +    //renderer->RenderCopyEx = D3D11_RenderCopyEx;
   8.140 +    //renderer->RenderReadPixels = D3D11_RenderReadPixels;
   8.141 +    //renderer->RenderPresent = D3D11_RenderPresent;
   8.142 +    //renderer->DestroyTexture = D3D11_DestroyTexture;
   8.143 +    //renderer->DestroyRenderer = D3D11_DestroyRenderer;
   8.144 +    renderer->info = D3D11_RenderDriver.info;
   8.145 +    renderer->driverdata = data;
   8.146 +
   8.147 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
   8.148 +
   8.149 +    //SDL_VERSION(&windowinfo.version);
   8.150 +    //SDL_GetWindowWMInfo(window, &windowinfo);
   8.151 +
   8.152 +    //window_flags = SDL_GetWindowFlags(window);
   8.153 +    //SDL_GetWindowSize(window, &w, &h);
   8.154 +    //SDL_GetWindowDisplayMode(window, &fullscreen_mode);
   8.155 +
   8.156 +    //SDL_zero(pparams);
   8.157 +    //pparams.hDeviceWindow = windowinfo.info.win.window;
   8.158 +    //pparams.BackBufferWidth = w;
   8.159 +    //pparams.BackBufferHeight = h;
   8.160 +    //if (window_flags & SDL_WINDOW_FULLSCREEN) {
   8.161 +    //    pparams.BackBufferFormat =
   8.162 +    //        PixelFormatToD3DFMT(fullscreen_mode.format);
   8.163 +    //} else {
   8.164 +    //    pparams.BackBufferFormat = D3DFMT_UNKNOWN;
   8.165 +    //}
   8.166 +    //pparams.BackBufferCount = 1;
   8.167 +    //pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
   8.168 +
   8.169 +    //if (window_flags & SDL_WINDOW_FULLSCREEN) {
   8.170 +    //    pparams.Windowed = FALSE;
   8.171 +    //    pparams.FullScreen_RefreshRateInHz =
   8.172 +    //        fullscreen_mode.refresh_rate;
   8.173 +    //} else {
   8.174 +    //    pparams.Windowed = TRUE;
   8.175 +    //    pparams.FullScreen_RefreshRateInHz = 0;
   8.176 +    //}
   8.177 +    //if (flags & SDL_RENDERER_PRESENTVSYNC) {
   8.178 +    //    pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
   8.179 +    //} else {
   8.180 +    //    pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
   8.181 +    //}
   8.182 +
   8.183 +    ///* FIXME: Which adapter? */
   8.184 +    //data->adapter = D3DADAPTER_DEFAULT;
   8.185 +    //IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
   8.186 +
   8.187 +    //result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
   8.188 +    //                                 D3DDEVTYPE_HAL,
   8.189 +    //                                 pparams.hDeviceWindow,
   8.190 +    //                                 D3DCREATE_FPU_PRESERVE | ((caps.
   8.191 +    //                                  DevCaps &
   8.192 +    //                                  D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
   8.193 +    //                                 D3DCREATE_HARDWARE_VERTEXPROCESSING :
   8.194 +    //                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING),
   8.195 +    //                                 &pparams, &data->device);
   8.196 +    //if (FAILED(result)) {
   8.197 +    //    D3D11_DestroyRenderer(renderer);
   8.198 +    //    D3D11_SetError("CreateDevice()", result);
   8.199 +    //    return NULL;
   8.200 +    //}
   8.201 +    //data->beginScene = SDL_TRUE;
   8.202 +    //data->scaleMode = D3DTEXF_FORCE_DWORD;
   8.203 +
   8.204 +    ///* Get presentation parameters to fill info */
   8.205 +    //result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
   8.206 +    //if (FAILED(result)) {
   8.207 +    //    D3D11_DestroyRenderer(renderer);
   8.208 +    //    D3D11_SetError("GetSwapChain()", result);
   8.209 +    //    return NULL;
   8.210 +    //}
   8.211 +    //result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
   8.212 +    //if (FAILED(result)) {
   8.213 +    //    IDirect3DSwapChain9_Release(chain);
   8.214 +    //    D3D11_DestroyRenderer(renderer);
   8.215 +    //    D3D11_SetError("GetPresentParameters()", result);
   8.216 +    //    return NULL;
   8.217 +    //}
   8.218 +    //IDirect3DSwapChain9_Release(chain);
   8.219 +    //if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
   8.220 +    //    renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   8.221 +    //}
   8.222 +    //data->pparams = pparams;
   8.223 +
   8.224 +    //IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
   8.225 +    //renderer->info.max_texture_width = caps.MaxTextureWidth;
   8.226 +    //renderer->info.max_texture_height = caps.MaxTextureHeight;
   8.227 +    //if (caps.NumSimultaneousRTs >= 2) {
   8.228 +    //    renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
   8.229 +    //}
   8.230 +
   8.231 +    ///* Set up parameters for rendering */
   8.232 +    //IDirect3DDevice9_SetVertexShader(data->device, NULL);
   8.233 +    //IDirect3DDevice9_SetFVF(data->device,
   8.234 +    //                        D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
   8.235 +    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
   8.236 +    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
   8.237 +    //                                D3DCULL_NONE);
   8.238 +    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
   8.239 +    ///* Enable color modulation by diffuse color */
   8.240 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
   8.241 +    //                                      D3DTOP_MODULATE);
   8.242 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
   8.243 +    //                                      D3DTA_TEXTURE);
   8.244 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
   8.245 +    //                                      D3DTA_DIFFUSE);
   8.246 +    ///* Enable alpha modulation by diffuse alpha */
   8.247 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
   8.248 +    //                                      D3DTOP_MODULATE);
   8.249 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
   8.250 +    //                                      D3DTA_TEXTURE);
   8.251 +    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
   8.252 +    //                                      D3DTA_DIFFUSE);
   8.253 +    ///* Disable second texture stage, since we're done */
   8.254 +    //IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
   8.255 +    //                                      D3DTOP_DISABLE);
   8.256 +    //IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
   8.257 +    //                                      D3DTOP_DISABLE);
   8.258 +
   8.259 +    ///* Store the default render target */
   8.260 +    //IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
   8.261 +    //data->currentRenderTarget = NULL;
   8.262 +
   8.263 +    ///* Set an identity world and view matrix */
   8.264 +    //matrix.m[0][0] = 1.0f;
   8.265 +    //matrix.m[0][1] = 0.0f;
   8.266 +    //matrix.m[0][2] = 0.0f;
   8.267 +    //matrix.m[0][3] = 0.0f;
   8.268 +    //matrix.m[1][0] = 0.0f;
   8.269 +    //matrix.m[1][1] = 1.0f;
   8.270 +    //matrix.m[1][2] = 0.0f;
   8.271 +    //matrix.m[1][3] = 0.0f;
   8.272 +    //matrix.m[2][0] = 0.0f;
   8.273 +    //matrix.m[2][1] = 0.0f;
   8.274 +    //matrix.m[2][2] = 1.0f;
   8.275 +    //matrix.m[2][3] = 0.0f;
   8.276 +    //matrix.m[3][0] = 0.0f;
   8.277 +    //matrix.m[3][1] = 0.0f;
   8.278 +    //matrix.m[3][2] = 0.0f;
   8.279 +    //matrix.m[3][3] = 1.0f;
   8.280 +    //IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
   8.281 +    //IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
   8.282 +
   8.283 +    return renderer;
   8.284 +}
   8.285 +
   8.286 +static int
   8.287 +D3D11_UpdateViewport(SDL_Renderer * renderer)
   8.288 +{
   8.289 +    return 0;
   8.290 +}
   8.291 +
   8.292 +#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
   8.293 +
   8.294 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/render/direct3d11/SDL_render_d3d11_cpp.h	Sat Feb 02 19:32:44 2013 -0500
     9.3 @@ -0,0 +1,45 @@
     9.4 +/*
     9.5 +  Simple DirectMedia Layer
     9.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     9.7 +
     9.8 +  This software is provided 'as-is', without any express or implied
     9.9 +  warranty.  In no event will the authors be held liable for any damages
    9.10 +  arising from the use of this software.
    9.11 +
    9.12 +  Permission is granted to anyone to use this software for any purpose,
    9.13 +  including commercial applications, and to alter it and redistribute it
    9.14 +  freely, subject to the following restrictions:
    9.15 +
    9.16 +  1. The origin of this software must not be misrepresented; you must not
    9.17 +     claim that you wrote the original software. If you use this software
    9.18 +     in a product, an acknowledgment in the product documentation would be
    9.19 +     appreciated but is not required.
    9.20 +  2. Altered source versions must be plainly marked as such, and must not be
    9.21 +     misrepresented as being the original software.
    9.22 +  3. This notice may not be removed or altered from any source distribution.
    9.23 +*/
    9.24 +#include "SDL_config.h"
    9.25 +
    9.26 +#include <D3D11_1.h>
    9.27 +#include <wrl/client.h>
    9.28 +
    9.29 +typedef struct
    9.30 +{
    9.31 +    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice;
    9.32 +    Microsoft::WRL::ComPtr<ID3D11DeviceContext1> d3dContext;
    9.33 +    Microsoft::WRL::ComPtr<IDXGISwapChain1> swapChain;
    9.34 +    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView;
    9.35 +    Microsoft::WRL::ComPtr<ID3D11InputLayout> inputLayout;
    9.36 +    Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer;
    9.37 +    Microsoft::WRL::ComPtr<ID3D11VertexShader> vertexShader;
    9.38 +    Microsoft::WRL::ComPtr<ID3D11PixelShader> pixelShader;
    9.39 +    Microsoft::WRL::ComPtr<ID3D11Texture2D> mainTexture;
    9.40 +    Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> mainTextureResourceView;
    9.41 +    Microsoft::WRL::ComPtr<ID3D11SamplerState> mainSampler;
    9.42 +} D3D11_RenderData;
    9.43 +
    9.44 +typedef struct
    9.45 +{
    9.46 +} D3D11_TextureData;
    9.47 +
    9.48 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Jan 29 20:27:47 2013 -0500
    10.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sat Feb 02 19:32:44 2013 -0500
    10.3 @@ -47,7 +47,8 @@
    10.4      m_windowClosed(false),
    10.5      m_windowVisible(true),
    10.6      m_sdlWindowData(NULL),
    10.7 -    m_useRelativeMouseMode(false)
    10.8 +    m_useRelativeMouseMode(false),
    10.9 +    m_renderer(nullptr)
   10.10  {
   10.11  }
   10.12  
   10.13 @@ -101,8 +102,7 @@
   10.14      window->KeyUp +=
   10.15          ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
   10.16  
   10.17 -
   10.18 -    m_renderer->Initialize(CoreWindow::GetForCurrentThread());
   10.19 +    //m_renderer->Initialize(CoreWindow::GetForCurrentThread());    // DLudwig: moved this call to WINRT_CreateWindow, likely elsewhere in the future
   10.20  }
   10.21  
   10.22  void SDL_WinRTApp::Load(Platform::String^ entryPoint)
    11.1 --- a/src/video/windowsrt/SDL_WinRTApp.h	Tue Jan 29 20:27:47 2013 -0500
    11.2 +++ b/src/video/windowsrt/SDL_WinRTApp.h	Sat Feb 02 19:32:44 2013 -0500
    11.3 @@ -47,8 +47,10 @@
    11.4      void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    11.5      void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    11.6  
    11.7 +internal:
    11.8 +    SDL_winrtrenderer^ m_renderer;
    11.9 +
   11.10  private:
   11.11 -    SDL_winrtrenderer^ m_renderer;
   11.12      bool m_windowClosed;
   11.13      bool m_windowVisible;
   11.14      const SDL_WindowData* m_sdlWindowData;
    12.1 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Tue Jan 29 20:27:47 2013 -0500
    12.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 02 19:32:44 2013 -0500
    12.3 @@ -11,7 +11,8 @@
    12.4  SDL_winrtrenderer::SDL_winrtrenderer() :
    12.5      m_mainTextureHelperSurface(NULL),
    12.6      m_loadingComplete(false),
    12.7 -    m_vertexCount(0)
    12.8 +    m_vertexCount(0),
    12.9 +    m_sdlRendererData(NULL)
   12.10  {
   12.11  }
   12.12  
   12.13 @@ -38,8 +39,9 @@
   12.14      // Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
   12.15      m_windowBounds.Width = 0;
   12.16      m_windowBounds.Height = 0;
   12.17 -    m_swapChain = nullptr;
   12.18 +    m_sdlRendererData->swapChain = nullptr;
   12.19  
   12.20 +    // TODO, WinRT: reconnect HandleDeviceLost to SDL_Renderer
   12.21      CreateDeviceResources();
   12.22      UpdateForWindowSizeChange();
   12.23  }
   12.24 @@ -90,12 +92,13 @@
   12.25          );
   12.26  
   12.27      // Get the Direct3D 11.1 API device and context interfaces.
   12.28 +    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice1;
   12.29      DX::ThrowIfFailed(
   12.30 -        device.As(&m_d3dDevice)
   12.31 +        device.As(&(m_sdlRendererData->d3dDevice))
   12.32          );
   12.33  
   12.34      DX::ThrowIfFailed(
   12.35 -        context.As(&m_d3dContext)
   12.36 +        context.As(&m_sdlRendererData->d3dContext)
   12.37          );
   12.38  
   12.39  #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   12.40 @@ -108,11 +111,11 @@
   12.41  
   12.42      auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
   12.43          DX::ThrowIfFailed(
   12.44 -            m_d3dDevice->CreateVertexShader(
   12.45 +            (m_sdlRendererData->d3dDevice)->CreateVertexShader(
   12.46                  fileData->Data,
   12.47                  fileData->Length,
   12.48                  nullptr,
   12.49 -                &m_vertexShader
   12.50 +                &m_sdlRendererData->vertexShader
   12.51                  )
   12.52              );
   12.53  
   12.54 @@ -123,23 +126,23 @@
   12.55          };
   12.56  
   12.57          DX::ThrowIfFailed(
   12.58 -            m_d3dDevice->CreateInputLayout(
   12.59 +            m_sdlRendererData->d3dDevice->CreateInputLayout(
   12.60                  vertexDesc,
   12.61                  ARRAYSIZE(vertexDesc),
   12.62                  fileData->Data,
   12.63                  fileData->Length,
   12.64 -                &m_inputLayout
   12.65 +                &m_sdlRendererData->inputLayout
   12.66                  )
   12.67              );
   12.68      });
   12.69  
   12.70      auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
   12.71          DX::ThrowIfFailed(
   12.72 -            m_d3dDevice->CreatePixelShader(
   12.73 +            m_sdlRendererData->d3dDevice->CreatePixelShader(
   12.74                  fileData->Data,
   12.75                  fileData->Length,
   12.76                  nullptr,
   12.77 -                &m_pixelShader
   12.78 +                &m_sdlRendererData->pixelShader
   12.79                  )
   12.80              );
   12.81      });
   12.82 @@ -161,10 +164,10 @@
   12.83          vertexBufferData.SysMemSlicePitch = 0;
   12.84          CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
   12.85          DX::ThrowIfFailed(
   12.86 -            m_d3dDevice->CreateBuffer(
   12.87 +            m_sdlRendererData->d3dDevice->CreateBuffer(
   12.88                  &vertexBufferDesc,
   12.89                  &vertexBufferData,
   12.90 -                &m_vertexBuffer
   12.91 +                &m_sdlRendererData->vertexBuffer
   12.92                  )
   12.93              );
   12.94      });
   12.95 @@ -185,9 +188,9 @@
   12.96          samplerDesc.MinLOD = 0.0f;
   12.97          samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
   12.98          DX::ThrowIfFailed(
   12.99 -            m_d3dDevice->CreateSamplerState(
  12.100 +            m_sdlRendererData->d3dDevice->CreateSamplerState(
  12.101                  &samplerDesc,
  12.102 -                &m_mainSampler
  12.103 +                &m_sdlRendererData->mainSampler
  12.104                  )
  12.105              );
  12.106      });
  12.107 @@ -218,11 +221,11 @@
  12.108      m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
  12.109      m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
  12.110  
  12.111 -    if(m_swapChain != nullptr)
  12.112 +    if(m_sdlRendererData->swapChain != nullptr)
  12.113      {
  12.114          // If the swap chain already exists, resize it.
  12.115          DX::ThrowIfFailed(
  12.116 -            m_swapChain->ResizeBuffers(
  12.117 +            m_sdlRendererData->swapChain->ResizeBuffers(
  12.118                  2, // Double-buffered swap chain.
  12.119                  static_cast<UINT>(m_renderTargetSize.Width),
  12.120                  static_cast<UINT>(m_renderTargetSize.Height),
  12.121 @@ -254,7 +257,7 @@
  12.122  
  12.123          ComPtr<IDXGIDevice1>  dxgiDevice;
  12.124          DX::ThrowIfFailed(
  12.125 -            m_d3dDevice.As(&dxgiDevice)
  12.126 +            m_sdlRendererData->d3dDevice.As(&dxgiDevice)
  12.127              );
  12.128  
  12.129          ComPtr<IDXGIAdapter> dxgiAdapter;
  12.130 @@ -273,11 +276,11 @@
  12.131          Windows::UI::Core::CoreWindow^ window = m_window.Get();
  12.132          DX::ThrowIfFailed(
  12.133              dxgiFactory->CreateSwapChainForCoreWindow(
  12.134 -                m_d3dDevice.Get(),
  12.135 +                m_sdlRendererData->d3dDevice.Get(),
  12.136                  reinterpret_cast<IUnknown*>(window),
  12.137                  &swapChainDesc,
  12.138                  nullptr, // Allow on all displays.
  12.139 -                &m_swapChain
  12.140 +                &m_sdlRendererData->swapChain
  12.141                  )
  12.142              );
  12.143              
  12.144 @@ -340,14 +343,14 @@
  12.145  #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
  12.146      // TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method.  Check if an alternative is available, or needed.
  12.147      DX::ThrowIfFailed(
  12.148 -        m_swapChain->SetRotation(rotation)
  12.149 +        m_sdlRendererData->swapChain->SetRotation(rotation)
  12.150          );
  12.151  #endif
  12.152  
  12.153      // Create a render target view of the swap chain back buffer.
  12.154      ComPtr<ID3D11Texture2D> backBuffer;
  12.155      DX::ThrowIfFailed(
  12.156 -        m_swapChain->GetBuffer(
  12.157 +        m_sdlRendererData->swapChain->GetBuffer(
  12.158              0,
  12.159              __uuidof(ID3D11Texture2D),
  12.160              &backBuffer
  12.161 @@ -355,10 +358,10 @@
  12.162          );
  12.163  
  12.164      DX::ThrowIfFailed(
  12.165 -        m_d3dDevice->CreateRenderTargetView(
  12.166 +        m_sdlRendererData->d3dDevice->CreateRenderTargetView(
  12.167              backBuffer.Get(),
  12.168              nullptr,
  12.169 -            &m_renderTargetView
  12.170 +            &m_sdlRendererData->renderTargetView
  12.171              )
  12.172          );
  12.173  
  12.174 @@ -374,7 +377,7 @@
  12.175  
  12.176      ComPtr<ID3D11Texture2D> depthStencil;
  12.177      DX::ThrowIfFailed(
  12.178 -        m_d3dDevice->CreateTexture2D(
  12.179 +        m_sdlRendererData->d3dDevice->CreateTexture2D(
  12.180              &depthStencilDesc,
  12.181              nullptr,
  12.182              &depthStencil
  12.183 @@ -389,7 +392,7 @@
  12.184          m_renderTargetSize.Height
  12.185          );
  12.186  
  12.187 -    m_d3dContext->RSSetViewports(1, &viewport);
  12.188 +    m_sdlRendererData->d3dContext->RSSetViewports(1, &viewport);
  12.189  }
  12.190  
  12.191  void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
  12.192 @@ -425,10 +428,10 @@
  12.193      initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
  12.194      initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
  12.195      DX::ThrowIfFailed(
  12.196 -        m_d3dDevice->CreateTexture2D(
  12.197 +        m_sdlRendererData->d3dDevice->CreateTexture2D(
  12.198              &textureDesc,
  12.199              &initialTextureData,
  12.200 -            &m_mainTexture
  12.201 +            &m_sdlRendererData->mainTexture
  12.202              )
  12.203          );
  12.204  
  12.205 @@ -452,10 +455,10 @@
  12.206      resourceViewDesc.Texture2D.MostDetailedMip = 0;
  12.207      resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
  12.208      DX::ThrowIfFailed(
  12.209 -        m_d3dDevice->CreateShaderResourceView(
  12.210 -            m_mainTexture.Get(),
  12.211 +        m_sdlRendererData->d3dDevice->CreateShaderResourceView(
  12.212 +            m_sdlRendererData->mainTexture.Get(),
  12.213              &resourceViewDesc,
  12.214 -            &m_mainTextureResourceView)
  12.215 +            &m_sdlRendererData->mainTextureResourceView)
  12.216          );
  12.217  }
  12.218  
  12.219 @@ -467,9 +470,9 @@
  12.220          m_orientation != DisplayProperties::CurrentOrientation)
  12.221      {
  12.222          ID3D11RenderTargetView* nullViews[] = {nullptr};
  12.223 -        m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
  12.224 -        m_renderTargetView = nullptr;
  12.225 -        m_d3dContext->Flush();
  12.226 +        m_sdlRendererData->d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
  12.227 +        m_sdlRendererData->renderTargetView = nullptr;
  12.228 +        m_sdlRendererData->d3dContext->Flush();
  12.229          CreateWindowSizeDependentResources();
  12.230      }
  12.231  }
  12.232 @@ -477,8 +480,8 @@
  12.233  void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
  12.234  {
  12.235      const float blackColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
  12.236 -    m_d3dContext->ClearRenderTargetView(
  12.237 -        m_renderTargetView.Get(),
  12.238 +    m_sdlRendererData->d3dContext->ClearRenderTargetView(
  12.239 +        m_sdlRendererData->renderTargetView.Get(),
  12.240          blackColor
  12.241          );
  12.242  
  12.243 @@ -487,7 +490,7 @@
  12.244      {
  12.245          return;
  12.246      }
  12.247 -    if (!m_mainTextureResourceView)
  12.248 +    if (!m_sdlRendererData->mainTextureResourceView)
  12.249      {
  12.250          return;
  12.251      }
  12.252 @@ -496,8 +499,8 @@
  12.253      // window's main texture to CPU-accessible memory:
  12.254      D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
  12.255      DX::ThrowIfFailed(
  12.256 -        m_d3dContext->Map(
  12.257 -            m_mainTexture.Get(),
  12.258 +        m_sdlRendererData->d3dContext->Map(
  12.259 +            m_sdlRendererData->mainTexture.Get(),
  12.260              0,
  12.261              D3D11_MAP_WRITE_DISCARD,
  12.262              0,
  12.263 @@ -513,47 +516,47 @@
  12.264      // Clean up a bit, then commit the texture's memory back to Direct3D:
  12.265      m_mainTextureHelperSurface->pixels = NULL;
  12.266      m_mainTextureHelperSurface->pitch = 0;
  12.267 -    m_d3dContext->Unmap(
  12.268 -        m_mainTexture.Get(),
  12.269 +    m_sdlRendererData->d3dContext->Unmap(
  12.270 +        m_sdlRendererData->mainTexture.Get(),
  12.271          0);
  12.272  
  12.273 -    m_d3dContext->OMSetRenderTargets(
  12.274 +    m_sdlRendererData->d3dContext->OMSetRenderTargets(
  12.275          1,
  12.276 -        m_renderTargetView.GetAddressOf(),
  12.277 +        m_sdlRendererData->renderTargetView.GetAddressOf(),
  12.278          nullptr
  12.279          );
  12.280  
  12.281      UINT stride = sizeof(VertexPositionColor);
  12.282      UINT offset = 0;
  12.283 -    m_d3dContext->IASetVertexBuffers(
  12.284 +    m_sdlRendererData->d3dContext->IASetVertexBuffers(
  12.285          0,
  12.286          1,
  12.287 -        m_vertexBuffer.GetAddressOf(),
  12.288 +        m_sdlRendererData->vertexBuffer.GetAddressOf(),
  12.289          &stride,
  12.290          &offset
  12.291          );
  12.292  
  12.293 -    m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
  12.294 +    m_sdlRendererData->d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
  12.295  
  12.296 -    m_d3dContext->IASetInputLayout(m_inputLayout.Get());
  12.297 +    m_sdlRendererData->d3dContext->IASetInputLayout(m_sdlRendererData->inputLayout.Get());
  12.298  
  12.299 -    m_d3dContext->VSSetShader(
  12.300 -        m_vertexShader.Get(),
  12.301 +    m_sdlRendererData->d3dContext->VSSetShader(
  12.302 +        m_sdlRendererData->vertexShader.Get(),
  12.303          nullptr,
  12.304          0
  12.305          );
  12.306  
  12.307 -    m_d3dContext->PSSetShader(
  12.308 -        m_pixelShader.Get(),
  12.309 +    m_sdlRendererData->d3dContext->PSSetShader(
  12.310 +        m_sdlRendererData->pixelShader.Get(),
  12.311          nullptr,
  12.312          0
  12.313          );
  12.314  
  12.315 -    m_d3dContext->PSSetShaderResources(0, 1, m_mainTextureResourceView.GetAddressOf());
  12.316 +    m_sdlRendererData->d3dContext->PSSetShaderResources(0, 1, m_sdlRendererData->mainTextureResourceView.GetAddressOf());
  12.317  
  12.318 -    m_d3dContext->PSSetSamplers(0, 1, m_mainSampler.GetAddressOf());
  12.319 +    m_sdlRendererData->d3dContext->PSSetSamplers(0, 1, m_sdlRendererData->mainSampler.GetAddressOf());
  12.320  
  12.321 -    m_d3dContext->Draw(4, 0);
  12.322 +    m_sdlRendererData->d3dContext->Draw(4, 0);
  12.323  }
  12.324  
  12.325  // Method to deliver the final image to the display.
  12.326 @@ -563,7 +566,7 @@
  12.327      // The first argument instructs DXGI to block until VSync, putting the application
  12.328  	// to sleep until the next VSync. This ensures we don't waste any cycles rendering
  12.329  	// frames that will never be displayed to the screen.
  12.330 -	HRESULT hr = m_swapChain->Present(1, 0);
  12.331 +	HRESULT hr = m_sdlRendererData->swapChain->Present(1, 0);
  12.332  #else
  12.333      // The application may optionally specify "dirty" or "scroll"
  12.334      // rects to improve efficiency in certain scenarios.
  12.335 @@ -577,13 +580,13 @@
  12.336      // The first argument instructs DXGI to block until VSync, putting the application
  12.337      // to sleep until the next VSync. This ensures we don't waste any cycles rendering
  12.338      // frames that will never be displayed to the screen.
  12.339 -    HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
  12.340 +    HRESULT hr = m_sdlRendererData->swapChain->Present1(1, 0, &parameters);
  12.341  #endif
  12.342  
  12.343      // Discard the contents of the render target.
  12.344      // This is a valid operation only when the existing contents will be entirely
  12.345      // overwritten. If dirty or scroll rects are used, this call should be removed.
  12.346 -    m_d3dContext->DiscardView(m_renderTargetView.Get());
  12.347 +    m_sdlRendererData->d3dContext->DiscardView(m_sdlRendererData->renderTargetView.Get());
  12.348  
  12.349      // If the device was removed either by a disconnect or a driver upgrade, we 
  12.350      // must recreate all device resources.
    13.1 --- a/src/video/windowsrt/SDL_winrtrenderer.h	Tue Jan 29 20:27:47 2013 -0500
    13.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 02 19:32:44 2013 -0500
    13.3 @@ -2,6 +2,7 @@
    13.4  
    13.5  #include "DirectXHelper.h"
    13.6  #include "SDL.h"
    13.7 +#include "../../render/direct3d11/SDL_render_d3d11_cpp.h"
    13.8  
    13.9  struct VertexPositionColor
   13.10  {
   13.11 @@ -29,20 +30,11 @@
   13.12      virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects);
   13.13      void ResizeMainTexture(int w, int h);
   13.14  
   13.15 +internal:
   13.16 +    // Internal SDL rendeerer (likely a temporary addition, for refactoring purposes):
   13.17 +    D3D11_RenderData * m_sdlRendererData;
   13.18 +
   13.19  protected private:
   13.20 -    // Direct3D Objects.
   13.21 -    Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
   13.22 -    Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
   13.23 -    Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
   13.24 -    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
   13.25 -    Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
   13.26 -    Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
   13.27 -    Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
   13.28 -    Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
   13.29 -    Microsoft::WRL::ComPtr<ID3D11Texture2D> m_mainTexture;
   13.30 -    Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_mainTextureResourceView;
   13.31 -    Microsoft::WRL::ComPtr<ID3D11SamplerState> m_mainSampler;
   13.32 -
   13.33      // UpdateWindowSurface helper objects
   13.34      SDL_Surface * m_mainTextureHelperSurface;
   13.35  
    14.1 --- a/src/video/windowsrt/SDL_winrtvideo.cpp	Tue Jan 29 20:27:47 2013 -0500
    14.2 +++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sat Feb 02 19:32:44 2013 -0500
    14.3 @@ -34,6 +34,7 @@
    14.4  #include "../SDL_sysvideo.h"
    14.5  #include "../SDL_pixels_c.h"
    14.6  #include "../../events/SDL_events_c.h"
    14.7 +#include "../../render/SDL_sysrender.h"
    14.8  }
    14.9  
   14.10  #include "SDL_WinRTApp.h"
   14.11 @@ -210,6 +211,19 @@
   14.12      */
   14.13      SDL_WinRTGlobalApp->SetSDLWindowData(data);
   14.14  
   14.15 +    /* For now, create a Direct3D 11 renderer up-front.  Eventually, this
   14.16 +       won't be done in WINRT_CreateWindow, although it may get done in
   14.17 +       SDL_WINRT_CreateWindowFramebuffer.
   14.18 +    */
   14.19 +
   14.20 +    // Link SDL_winrtrenderer to the SDL_Renderer temporarily,
   14.21 +    // for refactoring purposes.  Initialize the SDL_Renderer
   14.22 +    // first in order to give it the opportunity to create key
   14.23 +    // resources first.
   14.24 +    SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
   14.25 +    SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
   14.26 +    SDL_WinRTGlobalApp->m_renderer->Initialize(CoreWindow::GetForCurrentThread());
   14.27 +
   14.28      /* All done! */
   14.29      return 0;
   14.30  }