25 #ifndef OSD_D3D11MESH_H
26 #define OSD_D3D11MESH_H
28 #include "../version.h"
30 #include "../osd/mesh.h"
31 #include "../osd/d3d11ComputeController.h"
32 #include "../osd/d3d11DrawContext.h"
33 #include "../osd/d3d11VertexBuffer.h"
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
42 template <
class VERTEX_BUFFER,
class COMPUTE_CONTROLLER>
53 int numVertexElements,
54 int numVaryingElements,
57 ID3D11DeviceContext *d3d11DeviceContext) :
64 _computeController(computeController),
66 _d3d11DeviceContext(d3d11DeviceContext)
71 initializeVertexBuffers(numVertexElements, numVaryingElements, bits);
73 initializeComputeContext(numVertexElements, numVaryingElements);
75 initializeDrawContext(numElements, bits);
84 ID3D11DeviceContext *d3d11DeviceContext) :
87 _vertexBuffer(vertexBuffer),
88 _varyingBuffer(varyingBuffer),
89 _computeContext(computeContext),
90 _computeController(computeController),
91 _drawContext(drawContext),
92 _d3d11DeviceContext(d3d11DeviceContext)
94 _drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
100 delete _vertexBuffer;
101 delete _varyingBuffer;
102 delete _computeContext;
112 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts, _d3d11DeviceContext);
115 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts, _d3d11DeviceContext);
118 _computeController->Compute(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer);
123 _computeController->Compute(_computeContext, _kernelBatches,
124 _vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
125 vertexDesc, varyingDesc);
128 _computeController->Synchronize();
131 return _vertexBuffer->BindD3D11Buffer(_d3d11DeviceContext);
134 return _varyingBuffer->BindD3D11Buffer(_d3d11DeviceContext);
140 return _vertexBuffer;
143 return _varyingBuffer;
151 std::vector<float>
const & fvarData) {
153 if (_patchTables and _drawContext and fvarWidth and (not fvarData.empty())) {
154 _drawContext->SetFVarDataTexture(*_patchTables,
155 _d3d11DeviceContext, fvarWidth, fvarData);
161 void initializeComputeContext(
int numVertexElements,
162 int numVaryingElements ) {
172 if (numVertexElements>0) {
179 if (numVaryingElements>0) {
186 _computeContext = ComputeContext::Create(vertexStencils, varyingStencils);
188 delete vertexStencils;
189 delete varyingStencils;
192 void initializeDrawContext(
int numElements,
MeshBitset bits) {
194 assert(_refiner and _vertexBuffer);
196 Far::PatchTablesFactory::Options options;
201 _drawContext = DrawContext::Create(
202 _patchTables, _d3d11DeviceContext, numElements);
204 _drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
207 int initializeVertexBuffers(
int numVertexElements,
210 ID3D11Device * pd3d11Device;
211 _d3d11DeviceContext->GetDevice(&pd3d11Device);
215 int numElements = numVertexElements +
218 if (numVertexElements) {
221 VertexBuffer::Create(numElements, numVertices, pd3d11Device);
226 VertexBuffer::Create(numVaryingElements, numVertices, pd3d11Device);
231 Far::TopologyRefiner * _refiner;
232 Far::PatchTables * _patchTables;
242 ID3D11DeviceContext *_d3d11DeviceContext;
256 int numVertexElements,
257 int numVaryingElements,
260 ID3D11DeviceContext *d3d11DeviceContext) :
267 _computeController(computeController),
269 _d3d11DeviceContext(d3d11DeviceContext)
274 initializeVertexBuffers(numVertexElements, numVaryingElements, bits);
276 initializeComputeContext(numVertexElements, numVaryingElements);
278 initializeDrawContext(numElements, bits);
287 ID3D11DeviceContext *d3d11DeviceContext) :
290 _vertexBuffer(vertexBuffer),
291 _varyingBuffer(varyingBuffer),
292 _computeContext(computeContext),
293 _computeController(computeController),
294 _drawContext(drawContext),
295 _d3d11DeviceContext(d3d11DeviceContext)
297 _drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
303 delete _vertexBuffer;
304 delete _varyingBuffer;
305 delete _computeContext;
312 _vertexBuffer->UpdateData(vertexData, startVertex, numVerts, _d3d11DeviceContext);
315 _varyingBuffer->UpdateData(varyingData, startVertex, numVerts, _d3d11DeviceContext);
318 _computeController->Compute(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer);
323 _computeController->Compute(_computeContext, _kernelBatches,
324 _vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
325 vertexDesc, varyingDesc);
328 _computeController->Synchronize();
331 return _vertexBuffer->BindD3D11Buffer(_d3d11DeviceContext);
334 return _varyingBuffer->BindD3D11Buffer(_d3d11DeviceContext);
340 return _vertexBuffer;
343 return _varyingBuffer;
351 std::vector<float>
const & fvarData) {
353 if (_patchTables and _drawContext and fvarWidth and (not fvarData.empty())) {
354 _drawContext->SetFVarDataTexture(*_patchTables,
355 _d3d11DeviceContext, fvarWidth, fvarData);
362 void initializeComputeContext(
int numVertexElements,
363 int numVaryingElements ) {
373 if (numVertexElements>0) {
380 if (numVaryingElements>0) {
388 ComputeContext::Create(_d3d11DeviceContext, vertexStencils, varyingStencils);
390 delete vertexStencils;
391 delete varyingStencils;
394 void initializeDrawContext(
int numElements,
MeshBitset bits) {
396 assert(_refiner and _vertexBuffer);
398 Far::PatchTablesFactory::Options options;
403 _drawContext = DrawContext::Create(
404 _patchTables, _d3d11DeviceContext, numElements);
406 _drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
409 int initializeVertexBuffers(
int numVertexElements,
412 ID3D11Device * pd3d11Device;
413 _d3d11DeviceContext->GetDevice(&pd3d11Device);
417 int numElements = numVertexElements +
420 if (numVertexElements) {
422 VertexBuffer::Create(numElements, numVertices, pd3d11Device);
427 VertexBuffer::Create(numVaryingElements, numVertices, pd3d11Device);
432 Far::TopologyRefiner * _refiner;
433 Far::PatchTables * _patchTables;
443 ID3D11DeviceContext *_d3d11DeviceContext;
450 using namespace OPENSUBDIV_VERSION;
454 #endif // OSD_D3D11MESH_H
ComputeController::ComputeContext ComputeContext
COMPUTE_CONTROLLER ComputeController
D3D11VertexBuffer VertexBuffer
int generateOffsets
populate optional "_offsets" field
D3D11 specialized DrawContext class.
static PatchTables * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTables.
static void refineMesh(Far::TopologyRefiner &refiner, int level, bool adaptive)
virtual VertexBuffer * GetVertexBuffer()
virtual void SetFVarDataChannel(int fvarWidth, std::vector< float > const &fvarData)
int generateAllLevels
vertices at all levels or highest only
virtual void Synchronize()
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
Describes vertex elements in interleaved data buffers.
D3D11DrawContext DrawContext
virtual void Refine(VertexBufferDescriptor const *vertexDesc, VertexBufferDescriptor const *varyingDesc, bool interleaved)
Table of subdivision stencils.
virtual DrawContext * GetDrawContext()
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts)
std::vector< KernelBatch > KernelBatchVector
DrawContext::VertexBufferBinding VertexBufferBinding
virtual void Synchronize()
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
virtual DrawContext * GetDrawContext()
D3D11DrawContext DrawContext
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts)
virtual VertexBuffer * GetVertexBuffer()
ID3D11Buffer * VertexBufferBinding
virtual Far::TopologyRefiner const * GetTopologyRefiner() const
virtual void Refine(VertexBufferDescriptor const *vertexDesc, VertexBufferDescriptor const *varyingDesc, bool interleaved)
MeshInterface< D3D11DrawContext > D3D11MeshInterface
VERTEX_BUFFER VertexBuffer
int interpolationMode
interpolation mode
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits, ID3D11DeviceContext *d3d11DeviceContext)
virtual VertexBuffer * GetVaryingBuffer()
VERTEX_BUFFER VertexBuffer
virtual VertexBufferBinding BindVaryingBuffer()
virtual VertexBufferBinding BindVertexBuffer()
virtual VertexBuffer * GetVaryingBuffer()
Compute controller for launching D3D11 Compute subdivision kernels.
D3D11ComputeController ComputeController
ComputeController::ComputeContext ComputeContext
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, VertexBuffer *vertexBuffer, VertexBuffer *varyingBuffer, ComputeContext *computeContext, DrawContext *drawContext, ID3D11DeviceContext *d3d11DeviceContext)
virtual int GetNumVertices() const
std::bitset< NUM_MESH_BITS > MeshBitset
virtual VertexBufferBinding BindVaryingBuffer()
ComputeController::ComputeContext ComputeContext
DrawContext::VertexBufferBinding VertexBufferBinding
virtual int GetNumVertices() const
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, int numVertexElements, int numVaryingElements, int level, MeshBitset bits, ID3D11DeviceContext *d3d11DeviceContext)
COMPUTE_CONTROLLER ComputeController
Concrete vertex buffer class for DirectX subvision and DirectX drawing.
static StencilTables const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTables from TopologyRefiner that have been refined uniformly or adaptively...
bool IsUniform() const
Returns true if uniform subdivision has been applied.
Stores topology data for a specified set of refinement options.
Mesh(ComputeController *computeController, Far::TopologyRefiner *refiner, VertexBuffer *vertexBuffer, VertexBuffer *varyingBuffer, ComputeContext *computeContext, DrawContext *drawContext, ID3D11DeviceContext *d3d11DeviceContext)
virtual VertexBufferBinding BindVertexBuffer()
static int getNumVertices(Far::TopologyRefiner const &refiner)
virtual void SetFVarDataChannel(int fvarWidth, std::vector< float > const &fvarData)