Merged with local changes
authorDavid Ludwig <dludwig@pobox.com>
Mon, 19 Nov 2012 22:07:06 -0500
changeset 8343f593baeea84c
parent 8340 e470405f3ae9
parent 8342 05d7aa70928e
child 8344 11fd2e01a070
Merged with local changes
src/video/windowsrt/CubeRenderer.cpp
src/video/windowsrt/CubeRenderer.h
     1.1 --- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Mon Nov 12 13:25:44 2012 -0500
     1.2 +++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Mon Nov 19 22:07:06 2012 -0500
     1.3 @@ -101,14 +101,6 @@
     1.4      <ClCompile Include="..\..\src\video\SDL_stretch.c" />
     1.5      <ClCompile Include="..\..\src\video\SDL_surface.c" />
     1.6      <ClCompile Include="..\..\src\video\SDL_video.c" />
     1.7 -    <ClCompile Include="..\..\src\video\windowsrt\CubeRenderer.cpp">
     1.8 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     1.9 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.10 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.11 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.12 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.13 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.14 -    </ClCompile>
    1.15      <ClCompile Include="..\..\src\video\windowsrt\Direct3DBase.cpp">
    1.16        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.17        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.18 @@ -133,7 +125,22 @@
    1.19        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.20        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.21      </ClCompile>
    1.22 -    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.cpp" />
    1.23 +    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtframebuffer.cpp">
    1.24 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.25 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.26 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.27 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.28 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.29 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.30 +    </ClCompile>
    1.31 +    <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtrenderer.cpp">
    1.32 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.33 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.34 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.35 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.36 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.37 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.38 +    </ClCompile>
    1.39      <ClCompile Include="..\..\src\video\windowsrt\SDL_winrtvideo.cpp">
    1.40        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.41        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.42 @@ -245,13 +252,13 @@
    1.43      <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
    1.44      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
    1.45      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
    1.46 -    <ClInclude Include="..\..\src\video\windowsrt\CubeRenderer.h" />
    1.47      <ClInclude Include="..\..\src\video\windowsrt\Direct3DBase.h" />
    1.48      <ClInclude Include="..\..\src\video\windowsrt\DirectXHelper.h" />
    1.49      <ClInclude Include="..\..\src\video\windowsrt\SDLmain_WinRT_common.h" />
    1.50      <ClInclude Include="..\..\src\video\windowsrt\SDL_WinRTApp.h" />
    1.51      <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtevents_c.h" />
    1.52      <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtframebuffer_c.h" />
    1.53 +    <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtrenderer.h" />
    1.54      <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h" />
    1.55    </ItemGroup>
    1.56    <PropertyGroup Label="Globals">
     2.1 --- a/src/SDL_assert.c	Mon Nov 12 13:25:44 2012 -0500
     2.2 +++ b/src/SDL_assert.c	Mon Nov 19 22:07:06 2012 -0500
     2.3 @@ -37,8 +37,10 @@
     2.4  #else  /* fprintf, _exit(), etc. */
     2.5  #include <stdio.h>
     2.6  #include <stdlib.h>
     2.7 +#if ! defined(__WINRT__)
     2.8  #include <unistd.h>
     2.9  #endif
    2.10 +#endif
    2.11  
    2.12  static SDL_assert_state
    2.13  SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
     3.1 --- a/src/video/windowsrt/CubeRenderer.cpp	Mon Nov 12 13:25:44 2012 -0500
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,256 +0,0 @@
     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 --- a/src/video/windowsrt/CubeRenderer.h	Mon Nov 12 13:25:44 2012 -0500
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,44 +0,0 @@
     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 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Nov 12 13:25:44 2012 -0500
     5.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Mon Nov 19 22:07:06 2012 -0500
     5.3 @@ -11,6 +11,9 @@
     5.4  #include "SDL_log.h"
     5.5  }
     5.6  
     5.7 +// TODO, WinRT: Remove reference(s) to BasicTimer.h
     5.8 +#include "BasicTimer.h"
     5.9 +
    5.10  // HACK, DLudwig: The C-style main() will get loaded via the app's
    5.11  // WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
    5.12  // This seems wrong on some level, but does seem to work.
    5.13 @@ -54,7 +57,7 @@
    5.14  	CoreApplication::Resuming +=
    5.15          ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
    5.16  
    5.17 -	m_renderer = ref new CubeRenderer();
    5.18 +	m_renderer = ref new SDL_winrtrenderer();
    5.19  }
    5.20  
    5.21  void SDL_WinRTApp::SetWindow(CoreWindow^ window)
    5.22 @@ -112,9 +115,6 @@
    5.23  		if (m_windowVisible)
    5.24  		{
    5.25  			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
    5.26 -			m_renderer->Update(0.0f, 0.0f);
    5.27 -			m_renderer->Render();
    5.28 -			m_renderer->Present(); // This call is synchronized to the display frame rate.
    5.29  		}
    5.30  		else
    5.31  		{
    5.32 @@ -123,6 +123,16 @@
    5.33  	}
    5.34  }
    5.35  
    5.36 +void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects)
    5.37 +{
    5.38 +    if (!m_windowClosed && m_windowVisible)
    5.39 +	{
    5.40 +		m_renderer->Update(0.0f, 0.0f);
    5.41 +		m_renderer->Render();
    5.42 +		m_renderer->Present(); // This call is synchronized to the display frame rate.
    5.43 +	}
    5.44 +}
    5.45 +
    5.46  void SDL_WinRTApp::Uninitialize()
    5.47  {
    5.48  }
     6.1 --- a/src/video/windowsrt/SDL_WinRTApp.h	Mon Nov 12 13:25:44 2012 -0500
     6.2 +++ b/src/video/windowsrt/SDL_WinRTApp.h	Mon Nov 19 22:07:06 2012 -0500
     6.3 @@ -2,7 +2,7 @@
     6.4  
     6.5  #include "SDLmain_WinRT_common.h"
     6.6  #include "SDL_winrtvideo.h"
     6.7 -#include "CubeRenderer.h"
     6.8 +#include "SDL_winrtrenderer.h"
     6.9  #include <vector>
    6.10  
    6.11  using namespace Windows::UI::Core;
    6.12 @@ -26,6 +26,7 @@
    6.13      const SDL_WindowData * GetSDLWindowData() const;
    6.14      bool HasSDLWindowData() const;
    6.15      void SetSDLWindowData(const SDL_WindowData * windowData);
    6.16 +    void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
    6.17  
    6.18  protected:
    6.19  	// Event Handlers.
    6.20 @@ -43,7 +44,7 @@
    6.21      void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    6.22  
    6.23  private:
    6.24 -	CubeRenderer^ m_renderer;
    6.25 +	SDL_winrtrenderer^ m_renderer;
    6.26  	bool m_windowClosed;
    6.27  	bool m_windowVisible;
    6.28      const SDL_WindowData* m_sdlWindowData;
     7.1 --- a/src/video/windowsrt/SDL_winrtframebuffer.cpp	Mon Nov 12 13:25:44 2012 -0500
     7.2 +++ b/src/video/windowsrt/SDL_winrtframebuffer.cpp	Mon Nov 19 22:07:06 2012 -0500
     7.3 @@ -24,6 +24,9 @@
     7.4  
     7.5  #include "../SDL_sysvideo.h"
     7.6  #include "SDL_winrtframebuffer_c.h"
     7.7 +#include "SDL_WinRTApp.h"
     7.8 +
     7.9 +extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
    7.10  
    7.11  
    7.12  #define WINRT_SURFACE   "_SDL_WinRTSurface"
    7.13 @@ -76,6 +79,9 @@
    7.14                       SDL_GetWindowID(window), ++frame_number);
    7.15          SDL_SaveBMP(surface, file);
    7.16      }
    7.17 +
    7.18 +    SDL_WinRTGlobalApp->UpdateWindowFramebuffer(surface, rects, numrects);
    7.19 +
    7.20      return 0;
    7.21  }
    7.22  
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Mon Nov 19 22:07:06 2012 -0500
     8.3 @@ -0,0 +1,182 @@
     8.4 +#include "SDLmain_WinRT_common.h"
     8.5 +#include "SDL_winrtrenderer.h"
     8.6 +
     8.7 +using namespace DirectX;
     8.8 +using namespace Microsoft::WRL;
     8.9 +using namespace Windows::Foundation;
    8.10 +using namespace Windows::UI::Core;
    8.11 +
    8.12 +SDL_winrtrenderer::SDL_winrtrenderer() :
    8.13 +	m_loadingComplete(false),
    8.14 +	m_vertexCount(0)
    8.15 +{
    8.16 +}
    8.17 +
    8.18 +void SDL_winrtrenderer::CreateDeviceResources()
    8.19 +{
    8.20 +	Direct3DBase::CreateDeviceResources();
    8.21 +
    8.22 +	auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
    8.23 +	auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
    8.24 +
    8.25 +	auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
    8.26 +		DX::ThrowIfFailed(
    8.27 +			m_d3dDevice->CreateVertexShader(
    8.28 + 				fileData->Data,
    8.29 +				fileData->Length,
    8.30 +				nullptr,
    8.31 +				&m_vertexShader
    8.32 +				)
    8.33 +			);
    8.34 +
    8.35 +		const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
    8.36 +		{
    8.37 +			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
    8.38 +			{ "COLOR",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    8.39 +		};
    8.40 +
    8.41 +		DX::ThrowIfFailed(
    8.42 +			m_d3dDevice->CreateInputLayout(
    8.43 +				vertexDesc,
    8.44 +				ARRAYSIZE(vertexDesc),
    8.45 +				fileData->Data,
    8.46 +				fileData->Length,
    8.47 +				&m_inputLayout
    8.48 +				)
    8.49 +			);
    8.50 +	});
    8.51 +
    8.52 +	auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
    8.53 +		DX::ThrowIfFailed(
    8.54 +			m_d3dDevice->CreatePixelShader(
    8.55 +				fileData->Data,
    8.56 +				fileData->Length,
    8.57 +				nullptr,
    8.58 +				&m_pixelShader
    8.59 +				)
    8.60 +			);
    8.61 +
    8.62 +		CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
    8.63 +		DX::ThrowIfFailed(
    8.64 +			m_d3dDevice->CreateBuffer(
    8.65 +				&constantBufferDesc,
    8.66 +				nullptr,
    8.67 +				&m_constantBuffer
    8.68 +				)
    8.69 +			);
    8.70 +	});
    8.71 +
    8.72 +	auto createCubeTask = (createPSTask && createVSTask).then([this] () {
    8.73 +		VertexPositionColor cubeVertices[] = 
    8.74 +		{
    8.75 +			{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
    8.76 +			{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
    8.77 +			{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
    8.78 +			{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
    8.79 +		};
    8.80 +
    8.81 +		m_vertexCount = ARRAYSIZE(cubeVertices);
    8.82 +
    8.83 +		D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
    8.84 +		vertexBufferData.pSysMem = cubeVertices;
    8.85 +		vertexBufferData.SysMemPitch = 0;
    8.86 +		vertexBufferData.SysMemSlicePitch = 0;
    8.87 +		CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
    8.88 +		DX::ThrowIfFailed(
    8.89 +			m_d3dDevice->CreateBuffer(
    8.90 +				&vertexBufferDesc,
    8.91 +				&vertexBufferData,
    8.92 +				&m_vertexBuffer
    8.93 +				)
    8.94 +			);
    8.95 +	});
    8.96 +
    8.97 +	createCubeTask.then([this] () {
    8.98 +		m_loadingComplete = true;
    8.99 +	});
   8.100 +}
   8.101 +
   8.102 +void SDL_winrtrenderer::Update(float timeTotal, float timeDelta)
   8.103 +{
   8.104 +	(void) timeDelta; // Unused parameter.
   8.105 +
   8.106 +	XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
   8.107 +	XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
   8.108 +	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
   8.109 +
   8.110 +	XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixIdentity());
   8.111 +	XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixIdentity());
   8.112 +}
   8.113 +
   8.114 +void SDL_winrtrenderer::Render()
   8.115 +{
   8.116 +	const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
   8.117 +	m_d3dContext->ClearRenderTargetView(
   8.118 +		m_renderTargetView.Get(),
   8.119 +		midnightBlue
   8.120 +		);
   8.121 +
   8.122 +	m_d3dContext->ClearDepthStencilView(
   8.123 +		m_depthStencilView.Get(),
   8.124 +		D3D11_CLEAR_DEPTH,
   8.125 +		1.0f,
   8.126 +		0
   8.127 +		);
   8.128 +
   8.129 +	// Only draw the cube once it is loaded (loading is asynchronous).
   8.130 +	if (!m_loadingComplete)
   8.131 +	{
   8.132 +		return;
   8.133 +	}
   8.134 +
   8.135 +	m_d3dContext->RSSetState(m_rasterState.Get());
   8.136 +
   8.137 +	m_d3dContext->OMSetRenderTargets(
   8.138 +		1,
   8.139 +		m_renderTargetView.GetAddressOf(),
   8.140 +		m_depthStencilView.Get()
   8.141 +		);
   8.142 +
   8.143 +	m_d3dContext->UpdateSubresource(
   8.144 +		m_constantBuffer.Get(),
   8.145 +		0,
   8.146 +		NULL,
   8.147 +		&m_constantBufferData,
   8.148 +		0,
   8.149 +		0
   8.150 +		);
   8.151 +
   8.152 +	UINT stride = sizeof(VertexPositionColor);
   8.153 +	UINT offset = 0;
   8.154 +	m_d3dContext->IASetVertexBuffers(
   8.155 +		0,
   8.156 +		1,
   8.157 +		m_vertexBuffer.GetAddressOf(),
   8.158 +		&stride,
   8.159 +		&offset
   8.160 +		);
   8.161 +
   8.162 +	m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
   8.163 +
   8.164 +	m_d3dContext->IASetInputLayout(m_inputLayout.Get());
   8.165 +
   8.166 +	m_d3dContext->VSSetShader(
   8.167 +		m_vertexShader.Get(),
   8.168 +		nullptr,
   8.169 +		0
   8.170 +		);
   8.171 +
   8.172 +	m_d3dContext->VSSetConstantBuffers(
   8.173 +		0,
   8.174 +		1,
   8.175 +		m_constantBuffer.GetAddressOf()
   8.176 +		);
   8.177 +
   8.178 +	m_d3dContext->PSSetShader(
   8.179 +		m_pixelShader.Get(),
   8.180 +		nullptr,
   8.181 +		0
   8.182 +		);
   8.183 +
   8.184 +	m_d3dContext->Draw(4, 0);
   8.185 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.h	Mon Nov 19 22:07:06 2012 -0500
     9.3 @@ -0,0 +1,43 @@
     9.4 +#pragma once
     9.5 +
     9.6 +#include "Direct3DBase.h"
     9.7 +
     9.8 +struct ModelViewProjectionConstantBuffer
     9.9 +{
    9.10 +	DirectX::XMFLOAT4X4 model;
    9.11 +	DirectX::XMFLOAT4X4 view;
    9.12 +	DirectX::XMFLOAT4X4 projection;
    9.13 +};
    9.14 +
    9.15 +struct VertexPositionColor
    9.16 +{
    9.17 +	DirectX::XMFLOAT3 pos;
    9.18 +	DirectX::XMFLOAT3 color;
    9.19 +};
    9.20 +
    9.21 +// This class renders a simple spinning cube.
    9.22 +ref class SDL_winrtrenderer sealed : public Direct3DBase
    9.23 +{
    9.24 +public:
    9.25 +	SDL_winrtrenderer();
    9.26 +
    9.27 +	// Direct3DBase methods.
    9.28 +	virtual void CreateDeviceResources() override;
    9.29 +	virtual void Render() override;
    9.30 +	
    9.31 +	// Method for updating time-dependent objects.
    9.32 +	void Update(float timeTotal, float timeDelta);
    9.33 +
    9.34 +private:
    9.35 +	bool m_loadingComplete;
    9.36 +
    9.37 +	Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
    9.38 +	Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
    9.39 +	Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
    9.40 +	Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
    9.41 +	Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
    9.42 +	Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_rasterState;
    9.43 +
    9.44 +	uint32 m_vertexCount;
    9.45 +	ModelViewProjectionConstantBuffer m_constantBufferData;
    9.46 +};