CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UWP/Common/DirectXHelper.h
Views: 1401
#pragma once12#include <ppltasks.h> // For create_task34namespace DX5{6inline void ThrowIfFailed(HRESULT hr)7{8if (FAILED(hr))9{10// Set a breakpoint on this line to catch Win32 API errors.11throw Platform::Exception::CreateException(hr);12}13}1415// Function that reads from a binary file asynchronously.16inline Concurrency::task<std::vector<byte>> ReadDataAsync(const std::wstring& filename)17{18using namespace Windows::Storage;19using namespace Concurrency;2021auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;2223return create_task(folder->GetFileAsync(Platform::StringReference(filename.c_str()))).then([] (StorageFile^ file)24{25return FileIO::ReadBufferAsync(file);26}).then([] (Streams::IBuffer^ fileBuffer) -> std::vector<byte>27{28std::vector<byte> returnBuffer;29returnBuffer.resize(fileBuffer->Length);30Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(Platform::ArrayReference<byte>(returnBuffer.data(), fileBuffer->Length));31return returnBuffer;32});33}3435// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.36inline float ConvertDipsToPixels(float dips, float dpi)37{38static const float dipsPerInch = 96.0f;39return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.40}4142#if defined(_DEBUG)43// Check for SDK Layer support.44inline bool SdkLayersAvailable()45{46HRESULT hr = D3D11CreateDevice(47nullptr,48D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.490,50D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers.51nullptr, // Any feature level will do.520,53D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.54nullptr, // No need to keep the D3D device reference.55nullptr, // No need to know the feature level.56nullptr // No need to keep the D3D device context reference.57);5859return SUCCEEDED(hr);60}61#endif62}636465