Merged with local changes
authorDavid Ludwig <dludwig@pobox.com>
Mon, 19 Nov 2012 22:07:06 -0500
changeset 8343 f593baeea84c
parent 8340 e470405f3ae9 (current diff)
parent 8342 05d7aa70928e (diff)
child 8344 11fd2e01a070
Merged with local changes
src/video/windowsrt/CubeRenderer.cpp
src/video/windowsrt/CubeRenderer.h
--- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Mon Nov 12 13:25:44 2012 -0500
+++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Mon Nov 19 22:07:06 2012 -0500
@@ -101,14 +101,6 @@
     <ClCompile Include="..\..\src\video\SDL_stretch.c" />
     <ClCompile Include="..\..\src\video\SDL_surface.c" />
     <ClCompile Include="..\..\src\video\SDL_video.c" />
-    <ClCompile Include="..\..\src\video\windowsrt\CubeRenderer.cpp">
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
-      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
-    </ClCompile>
     <ClCompile Include="..\..\src\video\windowsrt\Direct3DBase.cpp">
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
@@ -133,7 +125,22 @@
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     </ClCompile>
-    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.cpp" />
+    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.cpp">
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+    </ClCompile>
+    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtrenderer.cpp">
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+    </ClCompile>
     <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.cpp">
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
@@ -245,13 +252,13 @@
     <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
     <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
-    <ClInclude Include="..\..\src\video\windowsrt\CubeRenderer.h" />
     <ClInclude Include="..\..\src\video\windowsrt\Direct3DBase.h" />
     <ClInclude Include="..\..\src\video\windowsrt\DirectXHelper.h" />
     <ClInclude Include="..\..\src\video\windowsrt\SDLmain_WinRT_common.h" />
     <ClInclude Include="..\..\src\video\windowsrt\SDL_WinRTApp.h" />
     <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtevents_c.h" />
     <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtframebuffer_c.h" />
+    <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtrenderer.h" />
     <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
--- a/src/SDL_assert.c	Mon Nov 12 13:25:44 2012 -0500
+++ b/src/SDL_assert.c	Mon Nov 19 22:07:06 2012 -0500
@@ -37,8 +37,10 @@
 #else  /* fprintf, _exit(), etc. */
 #include <stdio.h>
 #include <stdlib.h>
+#if ! defined(__WINRT__)
 #include <unistd.h>
 #endif
+#endif
 
 static SDL_assert_state
 SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
