Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UWP/Common/DirectXHelper.h
5692 views
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
winrt::throw_hresult(hr);
13
}
14
}
15
16
// Function that reads from a binary file asynchronously.
17
inline Concurrency::task<std::vector<uint8_t>> ReadDataAsync(const std::wstring& filename)
18
{
19
using namespace Concurrency;
20
21
auto folder = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation();
22
23
return create_task([folder, filename]() -> std::vector<uint8_t> {
24
auto file = folder.GetFileAsync(winrt::hstring(filename)).get();
25
auto buffer = winrt::Windows::Storage::FileIO::ReadBufferAsync(file).get();
26
27
28
std::vector<uint8_t> returnBuffer(buffer.Length());
29
auto reader = winrt::Windows::Storage::Streams::DataReader::FromBuffer(buffer);
30
reader.ReadBytes(returnBuffer);
31
return returnBuffer;
32
});
33
}
34
35
// Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
36
inline float ConvertDipsToPixels(float dips, float dpi)
37
{
38
static const float dipsPerInch = 96.0f;
39
return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.
40
}
41
42
#if defined(_DEBUG)
43
// Check for SDK Layer support.
44
inline bool SdkLayersAvailable()
45
{
46
HRESULT hr = D3D11CreateDevice(
47
nullptr,
48
D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
49
0,
50
D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers.
51
nullptr, // Any feature level will do.
52
0,
53
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
54
nullptr, // No need to keep the D3D device reference.
55
nullptr, // No need to know the feature level.
56
nullptr // No need to keep the D3D device context reference.
57
);
58
59
return SUCCEEDED(hr);
60
}
61
#endif
62
}
63
64