Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc')
-rw-r--r--intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc637
1 files changed, 315 insertions, 322 deletions
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
index 9a8729ccda4..fa45c0119ec 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
@@ -42,17 +42,17 @@
#include "internal/opensubdiv_util.h"
#include "opensubdiv_topology_refiner_capi.h"
-using OpenSubdiv::Osd::BufferDescriptor;
-using OpenSubdiv::Osd::CpuEvaluator;
-using OpenSubdiv::Osd::CpuPatchTable;
-using OpenSubdiv::Osd::CpuVertexBuffer;
-using OpenSubdiv::Osd::PatchCoord;
using OpenSubdiv::Far::PatchMap;
using OpenSubdiv::Far::PatchTable;
using OpenSubdiv::Far::PatchTableFactory;
using OpenSubdiv::Far::StencilTable;
using OpenSubdiv::Far::StencilTableFactory;
using OpenSubdiv::Far::TopologyRefiner;
+using OpenSubdiv::Osd::BufferDescriptor;
+using OpenSubdiv::Osd::CpuEvaluator;
+using OpenSubdiv::Osd::CpuPatchTable;
+using OpenSubdiv::Osd::CpuVertexBuffer;
+using OpenSubdiv::Osd::PatchCoord;
// TODO(sergey): Remove after official requirement bump for OSD version.
#if OPENSUBDIV_VERSION_NUMBER >= 30200
@@ -70,23 +70,27 @@ namespace {
// supported.
class PatchCoordBuffer : public vector<PatchCoord> {
public:
- static PatchCoordBuffer* Create(int size) {
- PatchCoordBuffer* buffer = new PatchCoordBuffer();
+ static PatchCoordBuffer *Create(int size)
+ {
+ PatchCoordBuffer *buffer = new PatchCoordBuffer();
buffer->resize(size);
return buffer;
}
- PatchCoord* BindCpuBuffer() {
- return reinterpret_cast<PatchCoord*>(&(*this)[0]);
+ PatchCoord *BindCpuBuffer()
+ {
+ return reinterpret_cast<PatchCoord *>(&(*this)[0]);
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return size();
}
- void UpdateData(const PatchCoord* patch_coords, int num_patch_coords) {
+ void UpdateData(const PatchCoord *patch_coords, int num_patch_coords)
+ {
memcpy(&(*this)[0],
- reinterpret_cast<const void*>(patch_coords),
+ reinterpret_cast<const void *>(patch_coords),
sizeof(PatchCoord) * num_patch_coords);
}
};
@@ -95,26 +99,31 @@ class PatchCoordBuffer : public vector<PatchCoord> {
// coordinates to the CPU evaluator. Other evaluators are not supported.
class SinglePatchCoordBuffer {
public:
- static SinglePatchCoordBuffer* Create() {
+ static SinglePatchCoordBuffer *Create()
+ {
return new SinglePatchCoordBuffer();
}
- SinglePatchCoordBuffer() {
+ SinglePatchCoordBuffer()
+ {
}
- explicit SinglePatchCoordBuffer(const PatchCoord &patch_coord)
- : patch_coord_(patch_coord) {
+ explicit SinglePatchCoordBuffer(const PatchCoord &patch_coord) : patch_coord_(patch_coord)
+ {
}
- PatchCoord* BindCpuBuffer() {
+ PatchCoord *BindCpuBuffer()
+ {
return &patch_coord_;
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return 1;
}
- void UpdateData(const PatchCoord &patch_coord) {
+ void UpdateData(const PatchCoord &patch_coord)
+ {
patch_coord_ = patch_coord;
}
@@ -126,20 +135,22 @@ class SinglePatchCoordBuffer {
// and better to be allocated in stack rather than in heap.
//
// TODO(sergey): Check if bare arrays could be used by CPU evaluator.
-template <int element_size, int num_vertices>
-class StackAllocatedBuffer {
+template<int element_size, int num_vertices> class StackAllocatedBuffer {
public:
- static PatchCoordBuffer* Create(int /*size*/) {
+ static PatchCoordBuffer *Create(int /*size*/)
+ {
// TODO(sergey): Validate that requested size is smaller than static
// stack memory size.
return new StackAllocatedBuffer<element_size, num_vertices>();
}
- float* BindCpuBuffer() {
+ float *BindCpuBuffer()
+ {
return &data_[0];
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return num_vertices;
}
@@ -148,87 +159,82 @@ class StackAllocatedBuffer {
float data_[element_size * num_vertices];
};
-template <typename EVAL_VERTEX_BUFFER,
- typename STENCIL_TABLE,
- typename PATCH_TABLE,
- typename EVALUATOR,
- typename DEVICE_CONTEXT = void>
+template<typename EVAL_VERTEX_BUFFER,
+ typename STENCIL_TABLE,
+ typename PATCH_TABLE,
+ typename EVALUATOR,
+ typename DEVICE_CONTEXT = void>
class FaceVaryingVolatileEval {
public:
typedef OpenSubdiv::Osd::EvaluatorCacheT<EVALUATOR> EvaluatorCache;
FaceVaryingVolatileEval(int face_varying_channel,
- const StencilTable* face_varying_stencils,
+ const StencilTable *face_varying_stencils,
int face_varying_width,
- PATCH_TABLE* patch_table,
- EvaluatorCache* evaluator_cache = NULL,
- DEVICE_CONTEXT* device_context = NULL)
+ PATCH_TABLE *patch_table,
+ EvaluatorCache *evaluator_cache = NULL,
+ DEVICE_CONTEXT *device_context = NULL)
: face_varying_channel_(face_varying_channel),
src_face_varying_desc_(0, face_varying_width, face_varying_width),
patch_table_(patch_table),
evaluator_cache_(evaluator_cache),
- device_context_(device_context) {
+ device_context_(device_context)
+ {
using OpenSubdiv::Osd::convertToCompatibleStencilTable;
- num_coarse_face_varying_vertices_ =
- face_varying_stencils->GetNumControlVertices();
- const int num_total_face_varying_vertices =
- face_varying_stencils->GetNumControlVertices() +
- face_varying_stencils->GetNumStencils();
- src_face_varying_data_ =
- EVAL_VERTEX_BUFFER::Create(2,
- num_total_face_varying_vertices,
- device_context);
- face_varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- face_varying_stencils, device_context_);
- }
-
- ~FaceVaryingVolatileEval() {
+ num_coarse_face_varying_vertices_ = face_varying_stencils->GetNumControlVertices();
+ const int num_total_face_varying_vertices = face_varying_stencils->GetNumControlVertices() +
+ face_varying_stencils->GetNumStencils();
+ src_face_varying_data_ = EVAL_VERTEX_BUFFER::Create(
+ 2, num_total_face_varying_vertices, device_context);
+ face_varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(face_varying_stencils,
+ device_context_);
+ }
+
+ ~FaceVaryingVolatileEval()
+ {
delete src_face_varying_data_;
delete face_varying_stencils_;
}
- void updateData(const float* src, int start_vertex, int num_vertices) {
- src_face_varying_data_->UpdateData(src,
- start_vertex,
- num_vertices,
- device_context_);
+ void updateData(const float *src, int start_vertex, int num_vertices)
+ {
+ src_face_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
- void refine() {
+ void refine()
+ {
BufferDescriptor dst_face_varying_desc = src_face_varying_desc_;
dst_face_varying_desc.offset += num_coarse_face_varying_vertices_ *
src_face_varying_desc_.stride;
- const EVALUATOR* eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
- evaluator_cache_,
- src_face_varying_desc_,
- dst_face_varying_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_face_varying_data_, src_face_varying_desc_,
- src_face_varying_data_, dst_face_varying_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_face_varying_desc_, dst_face_varying_desc, device_context_);
+ EVALUATOR::EvalStencils(src_face_varying_data_,
+ src_face_varying_desc_,
+ src_face_varying_data_,
+ dst_face_varying_desc,
face_varying_stencils_,
eval_instance,
device_context_);
}
- void evalPatch(const PatchCoord& patch_coord, float face_varying[2]) {
+ void evalPatch(const PatchCoord &patch_coord, float face_varying[2])
+ {
StackAllocatedBuffer<2, 1> face_varying_data;
BufferDescriptor face_varying_desc(0, 2, 2);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_face_varying_desc_,
- face_varying_desc,
- device_context_);
- EVALUATOR::EvalPatchesFaceVarying(
- src_face_varying_data_, src_face_varying_desc_,
- &face_varying_data, face_varying_desc,
- patch_coord_buffer.GetNumVertices(),
- &patch_coord_buffer,
- patch_table_,
- face_varying_channel_,
- eval_instance,
- device_context_);
- const float* refined_face_varying = face_varying_data.BindCpuBuffer();
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_face_varying_desc_, face_varying_desc, device_context_);
+ EVALUATOR::EvalPatchesFaceVarying(src_face_varying_data_,
+ src_face_varying_desc_,
+ &face_varying_data,
+ face_varying_desc,
+ patch_coord_buffer.GetNumVertices(),
+ &patch_coord_buffer,
+ patch_table_,
+ face_varying_channel_,
+ eval_instance,
+ device_context_);
+ const float *refined_face_varying = face_varying_data.BindCpuBuffer();
memcpy(face_varying, refined_face_varying, sizeof(float) * 2);
}
@@ -238,14 +244,14 @@ class FaceVaryingVolatileEval {
BufferDescriptor src_face_varying_desc_;
int num_coarse_face_varying_vertices_;
- EVAL_VERTEX_BUFFER* src_face_varying_data_;
- const STENCIL_TABLE* face_varying_stencils_;
+ EVAL_VERTEX_BUFFER *src_face_varying_data_;
+ const STENCIL_TABLE *face_varying_stencils_;
// NOTE: We reference this, do not own it.
- PATCH_TABLE* patch_table_;
+ PATCH_TABLE *patch_table_;
- EvaluatorCache* evaluator_cache_;
- DEVICE_CONTEXT* device_context_;
+ EvaluatorCache *evaluator_cache_;
+ DEVICE_CONTEXT *device_context_;
};
// Volatile evaluator which can be used from threads.
@@ -254,12 +260,12 @@ class FaceVaryingVolatileEval {
// TODO(sergey): Make it possible to evaluate multiple face varying layers.
// (or maybe, it's cheap to create new evaluator for existing
// topology to evaluate all needed face varying layers?)
-template <typename SRC_VERTEX_BUFFER,
- typename EVAL_VERTEX_BUFFER,
- typename STENCIL_TABLE,
- typename PATCH_TABLE,
- typename EVALUATOR,
- typename DEVICE_CONTEXT = void>
+template<typename SRC_VERTEX_BUFFER,
+ typename EVAL_VERTEX_BUFFER,
+ typename STENCIL_TABLE,
+ typename PATCH_TABLE,
+ typename EVALUATOR,
+ typename DEVICE_CONTEXT = void>
class VolatileEvalOutput {
public:
typedef OpenSubdiv::Osd::EvaluatorCacheT<EVALUATOR> EvaluatorCache;
@@ -267,146 +273,141 @@ class VolatileEvalOutput {
STENCIL_TABLE,
PATCH_TABLE,
EVALUATOR,
- DEVICE_CONTEXT> FaceVaryingEval;
-
- VolatileEvalOutput(
- const StencilTable* vertex_stencils,
- const StencilTable* varying_stencils,
- const vector<const StencilTable*>& all_face_varying_stencils,
- const int face_varying_width,
- const PatchTable* patch_table,
- EvaluatorCache* evaluator_cache = NULL,
- DEVICE_CONTEXT* device_context = NULL)
+ DEVICE_CONTEXT>
+ FaceVaryingEval;
+
+ VolatileEvalOutput(const StencilTable *vertex_stencils,
+ const StencilTable *varying_stencils,
+ const vector<const StencilTable *> &all_face_varying_stencils,
+ const int face_varying_width,
+ const PatchTable *patch_table,
+ EvaluatorCache *evaluator_cache = NULL,
+ DEVICE_CONTEXT *device_context = NULL)
: src_desc_(0, 3, 3),
src_varying_desc_(0, 3, 3),
face_varying_width_(face_varying_width),
evaluator_cache_(evaluator_cache),
- device_context_(device_context) {
+ device_context_(device_context)
+ {
// Total number of vertices = coarse points + refined points + local points.
int num_total_vertices = vertex_stencils->GetNumControlVertices() +
vertex_stencils->GetNumStencils();
num_coarse_vertices_ = vertex_stencils->GetNumControlVertices();
using OpenSubdiv::Osd::convertToCompatibleStencilTable;
- src_data_ =
- SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
- src_varying_data_ =
- SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
+ src_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
+ src_varying_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
patch_table_ = PATCH_TABLE::Create(patch_table, device_context_);
patch_coords_ = NULL;
- vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- vertex_stencils, device_context_);
- varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- varying_stencils, device_context_);
+ vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(vertex_stencils,
+ device_context_);
+ varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(varying_stencils,
+ device_context_);
// Create evaluators for every face varying channel.
face_varying_evaluators.reserve(all_face_varying_stencils.size());
int face_varying_channel = 0;
- foreach (const StencilTable* face_varying_stencils,
- all_face_varying_stencils) {
- face_varying_evaluators.push_back(
- new FaceVaryingEval(face_varying_channel,
- face_varying_stencils,
- face_varying_width,
- patch_table_,
- evaluator_cache_,
- device_context_));
+ foreach (const StencilTable *face_varying_stencils, all_face_varying_stencils) {
+ face_varying_evaluators.push_back(new FaceVaryingEval(face_varying_channel,
+ face_varying_stencils,
+ face_varying_width,
+ patch_table_,
+ evaluator_cache_,
+ device_context_));
++face_varying_channel;
}
}
- ~VolatileEvalOutput() {
+ ~VolatileEvalOutput()
+ {
delete src_data_;
delete src_varying_data_;
delete patch_table_;
delete vertex_stencils_;
delete varying_stencils_;
- foreach (FaceVaryingEval* face_varying_evaluator, face_varying_evaluators) {
+ foreach (FaceVaryingEval *face_varying_evaluator, face_varying_evaluators) {
delete face_varying_evaluator;
}
}
// TODO(sergey): Implement binding API.
- void updateData(const float* src, int start_vertex, int num_vertices) {
+ void updateData(const float *src, int start_vertex, int num_vertices)
+ {
src_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
- void updateVaryingData(const float* src, int start_vertex, int num_vertices) {
- src_varying_data_->UpdateData(src,
- start_vertex,
- num_vertices,
- device_context_);
+ void updateVaryingData(const float *src, int start_vertex, int num_vertices)
+ {
+ src_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
void updateFaceVaryingData(const int face_varying_channel,
- const float* src,
+ const float *src,
int start_vertex,
- int num_vertices) {
+ int num_vertices)
+ {
assert(face_varying_channel >= 0);
assert(face_varying_channel < face_varying_evaluators.size());
- face_varying_evaluators[face_varying_channel]->updateData(
- src, start_vertex, num_vertices);
+ face_varying_evaluators[face_varying_channel]->updateData(src, start_vertex, num_vertices);
}
- bool hasVaryingData() const {
+ bool hasVaryingData() const
+ {
// return varying_stencils_ != NULL;
// TODO(sergey): Check this based on actual topology.
return false;
}
- bool hasFaceVaryingData() const {
+ bool hasFaceVaryingData() const
+ {
return face_varying_evaluators.size() != 0;
}
- void refine() {
+ void refine()
+ {
// Evaluate vertex positions.
BufferDescriptor dst_desc = src_desc_;
dst_desc.offset += num_coarse_vertices_ * src_desc_.stride;
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- dst_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_data_, src_desc_,
- src_data_, dst_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, dst_desc, device_context_);
+ EVALUATOR::EvalStencils(src_data_,
+ src_desc_,
+ src_data_,
+ dst_desc,
vertex_stencils_,
eval_instance,
device_context_);
// Evaluate varying data.
if (hasVaryingData()) {
BufferDescriptor dst_varying_desc = src_varying_desc_;
- dst_varying_desc.offset +=
- num_coarse_vertices_ * src_varying_desc_.stride;
+ dst_varying_desc.offset += num_coarse_vertices_ * src_varying_desc_.stride;
eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
- evaluator_cache_,
- src_varying_desc_,
- dst_varying_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_varying_data_, src_varying_desc_,
- src_varying_data_, dst_varying_desc,
+ evaluator_cache_, src_varying_desc_, dst_varying_desc, device_context_);
+ EVALUATOR::EvalStencils(src_varying_data_,
+ src_varying_desc_,
+ src_varying_data_,
+ dst_varying_desc,
varying_stencils_,
- eval_instance, device_context_);
+ eval_instance,
+ device_context_);
}
// Evaluate face-varying data.
if (hasFaceVaryingData()) {
- foreach (FaceVaryingEval* face_varying_evaluator,
- face_varying_evaluators) {
+ foreach (FaceVaryingEval *face_varying_evaluator, face_varying_evaluators) {
face_varying_evaluator->refine();
}
}
}
- void evalPatchCoord(const PatchCoord& patch_coord, float P[3]) {
+ void evalPatchCoord(const PatchCoord &patch_coord, float P[3])
+ {
StackAllocatedBuffer<6, 1> vertex_data;
// TODO(sergey): Varying data is interleaved in vertex array, so need to
// adjust stride if there is a varying data.
// BufferDescriptor vertex_desc(0, 3, 6);
BufferDescriptor vertex_desc(0, 3, 3);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- vertex_desc,
- device_context_);
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, vertex_desc, device_context_);
EVALUATOR::EvalPatches(src_data_,
src_desc_,
&vertex_data,
@@ -416,13 +417,15 @@ class VolatileEvalOutput {
patch_table_,
eval_instance,
device_context_);
- const float* refined_vertices = vertex_data.BindCpuBuffer();
+ const float *refined_vertices = vertex_data.BindCpuBuffer();
memcpy(P, refined_vertices, sizeof(float) * 3);
}
- void evalPatchesWithDerivatives(const PatchCoord& patch_coord,
+ void evalPatchesWithDerivatives(const PatchCoord &patch_coord,
float P[3],
- float dPdu[3], float dPdv[3]) {
+ float dPdu[3],
+ float dPdv[3])
+ {
StackAllocatedBuffer<6, 1> vertex_data, derivatives;
// TODO(sergey): Varying data is interleaved in vertex array, so need to
// adjust stride if there is a varying data.
@@ -430,25 +433,25 @@ class VolatileEvalOutput {
BufferDescriptor vertex_desc(0, 3, 3);
BufferDescriptor du_desc(0, 3, 6), dv_desc(3, 3, 6);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- vertex_desc,
- du_desc, dv_desc,
- device_context_);
- EVALUATOR::EvalPatches(src_data_, src_desc_,
- &vertex_data, vertex_desc,
- &derivatives, du_desc,
- &derivatives, dv_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, vertex_desc, du_desc, dv_desc, device_context_);
+ EVALUATOR::EvalPatches(src_data_,
+ src_desc_,
+ &vertex_data,
+ vertex_desc,
+ &derivatives,
+ du_desc,
+ &derivatives,
+ dv_desc,
patch_coord_buffer.GetNumVertices(),
&patch_coord_buffer,
patch_table_,
eval_instance,
device_context_);
- const float* refined_vertices = vertex_data.BindCpuBuffer();
+ const float *refined_vertices = vertex_data.BindCpuBuffer();
memcpy(P, refined_vertices, sizeof(float) * 3);
if (dPdu != NULL || dPdv != NULL) {
- const float* refined_derivatives = derivatives.BindCpuBuffer();
+ const float *refined_derivatives = derivatives.BindCpuBuffer();
if (dPdu != NULL) {
memcpy(dPdu, refined_derivatives, sizeof(float) * 3);
}
@@ -458,53 +461,53 @@ class VolatileEvalOutput {
}
}
- void evalPatchVarying(const PatchCoord& patch_coord, float varying[3]) {
+ void evalPatchVarying(const PatchCoord &patch_coord, float varying[3])
+ {
StackAllocatedBuffer<6, 1> varying_data;
BufferDescriptor varying_desc(3, 3, 6);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_varying_desc_,
- varying_desc,
- device_context_);
- EVALUATOR::EvalPatchesVarying(src_varying_data_, src_varying_desc_,
- &varying_data, varying_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_varying_desc_, varying_desc, device_context_);
+ EVALUATOR::EvalPatchesVarying(src_varying_data_,
+ src_varying_desc_,
+ &varying_data,
+ varying_desc,
patch_coord_buffer.GetNumVertices(),
&patch_coord_buffer,
patch_table_,
eval_instance,
device_context_);
- const float* refined_varying = varying_data.BindCpuBuffer();
+ const float *refined_varying = varying_data.BindCpuBuffer();
memcpy(varying, refined_varying, sizeof(float) * 3);
}
void evalPatchFaceVarying(const int face_varying_channel,
- const PatchCoord& patch_coord,
- float face_varying[2]) {
+ const PatchCoord &patch_coord,
+ float face_varying[2])
+ {
assert(face_varying_channel >= 0);
assert(face_varying_channel < face_varying_evaluators.size());
- face_varying_evaluators[face_varying_channel]->evalPatch(
- patch_coord, face_varying);
+ face_varying_evaluators[face_varying_channel]->evalPatch(patch_coord, face_varying);
}
private:
- SRC_VERTEX_BUFFER* src_data_;
- SRC_VERTEX_BUFFER* src_varying_data_;
- PatchCoordBuffer* patch_coords_;
- PATCH_TABLE* patch_table_;
+ SRC_VERTEX_BUFFER *src_data_;
+ SRC_VERTEX_BUFFER *src_varying_data_;
+ PatchCoordBuffer *patch_coords_;
+ PATCH_TABLE *patch_table_;
BufferDescriptor src_desc_;
BufferDescriptor src_varying_desc_;
int num_coarse_vertices_;
- const STENCIL_TABLE* vertex_stencils_;
- const STENCIL_TABLE* varying_stencils_;
+ const STENCIL_TABLE *vertex_stencils_;
+ const STENCIL_TABLE *varying_stencils_;
int face_varying_width_;
- vector<FaceVaryingEval*> face_varying_evaluators;
+ vector<FaceVaryingEval *> face_varying_evaluators;
- EvaluatorCache* evaluator_cache_;
- DEVICE_CONTEXT* device_context_;
+ EvaluatorCache *evaluator_cache_;
+ DEVICE_CONTEXT *device_context_;
};
} // namespace
@@ -517,12 +520,12 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
CpuPatchTable,
CpuEvaluator> {
public:
- CpuEvalOutput(const StencilTable* vertex_stencils,
- const StencilTable* varying_stencils,
- const vector<const StencilTable*>& all_face_varying_stencils,
+ CpuEvalOutput(const StencilTable *vertex_stencils,
+ const StencilTable *varying_stencils,
+ const vector<const StencilTable *> &all_face_varying_stencils,
const int face_varying_width,
- const PatchTable* patch_table,
- EvaluatorCache* evaluator_cache = NULL)
+ const PatchTable *patch_table,
+ EvaluatorCache *evaluator_cache = NULL)
: VolatileEvalOutput<CpuVertexBuffer,
CpuVertexBuffer,
StencilTable,
@@ -532,171 +535,179 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
all_face_varying_stencils,
face_varying_width,
patch_table,
- evaluator_cache) {
+ evaluator_cache)
+ {
}
};
////////////////////////////////////////////////////////////////////////////////
// Evaluator wrapper for anonymous API.
-CpuEvalOutputAPI::CpuEvalOutputAPI(CpuEvalOutput* implementation,
- OpenSubdiv::Far::PatchMap* patch_map)
- : implementation_(implementation),
- patch_map_(patch_map) {
+CpuEvalOutputAPI::CpuEvalOutputAPI(CpuEvalOutput *implementation,
+ OpenSubdiv::Far::PatchMap *patch_map)
+ : implementation_(implementation), patch_map_(patch_map)
+{
}
-CpuEvalOutputAPI::~CpuEvalOutputAPI() {
+CpuEvalOutputAPI::~CpuEvalOutputAPI()
+{
delete implementation_;
}
-void CpuEvalOutputAPI::setCoarsePositions(const float* positions,
+void CpuEvalOutputAPI::setCoarsePositions(const float *positions,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
implementation_->updateData(positions, start_vertex_index, num_vertices);
}
-void CpuEvalOutputAPI::setVaryingData(const float* varying_data,
+void CpuEvalOutputAPI::setVaryingData(const float *varying_data,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- implementation_->updateVaryingData(varying_data,
- start_vertex_index,
- num_vertices);
+ implementation_->updateVaryingData(varying_data, start_vertex_index, num_vertices);
}
void CpuEvalOutputAPI::setFaceVaryingData(const int face_varying_channel,
- const float* face_varying_data,
+ const float *face_varying_data,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- implementation_->updateFaceVaryingData(face_varying_channel,
- face_varying_data,
- start_vertex_index,
- num_vertices);
+ implementation_->updateFaceVaryingData(
+ face_varying_channel, face_varying_data, start_vertex_index, num_vertices);
}
-void CpuEvalOutputAPI::setCoarsePositionsFromBuffer(
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setCoarsePositionsFromBuffer(const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
- implementation_->updateData(reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ implementation_->updateData(
+ reinterpret_cast<const float *>(current_buffer), current_vertex_index, 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::setVaryingDataFromBuffer(
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setVaryingDataFromBuffer(const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
implementation_->updateVaryingData(
- reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ reinterpret_cast<const float *>(current_buffer), current_vertex_index, 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::setFaceVaryingDataFromBuffer(
- const int face_varying_channel,
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setFaceVaryingDataFromBuffer(const int face_varying_channel,
+ const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
- implementation_->updateFaceVaryingData(
- face_varying_channel,
- reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ implementation_->updateFaceVaryingData(face_varying_channel,
+ reinterpret_cast<const float *>(current_buffer),
+ current_vertex_index,
+ 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::refine() {
+void CpuEvalOutputAPI::refine()
+{
implementation_->refine();
}
void CpuEvalOutputAPI::evaluateLimit(const int ptex_face_index,
- float face_u, float face_v,
- float P[3], float dPdu[3], float dPdv[3]) {
+ float face_u,
+ float face_v,
+ float P[3],
+ float dPdu[3],
+ float dPdv[3])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
if (dPdu != NULL || dPdv != NULL) {
implementation_->evalPatchesWithDerivatives(patch_coord, P, dPdu, dPdv);
- } else {
+ }
+ else {
implementation_->evalPatchCoord(patch_coord, P);
- }}
+ }
+}
void CpuEvalOutputAPI::evaluateVarying(const int ptex_face_index,
- float face_u, float face_v,
- float varying[3]) {
+ float face_u,
+ float face_v,
+ float varying[3])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
implementation_->evalPatchVarying(patch_coord, varying);
}
void CpuEvalOutputAPI::evaluateFaceVarying(const int face_varying_channel,
const int ptex_face_index,
- float face_u, float face_v,
- float face_varying[2]) {
+ float face_u,
+ float face_v,
+ float face_varying[2])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
- implementation_->evalPatchFaceVarying(
- face_varying_channel, patch_coord, face_varying);
+ implementation_->evalPatchFaceVarying(face_varying_channel, patch_coord, face_varying);
}
} // namespace opensubdiv_capi
OpenSubdiv_EvaluatorInternal::OpenSubdiv_EvaluatorInternal()
- : eval_output(NULL),
- patch_map(NULL),
- patch_table(NULL) {
+ : eval_output(NULL), patch_map(NULL), patch_table(NULL)
+{
}
-OpenSubdiv_EvaluatorInternal::~OpenSubdiv_EvaluatorInternal() {
+OpenSubdiv_EvaluatorInternal::~OpenSubdiv_EvaluatorInternal()
+{
delete eval_output;
delete patch_map;
delete patch_table;
}
-OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
- OpenSubdiv_TopologyRefiner* topology_refiner) {
+OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
+ OpenSubdiv_TopologyRefiner *topology_refiner)
+{
using opensubdiv_capi::vector;
- TopologyRefiner* refiner = topology_refiner->internal->osd_topology_refiner;
+ TopologyRefiner *refiner = topology_refiner->internal->osd_topology_refiner;
if (refiner == NULL) {
// Happens on bad topology.
return NULL;
@@ -718,7 +729,8 @@ OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
options.considerFVarChannels = has_face_varying_data;
options.useInfSharpPatch = use_inf_sharp_patch;
refiner->RefineAdaptive(options);
- } else {
+ }
+ else {
TopologyRefiner::UniformOptions options(level);
refiner->RefineUniform(options);
}
@@ -728,38 +740,31 @@ OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
// Vertex stencils.
StencilTableFactory::Options vertex_stencil_options;
vertex_stencil_options.generateOffsets = stencil_generate_offsets;
- vertex_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- const StencilTable* vertex_stencils =
- StencilTableFactory::Create(*refiner, vertex_stencil_options);
+ vertex_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ const StencilTable *vertex_stencils = StencilTableFactory::Create(*refiner,
+ vertex_stencil_options);
// Varying stencils.
//
// TODO(sergey): Seems currently varying stencils are always required in
// OpenSubdiv itself.
- const StencilTable* varying_stencils = NULL;
+ const StencilTable *varying_stencils = NULL;
if (has_varying_data) {
StencilTableFactory::Options varying_stencil_options;
varying_stencil_options.generateOffsets = stencil_generate_offsets;
- varying_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- varying_stencil_options.interpolationMode =
- StencilTableFactory::INTERPOLATE_VARYING;
- varying_stencils =
- StencilTableFactory::Create(*refiner, varying_stencil_options);
+ varying_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ varying_stencil_options.interpolationMode = StencilTableFactory::INTERPOLATE_VARYING;
+ varying_stencils = StencilTableFactory::Create(*refiner, varying_stencil_options);
}
// Face warying stencil.
-vector<const StencilTable*> all_face_varying_stencils;
+ vector<const StencilTable *> all_face_varying_stencils;
#ifdef OPENSUBDIV_HAS_FVAR_EVALUATION
all_face_varying_stencils.reserve(num_face_varying_channels);
- for (int face_varying_channel = 0;
- face_varying_channel < num_face_varying_channels;
+ for (int face_varying_channel = 0; face_varying_channel < num_face_varying_channels;
++face_varying_channel) {
StencilTableFactory::Options face_varying_stencil_options;
face_varying_stencil_options.generateOffsets = stencil_generate_offsets;
- face_varying_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- face_varying_stencil_options.interpolationMode =
- StencilTableFactory::INTERPOLATE_FACE_VARYING;
+ face_varying_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ face_varying_stencil_options.interpolationMode = StencilTableFactory::INTERPOLATE_FACE_VARYING;
face_varying_stencil_options.fvarChannel = face_varying_channel;
all_face_varying_stencils.push_back(
StencilTableFactory::Create(*refiner, face_varying_stencil_options));
@@ -774,42 +779,35 @@ vector<const StencilTable*> all_face_varying_stencils;
patch_options.useInfSharpPatch = use_inf_sharp_patch;
patch_options.generateFVarTables = has_face_varying_data;
patch_options.generateFVarLegacyLinearPatches = false;
- const PatchTable* patch_table = PatchTableFactory::Create(
- *refiner, patch_options);
+ const PatchTable *patch_table = PatchTableFactory::Create(*refiner, patch_options);
// Append local points stencils.
// Point stencils.
- const StencilTable* local_point_stencil_table =
- patch_table->GetLocalPointStencilTable();
+ const StencilTable *local_point_stencil_table = patch_table->GetLocalPointStencilTable();
if (local_point_stencil_table != NULL) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTable(
- *refiner, vertex_stencils, local_point_stencil_table);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTable(
+ *refiner, vertex_stencils, local_point_stencil_table);
delete vertex_stencils;
vertex_stencils = table;
}
// Varying stencils.
if (has_varying_data) {
- const StencilTable* local_point_varying_stencil_table =
+ const StencilTable *local_point_varying_stencil_table =
patch_table->GetLocalPointVaryingStencilTable();
if (local_point_varying_stencil_table != NULL) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTable(
- *refiner, varying_stencils, local_point_varying_stencil_table);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTable(
+ *refiner, varying_stencils, local_point_varying_stencil_table);
delete varying_stencils;
varying_stencils = table;
}
}
#ifdef OPENSUBDIV_HAS_FVAR_EVALUATION
- for (int face_varying_channel = 0;
- face_varying_channel < num_face_varying_channels;
+ for (int face_varying_channel = 0; face_varying_channel < num_face_varying_channels;
++face_varying_channel) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTableFaceVarying(
- *refiner,
- all_face_varying_stencils[face_varying_channel],
- patch_table->GetLocalPointFaceVaryingStencilTable(
- face_varying_channel),
- face_varying_channel);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTableFaceVarying(
+ *refiner,
+ all_face_varying_stencils[face_varying_channel],
+ patch_table->GetLocalPointFaceVaryingStencilTable(face_varying_channel),
+ face_varying_channel);
if (table != NULL) {
delete all_face_varying_stencils[face_varying_channel];
all_face_varying_stencils[face_varying_channel] = table;
@@ -818,30 +816,25 @@ vector<const StencilTable*> all_face_varying_stencils;
#endif
// Create OpenSubdiv's CPU side evaluator.
// TODO(sergey): Make it possible to use different evaluators.
- opensubdiv_capi::CpuEvalOutput* eval_output =
- new opensubdiv_capi::CpuEvalOutput(vertex_stencils,
- varying_stencils,
- all_face_varying_stencils,
- 2,
- patch_table);
- OpenSubdiv::Far::PatchMap* patch_map = new PatchMap(*patch_table);
+ opensubdiv_capi::CpuEvalOutput *eval_output = new opensubdiv_capi::CpuEvalOutput(
+ vertex_stencils, varying_stencils, all_face_varying_stencils, 2, patch_table);
+ OpenSubdiv::Far::PatchMap *patch_map = new PatchMap(*patch_table);
// Wrap everything we need into an object which we control from our side.
- OpenSubdiv_EvaluatorInternal* evaluator_descr;
+ OpenSubdiv_EvaluatorInternal *evaluator_descr;
evaluator_descr = OBJECT_GUARDED_NEW(OpenSubdiv_EvaluatorInternal);
- evaluator_descr->eval_output =
- new opensubdiv_capi::CpuEvalOutputAPI(eval_output, patch_map);
+ evaluator_descr->eval_output = new opensubdiv_capi::CpuEvalOutputAPI(eval_output, patch_map);
evaluator_descr->patch_map = patch_map;
evaluator_descr->patch_table = patch_table;
// TOOD(sergey): Look into whether we've got duplicated stencils arrays.
delete vertex_stencils;
delete varying_stencils;
- foreach (const StencilTable* table, all_face_varying_stencils) {
+ foreach (const StencilTable *table, all_face_varying_stencils) {
delete table;
}
return evaluator_descr;
}
-void openSubdiv_deleteEvaluatorInternal(
- OpenSubdiv_EvaluatorInternal* evaluator) {
+void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator)
+{
OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_EvaluatorInternal);
}