2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifndef OSD_D3D11MESH_H
|
|
|
|
#define OSD_D3D11MESH_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "../osd/mesh.h"
|
2012-12-13 18:22:30 +00:00
|
|
|
#include "../osd/d3d11ComputeController.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../osd/d3d11DrawContext.h"
|
2012-12-13 18:22:30 +00:00
|
|
|
#include "../osd/d3d11VertexBuffer.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Osd {
|
|
|
|
|
|
|
|
typedef MeshInterface<D3D11DrawContext> D3D11MeshInterface;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
template <class VERTEX_BUFFER, class COMPUTE_CONTROLLER>
|
2014-09-05 22:07:46 +00:00
|
|
|
class Mesh<VERTEX_BUFFER, COMPUTE_CONTROLLER, D3D11DrawContext> : public D3D11MeshInterface {
|
2012-12-11 01:15:13 +00:00
|
|
|
public:
|
|
|
|
typedef VERTEX_BUFFER VertexBuffer;
|
|
|
|
typedef COMPUTE_CONTROLLER ComputeController;
|
2014-09-05 22:07:46 +00:00
|
|
|
typedef typename ComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef D3D11DrawContext DrawContext;
|
2012-12-11 01:15:13 +00:00
|
|
|
typedef typename DrawContext::VertexBufferBinding VertexBufferBinding;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Mesh(ComputeController * computeController,
|
|
|
|
Far::TopologyRefiner * refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2012-12-11 01:15:13 +00:00
|
|
|
int level,
|
2014-09-05 22:07:46 +00:00
|
|
|
MeshBitset bits,
|
2012-12-11 01:15:13 +00:00
|
|
|
ID3D11DeviceContext *d3d11DeviceContext) :
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_refiner(refiner),
|
|
|
|
_patchTables(0),
|
2012-12-11 01:15:13 +00:00
|
|
|
_vertexBuffer(0),
|
2013-06-27 19:57:21 +00:00
|
|
|
_varyingBuffer(0),
|
2012-12-11 01:15:13 +00:00
|
|
|
_computeContext(0),
|
2013-02-20 01:33:32 +00:00
|
|
|
_computeController(computeController),
|
2012-12-11 01:15:13 +00:00
|
|
|
_drawContext(0),
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext(d3d11DeviceContext)
|
2012-12-11 01:15:13 +00:00
|
|
|
{
|
2014-09-05 22:07:46 +00:00
|
|
|
D3D11MeshInterface::refineMesh(*_refiner, level, bits.test(MeshAdaptive));
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int numElements =
|
|
|
|
initializeVertexBuffers(numVertexElements, numVaryingElements, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
initializeComputeContext(numVertexElements, numVaryingElements);
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
initializeDrawContext(numElements, bits);
|
2014-04-19 00:19:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Mesh(ComputeController * computeController,
|
|
|
|
Far::TopologyRefiner * refiner,
|
2014-09-12 20:13:43 +00:00
|
|
|
Far::PatchTables * patchTables,
|
|
|
|
Far::KernelBatchVector const & kernelBatches,
|
2014-04-19 00:19:08 +00:00
|
|
|
VertexBuffer * vertexBuffer,
|
|
|
|
VertexBuffer * varyingBuffer,
|
|
|
|
ComputeContext * computeContext,
|
|
|
|
DrawContext * drawContext,
|
|
|
|
ID3D11DeviceContext *d3d11DeviceContext) :
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_refiner(refiner),
|
2014-09-12 20:13:43 +00:00
|
|
|
_patchTables(patchTables),
|
|
|
|
_kernelBatches(kernelBatches),
|
2014-04-19 00:19:08 +00:00
|
|
|
_vertexBuffer(vertexBuffer),
|
|
|
|
_varyingBuffer(varyingBuffer),
|
|
|
|
_computeContext(computeContext),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(drawContext),
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext(d3d11DeviceContext)
|
2014-04-19 00:19:08 +00:00
|
|
|
{
|
2014-09-05 22:07:46 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual ~Mesh() {
|
|
|
|
delete _refiner;
|
|
|
|
delete _patchTables;
|
2012-12-11 01:15:13 +00:00
|
|
|
delete _vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
delete _varyingBuffer;
|
2012-12-11 01:15:13 +00:00
|
|
|
delete _computeContext;
|
|
|
|
delete _drawContext;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual int GetNumVertices() const {
|
|
|
|
assert(_refiner);
|
|
|
|
return D3D11MeshInterface::getNumVertices(*_refiner);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_vertexBuffer->UpdateData(vertexData, startVertex, numVerts, _d3d11DeviceContext);
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_varyingBuffer->UpdateData(varyingData, startVertex, numVerts, _d3d11DeviceContext);
|
2013-06-27 19:57:21 +00:00
|
|
|
}
|
2012-12-13 18:22:30 +00:00
|
|
|
virtual void Refine() {
|
2014-09-05 22:07:46 +00:00
|
|
|
_computeController->Compute(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer);
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual void Refine(VertexBufferDescriptor const *vertexDesc,
|
|
|
|
VertexBufferDescriptor const *varyingDesc,
|
2014-05-09 00:20:54 +00:00
|
|
|
bool interleaved) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_computeController->Compute(_computeContext, _kernelBatches,
|
|
|
|
_vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
|
2014-05-09 00:20:54 +00:00
|
|
|
vertexDesc, varyingDesc);
|
|
|
|
}
|
2012-12-13 18:22:30 +00:00
|
|
|
virtual void Synchronize() {
|
|
|
|
_computeController->Synchronize();
|
|
|
|
}
|
|
|
|
virtual VertexBufferBinding BindVertexBuffer() {
|
2014-09-05 22:07:46 +00:00
|
|
|
return _vertexBuffer->BindD3D11Buffer(_d3d11DeviceContext);
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() {
|
2014-09-05 22:07:46 +00:00
|
|
|
return _varyingBuffer->BindD3D11Buffer(_d3d11DeviceContext);
|
2013-06-27 19:57:21 +00:00
|
|
|
}
|
2012-12-13 18:22:30 +00:00
|
|
|
virtual DrawContext * GetDrawContext() {
|
|
|
|
return _drawContext;
|
|
|
|
}
|
2014-04-19 00:19:08 +00:00
|
|
|
virtual VertexBuffer * GetVertexBuffer() {
|
|
|
|
return _vertexBuffer;
|
|
|
|
}
|
|
|
|
virtual VertexBuffer * GetVaryingBuffer() {
|
|
|
|
return _varyingBuffer;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
virtual Far::TopologyRefiner const * GetTopologyRefiner() const {
|
|
|
|
return _refiner;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetFVarDataChannel(int fvarWidth,
|
|
|
|
std::vector<float> const & fvarData) {
|
|
|
|
|
|
|
|
if (_patchTables and _drawContext and fvarWidth and (not fvarData.empty())) {
|
|
|
|
_drawContext->SetFVarDataTexture(*_patchTables,
|
|
|
|
_d3d11DeviceContext, fvarWidth, fvarData);
|
|
|
|
}
|
2014-04-19 00:19:08 +00:00
|
|
|
}
|
2012-12-13 18:22:30 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void initializeComputeContext(int numVertexElements,
|
|
|
|
int numVaryingElements ) {
|
|
|
|
|
|
|
|
assert(_refiner);
|
|
|
|
|
|
|
|
Far::StencilTablesFactory::Options options;
|
|
|
|
options.generateOffsets=true;
|
|
|
|
options.generateAllLevels=_refiner->IsUniform() ? false : true;
|
|
|
|
|
|
|
|
Far::StencilTables const * vertexStencils=0, * varyingStencils=0;
|
|
|
|
|
|
|
|
if (numVertexElements>0) {
|
|
|
|
|
|
|
|
vertexStencils = Far::StencilTablesFactory::Create(*_refiner, options);
|
|
|
|
|
|
|
|
_kernelBatches.push_back(Far::StencilTablesFactory::Create(*vertexStencils));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numVaryingElements>0) {
|
|
|
|
|
|
|
|
options.interpolationMode = Far::StencilTablesFactory::INTERPOLATE_VARYING;
|
|
|
|
|
|
|
|
varyingStencils = Far::StencilTablesFactory::Create(*_refiner, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
_computeContext = ComputeContext::Create(vertexStencils, varyingStencils);
|
|
|
|
|
|
|
|
delete vertexStencils;
|
|
|
|
delete varyingStencils;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initializeDrawContext(int numElements, MeshBitset bits) {
|
|
|
|
|
|
|
|
assert(_refiner and _vertexBuffer);
|
|
|
|
|
|
|
|
Far::PatchTablesFactory::Options options;
|
|
|
|
options.generateFVarTables = bits.test(MeshFVarData);
|
|
|
|
|
|
|
|
_patchTables = Far::PatchTablesFactory::Create(*_refiner, options);
|
|
|
|
|
|
|
|
_drawContext = DrawContext::Create(
|
|
|
|
_patchTables, _d3d11DeviceContext, numElements);
|
|
|
|
|
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
int initializeVertexBuffers(int numVertexElements,
|
|
|
|
int numVaryingElements, MeshBitset bits) {
|
|
|
|
|
2014-04-19 00:19:08 +00:00
|
|
|
ID3D11Device * pd3d11Device;
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext->GetDevice(&pd3d11Device);
|
|
|
|
|
|
|
|
int numVertices = D3D11MeshInterface::getNumVertices(*_refiner);
|
|
|
|
|
|
|
|
int numElements = numVertexElements +
|
|
|
|
(bits.test(MeshInterleaveVarying) ? numVaryingElements : 0);
|
|
|
|
|
|
|
|
if (numVertexElements) {
|
|
|
|
|
|
|
|
_vertexBuffer =
|
|
|
|
VertexBuffer::Create(numElements, numVertices, pd3d11Device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numVaryingElements>0 and (not bits.test(MeshInterleaveVarying))) {
|
|
|
|
_varyingBuffer =
|
|
|
|
VertexBuffer::Create(numVaryingElements, numVertices, pd3d11Device);
|
|
|
|
}
|
|
|
|
return numElements;
|
|
|
|
}
|
|
|
|
|
|
|
|
Far::TopologyRefiner * _refiner;
|
|
|
|
Far::PatchTables * _patchTables;
|
|
|
|
Far::KernelBatchVector _kernelBatches;
|
|
|
|
|
2012-12-13 18:22:30 +00:00
|
|
|
VertexBuffer *_vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
VertexBuffer *_varyingBuffer;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2012-12-13 18:22:30 +00:00
|
|
|
ComputeContext *_computeContext;
|
|
|
|
ComputeController *_computeController;
|
|
|
|
DrawContext *_drawContext;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
ID3D11DeviceContext *_d3d11DeviceContext;
|
2012-12-13 18:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2014-09-05 22:07:46 +00:00
|
|
|
class Mesh<D3D11VertexBuffer, D3D11ComputeController, D3D11DrawContext> : public D3D11MeshInterface {
|
2012-12-13 18:22:30 +00:00
|
|
|
public:
|
2014-09-05 22:07:46 +00:00
|
|
|
typedef D3D11VertexBuffer VertexBuffer;
|
|
|
|
typedef D3D11ComputeController ComputeController;
|
|
|
|
typedef ComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef D3D11DrawContext DrawContext;
|
2012-12-13 18:22:30 +00:00
|
|
|
typedef DrawContext::VertexBufferBinding VertexBufferBinding;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Mesh(ComputeController * computeController,
|
|
|
|
Far::TopologyRefiner * refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2012-12-13 18:22:30 +00:00
|
|
|
int level,
|
2014-09-05 22:07:46 +00:00
|
|
|
MeshBitset bits,
|
2012-12-13 18:22:30 +00:00
|
|
|
ID3D11DeviceContext *d3d11DeviceContext) :
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_refiner(refiner),
|
|
|
|
_patchTables(0),
|
2012-12-13 18:22:30 +00:00
|
|
|
_vertexBuffer(0),
|
2013-06-27 19:57:21 +00:00
|
|
|
_varyingBuffer(0),
|
2012-12-13 18:22:30 +00:00
|
|
|
_computeContext(0),
|
2013-02-20 01:33:32 +00:00
|
|
|
_computeController(computeController),
|
2012-12-13 18:22:30 +00:00
|
|
|
_drawContext(0),
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext(d3d11DeviceContext)
|
2012-12-13 18:22:30 +00:00
|
|
|
{
|
2014-09-05 22:07:46 +00:00
|
|
|
D3D11MeshInterface::refineMesh(*_refiner, level, bits.test(MeshAdaptive));
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int numElements =
|
|
|
|
initializeVertexBuffers(numVertexElements, numVaryingElements, bits);
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
initializeComputeContext(numVertexElements, numVaryingElements);
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
initializeDrawContext(numElements, bits);
|
2014-04-19 00:19:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Mesh(ComputeController * computeController,
|
|
|
|
Far::TopologyRefiner * refiner,
|
2014-09-12 20:13:43 +00:00
|
|
|
Far::PatchTables * patchTables,
|
|
|
|
Far::KernelBatchVector const & kernelBatches,
|
2014-04-19 00:19:08 +00:00
|
|
|
VertexBuffer * vertexBuffer,
|
|
|
|
VertexBuffer * varyingBuffer,
|
|
|
|
ComputeContext * computeContext,
|
|
|
|
DrawContext * drawContext,
|
|
|
|
ID3D11DeviceContext *d3d11DeviceContext) :
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_refiner(refiner),
|
2014-09-12 20:13:43 +00:00
|
|
|
_patchTables(patchTables),
|
|
|
|
_kernelBatches(kernelBatches),
|
2014-04-19 00:19:08 +00:00
|
|
|
_vertexBuffer(vertexBuffer),
|
|
|
|
_varyingBuffer(varyingBuffer),
|
|
|
|
_computeContext(computeContext),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(drawContext),
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext(d3d11DeviceContext)
|
2014-04-19 00:19:08 +00:00
|
|
|
{
|
2014-09-05 22:07:46 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual ~Mesh() {
|
|
|
|
delete _refiner;
|
|
|
|
delete _patchTables;
|
2012-12-13 18:22:30 +00:00
|
|
|
delete _vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
delete _varyingBuffer;
|
2012-12-13 18:22:30 +00:00
|
|
|
delete _computeContext;
|
|
|
|
delete _drawContext;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual int GetNumVertices() const { return _refiner->GetNumVerticesTotal(); }
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_vertexBuffer->UpdateData(vertexData, startVertex, numVerts, _d3d11DeviceContext);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_varyingBuffer->UpdateData(varyingData, startVertex, numVerts, _d3d11DeviceContext);
|
2013-06-27 19:57:21 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Refine() {
|
2014-09-05 22:07:46 +00:00
|
|
|
_computeController->Compute(_computeContext, _kernelBatches, _vertexBuffer, _varyingBuffer);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual void Refine(VertexBufferDescriptor const *vertexDesc,
|
|
|
|
VertexBufferDescriptor const *varyingDesc,
|
2014-05-09 00:20:54 +00:00
|
|
|
bool interleaved) {
|
2014-09-05 22:07:46 +00:00
|
|
|
_computeController->Compute(_computeContext, _kernelBatches,
|
|
|
|
_vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
|
2014-05-09 00:20:54 +00:00
|
|
|
vertexDesc, varyingDesc);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Synchronize() {
|
|
|
|
_computeController->Synchronize();
|
|
|
|
}
|
|
|
|
virtual VertexBufferBinding BindVertexBuffer() {
|
2014-09-05 22:07:46 +00:00
|
|
|
return _vertexBuffer->BindD3D11Buffer(_d3d11DeviceContext);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() {
|
2014-09-05 22:07:46 +00:00
|
|
|
return _varyingBuffer->BindD3D11Buffer(_d3d11DeviceContext);
|
2013-06-27 19:57:21 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual DrawContext * GetDrawContext() {
|
|
|
|
return _drawContext;
|
|
|
|
}
|
2014-04-19 00:19:08 +00:00
|
|
|
virtual VertexBuffer * GetVertexBuffer() {
|
|
|
|
return _vertexBuffer;
|
|
|
|
}
|
|
|
|
virtual VertexBuffer * GetVaryingBuffer() {
|
|
|
|
return _varyingBuffer;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
virtual Far::TopologyRefiner const * GetTopologyRefiner() const {
|
|
|
|
return _refiner;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetFVarDataChannel(int fvarWidth,
|
|
|
|
std::vector<float> const & fvarData) {
|
|
|
|
|
|
|
|
if (_patchTables and _drawContext and fvarWidth and (not fvarData.empty())) {
|
|
|
|
_drawContext->SetFVarDataTexture(*_patchTables,
|
|
|
|
_d3d11DeviceContext, fvarWidth, fvarData);
|
|
|
|
}
|
2014-04-19 00:19:08 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void initializeComputeContext(int numVertexElements,
|
|
|
|
int numVaryingElements ) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(_refiner);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Far::StencilTablesFactory::Options options;
|
|
|
|
options.generateOffsets=true;
|
|
|
|
options.generateAllLevels=_refiner->IsUniform() ? false : true;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Far::StencilTables const * vertexStencils=0, * varyingStencils=0;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (numVertexElements>0) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
vertexStencils = Far::StencilTablesFactory::Create(*_refiner, options);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_kernelBatches.push_back(Far::StencilTablesFactory::Create(*vertexStencils));
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (numVaryingElements>0) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
options.interpolationMode = Far::StencilTablesFactory::INTERPOLATE_VARYING;
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
varyingStencils = Far::StencilTablesFactory::Create(*_refiner, options);
|
|
|
|
}
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_computeContext =
|
|
|
|
ComputeContext::Create(_d3d11DeviceContext, vertexStencils, varyingStencils);
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
delete vertexStencils;
|
|
|
|
delete varyingStencils;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void initializeDrawContext(int numElements, MeshBitset bits) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(_refiner and _vertexBuffer);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Far::PatchTablesFactory::Options options;
|
|
|
|
options.generateFVarTables = bits.test(MeshFVarData);
|
|
|
|
|
|
|
|
_patchTables = Far::PatchTablesFactory::Create(*_refiner, options);
|
|
|
|
|
|
|
|
_drawContext = DrawContext::Create(
|
|
|
|
_patchTables, _d3d11DeviceContext, numElements);
|
|
|
|
|
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer, _d3d11DeviceContext);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
int initializeVertexBuffers(int numVertexElements,
|
|
|
|
int numVaryingElements, MeshBitset bits) {
|
|
|
|
|
2013-06-27 19:57:21 +00:00
|
|
|
ID3D11Device * pd3d11Device;
|
2014-09-05 22:07:46 +00:00
|
|
|
_d3d11DeviceContext->GetDevice(&pd3d11Device);
|
|
|
|
|
|
|
|
int numVertices = D3D11MeshInterface::getNumVertices(*_refiner);
|
|
|
|
|
|
|
|
int numElements = numVertexElements +
|
|
|
|
(bits.test(MeshInterleaveVarying) ? numVaryingElements : 0);
|
|
|
|
|
|
|
|
if (numVertexElements) {
|
|
|
|
_vertexBuffer =
|
|
|
|
VertexBuffer::Create(numElements, numVertices, pd3d11Device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numVaryingElements>0 and (not bits.test(MeshInterleaveVarying))) {
|
|
|
|
_varyingBuffer =
|
|
|
|
VertexBuffer::Create(numVaryingElements, numVertices, pd3d11Device);
|
|
|
|
}
|
|
|
|
return numElements;
|
2014-04-19 00:19:08 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Far::TopologyRefiner * _refiner;
|
|
|
|
Far::PatchTables * _patchTables;
|
|
|
|
Far::KernelBatchVector _kernelBatches;
|
2014-04-19 00:19:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
VertexBuffer *_vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
VertexBuffer *_varyingBuffer;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
ComputeContext *_computeContext;
|
|
|
|
ComputeController *_computeController;
|
|
|
|
DrawContext *_drawContext;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
ID3D11DeviceContext *_d3d11DeviceContext;
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
} // end namespace Osd
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
2012-12-11 01:15:13 +00:00
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif // OSD_D3D11MESH_H
|