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 8400 1315402d9028
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
--- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Tue Jan 29 20:27:47 2013 -0500
+++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sat Feb 02 19:32:44 2013 -0500
@@ -211,6 +211,7 @@
     <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
     <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
@@ -302,6 +303,7 @@
     <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
     <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
     <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-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Tue Jan 29 20:27:47 2013 -0500
+++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Sat Feb 02 19:32:44 2013 -0500
@@ -345,6 +345,9 @@
     <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -602,6 +605,9 @@
     <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Jan 29 20:27:47 2013 -0500
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sat Feb 02 19:32:44 2013 -0500
@@ -78,6 +78,7 @@
     <ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
     <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp" />
     <ClCompile Include="..\..\src\render\SDL_render.c" />
     <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
     <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
@@ -248,6 +249,7 @@
     <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
     <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
--- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Jan 29 20:27:47 2013 -0500
+++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Sat Feb 02 19:32:44 2013 -0500
@@ -264,6 +264,9 @@
     <ClCompile Include="..\..\src\core\windowsrt\SDL_winrtpaths.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\begin_code.h">
@@ -599,6 +602,9 @@
     <ClInclude Include="..\..\include\SDL_system.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Header Files">
--- a/include/SDL_config_windowsrt.h	Tue Jan 29 20:27:47 2013 -0500
+++ b/include/SDL_config_windowsrt.h	Sat Feb 02 19:32:44 2013 -0500
@@ -159,6 +159,8 @@
 #define SDL_VIDEO_DRIVER_DUMMY  1
 
 // TODO, WinRT: Get a Direct3D 11 based renderer working in SDL.
+/* Enable appropriate renderer(s) */
+#define SDL_VIDEO_RENDER_D3D11  1
 
 /* Enable system power support */
 // TODO, WinRT: investigate system power support.  The Win32-based APIs don't work on WinRT.
--- a/src/render/SDL_render.c	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/render/SDL_render.c	Sat Feb 02 19:32:44 2013 -0500
@@ -49,6 +49,9 @@
 #if SDL_VIDEO_RENDER_D3D
     &D3D_RenderDriver,
 #endif
+#if SDL_VIDEO_RENDER_D3D11
+    &D3D11_RenderDriver,
+#endif
 #if SDL_VIDEO_RENDER_OGL
     &GL_RenderDriver,
 #endif
--- a/src/render/SDL_sysrender.h	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/render/SDL_sysrender.h	Sat Feb 02 19:32:44 2013 -0500
@@ -161,6 +161,9 @@
 #if SDL_VIDEO_RENDER_D3D
 extern SDL_RenderDriver D3D_RenderDriver;
 #endif
