GteDX11Include.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 // <windows.h> is referenced by the DX11 headers. Turn off the min and max
11 // macros to avoid conflicts with std::min and std::max.
12 #define NOMINMAX
13 #include <D3D11.h>
14 #include <D3Dcompiler.h>
15 #include <DXGI.h>
16 #include <LowLevel/GteLogger.h>
17 
18 // Required libraries for linking DX11.0 with GTE:
19 // d3d11.lib (for DX11.0 core)
20 // d3dcompiler.lib (for D3DCompile and D3DReflect)
21 // dxgi.lib (for IDXGIAdapter1 and IDXGIOutput)
22 // dxguid.lib (for IID_ID3D11ShaderReflection)
23 
24 // Convenient for reference counting.
25 namespace gte
26 {
27 
28 
29 template <typename T>
30 inline ULONG SafeRelease(T*& object)
31 {
32  if (object)
33  {
34  ULONG refs = object->Release();
35  object = nullptr;
36  return refs;
37  }
38  return 0;
39 }
40 
41 template <typename T>
42 inline ULONG FinalRelease(T*& object)
43 {
44  if (object)
45  {
46  ULONG refs = object->Release();
47  object = nullptr;
48  if (refs > 0)
49  {
50  LogError("Reference count is not zero after release.");
51  return refs;
52  }
53  }
54  return 0;
55 }
56 
58 {
59 public:
60  InterfaceReleaser(IUnknown* object)
61  :
62  mObject(object)
63  {
64  }
65 
67  {
68  if (mObject)
69  {
70  mObject->Release();
71  }
72  }
73 
74 private:
75  IUnknown* mObject;
76 };
77 
78 inline HRESULT SetPrivateName(ID3D11DeviceChild* object,
79  std::string const& name)
80 {
81  HRESULT hr;
82  if (object && name != "")
83  {
84  hr = object->SetPrivateData(WKPDID_D3DDebugObjectName,
85  static_cast<UINT>(name.length()), name.c_str());
86  }
87  else
88  {
89  // Callers are allowed to call this function with a null input
90  // or with an empty name (for convenience).
91  hr = S_OK;
92  }
93  return hr;
94 }
95 
96 inline HRESULT SetPrivateName(IDXGIObject* object, std::string const& name)
97 {
98  HRESULT hr;
99  if (object && name != "")
100  {
101  hr = object->SetPrivateData(WKPDID_D3DDebugObjectName,
102  static_cast<UINT>(name.length()), name.c_str());
103  }
104  else
105  {
106  // Callers are allowed to call this function with a null input
107  // or with an empty name (for convenience).
108  hr = S_OK;
109  }
110  return hr;
111 }
112 
113 
114 }
115 
116 #define CHECK_HR_RETURN_NONE(msg)\
117 if (FAILED(hr))\
118 { \
119  LogError(std::string(msg) + ", hr = " + std::to_string(hr) + "."); \
120 }
121 
122 #define CHECK_HR_RETURN_VOID(msg)\
123 if (FAILED(hr))\
124 { \
125  LogError(std::string(msg) + ", hr = " + std::to_string(hr) + "."); \
126  return; \
127 }
128 
129 #define CHECK_HR_RETURN(msg, value)\
130 if (FAILED(hr))\
131 { \
132  LogError(std::string(msg) + ", hr = " + std::to_string(hr) + "."); \
133  return value; \
134 }
135 
136 // Fake enumerations to have human-readable names that D3D11 did not provide.
137 
138 // D3D11_BIND_FLAG
139 #define D3D11_BIND_NONE 0
140 
141 // D3D11_RESOURCE_MISC_FLAG
142 #define D3D11_RESOURCE_MISC_NONE 0
143 
144 // D3D11_BUFFER_UAV_FLAG
145 #define D3D11_BUFFER_UAV_FLAG_BASIC 0
146 
147 // D3D11_CPU_ACCESS_FLAG
148 #define D3D11_CPU_ACCESS_NONE 0
149 #define D3D11_CPU_ACCESS_READ_WRITE (D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE)
150 
151 // D3D11_QUERY_MISC_FLAG
152 #define D3D11_QUERY_MISC_NONE 0
HRESULT SetPrivateName(ID3D11DeviceChild *object, std::string const &name)
GLuint const GLchar * name
Definition: glcorearb.h:781
ULONG FinalRelease(T *&object)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
#define LogError(message)
Definition: GteLogger.h:92
InterfaceReleaser(IUnknown *object)
ULONG SafeRelease(T *&object)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59