CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/Common/DirectXHelper.h
Views: 1401
1
#pragma once
2
3
#include <ppltasks.h> // For create_task
4
5
namespace DX
6
{
7
inline void ThrowIfFailed(HRESULT hr)
8
{
9
if (FAILED(hr))
10
{
11
// Set a breakpoint on this line to catch Win32 API errors.
12
throw Platform::Exception::CreateException(hr);
13
}
14
}
15
16
// Function that reads from a binary file asynchronously.
17
inline Concurrency::task<std::vector<byte>> ReadDataAsync(const std::wstring& filename)
18
{
19
using namespace Windows::Storage;
20
using namespace Concurrency;
21
22
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
23
24
return create_task(folder->GetFileAsync(Platform::StringReference(filename.c_str()))).then([] (StorageFile^ file)
25
{
26
return FileIO::ReadBufferAsync(file);
27
}).then([] (Streams::IBuffer^ fileBuffer) -> std::vector<byte>
28
{
29
std::vector<byte> returnBuffer;
30
returnBuffer.resize(fileBuffer->Length);
31
Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(Platform::ArrayReference<byte>(returnBuffer.data(), fileBuffer->Length));
32
return returnBuffer;
33
});
34
}
35
36
// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
37
inline float ConvertDipsToPixels(float dips, float dpi)
38
{
39
static const float dipsPerInch = 96.0f;
40
return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.
41
}
42
43
#if defined(_DEBUG)
44
// Check for SDK Layer support.
45
inline bool SdkLayersAvailable()
46
{
47
HRESULT hr = D3D11CreateDevice(
48
nullptr,
49
D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
50
0,
51
D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers.
52
nullptr, // Any feature level will do.
53
0,
54
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
55
nullptr, // No need to keep the D3D device reference.
56
nullptr, // No need to know the feature level.
57
nullptr // No need to keep the D3D device context reference.
58
);
59
60
return SUCCEEDED(hr);
61
}
62
#endif
63
}
64
65