--- a/src/video/windowsrt/CubeRenderer.cpp	Mon Nov 12 13:25:44 2012 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,256 +0,0 @@
-#include "SDLmain_WinRT_common.h"
-#include "CubeRenderer.h"
-
-using namespace DirectX;
-using namespace Microsoft::WRL;
-using namespace Windows::Foundation;
-using namespace Windows::UI::Core;
-
-CubeRenderer::CubeRenderer() :
-	m_loadingComplete(false),
-	m_indexCount(0)
-{
-}
-
-void CubeRenderer::CreateDeviceResources()
-{
-	Direct3DBase::CreateDeviceResources();
-
-	auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
-	auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
-
-	auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreateVertexShader(
- 				fileData->Data,
-				fileData->Length,
-				nullptr,
-				&m_vertexShader
-				)
-			);
-
-		const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
-		{
-			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
-			{ "COLOR",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
-		};
-
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreateInputLayout(
-				vertexDesc,
-				ARRAYSIZE(vertexDesc),
-				fileData->Data,
-				fileData->Length,
-				&m_inputLayout
-				)
-			);
-	});
-
-	auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreatePixelShader(
-				fileData->Data,
-				fileData->Length,
-				nullptr,
-				&m_pixelShader
-				)
-			);
-
-		CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreateBuffer(
-				&constantBufferDesc,
-				nullptr,
-				&m_constantBuffer
-				)
-			);
-	});
-
-	auto createCubeTask = (createPSTask && createVSTask).then([this] () {
-		VertexPositionColor cubeVertices[] = 
-		{
-			{XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},
-			{XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
-			{XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
-			{XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},
-			{XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
-			{XMFLOAT3( 0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},
-			{XMFLOAT3( 0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},
-			{XMFLOAT3( 0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
-		};
-
-		D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
-		vertexBufferData.pSysMem = cubeVertices;
-		vertexBufferData.SysMemPitch = 0;
-		vertexBufferData.SysMemSlicePitch = 0;
-		CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreateBuffer(
-				&vertexBufferDesc,
-				&vertexBufferData,
-				&m_vertexBuffer
-				)
-			);
-
-		unsigned short cubeIndices[] = 
-		{
-			0,2,1, // -x
-			1,2,3,
-
-			4,5,6, // +x
-			5,7,6,
-
-			0,1,5, // -y
-			0,5,4,
-
-			2,6,7, // +y
-			2,7,3,
-
-			0,4,6, // -z
-			0,6,2,
-
-			1,3,7, // +z
-			1,7,5,
-		};
-
-		m_indexCount = ARRAYSIZE(cubeIndices);
-
-		D3D11_SUBRESOURCE_DATA indexBufferData = {0};
-		indexBufferData.pSysMem = cubeIndices;
-		indexBufferData.SysMemPitch = 0;
-		indexBufferData.SysMemSlicePitch = 0;
-		CD3D11_BUFFER_DESC indexBufferDesc(sizeof(cubeIndices), D3D11_BIND_INDEX_BUFFER);
-		DX::ThrowIfFailed(
-			m_d3dDevice->CreateBuffer(
-				&indexBufferDesc,
-				&indexBufferData,
-				&m_indexBuffer
-				)
-			);
-	});
-
-	createCubeTask.then([this] () {
-		m_loadingComplete = true;
-	});
-}
-
-void CubeRenderer::CreateWindowSizeDependentResources()
-{
-	Direct3DBase::CreateWindowSizeDependentResources();
-
-	float aspectRatio = m_windowBounds.Width / m_windowBounds.Height;
-	float fovAngleY = 70.0f * XM_PI / 180.0f;
-
-	// Note that the m_orientationTransform3D matrix is post-multiplied here
-	// in order to correctly orient the scene to match the display orientation.
-	// This post-multiplication step is required for any draw calls that are
-	// made to the swap chain render target. For draw calls to other targets,
-	// this transform should not be applied.
-	XMStoreFloat4x4(
-		&m_constantBufferData.projection,
-		XMMatrixTranspose(
-			XMMatrixMultiply(
-				XMMatrixPerspectiveFovRH(
-					fovAngleY,
-					aspectRatio,
-					0.01f,
-					100.0f
-					),
-				XMLoadFloat4x4(&m_orientationTransform3D)
-				)
-			)
-		);
-}
-
-void CubeRenderer::Update(float timeTotal, float timeDelta)
-{
-	(void) timeDelta; // Unused parameter.
-
-	XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
-	XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
-	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
-
-	XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
-	XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY(timeTotal * XM_PIDIV4)));
-}
-
-void CubeRenderer::Render()
-{
-	const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
-	m_d3dContext->ClearRenderTargetView(
-		m_renderTargetView.Get(),
-		midnightBlue
-		);
-
-	m_d3dContext->ClearDepthStencilView(
-		m_depthStencilView.Get(),
-		D3D11_CLEAR_DEPTH,
-		1.0f,
-		0
-		);
-
-	// Only draw the cube once it is loaded (loading is asynchronous).
-	if (!m_loadingComplete)
-	{
-		return;
-	}
-
-	m_d3dContext->OMSetRenderTargets(
-		1,
-		m_renderTargetView.GetAddressOf(),
-		m_depthStencilView.Get()
-		);
-
-	m_d3dContext->UpdateSubresource(
-		m_constantBuffer.Get(),
-		0,
-		NULL,
-		&m_constantBufferData,
-		0,
-		0
-		);
-
-	UINT stride = sizeof(VertexPositionColor);
-	UINT offset = 0;
-	m_d3dContext->IASetVertexBuffers(
-		0,
-		1,
-		m_vertexBuffer.GetAddressOf(),
-		&stride,
-		&offset
-		);
-
-	m_d3dContext->IASetIndexBuffer(
-		m_indexBuffer.Get(),
-		DXGI_FORMAT_R16_UINT,
-		0
-		);
-
-	m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-
-	m_d3dContext->IASetInputLayout(m_inputLayout.Get());
-
-	m_d3dContext->VSSetShader(
-		m_vertexShader.Get(),
-		nullptr,
-		0
-		);
-
-	m_d3dContext->VSSetConstantBuffers(
-		0,
-		1,
-		m_constantBuffer.GetAddressOf()
-		);
-
-	m_d3dContext->PSSetShader(
-		m_pixelShader.Get(),
-		nullptr,
-		0
-		);
-
-	m_d3dContext->DrawIndexed(
-		m_indexCount,
-		0,
-		0
-		);
-}
--- a/src/video/windowsrt/CubeRenderer.h	Mon Nov 12 13:25:44 2012 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-#pragma once
-
-#include "Direct3DBase.h"
-
-struct ModelViewProjectionConstantBuffer
-{
-	DirectX::XMFLOAT4X4 model;
-	DirectX::XMFLOAT4X4 view;
-	DirectX::XMFLOAT4X4 projection;
-};
-
-struct VertexPositionColor
-{
-	DirectX::XMFLOAT3 pos;
-	DirectX::XMFLOAT3 color;
-};
-
-// This class renders a simple spinning cube.
-ref class CubeRenderer sealed : public Direct3DBase
-{
-public:
-	CubeRenderer();
-
-	// Direct3DBase methods.
-	virtual void CreateDeviceResources() override;
-	virtual void CreateWindowSizeDependentResources() override;
-	virtual void Render() override;
-	
-	// Method for updating time-dependent objects.
-	void Update(float timeTotal, float timeDelta);
-
-private:
-	bool m_loadingComplete;
-
-	Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
-	Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
-	Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
-	Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
-	Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
-	Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
-
-	uint32 m_indexCount;
-	ModelViewProjectionConstantBuffer m_constantBufferData;
-};
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Nov 12 13:25:44 2012 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Nov 19 22:07:06 2012 -0500
@@ -11,6 +11,9 @@
 #include "SDL_log.h"
 }
 
+// TODO, WinRT: Remove reference(s) to BasicTimer.h
+#include "BasicTimer.h"
+
 // HACK, DLudwig: The C-style main() will get loaded via the app's
 // WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
 // This seems wrong on some level, but does seem to work.
@@ -54,7 +57,7 @@
 	CoreApplication::Resuming +=
         ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
 
-	m_renderer = ref new CubeRenderer();
+	m_renderer = ref new SDL_winrtrenderer();
 }
 
 void SDL_WinRTApp::SetWindow(CoreWindow^ window)
@@ -112,9 +115,6 @@
 		if (m_windowVisible)
 		{
 			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
-			m_renderer->Update(0.0f, 0.0f);
-			m_renderer->Render();
-			m_renderer->Present(); // This call is synchronized to the display frame rate.
 		}
 		else
 		{
@@ -123,6 +123,16 @@
 	}
 }
 
