2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License
|
|
|
|
// and the following modification to it: Section 6 Trademarks.
|
|
|
|
// deleted and replaced with:
|
2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +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 for reproducing
|
|
|
|
// the content of the NOTICE file.
|
2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// You may obtain a copy of the License at
|
2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific
|
|
|
|
// language governing permissions and limitations under the
|
|
|
|
// License.
|
2012-06-09 00:06:35 +00:00
|
|
|
//
|
|
|
|
#ifndef OSD_MESH_H
|
|
|
|
#define OSD_MESH_H
|
|
|
|
|
2012-06-12 00:02:27 +00:00
|
|
|
#include "../version.h"
|
2012-06-20 00:15:07 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../far/mesh.h"
|
|
|
|
#include "../far/meshFactory.h"
|
|
|
|
|
|
|
|
#include "../hbr/mesh.h"
|
|
|
|
|
2012-06-20 00:15:07 +00:00
|
|
|
#include "../osd/vertex.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
#include <bitset>
|
2012-06-12 23:04:12 +00:00
|
|
|
|
2012-06-09 00:06:35 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
enum OsdMeshBits {
|
|
|
|
MeshAdaptive = 0,
|
2012-08-10 22:14:02 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
MeshPtexData = 1,
|
|
|
|
MeshFVarData = 2,
|
2012-08-10 22:14:02 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
NUM_MESH_BITS = 3,
|
|
|
|
};
|
|
|
|
typedef std::bitset<NUM_MESH_BITS> OsdMeshBitset;
|
2012-06-09 18:12:34 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
template <class DRAW_CONTEXT>
|
|
|
|
class OsdMeshInterface {
|
2012-06-09 00:06:35 +00:00
|
|
|
public:
|
2012-12-11 01:15:13 +00:00
|
|
|
typedef DRAW_CONTEXT DrawContext;
|
|
|
|
typedef typename DrawContext::VertexBufferBinding VertexBufferBinding;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
public:
|
|
|
|
OsdMeshInterface() { }
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual ~OsdMeshInterface() { }
|
2012-06-09 18:12:34 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual int GetNumVertices() const = 0;
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts) = 0;
|
2012-06-09 18:12:34 +00:00
|
|
|
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual void UpdateVaryingBuffer(float const *varyingData, int startVertex, int numVerts) = 0;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Refine() = 0;
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Synchronize() = 0;
|
2012-06-09 18:12:34 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual DrawContext * GetDrawContext() = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual VertexBufferBinding BindVertexBuffer() = 0;
|
2013-06-27 19:57:21 +00:00
|
|
|
|
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
template <class VERTEX_BUFFER, class COMPUTE_CONTROLLER, class DRAW_CONTEXT>
|
|
|
|
class OsdMesh : public OsdMeshInterface<DRAW_CONTEXT> {
|
|
|
|
public:
|
|
|
|
typedef VERTEX_BUFFER VertexBuffer;
|
|
|
|
typedef COMPUTE_CONTROLLER ComputeController;
|
|
|
|
typedef typename ComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef DRAW_CONTEXT DrawContext;
|
|
|
|
typedef typename DrawContext::VertexBufferBinding VertexBufferBinding;
|
|
|
|
|
2013-02-20 01:33:32 +00:00
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
HbrMesh<OsdVertex> * hmesh,
|
2013-06-27 19:57:21 +00:00
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2012-12-11 01:15:13 +00:00
|
|
|
int level,
|
|
|
|
OsdMeshBitset bits = OsdMeshBitset()) :
|
|
|
|
|
|
|
|
_farMesh(0),
|
|
|
|
_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)
|
|
|
|
{
|
|
|
|
FarMeshFactory<OsdVertex> meshFactory(hmesh, level, bits.test(MeshAdaptive));
|
2013-05-09 16:23:01 +00:00
|
|
|
_farMesh = meshFactory.Create(bits.test(MeshFVarData));
|
2013-08-08 20:11:16 +00:00
|
|
|
|
|
|
|
_initialize(numVertexElements, numVaryingElements, level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-08-08 20:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
FarMesh<OsdVertex> * fmesh,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
|
|
|
int level,
|
|
|
|
OsdMeshBitset bits = OsdMeshBitset()) :
|
|
|
|
|
|
|
|
_farMesh(fmesh),
|
|
|
|
_vertexBuffer(0),
|
|
|
|
_varyingBuffer(0),
|
|
|
|
_computeContext(0),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(0)
|
|
|
|
{
|
|
|
|
_initialize(numVertexElements, numVaryingElements, level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~OsdMesh() {
|
|
|
|
delete _farMesh;
|
|
|
|
delete _vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
delete _varyingBuffer;
|
2012-12-11 01:15:13 +00:00
|
|
|
delete _computeContext;
|
|
|
|
delete _drawContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetNumVertices() const { return _farMesh->GetNumVertices(); }
|
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
virtual void UpdateVertexBuffer(float const *vertexData, int startVertex, int numVerts) {
|
|
|
|
_vertexBuffer->UpdateData(vertexData, startVertex, numVerts);
|
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) {
|
|
|
|
_varyingBuffer->UpdateData(varyingData, startVertex, numVerts);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Refine() {
|
2013-06-27 19:57:21 +00:00
|
|
|
_computeController->Refine(_computeContext, _farMesh->GetKernelBatches(), _vertexBuffer, _varyingBuffer);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
virtual void Synchronize() {
|
|
|
|
_computeController->Synchronize();
|
|
|
|
}
|
|
|
|
virtual VertexBufferBinding BindVertexBuffer() {
|
|
|
|
return VertexBufferBinding(0);
|
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() {
|
|
|
|
return VertexBufferBinding(0);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual DrawContext * GetDrawContext() {
|
|
|
|
return _drawContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-08-08 20:11:16 +00:00
|
|
|
|
|
|
|
void _initialize( int numVertexElements,
|
|
|
|
int numVaryingElements,
|
|
|
|
int level,
|
|
|
|
OsdMeshBitset bits)
|
|
|
|
{
|
|
|
|
int numVertices = _farMesh->GetNumVertices();
|
|
|
|
if (numVertexElements)
|
|
|
|
_vertexBuffer = VertexBuffer::Create(numVertexElements, numVertices);
|
|
|
|
if (numVaryingElements)
|
|
|
|
_varyingBuffer = VertexBuffer::Create(numVaryingElements, numVertices);
|
|
|
|
_computeContext = ComputeContext::Create(_farMesh);
|
|
|
|
_drawContext = DrawContext::Create(_farMesh->GetPatchTables(), bits.test(MeshFVarData));
|
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
FarMesh<OsdVertex> *_farMesh;
|
2012-12-11 01:15:13 +00:00
|
|
|
VertexBuffer *_vertexBuffer;
|
2013-06-27 19:57:21 +00:00
|
|
|
VertexBuffer *_varyingBuffer;
|
2012-12-11 01:15:13 +00:00
|
|
|
ComputeContext *_computeContext;
|
|
|
|
ComputeController *_computeController;
|
|
|
|
DrawContext *_drawContext;
|
2012-06-09 00:06:35 +00:00
|
|
|
};
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
2012-06-09 00:06:35 +00:00
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} // end namespace OpenSubdiv
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif // OSD_MESH_H
|