All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glDrawRegistry.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_GL_DRAW_REGISTRY_H
26 #define OSD_GL_DRAW_REGISTRY_H
27 
28 #include "../version.h"
29 
30 #include "../osd/drawRegistry.h"
31 #include "../osd/vertex.h"
32 
33 #include "../osd/opengl.h"
34 
35 #include <map>
36 
37 namespace OpenSubdiv {
38 namespace OPENSUBDIV_VERSION {
39 
40 namespace Osd {
41 
42 struct GLDrawConfig : public DrawConfig {
43 
45  program(0) { }
46 
47  virtual ~GLDrawConfig();
48 
49  GLuint program;
50 };
51 
52 //------------------------------------------------------------------------------
53 
61 };
62 
63 //------------------------------------------------------------------------------
64 
66 
67 public:
71 
72  GLDrawRegistryBase(bool enablePtex=false) : _enablePtex(enablePtex) { }
73 
74  virtual ~GLDrawRegistryBase();
75 
76  bool IsPtexEnabled() const {
77  return _enablePtex;
78  }
79 
80  void SetPtexEnabled(bool b) {
81  _enablePtex=b;
82  }
83 
84 protected:
85  virtual ConfigType * _NewDrawConfig() {
86  return new ConfigType();
87  }
88 
89  virtual ConfigType * _CreateDrawConfig(DescType const & desc,
90  SourceConfigType const * sconfig);
91 
93  return new SourceConfigType();
94  }
95 
96  virtual SourceConfigType * _CreateDrawSourceConfig(DescType const & desc);
97 
98 private:
99  bool _enablePtex;
100 };
101 
102 //------------------------------------------------------------------------------
103 
104 template <class DESC_TYPE = DrawContext::PatchDescriptor,
105  class CONFIG_TYPE = GLDrawConfig,
106  class SOURCE_CONFIG_TYPE = GLDrawSourceConfig >
107 
109 
110 public:
111  typedef DESC_TYPE DescType;
112  typedef CONFIG_TYPE ConfigType;
113  typedef SOURCE_CONFIG_TYPE SourceConfigType;
114 
116 
117  typedef std::map<DescType, ConfigType *> ConfigMap;
118 
119  virtual ~GLDrawRegistry() {
120  Reset();
121  }
122 
123  void Reset() {
124  for (typename ConfigMap::iterator
125  i = _configMap.begin(); i != _configMap.end(); ++i) {
126  delete i->second;
127  }
128  _configMap.clear();
129  }
130 
131  // fetch shader config
133 
134  typename ConfigMap::iterator it = _configMap.find(desc);
135  if (it != _configMap.end()) {
136  return it->second;
137  } else {
138  ConfigType * config =
140  _configMap[desc] = config;
141  return config;
142  }
143  }
144 
145 protected:
146  virtual ConfigType * _NewDrawConfig() {
147  return new ConfigType();
148  }
149 
150  virtual ConfigType * _CreateDrawConfig(DescType const & /* desc */,
151  SourceConfigType const * /* sconfig */) {
152  return NULL;
153  }
154 
156  return new SourceConfigType();
157  }
158 
159  virtual SourceConfigType * _CreateDrawSourceConfig(DescType const & /* desc */) {
160  return NULL;
161  }
162 
163 private:
164  ConfigMap _configMap;
165 };
166 
167 } // end namespace Osd
168 
169 } // end namespace OPENSUBDIV_VERSION
170 using namespace OPENSUBDIV_VERSION;
171 
172 } // end namespace OpenSubdiv
173 
174 #endif /* OSD_GL_DRAW_REGISTRY_H */
175 
ConfigType * GetDrawConfig(DescType const &desc)
virtual ConfigType * _CreateDrawConfig(DescType const &desc, SourceConfigType const *sconfig)
virtual SourceConfigType * _CreateDrawSourceConfig(DescType const &)
virtual ConfigType * _CreateDrawConfig(DescType const &, SourceConfigType const *)
std::map< DescType, ConfigType * > ConfigMap
virtual SourceConfigType * _CreateDrawSourceConfig(DescType const &desc)