25#ifndef OPENSUBDIV3_OSD_MESH_H
26#define OPENSUBDIV3_OSD_MESH_H
28#include "../version.h"
35#include "../far/topologyRefiner.h"
36#include "../far/patchTableFactory.h"
37#include "../far/stencilTable.h"
38#include "../far/stencilTableFactory.h"
40#include "../osd/bufferDescriptor.h"
42struct ID3D11DeviceContext;
45namespace OPENSUBDIV_VERSION {
67template <
class PATCH_TABLE>
83 int startVertex,
int numVerts) = 0;
86 int startVertex,
int numVerts) = 0;
102 int level,
bool adaptive,
103 bool singleCreasePatch) {
138template <
typename STENCIL_TABLE,
typename SRC_STENCIL_TABLE,
139 typename DEVICE_CONTEXT>
142 SRC_STENCIL_TABLE
const *table, DEVICE_CONTEXT *context) {
143 if (! table)
return NULL;
144 return STENCIL_TABLE::Create(table, context);
153 if (! table)
return NULL;
163 if (! table)
return NULL;
173 if (! table)
return NULL;
185template <
typename EVALUATOR>
189 for(
typename Evaluators::iterator it = _evaluators.begin();
190 it != _evaluators.end(); ++it) {
191 delete it->evaluator;
227 template <
typename DEVICE_CONTEXT>
230 DEVICE_CONTEXT *deviceContext) {
240 template <
typename DEVICE_CONTEXT>
245 DEVICE_CONTEXT *deviceContext) {
254 template <
typename DEVICE_CONTEXT>
262 DEVICE_CONTEXT *deviceContext) {
264 for(
typename Evaluators::iterator it = _evaluators.begin();
265 it != _evaluators.end(); ++it) {
266 if (isEqual(srcDesc, it->srcDesc) &&
267 isEqual(dstDesc, it->dstDesc) &&
268 isEqual(duDesc, it->duDesc) &&
269 isEqual(dvDesc, it->dvDesc) &&
270 isEqual(duuDesc, it->duuDesc) &&
271 isEqual(duvDesc, it->duvDesc) &&
272 isEqual(dvvDesc, it->dvvDesc)) {
273 return it->evaluator;
276 EVALUATOR *e = EVALUATOR::Create(srcDesc, dstDesc,
278 duuDesc, duvDesc, dvvDesc,
280 _evaluators.push_back(
Entry(srcDesc, dstDesc,
282 duuDesc, duvDesc, dvvDesc, e));
294 return (offsetA == offsetB &&
305template <
typename EVALUATOR>
310 template <
typename C>
static yes &chk(
typename C::Instantiatable *t=0);
311 template <
typename C>
static no &chk(...);
312 static bool const value =
sizeof(chk<EVALUATOR>(0)) ==
sizeof(yes);
314template <
bool C,
typename T=
void>
315struct enable_if {
typedef T type; };
317struct enable_if<false, T> { };
322template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
323static EVALUATOR *GetEvaluator(
324 EvaluatorCacheT<EVALUATOR> *cache,
325 BufferDescriptor
const &srcDesc,
326 BufferDescriptor
const &dstDesc,
327 BufferDescriptor
const &duDesc,
328 BufferDescriptor
const &dvDesc,
329 BufferDescriptor
const &duuDesc,
330 BufferDescriptor
const &duvDesc,
331 BufferDescriptor
const &dvvDesc,
332 DEVICE_CONTEXT deviceContext,
333 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
335 if (cache == NULL)
return NULL;
336 return cache->GetEvaluator(srcDesc, dstDesc,
337 duDesc, dvDesc, duuDesc, duvDesc, dvvDesc,
341template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
342static EVALUATOR *GetEvaluator(
343 EvaluatorCacheT<EVALUATOR> *cache,
344 BufferDescriptor
const &srcDesc,
345 BufferDescriptor
const &dstDesc,
346 BufferDescriptor
const &duDesc,
347 BufferDescriptor
const &dvDesc,
348 DEVICE_CONTEXT deviceContext,
349 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
351 if (cache == NULL)
return NULL;
352 return cache->GetEvaluator(srcDesc, dstDesc, duDesc, dvDesc, deviceContext);
355template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
356static EVALUATOR *GetEvaluator(
357 EvaluatorCacheT<EVALUATOR> *cache,
358 BufferDescriptor
const &srcDesc,
359 BufferDescriptor
const &dstDesc,
360 DEVICE_CONTEXT deviceContext,
361 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
363 if (cache == NULL)
return NULL;
364 return cache->GetEvaluator(srcDesc, dstDesc,
371template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
372static EVALUATOR *GetEvaluator(
373 EvaluatorCacheT<EVALUATOR> *,
374 BufferDescriptor
const &,
375 BufferDescriptor
const &,
376 BufferDescriptor
const &,
377 BufferDescriptor
const &,
378 BufferDescriptor
const &,
379 BufferDescriptor
const &,
380 BufferDescriptor
const &,
382 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
387template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
388static EVALUATOR *GetEvaluator(
389 EvaluatorCacheT<EVALUATOR> *,
390 BufferDescriptor
const &,
391 BufferDescriptor
const &,
392 BufferDescriptor
const &,
393 BufferDescriptor
const &,
395 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
400template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
401static EVALUATOR *GetEvaluator(
402 EvaluatorCacheT<EVALUATOR> *,
403 BufferDescriptor
const &,
404 BufferDescriptor
const &,
406 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
413template <
typename VERTEX_BUFFER,
414 typename STENCIL_TABLE,
416 typename PATCH_TABLE,
417 typename DEVICE_CONTEXT =
void>
429 int numVertexElements,
430 int numVaryingElements,
437 _farPatchTable(NULL),
441 _varyingBuffer(NULL),
442 _vertexStencilTable(NULL),
443 _varyingStencilTable(NULL),
444 _evaluatorCache(evaluatorCache),
446 _deviceContext(deviceContext) {
451 *_refiner, level, bits);
453 int vertexBufferStride = numVertexElements +
455 int varyingBufferStride =
458 initializeContext(numVertexElements,
462 initializeVertexBuffers(_numVertices,
464 varyingBufferStride);
471 numVertexElements, numVaryingElements, vertexBufferStride);
474 0, numVaryingElements, varyingBufferStride);
480 delete _farPatchTable;
481 delete _vertexBuffer;
482 delete _varyingBuffer;
483 delete _vertexStencilTable;
484 delete _varyingStencilTable;
490 int startVertex,
int numVerts) {
491 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts,
496 int startVertex,
int numVerts) {
497 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts,
512 Evaluator const *instance = GetEvaluator<Evaluator>(
513 _evaluatorCache, srcDesc, dstDesc,
516 Evaluator::EvalStencils(_vertexBuffer, srcDesc,
517 _vertexBuffer, dstDesc,
519 instance, _deviceContext);
521 if (_varyingDesc.
length > 0) {
524 vDstDesc.
offset += numControlVertices * vDstDesc.
stride;
526 instance = GetEvaluator<Evaluator>(
527 _evaluatorCache, vSrcDesc, vDstDesc,
530 if (_varyingBuffer) {
532 Evaluator::EvalStencils(_varyingBuffer, vSrcDesc,
533 _varyingBuffer, vDstDesc,
534 _varyingStencilTable,
535 instance, _deviceContext);
538 Evaluator::EvalStencils(_vertexBuffer, vSrcDesc,
539 _vertexBuffer, vDstDesc,
540 _varyingStencilTable,
541 instance, _deviceContext);
547 Evaluator::Synchronize(_deviceContext);
555 return _farPatchTable;
563 return _vertexBuffer->BindVBO(_deviceContext);
567 return _varyingBuffer->BindVBO(_deviceContext);
571 return _vertexBuffer;
575 return _varyingBuffer;
583 void initializeContext(
int numVertexElements,
584 int numVaryingElements,
588 Far::StencilTableFactory::Options options;
589 options.generateOffsets =
true;
590 options.generateIntermediateLevels =
596 if (numVertexElements>0) {
602 if (numVaryingElements>0) {
604 options.interpolationMode =
621 poptions.SetEndCapType(
623 poptions.shareEndCapPatchPoints =
true;
625 poptions.SetEndCapType(
628 poptions.SetEndCapType(
630 poptions.shareEndCapPatchPoints =
true;
632 poptions.SetEndCapType(
641 if (Far::StencilTable
const *vertexStencilsWithLocalPoints =
646 delete vertexStencils;
647 vertexStencils = vertexStencilsWithLocalPoints;
649 if (varyingStencils) {
650 if (Far::StencilTable
const *varyingStencilsWithLocalPoints =
655 delete varyingStencils;
656 varyingStencils = varyingStencilsWithLocalPoints;
662 _patchTable = PatchTable::Create(_farPatchTable, _deviceContext);
669 _vertexStencilTable =
670 convertToCompatibleStencilTable<StencilTable>(
671 vertexStencils, _deviceContext);
672 _varyingStencilTable =
673 convertToCompatibleStencilTable<StencilTable>(
674 varyingStencils, _deviceContext);
677 delete vertexStencils;
678 delete varyingStencils;
681 void initializeVertexBuffers(
int numVertices,
682 int numVertexElements,
683 int numVaryingElements) {
685 if (numVertexElements) {
686 _vertexBuffer = VertexBuffer::Create(numVertexElements,
687 numVertices, _deviceContext);
690 if (numVaryingElements) {
691 _varyingBuffer = VertexBuffer::Create(numVaryingElements,
692 numVertices, _deviceContext);
696 Far::TopologyRefiner * _refiner;
697 Far::PatchTable * _farPatchTable;
705 BufferDescriptor _vertexDesc;
706 BufferDescriptor _varyingDesc;
719using namespace OPENSUBDIV_VERSION;
STENCIL_TABLE const * convertToCompatibleStencilTable(SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context)
@ MeshEndCapBilinearBasis
@ MeshUseSingleCreasePatch
@ MeshEndCapLegacyGregory
@ MeshUseSmoothCornerPatch
Far::StencilTable const * convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, void >(Far::StencilTable const *table, void *)
Far::LimitStencilTable const * convertToCompatibleStencilTable< Far::LimitStencilTable, Far::LimitStencilTable, void >(Far::LimitStencilTable const *table, void *)
std::bitset< NUM_MESH_BITS > MeshBitset
Far::StencilTable const * convertToCompatibleStencilTable< Far::StencilTable, Far::StencilTable, ID3D11DeviceContext >(Far::StencilTable const *table, ID3D11DeviceContext *)
Container for arrays of parametric patches.
int GetMaxValence() const
Returns max vertex valence.
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to compute local point vertex values.
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the stencil table to compute local point varying values.
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options(), ConstIndexArray selectedFaces=ConstIndexArray())
Instantiates a PatchTable from a client-provided TopologyRefiner.
Public options for the PatchTable factory.
@ ENDCAP_LEGACY_GREGORY
legacy option for 2.x style Gregory patches (Catmark only)
@ ENDCAP_GREGORY_BASIS
use Gregory patches (highest quality, recommended default)
@ ENDCAP_BILINEAR_BASIS
use linear patches (simple quads or tris)
@ ENDCAP_BSPLINE_BASIS
use BSpline-like patches (same patch type as regular)
@ INTERPOLATE_VARYING
varying primvar stencils
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
int GetNumStencils() const
Returns the number of stencils in the table.
Stencil table class wrapping the template for compatibility.
Limit stencil table class wrapping the template for compatibility.
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
static StencilTable const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
int GetNumVertices() const
Return the number of vertices in this level.
Stores topology data for a specified set of refinement options.
bool IsUniform() const
Returns true if uniform refinement has been applied.
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
TopologyLevel const & GetLevel(int level) const
Returns a handle to access data specific to a particular level.
void RefineAdaptive(AdaptiveOptions options, ConstIndexArray selectedFaces=ConstIndexArray())
Feature Adaptive topology refinement.
Uniform refinement options.
unsigned int fullTopologyInLastLevel
Adaptive refinement options.
unsigned int useSingleCreasePatch
unsigned int useInfSharpPatch
unsigned int considerFVarChannels
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers....
int stride
stride to the next element
int length
number or length of the data
int offset
offset to desired element data
virtual Far::PatchTable const * GetFarPatchTable() const =0
static void refineMesh(Far::TopologyRefiner &refiner, int level, MeshBitset bits)
virtual int GetMaxValence() const =0
virtual int GetNumVertices() const =0
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive, bool singleCreasePatch)
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
virtual PatchTable * GetPatchTable() const =0
PatchTable::VertexBufferBinding VertexBufferBinding
virtual VertexBufferBinding BindVertexBuffer()=0
virtual VertexBufferBinding BindVaryingBuffer()=0
virtual void Synchronize()=0
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, DEVICE_CONTEXT *deviceContext)
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)
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, DEVICE_CONTEXT *deviceContext)
std::vector< Entry > Evaluators
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, BufferDescriptor const &duuDescArg, BufferDescriptor const &duvDescArg, BufferDescriptor const &dvvDescArg, EVALUATOR *evalArg)
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, EVALUATOR *evalArg)
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
virtual VertexBuffer * GetVertexBuffer()
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
virtual VertexBuffer * GetVaryingBuffer()
DEVICE_CONTEXT DeviceContext
virtual VertexBufferBinding BindVertexBuffer()
virtual int GetNumVertices() const
Mesh(Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset(), EvaluatorCache *evaluatorCache=NULL, DeviceContext *deviceContext=NULL)
STENCIL_TABLE StencilTable
VERTEX_BUFFER VertexBuffer
EvaluatorCacheT< Evaluator > EvaluatorCache
virtual VertexBufferBinding BindVaryingBuffer()
PatchTable::VertexBufferBinding VertexBufferBinding
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
virtual void Synchronize()
virtual PatchTable * GetPatchTable() const
virtual Far::PatchTable const * GetFarPatchTable() const
virtual int GetMaxValence() const