Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merged with local changes

  • Loading branch information
DavidLudwig committed Nov 20, 2012
2 parents 46e3738 + f9f94bf commit 863fbf62d972d3d453fe3819d70fd05fd6f12aea
@@ -101,39 +101,46 @@
<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">
<ClCompile Include="..\..\src\video\windowsrt\Direct3DBase.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">
<ClCompile Include="..\..\src\video\windowsrt\SDL_WinRTApp.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\SDL_WinRTApp.cpp">
<ClCompile Include="..\..\src\video\windowsrt\SDL_winrtevents.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\SDL_winrtevents.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_winrtframebuffer.cpp" />
<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">
@@ -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);
@@ -11,6 +11,9 @@ extern "C" {
#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 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
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 @@ void SDL_WinRTApp::PumpEvents()
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::PumpEvents()
}
}

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()
{
}
@@ -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 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo
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 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo
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;
@@ -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 @@ int SDL_WINRT_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rec
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}

SDL_WinRTGlobalApp->UpdateWindowFramebuffer(surface, rects, numrects);

return 0;
}

@@ -1,18 +1,18 @@
#include "SDLmain_WinRT_common.h"
#include "CubeRenderer.h"
#include "SDL_winrtrenderer.h"

using namespace DirectX;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;

CubeRenderer::CubeRenderer() :
SDL_winrtrenderer::SDL_winrtrenderer() :
m_loadingComplete(false),
m_indexCount(0)
m_vertexCount(0)
{
}

void CubeRenderer::CreateDeviceResources()
void SDL_winrtrenderer::CreateDeviceResources()
{
Direct3DBase::CreateDeviceResources();

@@ -69,16 +69,14 @@ void CubeRenderer::CreateDeviceResources()
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)},
{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;
@@ -91,90 +89,26 @@ void CubeRenderer::CreateDeviceResources()
&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 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, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY(timeTotal * XM_PIDIV4)));
XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixIdentity());
XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixIdentity());
}

void CubeRenderer::Render()
void SDL_winrtrenderer::Render()
{
const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
m_d3dContext->ClearRenderTargetView(
@@ -195,6 +129,8 @@ void CubeRenderer::Render()
return;
}

m_d3dContext->RSSetState(m_rasterState.Get());

m_d3dContext->OMSetRenderTargets(
1,
m_renderTargetView.GetAddressOf(),
@@ -220,13 +156,7 @@ void CubeRenderer::Render()
&offset
);

m_d3dContext->IASetIndexBuffer(
m_indexBuffer.Get(),
DXGI_FORMAT_R16_UINT,
0
);

m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

m_d3dContext->IASetInputLayout(m_inputLayout.Get());

@@ -248,9 +178,5 @@ void CubeRenderer::Render()
0
);

m_d3dContext->DrawIndexed(
m_indexCount,
0,
0
);
m_d3dContext->Draw(4, 0);
}
@@ -16,14 +16,13 @@ struct VertexPositionColor
};

// This class renders a simple spinning cube.
ref class CubeRenderer sealed : public Direct3DBase
ref class SDL_winrtrenderer sealed : public Direct3DBase
{
public:
CubeRenderer();
SDL_winrtrenderer();

// Direct3DBase methods.
virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;

// Method for updating time-dependent objects.
@@ -34,11 +33,11 @@ ref class CubeRenderer sealed : public Direct3DBase

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;
Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_rasterState;

uint32 m_indexCount;
uint32 m_vertexCount;
ModelViewProjectionConstantBuffer m_constantBufferData;
};

0 comments on commit 863fbf6

Please sign in to comment.