28 #include "../version.h"
30 #include "../far/kernelBatch.h"
31 #include "../far/topologyRefiner.h"
32 #include "../far/patchTablesFactory.h"
33 #include "../far/stencilTables.h"
34 #include "../far/stencilTablesFactory.h"
36 #include "../osd/error.h"
37 #include "../osd/vertex.h"
38 #include "../osd/vertexDescriptor.h"
44 namespace OpenSubdiv {
45 namespace OPENSUBDIV_VERSION {
58 template <
class DRAW_CONTEXT>
71 virtual void UpdateVertexBuffer(
float const *vertexData,
int startVertex,
int numVerts) = 0;
73 virtual void UpdateVaryingBuffer(
float const *varyingData,
int startVertex,
int numVerts) = 0;
79 bool interleaved) = 0;
89 virtual void SetFVarDataChannel(
int fvarWidth, std::vector<float>
const & fvarData) = 0;
113 template <
class VERTEX_BUFFER,
class COMPUTE_CONTROLLER,
class DRAW_CONTEXT>
124 int numVertexElements,
125 int numVaryingElements,
133 _computeController(computeController),
140 initializeVertexBuffers(numVertexElements, numVaryingElements, bits);
142 initializeComputeContext(numVertexElements, numVaryingElements);
144 initializeDrawContext(numVertexElements, bits);
155 _vertexBuffer(vertexBuffer),
156 _varyingBuffer(varyingBuffer),
157 _computeContext(computeContext),
158 _computeController(computeController),
159 _drawContext(drawContext) { }
164 delete _vertexBuffer;
165 delete _varyingBuffer;
166 delete _computeContext;
176 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts);
180 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts);
184 _computeController->Compute(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer);
188 _computeController->Refine(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer, vertexDesc, varyingDesc);
192 _computeController->Synchronize();
208 if (_patchTables and _drawContext and fvarWidth and (not fvarData.empty())) {
209 _drawContext->SetFVarDataTexture(*_patchTables, fvarWidth, fvarData);
215 void initializeComputeContext(
int numVertexElements,
216 int numVaryingElements ) {
226 if (numVertexElements>0) {
233 if (numVaryingElements>0) {
240 _computeContext = ComputeContext::Create(vertexStencils, varyingStencils);
242 delete vertexStencils;
243 delete varyingStencils;
246 void initializeDrawContext(
int numElements,
MeshBitset bits) {
248 assert(_refiner and _vertexBuffer);
250 Far::PatchTablesFactory::Options options;
255 _drawContext = DrawContext::Create(
258 _drawContext->UpdateVertexTexture(_vertexBuffer);
261 int initializeVertexBuffers(
int numVertexElements,
266 int numElements = numVertexElements +
269 if (numVertexElements) {
271 _vertexBuffer = VertexBuffer::Create(numElements, numVertices);
275 _varyingBuffer = VertexBuffer::Create(numVaryingElements, numVertices);
280 Far::TopologyRefiner * _refiner;
281 Far::PatchTables * _patchTables;
296 using namespace OPENSUBDIV_VERSION;
virtual DrawContext * GetDrawContext()
COMPUTE_CONTROLLER ComputeController
int generateOffsets
populate optional "_offsets" field
virtual VertexBufferBinding BindVaryingBuffer()=0
static PatchTables * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTables.
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive)
int generateAllLevels
vertices at all levels or highest only
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
Describes vertex elements in interleaved data buffers.
int GetNumVertices(int level) const
Returns the number of vertices at a given level of refinement.
virtual void SetFVarDataChannel(int fvarWidth, std::vector< float > const &fvarData)
Table of subdivision stencils.
DrawContext::VertexBufferBinding VertexBufferBinding
std::vector< KernelBatch > KernelBatchVector
virtual void SetFVarDataChannel(int fvarWidth, std::vector< float > const &fvarData)=0
virtual DrawContext * GetDrawContext()=0
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)=0
virtual void Synchronize()
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
DrawContext::VertexBufferBinding VertexBufferBinding
virtual void Refine(VertexBufferDescriptor const *vertexDesc, VertexBufferDescriptor const *varyingDesc)
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, VertexBuffer *vertexBuffer, VertexBuffer *varyingBuffer, ComputeContext *computeContext, DrawContext *drawContext)
int interpolationMode
interpolation mode
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
VERTEX_BUFFER VertexBuffer
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)=0
virtual int GetNumVertices() const
void RefineAdaptive(int maxLevel, bool fullTopologyInLastLevel=false)
Feature Adaptive topology refinement.
std::bitset< NUM_MESH_BITS > MeshBitset
ComputeController::ComputeContext ComputeContext
virtual VertexBufferBinding BindVertexBuffer()=0
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits=MeshBitset())
int GetMaxLevel() const
Returns the highest level of refinement.
virtual VertexBufferBinding BindVaryingBuffer()
static StencilTables const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTables from TopologyRefiner that have been refined uniformly or adaptively...
virtual int GetNumVertices() const =0
bool IsUniform() const
Returns true if uniform subdivision has been applied.
Stores topology data for a specified set of refinement options.
void RefineUniform(int maxLevel, bool fullTopologyInLastLevel=false)
Refine the topology uniformly.
virtual void Synchronize()=0
virtual VertexBufferBinding BindVertexBuffer()
static int getNumVertices(Far::TopologyRefiner const &refiner)