OpenSubdiv: opensubdiv/osd/mesh.h Source File

| OpenSubdiv

Loading...
Searching...
No Matches
mesh.h
Go to the documentation of this file.
1//
2// Copyright 2013 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7
8#ifndef OPENSUBDIV3_OSD_MESH_H
9#define OPENSUBDIV3_OSD_MESH_H
10
11#include "../version.h"
12
13#include <bitset>
14#include <cassert>
15#include <cstring>
16#include <vector>
17
18#include "../far/topologyRefiner.h"
19#include "../far/patchTableFactory.h"
20#include "../far/stencilTable.h"
21#include "../far/stencilTableFactory.h"
22
23#include "../osd/bufferDescriptor.h"
24
25struct ID3D11DeviceContext;
26
27namespace OpenSubdiv {
28namespace OPENSUBDIV_VERSION {
29
30namespace Osd {
31
32 enum MeshBits {
33 MeshAdaptive = 0,
34 MeshInterleaveVarying = 1,
35 MeshFVarData = 2,
36 MeshFVarAdaptive = 3,
37 MeshUseSmoothCornerPatch = 4,
38 MeshUseSingleCreasePatch = 5,
39 MeshUseInfSharpPatch = 6,
40 MeshEndCapBilinearBasis = 7, // exclusive
41 MeshEndCapBSplineBasis = 8, // exclusive
42 MeshEndCapGregoryBasis = 9, // exclusive
43 MeshEndCapLegacyGregory = 10, // exclusive
44 NUM_MESH_BITS = 11,
45};
46 typedef std::bitset<NUM_MESH_BITS> MeshBitset;
47
48// ---------------------------------------------------------------------------
49
50template <class PATCH_TABLE>
51 class MeshInterface {
52public:
53 typedef PATCH_TABLE PatchTable;
54 typedef typename PatchTable::VertexBufferBinding VertexBufferBinding;
55
56public:
57 MeshInterface() { }
58
59 virtual ~MeshInterface() { }
60
61 virtual int GetNumVertices() const = 0;
62
63 virtual int GetMaxValence() const = 0;
64
65 virtual void UpdateVertexBuffer(float const *vertexData,
66 int startVertex, int numVerts) = 0;
67
68 virtual void UpdateVaryingBuffer(float const *varyingData,
69 int startVertex, int numVerts) = 0;
70
71 virtual void Refine() = 0;
72
73 virtual void Synchronize() = 0;
74
75 virtual PatchTable * GetPatchTable() const = 0;
76
77 virtual Far::PatchTable const *GetFarPatchTable() const = 0;
78
79 virtual VertexBufferBinding BindVertexBuffer() = 0;
80
81 virtual VertexBufferBinding BindVaryingBuffer() = 0;
82
83protected:
84 static inline void refineMesh(Far::TopologyRefiner & refiner,
85 int level, bool adaptive,
86 bool singleCreasePatch) {
87 if (adaptive) {
88 Far::TopologyRefiner::AdaptiveOptions options(level);
89 options.useSingleCreasePatch = singleCreasePatch;
90 refiner.RefineAdaptive(options);
91 } else {
92 // This dependency on FVar channels should not be necessary
93 bool fullTopologyInLastLevel = refiner.GetNumFVarChannels()>0;
94
95 Far::TopologyRefiner::UniformOptions options(level);
96 options.fullTopologyInLastLevel = fullTopologyInLastLevel;
97 refiner.RefineUniform(options);
98 }
99 }
100 static inline void refineMesh(Far::TopologyRefiner & refiner,
101 int level, MeshBitset bits) {
102 if (bits.test(MeshAdaptive)) {
103 Far::TopologyRefiner::AdaptiveOptions options(level);
104 options.useSingleCreasePatch = bits.test(MeshUseSingleCreasePatch);
105 options.useInfSharpPatch = bits.test(MeshUseInfSharpPatch);
106 options.considerFVarChannels = bits.test(MeshFVarAdaptive);
107 refiner.RefineAdaptive(options);
108 } else {
109 // This dependency on FVar channels should not be necessary
110 bool fullTopologyInLastLevel = refiner.GetNumFVarChannels()>0;
111
112 Far::TopologyRefiner::UniformOptions options(level);
113 options.fullTopologyInLastLevel = fullTopologyInLastLevel;
114 refiner.RefineUniform(options);
115 }
116 }
117};
118
119// ---------------------------------------------------------------------------
120
121template <typename STENCIL_TABLE, typename SRC_STENCIL_TABLE,
122 typename DEVICE_CONTEXT>
123STENCIL_TABLE const *
124convertToCompatibleStencilTable(
125 SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context) {
126 if (! table) return NULL;
127 return STENCIL_TABLE::Create(table, context);
128}
129
130template <>
131 inline Far::StencilTable const *
132 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, void>(
133 Far::StencilTable const *table, void * /*context*/) {
134 // no need for conversion
135 // XXX: We don't want to even copy.
136 if (! table) return NULL;
137 return new Far::StencilTable(*table);
138}
139
140template <>
141 inline Far::LimitStencilTable const *
142 convertToCompatibleStencilTable<Far::LimitStencilTable, Far::LimitStencilTable, void>(
143 Far::LimitStencilTable const *table, void * /*context*/) {
144 // no need for conversion
145 // XXX: We don't want to even copy.
146 if (! table) return NULL;
147 return new Far::LimitStencilTable(*table);
148}
149
150template <>
151 inline Far::StencilTable const *
152 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, ID3D11DeviceContext>(
153 Far::StencilTable const *table, ID3D11DeviceContext * /*context*/) {
154 // no need for conversion
155 // XXX: We don't want to even copy.
156 if (! table) return NULL;
157 return new Far::StencilTable(*table);
158}
159
160// ---------------------------------------------------------------------------
161
162// Osd evaluator cache: for the GPU backends require compiled instance
163// (GLXFB, GLCompute, CL)
164//
165// note: this is just an example usage and client applications are supposed
166// to implement their own structure for Evaluator instance.
167//
168template <typename EVALUATOR>
169 class EvaluatorCacheT {
170public:
171 ~EvaluatorCacheT() {
172 for(typename Evaluators::iterator it = _evaluators.begin();
173 it != _evaluators.end(); ++it) {
174 delete it->evaluator;
175 }
176 }
177
178 // XXX: FIXME, linear search
179 struct Entry {
180 Entry(BufferDescriptor const &srcDescArg,
181 BufferDescriptor const &dstDescArg,
182 BufferDescriptor const &duDescArg,
183 BufferDescriptor const &dvDescArg,
184 EVALUATOR *evalArg) : srcDesc(srcDescArg), dstDesc(dstDescArg),
185 duDesc(duDescArg), dvDesc(dvDescArg),
186 duuDesc(BufferDescriptor()),
187 duvDesc(BufferDescriptor()),
188 dvvDesc(BufferDescriptor()),
189 evaluator(evalArg) {}
190 Entry(BufferDescriptor const &srcDescArg,
191 BufferDescriptor const &dstDescArg,
192 BufferDescriptor const &duDescArg,
193 BufferDescriptor const &dvDescArg,
194 BufferDescriptor const &duuDescArg,
195 BufferDescriptor const &duvDescArg,
196 BufferDescriptor const &dvvDescArg,
197 EVALUATOR *evalArg) : srcDesc(srcDescArg), dstDesc(dstDescArg),
198 duDesc(duDescArg), dvDesc(dvDescArg),
199 duuDesc(duuDescArg),
200 duvDesc(duvDescArg),
201 dvvDesc(dvvDescArg),
202 evaluator(evalArg) {}
203 BufferDescriptor srcDesc, dstDesc;
204 BufferDescriptor duDesc, dvDesc;
205 BufferDescriptor duuDesc, duvDesc, dvvDesc;
206 EVALUATOR *evaluator;
207 };
208 typedef std::vector<Entry> Evaluators;
209
210 template <typename DEVICE_CONTEXT>
211 EVALUATOR *GetEvaluator(BufferDescriptor const &srcDesc,
212 BufferDescriptor const &dstDesc,
213 DEVICE_CONTEXT *deviceContext) {
214 return GetEvaluator(srcDesc, dstDesc,
215 BufferDescriptor(),
216 BufferDescriptor(),
217 BufferDescriptor(),
218 BufferDescriptor(),
219 BufferDescriptor(),
220 deviceContext);
221 }
222
223 template <typename DEVICE_CONTEXT>
224 EVALUATOR *GetEvaluator(BufferDescriptor const &srcDesc,
225 BufferDescriptor const &dstDesc,
226 BufferDescriptor const &duDesc,
227 BufferDescriptor const &dvDesc,
228 DEVICE_CONTEXT *deviceContext) {
229 return GetEvaluator(srcDesc, dstDesc,
230 duDesc, dvDesc,
231 BufferDescriptor(),
232 BufferDescriptor(),
233 BufferDescriptor(),
234 deviceContext);
235 }
236
237 template <typename DEVICE_CONTEXT>
238 EVALUATOR *GetEvaluator(BufferDescriptor const &srcDesc,
239 BufferDescriptor const &dstDesc,
240 BufferDescriptor const &duDesc,
241 BufferDescriptor const &dvDesc,
242 BufferDescriptor const &duuDesc,
243 BufferDescriptor const &duvDesc,
244 BufferDescriptor const &dvvDesc,
245 DEVICE_CONTEXT *deviceContext) {
246
247 for(typename Evaluators::iterator it = _evaluators.begin();
248 it != _evaluators.end(); ++it) {
249 if (isEqual(srcDesc, it->srcDesc) &&
250 isEqual(dstDesc, it->dstDesc) &&
251 isEqual(duDesc, it->duDesc) &&
252 isEqual(dvDesc, it->dvDesc) &&
253 isEqual(duuDesc, it->duuDesc) &&
254 isEqual(duvDesc, it->duvDesc) &&
255 isEqual(dvvDesc, it->dvvDesc)) {
256 return it->evaluator;
257 }
258 }
259 EVALUATOR *e = EVALUATOR::Create(srcDesc, dstDesc,
260 duDesc, dvDesc,
261 duuDesc, duvDesc, dvvDesc,
262 deviceContext);
263 _evaluators.push_back(Entry(srcDesc, dstDesc,
264 duDesc, dvDesc,
265 duuDesc, duvDesc, dvvDesc, e));
266 return e;
267 }
268
269private:
270 static bool isEqual(BufferDescriptor const &a,
271 BufferDescriptor const &b) {
272 int offsetA = a.stride ? (a.offset % a.stride) : 0;
273 int offsetB = b.stride ? (b.offset % b.stride) : 0;
274
275 // Note: XFB kernel needs to be configured with the local offset
276 // of the dstDesc to skip preceding primvars.
277 return (offsetA == offsetB &&
278 a.length == b.length &&
279 a.stride == b.stride);
280 }
281
282 Evaluators _evaluators;
283};
284
286
287// template helpers to see if the evaluator is instantiatable or not.
288template <typename EVALUATOR>
289struct instantiatable
290{
291 typedef char yes[1];
292 typedef char no[2];
293 template <typename C> static yes &chk(typename C::Instantiatable *t=0);
294 template <typename C> static no &chk(...);
295 static bool const value = sizeof(chk<EVALUATOR>(0)) == sizeof(yes);
296};
297template <bool C, typename T=void>
298struct enable_if { typedef T type; };
299template <typename T>
300struct enable_if<false, T> { };
301
303
304// extract a kernel from cache if available
305template <typename EVALUATOR, typename DEVICE_CONTEXT>
306static EVALUATOR *GetEvaluator(
307 EvaluatorCacheT<EVALUATOR> *cache,
308 BufferDescriptor const &srcDesc,
309 BufferDescriptor const &dstDesc,
310 BufferDescriptor const &duDesc,
311 BufferDescriptor const &dvDesc,
312 BufferDescriptor const &duuDesc,
313 BufferDescriptor const &duvDesc,
314 BufferDescriptor const &dvvDesc,
315 DEVICE_CONTEXT deviceContext,
316 typename enable_if<instantiatable<EVALUATOR>::value, void>::type*t=0) {
317 (void)t;
318 if (cache == NULL) return NULL;
319 return cache->GetEvaluator(srcDesc, dstDesc,
320 duDesc, dvDesc, duuDesc, duvDesc, dvvDesc,
321 deviceContext);
322}
323
324template <typename EVALUATOR, typename DEVICE_CONTEXT>
325static EVALUATOR *GetEvaluator(
326 EvaluatorCacheT<EVALUATOR> *cache,
327 BufferDescriptor const &srcDesc,
328 BufferDescriptor const &dstDesc,
329 BufferDescriptor const &duDesc,
330 BufferDescriptor const &dvDesc,
331 DEVICE_CONTEXT deviceContext,
332 typename enable_if<instantiatable<EVALUATOR>::value, void>::type*t=0) {
333 (void)t;
334 if (cache == NULL) return NULL;
335 return cache->GetEvaluator(srcDesc, dstDesc, duDesc, dvDesc, deviceContext);
336}
337
338template <typename EVALUATOR, typename DEVICE_CONTEXT>
339static EVALUATOR *GetEvaluator(
340 EvaluatorCacheT<EVALUATOR> *cache,
341 BufferDescriptor const &srcDesc,
342 BufferDescriptor const &dstDesc,
343 DEVICE_CONTEXT deviceContext,
344 typename enable_if<instantiatable<EVALUATOR>::value, void>::type*t=0) {
345 (void)t;
346 if (cache == NULL) return NULL;
347 return cache->GetEvaluator(srcDesc, dstDesc,
348 BufferDescriptor(),
349 BufferDescriptor(),
350 deviceContext);
351}
352
353// fallback
354template <typename EVALUATOR, typename DEVICE_CONTEXT>
355static EVALUATOR *GetEvaluator(
356 EvaluatorCacheT<EVALUATOR> *,
357 BufferDescriptor const &,
358 BufferDescriptor const &,
359 BufferDescriptor const &,
360 BufferDescriptor const &,
361 BufferDescriptor const &,
362 BufferDescriptor const &,
363 BufferDescriptor const &,
364 DEVICE_CONTEXT,
365 typename enable_if<!instantiatable<EVALUATOR>::value, void>::type*t=0) {
366 (void)t;
367 return NULL;
368}
369
370template <typename EVALUATOR, typename DEVICE_CONTEXT>
371static EVALUATOR *GetEvaluator(
372 EvaluatorCacheT<EVALUATOR> *,
373 BufferDescriptor const &,
374 BufferDescriptor const &,
375 BufferDescriptor const &,
376 BufferDescriptor const &,
377 DEVICE_CONTEXT,
378 typename enable_if<!instantiatable<EVALUATOR>::value, void>::type*t=0) {
379 (void)t;
380 return NULL;
381}
382
383template <typename EVALUATOR, typename DEVICE_CONTEXT>
384static EVALUATOR *GetEvaluator(
385 EvaluatorCacheT<EVALUATOR> *,
386 BufferDescriptor const &,
387 BufferDescriptor const &,
388 DEVICE_CONTEXT,
389 typename enable_if<!instantiatable<EVALUATOR>::value, void>::type*t=0) {
390 (void)t;
391 return NULL;
392}
393
394// ---------------------------------------------------------------------------
395
396template <typename VERTEX_BUFFER,
397 typename STENCIL_TABLE,
398 typename EVALUATOR,
399 typename PATCH_TABLE,
400 typename DEVICE_CONTEXT = void>
401 class Mesh : public MeshInterface<PATCH_TABLE> {
402public:
403 typedef VERTEX_BUFFER VertexBuffer;
404 typedef EVALUATOR Evaluator;
405 typedef STENCIL_TABLE StencilTable;
406 typedef PATCH_TABLE PatchTable;
407 typedef DEVICE_CONTEXT DeviceContext;
408 typedef EvaluatorCacheT<Evaluator> EvaluatorCache;
409 typedef typename PatchTable::VertexBufferBinding VertexBufferBinding;
410
411 Mesh(Far::TopologyRefiner * refiner,
412 int numVertexElements,
413 int numVaryingElements,
414 int level,
415 MeshBitset bits = MeshBitset(),
416 EvaluatorCache * evaluatorCache = NULL,
417 DeviceContext * deviceContext = NULL) :
418
419 _refiner(refiner),
420 _farPatchTable(NULL),
421 _numVertices(0),
422 _maxValence(0),
423 _vertexBuffer(NULL),
424 _varyingBuffer(NULL),
425 _vertexStencilTable(NULL),
426 _varyingStencilTable(NULL),
427 _evaluatorCache(evaluatorCache),
428 _patchTable(NULL),
429 _deviceContext(deviceContext) {
430
431 assert(_refiner);
432
433 MeshInterface<PATCH_TABLE>::refineMesh(
434 *_refiner, level, bits);
435
436 int vertexBufferStride = numVertexElements +
437 (bits.test(MeshInterleaveVarying) ? numVaryingElements : 0);
438 int varyingBufferStride =
439 (bits.test(MeshInterleaveVarying) ? 0 : numVaryingElements);
440
441 initializeContext(numVertexElements,
442 numVaryingElements,
443 level, bits);
444
445 initializeVertexBuffers(_numVertices,
446 vertexBufferStride,
447 varyingBufferStride);
448
449 // configure vertex buffer descriptor
450 _vertexDesc =
451 BufferDescriptor(0, numVertexElements, vertexBufferStride);
452 if (bits.test(MeshInterleaveVarying)) {
453 _varyingDesc = BufferDescriptor(
454 numVertexElements, numVaryingElements, vertexBufferStride);
455 } else {
456 _varyingDesc = BufferDescriptor(
457 0, numVaryingElements, varyingBufferStride);
458 }
459 }
460
461 virtual ~Mesh() {
462 delete _refiner;
463 delete _farPatchTable;
464 delete _vertexBuffer;
465 delete _varyingBuffer;
466 delete _vertexStencilTable;
467 delete _varyingStencilTable;
468 delete _patchTable;
469 // deviceContext and evaluatorCache are not owned by this class.
470 }
471
472 virtual void UpdateVertexBuffer(float const *vertexData,
473 int startVertex, int numVerts) {
474 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts,
475 _deviceContext);
476 }
477
478 virtual void UpdateVaryingBuffer(float const *varyingData,
479 int startVertex, int numVerts) {
480 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts,
481 _deviceContext);
482 }
483
484 virtual void Refine() {
485
486 int numControlVertices = _refiner->GetLevel(0).GetNumVertices();
487
488 BufferDescriptor srcDesc = _vertexDesc;
489 BufferDescriptor dstDesc(srcDesc);
490 dstDesc.offset += numControlVertices * dstDesc.stride;
491
492 // note that the _evaluatorCache can be NULL and thus
493 // the evaluatorInstance can be NULL
494 // (for uninstantiatable kernels CPU,TBB etc)
495 Evaluator const *instance = GetEvaluator<Evaluator>(
496 _evaluatorCache, srcDesc, dstDesc,
497 _deviceContext);
498
499 Evaluator::EvalStencils(_vertexBuffer, srcDesc,
500 _vertexBuffer, dstDesc,
501 _vertexStencilTable,
502 instance, _deviceContext);
503
504 if (_varyingDesc.length > 0) {
505 BufferDescriptor vSrcDesc = _varyingDesc;
506 BufferDescriptor vDstDesc(vSrcDesc);
507 vDstDesc.offset += numControlVertices * vDstDesc.stride;
508
509 instance = GetEvaluator<Evaluator>(
510 _evaluatorCache, vSrcDesc, vDstDesc,
511 _deviceContext);
512
513 if (_varyingBuffer) {
514 // non-interleaved
515 Evaluator::EvalStencils(_varyingBuffer, vSrcDesc,
516 _varyingBuffer, vDstDesc,
517 _varyingStencilTable,
518 instance, _deviceContext);
519 } else {
520 // interleaved
521 Evaluator::EvalStencils(_vertexBuffer, vSrcDesc,
522 _vertexBuffer, vDstDesc,
523 _varyingStencilTable,
524 instance, _deviceContext);
525 }
526 }
527 }
528
529 virtual void Synchronize() {
530 Evaluator::Synchronize(_deviceContext);
531 }
532
533 virtual PatchTable * GetPatchTable() const {
534 return _patchTable;
535 }
536
537 virtual Far::PatchTable const *GetFarPatchTable() const {
538 return _farPatchTable;
539 }
540
541 virtual int GetNumVertices() const { return _numVertices; }
542
543 virtual int GetMaxValence() const { return _maxValence; }
544
545 virtual VertexBufferBinding BindVertexBuffer() {
546 return _vertexBuffer->BindVBO(_deviceContext);
547 }
548
549 virtual VertexBufferBinding BindVaryingBuffer() {
550 return _varyingBuffer->BindVBO(_deviceContext);
551 }
552
553 virtual VertexBuffer * GetVertexBuffer() {
554 return _vertexBuffer;
555 }
556
557 virtual VertexBuffer * GetVaryingBuffer() {
558 return _varyingBuffer;
559 }
560
561 virtual Far::TopologyRefiner const * GetTopologyRefiner() const {
562 return _refiner;
563 }
564
565private:
566 void initializeContext(int numVertexElements,
567 int numVaryingElements,
568 int level, MeshBitset bits) {
569 assert(_refiner);
570
571 Far::StencilTableFactory::Options options;
572 options.generateOffsets = true;
573 options.generateIntermediateLevels =
574 _refiner->IsUniform() ? false : true;
575
576 Far::StencilTable const * vertexStencils = NULL;
577 Far::StencilTable const * varyingStencils = NULL;
578
579 if (numVertexElements>0) {
580
581 vertexStencils = Far::StencilTableFactory::Create(*_refiner,
582 options);
583 }
584
585 if (numVaryingElements>0) {
586
587 options.interpolationMode =
588 Far::StencilTableFactory::INTERPOLATE_VARYING;
589
590 varyingStencils = Far::StencilTableFactory::Create(*_refiner,
591 options);
592 }
593
594 Far::PatchTableFactory::Options poptions(level);
595 poptions.generateFVarTables = bits.test(MeshFVarData);
596 poptions.generateFVarLegacyLinearPatches = !bits.test(MeshFVarAdaptive);
597 poptions.generateLegacySharpCornerPatches = !bits.test(MeshUseSmoothCornerPatch);
598 poptions.useSingleCreasePatch = bits.test(MeshUseSingleCreasePatch);
599 poptions.useInfSharpPatch = bits.test(MeshUseInfSharpPatch);
600
601 // points on bilinear and gregory basis endcap boundaries can be
602 // shared among adjacent patches to save some stencils.
603 if (bits.test(MeshEndCapBilinearBasis)) {
604 poptions.SetEndCapType(
605 Far::PatchTableFactory::Options::ENDCAP_BILINEAR_BASIS);
606 poptions.shareEndCapPatchPoints = true;
607 } else if (bits.test(MeshEndCapBSplineBasis)) {
608 poptions.SetEndCapType(
609 Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS);
610 } else if (bits.test(MeshEndCapGregoryBasis)) {
611 poptions.SetEndCapType(
612 Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS);
613 poptions.shareEndCapPatchPoints = true;
614 } else if (bits.test(MeshEndCapLegacyGregory)) {
615 poptions.SetEndCapType(
616 Far::PatchTableFactory::Options::ENDCAP_LEGACY_GREGORY);
617 }
618
619 _farPatchTable = Far::PatchTableFactory::Create(*_refiner, poptions);
620
621 // if there's endcap stencils, merge it into regular stencils.
622 if (_farPatchTable->GetLocalPointStencilTable()) {
623 // append stencils
624 if (Far::StencilTable const *vertexStencilsWithLocalPoints =
625 Far::StencilTableFactory::AppendLocalPointStencilTable(
626 *_refiner,
627 vertexStencils,
628 _farPatchTable->GetLocalPointStencilTable())) {
629 delete vertexStencils;
630 vertexStencils = vertexStencilsWithLocalPoints;
631 }
632 if (varyingStencils) {
633 if (Far::StencilTable const *varyingStencilsWithLocalPoints =
634 Far::StencilTableFactory::AppendLocalPointStencilTable(
635 *_refiner,
636 varyingStencils,
637 _farPatchTable->GetLocalPointVaryingStencilTable())) {
638 delete varyingStencils;
639 varyingStencils = varyingStencilsWithLocalPoints;
640 }
641 }
642 }
643
644 _maxValence = _farPatchTable->GetMaxValence();
645 _patchTable = PatchTable::Create(_farPatchTable, _deviceContext);
646
647 // numvertices = coarse verts + refined verts + gregory basis verts
648 _numVertices = vertexStencils->GetNumControlVertices()
649 + vertexStencils->GetNumStencils();
650
651 // convert to device stenciltable if necessary.
652 _vertexStencilTable =
653 convertToCompatibleStencilTable<StencilTable>(
654 vertexStencils, _deviceContext);
655 _varyingStencilTable =
656 convertToCompatibleStencilTable<StencilTable>(
657 varyingStencils, _deviceContext);
658
659 // FIXME: we do extra copyings for Far::Stencils.
660 delete vertexStencils;
661 delete varyingStencils;
662 }
663
664 void initializeVertexBuffers(int numVertices,
665 int numVertexElements,
666 int numVaryingElements) {
667
668 if (numVertexElements) {
669 _vertexBuffer = VertexBuffer::Create(numVertexElements,
670 numVertices, _deviceContext);
671 }
672
673 if (numVaryingElements) {
674 _varyingBuffer = VertexBuffer::Create(numVaryingElements,
675 numVertices, _deviceContext);
676 }
677 }
678
679 Far::TopologyRefiner * _refiner;
680 Far::PatchTable * _farPatchTable;
681
682 int _numVertices;
683 int _maxValence;
684
685 VertexBuffer * _vertexBuffer;
686 VertexBuffer * _varyingBuffer;
687
688 BufferDescriptor _vertexDesc;
689 BufferDescriptor _varyingDesc;
690
691 StencilTable const * _vertexStencilTable;
692 StencilTable const * _varyingStencilTable;
693 EvaluatorCache * _evaluatorCache;
694
695 PatchTable *_patchTable;
696 DeviceContext *_deviceContext;
697};
698
699} // end namespace Osd
700
701} // end namespace OPENSUBDIV_VERSION
702using namespace OPENSUBDIV_VERSION;
703
704} // end namespace OpenSubdiv
705
706#endif // OPENSUBDIV3_OSD_MESH_H
patchTableFactory.h
stencilTable.h
stencilTableFactory.h
topologyRefiner.h
bufferDescriptor.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Osd
Definition bufferDescriptor.h:17
OpenSubdiv::OPENSUBDIV_VERSION::Osd::convertToCompatibleStencilTable
STENCIL_TABLE const * convertToCompatibleStencilTable(SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context)
Definition mesh.h:124
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshBits
MeshBits
Definition mesh.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshEndCapBilinearBasis
@ MeshEndCapBilinearBasis
Definition mesh.h:40
OpenSubdiv::OPENSUBDIV_VERSION::Osd::NUM_MESH_BITS
@ NUM_MESH_BITS
Definition mesh.h:44
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshUseInfSharpPatch
@ MeshUseInfSharpPatch
Definition mesh.h:39
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshUseSingleCreasePatch
@ MeshUseSingleCreasePatch
Definition mesh.h:38
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterleaveVarying
@ MeshInterleaveVarying
Definition mesh.h:34
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshFVarAdaptive
@ MeshFVarAdaptive
Definition mesh.h:36
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshEndCapGregoryBasis
@ MeshEndCapGregoryBasis
Definition mesh.h:42
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshEndCapBSplineBasis
@ MeshEndCapBSplineBasis
Definition mesh.h:41
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshEndCapLegacyGregory
@ MeshEndCapLegacyGregory
Definition mesh.h:43
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshUseSmoothCornerPatch
@ MeshUseSmoothCornerPatch
Definition mesh.h:37
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshFVarData
@ MeshFVarData
Definition mesh.h:35
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshAdaptive
@ MeshAdaptive
Definition mesh.h:33
OpenSubdiv::OPENSUBDIV_VERSION::Osd::convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, void >
Far::StencilTable const * convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, void >(Far::StencilTable const *table, void *)
Definition mesh.h:132
OpenSubdiv::OPENSUBDIV_VERSION::Osd::convertToCompatibleStencilTable< Far::LimitStencilTable, Far::LimitStencilTable, void >
Far::LimitStencilTable const * convertToCompatibleStencilTable< Far::LimitStencilTable, Far::LimitStencilTable, void >(Far::LimitStencilTable const *table, void *)
Definition mesh.h:142
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshBitset
std::bitset< NUM_MESH_BITS > MeshBitset
Definition mesh.h:46
OpenSubdiv::OPENSUBDIV_VERSION::Osd::convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, ID3D11DeviceContext >
Far::StencilTable const * convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, ID3D11DeviceContext >(Far::StencilTable const *table, ID3D11DeviceContext *)
Definition mesh.h:152
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTable
Container for arrays of parametric patches.
Definition patchTable.h:38
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Create
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options(), ConstIndexArray selectedFaces=ConstIndexArray())
Instantiates a PatchTable from a client-provided TopologyRefiner.
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Options
Public options for the PatchTable factory.
Definition patchTableFactory.h:28
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Options::ENDCAP_LEGACY_GREGORY
@ ENDCAP_LEGACY_GREGORY
legacy option for 2.x style Gregory patches (Catmark only)
Definition patchTableFactory.h:43
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS
@ ENDCAP_GREGORY_BASIS
use Gregory patches (highest quality, recommended default)
Definition patchTableFactory.h:42
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Options::ENDCAP_BILINEAR_BASIS
@ ENDCAP_BILINEAR_BASIS
use linear patches (simple quads or tris)
Definition patchTableFactory.h:40
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS
@ ENDCAP_BSPLINE_BASIS
use BSpline-like patches (same patch type as regular)
Definition patchTableFactory.h:41
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal< float >::INTERPOLATE_VARYING
@ INTERPOLATE_VARYING
Definition stencilTableFactory.h:40
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableReal::GetNumControlVertices
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
Definition stencilTable.h:144
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableReal::GetNumStencils
int GetNumStencils() const
Returns the number of stencils in the table.
Definition stencilTable.h:139
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Stencil table class wrapping the template for compatibility.
Definition stencilTable.h:256
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTable
Limit stencil table class wrapping the template for compatibility.
Definition stencilTable.h:566
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::Create
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
Definition stencilTableFactory.h:276
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::AppendLocalPointStencilTable
static StencilTable const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
Definition stencilTableFactory.h:291
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner
Stores topology data for a specified set of refinement options.
Definition topologyRefiner.h:34
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::IsUniform
bool IsUniform() const
Returns true if uniform refinement has been applied.
Definition topologyRefiner.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumFVarChannels
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
Definition topologyRefiner.h:276
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::RefineUniform
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::RefineAdaptive
void RefineAdaptive(AdaptiveOptions options, ConstIndexArray selectedFaces=ConstIndexArray())
Feature Adaptive topology refinement.
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::UniformOptions
Uniform refinement options.
Definition topologyRefiner.h:101
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::UniformOptions::fullTopologyInLastLevel
unsigned int fullTopologyInLastLevel
Definition topologyRefiner.h:114
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions
Adaptive refinement options.
Definition topologyRefiner.h:139
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions::useSingleCreasePatch
unsigned int useSingleCreasePatch
Definition topologyRefiner.h:159
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions::useInfSharpPatch
unsigned int useInfSharpPatch
Definition topologyRefiner.h:161
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions::considerFVarChannels
unsigned int considerFVarChannels
Definition topologyRefiner.h:163
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers....
Definition bufferDescriptor.h:44
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::stride
int stride
stride to the next element
Definition bufferDescriptor.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::length
int length
number or length of the data
Definition bufferDescriptor.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::offset
int offset
offset to desired element data
Definition bufferDescriptor.h:81
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11PatchTable::VertexBufferBinding
ID3D11Buffer * VertexBufferBinding
Definition d3d11PatchTable.h:34
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::GetFarPatchTable
virtual Far::PatchTable const * GetFarPatchTable() const =0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::refineMesh
static void refineMesh(Far::TopologyRefiner &refiner, int level, MeshBitset bits)
Definition mesh.h:100
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::GetMaxValence
virtual int GetMaxValence() const =0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::GetNumVertices
virtual int GetNumVertices() const =0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::UpdateVaryingBuffer
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::refineMesh
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive, bool singleCreasePatch)
Definition mesh.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::UpdateVertexBuffer
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::GetPatchTable
virtual PatchTable * GetPatchTable() const =0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::~MeshInterface
virtual ~MeshInterface()
Definition mesh.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::MeshInterface
MeshInterface()
Definition mesh.h:57
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::Refine
virtual void Refine()=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface< D3D11PatchTable >::VertexBufferBinding
PatchTable::VertexBufferBinding VertexBufferBinding
Definition mesh.h:54
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::BindVertexBuffer
virtual VertexBufferBinding BindVertexBuffer()=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::BindVaryingBuffer
virtual VertexBufferBinding BindVaryingBuffer()=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface< D3D11PatchTable >::PatchTable
D3D11PatchTable PatchTable
Definition mesh.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Osd::MeshInterface::Synchronize
virtual void Synchronize()=0
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT
Definition mesh.h:169
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::GetEvaluator
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, DEVICE_CONTEXT *deviceContext)
Definition mesh.h:224
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::GetEvaluator
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, BufferDescriptor const &duuDesc, BufferDescriptor const &duvDesc, BufferDescriptor const &dvvDesc, DEVICE_CONTEXT *deviceContext)
Definition mesh.h:238
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::GetEvaluator
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, DEVICE_CONTEXT *deviceContext)
Definition mesh.h:211
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::~EvaluatorCacheT
~EvaluatorCacheT()
Definition mesh.h:171
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Evaluators
std::vector< Entry > Evaluators
Definition mesh.h:208
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::Entry
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, BufferDescriptor const &duuDescArg, BufferDescriptor const &duvDescArg, BufferDescriptor const &dvvDescArg, EVALUATOR *evalArg)
Definition mesh.h:190
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::dvvDesc
BufferDescriptor dvvDesc
Definition mesh.h:205
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::duvDesc
BufferDescriptor duvDesc
Definition mesh.h:205
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::dstDesc
BufferDescriptor dstDesc
Definition mesh.h:203
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::duDesc
BufferDescriptor duDesc
Definition mesh.h:204
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::srcDesc
BufferDescriptor srcDesc
Definition mesh.h:203
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::duuDesc
BufferDescriptor duuDesc
Definition mesh.h:205
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::evaluator
EVALUATOR * evaluator
Definition mesh.h:206
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::Entry
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, EVALUATOR *evalArg)
Definition mesh.h:180
OpenSubdiv::OPENSUBDIV_VERSION::Osd::EvaluatorCacheT::Entry::dvDesc
BufferDescriptor dvDesc
Definition mesh.h:204
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetTopologyRefiner
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
Definition mesh.h:561
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetVertexBuffer
virtual VertexBuffer * GetVertexBuffer()
Definition mesh.h:553
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::UpdateVaryingBuffer
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
Definition mesh.h:478
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetVaryingBuffer
virtual VertexBuffer * GetVaryingBuffer()
Definition mesh.h:557
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::Refine
virtual void Refine()
Definition mesh.h:484
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::DeviceContext
DEVICE_CONTEXT DeviceContext
Definition mesh.h:407
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::Evaluator
EVALUATOR Evaluator
Definition mesh.h:404
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::BindVertexBuffer
virtual VertexBufferBinding BindVertexBuffer()
Definition mesh.h:545
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetNumVertices
virtual int GetNumVertices() const
Definition mesh.h:541
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::Mesh
Mesh(Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset(), EvaluatorCache *evaluatorCache=NULL, DeviceContext *deviceContext=NULL)
Definition mesh.h:411
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::StencilTable
STENCIL_TABLE StencilTable
Definition mesh.h:405
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::VertexBuffer
VERTEX_BUFFER VertexBuffer
Definition mesh.h:403
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::EvaluatorCache
EvaluatorCacheT< Evaluator > EvaluatorCache
Definition mesh.h:408
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::BindVaryingBuffer
virtual VertexBufferBinding BindVaryingBuffer()
Definition mesh.h:549
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::~Mesh
virtual ~Mesh()
Definition mesh.h:461
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::VertexBufferBinding
PatchTable::VertexBufferBinding VertexBufferBinding
Definition mesh.h:409
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::UpdateVertexBuffer
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
Definition mesh.h:472
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::Synchronize
virtual void Synchronize()
Definition mesh.h:529
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetPatchTable
virtual PatchTable * GetPatchTable() const
Definition mesh.h:533
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetFarPatchTable
virtual Far::PatchTable const * GetFarPatchTable() const
Definition mesh.h:537
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::PatchTable
PATCH_TABLE PatchTable
Definition mesh.h:406
OpenSubdiv::OPENSUBDIV_VERSION::Osd::Mesh::GetMaxValence
virtual int GetMaxValence() const
Definition mesh.h:543