Changeset View
Changeset View
Standalone View
Standalone View
intern/opensubdiv/internal/evaluator/evaluator_impl.cc
| Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | |||||
| void EvalOutputAPI::setVaryingData(const float *varying_data, | void EvalOutputAPI::setVaryingData(const float *varying_data, | ||||
| const int start_vertex_index, | const int start_vertex_index, | ||||
| const int num_vertices) | const int num_vertices) | ||||
| { | { | ||||
| // TODO(sergey): Add sanity check on indices. | // 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 EvalOutputAPI::setVertexData(const float *extra_data, | |||||
| const int start_vertex_index, | |||||
| const int num_vertices) | |||||
| { | |||||
| // TODO(sergey): Add sanity check on indices. | |||||
| implementation_->updateVertexData(extra_data, start_vertex_index, num_vertices); | |||||
| } | |||||
| void EvalOutputAPI::setFaceVaryingData(const int face_varying_channel, | void EvalOutputAPI::setFaceVaryingData(const int face_varying_channel, | ||||
| const float *face_varying_data, | const float *face_varying_data, | ||||
| const int start_vertex_index, | const int start_vertex_index, | ||||
| const int num_vertices) | const int num_vertices) | ||||
| { | { | ||||
| // TODO(sergey): Add sanity check on indices. | // TODO(sergey): Add sanity check on indices. | ||||
| implementation_->updateFaceVaryingData( | implementation_->updateFaceVaryingData( | ||||
| face_varying_channel, face_varying_data, start_vertex_index, num_vertices); | face_varying_channel, face_varying_data, start_vertex_index, num_vertices); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | void EvalOutputAPI::evaluateVarying(const int ptex_face_index, | ||||
| assert(face_u <= 1.0f); | assert(face_u <= 1.0f); | ||||
| assert(face_v >= 0.0f); | assert(face_v >= 0.0f); | ||||
| assert(face_v <= 1.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); | PatchCoord patch_coord(*handle, face_u, face_v); | ||||
| implementation_->evalPatchesVarying(&patch_coord, 1, varying); | implementation_->evalPatchesVarying(&patch_coord, 1, varying); | ||||
| } | } | ||||
| void EvalOutputAPI::evaluateVertexData(const int ptex_face_index, | |||||
| float face_u, | |||||
| float face_v, | |||||
| float extra_data[]) | |||||
| { | |||||
| 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); | |||||
| PatchCoord patch_coord(*handle, face_u, face_v); | |||||
| implementation_->evalPatchesVertexData(&patch_coord, 1, extra_data); | |||||
| } | |||||
| void EvalOutputAPI::evaluateFaceVarying(const int face_varying_channel, | void EvalOutputAPI::evaluateFaceVarying(const int face_varying_channel, | ||||
| const int ptex_face_index, | const int ptex_face_index, | ||||
| float face_u, | float face_u, | ||||
| float face_v, | float face_v, | ||||
| float face_varying[2]) | float face_varying[2]) | ||||
| { | { | ||||
| assert(face_u >= 0.0f); | assert(face_u >= 0.0f); | ||||
| assert(face_u <= 1.0f); | assert(face_u <= 1.0f); | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | OpenSubdiv_EvaluatorImpl::~OpenSubdiv_EvaluatorImpl() | ||||
| delete eval_output; | delete eval_output; | ||||
| delete patch_map; | delete patch_map; | ||||
| delete patch_table; | delete patch_table; | ||||
| } | } | ||||
| OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal( | OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal( | ||||
| OpenSubdiv_TopologyRefiner *topology_refiner, | OpenSubdiv_TopologyRefiner *topology_refiner, | ||||
| eOpenSubdivEvaluator evaluator_type, | eOpenSubdivEvaluator evaluator_type, | ||||
| OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr) | OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr, | ||||
| const OpenSubdiv_EvaluatorSettings *settings) | |||||
| { | { | ||||
| // Only CPU and GLCompute are implemented at the moment. | // Only CPU and GLCompute are implemented at the moment. | ||||
| if (evaluator_type != OPENSUBDIV_EVALUATOR_CPU && | if (evaluator_type != OPENSUBDIV_EVALUATOR_CPU && | ||||
| evaluator_type != OPENSUBDIV_EVALUATOR_GLSL_COMPUTE) { | evaluator_type != OPENSUBDIV_EVALUATOR_GLSL_COMPUTE) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| using blender::opensubdiv::vector; | using blender::opensubdiv::vector; | ||||
| TopologyRefiner *refiner = topology_refiner->impl->topology_refiner; | TopologyRefiner *refiner = topology_refiner->impl->topology_refiner; | ||||
| if (refiner == NULL) { | if (refiner == NULL) { | ||||
| // Happens on bad topology. | // Happens on bad topology. | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| // TODO(sergey): Base this on actual topology. | // TODO(sergey): Base this on actual topology. | ||||
| const bool has_varying_data = false; | const bool has_varying_data = false; | ||||
| const int num_face_varying_channels = refiner->GetNumFVarChannels(); | const int num_face_varying_channels = refiner->GetNumFVarChannels(); | ||||
| const bool has_face_varying_data = (num_face_varying_channels != 0); | const bool has_face_varying_data = (num_face_varying_channels != 0); | ||||
| const int level = topology_refiner->getSubdivisionLevel(topology_refiner); | const int level = topology_refiner->getSubdivisionLevel(topology_refiner); | ||||
| const bool is_adaptive = topology_refiner->getIsAdaptive(topology_refiner); | const bool is_adaptive = topology_refiner->getIsAdaptive(topology_refiner); | ||||
| const int vertex_data_width = settings->num_vertex_data; | |||||
| // Common settings for stencils and patches. | // Common settings for stencils and patches. | ||||
| const bool stencil_generate_intermediate_levels = is_adaptive; | const bool stencil_generate_intermediate_levels = is_adaptive; | ||||
| const bool stencil_generate_offsets = true; | const bool stencil_generate_offsets = true; | ||||
| const bool use_inf_sharp_patch = true; | const bool use_inf_sharp_patch = true; | ||||
| // Refine the topology with given settings. | // Refine the topology with given settings. | ||||
| // TODO(sergey): What if topology is already refined? | // TODO(sergey): What if topology is already refined? | ||||
| if (is_adaptive) { | if (is_adaptive) { | ||||
| TopologyRefiner::AdaptiveOptions options(level); | TopologyRefiner::AdaptiveOptions options(level); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if (evaluator_cache_descr) { | ||||
| evaluator_cache = static_cast<blender::opensubdiv::GpuEvalOutput::EvaluatorCache *>( | evaluator_cache = static_cast<blender::opensubdiv::GpuEvalOutput::EvaluatorCache *>( | ||||
| evaluator_cache_descr->eval_cache); | evaluator_cache_descr->eval_cache); | ||||
| } | } | ||||
| eval_output = new blender::opensubdiv::GpuEvalOutput(vertex_stencils, | eval_output = new blender::opensubdiv::GpuEvalOutput(vertex_stencils, | ||||
| varying_stencils, | varying_stencils, | ||||
| all_face_varying_stencils, | all_face_varying_stencils, | ||||
| 2, | 2, | ||||
| vertex_data_width, | |||||
| patch_table, | patch_table, | ||||
| evaluator_cache); | evaluator_cache); | ||||
| } | } | ||||
| else { | else { | ||||
| eval_output = new blender::opensubdiv::CpuEvalOutput( | eval_output = new blender::opensubdiv::CpuEvalOutput(vertex_stencils, | ||||
| vertex_stencils, varying_stencils, all_face_varying_stencils, 2, patch_table); | varying_stencils, | ||||
| all_face_varying_stencils, | |||||
| 2, | |||||
| vertex_data_width, | |||||
| patch_table); | |||||
| } | } | ||||
| blender::opensubdiv::PatchMap *patch_map = new blender::opensubdiv::PatchMap(*patch_table); | blender::opensubdiv::PatchMap *patch_map = new blender::opensubdiv::PatchMap(*patch_table); | ||||
| // Wrap everything we need into an object which we control from our side. | // Wrap everything we need into an object which we control from our side. | ||||
| OpenSubdiv_EvaluatorImpl *evaluator_descr; | OpenSubdiv_EvaluatorImpl *evaluator_descr; | ||||
| evaluator_descr = new OpenSubdiv_EvaluatorImpl(); | evaluator_descr = new OpenSubdiv_EvaluatorImpl(); | ||||
| evaluator_descr->eval_output = new blender::opensubdiv::EvalOutputAPI(eval_output, patch_map); | evaluator_descr->eval_output = new blender::opensubdiv::EvalOutputAPI(eval_output, patch_map); | ||||
| Show All 15 Lines | |||||