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 {
65 template <
class PATCH_TABLE>
81 int startVertex,
int numVerts) = 0;
84 int startVertex,
int numVerts) = 0;
100 int level,
bool adaptive,
101 bool singleCreasePatch) {
116 int level, MeshBitset bits) {
136 template <
typename STENCIL_TABLE,
typename SRC_STENCIL_TABLE,
137 typename DEVICE_CONTEXT>
138 STENCIL_TABLE
const *
140 SRC_STENCIL_TABLE
const *table, DEVICE_CONTEXT *context) {
141 if (! table)
return NULL;
142 return STENCIL_TABLE::Create(table, context);
147 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, void>(
151 if (! table)
return NULL;
157 convertToCompatibleStencilTable<Far::LimitStencilTable, Far::LimitStencilTable, void>(
161 if (! table)
return NULL;
167 convertToCompatibleStencilTable<Far::StencilTable, Far::StencilTable, ID3D11DeviceContext>(
171 if (! table)
return NULL;
183 template <
typename EVALUATOR>
187 for(
typename Evaluators::iterator it = _evaluators.begin();
188 it != _evaluators.end(); ++it) {
189 delete it->evaluator;
199 EVALUATOR *evalArg) : srcDesc(srcDescArg), dstDesc(dstDescArg),
200 duDesc(duDescArg), dvDesc(dvDescArg), evaluator(evalArg) {}
206 template <
typename DEVICE_CONTEXT>
209 DEVICE_CONTEXT *deviceContext) {
210 return GetEvaluator(srcDesc, dstDesc,
216 template <
typename DEVICE_CONTEXT>
221 DEVICE_CONTEXT *deviceContext) {
223 for(
typename Evaluators::iterator it = _evaluators.begin();
224 it != _evaluators.end(); ++it) {
225 if (isEqual(srcDesc, it->srcDesc) &&
226 isEqual(dstDesc, it->dstDesc) &&
227 isEqual(duDesc, it->duDesc) &&
228 isEqual(dvDesc, it->dvDesc)) {
229 return it->evaluator;
232 EVALUATOR *e = EVALUATOR::Create(srcDesc, dstDesc,
235 _evaluators.push_back(
Entry(srcDesc, dstDesc, duDesc, dvDesc, e));
247 return (offsetA == offsetB &&
252 Evaluators _evaluators;
258 template <
typename EVALUATOR>
259 struct instantiatable
263 template <
typename C>
static yes &chk(
typename C::Instantiatable *t=0);
264 template <
typename C>
static no &chk(...);
265 static bool const value =
sizeof(chk<EVALUATOR>(0)) ==
sizeof(yes);
267 template <
bool C,
typename T=
void>
268 struct enable_if {
typedef T type; };
269 template <
typename T>
270 struct enable_if<false, T> { };
275 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
276 static EVALUATOR *GetEvaluator(
282 DEVICE_CONTEXT deviceContext,
283 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
285 if (cache == NULL)
return NULL;
286 return cache->
GetEvaluator(srcDesc, dstDesc, duDesc, dvDesc, deviceContext);
289 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
290 static EVALUATOR *GetEvaluator(
294 DEVICE_CONTEXT deviceContext,
295 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
297 if (cache == NULL)
return NULL;
305 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
306 static EVALUATOR *GetEvaluator(
313 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
318 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
319 static EVALUATOR *GetEvaluator(
324 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
331 template <
typename VERTEX_BUFFER,
332 typename STENCIL_TABLE,
334 typename PATCH_TABLE,
335 typename DEVICE_CONTEXT =
void>
347 int numVertexElements,
348 int numVaryingElements,
351 EvaluatorCache * evaluatorCache = NULL,
352 DeviceContext * deviceContext = NULL) :
355 _farPatchTable(NULL),
359 _varyingBuffer(NULL),
360 _vertexStencilTable(NULL),
361 _varyingStencilTable(NULL),
362 _evaluatorCache(evaluatorCache),
364 _deviceContext(deviceContext) {
369 *_refiner, level, bits);
371 int vertexBufferStride = numVertexElements +
373 int varyingBufferStride =
376 initializeContext(numVertexElements,
380 initializeVertexBuffers(_numVertices,
382 varyingBufferStride);
389 numVertexElements, numVaryingElements, vertexBufferStride);
392 0, numVaryingElements, varyingBufferStride);
398 delete _farPatchTable;
399 delete _vertexBuffer;
400 delete _varyingBuffer;
401 delete _vertexStencilTable;
402 delete _varyingStencilTable;
408 int startVertex,
int numVerts) {
409 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts,
414 int startVertex,
int numVerts) {
415 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts,
421 int numControlVertices = _refiner->GetLevel(0).GetNumVertices();
430 Evaluator
const *instance = GetEvaluator<Evaluator>(
431 _evaluatorCache, srcDesc, dstDesc,
434 Evaluator::EvalStencils(_vertexBuffer, srcDesc,
435 _vertexBuffer, dstDesc,
437 instance, _deviceContext);
439 if (_varyingDesc.length > 0) {
442 vDstDesc.
offset += numControlVertices * vDstDesc.
stride;
444 instance = GetEvaluator<Evaluator>(
445 _evaluatorCache, vSrcDesc, vDstDesc,
448 if (_varyingBuffer) {
450 Evaluator::EvalStencils(_varyingBuffer, vSrcDesc,
451 _varyingBuffer, vDstDesc,
452 _varyingStencilTable,
453 instance, _deviceContext);
456 Evaluator::EvalStencils(_vertexBuffer, vSrcDesc,
457 _vertexBuffer, vDstDesc,
458 _varyingStencilTable,
459 instance, _deviceContext);
465 Evaluator::Synchronize(_deviceContext);
473 return _farPatchTable;
481 return _vertexBuffer->BindVBO(_deviceContext);
485 return _varyingBuffer->BindVBO(_deviceContext);
489 return _vertexBuffer;
493 return _varyingBuffer;
501 void initializeContext(
int numVertexElements,
502 int numVaryingElements,
503 int level, MeshBitset bits) {
509 _refiner->IsUniform() ?
false :
true;
514 if (numVertexElements>0) {
520 if (numVaryingElements>0) {
552 if (_farPatchTable->GetLocalPointStencilTable()) {
558 _farPatchTable->GetLocalPointStencilTable())) {
559 delete vertexStencils;
560 vertexStencils = vertexStencilsWithLocalPoints;
562 if (varyingStencils) {
567 _farPatchTable->GetLocalPointVaryingStencilTable())) {
568 delete varyingStencils;
569 varyingStencils = varyingStencilsWithLocalPoints;
574 _maxValence = _farPatchTable->GetMaxValence();
575 _patchTable = PatchTable::Create(_farPatchTable, _deviceContext);
582 _vertexStencilTable =
583 convertToCompatibleStencilTable<StencilTable>(
584 vertexStencils, _deviceContext);
585 _varyingStencilTable =
586 convertToCompatibleStencilTable<StencilTable>(
587 varyingStencils, _deviceContext);
590 delete vertexStencils;
591 delete varyingStencils;
594 void initializeVertexBuffers(
int numVertices,
595 int numVertexElements,
596 int numVaryingElements) {
598 if (numVertexElements) {
599 _vertexBuffer = VertexBuffer::Create(numVertexElements,
600 numVertices, _deviceContext);
603 if (numVaryingElements) {
604 _varyingBuffer = VertexBuffer::Create(numVaryingElements,
605 numVertices, _deviceContext);
615 VertexBuffer * _vertexBuffer;
616 VertexBuffer * _varyingBuffer;
621 StencilTable
const * _vertexStencilTable;
622 StencilTable
const * _varyingStencilTable;
623 EvaluatorCache * _evaluatorCache;
625 PatchTable *_patchTable;
626 DeviceContext *_deviceContext;
632 using namespace OPENSUBDIV_VERSION;
636 #endif // OPENSUBDIV3_OSD_MESH_H
STENCIL_TABLE const * convertToCompatibleStencilTable(SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context)
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
void RefineAdaptive(AdaptiveOptions options)
Feature Adaptive topology refinement (restricted to scheme Catmark)
use legacy (2.x) Gregory patches (4 cp + valence table) as end-caps
virtual Far::PatchTable const * GetFarPatchTable() const
virtual int GetNumVertices() const
Container for arrays of parametric patches.
Table of subdivision stencils.
unsigned int generateFVarTables
Generate face-varying patch tables.
use BSpline basis patches (16 cp) as end-caps
Public options for the PatchTable factory.
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, DEVICE_CONTEXT *deviceContext)
int length
number or length of the data
unsigned int useInfSharpPatch
use Gregory basis patches (20 cp) as end-caps
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, DEVICE_CONTEXT *deviceContext)
virtual PatchTable * GetPatchTable() const =0
DEVICE_CONTEXT DeviceContext
unsigned int considerFVarChannels
void SetEndCapType(EndCapType e)
Set endcap patch type.
int stride
stride to the next element
Table of limit subdivision stencils.
virtual int GetNumVertices() const =0
virtual VertexBuffer * GetVaryingBuffer()
Uniform refinement options.
virtual PatchTable * GetPatchTable() const
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive, bool singleCreasePatch)
virtual int GetMaxValence() const =0
unsigned int fullTopologyInLastLevel
virtual VertexBufferBinding BindVaryingBuffer()
unsigned int useSingleCreasePatch
virtual void Synchronize()
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTable from TopologyRefiner that have been refined uniformly or adaptively...
Stores topology data for a specified set of refinement options.
virtual void Synchronize()=0
virtual VertexBufferBinding BindVertexBuffer()
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.
unsigned int shareEndCapPatchPoints
Adaptive refinement options.
std::vector< Entry > Evaluators
unsigned int useInfSharpPatch
Use infinitely-sharp patch.
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
virtual VertexBufferBinding BindVaryingBuffer()=0
int offset
offset to desired element data
Mesh(Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset(), EvaluatorCache *evaluatorCache=NULL, DeviceContext *deviceContext=NULL)
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
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.
unsigned int generateOffsets
populate optional "_offsets" field
unsigned int interpolationMode
interpolation mode
virtual VertexBuffer * GetVertexBuffer()
unsigned int useSingleCreasePatch
Use single crease patch.
unsigned int generateFVarLegacyLinearPatches
Generate all linear face-varying patches (legacy)
VERTEX_BUFFER VertexBuffer
PatchTable::VertexBufferBinding VertexBufferBinding
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
EvaluatorCacheT< Evaluator > EvaluatorCache
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTable.
STENCIL_TABLE StencilTable
virtual VertexBufferBinding BindVertexBuffer()=0
static void refineMesh(Far::TopologyRefiner &refiner, int level, MeshBitset bits)
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, EVALUATOR *evalArg)
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
std::bitset< NUM_MESH_BITS > MeshBitset
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
unsigned int generateIntermediateLevels
vertices at all levels or highest only
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
virtual int GetMaxValence() const
virtual Far::PatchTable const * GetFarPatchTable() const =0
int GetNumStencils() const
Returns the number of stencils in the table.
PatchTable::VertexBufferBinding VertexBufferBinding