12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #pragma once
- #include <stdio.h>
- #include <tchar.h>
- #include <dxgi1_4.h>
- #include <d3d12.h>
- #include <d3dcompiler.h>
- #include <wrl.h>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- namespace DX
- {
- using namespace Microsoft::WRL;
- inline LPTSTR GetErrorDescription(HRESULT hr, WCHAR* buffer, size_t size)
- {
- if (FACILITY_WINDOWS == HRESULT_FACILITY(hr))
- hr = HRESULT_CODE(hr);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
- nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, DWORD(size), nullptr);
- return buffer;
- }
- inline void ThrowIfFailed(HRESULT hr)
- {
- if (FAILED(hr))
- {
-
- const size_t size = 1024;
- WCHAR buffer[size];
- GetErrorDescription(hr, buffer, size);
- char str[size];
- size_t i = 0;
- wcstombs_s(&i, str, 1024, buffer, 1024);
- throw std::runtime_error(str);
- }
- }
- inline std::vector<uint8_t> ReadBinaryFile(const std::string& filename)
- {
- std::ifstream ifs(filename, std::ios::in | std::ios::binary | std::ios::ate);
- if (!ifs)
- throw std::runtime_error("ReadBinaryFile");
- std::streampos len = ifs.tellg();
- std::vector<uint8_t> data;
- data.resize(size_t(len));
- ifs.seekg(0, std::ios::beg);
- ifs.read(reinterpret_cast<char*>(data.data()), len);
- ifs.close();
- return data;
- }
- }
|