WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
authorDavid Ludwig <dludwig@pobox.com>
Sat, 09 Feb 2013 11:42:17 -0500
changeset 8410ba725b3a0c87
parent 8409 fd48120bd35f
child 8411 aca0591bc58f
WinRT: more code-moving from SDL_winrtrenderer* to SDL_render_d3d11*
src/render/direct3d11/SDL_render_d3d11.cpp
src/render/direct3d11/SDL_render_d3d11_cpp.h
src/video/windowsrt/SDL_winrtrenderer.cpp
src/video/windowsrt/SDL_winrtrenderer.h
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 10:43:20 2013 -0500
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 11:42:17 2013 -0500
     1.3 @@ -27,14 +27,23 @@
     1.4  #include "../../core/windows/SDL_windows.h"
     1.5  //#include "SDL_hints.h"
     1.6  //#include "SDL_loadso.h"
     1.7 +#include "SDL_system.h"
     1.8  #include "SDL_syswm.h"
     1.9  #include "../SDL_sysrender.h"
    1.10  //#include "stdio.h"
    1.11  }
    1.12  
    1.13 +#include <fstream>
    1.14 +#include <string>
    1.15 +#include <vector>
    1.16 +
    1.17  #include "SDL_render_d3d11_cpp.h"
    1.18  
    1.19 -/* Direct3D renderer implementation */
    1.20 +using namespace DirectX;
    1.21 +using namespace Microsoft::WRL;
    1.22 +using namespace std;
    1.23 +
    1.24 +/* Direct3D 11.1 renderer implementation */
    1.25  
    1.26  static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
    1.27  //static void D3D11_WindowEvent(SDL_Renderer * renderer,
    1.28 @@ -67,6 +76,9 @@
    1.29  //                               SDL_Texture * texture);
    1.30  //static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
    1.31  
    1.32 +/* Direct3D 11.1 Internal Functions */
    1.33 +HRESULT WINRT_CreateDeviceResources(SDL_Renderer * renderer);
    1.34 +
    1.35  
    1.36  extern "C" {
    1.37      SDL_RenderDriver D3D11_RenderDriver = {
    1.38 @@ -114,10 +126,12 @@
    1.39  
    1.40      data = new D3D11_RenderData;    // Use the C++ 'new' operator to make sure the struct's members initialize using C++ rules
    1.41      if (!data) {
    1.42 -        delete data;
    1.43          SDL_OutOfMemory();
    1.44          return NULL;
    1.45      }
    1.46 +    data->featureLevel = (D3D_FEATURE_LEVEL) 0;
    1.47 +    data->vertexCount = 0;
    1.48 +    data->loadingComplete = false;
    1.49  
    1.50      // TODO: Create Direct3D Object(s)
    1.51  
    1.52 @@ -280,6 +294,224 @@
    1.53      return renderer;
    1.54  }
    1.55  
    1.56 +static bool
    1.57 +D3D11_ReadFileContents(const wstring & fileName, vector<char> & out)
    1.58 +{
    1.59 +    ifstream in(fileName, ios::in | ios::binary);
    1.60 +    if (!in) {
    1.61 +        return false;
    1.62 +    }
    1.63 +
    1.64 +    in.seekg(0, ios::end);
    1.65 +    out.resize((size_t) in.tellg());
    1.66 +    in.seekg(0, ios::beg);
    1.67 +    in.read(&out[0], out.size());
    1.68 +    return in.good();
    1.69 +}
    1.70 +
    1.71 +static bool
    1.72 +D3D11_ReadShaderContents(const wstring & shaderName, vector<char> & out)
    1.73 +{
    1.74 +    wstring fileName;
    1.75 +
    1.76 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    1.77 +    fileName = SDL_WinRTGetInstalledLocationPath();
    1.78 +    fileName += L"\\SDL_VS2012_WinRT\\";
    1.79 +#elif WINAPI_FAMILY == WINAPI_PHONE_APP
    1.80 +    fileName = SDL_WinRTGetInstalledLocationPath();
    1.81 +    fileName += L"\\";
    1.82 +#endif
    1.83 +    // WinRT, TODO: test Direct3D 11.1 shader loading on Win32
    1.84 +    fileName += shaderName;
    1.85 +    return D3D11_ReadFileContents(fileName, out);
    1.86 +}
    1.87 +
    1.88 +HRESULT
    1.89 +WINRT_CreateDeviceResources(SDL_Renderer * renderer)
    1.90 +{
    1.91 +    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
    1.92 +
    1.93 +    // This flag adds support for surfaces with a different color channel ordering
    1.94 +    // than the API default. It is required for compatibility with Direct2D.
    1.95 +    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    1.96 +
    1.97 +#if defined(_DEBUG)
    1.98 +    // If the project is in a debug build, enable debugging via SDK Layers with this flag.
    1.99 +    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
   1.100 +#endif
   1.101 +
   1.102 +    // This array defines the set of DirectX hardware feature levels this app will support.
   1.103 +    // Note the ordering should be preserved.
   1.104 +    // Don't forget to declare your application's minimum required feature level in its
   1.105 +    // description.  All applications are assumed to support 9.1 unless otherwise stated.
   1.106 +    D3D_FEATURE_LEVEL featureLevels[] = 
   1.107 +    {
   1.108 +        D3D_FEATURE_LEVEL_11_1,
   1.109 +        D3D_FEATURE_LEVEL_11_0,
   1.110 +        D3D_FEATURE_LEVEL_10_1,
   1.111 +        D3D_FEATURE_LEVEL_10_0,
   1.112 +        D3D_FEATURE_LEVEL_9_3,
   1.113 +        D3D_FEATURE_LEVEL_9_2,
   1.114 +        D3D_FEATURE_LEVEL_9_1
   1.115 +    };
   1.116 +
   1.117 +    // Create the Direct3D 11 API device object and a corresponding context.
   1.118 +    ComPtr<ID3D11Device> device;
   1.119 +    ComPtr<ID3D11DeviceContext> context;
   1.120 +    HRESULT result = S_OK;
   1.121 +    result = D3D11CreateDevice(
   1.122 +        nullptr, // Specify nullptr to use the default adapter.
   1.123 +        D3D_DRIVER_TYPE_HARDWARE,
   1.124 +        nullptr,
   1.125 +        creationFlags, // Set set debug and Direct2D compatibility flags.
   1.126 +        featureLevels, // List of feature levels this app can support.
   1.127 +        ARRAYSIZE(featureLevels),
   1.128 +        D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
   1.129 +        &device, // Returns the Direct3D device created.
   1.130 +        &data->featureLevel, // Returns feature level of device created.
   1.131 +        &context // Returns the device immediate context.
   1.132 +        );
   1.133 +    if (FAILED(result)) {
   1.134 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.135 +        return result;
   1.136 +    }
   1.137 +
   1.138 +    // Get the Direct3D 11.1 API device and context interfaces.
   1.139 +    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice1;
   1.140 +    result = device.As(&(data->d3dDevice));
   1.141 +    if (FAILED(result)) {
   1.142 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.143 +        return result;
   1.144 +    }
   1.145 +
   1.146 +    result = context.As(&data->d3dContext);
   1.147 +    if (FAILED(result)) {
   1.148 +        return result;
   1.149 +    }
   1.150 +
   1.151 +    // Start loading GPU shaders:
   1.152 +    vector<char> fileData;
   1.153 +
   1.154 +    //
   1.155 +    // Load in SDL's one and only vertex shader:
   1.156 +    //
   1.157 +    if (!D3D11_ReadShaderContents(L"SimpleVertexShader.cso", fileData)) {
   1.158 +        SDL_SetError("Unable to open SDL's vertex shader file.");
   1.159 +        return E_FAIL;
   1.160 +    }
   1.161 +
   1.162 +    result = data->d3dDevice->CreateVertexShader(
   1.163 +        &fileData[0],
   1.164 +        fileData.size(),
   1.165 +        nullptr,
   1.166 +        &data->vertexShader
   1.167 +        );
   1.168 +    if (FAILED(result)) {
   1.169 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.170 +        return result;
   1.171 +    }
   1.172 +
   1.173 +    //
   1.174 +    // Create an input layout for SDL's vertex shader:
   1.175 +    //
   1.176 +    const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
   1.177 +    {
   1.178 +        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
   1.179 +        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
   1.180 +    };
   1.181 +
   1.182 +    result = data->d3dDevice->CreateInputLayout(
   1.183 +        vertexDesc,
   1.184 +        ARRAYSIZE(vertexDesc),
   1.185 +        &fileData[0],
   1.186 +        fileData.size(),
   1.187 +        &data->inputLayout
   1.188 +        );
   1.189 +    if (FAILED(result)) {
   1.190 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.191 +        return result;
   1.192 +    }
   1.193 +
   1.194 +    //
   1.195 +    // Load in SDL's one and only pixel shader (for now, more are likely to follow):
   1.196 +    //
   1.197 +    if (!D3D11_ReadShaderContents(L"SimplePixelShader.cso", fileData)) {
   1.198 +        SDL_SetError("Unable to open SDL's pixel shader file.");
   1.199 +        return E_FAIL;
   1.200 +    }
   1.201 +
   1.202 +    result = data->d3dDevice->CreatePixelShader(
   1.203 +        &fileData[0],
   1.204 +        fileData.size(),
   1.205 +        nullptr,
   1.206 +        &data->pixelShader
   1.207 +        );
   1.208 +    if (FAILED(result)) {
   1.209 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.210 +        return result;
   1.211 +    }
   1.212 +
   1.213 +    //
   1.214 +    // Create a vertex buffer:
   1.215 +    //
   1.216 +    VertexPositionColor vertices[] = 
   1.217 +    {
   1.218 +        {XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
   1.219 +        {XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
   1.220 +        {XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
   1.221 +        {XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
   1.222 +    };
   1.223 +
   1.224 +    data->vertexCount = ARRAYSIZE(vertices);
   1.225 +
   1.226 +    D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
   1.227 +    vertexBufferData.pSysMem = vertices;
   1.228 +    vertexBufferData.SysMemPitch = 0;
   1.229 +    vertexBufferData.SysMemSlicePitch = 0;
   1.230 +    CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
   1.231 +    result = data->d3dDevice->CreateBuffer(
   1.232 +        &vertexBufferDesc,
   1.233 +        &vertexBufferData,
   1.234 +        &data->vertexBuffer
   1.235 +        );
   1.236 +    if (FAILED(result)) {
   1.237 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.238 +        return result;
   1.239 +    }
   1.240 +
   1.241 +    //
   1.242 +    // Create a sampler to use when drawing textures:
   1.243 +    //
   1.244 +    D3D11_SAMPLER_DESC samplerDesc;
   1.245 +    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
   1.246 +    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
   1.247 +    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
   1.248 +    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
   1.249 +    samplerDesc.MipLODBias = 0.0f;
   1.250 +    samplerDesc.MaxAnisotropy = 1;
   1.251 +    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
   1.252 +    samplerDesc.BorderColor[0] = 0.0f;
   1.253 +    samplerDesc.BorderColor[1] = 0.0f;
   1.254 +    samplerDesc.BorderColor[2] = 0.0f;
   1.255 +    samplerDesc.BorderColor[3] = 0.0f;
   1.256 +    samplerDesc.MinLOD = 0.0f;
   1.257 +    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
   1.258 +    result = data->d3dDevice->CreateSamplerState(
   1.259 +        &samplerDesc,
   1.260 +        &data->mainSampler
   1.261 +        );
   1.262 +    if (FAILED(result)) {
   1.263 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   1.264 +        return result;
   1.265 +    }
   1.266 +
   1.267 +    //
   1.268 +    // All done!
   1.269 +    //
   1.270 +    data->loadingComplete = true;       // This variable can probably be factored-out
   1.271 +    return S_OK;
   1.272 +}
   1.273 +
   1.274  static int
   1.275  D3D11_UpdateViewport(SDL_Renderer * renderer)
   1.276  {
     2.1 --- a/src/render/direct3d11/SDL_render_d3d11_cpp.h	Sat Feb 09 10:43:20 2013 -0500
     2.2 +++ b/src/render/direct3d11/SDL_render_d3d11_cpp.h	Sat Feb 09 11:42:17 2013 -0500
     2.3 @@ -21,6 +21,7 @@
     2.4  #include "SDL_config.h"
     2.5  
     2.6  #include <D3D11_1.h>
     2.7 +#include <DirectXMath.h>
     2.8  #include <wrl/client.h>
     2.9  
    2.10  typedef struct
    2.11 @@ -36,10 +37,19 @@
    2.12      Microsoft::WRL::ComPtr<ID3D11Texture2D> mainTexture;
    2.13      Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> mainTextureResourceView;
    2.14      Microsoft::WRL::ComPtr<ID3D11SamplerState> mainSampler;
    2.15 +    D3D_FEATURE_LEVEL featureLevel;
    2.16 +    unsigned int vertexCount;
    2.17 +    bool loadingComplete;
    2.18  } D3D11_RenderData;
    2.19  
    2.20  typedef struct
    2.21  {
    2.22  } D3D11_TextureData;
    2.23  
    2.24 +struct VertexPositionColor
    2.25 +{
    2.26 +    DirectX::XMFLOAT3 pos;
    2.27 +    DirectX::XMFLOAT2 tex;
    2.28 +};
    2.29 +
    2.30  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 09 10:43:20 2013 -0500
     3.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Sat Feb 09 11:42:17 2013 -0500
     3.3 @@ -15,8 +15,6 @@
     3.4  // Constructor.
     3.5  SDL_winrtrenderer::SDL_winrtrenderer() :
     3.6      m_mainTextureHelperSurface(NULL),
     3.7 -    m_loadingComplete(false),
     3.8 -    m_vertexCount(0),
     3.9      m_sdlRenderer(NULL),
    3.10      m_sdlRendererData(NULL)
    3.11  {
    3.12 @@ -52,197 +50,12 @@
    3.13      UpdateForWindowSizeChange();
    3.14  }
    3.15  
    3.16 -static bool
    3.17 -read_file_contents(const wstring & fileName, vector<char> & out)
    3.18 -{
    3.19 -    ifstream in(fileName, ios::in | ios::binary);
    3.20 -    if (!in) {
    3.21 -        return false;
    3.22 -    }
    3.23 -
    3.24 -    in.seekg(0, ios::end);
    3.25 -    out.resize((size_t) in.tellg());
    3.26 -    in.seekg(0, ios::beg);
    3.27 -    in.read(&out[0], out.size());
    3.28 -    return in.good();
    3.29 -}
    3.30 -
    3.31 -static bool
    3.32 -read_shader_contents(const wstring & shaderName, vector<char> & out)
    3.33 -{
    3.34 -    wstring fileName = SDL_WinRTGetInstalledLocationPath();
    3.35 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    3.36 -    fileName += L"\\";
    3.37 -#else
    3.38 -    fileName += L"\\SDL_VS2012_WinRT\\";
    3.39 -#endif
    3.40 -    fileName += shaderName;
    3.41 -    return read_file_contents(fileName, out);
    3.42 -}
    3.43 +extern HRESULT WINRT_CreateDeviceResources(SDL_Renderer * renderer);
    3.44  
    3.45  // These are the resources that depend on the device.
    3.46  void SDL_winrtrenderer::CreateDeviceResources()
    3.47  {
    3.48 -    // This flag adds support for surfaces with a different color channel ordering
    3.49 -    // than the API default. It is required for compatibility with Direct2D.
    3.50 -    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    3.51 -
    3.52 -#if defined(_DEBUG)
    3.53 -    // If the project is in a debug build, enable debugging via SDK Layers with this flag.
    3.54 -    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
    3.55 -#endif
    3.56 -
    3.57 -    // This array defines the set of DirectX hardware feature levels this app will support.
    3.58 -    // Note the ordering should be preserved.
    3.59 -    // Don't forget to declare your application's minimum required feature level in its
    3.60 -    // description.  All applications are assumed to support 9.1 unless otherwise stated.
    3.61 -    D3D_FEATURE_LEVEL featureLevels[] = 
    3.62 -    {
    3.63 -        D3D_FEATURE_LEVEL_11_1,
    3.64 -        D3D_FEATURE_LEVEL_11_0,
    3.65 -        D3D_FEATURE_LEVEL_10_1,
    3.66 -        D3D_FEATURE_LEVEL_10_0,
    3.67 -        D3D_FEATURE_LEVEL_9_3,
    3.68 -        D3D_FEATURE_LEVEL_9_2,
    3.69 -        D3D_FEATURE_LEVEL_9_1
    3.70 -    };
    3.71 -
    3.72 -    // Create the Direct3D 11 API device object and a corresponding context.
    3.73 -    ComPtr<ID3D11Device> device;
    3.74 -    ComPtr<ID3D11DeviceContext> context;
    3.75 -    DX::ThrowIfFailed(
    3.76 -        D3D11CreateDevice(
    3.77 -            nullptr, // Specify nullptr to use the default adapter.
    3.78 -            D3D_DRIVER_TYPE_HARDWARE,
    3.79 -            nullptr,
    3.80 -            creationFlags, // Set set debug and Direct2D compatibility flags.
    3.81 -            featureLevels, // List of feature levels this app can support.
    3.82 -            ARRAYSIZE(featureLevels),
    3.83 -            D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
    3.84 -            &device, // Returns the Direct3D device created.
    3.85 -            &m_featureLevel, // Returns feature level of device created.
    3.86 -            &context // Returns the device immediate context.
    3.87 -            )
    3.88 -        );
    3.89 -
    3.90 -    // Get the Direct3D 11.1 API device and context interfaces.
    3.91 -    Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice1;
    3.92 -    DX::ThrowIfFailed(
    3.93 -        device.As(&(m_sdlRendererData->d3dDevice))
    3.94 -        );
    3.95 -
    3.96 -    DX::ThrowIfFailed(
    3.97 -        context.As(&m_sdlRendererData->d3dContext)
    3.98 -        );
    3.99 -
   3.100 -    // Start loading GPU shaders:
   3.101 -    vector<char> fileData;
   3.102 -
   3.103 -    //
   3.104 -    // Load in SDL's one and only vertex shader:
   3.105 -    //
   3.106 -    if (!read_shader_contents(L"SimpleVertexShader.cso", fileData)) {
   3.107 -        throw ref new Platform::Exception(E_FAIL, L"Unable to open SDL's vertex shader file.");
   3.108 -    }
   3.109 -
   3.110 -    DX::ThrowIfFailed(
   3.111 -        (m_sdlRendererData->d3dDevice)->CreateVertexShader(
   3.112 -            &fileData[0],
   3.113 -            fileData.size(),
   3.114 -            nullptr,
   3.115 -            &m_sdlRendererData->vertexShader
   3.116 -            )
   3.117 -        );
   3.118 -
   3.119 -    //
   3.120 -    // Create an input layout for SDL's vertex shader:
   3.121 -    //
   3.122 -    const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
   3.123 -    {
   3.124 -        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
   3.125 -        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
   3.126 -    };
   3.127 -
   3.128 -    DX::ThrowIfFailed(
   3.129 -        m_sdlRendererData->d3dDevice->CreateInputLayout(
   3.130 -            vertexDesc,
   3.131 -            ARRAYSIZE(vertexDesc),
   3.132 -            &fileData[0],
   3.133 -            fileData.size(),
   3.134 -            &m_sdlRendererData->inputLayout
   3.135 -            )
   3.136 -        );
   3.137 -
   3.138 -    //
   3.139 -    // Load in SDL's one and only pixel shader (for now, more are likely to follow):
   3.140 -    //
   3.141 -    if (!read_shader_contents(L"SimplePixelShader.cso", fileData)) {
   3.142 -        throw ref new Platform::Exception(E_FAIL, L"Unable to open SDL's pixel shader file.");
   3.143 -    }
   3.144 -
   3.145 -    DX::ThrowIfFailed(
   3.146 -        m_sdlRendererData->d3dDevice->CreatePixelShader(
   3.147 -            &fileData[0],
   3.148 -            fileData.size(),
   3.149 -            nullptr,
   3.150 -            &m_sdlRendererData->pixelShader
   3.151 -            )
   3.152 -        );
   3.153 -
   3.154 -    //
   3.155 -    // Create a vertex buffer:
   3.156 -    //
   3.157 -    VertexPositionColor vertices[] = 
   3.158 -    {
   3.159 -        {XMFLOAT3(-1.0f, -1.0f, 0.0f),  XMFLOAT2(0.0f, 1.0f)},
   3.160 -        {XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
   3.161 -        {XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
   3.162 -        {XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
   3.163 -    };
   3.164 -
   3.165 -    m_vertexCount = ARRAYSIZE(vertices);
   3.166 -
   3.167 -    D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
   3.168 -    vertexBufferData.pSysMem = vertices;
   3.169 -    vertexBufferData.SysMemPitch = 0;
   3.170 -    vertexBufferData.SysMemSlicePitch = 0;
   3.171 -    CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
   3.172 -    DX::ThrowIfFailed(
   3.173 -        m_sdlRendererData->d3dDevice->CreateBuffer(
   3.174 -            &vertexBufferDesc,
   3.175 -            &vertexBufferData,
   3.176 -            &m_sdlRendererData->vertexBuffer
   3.177 -            )
   3.178 -        );
   3.179 -
   3.180 -    //
   3.181 -    // Create a sampler to use when drawing textures:
   3.182 -    //
   3.183 -    D3D11_SAMPLER_DESC samplerDesc;
   3.184 -    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
   3.185 -    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
   3.186 -    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
   3.187 -    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
   3.188 -    samplerDesc.MipLODBias = 0.0f;
   3.189 -    samplerDesc.MaxAnisotropy = 1;
   3.190 -    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
   3.191 -    samplerDesc.BorderColor[0] = 0.0f;
   3.192 -    samplerDesc.BorderColor[1] = 0.0f;
   3.193 -    samplerDesc.BorderColor[2] = 0.0f;
   3.194 -    samplerDesc.BorderColor[3] = 0.0f;
   3.195 -    samplerDesc.MinLOD = 0.0f;
   3.196 -    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
   3.197 -    DX::ThrowIfFailed(
   3.198 -        m_sdlRendererData->d3dDevice->CreateSamplerState(
   3.199 -            &samplerDesc,
   3.200 -            &m_sdlRendererData->mainSampler
   3.201 -            )
   3.202 -        );
   3.203 -
   3.204 -    //
   3.205 -    // All done!
   3.206 -    //
   3.207 -    m_loadingComplete = true;       // This variable can probably be factored-out
   3.208 +    DX::ThrowIfFailed(WINRT_CreateDeviceResources(m_sdlRenderer));
   3.209  }
   3.210  
   3.211  // Allocate all memory resources that change on a window SizeChanged event.
   3.212 @@ -531,7 +344,7 @@
   3.213          );
   3.214  
   3.215      // Only draw the screen once it is loaded (some loading is asynchronous).
   3.216 -    if (!m_loadingComplete)
   3.217 +    if (!m_sdlRendererData->loadingComplete)
   3.218      {
   3.219          return;
   3.220      }
     4.1 --- a/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 09 10:43:20 2013 -0500
     4.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.h	Sat Feb 09 11:42:17 2013 -0500
     4.3 @@ -4,12 +4,6 @@
     4.4  #include "SDL.h"
     4.5  #include "../../render/direct3d11/SDL_render_d3d11_cpp.h"
     4.6  
     4.7 -struct VertexPositionColor
     4.8 -{
     4.9 -    DirectX::XMFLOAT3 pos;
    4.10 -    DirectX::XMFLOAT2 tex;
    4.11 -};
    4.12 -
    4.13  // Helper class that initializes DirectX APIs for 3D rendering.
    4.14  ref class SDL_winrtrenderer
    4.15  {
    4.16 @@ -40,12 +34,10 @@
    4.17      SDL_Surface * m_mainTextureHelperSurface;
    4.18  
    4.19      // Cached renderer properties.
    4.20 -    D3D_FEATURE_LEVEL m_featureLevel;
    4.21      Windows::Foundation::Size m_renderTargetSize;
    4.22      Windows::Foundation::Rect m_windowBounds;
    4.23      Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
    4.24      Windows::Graphics::Display::DisplayOrientations m_orientation;
    4.25 -    uint32 m_vertexCount;
    4.26  
    4.27      // Transform used for display orientation.
    4.28      DirectX::XMFLOAT4X4 m_orientationTransform3D;