+#if SDL_VIDEO_RENDER_D3D11
+extern SDL_RenderDriver D3D11_RenderDriver;
+#endif
 #if SDL_VIDEO_RENDER_OGL
 extern SDL_RenderDriver GL_RenderDriver;
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 02 19:32:44 2013 -0500
@@ -0,0 +1,291 @@
+/*
+  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_config.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+extern "C" {
+#include "../../core/windows/SDL_windows.h"
+//#include "SDL_hints.h"
+//#include "SDL_loadso.h"
+#include "SDL_syswm.h"
+#include "../SDL_sysrender.h"
+//#include "stdio.h"
+}
+
+#include "SDL_render_d3d11_cpp.h"
+
+/* Direct3D renderer implementation */
+
+static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
+//static void D3D11_WindowEvent(SDL_Renderer * renderer,
+//                            const SDL_WindowEvent *event);
+//static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+//static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+//                             const SDL_Rect * rect, const void *pixels,
+//                             int pitch);
+//static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+//                           const SDL_Rect * rect, void **pixels, int *pitch);
+//static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+//static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D11_UpdateViewport(SDL_Renderer * renderer);
+//static int D3D11_RenderClear(SDL_Renderer * renderer);
+//static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
+//                                const SDL_FPoint * points, int count);
+//static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
+//                               const SDL_FPoint * points, int count);
+//static int D3D11_RenderFillRects(SDL_Renderer * renderer,
+//                               const SDL_FRect * rects, int count);
+//static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+//                          const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+//static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+//                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+//                          const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
+//static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+//                                Uint32 format, void * pixels, int pitch);
+//static void D3D11_RenderPresent(SDL_Renderer * renderer);
+//static void D3D11_DestroyTexture(SDL_Renderer * renderer,
+//                               SDL_Texture * texture);
+//static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
+
+
+extern "C" {
+    SDL_RenderDriver D3D11_RenderDriver = {
+    D3D11_CreateRenderer,
+    {
+     "direct3d",
+     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+     1,
+     {SDL_PIXELFORMAT_ARGB8888},
+     0,
+     0}
+    };
+}
+
+//typedef struct
+//{
+//    float x, y, z;
+//    DWORD color;
+//    float u, v;
+//} Vertex;
+
+SDL_Renderer *
+D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+    SDL_Renderer *renderer;
+    D3D11_RenderData *data;
+//    SDL_SysWMinfo windowinfo;
+ //   HRESULT result;
+ //   D3DPRESENT_PARAMETERS pparams;
+ //   IDirect3DSwapChain9 *chain;
+ //   D3DCAPS9 caps;
+ //   Uint32 window_flags;
+ //   int w, h;
+ //   SDL_DisplayMode fullscreen_mode;
+ //   D3DMATRIX matrix;
+ //   int d3dxVersion;
+	//char d3dxDLLFile[50];
+
+    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+    if (!renderer) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+    SDL_zerop(renderer);
+
+    data = new D3D11_RenderData;    // Use the C++ 'new' operator to make sure the struct's members initialize using C++ rules
+    if (!data) {
+        delete data;
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    // TODO: Create Direct3D Object(s)
+
+    //renderer->WindowEvent = D3D11_WindowEvent;
+    //renderer->CreateTexture = D3D11_CreateTexture;
+    //renderer->UpdateTexture = D3D11_UpdateTexture;
+    //renderer->LockTexture = D3D11_LockTexture;
+    //renderer->UnlockTexture = D3D11_UnlockTexture;
+    //renderer->SetRenderTarget = D3D11_SetRenderTarget;
+    renderer->UpdateViewport = D3D11_UpdateViewport;
+    //renderer->RenderClear = D3D11_RenderClear;
+    //renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
+    //renderer->RenderDrawLines = D3D11_RenderDrawLines;
+    //renderer->RenderFillRects = D3D11_RenderFillRects;
+    //renderer->RenderCopy = D3D11_RenderCopy;
+    //renderer->RenderCopyEx = D3D11_RenderCopyEx;
+    //renderer->RenderReadPixels = D3D11_RenderReadPixels;
+    //renderer->RenderPresent = D3D11_RenderPresent;
+    //renderer->DestroyTexture = D3D11_DestroyTexture;
+    //renderer->DestroyRenderer = D3D11_DestroyRenderer;
+    renderer->info = D3D11_RenderDriver.info;
+    renderer->driverdata = data;
+
+    renderer->info.flags = SDL_RENDERER_ACCELERATED;
+
+    //SDL_VERSION(&windowinfo.version);
+    //SDL_GetWindowWMInfo(window, &windowinfo);
+
+    //window_flags = SDL_GetWindowFlags(window);
+    //SDL_GetWindowSize(window, &w, &h);
+    //SDL_GetWindowDisplayMode(window, &fullscreen_mode);
+
+    //SDL_zero(pparams);
+    //pparams.hDeviceWindow = windowinfo.info.win.window;
+    //pparams.BackBufferWidth = w;
+    //pparams.BackBufferHeight = h;
+    //if (window_flags & SDL_WINDOW_FULLSCREEN) {
+    //    pparams.BackBufferFormat =
+    //        PixelFormatToD3DFMT(fullscreen_mode.format);
+    //} else {
+    //    pparams.BackBufferFormat = D3DFMT_UNKNOWN;
+    //}
+    //pparams.BackBufferCount = 1;
+    //pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
+
+    //if (window_flags & SDL_WINDOW_FULLSCREEN) {
+    //    pparams.Windowed = FALSE;
+    //    pparams.FullScreen_RefreshRateInHz =
+    //        fullscreen_mode.refresh_rate;
+    //} else {
+    //    pparams.Windowed = TRUE;
+    //    pparams.FullScreen_RefreshRateInHz = 0;
+    //}
+    //if (flags & SDL_RENDERER_PRESENTVSYNC) {
+    //    pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
+    //} else {
+    //    pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
+    //}
+
+    ///* FIXME: Which adapter? */
+    //data->adapter = D3DADAPTER_DEFAULT;
+    //IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
+
+    //result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
+    //                                 D3DDEVTYPE_HAL,
+    //                                 pparams.hDeviceWindow,
+    //                                 D3DCREATE_FPU_PRESERVE | ((caps.
+    //                                  DevCaps &
+    //                                  D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
+    //                                 D3DCREATE_HARDWARE_VERTEXPROCESSING :
+    //                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING),
+    //                                 &pparams, &data->device);
+    //if (FAILED(result)) {
+    //    D3D11_DestroyRenderer(renderer);
+    //    D3D11_SetError("CreateDevice()", result);
+    //    return NULL;
+    //}
+    //data->beginScene = SDL_TRUE;
+    //data->scaleMode = D3DTEXF_FORCE_DWORD;
+
+    ///* Get presentation parameters to fill info */
+    //result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
+    //if (FAILED(result)) {
+    //    D3D11_DestroyRenderer(renderer);
+    //    D3D11_SetError("GetSwapChain()", result);
+    //    return NULL;
+    //}
+    //result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
+    //if (FAILED(result)) {
+    //    IDirect3DSwapChain9_Release(chain);
+    //    D3D11_DestroyRenderer(renderer);
+    //    D3D11_SetError("GetPresentParameters()", result);
+    //    return NULL;
+    //}
+    //IDirect3DSwapChain9_Release(chain);
+    //if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
+    //    renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+    //}
+    //data->pparams = pparams;
+
+    //IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
+    //renderer->info.max_texture_width = caps.MaxTextureWidth;
+    //renderer->info.max_texture_height = caps.MaxTextureHeight;
+    //if (caps.NumSimultaneousRTs >= 2) {
+    //    renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
+    //}
+
+    ///* Set up parameters for rendering */
+    //IDirect3DDevice9_SetVertexShader(data->device, NULL);
+    //IDirect3DDevice9_SetFVF(data->device,
+    //                        D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
+    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
+    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
+    //                                D3DCULL_NONE);
+    //IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
+    ///* Enable color modulation by diffuse color */
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
+    //                                      D3DTOP_MODULATE);
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
+    //                                      D3DTA_TEXTURE);
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
+    //                                      D3DTA_DIFFUSE);
+    ///* Enable alpha modulation by diffuse alpha */
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
+    //                                      D3DTOP_MODULATE);
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
+    //                                      D3DTA_TEXTURE);
+    //IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
+    //                                      D3DTA_DIFFUSE);
+    ///* Disable second texture stage, since we're done */
+    //IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
+    //                                      D3DTOP_DISABLE);
+    //IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
+    //                                      D3DTOP_DISABLE);
+
+    ///* Store the default render target */
+    //IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
+    //data->currentRenderTarget = NULL;
+
+    ///* Set an identity world and view matrix */
+    //matrix.m[0][0] = 1.0f;
+    //matrix.m[0][1] = 0.0f;
+    //matrix.m[0][2] = 0.0f;
+    //matrix.m[0][3] = 0.0f;
+    //matrix.m[1][0] = 0.0f;
+    //matrix.m[1][1] = 1.0f;
+    //matrix.m[1][2] = 0.0f;
+    //matrix.m[1][3] = 0.0f;
+    //matrix.m[2][0] = 0.0f;
+    //matrix.m[2][1] = 0.0f;
+    //matrix.m[2][2] = 1.0f;
+    //matrix.m[2][3] = 0.0f;
+    //matrix.m[3][0] = 0.0f;
+    //matrix.m[3][1] = 0.0f;
+    //matrix.m[3][2] = 0.0f;
+    //matrix.m[3][3] = 1.0f;
+    //IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
+    //IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
+
+    return renderer;
+}
+
+static int
+D3D11_UpdateViewport(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/render/direct3d11/SDL_render_d3d11_cpp.h	Sat Feb 02 19:32:44 2013 -0500
@@ -0,0 +1,45 @@
+/*
+  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_config.h"
+
+#include <D3D11_1.h>
+#include <wrl/client.h>
+
+typedef struct
+{
+    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice;
+    Microsoft::WRL::ComPtr<ID3D11DeviceContext1> d3dContext;
+    Microsoft::WRL::ComPtr<IDXGISwapChain1> swapChain;
+    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView;
+    Microsoft::WRL::ComPtr<ID3D11InputLayout> inputLayout;
+    Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer;
+    Microsoft::WRL::ComPtr<ID3D11VertexShader> vertexShader;
+    Microsoft::WRL::ComPtr<ID3D11PixelShader> pixelShader;
+    Microsoft::WRL::ComPtr<ID3D11Texture2D> mainTexture;
+    Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> mainTextureResourceView;
+    Microsoft::WRL::ComPtr<ID3D11SamplerState> mainSampler;
+} D3D11_RenderData;
+
+typedef struct
+{
+} D3D11_TextureData;
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sat Feb 02 19:32:44 2013 -0500
@@ -47,7 +47,8 @@
     m_windowClosed(false),
     m_windowVisible(true),
     m_sdlWindowData(NULL),
-    m_useRelativeMouseMode(false)
+    m_useRelativeMouseMode(false),
+    m_renderer(nullptr)
 {
 }
 
@@ -101,8 +102,7 @@
     window->KeyUp +=
         ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
 
-
-    m_renderer->Initialize(CoreWindow::GetForCurrentThread());
+    //m_renderer->Initialize(CoreWindow::GetForCurrentThread());    // DLudwig: moved this call to WINRT_CreateWindow, likely elsewhere in the future
 }
 
 void SDL_WinRTApp::Load(Platform::String^ entryPoint)
--- a/src/video/windowsrt/SDL_WinRTApp.h	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.h	Sat Feb 02 19:32:44 2013 -0500
@@ -47,8 +47,10 @@
     void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
     void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
 
+internal:
+    SDL_winrtrenderer^ m_renderer;
+
 private:
-    SDL_winrtrenderer^ m_renderer;
     bool m_windowClosed;
     bool m_windowVisible;
     const SDL_WindowData* m_sdlWindowData;
--- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 02 19:32:44 2013 -0500
@@ -11,7 +11,8 @@
 SDL_winrtrenderer::SDL_winrtrenderer() :
     m_mainTextureHelperSurface(NULL),
     m_loadingComplete(false),
-    m_vertexCount(0)
+    m_vertexCount(0),
+    m_sdlRendererData(NULL)
 {
 }
 
@@ -38,8 +39,9 @@
     // Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
     m_windowBounds.Width = 0;
     m_windowBounds.Height = 0;
-    m_swapChain = nullptr;
+    m_sdlRendererData->swapChain = nullptr;
 
+    // TODO, WinRT: reconnect HandleDeviceLost to SDL_Renderer
     CreateDeviceResources();
     UpdateForWindowSizeChange();
 }
@@ -90,12 +92,13 @@
         );
 
     // Get the Direct3D 11.1 API device and context interfaces.
+    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice1;
     DX::ThrowIfFailed(
-        device.As(&m_d3dDevice)
+        device.As(&(m_sdlRendererData->d3dDevice))
         );
 
     DX::ThrowIfFailed(
-        context.As(&m_d3dContext)
+        context.As(&m_sdlRendererData->d3dContext)
         );
 
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
@@ -108,11 +111,11 @@
 
     auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
         DX::ThrowIfFailed(
-            m_d3dDevice->CreateVertexShader(
+            (m_sdlRendererData->d3dDevice)->CreateVertexShader(
                 fileData->Data,
                 fileData->Length,
                 nullptr,
-                &m_vertexShader
+                &m_sdlRendererData->vertexShader
                 )
             );
 
@@ -123,23 +126,23 @@
         };
 
         DX::ThrowIfFailed(
-            m_d3dDevice->CreateInputLayout(
+            m_sdlRendererData->d3dDevice->CreateInputLayout(
                 vertexDesc,
                 ARRAYSIZE(vertexDesc),
                 fileData->Data,
                 fileData->Length,
-                &m_inputLayout
+                &m_sdlRendererData->inputLayout
                 )
             );
     });
 
     auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
         DX::ThrowIfFailed(
-            m_d3dDevice->CreatePixelShader(
+            m_sdlRendererData->d3dDevice->CreatePixelShader(
                 fileData->Data,
                 fileData->Length,
                 nullptr,
-                &m_pixelShader
+                &m_sdlRendererData->pixelShader
                 )
             );
     });
@@ -161,10 +164,10 @@
         vertexBufferData.SysMemSlicePitch = 0;
         CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
         DX::ThrowIfFailed(
-            m_d3dDevice->CreateBuffer(
+            m_sdlRendererData->d3dDevice->CreateBuffer(
                 &vertexBufferDesc,
                 &vertexBufferData,
-                &m_vertexBuffer
+                &m_sdlRendererData->vertexBuffer
                 )
             );
     });
@@ -185,9 +188,9 @@
         samplerDesc.MinLOD = 0.0f;
         samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
         DX::ThrowIfFailed(
-            m_d3dDevice->CreateSamplerState(
+            m_sdlRendererData->d3dDevice->CreateSamplerState(
                 &samplerDesc,
-                &m_mainSampler
+                &m_sdlRendererData->mainSampler
                 )
             );
     });
@@ -218,11 +221,11 @@
     m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
     m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
 
-    if(m_swapChain != nullptr)
+    if(m_sdlRendererData->swapChain != nullptr)
     {
         // If the swap chain already exists, resize it.
         DX::ThrowIfFailed(
-            m_swapChain->ResizeBuffers(
+            m_sdlRendererData->swapChain->ResizeBuffers(
                 2, // Double-buffered swap chain.
                 static_cast<UINT>(m_renderTargetSize.Width),
                 static_cast<UINT>(m_renderTargetSize.Height),
@@ -254,7 +257,7 @@
 
         ComPtr<IDXGIDevice1>  dxgiDevice;
         DX::ThrowIfFailed(
-            m_d3dDevice.As(&dxgiDevice)
+            m_sdlRendererData->d3dDevice.As(&dxgiDevice)
             );
 
         ComPtr<IDXGIAdapter> dxgiAdapter;
@@ -273,11 +276,11 @@
         Windows::UI::Core::CoreWindow^ window = m_window.Get();
         DX::ThrowIfFailed(
             dxgiFactory->CreateSwapChainForCoreWindow(
-                m_d3dDevice.Get(),
+                m_sdlRendererData->d3dDevice.Get(),
                 reinterpret_cast<IUnknown*>(window),
                 &swapChainDesc,
                 nullptr, // Allow on all displays.
-                &m_swapChain
+                &m_sdlRendererData->swapChain
                 )
             );
             
@@ -340,14 +343,14 @@
 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
     // TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method.  Check if an alternative is available, or needed.
     DX::ThrowIfFailed(
-        m_swapChain->SetRotation(rotation)
+        m_sdlRendererData->swapChain->SetRotation(rotation)
         );
 #endif
 
     // Create a render target view of the swap chain back buffer.
     ComPtr<ID3D11Texture2D> backBuffer;
     DX::ThrowIfFailed(
-        m_swapChain->GetBuffer(
+        m_sdlRendererData->swapChain->GetBuffer(
             0,
             __uuidof(ID3D11Texture2D),
             &backBuffer
@@ -355,10 +358,10 @@
         );
 
     DX::ThrowIfFailed(
-        m_d3dDevice->CreateRenderTargetView(
+        m_sdlRendererData->d3dDevice->CreateRenderTargetView(
             backBuffer.Get(),
             nullptr,
-            &m_renderTargetView
+            &m_sdlRendererData->renderTargetView
             )
         );
 
@@ -374,7 +377,7 @@
 
     ComPtr<ID3D11Texture2D> depthStencil;
     DX::ThrowIfFailed(
-        m_d3dDevice->CreateTexture2D(
+        m_sdlRendererData->d3dDevice->CreateTexture2D(
             &depthStencilDesc,
             nullptr,
             &depthStencil
@@ -389,7 +392,7 @@
         m_renderTargetSize.Height
         );
 
-    m_d3dContext->RSSetViewports(1, &viewport);
+    m_sdlRendererData->d3dContext->RSSetViewports(1, &viewport);
 }
 
 void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
@@ -425,10 +428,10 @@
     initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
     initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
     DX::ThrowIfFailed(
-        m_d3dDevice->CreateTexture2D(
+        m_sdlRendererData->d3dDevice->CreateTexture2D(
             &textureDesc,
             &initialTextureData,
-            &m_mainTexture
+            &m_sdlRendererData->mainTexture
             )
         );
 
@@ -452,10 +455,10 @@
     resourceViewDesc.Texture2D.MostDetailedMip = 0;
     resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
     DX::ThrowIfFailed(
-        m_d3dDevice->CreateShaderResourceView(
-            m_mainTexture.Get(),
+        m_sdlRendererData->d3dDevice->CreateShaderResourceView(
+            m_sdlRendererData->mainTexture.Get(),
             &resourceViewDesc,
-            &m_mainTextureResourceView)
+            &m_sdlRendererData->mainTextureResourceView)
         );
 }
 
@@ -467,9 +470,9 @@
         m_orientation != DisplayProperties::CurrentOrientation)
     {
         ID3D11RenderTargetView* nullViews[] = {nullptr};
-        m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
-        m_renderTargetView = nullptr;
-        m_d3dContext->Flush();
+        m_sdlRendererData->d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
+        m_sdlRendererData->renderTargetView = nullptr;
+        m_sdlRendererData->d3dContext->Flush();
         CreateWindowSizeDependentResources();
     }
 }
@@ -477,8 +480,8 @@
 void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
 {
     const float blackColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
-    m_d3dContext->ClearRenderTargetView(
-        m_renderTargetView.Get(),
+    m_sdlRendererData->d3dContext->ClearRenderTargetView(
+        m_sdlRendererData->renderTargetView.Get(),
         blackColor
         );
 
@@ -487,7 +490,7 @@
     {
         return;
     }
-    if (!m_mainTextureResourceView)
+    if (!m_sdlRendererData->mainTextureResourceView)
     {
         return;
     }
@@ -496,8 +499,8 @@
     // window's main texture to CPU-accessible memory:
     D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
     DX::ThrowIfFailed(
-        m_d3dContext->Map(
-            m_mainTexture.Get(),
+        m_sdlRendererData->d3dContext->Map(
+            m_sdlRendererData->mainTexture.Get(),
             0,
             D3D11_MAP_WRITE_DISCARD,
             0,
@@ -513,47 +516,47 @@
     // Clean up a bit, then commit the texture's memory back to Direct3D:
     m_mainTextureHelperSurface->pixels = NULL;
     m_mainTextureHelperSurface->pitch = 0;
-    m_d3dContext->Unmap(
-        m_mainTexture.Get(),
+    m_sdlRendererData->d3dContext->Unmap(
+        m_sdlRendererData->mainTexture.Get(),
         0);
 
-    m_d3dContext->OMSetRenderTargets(
+    m_sdlRendererData->d3dContext->OMSetRenderTargets(
         1,
-        m_renderTargetView.GetAddressOf(),
+        m_sdlRendererData->renderTargetView.GetAddressOf(),
         nullptr
         );
 
     UINT stride = sizeof(VertexPositionColor);
     UINT offset = 0;
-    m_d3dContext->IASetVertexBuffers(
+    m_sdlRendererData->d3dContext->IASetVertexBuffers(
         0,
         1,
-        m_vertexBuffer.GetAddressOf(),
+        m_sdlRendererData->vertexBuffer.GetAddressOf(),
         &stride,
         &offset
         );
 
-    m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
+    m_sdlRendererData->d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
 
-    m_d3dContext->IASetInputLayout(m_inputLayout.Get());
+    m_sdlRendererData->d3dContext->IASetInputLayout(m_sdlRendererData->inputLayout.Get());
 
-    m_d3dContext->VSSetShader(
-        m_vertexShader.Get(),
+    m_sdlRendererData->d3dContext->VSSetShader(
+        m_sdlRendererData->vertexShader.Get(),
         nullptr,
         0
         );
 
-    m_d3dContext->PSSetShader(
-        m_pixelShader.Get(),
+    m_sdlRendererData->d3dContext->PSSetShader(
+        m_sdlRendererData->pixelShader.Get(),
         nullptr,
         0
         );
 
-    m_d3dContext->PSSetShaderResources(0, 1, m_mainTextureResourceView.GetAddressOf());
+    m_sdlRendererData->d3dContext->PSSetShaderResources(0, 1, m_sdlRendererData->mainTextureResourceView.GetAddressOf());
 
-    m_d3dContext->PSSetSamplers(0, 1, m_mainSampler.GetAddressOf());
+    m_sdlRendererData->d3dContext->PSSetSamplers(0, 1, m_sdlRendererData->mainSampler.GetAddressOf());
 
-    m_d3dContext->Draw(4, 0);
+    m_sdlRendererData->d3dContext->Draw(4, 0);
 }
 
 // Method to deliver the final image to the display.
@@ -563,7 +566,7 @@
     // The first argument instructs DXGI to block until VSync, putting the application
 	// to sleep until the next VSync. This ensures we don't waste any cycles rendering
 	// frames that will never be displayed to the screen.
-	HRESULT hr = m_swapChain->Present(1, 0);
+	HRESULT hr = m_sdlRendererData->swapChain->Present(1, 0);
 #else
     // The application may optionally specify "dirty" or "scroll"
     // rects to improve efficiency in certain scenarios.
@@ -577,13 +580,13 @@
     // The first argument instructs DXGI to block until VSync, putting the application
     // to sleep until the next VSync. This ensures we don't waste any cycles rendering
     // frames that will never be displayed to the screen.
-    HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
+    HRESULT hr = m_sdlRendererData->swapChain->Present1(1, 0, &parameters);
 #endif
 
     // Discard the contents of the render target.
     // This is a valid operation only when the existing contents will be entirely
     // overwritten. If dirty or scroll rects are used, this call should be removed.
-    m_d3dContext->DiscardView(m_renderTargetView.Get());
+    m_sdlRendererData->d3dContext->DiscardView(m_sdlRendererData->renderTargetView.Get());
 
     // If the device was removed either by a disconnect or a driver upgrade, we 
     // must recreate all device resources.
--- a/src/video/windowsrt/SDL_winrtrenderer.h	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 02 19:32:44 2013 -0500
@@ -2,6 +2,7 @@
 
 #include "DirectXHelper.h"
 #include "SDL.h"
+#include "../../render/direct3d11/SDL_render_d3d11_cpp.h"
 
 struct VertexPositionColor
 {
@@ -29,20 +30,11 @@
     virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects);
     void ResizeMainTexture(int w, int h);
 
+internal:
+    // Internal SDL rendeerer (likely a temporary addition, for refactoring purposes):
+    D3D11_RenderData * m_sdlRendererData;
+
 protected private:
-    // Direct3D Objects.
-    Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
-    Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
-    Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
-    Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
-    Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
-    Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
-    Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
-    Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
-    Microsoft::WRL::ComPtr<ID3D11Texture2D> m_mainTexture;
-    Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_mainTextureResourceView;
-    Microsoft::WRL::ComPtr<ID3D11SamplerState> m_mainSampler;
-
     // UpdateWindowSurface helper objects
     SDL_Surface * m_mainTextureHelperSurface;
 
--- a/src/video/windowsrt/SDL_winrtvideo.cpp	Tue Jan 29 20:27:47 2013 -0500
+++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sat Feb 02 19:32:44 2013 -0500
@@ -34,6 +34,7 @@
 #include "../SDL_sysvideo.h"
 #include "../SDL_pixels_c.h"
 #include "../../events/SDL_events_c.h"
+#include "../../render/SDL_sysrender.h"
 }
 
 #include "SDL_WinRTApp.h"
@@ -210,6 +211,19 @@
     */
     SDL_WinRTGlobalApp->SetSDLWindowData(data);
 
+    /* For now, create a Direct3D 11 renderer up-front.  Eventually, this
+       won't be done in WINRT_CreateWindow, although it may get done in
+       SDL_WINRT_CreateWindowFramebuffer.
+    */
+
+    // Link SDL_winrtrenderer to the SDL_Renderer temporarily,
+    // for refactoring purposes.  Initialize the SDL_Renderer
+    // first in order to give it the opportunity to create key
+    // resources first.
+    SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
+    SDL_WinRTGlobalApp->m_renderer->m_sdlRendererData = (D3D11_RenderData *) renderer->driverdata;
+    SDL_WinRTGlobalApp->m_renderer->Initialize(CoreWindow::GetForCurrentThread());
+
     /* All done! */
     return 0;
 }