All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
drawContext.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_DRAW_CONTEXT_H
26 #define OSD_DRAW_CONTEXT_H
27 
28 #include "../version.h"
29 
30 #include "../far/patchTables.h"
31 
32 #include <utility>
33 #include <string>
34 
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
37 
38 namespace Osd {
39 
54 class DrawContext {
55 
56 public:
57 
59  public:
74  PatchDescriptor(Far::PatchTables::Descriptor farDesc, unsigned char maxValence,
75  unsigned char subPatch, unsigned char numElements) :
76  _farDesc(farDesc), _maxValence(maxValence), _subPatch(subPatch), _numElements(numElements) { }
77 
78 
81  return _farDesc.GetType();
82  }
83 
86  return _farDesc.GetPattern();
87  }
88 
90  unsigned char GetRotation() const {
91  return _farDesc.GetRotation();
92  }
93 
96  int GetNumControlVertices() const {
97  return _farDesc.GetNumControlVertices();
98  }
99 
101  int GetMaxValence() const {
102  return _maxValence;
103  }
104 
106  int GetSubPatch() const {
107  return _subPatch;
108  }
109 
111  int GetNumElements() const {
112  return _numElements;
113  }
114 
116  void SetNumElements(int numElements) {
117  _numElements = (unsigned char)numElements;
118  }
119 
121  bool operator < ( PatchDescriptor const other ) const;
122 
124  bool operator == ( PatchDescriptor const other ) const;
125 
126  private:
128  unsigned char _maxValence;
129  unsigned char _subPatch;
130  unsigned char _numElements;
131  };
132 
133  class PatchArray {
134  public:
143  _desc(desc), _range(range) { }
144 
147  return _desc;
148  }
149 
152  _desc = desc;
153  }
154 
157  return _range;
158  }
159 
162  unsigned int GetVertIndex() const {
163  return _range.vertIndex;
164  }
165 
168  unsigned int GetPatchIndex() const {
169  return _range.patchIndex;
170  }
171 
173  unsigned int GetNumPatches() const {
174  return _range.npatches;
175  }
176 
178  unsigned int GetNumIndices() const {
179  return _range.npatches * _desc.GetNumControlVertices();
180  }
181 
183  unsigned int GetQuadOffsetIndex() const {
184  return _range.quadOffsetIndex;
185  }
186 
188  void SetNumPatches(int npatches) {
189  _range.npatches = npatches;
190  }
191 
192  private:
193  PatchDescriptor _desc;
195  };
196 
198  DrawContext() : _isAdaptive(false) {}
199 
201  virtual ~DrawContext();
202 
205  bool IsAdaptive() const {
206  return _isAdaptive;
207  }
208 
209  typedef std::vector<PatchArray> PatchArrayVector;
210 
212  return _patchArrays;
213  }
214 
215  // processes FarPatchArrays and inserts requisite sub-patches for the arrays
216  // containing transition patches
217  static void ConvertPatchArrays(Far::PatchTables::PatchArrayVector const &farPatchArrays,
218  DrawContext::PatchArrayVector &osdPatchArrays,
219  int maxValence, int numElements);
220 
221 
222  typedef std::vector<float> FVarData;
223 
224 protected:
225 
226  static void packFVarData(Far::PatchTables const & patchTables,
227  int fvarWidth, FVarData const & src, FVarData & dst);
228 
229  // XXXX: move to private member
231 
233 };
234 
235 // Allows ordering of patches by type
236 inline bool
238 {
239  return _farDesc < other._farDesc or (_farDesc == other._farDesc and
240  (_subPatch < other._subPatch or ((_subPatch == other._subPatch) and
241  (_maxValence < other._maxValence or ((_maxValence == other._maxValence) and
242  (_numElements < other._numElements))))));
243 }
244 
245 // True if the descriptors are identical
246 inline bool
248 {
249  return _farDesc == other._farDesc and
250  _subPatch == other._subPatch and
251  _maxValence == other._maxValence and
252  _numElements == other._numElements;
253 }
254 
255 
256 
257 } // end namespace Osd
258 
259 } // end namespace OPENSUBDIV_VERSION
260 using namespace OPENSUBDIV_VERSION;
261 
262 } // end namespace OpenSubdiv
263 
264 #endif /* OSD_DRAW_CONTEXT_H */
265 
bool operator<(PatchDescriptor const other) const
Allows ordering of patches by type.
Definition: drawContext.h:237
unsigned char GetRotation() const
Returns the rotation of the patch (4 rotations)
Definition: patchTables.h:128
TransitionPattern GetPattern() const
Returns the transition pattern of the patch if any (5 types)
Definition: patchTables.h:123
Container for patch vertex indices tables.
Definition: patchTables.h:49
Describes the range of patches in a PatchArray.
Definition: patchTables.h:245
int GetNumElements() const
Returns the number of vertex elements.
Definition: drawContext.h:111
PatchArrayVector const & GetPatchArrays() const
Definition: drawContext.h:211
static void ConvertPatchArrays(Far::PatchTables::PatchArrayVector const &farPatchArrays, DrawContext::PatchArrayVector &osdPatchArrays, int maxValence, int numElements)
Far::PatchTables::Type GetType() const
Returns the type of the patch.
Definition: drawContext.h:80
void SetDescriptor(PatchDescriptor desc)
Update a patch descriptor.
Definition: drawContext.h:151
Far::PatchTables::TransitionPattern GetPattern() const
Returns the transition pattern of the patch if any (5 types)
Definition: drawContext.h:85
static short GetNumControlVertices(Type t)
Returns the number of control vertices expected for a patch of the type described.
Definition: patchTables.h:676
unsigned int GetQuadOffsetIndex() const
Returns the offset of quad offset table.
Definition: drawContext.h:183
PatchDescriptor(Far::PatchTables::Descriptor farDesc, unsigned char maxValence, unsigned char subPatch, unsigned char numElements)
Definition: drawContext.h:74
void SetNumPatches(int npatches)
Set num patches (used at batch glomming)
Definition: drawContext.h:188
PatchArray(PatchDescriptor desc, Far::PatchTables::PatchArray::ArrayRange const &range)
Definition: drawContext.h:142
Far::PatchTables::PatchArray::ArrayRange const & GetArrayRange() const
Returns a array range struct.
Definition: drawContext.h:156
void SetNumElements(int numElements)
Set the number of vertex elements.
Definition: drawContext.h:116
unsigned char GetRotation() const
Returns the rotation of the patch (4 rotations)
Definition: drawContext.h:90
unsigned int GetNumPatches() const
Returns the number of patches in the array.
Definition: drawContext.h:173
static void packFVarData(Far::PatchTables const &patchTables, int fvarWidth, FVarData const &src, FVarData &dst)
bool operator==(PatchDescriptor const other) const
True if the descriptors are identical.
Definition: drawContext.h:247
PatchDescriptor GetDescriptor() const
Returns a patch descriptor defining the type of patches in the array.
Definition: drawContext.h:146
Type GetType() const
Returns the type of the patch.
Definition: patchTables.h:118
unsigned int GetNumIndices() const
Returns the number of patch indices in the array.
Definition: drawContext.h:178