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_GL_MESH_H
|
|
|
|
#define OSD_GL_MESH_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "../osd/mesh.h"
|
|
|
|
#include "../osd/glDrawContext.h"
|
2014-05-09 00:20:54 +00:00
|
|
|
#include "../osd/vertexDescriptor.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <OpenCL/opencl.h>
|
|
|
|
#else
|
|
|
|
#include <CL/opencl.h>
|
|
|
|
#endif
|
|
|
|
#include "../osd/clComputeController.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
typedef OsdMeshInterface<OsdGLDrawContext> OsdGLMeshInterface;
|
|
|
|
|
|
|
|
template <class VERTEX_BUFFER, class COMPUTE_CONTROLLER>
|
|
|
|
class OsdMesh<VERTEX_BUFFER, COMPUTE_CONTROLLER, OsdGLDrawContext> : public OsdGLMeshInterface {
|
|
|
|
public:
|
|
|
|
typedef VERTEX_BUFFER VertexBuffer;
|
|
|
|
typedef COMPUTE_CONTROLLER ComputeController;
|
|
|
|
typedef typename ComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef OsdGLDrawContext 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) :
|
|
|
|
|
|
|
|
_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));
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-04-17 23:47:48 +00:00
|
|
|
_initialize(numVertexElements, numVaryingElements, bits);
|
2013-08-08 20:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
FarMesh<OsdVertex> * fmesh,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
|
|
|
OsdMeshBitset bits) :
|
|
|
|
|
|
|
|
_farMesh(fmesh),
|
|
|
|
_vertexBuffer(0),
|
|
|
|
_varyingBuffer(0),
|
|
|
|
_computeContext(0),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(0)
|
|
|
|
{
|
2014-04-17 23:47:48 +00:00
|
|
|
_initialize(numVertexElements, numVaryingElements, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 00:19:08 +00:00
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
FarMesh<OsdVertex> * fmesh,
|
|
|
|
VertexBuffer * vertexBuffer,
|
|
|
|
VertexBuffer * varyingBuffer,
|
|
|
|
ComputeContext * computeContext,
|
|
|
|
DrawContext * drawContext) :
|
|
|
|
|
|
|
|
_farMesh(fmesh),
|
|
|
|
_vertexBuffer(vertexBuffer),
|
|
|
|
_varyingBuffer(varyingBuffer),
|
|
|
|
_computeContext(computeContext),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(drawContext)
|
|
|
|
{
|
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
virtual void Refine(OsdVertexBufferDescriptor const *vertexDesc,
|
|
|
|
OsdVertexBufferDescriptor const *varyingDesc,
|
|
|
|
bool interleaved) {
|
|
|
|
_computeController->Refine(_computeContext, _farMesh->GetKernelBatches(),
|
|
|
|
_vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
|
|
|
|
vertexDesc, varyingDesc);
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Synchronize() {
|
|
|
|
_computeController->Synchronize();
|
|
|
|
}
|
|
|
|
virtual VertexBufferBinding BindVertexBuffer() {
|
|
|
|
return _vertexBuffer->BindVBO();
|
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() {
|
|
|
|
return _varyingBuffer->BindVBO();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual DrawContext * GetDrawContext() {
|
|
|
|
return _drawContext;
|
|
|
|
}
|
2013-06-19 19:55:12 +00:00
|
|
|
virtual VertexBuffer * GetVertexBuffer() {
|
|
|
|
return _vertexBuffer;
|
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBuffer * GetVaryingBuffer() {
|
|
|
|
return _varyingBuffer;
|
|
|
|
}
|
2013-06-19 19:55:12 +00:00
|
|
|
virtual FarMesh<OsdVertex> const * GetFarMesh() const {
|
|
|
|
return _farMesh;
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
private:
|
2013-08-08 20:11:16 +00:00
|
|
|
|
|
|
|
void _initialize( int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2014-04-17 23:47:48 +00:00
|
|
|
OsdMeshBitset bits)
|
2013-08-08 20:11:16 +00:00
|
|
|
{
|
|
|
|
int numVertices = _farMesh->GetNumVertices();
|
|
|
|
if (numVertexElements)
|
|
|
|
_vertexBuffer = VertexBuffer::Create(numVertexElements, numVertices);
|
|
|
|
if (numVaryingElements)
|
|
|
|
_varyingBuffer = VertexBuffer::Create(numVaryingElements, numVertices);
|
2014-03-28 19:10:13 +00:00
|
|
|
_computeContext = ComputeContext::Create(_farMesh->GetSubdivisionTables(), _farMesh->GetVertexEditTables());
|
2014-04-17 23:47:48 +00:00
|
|
|
_drawContext = DrawContext::Create(_farMesh->GetPatchTables(), numVertexElements, bits.test(MeshFVarData));
|
2013-08-08 20:11:16 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
FarMesh<OsdVertex> *_farMesh;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
|
|
|
|
|
|
|
template <class VERTEX_BUFFER>
|
|
|
|
class OsdMesh<VERTEX_BUFFER, OsdCLComputeController, OsdGLDrawContext> : public OsdGLMeshInterface {
|
|
|
|
public:
|
|
|
|
typedef VERTEX_BUFFER VertexBuffer;
|
|
|
|
typedef OsdCLComputeController ComputeController;
|
|
|
|
typedef typename ComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef OsdGLDrawContext 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,
|
|
|
|
cl_context clContext,
|
|
|
|
cl_command_queue clQueue) :
|
|
|
|
|
|
|
|
_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),
|
|
|
|
_clContext(clContext),
|
|
|
|
_clQueue(clQueue)
|
|
|
|
{
|
|
|
|
FarMeshFactory<OsdVertex> meshFactory(hmesh, level, bits.test(MeshAdaptive));
|
2013-05-09 16:23:01 +00:00
|
|
|
_farMesh = meshFactory.Create(bits.test(MeshFVarData));
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-04-17 23:47:48 +00:00
|
|
|
_initialize(numVertexElements, numVaryingElements, bits);
|
2013-08-08 20:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
FarMesh<OsdVertex> * fmesh,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
|
|
|
OsdMeshBitset bits,
|
|
|
|
cl_context clContext,
|
|
|
|
cl_command_queue clQueue) :
|
|
|
|
|
|
|
|
_farMesh(fmesh),
|
|
|
|
_vertexBuffer(0),
|
|
|
|
_varyingBuffer(0),
|
|
|
|
_computeContext(0),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(0),
|
|
|
|
_clContext(clContext),
|
|
|
|
_clQueue(clQueue)
|
|
|
|
{
|
2014-04-17 23:47:48 +00:00
|
|
|
_initialize(numVertexElements, numVaryingElements, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 00:19:08 +00:00
|
|
|
OsdMesh(ComputeController * computeController,
|
|
|
|
FarMesh<OsdVertex> * fmesh,
|
|
|
|
VertexBuffer * vertexBuffer,
|
|
|
|
VertexBuffer * varyingBuffer,
|
|
|
|
ComputeContext * computeContext,
|
|
|
|
DrawContext * drawContext,
|
|
|
|
cl_context clContext,
|
|
|
|
cl_command_queue clQueue) :
|
|
|
|
|
|
|
|
_farMesh(fmesh),
|
|
|
|
_vertexBuffer(vertexBuffer),
|
|
|
|
_varyingBuffer(varyingBuffer),
|
|
|
|
_computeContext(computeContext),
|
|
|
|
_computeController(computeController),
|
|
|
|
_drawContext(drawContext),
|
|
|
|
_clContext(clContext),
|
|
|
|
_clQueue(clQueue)
|
|
|
|
{
|
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual ~OsdMesh() {
|
|
|
|
delete _farMesh;
|
|
|
|
delete _vertexBuffer;
|
2014-05-09 00:20:54 +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, _clQueue);
|
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, _clQueue);
|
|
|
|
}
|
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
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
virtual void Refine(OsdVertexBufferDescriptor const *vertexDesc,
|
|
|
|
OsdVertexBufferDescriptor const *varyingDesc,
|
|
|
|
bool interleaved) {
|
|
|
|
|
|
|
|
_computeController->Refine(_computeContext, _farMesh->GetKernelBatches(),
|
|
|
|
_vertexBuffer, (interleaved ? _vertexBuffer : _varyingBuffer),
|
|
|
|
vertexDesc, varyingDesc);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual void Synchronize() {
|
|
|
|
_computeController->Synchronize();
|
|
|
|
}
|
|
|
|
virtual VertexBufferBinding BindVertexBuffer() {
|
|
|
|
return _vertexBuffer->BindVBO();
|
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBufferBinding BindVaryingBuffer() {
|
|
|
|
return _varyingBuffer->BindVBO();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual DrawContext * GetDrawContext() {
|
|
|
|
return _drawContext;
|
|
|
|
}
|
2013-06-19 19:55:12 +00:00
|
|
|
virtual VertexBuffer * GetVertexBuffer() {
|
|
|
|
return _vertexBuffer;
|
|
|
|
}
|
2013-06-27 19:57:21 +00:00
|
|
|
virtual VertexBuffer * GetVaryingBuffer() {
|
|
|
|
return _varyingBuffer;
|
|
|
|
}
|
2013-06-19 19:55:12 +00:00
|
|
|
virtual FarMesh<OsdVertex> const * GetFarMesh() const {
|
|
|
|
return _farMesh;
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
private:
|
2013-08-08 20:11:16 +00:00
|
|
|
|
|
|
|
void _initialize( int numVertexElements,
|
|
|
|
int numVaryingElements,
|
|
|
|
OsdMeshBitset bits)
|
|
|
|
{
|
|
|
|
int numVertices = _farMesh->GetNumVertices();
|
|
|
|
if (numVertexElements)
|
|
|
|
_vertexBuffer = VertexBuffer::Create(numVertexElements, numVertices, _clContext);
|
|
|
|
if (numVaryingElements)
|
|
|
|
_varyingBuffer = VertexBuffer::Create(numVaryingElements, numVertices, _clContext);
|
2014-03-28 19:10:13 +00:00
|
|
|
_computeContext = ComputeContext::Create(_farMesh->GetSubdivisionTables(), _farMesh->GetVertexEditTables(), _clContext);
|
2014-04-17 23:47:48 +00:00
|
|
|
_drawContext = DrawContext::Create(_farMesh->GetPatchTables(), numVertexElements, bits.test(MeshFVarData));
|
2013-08-08 20:11:16 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
FarMesh<OsdVertex> *_farMesh;
|
|
|
|
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;
|
|
|
|
|
|
|
|
cl_context _clContext;
|
|
|
|
cl_command_queue _clQueue;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif // OSD_GL_MESH_H
|