HatchitGraphics
ht_directx.h
1 
15 #pragma once
16 
17 #include <ht_platform.h>
18 
19 #ifdef DX11_SUPPORT
20 #include <d3d11.h>
21 #endif
22 
23 #ifdef DX12_SUPPORT
24 #include <d3d12.h>
25 #include <d3d12sdklayers.h>
26 #include <d3dx12.h>
27 #endif
28 
29 #include <dxgi1_4.h>
30 #include <d3dcompiler.h>
31 
32 #include <ht_math.h>
33 
34 #ifndef HT_D3D12_DEBUGNAME
35  #if defined(_DEBUG) || defined(D3D12_ASSIGN_DEBUG_NAMES)
36  #define HT_D3D12_DEBUGNAME(object, name) Hatchit::Graphics::DX::RegisterDebugName(object, name)
37  #else
38  #define HT_D3D12_DEBUGNAME(object, name)
39  #endif
40 #endif
41 
42 namespace Hatchit {
43 
44  namespace Graphics {
45 
46  namespace DX
47  {
48  template <typename T>
49  void ReleaseCOM(T* t)
50  {
51  if (t)
52  {
53  t->Release();
54  t = nullptr;
55  }
56  }
57 
58  inline
59  void RegisterDebugName(ID3D12Object* object, LPCSTR name)
60  {
61  std::wstringstream ss;
62  ss << name;
63  if(object)
64  {
65  object->SetName(ss.str().c_str());
66  }
67  }
68 
69  inline void ThrowIfFailed(HRESULT hr)
70  {
71  if (FAILED(hr))
72  throw;
73  }
74 
75  inline UINT ConstantBufferByteSize(UINT byteSize)
76  {
77  // Constant buffers must be a multiple of the minimum hardware
78  // allocation size (usually 256 bytes). So round up to nearest
79  // multiple of 256. We do this by adding 255 and then masking off
80  // the lower 2 bytes which store all bits < 256.
81  // Example: Suppose byteSize = 300.
82  // (300 + 255) & ~255
83  // 555 & ~255
84  // 0x022B & ~0x00ff
85  // 0x022B & 0xff00
86  // 0x0200
87  // 512
88  return (byteSize + 255) & ~255;
89  }
90 
91  struct Vertex
92  {
93  Math::Float3 position;
94  Math::Float3 normal;
95  Math::Float2 uv;
96  };
97 
98  }
99 
100  }
101 
102 }
Definition: ht_directx.h:91
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_color.h:19