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;
187 template <
typename DEVICE_CONTEXT>
190 DEVICE_CONTEXT *deviceContext) {
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(
258 EvaluatorCacheT<EVALUATOR> *cache,
259 BufferDescriptor
const &srcDesc,
260 BufferDescriptor
const &dstDesc,
261 BufferDescriptor
const &duDesc,
262 BufferDescriptor
const &dvDesc,
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(
272 EvaluatorCacheT<EVALUATOR> *cache,
273 BufferDescriptor
const &srcDesc,
274 BufferDescriptor
const &dstDesc,
275 DEVICE_CONTEXT deviceContext,
276 typename enable_if<instantiatable<EVALUATOR>::value,
void>::type*t=0) {
278 if (cache == NULL)
return NULL;
279 return cache->GetEvaluator(srcDesc, dstDesc,
286 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
287 static EVALUATOR *GetEvaluator(
288 EvaluatorCacheT<EVALUATOR> *,
289 BufferDescriptor
const &,
290 BufferDescriptor
const &,
291 BufferDescriptor
const &,
292 BufferDescriptor
const &,
294 typename enable_if<!instantiatable<EVALUATOR>::value,
void>::type*t=0) {
299 template <
typename EVALUATOR,
typename DEVICE_CONTEXT>
300 static EVALUATOR *GetEvaluator(
301 EvaluatorCacheT<EVALUATOR> *,
302 BufferDescriptor
const &,
303 BufferDescriptor
const &,
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,
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) {
497 if (numVertexElements>0) {
503 if (numVaryingElements>0) {
517 poptions.SetEndCapType(
520 poptions.SetEndCapType(
524 poptions.shareEndCapPatchPoints =
true;
526 poptions.SetEndCapType(
535 if (Far::StencilTable
const *vertexStencilsWithLocalPoints =
540 delete vertexStencils;
541 vertexStencils = vertexStencilsWithLocalPoints;
543 if (varyingStencils) {
544 if (Far::StencilTable
const *varyingStencilsWithLocalPoints =
549 delete varyingStencils;
550 varyingStencils = varyingStencilsWithLocalPoints;
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);
590 Far::TopologyRefiner * _refiner;
591 Far::PatchTable * _farPatchTable;
596 VertexBuffer * _vertexBuffer;
597 VertexBuffer * _varyingBuffer;
599 BufferDescriptor _vertexDesc;
600 BufferDescriptor _varyingDesc;
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
STENCIL_TABLE StencilTable
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive, bool singleCreasePatch)
Mesh(Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset(), EvaluatorCache *evaluatorCache=NULL, DeviceContext *deviceContext=NULL)
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTable.
int stride
stride to the next element
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.
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.
virtual VertexBufferBinding BindVaryingBuffer()=0
EvaluatorCacheT< Evaluator > EvaluatorCache
int GetMaxValence() const
Returns max vertex valence.
Adaptive refinement options.
virtual VertexBuffer * GetVertexBuffer()
std::bitset< NUM_MESH_BITS > MeshBitset
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
PatchTable::VertexBufferBinding VertexBufferBinding
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
bool IsUniform() const
Returns true if uniform subdivision has been applied.
unsigned int generateOffsets
populate optional "_offsets" field
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTable from TopologyRefiner that have been refined uniformly or adaptively...
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the varying stencil table for the change of basis patch points.
virtual int GetNumVertices() const =0
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
virtual PatchTable * GetPatchTable() const =0
int GetNumVertices() const
Return the number of vertices in this level.
unsigned int interpolationMode
interpolation mode
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, DEVICE_CONTEXT *deviceContext)
virtual VertexBufferBinding BindVertexBuffer()
virtual VertexBufferBinding BindVertexBuffer()=0
virtual void Synchronize()=0
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.
unsigned int generateIntermediateLevels
vertices at all levels or highest only
virtual Far::PatchTable const * GetFarPatchTable() const =0
DEVICE_CONTEXT DeviceContext
unsigned int fullTopologyInLastLevel
Table of subdivision stencils.
VERTEX_BUFFER VertexBuffer
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to get change of basis patch points.
void RefineAdaptive(AdaptiveOptions options)
Feature Adaptive topology refinement (restricted to scheme Catmark)
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
PatchTable::VertexBufferBinding VertexBufferBinding
Container for arrays of parametric patches.
Stores topology data for a specified set of refinement options.
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
int length
number or length of the data
virtual int GetMaxValence() const
use legacy (2.x) Gregory patches (4 cp + valence table) as end-caps
std::vector< Entry > Evaluators
int offset
offset to desired element data
STENCIL_TABLE const * convertToCompatibleStencilTable(SRC_STENCIL_TABLE const *table, DEVICE_CONTEXT *context)
Entry(BufferDescriptor const &srcDescArg, BufferDescriptor const &dstDescArg, BufferDescriptor const &duDescArg, BufferDescriptor const &dvDescArg, EVALUATOR *evalArg)
unsigned int useSingleCreasePatch
Uniform refinement options.
virtual VertexBufferBinding BindVaryingBuffer()
virtual int GetMaxValence() const =0
use Gregory basis patches (20 cp) as end-caps
virtual void Synchronize()
int GetNumStencils() const
Returns the number of stencils in the table.
virtual PatchTable * GetPatchTable() const
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
virtual VertexBuffer * GetVaryingBuffer()
virtual Far::PatchTable const * GetFarPatchTable() const
use BSpline basis patches (16 cp) as end-caps
virtual int GetNumVertices() const
Table of limit subdivision stencils.
EVALUATOR * GetEvaluator(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, DEVICE_CONTEXT *deviceContext)