All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
d3d11DrawRegistry.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef OSD_D3D11_DRAW_REGISTRY_H
26 #define OSD_D3D11_DRAW_REGISTRY_H
27 
28 #include "../version.h"
29 
30 #include "../far/patchTables.h"
31 #include "../osd/drawRegistry.h"
32 #include "../osd/vertex.h"
33 
34 #include <map>
35 
36 struct ID3D11VertexShader;
37 struct ID3D11HullShader;
38 struct ID3D11DomainShader;
39 struct ID3D11GeometryShader;
40 struct ID3D11PixelShader;
41 
42 struct ID3D11Buffer;
43 struct ID3D11ShaderResourceView;
44 struct ID3D11Device;
45 
46 struct ID3D11InputLayout;
47 struct D3D11_INPUT_ELEMENT_DESC;
48 
49 namespace OpenSubdiv {
50 namespace OPENSUBDIV_VERSION {
51 
52 namespace Osd {
53 
54 struct D3D11DrawConfig : public DrawConfig {
57  geometryShader(0), pixelShader(0) {}
58  virtual ~D3D11DrawConfig();
59 
60  ID3D11VertexShader *vertexShader;
61  ID3D11HullShader *hullShader;
62  ID3D11DomainShader *domainShader;
63  ID3D11GeometryShader *geometryShader;
64  ID3D11PixelShader *pixelShader;
65 };
66 
67 //------------------------------------------------------------------------------
68 
76 };
77 
78 
79 //------------------------------------------------------------------------------
80 
82 
83 public:
87 
88  D3D11DrawRegistryBase(bool enablePtex=false) : _enablePtex(enablePtex) { }
89 
90  virtual ~D3D11DrawRegistryBase();
91 
92  bool IsPtexEnabled() const {
93  return _enablePtex;
94  }
95 
96  void SetPtexEnabled(bool b) {
97  _enablePtex=b;
98  }
99 
100 protected:
101  virtual ConfigType * _NewDrawConfig() { return new ConfigType(); }
102  virtual ConfigType *
103  _CreateDrawConfig(DescType const & desc,
104  SourceConfigType const * sconfig,
105  ID3D11Device * pd3dDevice,
106  ID3D11InputLayout ** ppInputLayout,
107  D3D11_INPUT_ELEMENT_DESC const * pInputElementDescs,
108  int numInputElements);
109 
111  virtual SourceConfigType *
112  _CreateDrawSourceConfig(DescType const & desc, ID3D11Device * pd3dDevice);
113 
114 private:
115  bool _enablePtex;
116 };
117 
118 //------------------------------------------------------------------------------
119 
120 template <class DESC_TYPE = DrawContext::PatchDescriptor,
121  class CONFIG_TYPE = D3D11DrawConfig,
122  class SOURCE_CONFIG_TYPE = D3D11DrawSourceConfig>
124 
125 public:
127 
128  typedef DESC_TYPE DescType;
129  typedef CONFIG_TYPE ConfigType;
130  typedef SOURCE_CONFIG_TYPE SourceConfigType;
131 
132  typedef std::map<DescType, ConfigType *> ConfigMap;
133 
134 public:
135  virtual ~D3D11DrawRegistry() {
136  Reset();
137  }
138 
139  void Reset() {
140  for (typename ConfigMap::iterator
141  i = _configMap.begin(); i != _configMap.end(); ++i) {
142  delete i->second;
143  }
144  _configMap.clear();
145  }
146 
147  // fetch shader config
148  ConfigType *
149  GetDrawConfig(DescType const & desc,
150  ID3D11Device * pd3dDevice,
151  ID3D11InputLayout ** ppInputLayout = NULL,
152  D3D11_INPUT_ELEMENT_DESC const * pInputElementDescs = NULL,
153  int numInputElements = 0) {
154  typename ConfigMap::iterator it = _configMap.find(desc);
155  if (it != _configMap.end()) {
156  return it->second;
157  } else {
158  ConfigType * config =
159  _CreateDrawConfig(desc,
160  _CreateDrawSourceConfig(desc, pd3dDevice),
161  pd3dDevice,
162  ppInputLayout,
163  pInputElementDescs, numInputElements);
164  _configMap[desc] = config;
165  return config;
166  }
167  }
168 
169 protected:
171  return new ConfigType();
172  }
173 
174  virtual ConfigType * _CreateDrawConfig(DescType const & desc,
175  SourceConfigType const * sconfig,
176  ID3D11Device * pd3dDevice,
177  ID3D11InputLayout ** ppInputLayout,
178  D3D11_INPUT_ELEMENT_DESC const * pInputElementDescs,
179  int numInputElements) {
180  return NULL;
181  }
182 
184  return new SourceConfigType();
185  }
186 
188  ID3D11Device * pd3dDevice) {
189  return NULL;
190  }
191 
192 private:
193  ConfigMap _configMap;
194 };
195 
196 } // end namespace Osd
197 
198 } // end namespace OPENSUBDIV_VERSION
199 using namespace OPENSUBDIV_VERSION;
200 
201 } // end namespace OpenSubdiv
202 
203 #endif /* OSD_D3D11_DRAW_REGISTRY_H */
204 
virtual ConfigType * _CreateDrawConfig(DescType const &desc, SourceConfigType const *sconfig, ID3D11Device *pd3dDevice, ID3D11InputLayout **ppInputLayout, D3D11_INPUT_ELEMENT_DESC const *pInputElementDescs, int numInputElements)
virtual ConfigType * _CreateDrawConfig(DescType const &desc, SourceConfigType const *sconfig, ID3D11Device *pd3dDevice, ID3D11InputLayout **ppInputLayout, D3D11_INPUT_ELEMENT_DESC const *pInputElementDescs, int numInputElements)
ConfigType * GetDrawConfig(DescType const &desc, ID3D11Device *pd3dDevice, ID3D11InputLayout **ppInputLayout=NULL, D3D11_INPUT_ELEMENT_DESC const *pInputElementDescs=NULL, int numInputElements=0)
virtual SourceConfigType * _CreateDrawSourceConfig(DescType const &desc, ID3D11Device *pd3dDevice)
virtual SourceConfigType * _CreateDrawSourceConfig(DescType const &desc, ID3D11Device *pd3dDevice)