GteGraphicsObject.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 #include <GTEngineDEF.h>
11 #include <memory>
12 #include <mutex>
13 #include <set>
14 #include <string>
15 
16 namespace gte
17 {
18 
19 // The current hierarchy of GTEngine 6 graphics objects is
20 // GraphicsObject
21 // Resource
22 // Buffer
23 // ConstantBuffer
24 // TextureBuffer
25 // VertexBuffer
26 // IndexBuffer
27 // StructuredBuffer
28 // TypedBuffer
29 // RawBuffer
30 // IndirectArgumentsBuffer
31 // Texture
32 // TextureSingle
33 // Texture1
34 // Texture2
35 // TextureRT
36 // TextureDS
37 // Texture3
38 // TextureArray
39 // Texture1Array
40 // Texture2Array
41 // TextureCube
42 // TextureCubeArray
43 // Shader
44 // VertexShader
45 // GeometryShader
46 // PixelShader
47 // ComputeShader
48 // DrawingState
49 // SamplerState
50 // BlendState
51 // DepthStencilState
52 // RasterizerState
53 //
54 // The corresponding hierarchy of GTEngine DX11* bridge objects is the same
55 // but with class names prepended by DX11 (e.g. DX11GraphicsObject).
56 //
57 // The hierarchy of DX11 interfaces is the following
58 // ID3D11DeviceChild
59 // ID3D11Resource
60 // ID3D11Buffer
61 // ID3D11Texture1D
62 // ID3D11Texture2D
63 // ID3D11Texture3D
64 // ID3D11VertexShader
65 // ID3D11GeometryShader
66 // ID3D11PixelShader
67 // ID3D11ComputeShader
68 // ID3D11SamplerState
69 // ID3D11BlendState
70 // ID3D11DepthStencilState
71 // ID3D11RasterizerState
72 //
73 // The GraphicsObjectType enumeration is for run-time type information.
74 // The typeid() mechanism does not work in DX11Engine::Unbind(...), because
75 // the listeners receive 'this' from a base class during a destructor call.
76 
77 enum GTE_IMPEXP GraphicsObjectType
78 {
79  GT_GRAPHICS_OBJECT, // abstract
80  GT_RESOURCE, // abstract
81  GT_BUFFER, // abstract
90  GT_TEXTURE, // abstract
91  GT_TEXTURE_SINGLE, // abstract
97  GT_TEXTURE_ARRAY, // abstract
102  GT_SHADER, // abstract
107  GT_DRAWING_STATE, // abstract
112  GT_NUM_TYPES
113 };
114 
116 {
117 public:
118  // This is an abstract base class that is used for bridging GTEngine
119  // graphics objects with DX11 graphics objects. The latter are
120  // represented by the ID3D11DeviceChild interface.
121  virtual ~GraphicsObject();
122 
123  // Run-time type information.
124  inline GraphicsObjectType GetType() const;
125  inline bool IsBuffer() const;
126  inline bool IsTexture() const;
127  inline bool IsTextureArray() const;
128  inline bool IsShader() const;
129  inline bool IsDrawingState() const;
130 
131  // Naming support, used in the DX11 debug layer. The default name is "".
132  // If you want the name to show up in the DX11 destruction messages when
133  // the associated DX11GraphicsObject is destroyed, set the name to
134  // something other than "".
135  inline void SetName(std::string const& name);
136  inline std::string const& GetName() const;
137 
138  // Listeners subscribe to receive notification when a GraphicsObject is
139  // about to be destroyed. The intended use is for the DX11Engine objects
140  // to destroy corresponding ID3D11DeviceChild objects.
142  {
143  public:
146  virtual void OnDestroy(GraphicsObject const*) { }
147  };
148 
149  static void SubscribeForDestruction(std::shared_ptr<ListenerForDestruction> const& listener);
150  static void UnsubscribeForDestruction(std::shared_ptr<ListenerForDestruction> const& listener);
151 
152 protected:
153  // This is an abstract base class.
154  GraphicsObject();
155 
156  GraphicsObjectType mType;
158 
159 private:
160  // Support for listeners for destruction (LFD).
161  static std::mutex msLFDMutex;
162  static std::set<std::shared_ptr<ListenerForDestruction>> msLFDSet;
163 };
164 
165 inline GraphicsObjectType GraphicsObject::GetType() const
166 {
167  return mType;
168 }
169 
170 inline bool GraphicsObject::IsBuffer() const
171 {
172  return GT_BUFFER <= mType && mType <= GT_INDIRECT_ARGUMENTS_BUFFER;
173 }
174 
175 inline bool GraphicsObject::IsTexture() const
176 {
177  return GT_TEXTURE_SINGLE <= mType && mType <= GT_TEXTURE3;
178 }
179 
181 {
182  return GT_TEXTURE_ARRAY <= mType && mType <= GT_TEXTURE_CUBE_ARRAY;
183 }
184 
185 inline bool GraphicsObject::IsShader() const
186 {
187  return GT_SHADER <= mType && mType <= GT_COMPUTE_SHADER;
188 }
189 
191 {
192  return GT_DRAWING_STATE <= mType && mType <= GT_RASTERIZER_STATE;
193 }
194 
196 {
197  mName = name;
198 }
199 
201 {
202  return mName;
203 }
204 
205 }
GT_TYPED_BUFFER
GT_SHADER
bool IsDrawingState() const
GT_VERTEX_BUFFER
GT_TEXTURE2
GT_COMPUTE_SHADER
GT_TEXTURE_SINGLE
GT_VERTEX_SHADER
GraphicsObjectType mType
GT_TEXTURE_RT
GT_RESOURCE
GT_SAMPLER_STATE
GraphicsObjectType GetType() const
GT_RASTERIZER_STATE
GLuint const GLchar * name
Definition: glcorearb.h:781
static std::mutex msLFDMutex
GT_TEXTURE
GT_TEXTURE_ARRAY
GT_INDIRECT_ARGUMENTS_BUFFER
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GT_TEXTURE2_ARRAY
void SetName(std::string const &name)
GT_TEXTURE_CUBE_ARRAY
GT_TEXTURE_CUBE
GT_TEXTURE_DS
GT_PIXEL_SHADER
GT_STRUCTURED_BUFFER
GT_TEXTURE1_ARRAY
static std::set< std::shared_ptr< ListenerForDestruction > > msLFDSet
GT_DRAWING_STATE
GT_CONSTANT_BUFFER
GT_BLEND_STATE
GT_BUFFER
GT_GRAPHICS_OBJECT
GT_TEXTURE_BUFFER
std::string const & GetName() const
GT_INDEX_BUFFER
virtual void OnDestroy(GraphicsObject const *)
GT_TEXTURE3
GT_TEXTURE1
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
GT_DEPTH_STENCIL_STATE
GT_GEOMETRY_SHADER
bool IsTextureArray() const
GT_RAW_BUFFER


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00