diff options
Diffstat (limited to 'dxcommon')
-rw-r--r-- | dxcommon/CMakeLists.txt | 12 | ||||
-rw-r--r-- | dxcommon/include/dxcommon.h | 55 | ||||
-rw-r--r-- | dxcommon/src/dxcommon.cc | 8 |
3 files changed, 75 insertions, 0 deletions
diff --git a/dxcommon/CMakeLists.txt b/dxcommon/CMakeLists.txt new file mode 100644 index 0000000..ad8e2b6 --- /dev/null +++ b/dxcommon/CMakeLists.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | ||
2 | |||
3 | add_library(dxcommon | ||
4 | src/dxcommon.cc) | ||
5 | |||
6 | target_include_directories(dxcommon PUBLIC | ||
7 | ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
8 | |||
9 | target_link_libraries(dxcommon PUBLIC | ||
10 | DirectX-Headers | ||
11 | D3D12.lib | ||
12 | DXGI.lib) | ||
diff --git a/dxcommon/include/dxcommon.h b/dxcommon/include/dxcommon.h new file mode 100644 index 0000000..0270629 --- /dev/null +++ b/dxcommon/include/dxcommon.h | |||
@@ -0,0 +1,55 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <wrl.h> | ||
4 | |||
5 | #include <stdexcept> | ||
6 | |||
7 | //#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast<void**>(ppType) | ||
8 | |||
9 | namespace dx { | ||
10 | |||
11 | using Microsoft::WRL::ComPtr; | ||
12 | |||
13 | class exception : public std::exception { | ||
14 | public: | ||
15 | exception() noexcept {} | ||
16 | |||
17 | exception(HRESULT result, const char* file, int line) noexcept | ||
18 | { | ||
19 | sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", | ||
20 | file, line, static_cast<unsigned int>(result)); | ||
21 | } | ||
22 | |||
23 | exception(const char* error, const char* file, int line) noexcept | ||
24 | { | ||
25 | sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); | ||
26 | } | ||
27 | |||
28 | const char* what() const noexcept | ||
29 | { | ||
30 | return m_error; | ||
31 | } | ||
32 | |||
33 | private: | ||
34 | static char m_error[1024]; | ||
35 | }; | ||
36 | |||
37 | #define THROW(error) throw exception(error, __FILE__, __LINE__) | ||
38 | |||
39 | #define ThrowIfFailed(result) {\ | ||
40 | if (result != S_OK) {\ | ||
41 | THROW(result);\ | ||
42 | }\ | ||
43 | } | ||
44 | |||
45 | template <typename T> | ||
46 | void SafeRelease(ComPtr<T>& ptr) | ||
47 | { | ||
48 | if (ptr) | ||
49 | { | ||
50 | ptr->Release(); | ||
51 | ptr = nullptr; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | } // dx | ||
diff --git a/dxcommon/src/dxcommon.cc b/dxcommon/src/dxcommon.cc new file mode 100644 index 0000000..841ebcd --- /dev/null +++ b/dxcommon/src/dxcommon.cc | |||
@@ -0,0 +1,8 @@ | |||
1 | #include "dxcommon.h" | ||
2 | |||
3 | namespace dx | ||
4 | { | ||
5 | |||
6 | char exception::m_error[1024]; | ||
7 | |||
8 | } // namespace dx | ||