From fba8184491e0b7ae6fab7ac01b4600d230dc4569 Mon Sep 17 00:00:00 2001 From: marsunet Date: Tue, 21 Dec 2021 17:04:22 -0800 Subject: Initial commit with window demo. --- dxcommon/CMakeLists.txt | 12 ++++++++++ dxcommon/include/dxcommon.h | 55 +++++++++++++++++++++++++++++++++++++++++++++ dxcommon/src/dxcommon.cc | 8 +++++++ 3 files changed, 75 insertions(+) create mode 100644 dxcommon/CMakeLists.txt create mode 100644 dxcommon/include/dxcommon.h create mode 100644 dxcommon/src/dxcommon.cc (limited to 'dxcommon') 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 @@ +cmake_minimum_required(VERSION 3.0) + +add_library(dxcommon + src/dxcommon.cc) + +target_include_directories(dxcommon PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include) + +target_link_libraries(dxcommon PUBLIC + DirectX-Headers + D3D12.lib + 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 @@ +#pragma once + +#include + +#include + +//#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast(ppType) + +namespace dx { + +using Microsoft::WRL::ComPtr; + +class exception : public std::exception { +public: + exception() noexcept {} + + exception(HRESULT result, const char* file, int line) noexcept + { + sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", + file, line, static_cast(result)); + } + + exception(const char* error, const char* file, int line) noexcept + { + sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); + } + + const char* what() const noexcept + { + return m_error; + } + +private: + static char m_error[1024]; +}; + +#define THROW(error) throw exception(error, __FILE__, __LINE__) + +#define ThrowIfFailed(result) {\ + if (result != S_OK) {\ + THROW(result);\ + }\ +} + +template +void SafeRelease(ComPtr& ptr) +{ + if (ptr) + { + ptr->Release(); + ptr = nullptr; + } +} + +} // 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 @@ +#include "dxcommon.h" + +namespace dx +{ + +char exception::m_error[1024]; + +} // namespace dx -- cgit v1.2.3