+void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects)
+{
+    if (!m_windowClosed && m_windowVisible)
+	{
+		m_renderer->Update(0.0f, 0.0f);
+		m_renderer->Render();
+		m_renderer->Present(); // This call is synchronized to the display frame rate.
+	}
+}
+
 void SDL_WinRTApp::Uninitialize()
 {
 }
--- a/src/video/windowsrt/SDL_WinRTApp.h	Mon Nov 12 13:25:44 2012 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.h	Mon Nov 19 22:07:06 2012 -0500
@@ -2,7 +2,7 @@
 
 #include "SDLmain_WinRT_common.h"
 #include "SDL_winrtvideo.h"
-#include "CubeRenderer.h"
+#include "SDL_winrtrenderer.h"
 #include <vector>
 
 using namespace Windows::UI::Core;
@@ -26,6 +26,7 @@
     const SDL_WindowData * GetSDLWindowData() const;
     bool HasSDLWindowData() const;
     void SetSDLWindowData(const SDL_WindowData * windowData);
+    void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
 
 protected:
 	// Event Handlers.
@@ -43,7 +44,7 @@
     void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
 
 private:
-	CubeRenderer^ m_renderer;
+	SDL_winrtrenderer^ m_renderer;
 	bool m_windowClosed;
 	bool m_windowVisible;
     const SDL_WindowData* m_sdlWindowData;
--- a/src/video/windowsrt/SDL_winrtframebuffer.cpp	Mon Nov 12 13:25:44 2012 -0500
+++ b/src/video/windowsrt/SDL_winrtframebuffer.cpp	Mon Nov 19 22:07:06 2012 -0500
@@ -24,6 +24,9 @@
 
 #include "../SDL_sysvideo.h"
 #include "SDL_winrtframebuffer_c.h"
+#include "SDL_WinRTApp.h"
+
+extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
 
 
 #define WINRT_SURFACE   "_SDL_WinRTSurface"
@@ -76,6 +79,9 @@
                      SDL_GetWindowID(window), ++frame_number);
         SDL_SaveBMP(surface, file);
     }
+
+    SDL_WinRTGlobalApp->UpdateWindowFramebuffer(surface, rects, numrects);
+
     return 0;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Mon Nov 19 22:07:06 2012 -0500
