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" 42 struct ID3D11DeviceContext;
45 namespace OPENSUBDIV_VERSION {
63 template <
class PATCH_TABLE>
79 int startVertex,
int numVerts) = 0;
82 int startVertex,
int numVerts) = 0;
98 int level,
bool adaptive,
99 bool singleCreasePatch) {
117 template <
typename STENCIL_TABLE,
typename SRC_STENCIL_TABLE,
118 typename DEVICE_CONTEXT>
119 STENCIL_TABLE
const *
121 SRC_STENCIL_TABLE
const *table, DEVICE_CONTEXT *context) {
122 if (not table)
return NULL;
123 return STENCIL_TABLE::Create(table, context);
128 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, void>(
132 if (not table)
return NULL;
138 convertToCompatibleStencilTable<Far::LimitStencilTable, Far::LimitStencilTable, void>(
142 if (not table)
return NULL;
148 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, ID3D11DeviceContext>(
152 if (not table)
return NULL;
164 template <
typename EVALUATOR>
168 for(
typename Evaluators::iterator it = _evaluators.begin();
169 it != _evaluators.end(); ++it) {
170 delete it->evaluator;
180 EVALUATOR *evalArg) : srcDesc(srcDescArg), dstDesc(dstDescArg),
181 duDesc(duDescArg), dvDesc(dvDescArg), evaluator(evalArg) {}
187 template <
typename DEVICE_CONTEXT>
190 DEVICE_CONTEXT *deviceContext) {
191 return GetEvaluator(srcDesc, dstDesc,
197 template <
typename DEVICE_CONTEXT>
202 DEVICE_CONTEXT *deviceContext) {
204 for(
typename Evaluators::iterator it = _evaluators.begin();
205 it != _evaluators.end(); ++it) {
206 if (isEqual(srcDesc, it->srcDesc) &&
207 isEqual(dstDesc, it->dstDesc) &&
208 isEqual(duDesc, it->duDesc) &&
209 isEqual(dvDesc, it->dvDesc)) {
210 return it->evaluator;
213 EVALUATOR *e = EVALUATOR::Create(srcDesc, dstDesc,
216 _evaluators.push_back(
Entry(srcDesc, dstDesc, duDesc, dvDesc, e));
228 return (offsetA == offsetB &&
233 Evaluators _evaluators;
239 template <
typename EVALUATOR>
240 struct instantiatable
244 template <
typename C>
static yes &chk(
typename C::Instantiatable *t=0);
245 template <
typename C>
static no &chk(...);
246 static bool const value =
sizeof(chk<EVALUATOR>(0)) ==
sizeof(yes);
248 template <
bool C,
typename T=
void>
249 struct enable_if {
typedef T type; };
250 template <
typename T>
251 struct enable_if<false, T> { };
256 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
257 static EVALUATOR *GetEvaluator(
263 DEVICE_CONTEXT deviceContext,
264 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
266 if (cache == NULL)
return NULL;
267 return cache->
GetEvaluator(srcDesc, dstDesc, duDesc, dvDesc, deviceContext);
270 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
271 static EVALUATOR *GetEvaluator(
275 DEVICE_CONTEXT deviceContext,
276 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
278 if (cache == NULL)
return NULL;
286 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
287 static EVALUATOR *GetEvaluator(
294 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
299 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
300 static EVALUATOR *GetEvaluator(
305 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
312 template <
typename VERTEX_BUFFER,
313 typename STENCIL_TABLE,
315 typename PATCH_TABLE,
316 typename DEVICE_CONTEXT =
void>
328 int numVertexElements,
329 int numVaryingElements,
332 EvaluatorCache * evaluatorCache = NULL,
333 DeviceContext * deviceContext = NULL) :
336 _farPatchTable(NULL),
340 _varyingBuffer(NULL),
341 _vertexStencilTable(NULL),
342 _varyingStencilTable(NULL),
343 _evaluatorCache(evaluatorCache),
345 _deviceContext(deviceContext) {
354 int vertexBufferStride = numVertexElements +
356 int varyingBufferStride =
359 initializeContext(numVertexElements,
363 initializeVertexBuffers(_numVertices,
365 varyingBufferStride);
372 numVertexElements, numVaryingElements, vertexBufferStride);
375 0, numVaryingElements, varyingBufferStride);
381 delete _farPatchTable;
382 delete _vertexBuffer;
383 delete _varyingBuffer;
384 delete _vertexStencilTable;
385 delete _varyingStencilTable;
391 int startVertex,
int numVerts) {
392 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts,
397 int startVertex,
int numVerts) {
398 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts,
404 int numControlVertices = _refiner->GetLevel(0).GetNumVertices();
413 Evaluator
const *instance = GetEvaluator<Evaluator>(
414 _evaluatorCache, srcDesc, dstDesc,
417 Evaluator::EvalStencils(_vertexBuffer, srcDesc,
418 _vertexBuffer, dstDesc,
420 instance, _deviceContext);
422 if (_varyingDesc.length > 0) {
425 vDstDesc.
offset += numControlVertices * vDstDesc.
stride;
427 instance = GetEvaluator<Evaluator>(
428 _evaluatorCache, vSrcDesc, vDstDesc,
431 if (_varyingBuffer) {
433 Evaluator::EvalStencils(_varyingBuffer, vSrcDesc,
434 _varyingBuffer, vDstDesc,
435 _varyingStencilTable,
436 instance, _deviceContext);
439 Evaluator::EvalStencils(_vertexBuffer, vSrcDesc,
440 _vertexBuffer, vDstDesc,
441 _varyingStencilTable,
442 instance, _deviceContext);
448 Evaluator::Synchronize(_deviceContext);
456 return _farPatchTable;
464 return _vertexBuffer->BindVBO(_deviceContext);
468 return _varyingBuffer->BindVBO(_deviceContext);
472 return _vertexBuffer;
476 return _varyingBuffer;
484 void initializeContext(
int numVertexElements,
485 int numVaryingElements,
486 int level, MeshBitset bits) {
492 _refiner->IsUniform() ? false :
true;
497 if (numVertexElements>0) {
503 if (numVaryingElements>0) {
533 if (_farPatchTable->GetLocalPointStencilTable()) {
539 _farPatchTable->GetLocalPointStencilTable())) {
540 delete vertexStencils;
541 vertexStencils = vertexStencilsWithLocalPoints;
543 if (varyingStencils) {
548 _farPatchTable->GetLocalPointVaryingStencilTable())) {
549 delete varyingStencils;
550 varyingStencils = varyingStencilsWithLocalPoints;
555 _maxValence = _farPatchTable->GetMaxValence();
556 _patchTable = PatchTable::Create(_farPatchTable, _deviceContext);
563 _vertexStencilTable =
564 convertToCompatibleStencilTable<StencilTable>(
565 vertexStencils, _deviceContext);
566 _varyingStencilTable =
567 convertToCompatibleStencilTable<StencilTable>(
568 varyingStencils, _deviceContext);
571 delete vertexStencils;
572 delete varyingStencils;
575 void initializeVertexBuffers(
int numVertices,
576 int numVertexElements,
577 int numVaryingElements) {
579 if (numVertexElements) {
580 _vertexBuffer = VertexBuffer::Create(numVertexElements,
581 numVertices, _deviceContext);
584 if (numVaryingElements) {
585 _varyingBuffer = VertexBuffer::Create(numVaryingElements,
586 numVertices, _deviceContext);
596 VertexBuffer * _vertexBuffer;
597 VertexBuffer * _varyingBuffer;
602 StencilTable
const * _vertexStencilTable;
603 StencilTable
const * _varyingStencilTable;
604 EvaluatorCache * _evaluatorCache;
606 PatchTable *_patchTable;
607 DeviceContext *_deviceContext;
613 using namespace OPENSUBDIV_VERSION;
617 #endif // OPENSUBDIV3_OSD_MESH_H unsigned int useSingleCreasePatch
Use single crease patch.
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
Mesh(Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset(), EvaluatorCache *evaluatorCache=NULL, DeviceContext *deviceContext=NULL)
EvaluatorCacheT< Evaluator > EvaluatorCache
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, EVALUATOR *evalArg)
Uniform refinement options.
unsigned int useSingleCreasePatch
void RefineAdaptive(AdaptiveOptions options)
Feature Adaptive topology refinement (restricted to scheme Catmark)
virtual PatchTable * GetPatchTable() const
virtual int GetNumVertices() const
unsigned int shareEndCapPatchPoints
virtual Far::PatchTable const * GetFarPatchTable() const =0
int GetNumStencils() const
Returns the number of stencils in the table.
Table of subdivision stencils.
VERTEX_BUFFER VertexBuffer
virtual void Synchronize()=0
int offset
offset to desired element data
std::vector< Entry > Evaluators
unsigned int generateIntermediateLevels
vertices at all levels or highest only
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTable.
int length
number or length of the data
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
PatchTable::VertexBufferBinding VertexBufferBinding
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
virtual VertexBufferBinding BindVaryingBuffer()
virtual VertexBufferBinding BindVertexBuffer()
use legacy (2.x) Gregory patches (4 cp + valence table) as end-caps
virtual VertexBuffer * GetVaryingBuffer()
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTable from TopologyRefiner that have been refined uniformly or adaptively...
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
unsigned int fullTopologyInLastLevel
virtual void Synchronize()
use Gregory basis patches (20 cp) as end-caps
virtual VertexBufferBinding BindVaryingBuffer()=0
unsigned int interpolationMode
interpolation mode
virtual PatchTable * GetPatchTable() const =0
use BSpline basis patches (16 cp) as end-caps
virtual VertexBufferBinding BindVertexBuffer()=0
virtual int GetMaxValence() const =0
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, DEVICE_CONTEXT *deviceContext)
PatchTable::VertexBufferBinding VertexBufferBinding
Stores topology data for a specified set of refinement options.
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
static StencilTable const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
Utility function for stencil splicing for local point stencils.
std::bitset< NUM_MESH_BITS > MeshBitset
virtual int GetNumVertices() const =0
unsigned int generateFVarTables
Generate face-varying patch tables.
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers. Almost all Osd Evaluator APIs take BufferDescriptors along with device-specific buffer objects.
Container for arrays of parametric patches.
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
int stride
stride to the next element
unsigned int generateOffsets
populate optional "_offsets" field
void SetEndCapType(EndCapType e)
Set endcap patch type.
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive, bool singleCreasePatch)
STENCIL_TABLE StencilTable
virtual VertexBuffer * GetVertexBuffer()
DEVICE_CONTEXT DeviceContext
Table of limit subdivision stencils.
virtual Far::PatchTable const * GetFarPatchTable() const
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, DEVICE_CONTEXT *deviceContext)
STENCIL_TABLE const * convertToCompatibleStencilTable(SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context)
Adaptive refinement options.
virtual int GetMaxValence() const