2525#include " ../far/patchTable.h"
2626#include " ../far/patchBasis.h"
2727
28+ #include < algorithm>
2829#include < cstring>
2930#include < cstdio>
3031
@@ -157,7 +158,10 @@ struct PatchTable::FVarPatchChannel {
157158
158159 Sdc::Options::FVarLinearInterpolation interpolation;
159160
160- PatchDescriptor desc;
161+ PatchDescriptor regDesc;
162+ PatchDescriptor irregDesc;
163+
164+ int stride;
161165
162166 std::vector<Index> patchValues;
163167 std::vector<PatchParam> patchParam;
@@ -186,10 +190,16 @@ PatchTable::allocateFVarPatchChannels(int numChannels) {
186190}
187191void
188192PatchTable::allocateFVarPatchChannelValues (
189- PatchDescriptor desc, int numPatches, int channel) {
193+ PatchDescriptor regDesc, PatchDescriptor irregDesc,
194+ int numPatches, int channel) {
190195 FVarPatchChannel & c = getFVarPatchChannel (channel);
191- c.desc = desc;
192- c.patchValues .resize (numPatches*desc.GetNumControlVertices ());
196+ c.regDesc = regDesc;
197+ c.irregDesc = irregDesc;
198+
199+ c.stride = std::max (regDesc.GetNumControlVertices (),
200+ irregDesc.GetNumControlVertices ());
201+
202+ c.patchValues .resize (numPatches * c.stride );
193203 c.patchParam .resize (numPatches);
194204}
195205void
@@ -487,15 +497,30 @@ PatchTable::GetFVarChannelLinearInterpolation(int channel) const {
487497 return c.interpolation ;
488498}
489499PatchDescriptor
500+ PatchTable::GetFVarPatchDescriptorRegular (int channel) const {
501+ FVarPatchChannel const & c = getFVarPatchChannel (channel);
502+ return c.regDesc ;
503+ }
504+ PatchDescriptor
505+ PatchTable::GetFVarPatchDescriptorIrregular (int channel) const {
506+ FVarPatchChannel const & c = getFVarPatchChannel (channel);
507+ return c.irregDesc ;
508+ }
509+ PatchDescriptor
490510PatchTable::GetFVarPatchDescriptor (int channel) const {
491511 FVarPatchChannel const & c = getFVarPatchChannel (channel);
492- return c.desc ;
512+ return c.irregDesc ;
493513}
494514ConstIndexArray
495515PatchTable::GetFVarValues (int channel) const {
496516 FVarPatchChannel const & c = getFVarPatchChannel (channel);
497517 return ConstIndexArray (&c.patchValues [0 ], (int )c.patchValues .size ());
498518}
519+ int
520+ PatchTable::GetFVarValueStride (int channel) const {
521+ FVarPatchChannel const & c = getFVarPatchChannel (channel);
522+ return c.stride ;
523+ }
499524IndexArray
500525PatchTable::getFVarValues (int channel) {
501526 FVarPatchChannel & c = getFVarPatchChannel (channel);
@@ -504,10 +529,10 @@ PatchTable::getFVarValues(int channel) {
504529ConstIndexArray
505530PatchTable::getPatchFVarValues (int patch, int channel) const {
506531 FVarPatchChannel const & c = getFVarPatchChannel (channel);
507- int ncvsPerPatch = c.desc .GetNumControlVertices ();
508532 int ncvsThisPatch = c.patchParam [patch].IsRegular ()
509- ? c.desc .GetRegularPatchSize () : ncvsPerPatch;
510- return ConstIndexArray (&c.patchValues [patch * ncvsPerPatch], ncvsThisPatch);
533+ ? c.regDesc .GetNumControlVertices ()
534+ : c.irregDesc .GetNumControlVertices ();
535+ return ConstIndexArray (&c.patchValues [patch * c.stride ], ncvsThisPatch);
511536}
512537ConstIndexArray
513538PatchTable::GetPatchFVarValues (PatchHandle const & handle, int channel) const {
@@ -521,7 +546,7 @@ ConstIndexArray
521546PatchTable::GetPatchArrayFVarValues (int array, int channel) const {
522547 PatchArray const & pa = getPatchArray (array);
523548 FVarPatchChannel const & c = getFVarPatchChannel (channel);
524- int ncvs = c.desc . GetNumControlVertices () ;
549+ int ncvs = c.stride ;
525550 int start = pa.patchIndex * ncvs;
526551 int count = pa.numPatches * ncvs;
527552 return ConstIndexArray (&c.patchValues [start], count);
@@ -620,8 +645,8 @@ PatchTable::EvaluateBasisFaceVarying(
620645
621646 PatchParam param = getPatchFVarPatchParam (handle.patchIndex , channel);
622647 PatchDescriptor::Type patchType = param.IsRegular ()
623- ? PatchDescriptor::REGULAR
624- : GetFVarPatchDescriptor (channel).GetType ();
648+ ? GetFVarPatchDescriptorRegular (channel). GetType ()
649+ : GetFVarPatchDescriptorIrregular (channel).GetType ();
625650
626651 if (patchType == PatchDescriptor::REGULAR) {
627652 internal::GetBSplineWeights (param, s, t, wP, wDs, wDt, wDss, wDst, wDtt);
0 commit comments