diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Tests/VSWinStorePhone | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Tests/VSWinStorePhone')
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h | 25 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp | 283 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp | 101 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h | 46 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp | 301 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h | 8 | ||||
-rw-r--r-- | Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h | 37 |
7 files changed, 345 insertions, 456 deletions
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h b/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h index b58c77d..56bd398 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h +++ b/Tests/VSWinStorePhone/Direct3DApp1/BasicTimer.h @@ -9,8 +9,7 @@ public: // Initializes internal timer values. BasicTimer() { - if (!QueryPerformanceFrequency(&m_frequency)) - { + if (!QueryPerformanceFrequency(&m_frequency)) { throw ref new Platform::FailureException(); } Reset(); @@ -28,33 +27,29 @@ public: // Update the timer's internal values. void Update() { - if (!QueryPerformanceCounter(&m_currentTime)) - { + if (!QueryPerformanceCounter(&m_currentTime)) { throw ref new Platform::FailureException(); } m_total = static_cast<float>( static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) / - static_cast<double>(m_frequency.QuadPart) - ); + static_cast<double>(m_frequency.QuadPart)); - if (m_lastTime.QuadPart == m_startTime.QuadPart) - { - // If the timer was just reset, report a time delta equivalent to 60Hz frame time. + if (m_lastTime.QuadPart == m_startTime.QuadPart) { + // If the timer was just reset, report a time delta equivalent to 60Hz + // frame time. m_delta = 1.0f / 60.0f; - } - else - { + } else { m_delta = static_cast<float>( static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) / - static_cast<double>(m_frequency.QuadPart) - ); + static_cast<double>(m_frequency.QuadPart)); } m_lastTime = m_currentTime; } - // Duration in seconds between the last call to Reset() and the last call to Update(). + // Duration in seconds between the last call to Reset() and the last call to + // Update(). property float Total { float get() { return m_total; } diff --git a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp index 7632388..1c969cd 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp +++ b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp @@ -7,9 +7,9 @@ using namespace Microsoft::WRL; using namespace Windows::Foundation; using namespace Windows::UI::Core; -CubeRenderer::CubeRenderer() : - m_loadingComplete(false), - m_indexCount(0) +CubeRenderer::CubeRenderer() + : m_loadingComplete(false) + , m_indexCount(0) { } @@ -20,119 +20,88 @@ void CubeRenderer::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 }, + 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) }, }; - 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}; + 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, + 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}; + 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 - ) - ); + 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; - }); + createCubeTask.then([this]() { m_loadingComplete = true; }); } void CubeRenderer::CreateWindowSizeDependentResources() @@ -141,8 +110,7 @@ void CubeRenderer::CreateWindowSizeDependentResources() float aspectRatio = m_windowBounds.Width / m_windowBounds.Height; float fovAngleY = 70.0f * XM_PI / 180.0f; - if (aspectRatio < 1.0f) - { + if (aspectRatio < 1.0f) { fovAngleY /= aspectRatio; } @@ -153,109 +121,60 @@ void CubeRenderer::CreateWindowSizeDependentResources() // this transform should not be applied. XMStoreFloat4x4( &m_constantBufferData.projection, - XMMatrixTranspose( - XMMatrixMultiply( - XMMatrixPerspectiveFovRH( - fovAngleY, - aspectRatio, - 0.01f, - 100.0f - ), - XMLoadFloat4x4(&m_orientationTransform3D) - ) - ) - ); + XMMatrixTranspose(XMMatrixMultiply( + XMMatrixPerspectiveFovRH(fovAngleY, aspectRatio, 0.01f, 100.0f), + XMLoadFloat4x4(&m_orientationTransform3D)))); } void CubeRenderer::Update(float timeTotal, float timeDelta) { - (void) timeDelta; // Unused parameter. + (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, + 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 - ); + 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) - { + 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 - ); + 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->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 - ); + 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); } diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp index 41ca124..ddcd8bd 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp +++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.cpp @@ -12,71 +12,76 @@ using namespace Windows::Foundation; using namespace Windows::Graphics::Display; using namespace concurrency; -Direct3DApp1::Direct3DApp1() : - m_windowClosed(false), - m_windowVisible(true) +Direct3DApp1::Direct3DApp1() + : m_windowClosed(false) + , m_windowVisible(true) { } -void Direct3DApp1::Initialize(CoreApplicationView^ applicationView) +void Direct3DApp1::Initialize(CoreApplicationView ^ applicationView) { applicationView->Activated += - ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &Direct3DApp1::OnActivated); + ref new TypedEventHandler<CoreApplicationView ^, IActivatedEventArgs ^>( + this, &Direct3DApp1::OnActivated); - CoreApplication::Suspending += - ref new EventHandler<SuspendingEventArgs^>(this, &Direct3DApp1::OnSuspending); + CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs ^>( + this, &Direct3DApp1::OnSuspending); CoreApplication::Resuming += - ref new EventHandler<Platform::Object^>(this, &Direct3DApp1::OnResuming); + ref new EventHandler<Platform::Object ^>(this, &Direct3DApp1::OnResuming); m_renderer = ref new CubeRenderer(); } -void Direct3DApp1::SetWindow(CoreWindow^ window) +void Direct3DApp1::SetWindow(CoreWindow ^ window) { window->SizeChanged += - ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &Direct3DApp1::OnWindowSizeChanged); + ref new TypedEventHandler<CoreWindow ^, WindowSizeChangedEventArgs ^>( + this, &Direct3DApp1::OnWindowSizeChanged); window->VisibilityChanged += - ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &Direct3DApp1::OnVisibilityChanged); + ref new TypedEventHandler<CoreWindow ^, VisibilityChangedEventArgs ^>( + this, &Direct3DApp1::OnVisibilityChanged); window->Closed += - ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &Direct3DApp1::OnWindowClosed); + ref new TypedEventHandler<CoreWindow ^, CoreWindowEventArgs ^>( + this, &Direct3DApp1::OnWindowClosed); #ifndef PHONE window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); #endif window->PointerPressed += - ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &Direct3DApp1::OnPointerPressed); + ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>( + this, &Direct3DApp1::OnPointerPressed); window->PointerMoved += - ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &Direct3DApp1::OnPointerMoved); + ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>( + this, &Direct3DApp1::OnPointerMoved); m_renderer->Initialize(CoreWindow::GetForCurrentThread()); } -void Direct3DApp1::Load(Platform::String^ entryPoint) +void Direct3DApp1::Load(Platform::String ^ entryPoint) { } void Direct3DApp1::Run() { - BasicTimer^ timer = ref new BasicTimer(); + BasicTimer ^ timer = ref new BasicTimer(); - while (!m_windowClosed) - { - if (m_windowVisible) - { + while (!m_windowClosed) { + if (m_windowVisible) { timer->Update(); - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents( + CoreProcessEventsOption::ProcessAllIfPresent); m_renderer->Update(timer->Total, timer->Delta); m_renderer->Render(); - m_renderer->Present(); // This call is synchronized to the display frame rate. - } - else - { - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + m_renderer + ->Present(); // This call is synchronized to the display frame rate. + } else { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents( + CoreProcessEventsOption::ProcessOneAndAllPending); } } } @@ -85,54 +90,63 @@ void Direct3DApp1::Uninitialize() { } -void Direct3DApp1::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) +void Direct3DApp1::OnWindowSizeChanged(CoreWindow ^ sender, + WindowSizeChangedEventArgs ^ args) { m_renderer->UpdateForWindowSizeChange(); } -void Direct3DApp1::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) +void Direct3DApp1::OnVisibilityChanged(CoreWindow ^ sender, + VisibilityChangedEventArgs ^ args) { m_windowVisible = args->Visible; } -void Direct3DApp1::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) +void Direct3DApp1::OnWindowClosed(CoreWindow ^ sender, + CoreWindowEventArgs ^ args) { m_windowClosed = true; } -void Direct3DApp1::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) +void Direct3DApp1::OnPointerPressed(CoreWindow ^ sender, + PointerEventArgs ^ args) { // Insert your code here. } -void Direct3DApp1::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) +void Direct3DApp1::OnPointerMoved(CoreWindow ^ sender, PointerEventArgs ^ args) { // Insert your code here. } -void Direct3DApp1::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) +void Direct3DApp1::OnActivated(CoreApplicationView ^ applicationView, + IActivatedEventArgs ^ args) { CoreWindow::GetForCurrentThread()->Activate(); } -void Direct3DApp1::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) +void Direct3DApp1::OnSuspending(Platform::Object ^ sender, + SuspendingEventArgs ^ args) { - // Save app state asynchronously after requesting a deferral. Holding a deferral - // indicates that the application is busy performing suspending operations. Be - // aware that a deferral may not be held indefinitely. After about five seconds, + // Save app state asynchronously after requesting a deferral. Holding a + // deferral + // indicates that the application is busy performing suspending operations. + // Be + // aware that a deferral may not be held indefinitely. After about five + // seconds, // the app will be forced to exit. - SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); + SuspendingDeferral ^ deferral = args->SuspendingOperation->GetDeferral(); m_renderer->ReleaseResourcesForSuspending(); - create_task([this, deferral]() - { + create_task([this, deferral]() { // Insert your code here. deferral->Complete(); }); } -void Direct3DApp1::OnResuming(Platform::Object^ sender, Platform::Object^ args) +void Direct3DApp1::OnResuming(Platform::Object ^ sender, + Platform::Object ^ args) { // Restore any data or state that was unloaded on suspend. By default, data // and state are persisted when resuming from suspend. Note that this event @@ -140,13 +154,12 @@ void Direct3DApp1::OnResuming(Platform::Object^ sender, Platform::Object^ args) m_renderer->CreateWindowSizeDependentResources(); } -IFrameworkView^ Direct3DApplicationSource::CreateView() +IFrameworkView ^ Direct3DApplicationSource::CreateView() { - return ref new Direct3DApp1(); + return ref new Direct3DApp1(); } -[Platform::MTAThread] -int main(Platform::Array<Platform::String^>^) +[Platform::MTAThread] int main(Platform::Array<Platform::String ^> ^) { auto direct3DApplicationSource = ref new Direct3DApplicationSource(); CoreApplication::Run(direct3DApplicationSource); diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h index 6861e44..c3499c7 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h +++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DApp1.h @@ -4,38 +4,52 @@ #include "CubeRenderer.h" -ref class Direct3DApp1 sealed : public Windows::ApplicationModel::Core::IFrameworkView +ref class Direct3DApp1 sealed + : public Windows::ApplicationModel::Core::IFrameworkView { public: Direct3DApp1(); // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); - virtual void Load(Platform::String^ entryPoint); + virtual void Initialize( + Windows::ApplicationModel::Core::CoreApplicationView ^ applicationView); + virtual void SetWindow(Windows::UI::Core::CoreWindow ^ window); + virtual void Load(Platform::String ^ entryPoint); virtual void Run(); virtual void Uninitialize(); protected: // Event Handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); - void OnLogicalDpiChanged(Platform::Object^ sender); - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); - void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args); - void OnResuming(Platform::Object^ sender, Platform::Object^ args); - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); - void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow ^ sender, + Windows::UI::Core::WindowSizeChangedEventArgs ^ + args); + void OnLogicalDpiChanged(Platform::Object ^ sender); + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView ^ + applicationView, + Windows::ApplicationModel::Activation::IActivatedEventArgs ^ + args); + void OnSuspending(Platform::Object ^ sender, + Windows::ApplicationModel::SuspendingEventArgs ^ args); + void OnResuming(Platform::Object ^ sender, Platform::Object ^ args); + void OnWindowClosed(Windows::UI::Core::CoreWindow ^ sender, + Windows::UI::Core::CoreWindowEventArgs ^ args); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow ^ sender, + Windows::UI::Core::VisibilityChangedEventArgs ^ + args); + void OnPointerPressed(Windows::UI::Core::CoreWindow ^ sender, + Windows::UI::Core::PointerEventArgs ^ args); + void OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, + Windows::UI::Core::PointerEventArgs ^ args); private: - CubeRenderer^ m_renderer; + CubeRenderer ^ m_renderer; bool m_windowClosed; bool m_windowVisible; }; -ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +ref class Direct3DApplicationSource sealed + : Windows::ApplicationModel::Core::IFrameworkViewSource { public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView(); + virtual Windows::ApplicationModel::Core::IFrameworkView ^ CreateView(); }; diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp index f09c8da..8f3452c 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp +++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp @@ -14,7 +14,7 @@ Direct3DBase::Direct3DBase() } // Initialize the Direct3D resources required to run. -void Direct3DBase::Initialize(CoreWindow^ window) +void Direct3DBase::Initialize(CoreWindow ^ window) { m_window = window; @@ -25,7 +25,8 @@ void Direct3DBase::Initialize(CoreWindow^ window) // Recreate all device resources and set them back to the current state. void Direct3DBase::HandleDeviceLost() { - // Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources. + // Reset these member variables to ensure that UpdateForWindowSizeChange + // recreates all resources. m_windowBounds.Width = 0; m_windowBounds.Height = 0; m_swapChain = nullptr; @@ -37,56 +38,50 @@ void Direct3DBase::HandleDeviceLost() // These are the resources that depend on the device. void Direct3DBase::CreateDeviceResources() { - // This flag adds support for surfaces with a different color channel ordering + // This flag adds support for surfaces with a different color channel + // ordering // than the API default. It is required for compatibility with Direct2D. UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; #if defined(_DEBUG) - // If the project is in a debug build, enable debugging via SDK Layers with this flag. + // If the project is in a debug build, enable debugging via SDK Layers with + // this flag. creationFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif - // This array defines the set of DirectX hardware feature levels this app will support. + // This array defines the set of DirectX hardware feature levels this app + // will support. // Note the ordering should be preserved. - // Don't forget to declare your application's minimum required feature level in its - // description. All applications are assumed to support 9.1 unless otherwise stated. - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, + // Don't forget to declare your application's minimum required feature level + // in its + // description. All applications are assumed to support 9.1 unless otherwise + // stated. + D3D_FEATURE_LEVEL featureLevels[] = { + D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 }; // Create the Direct3D 11 API device object and a corresponding context. ComPtr<ID3D11Device> device; ComPtr<ID3D11DeviceContext> context; - DX::ThrowIfFailed( - D3D11CreateDevice( - nullptr, // Specify nullptr to use the default adapter. - D3D_DRIVER_TYPE_HARDWARE, - nullptr, - creationFlags, // Set set debug and Direct2D compatibility flags. - featureLevels, // List of feature levels this app can support. - ARRAYSIZE(featureLevels), - D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. - &device, // Returns the Direct3D device created. - &m_featureLevel, // Returns feature level of device created. - &context // Returns the device immediate context. - ) - ); + DX::ThrowIfFailed(D3D11CreateDevice( + nullptr, // Specify nullptr to use the default adapter. + D3D_DRIVER_TYPE_HARDWARE, nullptr, + creationFlags, // Set set debug and Direct2D compatibility flags. + featureLevels, // List of feature levels this app can support. + ARRAYSIZE(featureLevels), + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows + // Store apps. + &device, // Returns the Direct3D device created. + &m_featureLevel, // Returns feature level of device created. + &context // Returns the device immediate context. + )); // Get the Direct3D 11.1 API device and context interfaces. - DX::ThrowIfFailed( - device.As(&m_d3dDevice) - ); + DX::ThrowIfFailed(device.As(&m_d3dDevice)); - DX::ThrowIfFailed( - context.As(&m_d3dContext) - ); + DX::ThrowIfFailed(context.As(&m_d3dContext)); } // Allocate all memory resources that change on a window SizeChanged event. @@ -100,9 +95,9 @@ void Direct3DBase::CreateWindowSizeDependentResources() float windowWidth = ConvertDipsToPixels(m_windowBounds.Width); float windowHeight = ConvertDipsToPixels(m_windowBounds.Height); - // The width and height of the swap chain must be based on the window's - // landscape-oriented width and height. If the window is in a portrait - // orientation, the dimensions must be reversed. +// The width and height of the swap chain must be based on the window's +// landscape-oriented width and height. If the window is in a portrait +// orientation, the dimensions must be reversed. #if WINVER > 0x0602 m_orientation = DisplayInformation::GetForCurrentView()->CurrentOrientation; #else @@ -113,126 +108,100 @@ void Direct3DBase::CreateWindowSizeDependentResources() m_orientation = DisplayProperties::CurrentOrientation; #endif #endif - bool swapDimensions = - m_orientation == DisplayOrientations::Portrait || + bool swapDimensions = m_orientation == DisplayOrientations::Portrait || m_orientation == DisplayOrientations::PortraitFlipped; m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth; m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight; - if(m_swapChain != nullptr) - { + if (m_swapChain != nullptr) { // If the swap chain already exists, resize it. DX::ThrowIfFailed( - m_swapChain->ResizeBuffers( - 2, // Double-buffered swap chain. - static_cast<UINT>(m_renderTargetSize.Width), - static_cast<UINT>(m_renderTargetSize.Height), - DXGI_FORMAT_B8G8R8A8_UNORM, - 0 - ) - ); - } - else - { - // Otherwise, create a new one using the same adapter as the existing Direct3D device. - DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0}; - swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the window. + m_swapChain->ResizeBuffers(2, // Double-buffered swap chain. + static_cast<UINT>(m_renderTargetSize.Width), + static_cast<UINT>(m_renderTargetSize.Height), + DXGI_FORMAT_B8G8R8A8_UNORM, 0)); + } else { + // Otherwise, create a new one using the same adapter as the existing + // Direct3D device. + DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 }; + swapChainDesc.Width = static_cast<UINT>( + m_renderTargetSize.Width); // Match the size of the window. swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height); - swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format. + swapChainDesc.Format = + DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format. swapChainDesc.Stereo = false; swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling. swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; #if PHONE && WINVER <= 0x0602 swapChainDesc.BufferCount = 1; // Use double-buffering to minimize latency. - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed. - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported. + swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and + // aspect-ratio stretch + // scaling are allowed. + swapChainDesc.SwapEffect = + DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported. #else swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency. swapChainDesc.Scaling = DXGI_SCALING_NONE; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect. + swapChainDesc.SwapEffect = + DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this + // SwapEffect. #endif swapChainDesc.Flags = 0; - ComPtr<IDXGIDevice1> dxgiDevice; - DX::ThrowIfFailed( - m_d3dDevice.As(&dxgiDevice) - ); + ComPtr<IDXGIDevice1> dxgiDevice; + DX::ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ComPtr<IDXGIAdapter> dxgiAdapter; - DX::ThrowIfFailed( - dxgiDevice->GetAdapter(&dxgiAdapter) - ); + DX::ThrowIfFailed(dxgiDevice->GetAdapter(&dxgiAdapter)); ComPtr<IDXGIFactory2> dxgiFactory; DX::ThrowIfFailed( - dxgiAdapter->GetParent( - __uuidof(IDXGIFactory2), - &dxgiFactory - ) - ); - - Windows::UI::Core::CoreWindow^ window = m_window.Get(); - DX::ThrowIfFailed( - dxgiFactory->CreateSwapChainForCoreWindow( - m_d3dDevice.Get(), - reinterpret_cast<IUnknown*>(window), - &swapChainDesc, - nullptr, // Allow on all displays. - &m_swapChain - ) - ); - - // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and - // ensures that the application will only render after each VSync, minimizing power consumption. - DX::ThrowIfFailed( - dxgiDevice->SetMaximumFrameLatency(1) - ); + dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), &dxgiFactory)); + + Windows::UI::Core::CoreWindow ^ window = m_window.Get(); + DX::ThrowIfFailed(dxgiFactory->CreateSwapChainForCoreWindow( + m_d3dDevice.Get(), reinterpret_cast<IUnknown*>(window), &swapChainDesc, + nullptr, // Allow on all displays. + &m_swapChain)); + + // Ensure that DXGI does not queue more than one frame at a time. This both + // reduces latency and + // ensures that the application will only render after each VSync, + // minimizing power consumption. + DX::ThrowIfFailed(dxgiDevice->SetMaximumFrameLatency(1)); } // Set the proper orientation for the swap chain, and generate the // 3D matrix transformation for rendering to the rotated swap chain. DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED; - switch (m_orientation) - { + switch (m_orientation) { case DisplayOrientations::Landscape: rotation = DXGI_MODE_ROTATION_IDENTITY; m_orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); break; case DisplayOrientations::Portrait: rotation = DXGI_MODE_ROTATION_ROTATE270; m_orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation - 0.0f, 1.0f, 0.0f, 0.0f, - -1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); break; case DisplayOrientations::LandscapeFlipped: rotation = DXGI_MODE_ROTATION_ROTATE180; m_orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation - -1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, -1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); break; case DisplayOrientations::PortraitFlipped: rotation = DXGI_MODE_ROTATION_ROTATE90; m_orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation - 0.0f, -1.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); break; default: @@ -240,64 +209,35 @@ void Direct3DBase::CreateWindowSizeDependentResources() } #if !PHONE || WINVER > 0x0602 - DX::ThrowIfFailed( - m_swapChain->SetRotation(rotation) - ); + DX::ThrowIfFailed(m_swapChain->SetRotation(rotation)); #endif // !PHONE // Create a render target view of the swap chain back buffer. ComPtr<ID3D11Texture2D> backBuffer; DX::ThrowIfFailed( - m_swapChain->GetBuffer( - 0, - __uuidof(ID3D11Texture2D), - &backBuffer - ) - ); + m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), &backBuffer)); - DX::ThrowIfFailed( - m_d3dDevice->CreateRenderTargetView( - backBuffer.Get(), - nullptr, - &m_renderTargetView - ) - ); + DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView( + backBuffer.Get(), nullptr, &m_renderTargetView)); // Create a depth stencil view. CD3D11_TEXTURE2D_DESC depthStencilDesc( - DXGI_FORMAT_D24_UNORM_S8_UINT, - static_cast<UINT>(m_renderTargetSize.Width), - static_cast<UINT>(m_renderTargetSize.Height), - 1, - 1, - D3D11_BIND_DEPTH_STENCIL - ); + DXGI_FORMAT_D24_UNORM_S8_UINT, static_cast<UINT>(m_renderTargetSize.Width), + static_cast<UINT>(m_renderTargetSize.Height), 1, 1, + D3D11_BIND_DEPTH_STENCIL); ComPtr<ID3D11Texture2D> depthStencil; DX::ThrowIfFailed( - m_d3dDevice->CreateTexture2D( - &depthStencilDesc, - nullptr, - &depthStencil - ) - ); - - CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D); - DX::ThrowIfFailed( - m_d3dDevice->CreateDepthStencilView( - depthStencil.Get(), - &depthStencilViewDesc, - &m_depthStencilView - ) - ); + m_d3dDevice->CreateTexture2D(&depthStencilDesc, nullptr, &depthStencil)); + + CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc( + D3D11_DSV_DIMENSION_TEXTURE2D); + DX::ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( + depthStencil.Get(), &depthStencilViewDesc, &m_depthStencilView)); // Set the rendering viewport to target the entire window. - CD3D11_VIEWPORT viewport( - 0.0f, - 0.0f, - m_renderTargetSize.Width, - m_renderTargetSize.Height - ); + CD3D11_VIEWPORT viewport(0.0f, 0.0f, m_renderTargetSize.Width, + m_renderTargetSize.Height); m_d3dContext->RSSetViewports(1, &viewport); } @@ -306,14 +246,15 @@ void Direct3DBase::CreateWindowSizeDependentResources() void Direct3DBase::UpdateForWindowSizeChange() { if (m_window->Bounds.Width != m_windowBounds.Width || - m_window->Bounds.Height != m_windowBounds.Height || + m_window->Bounds.Height != m_windowBounds.Height || #if WINVER > 0x0602 - m_orientation != DisplayInformation::GetForCurrentView()->CurrentOrientation) + m_orientation != + DisplayInformation::GetForCurrentView()->CurrentOrientation) #else - m_orientation != DisplayProperties::CurrentOrientation) + m_orientation != DisplayProperties::CurrentOrientation) #endif { - ID3D11RenderTargetView* nullViews[] = {nullptr}; + ID3D11RenderTargetView* nullViews[] = { nullptr }; m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr); m_renderTargetView = nullptr; m_depthStencilView = nullptr; @@ -324,10 +265,14 @@ void Direct3DBase::UpdateForWindowSizeChange() void Direct3DBase::ReleaseResourcesForSuspending() { - // Phone applications operate in a memory-constrained environment, so when entering - // the background it is a good idea to free memory-intensive objects that will be - // easy to restore upon reactivation. The swapchain and backbuffer are good candidates - // here, as they consume a large amount of memory and can be reinitialized quickly. + // Phone applications operate in a memory-constrained environment, so when + // entering + // the background it is a good idea to free memory-intensive objects that + // will be + // easy to restore upon reactivation. The swapchain and backbuffer are good + // candidates + // here, as they consume a large amount of memory and can be reinitialized + // quickly. m_swapChain = nullptr; m_renderTargetView = nullptr; m_depthStencilView = nullptr; @@ -336,9 +281,11 @@ void Direct3DBase::ReleaseResourcesForSuspending() // Method to deliver the final image to the display. void Direct3DBase::Present() { - // The first argument instructs DXGI to block until VSync, putting the application - // to sleep until the next VSync. This ensures we don't waste any cycles rendering - // frames that will never be displayed to the screen. +// The first argument instructs DXGI to block until VSync, putting the +// application +// to sleep until the next VSync. This ensures we don't waste any cycles +// rendering +// frames that will never be displayed to the screen. #if PHONE && WINVER <= 0x0602 HRESULT hr = m_swapChain->Present(1, 0); #else @@ -350,12 +297,13 @@ void Direct3DBase::Present() parameters.pScrollRect = nullptr; parameters.pScrollOffset = nullptr; - HRESULT hr = m_swapChain->Present1(1, 0 , ¶meters); + HRESULT hr = m_swapChain->Present1(1, 0, ¶meters); #endif // Discard the contents of the render target. // This is a valid operation only when the existing contents will be entirely - // overwritten. If dirty or scroll rects are used, this call should be removed. + // overwritten. If dirty or scroll rects are used, this call should be + // removed. m_d3dContext->DiscardView(m_renderTargetView.Get()); // Discard the contents of the depth stencil. @@ -363,23 +311,24 @@ void Direct3DBase::Present() // If the device was removed either by a disconnect or a driver upgrade, we // must recreate all device resources. - if (hr == DXGI_ERROR_DEVICE_REMOVED) - { + if (hr == DXGI_ERROR_DEVICE_REMOVED) { HandleDeviceLost(); - } - else - { + } else { DX::ThrowIfFailed(hr); } } -// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels. +// Method to convert a length in device-independent pixels (DIPs) to a length +// in physical pixels. float Direct3DBase::ConvertDipsToPixels(float dips) { static const float dipsPerInch = 96.0f; #if WINVER > 0x0602 - return floor(dips * DisplayInformation::GetForCurrentView()->LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer. + return floor(dips * DisplayInformation::GetForCurrentView()->LogicalDpi / + dipsPerInch + + 0.5f); // Round to nearest integer. #else - return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer. + return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + + 0.5f); // Round to nearest integer. #endif } diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h index bba9f16..f373f00 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h +++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.h @@ -5,11 +5,10 @@ // Helper class that initializes DirectX APIs for 3D rendering. ref class Direct3DBase abstract { -internal: - Direct3DBase(); + internal : Direct3DBase(); public: - virtual void Initialize(Windows::UI::Core::CoreWindow^ window); + virtual void Initialize(Windows::UI::Core::CoreWindow ^ window); virtual void HandleDeviceLost(); virtual void CreateDeviceResources(); virtual void CreateWindowSizeDependentResources(); @@ -19,7 +18,8 @@ public: virtual void Present(); virtual float ConvertDipsToPixels(float dips); -protected private: +protected +private: // Direct3D Objects. Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice; Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext; diff --git a/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h index 3434ba9..c991dbb 100644 --- a/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h +++ b/Tests/VSWinStorePhone/Direct3DApp1/DirectXHelper.h @@ -4,27 +4,26 @@ #include <ppltasks.h> #include <wrl/client.h> -namespace DX +namespace DX { +inline void ThrowIfFailed(HRESULT hr) { - inline void ThrowIfFailed(HRESULT hr) - { - if (FAILED(hr)) - { - // Set a breakpoint on this line to catch Win32 API errors. - throw Platform::Exception::CreateException(hr); - } + if (FAILED(hr)) { + // Set a breakpoint on this line to catch Win32 API errors. + throw Platform::Exception::CreateException(hr); } +} - // Function that reads from a binary file asynchronously. - inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename) - { - using namespace Windows::Storage; - using namespace Concurrency; +// Function that reads from a binary file asynchronously. +inline Concurrency::task<Platform::Array<byte> ^> ReadDataAsync( + Platform::String ^ filename) +{ + using namespace Windows::Storage; + using namespace Concurrency; - auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation; + auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation; - return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) - { + return create_task(folder->GetFileAsync(filename)) + .then([](StorageFile ^ file) { #if !PHONE return FileIO::ReadBufferAsync(file); #else @@ -35,11 +34,11 @@ namespace DX auto fileBuffer = ref new Streams::Buffer(bufferSize); return stream->ReadAsync(fileBuffer, bufferSize, Streams::InputStreamOptions::None); #endif - }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ - { + }) + .then([](Streams::IBuffer ^ fileBuffer) -> Platform::Array<byte> ^ { auto fileData = ref new Platform::Array<byte>(fileBuffer->Length); Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData); return fileData; }); - } +} } |