2013-02-08 21:48:51 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2013-02-08 21:48:51 +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:
|
2013-02-08 21:48:51 +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.
|
2013-02-08 21:48:51 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2013-02-08 21:48:51 +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.
|
2013-02-08 21:48:51 +00:00
|
|
|
//
|
|
|
|
|
2013-02-05 05:10:58 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "subdivider.h"
|
|
|
|
#include "topology.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace shim;
|
|
|
|
|
|
|
|
OpenSubdiv::OsdCpuComputeController* g_osdComputeController = 0;
|
|
|
|
|
|
|
|
shim::Subdivider::Subdivider(
|
|
|
|
const Topology& topo,
|
|
|
|
Layout refinedLayout,
|
|
|
|
DataType refinedIndexType,
|
|
|
|
int subdivisionLevels)
|
|
|
|
{
|
|
|
|
self = new SubdividerImpl();
|
|
|
|
|
|
|
|
if (!g_osdComputeController) {
|
|
|
|
g_osdComputeController = new OpenSubdiv::OsdCpuComputeController();
|
|
|
|
}
|
|
|
|
|
2013-02-17 16:24:21 +00:00
|
|
|
int numFloatsPerVertex = 0;
|
2013-02-05 05:10:58 +00:00
|
|
|
Layout::const_iterator it;
|
|
|
|
for (it = refinedLayout.begin(); it != refinedLayout.end(); ++it) {
|
|
|
|
if (*it != float32) {
|
|
|
|
cerr << "Unsupported vertex type." << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++numFloatsPerVertex;
|
|
|
|
}
|
|
|
|
OpenSubdiv::FarMeshFactory<OpenSubdiv::OsdVertex> meshFactory(
|
|
|
|
topo.self->hmesh,
|
|
|
|
subdivisionLevels);
|
|
|
|
self->farMesh = meshFactory.Create();
|
|
|
|
self->computeContext = OpenSubdiv::OsdCpuComputeContext::Create(
|
2014-03-28 19:28:59 +00:00
|
|
|
self->farMesh->GetSubdivisionTables(),
|
|
|
|
self->farMesh->GetVertexEditTables());
|
2013-02-05 05:10:58 +00:00
|
|
|
self->vertexBuffer = OpenSubdiv::OsdCpuVertexBuffer::Create(
|
|
|
|
numFloatsPerVertex, self->farMesh->GetNumVertices());
|
|
|
|
}
|
|
|
|
|
|
|
|
shim::Subdivider::~Subdivider()
|
|
|
|
{
|
|
|
|
delete self->computeContext;
|
|
|
|
delete self->farMesh;
|
|
|
|
delete self->vertexBuffer;
|
|
|
|
delete self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shim::Subdivider::setCoarseVertices(const HeterogeneousBuffer& cage)
|
|
|
|
{
|
|
|
|
float* pFloats = (float*) &cage.Buffer[0];
|
|
|
|
int numFloats = cage.Buffer.size() / sizeof(float);
|
2013-03-18 21:09:46 +00:00
|
|
|
self->vertexBuffer->UpdateData(pFloats, /*start vertex*/ 0, numFloats);
|
2013-02-05 05:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shim::Subdivider::refine()
|
|
|
|
{
|
2013-03-08 01:50:15 +00:00
|
|
|
g_osdComputeController->Refine(self->computeContext,
|
2013-03-18 21:09:46 +00:00
|
|
|
self->farMesh->GetKernelBatches(),
|
2013-03-08 01:50:15 +00:00
|
|
|
self->vertexBuffer);
|
2013-02-05 05:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shim::Subdivider::getRefinedVertices(Buffer* refinedVertices)
|
|
|
|
{
|
|
|
|
float* pFloats = self->vertexBuffer->BindCpuBuffer();
|
|
|
|
|
|
|
|
int numFloats = self->vertexBuffer->GetNumElements() *
|
|
|
|
self->vertexBuffer->GetNumVertices();
|
|
|
|
|
|
|
|
unsigned char* srcBegin = (unsigned char*) pFloats;
|
|
|
|
unsigned char* srcEnd = srcBegin + numFloats * 4;
|
|
|
|
refinedVertices->assign(srcBegin, srcEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shim::Subdivider::getRefinedQuads(Buffer* refinedQuads)
|
|
|
|
{
|
|
|
|
OpenSubdiv::FarPatchTables const * patchTables =
|
|
|
|
self->farMesh->GetPatchTables();
|
|
|
|
|
|
|
|
if (patchTables) {
|
|
|
|
cerr << "Feature adaptive not supported" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-19 18:44:51 +00:00
|
|
|
const OpenSubdiv::FarSubdivisionTables *tables =
|
2013-02-05 05:10:58 +00:00
|
|
|
self->farMesh->GetSubdivisionTables();
|
|
|
|
|
2014-03-20 00:19:08 +00:00
|
|
|
bool loop = (tables->GetScheme() == OpenSubdiv::FarSubdivisionTables::LOOP);
|
2013-02-05 05:10:58 +00:00
|
|
|
|
|
|
|
if (loop) {
|
|
|
|
cerr << "loop subdivision not supported" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int level = tables->GetMaxLevel();
|
2013-05-16 00:53:40 +00:00
|
|
|
unsigned int const * indices = self->farMesh->GetPatchTables()->GetFaceVertices(level-1);
|
|
|
|
int numInts = self->farMesh->GetPatchTables()->GetNumFaces(level-1)*4;
|
2013-02-05 05:10:58 +00:00
|
|
|
|
2013-05-16 00:53:40 +00:00
|
|
|
unsigned char const * srcBegin = reinterpret_cast<unsigned char const *>(indices);
|
|
|
|
unsigned char const * srcEnd = srcBegin + numInts * 4;
|
2013-02-05 05:10:58 +00:00
|
|
|
refinedQuads->assign(srcBegin, srcEnd);
|
|
|
|
}
|