2013-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2013-09-11 23:05:14 +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-09-11 23:05:14 +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-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2013-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-09-11 23:05:14 +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-09-11 23:05:14 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "../osd/cpuEvalStencilsController.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Osd {
|
|
|
|
|
|
|
|
CpuEvalStencilsController::CpuEvalStencilsController() {
|
2013-09-11 23:05:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
CpuEvalStencilsController::~CpuEvalStencilsController() {
|
2013-09-11 23:05:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int
|
|
|
|
CpuEvalStencilsController::_UpdateValues( CpuEvalStencilsContext * context ) {
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
int result=0;
|
|
|
|
|
2014-09-12 23:59:16 +00:00
|
|
|
Far::LimitStencilTables const * stencils = context->GetStencilTables();
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
int nstencils = stencils->GetNumStencils();
|
|
|
|
if (not nstencils)
|
|
|
|
return result;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
VertexBufferDescriptor ctrlDesc = _currentBindState.controlDataDesc,
|
2014-05-10 23:38:13 +00:00
|
|
|
outDesc = _currentBindState.outputDataDesc;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
// make sure that we have control data to work with
|
|
|
|
if (not ctrlDesc.CanEval(outDesc))
|
|
|
|
return 0;
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
float const * ctrl = _currentBindState.controlData + ctrlDesc.offset;
|
2013-09-11 23:05:14 +00:00
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
float * out = _currentBindState.outputData + outDesc.offset;
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
if ((not ctrl) or (not out))
|
|
|
|
return result;
|
|
|
|
|
2014-09-12 23:59:16 +00:00
|
|
|
unsigned char const * sizes = &stencils->GetSizes().at(0);
|
2014-10-09 23:36:23 +00:00
|
|
|
Far::Index const * index = &stencils->GetControlIndices().at(0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
float const * weight = &stencils->GetWeights().at(0);
|
|
|
|
|
|
|
|
for (int i=0; i<nstencils; ++i) {
|
|
|
|
|
|
|
|
memset(out, 0, outDesc.length*sizeof(float));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
for (int j=0; j<sizes[i]; ++j, ++index, ++weight) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
float const * cv = ctrl + (*index)*ctrlDesc.stride;
|
|
|
|
|
|
|
|
for (int k=0; k<outDesc.length; ++k) {
|
|
|
|
out[k] += cv[k] * (*weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out += outDesc.stride;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
return nstencils;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int
|
|
|
|
CpuEvalStencilsController::_UpdateDerivs( CpuEvalStencilsContext * context ) {
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
int result=0;
|
|
|
|
|
2014-09-12 23:59:16 +00:00
|
|
|
Far::LimitStencilTables const * stencils = context->GetStencilTables();
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
int nstencils = stencils->GetNumStencils();
|
|
|
|
if (not nstencils)
|
|
|
|
return result;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
VertexBufferDescriptor ctrlDesc = _currentBindState.controlDataDesc,
|
2014-05-10 23:38:13 +00:00
|
|
|
duDesc = _currentBindState.outputDuDesc,
|
|
|
|
dvDesc = _currentBindState.outputDvDesc;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
// make sure that we have control data to work with
|
|
|
|
if (not (ctrlDesc.CanEval(duDesc) and ctrlDesc.CanEval(dvDesc)))
|
|
|
|
return 0;
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
float const * ctrl = _currentBindState.controlData + ctrlDesc.offset;
|
2013-09-11 23:05:14 +00:00
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
float * du = _currentBindState.outputUDeriv + duDesc.offset,
|
|
|
|
* dv = _currentBindState.outputVDeriv + dvDesc.offset;
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
if ((not ctrl) or (not du) or (not dv))
|
|
|
|
return result;
|
|
|
|
|
2014-09-12 23:59:16 +00:00
|
|
|
unsigned char const * sizes = &stencils->GetSizes().at(0);
|
2014-10-09 23:36:23 +00:00
|
|
|
Far::Index const * index = &stencils->GetControlIndices().at(0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
float const * duweight = &stencils->GetDuWeights().at(0),
|
|
|
|
* dvweight = &stencils->GetDvWeights().at(0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
for (int i=0; i<nstencils; ++i) {
|
|
|
|
|
|
|
|
memset(du, 0, duDesc.length*sizeof(float));
|
|
|
|
memset(dv, 0, dvDesc.length*sizeof(float));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
for (int j=0; j<sizes[i]; ++j, ++index, ++duweight, ++dvweight) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
float const * cv = ctrl + (*index)*ctrlDesc.stride;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
for (int k=0; k<duDesc.length; ++k) {
|
|
|
|
du[k] += cv[k] * (*duweight);
|
|
|
|
dv[k] += cv[k] * (*dvweight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
du += duDesc.stride;
|
|
|
|
dv += dvDesc.stride;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
return nstencils;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
CpuEvalStencilsController::Synchronize() {
|
2013-09-11 23:05:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Osd
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|