@@ -0,0 +1,182 @@
+#include "SDLmain_WinRT_common.h"
+#include "SDL_winrtrenderer.h"
+
+using namespace DirectX;
+using namespace Microsoft::WRL;
+using namespace Windows::Foundation;
+using namespace Windows::UI::Core;
+
+SDL_winrtrenderer::SDL_winrtrenderer() :
+	m_loadingComplete(false),
+	m_vertexCount(0)
+{
+}
+
+void SDL_winrtrenderer::CreateDeviceResources()
+{
+	Direct3DBase::CreateDeviceResources();
+
+	auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
+	auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
+
+	auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
+		DX::ThrowIfFailed(
+			m_d3dDevice->CreateVertexShader(
+ 				fileData->Data,
+				fileData->Length,
+				nullptr,
+				&m_vertexShader
+				)
+			);
+
+		const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
+		{
+			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
+			{ "COLOR",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+		};
+
+		DX::ThrowIfFailed(
+			m_d3dDevice->CreateInputLayout(
+				vertexDesc,
+				ARRAYSIZE(vertexDesc),
+				fileData->Data,
+				fileData->Length,
+				&m_inputLayout
+				)
+			);
+	});
+
+	auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
+		DX::ThrowIfFailed(
+			m_d3dDevice->CreatePixelShader(
+				fileData->Data,
+				fileData->Length,
+				nullptr,
+				&m_pixelShader
+				)
+			);
+
+		CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
+		DX::ThrowIfFailed(
+			m_d3dDevice->CreateBuffer(
+				&constantBufferDesc,
+				nullptr,
+				&m_constantBuffer
+				)
+			);
+	});
+
+	auto createCubeTask = (createPSTask && createVSTask).then([this] () {
+		VertexPositionColor cubeVertices[] = 
+		{
+			{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
+			{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
+			{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
+			{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
+		};
+
+		m_vertexCount = ARRAYSIZE(cubeVertices);
+
+		D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
+		vertexBufferData.pSysMem = cubeVertices;
+		vertexBufferData.SysMemPitch = 0;
+		vertexBufferData.SysMemSlicePitch = 0;
+		CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
+		DX::ThrowIfFailed(
+			m_d3dDevice->CreateBuffer(
+				&vertexBufferDesc,
+				&vertexBufferData,
+				&m_vertexBuffer
+				)
+			);
+	});
+
+	createCubeTask.then([this] () {
+		m_loadingComplete = true;
+	});
+}
+
+void SDL_winrtrenderer::Update(float timeTotal, float timeDelta)
+{
+	(void) timeDelta; // Unused parameter.
+
+	XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
+	XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
+	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
+
+	XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixIdentity());
+	XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixIdentity());
+}
+
+void SDL_winrtrenderer::Render()
+{
+	const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
+	m_d3dContext->ClearRenderTargetView(
+		m_renderTargetView.Get(),
+		midnightBlue
+		);
+
+	m_d3dContext->ClearDepthStencilView(
+		m_depthStencilView.Get(),
+		D3D11_CLEAR_DEPTH,
+		1.0f,
+		0
+		);
+
+	// Only draw the cube once it is loaded (loading is asynchronous).
+	if (!m_loadingComplete)
+	{
+		return;
+	}
+
+	m_d3dContext->RSSetState(m_rasterState.Get());
+
+	m_d3dContext->OMSetRenderTargets(
+		1,
+		m_renderTargetView.GetAddressOf(),
+		m_depthStencilView.Get()
+		);
+
+	m_d3dContext->UpdateSubresource(
+		m_constantBuffer.Get(),
+		0,
+		NULL,
+		&m_constantBufferData,
+		0,
+		0
+		);
+
+	UINT stride = sizeof(VertexPositionColor);
+	UINT offset = 0;
+	m_d3dContext->IASetVertexBuffers(
+		0,
+		1,
+		m_vertexBuffer.GetAddressOf(),
+		&stride,
+		&offset
+		);
+
+	m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
+
+	m_d3dContext->IASetInputLayout(m_inputLayout.Get());
+
+	m_d3dContext->VSSetShader(
+		m_vertexShader.Get(),
+		nullptr,
+		0
+		);
+
+	m_d3dContext->VSSetConstantBuffers(
+		0,
+		1,
+		m_constantBuffer.GetAddressOf()
+		);
+
+	m_d3dContext->PSSetShader(
+		m_pixelShader.Get(),
+		nullptr,
+		0
+		);
+
+	m_d3dContext->Draw(4, 0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/windowsrt/SDL_winrtrenderer.h	Mon Nov 19 22:07:06 2012 -0500
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "Direct3DBase.h"
+
+struct ModelViewProjectionConstantBuffer
+{
+	DirectX::XMFLOAT4X4 model;
+	DirectX::XMFLOAT4X4 view;
+	DirectX::XMFLOAT4X4 projection;
+};
+
+struct VertexPositionColor
+{
+	DirectX::XMFLOAT3 pos;
+	DirectX::XMFLOAT3 color;
+};
+
+// This class renders a simple spinning cube.
+ref class SDL_winrtrenderer sealed : public Direct3DBase
+{
+public:
+	SDL_winrtrenderer();
+
+	// Direct3DBase methods.
+	virtual void CreateDeviceResources() override;
+	virtual void Render() override;
+	
+	// Method for updating time-dependent objects.
+	void Update(float timeTotal, float timeDelta);
+
+private:
+	bool m_loadingComplete;
+
+	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<ID3D11Buffer> m_constantBuffer;
+	Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_rasterState;
+
+	uint32 m_vertexCount;
+	ModelViewProjectionConstantBuffer m_constantBufferData;
+};