WinRT: created SDLmain library using most of VC++ 2012's template for Direct3D 11 apps. Most of this will be moved into SDL itself.
authorDavid Ludwig <dludwig@pobox.com>
Sat, 27 Oct 2012 20:12:31 -0400
changeset 8321d95a438e6c84
parent 8320 e9db1532c340
child 8322 839cd578a474
WinRT: created SDLmain library using most of VC++ 2012's template for Direct3D 11 apps. Most of this will be moved into SDL itself.
VisualC/SDLmain/SDLmain_VS2012_WinRT.vcxproj
src/main/windowsrt/BasicTimer.h
src/main/windowsrt/CubeRenderer.cpp
src/main/windowsrt/CubeRenderer.h
src/main/windowsrt/Direct3DBase.cpp
src/main/windowsrt/Direct3DBase.h
src/main/windowsrt/DirectXHelper.h
src/main/windowsrt/SDL_WinRTApp.cpp
src/main/windowsrt/SDL_WinRTApp.h
src/main/windowsrt/SDLmain_WinRT_common.h
src/main/windowsrt/SimplePixelShader.hlsl
src/main/windowsrt/SimpleVertexShader.hlsl
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/VisualC/SDLmain/SDLmain_VS2012_WinRT.vcxproj	Sat Oct 27 20:12:31 2012 -0400
     1.3 @@ -0,0 +1,199 @@
     1.4 +<?xml version="1.0" encoding="utf-8"?>
     1.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     1.6 +  <ItemGroup Label="ProjectConfigurations">
     1.7 +    <ProjectConfiguration Include="Debug|ARM">
     1.8 +      <Configuration>Debug</Configuration>
     1.9 +      <Platform>ARM</Platform>
    1.10 +    </ProjectConfiguration>
    1.11 +    <ProjectConfiguration Include="Debug|Win32">
    1.12 +      <Configuration>Debug</Configuration>
    1.13 +      <Platform>Win32</Platform>
    1.14 +    </ProjectConfiguration>
    1.15 +    <ProjectConfiguration Include="Debug|x64">
    1.16 +      <Configuration>Debug</Configuration>
    1.17 +      <Platform>x64</Platform>
    1.18 +    </ProjectConfiguration>
    1.19 +    <ProjectConfiguration Include="Release|ARM">
    1.20 +      <Configuration>Release</Configuration>
    1.21 +      <Platform>ARM</Platform>
    1.22 +    </ProjectConfiguration>
    1.23 +    <ProjectConfiguration Include="Release|Win32">
    1.24 +      <Configuration>Release</Configuration>
    1.25 +      <Platform>Win32</Platform>
    1.26 +    </ProjectConfiguration>
    1.27 +    <ProjectConfiguration Include="Release|x64">
    1.28 +      <Configuration>Release</Configuration>
    1.29 +      <Platform>x64</Platform>
    1.30 +    </ProjectConfiguration>
    1.31 +  </ItemGroup>
    1.32 +  <ItemGroup>
    1.33 +    <ClInclude Include="..\..\src\main\windowsrt\BasicTimer.h" />
    1.34 +    <ClInclude Include="..\..\src\main\windowsrt\CubeRenderer.h" />
    1.35 +    <ClInclude Include="..\..\src\main\windowsrt\Direct3DBase.h" />
    1.36 +    <ClInclude Include="..\..\src\main\windowsrt\DirectXHelper.h" />
    1.37 +    <ClInclude Include="..\..\src\main\windowsrt\SDLmain_WinRT_common.h" />
    1.38 +    <ClInclude Include="..\..\src\main\windowsrt\SDL_WinRTApp.h" />
    1.39 +  </ItemGroup>
    1.40 +  <ItemGroup>
    1.41 +    <ClCompile Include="..\..\src\main\windowsrt\CubeRenderer.cpp" />
    1.42 +    <ClCompile Include="..\..\src\main\windowsrt\Direct3DBase.cpp" />
    1.43 +    <ClCompile Include="..\..\src\main\windowsrt\SDL_WinRTApp.cpp" />
    1.44 +  </ItemGroup>
    1.45 +  <PropertyGroup Label="Globals">
    1.46 +    <ProjectGuid>{48666378-b527-43f5-8968-f867a6f8d2a3}</ProjectGuid>
    1.47 +    <Keyword>Win32Proj</Keyword>
    1.48 +    <ProjectName>SDLmain_VS2012_WinRT</ProjectName>
    1.49 +    <RootNamespace>SDLmain_VS2012_WinRT</RootNamespace>
    1.50 +    <DefaultLanguage>en-US</DefaultLanguage>
    1.51 +    <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
    1.52 +    <AppContainerApplication>true</AppContainerApplication>
    1.53 +  </PropertyGroup>
    1.54 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    1.55 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    1.56 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.57 +    <UseDebugLibraries>true</UseDebugLibraries>
    1.58 +    <PlatformToolset>v110</PlatformToolset>
    1.59 +  </PropertyGroup>
    1.60 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
    1.61 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.62 +    <UseDebugLibraries>true</UseDebugLibraries>
    1.63 +    <PlatformToolset>v110</PlatformToolset>
    1.64 +  </PropertyGroup>
    1.65 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    1.66 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.67 +    <UseDebugLibraries>true</UseDebugLibraries>
    1.68 +    <PlatformToolset>v110</PlatformToolset>
    1.69 +  </PropertyGroup>
    1.70 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    1.71 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.72 +    <UseDebugLibraries>false</UseDebugLibraries>
    1.73 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    1.74 +    <PlatformToolset>v110</PlatformToolset>
    1.75 +  </PropertyGroup>
    1.76 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
    1.77 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.78 +    <UseDebugLibraries>false</UseDebugLibraries>
    1.79 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    1.80 +    <PlatformToolset>v110</PlatformToolset>
    1.81 +  </PropertyGroup>
    1.82 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    1.83 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    1.84 +    <UseDebugLibraries>false</UseDebugLibraries>
    1.85 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    1.86 +    <PlatformToolset>v110</PlatformToolset>
    1.87 +  </PropertyGroup>
    1.88 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    1.89 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    1.90 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    1.91 +  </ImportGroup>
    1.92 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    1.93 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    1.94 +  </ImportGroup>
    1.95 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
    1.96 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    1.97 +  </ImportGroup>
    1.98 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
    1.99 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   1.100 +  </ImportGroup>
   1.101 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   1.102 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   1.103 +  </ImportGroup>
   1.104 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   1.105 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   1.106 +  </ImportGroup>
   1.107 +  <PropertyGroup Label="UserMacros" />
   1.108 +  <PropertyGroup />
   1.109 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
   1.110 +    <GenerateManifest>false</GenerateManifest>
   1.111 +  </PropertyGroup>
   1.112 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   1.113 +    <GenerateManifest>false</GenerateManifest>
   1.114 +  </PropertyGroup>
   1.115 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
   1.116 +    <GenerateManifest>false</GenerateManifest>
   1.117 +  </PropertyGroup>
   1.118 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
   1.119 +    <GenerateManifest>false</GenerateManifest>
   1.120 +  </PropertyGroup>
   1.121 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   1.122 +    <GenerateManifest>false</GenerateManifest>
   1.123 +  </PropertyGroup>
   1.124 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   1.125 +    <GenerateManifest>false</GenerateManifest>
   1.126 +  </PropertyGroup>
   1.127 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
   1.128 +    <ClCompile>
   1.129 +      <PrecompiledHeader>NotUsing</PrecompiledHeader>
   1.130 +      <CompileAsWinRT>true</CompileAsWinRT>
   1.131 +      <SDLCheck>true</SDLCheck>
   1.132 +    </ClCompile>
   1.133 +    <Link>
   1.134 +      <SubSystem>Console</SubSystem>
   1.135 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.136 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.137 +    </Link>
   1.138 +  </ItemDefinitionGroup>
   1.139 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   1.140 +    <ClCompile>
   1.141 +      <PrecompiledHeader>NotUsing</PrecompiledHeader>
   1.142 +      <CompileAsWinRT>true</CompileAsWinRT>
   1.143 +      <SDLCheck>true</SDLCheck>
   1.144 +    </ClCompile>
   1.145 +    <Link>
   1.146 +      <SubSystem>Console</SubSystem>
   1.147 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.148 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.149 +    </Link>
   1.150 +  </ItemDefinitionGroup>
   1.151 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
   1.152 +    <ClCompile>
   1.153 +      <PrecompiledHeader>Use</PrecompiledHeader>
   1.154 +      <CompileAsWinRT>false</CompileAsWinRT>
   1.155 +      <SDLCheck>true</SDLCheck>
   1.156 +    </ClCompile>
   1.157 +    <Link>
   1.158 +      <SubSystem>Console</SubSystem>
   1.159 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.160 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.161 +    </Link>
   1.162 +  </ItemDefinitionGroup>
   1.163 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm'">
   1.164 +    <ClCompile>
   1.165 +      <PrecompiledHeader>Use</PrecompiledHeader>
   1.166 +      <CompileAsWinRT>false</CompileAsWinRT>
   1.167 +      <SDLCheck>true</SDLCheck>
   1.168 +    </ClCompile>
   1.169 +    <Link>
   1.170 +      <SubSystem>Console</SubSystem>
   1.171 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.172 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.173 +    </Link>
   1.174 +  </ItemDefinitionGroup>
   1.175 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   1.176 +    <ClCompile>
   1.177 +      <PrecompiledHeader>Use</PrecompiledHeader>
   1.178 +      <CompileAsWinRT>false</CompileAsWinRT>
   1.179 +      <SDLCheck>true</SDLCheck>
   1.180 +    </ClCompile>
   1.181 +    <Link>
   1.182 +      <SubSystem>Console</SubSystem>
   1.183 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.184 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.185 +    </Link>
   1.186 +  </ItemDefinitionGroup>
   1.187 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   1.188 +    <ClCompile>
   1.189 +      <PrecompiledHeader>Use</PrecompiledHeader>
   1.190 +      <CompileAsWinRT>false</CompileAsWinRT>
   1.191 +      <SDLCheck>true</SDLCheck>
   1.192 +    </ClCompile>
   1.193 +    <Link>
   1.194 +      <SubSystem>Console</SubSystem>
   1.195 +      <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
   1.196 +      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
   1.197 +    </Link>
   1.198 +  </ItemDefinitionGroup>
   1.199 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   1.200 +  <ImportGroup Label="ExtensionTargets">
   1.201 +  </ImportGroup>
   1.202 +</Project>
   1.203 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/main/windowsrt/BasicTimer.h	Sat Oct 27 20:12:31 2012 -0400
     2.3 @@ -0,0 +1,76 @@
     2.4 +#pragma once
     2.5 +
     2.6 +#include <wrl.h>
     2.7 +
     2.8 +// Helper class for basic timing.
     2.9 +ref class BasicTimer sealed
    2.10 +{
    2.11 +public:
    2.12 +	// Initializes internal timer values.
    2.13 +	BasicTimer()
    2.14 +	{
    2.15 +		if (!QueryPerformanceFrequency(&m_frequency))
    2.16 +		{
    2.17 +			throw ref new Platform::FailureException();
    2.18 +		}
    2.19 +		Reset();
    2.20 +	}
    2.21 +	
    2.22 +	// Reset the timer to initial values.
    2.23 +	void Reset()
    2.24 +	{
    2.25 +		Update();
    2.26 +		m_startTime = m_currentTime;
    2.27 +		m_total = 0.0f;
    2.28 +		m_delta = 1.0f / 60.0f;
    2.29 +	}
    2.30 +	
    2.31 +	// Update the timer's internal values.
    2.32 +	void Update()
    2.33 +	{
    2.34 +		if (!QueryPerformanceCounter(&m_currentTime))
    2.35 +		{
    2.36 +			throw ref new Platform::FailureException();
    2.37 +		}
    2.38 +		
    2.39 +		m_total = static_cast<float>(
    2.40 +			static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) /
    2.41 +			static_cast<double>(m_frequency.QuadPart)
    2.42 +			);
    2.43 +		
    2.44 +		if (m_lastTime.QuadPart == m_startTime.QuadPart)
    2.45 +		{
    2.46 +			// If the timer was just reset, report a time delta equivalent to 60Hz frame time.
    2.47 +			m_delta = 1.0f / 60.0f;
    2.48 +		}
    2.49 +		else
    2.50 +		{
    2.51 +			m_delta = static_cast<float>(
    2.52 +				static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) /
    2.53 +				static_cast<double>(m_frequency.QuadPart)
    2.54 +				);
    2.55 +		}
    2.56 +		
    2.57 +		m_lastTime = m_currentTime;
    2.58 +	}
    2.59 +	
    2.60 +	// Duration in seconds between the last call to Reset() and the last call to Update().
    2.61 +	property float Total
    2.62 +	{
    2.63 +		float get() { return m_total; }
    2.64 +	}
    2.65 +	
    2.66 +	// Duration in seconds between the previous two calls to Update().
    2.67 +	property float Delta
    2.68 +	{
    2.69 +		float get() { return m_delta; }
    2.70 +	}
    2.71 +
    2.72 +private:
    2.73 +	LARGE_INTEGER m_frequency;
    2.74 +	LARGE_INTEGER m_currentTime;
    2.75 +	LARGE_INTEGER m_startTime;
    2.76 +	LARGE_INTEGER m_lastTime;
    2.77 +	float m_total;
    2.78 +	float m_delta;
    2.79 +};
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main/windowsrt/CubeRenderer.cpp	Sat Oct 27 20:12:31 2012 -0400
     3.3 @@ -0,0 +1,256 @@
     3.4 +#include "SDLmain_WinRT_common.h"
     3.5 +#include "CubeRenderer.h"
     3.6 +
     3.7 +using namespace DirectX;
     3.8 +using namespace Microsoft::WRL;
     3.9 +using namespace Windows::Foundation;
    3.10 +using namespace Windows::UI::Core;
    3.11 +
    3.12 +CubeRenderer::CubeRenderer() :
    3.13 +	m_loadingComplete(false),
    3.14 +	m_indexCount(0)
    3.15 +{
    3.16 +}
    3.17 +
    3.18 +void CubeRenderer::CreateDeviceResources()
    3.19 +{
    3.20 +	Direct3DBase::CreateDeviceResources();
    3.21 +
    3.22 +	auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
    3.23 +	auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
    3.24 +
    3.25 +	auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
    3.26 +		DX::ThrowIfFailed(
    3.27 +			m_d3dDevice->CreateVertexShader(
    3.28 + 				fileData->Data,
    3.29 +				fileData->Length,
    3.30 +				nullptr,
    3.31 +				&m_vertexShader
    3.32 +				)
    3.33 +			);
    3.34 +
    3.35 +		const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
    3.36 +		{
    3.37 +			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
    3.38 +			{ "COLOR",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    3.39 +		};
    3.40 +
    3.41 +		DX::ThrowIfFailed(
    3.42 +			m_d3dDevice->CreateInputLayout(
    3.43 +				vertexDesc,
    3.44 +				ARRAYSIZE(vertexDesc),
    3.45 +				fileData->Data,
    3.46 +				fileData->Length,
    3.47 +				&m_inputLayout
    3.48 +				)
    3.49 +			);
    3.50 +	});
    3.51 +
    3.52 +	auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
    3.53 +		DX::ThrowIfFailed(
    3.54 +			m_d3dDevice->CreatePixelShader(
    3.55 +				fileData->Data,
    3.56 +				fileData->Length,
    3.57 +				nullptr,
    3.58 +				&m_pixelShader
    3.59 +				)
    3.60 +			);
    3.61 +
    3.62 +		CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
    3.63 +		DX::ThrowIfFailed(
    3.64 +			m_d3dDevice->CreateBuffer(
    3.65 +				&constantBufferDesc,
    3.66 +				nullptr,
    3.67 +				&m_constantBuffer
    3.68 +				)
    3.69 +			);
    3.70 +	});
    3.71 +
    3.72 +	auto createCubeTask = (createPSTask && createVSTask).then([this] () {
    3.73 +		VertexPositionColor cubeVertices[] = 
    3.74 +		{
    3.75 +			{XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},
    3.76 +			{XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
    3.77 +			{XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
    3.78 +			{XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},
    3.79 +			{XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
    3.80 +			{XMFLOAT3( 0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},
    3.81 +			{XMFLOAT3( 0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},
    3.82 +			{XMFLOAT3( 0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
    3.83 +		};
    3.84 +
    3.85 +		D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
    3.86 +		vertexBufferData.pSysMem = cubeVertices;
    3.87 +		vertexBufferData.SysMemPitch = 0;
    3.88 +		vertexBufferData.SysMemSlicePitch = 0;
    3.89 +		CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
    3.90 +		DX::ThrowIfFailed(
    3.91 +			m_d3dDevice->CreateBuffer(
    3.92 +				&vertexBufferDesc,
    3.93 +				&vertexBufferData,
    3.94 +				&m_vertexBuffer
    3.95 +				)
    3.96 +			);
    3.97 +
    3.98 +		unsigned short cubeIndices[] = 
    3.99 +		{
   3.100 +			0,2,1, // -x
   3.101 +			1,2,3,
   3.102 +
   3.103 +			4,5,6, // +x
   3.104 +			5,7,6,
   3.105 +
   3.106 +			0,1,5, // -y
   3.107 +			0,5,4,
   3.108 +
   3.109 +			2,6,7, // +y
   3.110 +			2,7,3,
   3.111 +
   3.112 +			0,4,6, // -z
   3.113 +			0,6,2,
   3.114 +
   3.115 +			1,3,7, // +z
   3.116 +			1,7,5,
   3.117 +		};
   3.118 +
   3.119 +		m_indexCount = ARRAYSIZE(cubeIndices);
   3.120 +
   3.121 +		D3D11_SUBRESOURCE_DATA indexBufferData = {0};
   3.122 +		indexBufferData.pSysMem = cubeIndices;
   3.123 +		indexBufferData.SysMemPitch = 0;
   3.124 +		indexBufferData.SysMemSlicePitch = 0;
   3.125 +		CD3D11_BUFFER_DESC indexBufferDesc(sizeof(cubeIndices), D3D11_BIND_INDEX_BUFFER);
   3.126 +		DX::ThrowIfFailed(
   3.127 +			m_d3dDevice->CreateBuffer(
   3.128 +				&indexBufferDesc,
   3.129 +				&indexBufferData,
   3.130 +				&m_indexBuffer
   3.131 +				)
   3.132 +			);
   3.133 +	});
   3.134 +
   3.135 +	createCubeTask.then([this] () {
   3.136 +		m_loadingComplete = true;
   3.137 +	});
   3.138 +}
   3.139 +
   3.140 +void CubeRenderer::CreateWindowSizeDependentResources()
   3.141 +{
   3.142 +	Direct3DBase::CreateWindowSizeDependentResources();
   3.143 +
   3.144 +	float aspectRatio = m_windowBounds.Width / m_windowBounds.Height;
   3.145 +	float fovAngleY = 70.0f * XM_PI / 180.0f;
   3.146 +
   3.147 +	// Note that the m_orientationTransform3D matrix is post-multiplied here
   3.148 +	// in order to correctly orient the scene to match the display orientation.
   3.149 +	// This post-multiplication step is required for any draw calls that are
   3.150 +	// made to the swap chain render target. For draw calls to other targets,
   3.151 +	// this transform should not be applied.
   3.152 +	XMStoreFloat4x4(
   3.153 +		&m_constantBufferData.projection,
   3.154 +		XMMatrixTranspose(
   3.155 +			XMMatrixMultiply(
   3.156 +				XMMatrixPerspectiveFovRH(
   3.157 +					fovAngleY,
   3.158 +					aspectRatio,
   3.159 +					0.01f,
   3.160 +					100.0f
   3.161 +					),
   3.162 +				XMLoadFloat4x4(&m_orientationTransform3D)
   3.163 +				)
   3.164 +			)
   3.165 +		);
   3.166 +}
   3.167 +
   3.168 +void CubeRenderer::Update(float timeTotal, float timeDelta)
   3.169 +{
   3.170 +	(void) timeDelta; // Unused parameter.
   3.171 +
   3.172 +	XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
   3.173 +	XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
   3.174 +	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
   3.175 +
   3.176 +	XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
   3.177 +	XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY(timeTotal * XM_PIDIV4)));
   3.178 +}
   3.179 +
   3.180 +void CubeRenderer::Render()
   3.181 +{
   3.182 +	const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
   3.183 +	m_d3dContext->ClearRenderTargetView(
   3.184 +		m_renderTargetView.Get(),
   3.185 +		midnightBlue
   3.186 +		);
   3.187 +
   3.188 +	m_d3dContext->ClearDepthStencilView(
   3.189 +		m_depthStencilView.Get(),
   3.190 +		D3D11_CLEAR_DEPTH,
   3.191 +		1.0f,
   3.192 +		0
   3.193 +		);
   3.194 +
   3.195 +	// Only draw the cube once it is loaded (loading is asynchronous).
   3.196 +	if (!m_loadingComplete)
   3.197 +	{
   3.198 +		return;
   3.199 +	}
   3.200 +
   3.201 +	m_d3dContext->OMSetRenderTargets(
   3.202 +		1,
   3.203 +		m_renderTargetView.GetAddressOf(),
   3.204 +		m_depthStencilView.Get()
   3.205 +		);
   3.206 +
   3.207 +	m_d3dContext->UpdateSubresource(
   3.208 +		m_constantBuffer.Get(),
   3.209 +		0,
   3.210 +		NULL,
   3.211 +		&m_constantBufferData,
   3.212 +		0,
   3.213 +		0
   3.214 +		);
   3.215 +
   3.216 +	UINT stride = sizeof(VertexPositionColor);
   3.217 +	UINT offset = 0;
   3.218 +	m_d3dContext->IASetVertexBuffers(
   3.219 +		0,
   3.220 +		1,
   3.221 +		m_vertexBuffer.GetAddressOf(),
   3.222 +		&stride,
   3.223 +		&offset
   3.224 +		);
   3.225 +
   3.226 +	m_d3dContext->IASetIndexBuffer(
   3.227 +		m_indexBuffer.Get(),
   3.228 +		DXGI_FORMAT_R16_UINT,
   3.229 +		0
   3.230 +		);
   3.231 +
   3.232 +	m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
   3.233 +
   3.234 +	m_d3dContext->IASetInputLayout(m_inputLayout.Get());
   3.235 +
   3.236 +	m_d3dContext->VSSetShader(
   3.237 +		m_vertexShader.Get(),
   3.238 +		nullptr,
   3.239 +		0
   3.240 +		);
   3.241 +
   3.242 +	m_d3dContext->VSSetConstantBuffers(
   3.243 +		0,
   3.244 +		1,
   3.245 +		m_constantBuffer.GetAddressOf()
   3.246 +		);
   3.247 +
   3.248 +	m_d3dContext->PSSetShader(
   3.249 +		m_pixelShader.Get(),
   3.250 +		nullptr,
   3.251 +		0
   3.252 +		);
   3.253 +
   3.254 +	m_d3dContext->DrawIndexed(
   3.255 +		m_indexCount,
   3.256 +		0,
   3.257 +		0
   3.258 +		);
   3.259 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/main/windowsrt/CubeRenderer.h	Sat Oct 27 20:12:31 2012 -0400
     4.3 @@ -0,0 +1,44 @@
     4.4 +#pragma once
     4.5 +
     4.6 +#include "Direct3DBase.h"
     4.7 +
     4.8 +struct ModelViewProjectionConstantBuffer
     4.9 +{
    4.10 +	DirectX::XMFLOAT4X4 model;
    4.11 +	DirectX::XMFLOAT4X4 view;
    4.12 +	DirectX::XMFLOAT4X4 projection;
    4.13 +};
    4.14 +
    4.15 +struct VertexPositionColor
    4.16 +{
    4.17 +	DirectX::XMFLOAT3 pos;
    4.18 +	DirectX::XMFLOAT3 color;
    4.19 +};
    4.20 +
    4.21 +// This class renders a simple spinning cube.
    4.22 +ref class CubeRenderer sealed : public Direct3DBase
    4.23 +{
    4.24 +public:
    4.25 +	CubeRenderer();
    4.26 +
    4.27 +	// Direct3DBase methods.
    4.28 +	virtual void CreateDeviceResources() override;
    4.29 +	virtual void CreateWindowSizeDependentResources() override;
    4.30 +	virtual void Render() override;
    4.31 +	
    4.32 +	// Method for updating time-dependent objects.
    4.33 +	void Update(float timeTotal, float timeDelta);
    4.34 +
    4.35 +private:
    4.36 +	bool m_loadingComplete;
    4.37 +
    4.38 +	Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
    4.39 +	Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
    4.40 +	Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
    4.41 +	Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
    4.42 +	Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
    4.43 +	Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
    4.44 +
    4.45 +	uint32 m_indexCount;
    4.46 +	ModelViewProjectionConstantBuffer m_constantBufferData;
    4.47 +};
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main/windowsrt/Direct3DBase.cpp	Sat Oct 27 20:12:31 2012 -0400
     5.3 @@ -0,0 +1,344 @@
     5.4 +#include "SDLmain_WinRT_common.h"
     5.5 +#include "Direct3DBase.h"
     5.6 +
     5.7 +using namespace DirectX;
     5.8 +using namespace Microsoft::WRL;
     5.9 +using namespace Windows::UI::Core;
    5.10 +using namespace Windows::Foundation;
    5.11 +using namespace Windows::Graphics::Display;
    5.12 +
    5.13 +// Constructor.
    5.14 +Direct3DBase::Direct3DBase()
    5.15 +{
    5.16 +}
    5.17 +
    5.18 +// Initialize the Direct3D resources required to run.
    5.19 +void Direct3DBase::Initialize(CoreWindow^ window)
    5.20 +{
    5.21 +	m_window = window;
    5.22 +	
    5.23 +	CreateDeviceResources();
    5.24 +	CreateWindowSizeDependentResources();
    5.25 +}
    5.26 +
    5.27 +// Recreate all device resources and set them back to the current state.
    5.28 +void Direct3DBase::HandleDeviceLost()
    5.29 +{
    5.30 +	// Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
    5.31 +	m_windowBounds.Width = 0;
    5.32 +	m_windowBounds.Height = 0;
    5.33 +	m_swapChain = nullptr;
    5.34 +
    5.35 +	CreateDeviceResources();
    5.36 +	UpdateForWindowSizeChange();
    5.37 +}
    5.38 +
    5.39 +// These are the resources that depend on the device.
    5.40 +void Direct3DBase::CreateDeviceResources()
    5.41 +{
    5.42 +	// This flag adds support for surfaces with a different color channel ordering
    5.43 +	// than the API default. It is required for compatibility with Direct2D.
    5.44 +	UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    5.45 +
    5.46 +#if defined(_DEBUG)
    5.47 +	// If the project is in a debug build, enable debugging via SDK Layers with this flag.
    5.48 +	creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
    5.49 +#endif
    5.50 +
    5.51 +	// This array defines the set of DirectX hardware feature levels this app will support.
    5.52 +	// Note the ordering should be preserved.
    5.53 +	// Don't forget to declare your application's minimum required feature level in its
    5.54 +	// description.  All applications are assumed to support 9.1 unless otherwise stated.
    5.55 +	D3D_FEATURE_LEVEL featureLevels[] = 
    5.56 +	{
    5.57 +		D3D_FEATURE_LEVEL_11_1,
    5.58 +		D3D_FEATURE_LEVEL_11_0,
    5.59 +		D3D_FEATURE_LEVEL_10_1,
    5.60 +		D3D_FEATURE_LEVEL_10_0,
    5.61 +		D3D_FEATURE_LEVEL_9_3,
    5.62 +		D3D_FEATURE_LEVEL_9_2,
    5.63 +		D3D_FEATURE_LEVEL_9_1
    5.64 +	};
    5.65 +
    5.66 +	// Create the Direct3D 11 API device object and a corresponding context.
    5.67 +	ComPtr<ID3D11Device> device;
    5.68 +	ComPtr<ID3D11DeviceContext> context;
    5.69 +	DX::ThrowIfFailed(
    5.70 +		D3D11CreateDevice(
    5.71 +			nullptr, // Specify nullptr to use the default adapter.
    5.72 +			D3D_DRIVER_TYPE_HARDWARE,
    5.73 +			nullptr,
    5.74 +			creationFlags, // Set set debug and Direct2D compatibility flags.
    5.75 +			featureLevels, // List of feature levels this app can support.
    5.76 +			ARRAYSIZE(featureLevels),
    5.77 +			D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
    5.78 +			&device, // Returns the Direct3D device created.
    5.79 +			&m_featureLevel, // Returns feature level of device created.
    5.80 +			&context // Returns the device immediate context.
    5.81 +			)
    5.82 +		);
    5.83 +
    5.84 +	// Get the Direct3D 11.1 API device and context interfaces.
    5.85 +	DX::ThrowIfFailed(
    5.86 +		device.As(&m_d3dDevice)
    5.87 +		);
    5.88 +
    5.89 +	DX::ThrowIfFailed(
    5.90 +		context.As(&m_d3dContext)
    5.91 +		);
    5.92 +}
    5.93 +
    5.94 +// Allocate all memory resources that change on a window SizeChanged event.
    5.95 +void Direct3DBase::CreateWindowSizeDependentResources()
    5.96 +{ 
    5.97 +	// Store the window bounds so the next time we get a SizeChanged event we can
    5.98 +	// avoid rebuilding everything if the size is identical.
    5.99 +	m_windowBounds = m_window->Bounds;
   5.100 +
   5.101 +	// Calculate the necessary swap chain and render target size in pixels.
   5.102 +	float windowWidth = ConvertDipsToPixels(m_windowBounds.Width);
   5.103 +	float windowHeight = ConvertDipsToPixels(m_windowBounds.Height);
   5.104 +
   5.105 +	// The width and height of the swap chain must be based on the window's
   5.106 +	// landscape-oriented width and height. If the window is in a portrait
   5.107 +	// orientation, the dimensions must be reversed.
   5.108 +	m_orientation = DisplayProperties::CurrentOrientation;
   5.109 +	bool swapDimensions =
   5.110 +		m_orientation == DisplayOrientations::Portrait ||
   5.111 +		m_orientation == DisplayOrientations::PortraitFlipped;
   5.112 +	m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
   5.113 +	m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
   5.114 +
   5.115 +	if(m_swapChain != nullptr)
   5.116 +	{
   5.117 +		// If the swap chain already exists, resize it.
   5.118 +		DX::ThrowIfFailed(
   5.119 +			m_swapChain->ResizeBuffers(
   5.120 +				2, // Double-buffered swap chain.
   5.121 +				static_cast<UINT>(m_renderTargetSize.Width),
   5.122 +				static_cast<UINT>(m_renderTargetSize.Height),
   5.123 +				DXGI_FORMAT_B8G8R8A8_UNORM,
   5.124 +				0
   5.125 +				)
   5.126 +			);
   5.127 +	}
   5.128 +	else
   5.129 +	{
   5.130 +		// Otherwise, create a new one using the same adapter as the existing Direct3D device.
   5.131 +		DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
   5.132 +		swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the window.
   5.133 +		swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
   5.134 +		swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
   5.135 +		swapChainDesc.Stereo = false;
   5.136 +		swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
   5.137 +		swapChainDesc.SampleDesc.Quality = 0;
   5.138 +		swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
   5.139 +		swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
   5.140 +		swapChainDesc.Scaling = DXGI_SCALING_NONE;
   5.141 +		swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
   5.142 +		swapChainDesc.Flags = 0;
   5.143 +
   5.144 +		ComPtr<IDXGIDevice1>  dxgiDevice;
   5.145 +		DX::ThrowIfFailed(
   5.146 +			m_d3dDevice.As(&dxgiDevice)
   5.147 +			);
   5.148 +
   5.149 +		ComPtr<IDXGIAdapter> dxgiAdapter;
   5.150 +		DX::ThrowIfFailed(
   5.151 +			dxgiDevice->GetAdapter(&dxgiAdapter)
   5.152 +			);
   5.153 +
   5.154 +		ComPtr<IDXGIFactory2> dxgiFactory;
   5.155 +		DX::ThrowIfFailed(
   5.156 +			dxgiAdapter->GetParent(
   5.157 +				__uuidof(IDXGIFactory2), 
   5.158 +				&dxgiFactory
   5.159 +				)
   5.160 +			);
   5.161 +
   5.162 +		Windows::UI::Core::CoreWindow^ window = m_window.Get();
   5.163 +		DX::ThrowIfFailed(
   5.164 +			dxgiFactory->CreateSwapChainForCoreWindow(
   5.165 +				m_d3dDevice.Get(),
   5.166 +				reinterpret_cast<IUnknown*>(window),
   5.167 +				&swapChainDesc,
   5.168 +				nullptr, // Allow on all displays.
   5.169 +				&m_swapChain
   5.170 +				)
   5.171 +			);
   5.172 +			
   5.173 +		// Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
   5.174 +		// ensures that the application will only render after each VSync, minimizing power consumption.
   5.175 +		DX::ThrowIfFailed(
   5.176 +			dxgiDevice->SetMaximumFrameLatency(1)
   5.177 +			);
   5.178 +	}
   5.179 +	
   5.180 +	// Set the proper orientation for the swap chain, and generate the
   5.181 +	// 3D matrix transformation for rendering to the rotated swap chain.
   5.182 +	DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
   5.183 +	switch (m_orientation)
   5.184 +	{
   5.185 +		case DisplayOrientations::Landscape:
   5.186 +			rotation = DXGI_MODE_ROTATION_IDENTITY;
   5.187 +			m_orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation
   5.188 +				1.0f, 0.0f, 0.0f, 0.0f,
   5.189 +				0.0f, 1.0f, 0.0f, 0.0f,
   5.190 +				0.0f, 0.0f, 1.0f, 0.0f,
   5.191 +				0.0f, 0.0f, 0.0f, 1.0f
   5.192 +				);
   5.193 +			break;
   5.194 +
   5.195 +		case DisplayOrientations::Portrait:
   5.196 +			rotation = DXGI_MODE_ROTATION_ROTATE270;
   5.197 +			m_orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation
   5.198 +				0.0f, 1.0f, 0.0f, 0.0f,
   5.199 +				-1.0f, 0.0f, 0.0f, 0.0f,
   5.200 +				0.0f, 0.0f, 1.0f, 0.0f,
   5.201 +				0.0f, 0.0f, 0.0f, 1.0f
   5.202 +				);
   5.203 +			break;
   5.204 +
   5.205 +		case DisplayOrientations::LandscapeFlipped:
   5.206 +			rotation = DXGI_MODE_ROTATION_ROTATE180;
   5.207 +			m_orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation
   5.208 +				-1.0f, 0.0f, 0.0f, 0.0f,
   5.209 +				0.0f, -1.0f, 0.0f, 0.0f,
   5.210 +				0.0f, 0.0f, 1.0f, 0.0f,
   5.211 +				0.0f, 0.0f, 0.0f, 1.0f
   5.212 +				);
   5.213 +			break;
   5.214 +
   5.215 +		case DisplayOrientations::PortraitFlipped:
   5.216 +			rotation = DXGI_MODE_ROTATION_ROTATE90;
   5.217 +			m_orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation
   5.218 +				0.0f, -1.0f, 0.0f, 0.0f,
   5.219 +				1.0f, 0.0f, 0.0f, 0.0f,
   5.220 +				0.0f, 0.0f, 1.0f, 0.0f,
   5.221 +				0.0f, 0.0f, 0.0f, 1.0f
   5.222 +				);
   5.223 +			break;
   5.224 +
   5.225 +		default:
   5.226 +			throw ref new Platform::FailureException();
   5.227 +	}
   5.228 +
   5.229 +	DX::ThrowIfFailed(
   5.230 +		m_swapChain->SetRotation(rotation)
   5.231 +		);
   5.232 +
   5.233 +	// Create a render target view of the swap chain back buffer.
   5.234 +	ComPtr<ID3D11Texture2D> backBuffer;
   5.235 +	DX::ThrowIfFailed(
   5.236 +		m_swapChain->GetBuffer(
   5.237 +			0,
   5.238 +			__uuidof(ID3D11Texture2D),
   5.239 +			&backBuffer
   5.240 +			)
   5.241 +		);
   5.242 +
   5.243 +	DX::ThrowIfFailed(
   5.244 +		m_d3dDevice->CreateRenderTargetView(
   5.245 +			backBuffer.Get(),
   5.246 +			nullptr,
   5.247 +			&m_renderTargetView
   5.248 +			)
   5.249 +		);
   5.250 +
   5.251 +	// Create a depth stencil view.
   5.252 +	CD3D11_TEXTURE2D_DESC depthStencilDesc(
   5.253 +		DXGI_FORMAT_D24_UNORM_S8_UINT, 
   5.254 +		static_cast<UINT>(m_renderTargetSize.Width),
   5.255 +		static_cast<UINT>(m_renderTargetSize.Height),
   5.256 +		1,
   5.257 +		1,
   5.258 +		D3D11_BIND_DEPTH_STENCIL
   5.259 +		);
   5.260 +
   5.261 +	ComPtr<ID3D11Texture2D> depthStencil;
   5.262 +	DX::ThrowIfFailed(
   5.263 +		m_d3dDevice->CreateTexture2D(
   5.264 +			&depthStencilDesc,
   5.265 +			nullptr,
   5.266 +			&depthStencil
   5.267 +			)
   5.268 +		);
   5.269 +
   5.270 +	CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
   5.271 +	DX::ThrowIfFailed(
   5.272 +		m_d3dDevice->CreateDepthStencilView(
   5.273 +			depthStencil.Get(),
   5.274 +			&depthStencilViewDesc,
   5.275 +			&m_depthStencilView
   5.276 +			)
   5.277 +		);
   5.278 +
   5.279 +	// Set the rendering viewport to target the entire window.
   5.280 +	CD3D11_VIEWPORT viewport(
   5.281 +		0.0f,
   5.282 +		0.0f,
   5.283 +		m_renderTargetSize.Width,
   5.284 +		m_renderTargetSize.Height
   5.285 +		);
   5.286 +
   5.287 +	m_d3dContext->RSSetViewports(1, &viewport);
   5.288 +}
   5.289 +
   5.290 +// This method is called in the event handler for the SizeChanged event.
   5.291 +void Direct3DBase::UpdateForWindowSizeChange()
   5.292 +{
   5.293 +	if (m_window->Bounds.Width  != m_windowBounds.Width ||
   5.294 +		m_window->Bounds.Height != m_windowBounds.Height ||
   5.295 +		m_orientation != DisplayProperties::CurrentOrientation)
   5.296 +	{
   5.297 +		ID3D11RenderTargetView* nullViews[] = {nullptr};
   5.298 +		m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
   5.299 +		m_renderTargetView = nullptr;
   5.300 +		m_depthStencilView = nullptr;
   5.301 +		m_d3dContext->Flush();
   5.302 +		CreateWindowSizeDependentResources();
   5.303 +	}
   5.304 +}
   5.305 +
   5.306 +// Method to deliver the final image to the display.
   5.307 +void Direct3DBase::Present()
   5.308 +{
   5.309 +	// The application may optionally specify "dirty" or "scroll"
   5.310 +	// rects to improve efficiency in certain scenarios.
   5.311 +	DXGI_PRESENT_PARAMETERS parameters = {0};
   5.312 +	parameters.DirtyRectsCount = 0;
   5.313 +	parameters.pDirtyRects = nullptr;
   5.314 +	parameters.pScrollRect = nullptr;
   5.315 +	parameters.pScrollOffset = nullptr;
   5.316 +	
   5.317 +	// The first argument instructs DXGI to block until VSync, putting the application
   5.318 +	// to sleep until the next VSync. This ensures we don't waste any cycles rendering
   5.319 +	// frames that will never be displayed to the screen.
   5.320 +	HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
   5.321 +
   5.322 +	// Discard the contents of the render target.
   5.323 +	// This is a valid operation only when the existing contents will be entirely
   5.324 +	// overwritten. If dirty or scroll rects are used, this call should be removed.
   5.325 +	m_d3dContext->DiscardView(m_renderTargetView.Get());
   5.326 +
   5.327 +	// Discard the contents of the depth stencil.
   5.328 +	m_d3dContext->DiscardView(m_depthStencilView.Get());
   5.329 +
   5.330 +	// If the device was removed either by a disconnect or a driver upgrade, we 
   5.331 +	// must recreate all device resources.
   5.332 +	if (hr == DXGI_ERROR_DEVICE_REMOVED)
   5.333 +	{
   5.334 +		HandleDeviceLost();
   5.335 +	}
   5.336 +	else
   5.337 +	{
   5.338 +		DX::ThrowIfFailed(hr);
   5.339 +	}
   5.340 +}
   5.341 +
   5.342 +// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
   5.343 +float Direct3DBase::ConvertDipsToPixels(float dips)
   5.344 +{
   5.345 +	static const float dipsPerInch = 96.0f;
   5.346 +	return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
   5.347 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/main/windowsrt/Direct3DBase.h	Sat Oct 27 20:12:31 2012 -0400
     6.3 @@ -0,0 +1,38 @@
     6.4 +#pragma once
     6.5 +
     6.6 +#include "DirectXHelper.h"
     6.7 +
     6.8 +// Helper class that initializes DirectX APIs for 3D rendering.
     6.9 +ref class Direct3DBase abstract
    6.10 +{
    6.11 +internal:
    6.12 +	Direct3DBase();
    6.13 +
    6.14 +public:
    6.15 +	virtual void Initialize(Windows::UI::Core::CoreWindow^ window);
    6.16 +	virtual void HandleDeviceLost();
    6.17 +	virtual void CreateDeviceResources();
    6.18 +	virtual void CreateWindowSizeDependentResources();
    6.19 +	virtual void UpdateForWindowSizeChange();
    6.20 +	virtual void Render() = 0;
    6.21 +	virtual void Present();
    6.22 +	virtual float ConvertDipsToPixels(float dips);
    6.23 +
    6.24 +protected private:
    6.25 +	// Direct3D Objects.
    6.26 +	Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
    6.27 +	Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
    6.28 +	Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
    6.29 +	Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
    6.30 +	Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
    6.31 +
    6.32 +	// Cached renderer properties.
    6.33 +	D3D_FEATURE_LEVEL m_featureLevel;
    6.34 +	Windows::Foundation::Size m_renderTargetSize;
    6.35 +	Windows::Foundation::Rect m_windowBounds;
    6.36 +	Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
    6.37 +	Windows::Graphics::Display::DisplayOrientations m_orientation;
    6.38 +
    6.39 +	// Transform used for display orientation.
    6.40 +	DirectX::XMFLOAT4X4 m_orientationTransform3D;
    6.41 +};
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/main/windowsrt/DirectXHelper.h	Sat Oct 27 20:12:31 2012 -0400
     7.3 @@ -0,0 +1,36 @@
     7.4 +#pragma once
     7.5 +
     7.6 +#include <wrl/client.h>
     7.7 +#include <ppl.h>
     7.8 +#include <ppltasks.h>
     7.9 +
    7.10 +namespace DX
    7.11 +{
    7.12 +	inline void ThrowIfFailed(HRESULT hr)
    7.13 +	{
    7.14 +		if (FAILED(hr))
    7.15 +		{
    7.16 +			// Set a breakpoint on this line to catch Win32 API errors.
    7.17 +			throw Platform::Exception::CreateException(hr);
    7.18 +		}
    7.19 +	}
    7.20 +
    7.21 +	// Function that reads from a binary file asynchronously.
    7.22 +	inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
    7.23 +	{
    7.24 +		using namespace Windows::Storage;
    7.25 +		using namespace Concurrency;
    7.26 +		
    7.27 +		auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    7.28 +		
    7.29 +		return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
    7.30 +		{
    7.31 +			return FileIO::ReadBufferAsync(file);
    7.32 +		}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
    7.33 +		{
    7.34 +			auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
    7.35 +			Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
    7.36 +			return fileData;
    7.37 +		});
    7.38 +	}
    7.39 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/main/windowsrt/SDL_WinRTApp.cpp	Sat Oct 27 20:12:31 2012 -0400
     8.3 @@ -0,0 +1,148 @@
     8.4 +#include "SDLmain_WinRT_common.h"
     8.5 +#include "SDL_WinRTApp.h"
     8.6 +#include "BasicTimer.h"
     8.7 +
     8.8 +using namespace Windows::ApplicationModel;
     8.9 +using namespace Windows::ApplicationModel::Core;
    8.10 +using namespace Windows::ApplicationModel::Activation;
    8.11 +using namespace Windows::UI::Core;
    8.12 +using namespace Windows::System;
    8.13 +using namespace Windows::Foundation;
    8.14 +using namespace Windows::Graphics::Display;
    8.15 +using namespace concurrency;
    8.16 +
    8.17 +SDL_WinRTApp::SDL_WinRTApp() :
    8.18 +	m_windowClosed(false),
    8.19 +	m_windowVisible(true)
    8.20 +{
    8.21 +}
    8.22 +
    8.23 +void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
    8.24 +{
    8.25 +	applicationView->Activated +=
    8.26 +        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
    8.27 +
    8.28 +	CoreApplication::Suspending +=
    8.29 +        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
    8.30 +
    8.31 +	CoreApplication::Resuming +=
    8.32 +        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
    8.33 +
    8.34 +	m_renderer = ref new CubeRenderer();
    8.35 +}
    8.36 +
    8.37 +void SDL_WinRTApp::SetWindow(CoreWindow^ window)
    8.38 +{
    8.39 +	window->SizeChanged += 
    8.40 +        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
    8.41 +
    8.42 +	window->VisibilityChanged +=
    8.43 +		ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
    8.44 +
    8.45 +	window->Closed += 
    8.46 +        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
    8.47 +
    8.48 +	window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
    8.49 +
    8.50 +	window->PointerPressed +=
    8.51 +		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
    8.52 +
    8.53 +	window->PointerMoved +=
    8.54 +		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
    8.55 +
    8.56 +	m_renderer->Initialize(CoreWindow::GetForCurrentThread());
    8.57 +}
    8.58 +
    8.59 +void SDL_WinRTApp::Load(Platform::String^ entryPoint)
    8.60 +{
    8.61 +}
    8.62 +
    8.63 +void SDL_WinRTApp::Run()
    8.64 +{
    8.65 +	BasicTimer^ timer = ref new BasicTimer();
    8.66 +
    8.67 +	while (!m_windowClosed)
    8.68 +	{
    8.69 +		if (m_windowVisible)
    8.70 +		{
    8.71 +			timer->Update();
    8.72 +			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
    8.73 +			m_renderer->Update(timer->Total, timer->Delta);
    8.74 +			m_renderer->Render();
    8.75 +			m_renderer->Present(); // This call is synchronized to the display frame rate.
    8.76 +		}
    8.77 +		else
    8.78 +		{
    8.79 +			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
    8.80 +		}
    8.81 +	}
    8.82 +}
    8.83 +
    8.84 +void SDL_WinRTApp::Uninitialize()
    8.85 +{
    8.86 +}
    8.87 +
    8.88 +void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
    8.89 +{
    8.90 +	m_renderer->UpdateForWindowSizeChange();
    8.91 +}
    8.92 +
    8.93 +void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
    8.94 +{
    8.95 +	m_windowVisible = args->Visible;
    8.96 +}
    8.97 +
    8.98 +void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
    8.99 +{
   8.100 +	m_windowClosed = true;
   8.101 +}
   8.102 +
   8.103 +void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   8.104 +{
   8.105 +	// Insert your code here.
   8.106 +}
   8.107 +
   8.108 +void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
   8.109 +{
   8.110 +	// Insert your code here.
   8.111 +}
   8.112 +
   8.113 +void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   8.114 +{
   8.115 +	CoreWindow::GetForCurrentThread()->Activate();
   8.116 +}
   8.117 +
   8.118 +void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
   8.119 +{
   8.120 +	// Save app state asynchronously after requesting a deferral. Holding a deferral
   8.121 +	// indicates that the application is busy performing suspending operations. Be
   8.122 +	// aware that a deferral may not be held indefinitely. After about five seconds,
   8.123 +	// the app will be forced to exit.
   8.124 +	SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   8.125 +
   8.126 +	create_task([this, deferral]()
   8.127 +	{
   8.128 +		// Insert your code here.
   8.129 +
   8.130 +		deferral->Complete();
   8.131 +	});
   8.132 +}
   8.133 + 
   8.134 +void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
   8.135 +{
   8.136 +	// Restore any data or state that was unloaded on suspend. By default, data
   8.137 +	// and state are persisted when resuming from suspend. Note that this event
   8.138 +	// does not occur if the app was previously terminated.
   8.139 +}
   8.140 +
   8.141 +IFrameworkView^ Direct3DApplicationSource::CreateView()
   8.142 +{
   8.143 +    return ref new SDL_WinRTApp();
   8.144 +}
   8.145 +
   8.146 +int SDL_WinRT_RunApplication(/*Platform::Array<Platform::String^>^*/)
   8.147 +{
   8.148 +	auto direct3DApplicationSource = ref new Direct3DApplicationSource();
   8.149 +	CoreApplication::Run(direct3DApplicationSource);
   8.150 +	return 0;
   8.151 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/main/windowsrt/SDL_WinRTApp.h	Sat Oct 27 20:12:31 2012 -0400
     9.3 @@ -0,0 +1,40 @@
     9.4 +#pragma once
     9.5 +
     9.6 +#include "SDLmain_WinRT_common.h"
     9.7 +#include "CubeRenderer.h"
     9.8 +
     9.9 +ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
    9.10 +{
    9.11 +public:
    9.12 +	SDL_WinRTApp();
    9.13 +	
    9.14 +	// IFrameworkView Methods.
    9.15 +	virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
    9.16 +	virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
    9.17 +	virtual void Load(Platform::String^ entryPoint);
    9.18 +	virtual void Run();
    9.19 +	virtual void Uninitialize();
    9.20 +
    9.21 +protected:
    9.22 +	// Event Handlers.
    9.23 +	void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
    9.24 +	void OnLogicalDpiChanged(Platform::Object^ sender);
    9.25 +	void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
    9.26 +	void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
    9.27 +	void OnResuming(Platform::Object^ sender, Platform::Object^ args);
    9.28 +	void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
    9.29 +	void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
    9.30 +	void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    9.31 +	void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    9.32 +
    9.33 +private:
    9.34 +	CubeRenderer^ m_renderer;
    9.35 +	bool m_windowClosed;
    9.36 +	bool m_windowVisible;
    9.37 +};
    9.38 +
    9.39 +ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
    9.40 +{
    9.41 +public:
    9.42 +	virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
    9.43 +};
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/main/windowsrt/SDLmain_WinRT_common.h	Sat Oct 27 20:12:31 2012 -0400
    10.3 @@ -0,0 +1,7 @@
    10.4 +#pragma once
    10.5 +
    10.6 +#include <wrl/client.h>
    10.7 +#include <d3d11_1.h>
    10.8 +#include <DirectXMath.h>
    10.9 +#include <memory>
   10.10 +#include <agile.h>
   10.11 \ No newline at end of file
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/main/windowsrt/SimplePixelShader.hlsl	Sat Oct 27 20:12:31 2012 -0400
    11.3 @@ -0,0 +1,10 @@
    11.4 +struct PixelShaderInput
    11.5 +{
    11.6 +	float4 pos : SV_POSITION;
    11.7 +	float3 color : COLOR0;
    11.8 +};
    11.9 +
   11.10 +float4 main(PixelShaderInput input) : SV_TARGET
   11.11 +{
   11.12 +	return float4(input.color,1.0f);
   11.13 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/main/windowsrt/SimpleVertexShader.hlsl	Sat Oct 27 20:12:31 2012 -0400
    12.3 @@ -0,0 +1,35 @@
    12.4 +cbuffer ModelViewProjectionConstantBuffer : register(b0)
    12.5 +{
    12.6 +	matrix model;
    12.7 +	matrix view;
    12.8 +	matrix projection;
    12.9 +};
   12.10 +
   12.11 +struct VertexShaderInput
   12.12 +{
   12.13 +	float3 pos : POSITION;
   12.14 +	float3 color : COLOR0;
   12.15 +};
   12.16 +
   12.17 +struct VertexShaderOutput
   12.18 +{
   12.19 +	float4 pos : SV_POSITION;
   12.20 +	float3 color : COLOR0;
   12.21 +};
   12.22 +
   12.23 +VertexShaderOutput main(VertexShaderInput input)
   12.24 +{
   12.25 +	VertexShaderOutput output;
   12.26 +	float4 pos = float4(input.pos, 1.0f);
   12.27 +
   12.28 +	// Transform the vertex position into projected space.
   12.29 +	pos = mul(pos, model);
   12.30 +	pos = mul(pos, view);
   12.31 +	pos = mul(pos, projection);
   12.32 +	output.pos = pos;
   12.33 +
   12.34 +	// Pass through the color without modification.
   12.35 +	output.color = input.color;
   12.36 +
   12.37 +	return output;
   12.38 +}