Changes to address comments in #284.

* rolled getNumFVarVertices into allocateTables
* renamed tessellate to triangulateQuads (technically speaking, Loop scheme uses a trivial triangulation)
* condensed the pointer arithmetic used for triangulating the data tables
This commit is contained in:
Nathan Litke 2014-04-21 17:56:53 -07:00
parent 5195d93947
commit d5deab632c
2 changed files with 24 additions and 89 deletions

View File

@ -154,9 +154,6 @@ private:
// The number of patches in the mesh
static int getNumPatches( FarPatchTables::PatchArrayVector const & parrays );
// The number of vertices in the face-varying table
static int getNumFVarVertices( FarPatchTables::PatchArrayVector const & parrays );
// Reserves tables based on the contents of the PatchArrayVector
static void allocateTables( FarPatchTables * tables, int nlevels, int fvarwidth );
@ -307,7 +304,13 @@ FarPatchTablesFactory<T>::allocateTables( FarPatchTables * tables, int nlevels,
tables->_paramTable.resize( npatches );
if (fvarwidth>0) {
int nfvarverts = getNumFVarVertices(tables->GetPatchArrayVector());
FarPatchTables::PatchArrayVector const & parrays = tables->GetPatchArrayVector();
int nfvarverts = 0;
for (int i=0; i<(int)parrays.size(); ++i) {
nfvarverts += parrays[i].GetNumPatches() *
(parrays[i].GetDescriptor().GetType() == FarPatchTables::TRIANGLES ? 3 : 4);
}
tables->_fvarData._data.resize( nfvarverts * fvarwidth );
if (nlevels >1) {
@ -331,9 +334,9 @@ FarPatchTablesFactory<T>::Create( HbrMesh<T> const * mesh, FacesList const & fli
if (isLoop)
patchType = FarPatchTables::TRIANGLES;
bool tessellate = !isLoop && patchType == FarPatchTables::TRIANGLES;
bool triangulateQuads = !isLoop && patchType == FarPatchTables::TRIANGLES;
int nv = patchType == FarPatchTables::TRIANGLES ? 3 : 4;
int nverts = patchType == FarPatchTables::TRIANGLES ? 3 : 4;
int firstArray = firstLevel > -1 ? firstLevel : (int)flist.size()-1,
nlevels = (int)flist.size()-firstArray;
@ -348,13 +351,13 @@ FarPatchTablesFactory<T>::Create( HbrMesh<T> const * mesh, FacesList const & fli
for (int i=1, poffset=0, voffset=0; i<(int)flist.size(); ++i) {
int npatches = (int)flist[i].size();
if (tessellate)
if (triangulateQuads)
npatches *= 2;
if (i>=firstArray) {
parray.push_back( FarPatchTables::PatchArray(desc, voffset, poffset, npatches, 0 ) );
voffset += npatches * nv;
voffset += npatches * nverts;
poffset += npatches;
}
}
@ -385,37 +388,27 @@ FarPatchTablesFactory<T>::Create( HbrMesh<T> const * mesh, FacesList const & fli
if (fvarwidth>0)
fptr = computeFVarData(f, fvarwidth, fptr, /*isAdaptive=*/false);
if (tessellate) {
if (triangulateQuads) {
// Triangulate the quadrilateral: {v0,v1,v2,v3} -> {v0,v1,v2},{v3,v0,v2}.
iptr += 2;
unsigned int * iptr0 = iptr - 6;
unsigned int * iptr2 = iptr - 4;
unsigned int * iptr4 = iptr - 2;
unsigned int * iptr5 = iptr - 1;
*iptr4 = *iptr0;
*iptr5 = *iptr2;
*iptr = *(iptr - 4); // copy v0 index
++iptr;
*iptr = *(iptr - 3); // copy v2 index
++iptr;
pptr++;
FarPatchParam * pptr0 = pptr - 2;
FarPatchParam * pptr1 = pptr - 1;
*pptr1 = *pptr0;
*pptr = *(pptr - 1); // copy first patch param
++pptr;
if (fvarwidth > 0) {
fptr += 2 * fvarwidth;
float * fptr0 = fptr - 6 * fvarwidth;
float * fptr2 = fptr - 4 * fvarwidth;
float * fptr4 = fptr - 2 * fvarwidth;
float * fptr5 = fptr - 1 * fvarwidth;
for (int j = 0; j < fvarwidth; ++j) {
fptr4[j] = fptr0[j];
fptr5[j] = fptr2[j];
}
for (int j = 0; j < fvarwidth; ++j, ++fptr) {
*fptr = *(fptr - 4 * fvarwidth); // copy v0 fvar data
}
for (int j = 0; j < fvarwidth; ++j, ++fptr) {
*fptr = *(fptr - 3 * fvarwidth); // copy v2 fvar data
}
}
}
if (fvarwidth>0 and (not result->_fvarData._offsets.empty())) {
result->_fvarData._offsets[level-firstArray] = (fvarOffset+=(int)flist[level].size()*nv*fvarwidth);
result->_fvarData._offsets[level-firstArray] = (fvarOffset+=(int)flist[level].size()*nverts*fvarwidth);
}
}
@ -703,19 +696,6 @@ FarPatchTablesFactory<T>::getNumPatches( FarPatchTables::PatchArrayVector const
return result;
}
template <class T> int
FarPatchTablesFactory<T>::getNumFVarVertices( FarPatchTables::PatchArrayVector const & parrays ) {
int result=0;
for (int i=0; i<(int)parrays.size(); ++i) {
int npatches = parrays[i].GetNumPatches();
int nverts = parrays[i].GetDescriptor().GetType() == FarPatchTables::TRIANGLES ? 3 : 4;
result += npatches * nverts;
}
return result;
}
template <class T> void
FarPatchTablesFactory<T>::pushPatchArray( FarPatchTables::Descriptor desc,
FarPatchTables::PatchArrayVector & parray,

View File

@ -60,51 +60,6 @@ OsdDrawContext::ConvertPatchArrays(FarPatchTables::PatchArrayVector const &farPa
osdPatchArrays.push_back(PatchArray(desc, parray.GetArrayRange()));
}
}
/*
#if defined(GL_ES_VERSION_2_0)
// XXX: farmesh should have FarDensePatchTable for dense mesh indices.
// instead of GetFaceVertices().
const FarSubdivisionTables *tables = farMesh->GetSubdivisionTables();
int level = tables->GetMaxLevel();
const std::vector<int> &indices = farMesh->GetFaceVertices(level-1);
int numIndices = (int)indices.size();
// Allocate and fill index buffer.
glGenBuffers(1, &patchIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, patchIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
numIndices * sizeof(unsigned int), &(indices[0]), GL_STATIC_DRAW);
// OpenGLES 2 supports only triangle topologies for filled
// primitives i.e. not QUADS or PATCHES or LINES_ADJACENCY
// For the convenience of clients build build a triangles
// index buffer by splitting quads.
int numQuads = indices.size() / 4;
int numTrisIndices = numQuads * 6;
std::vector<short> trisIndices;
trisIndices.reserve(numTrisIndices);
for (int i=0; i<numQuads; ++i) {
const int * quad = &indices[i*4];
trisIndices.push_back(short(quad[0]));
trisIndices.push_back(short(quad[1]));
trisIndices.push_back(short(quad[2]));
trisIndices.push_back(short(quad[2]));
trisIndices.push_back(short(quad[3]));
trisIndices.push_back(short(quad[0]));
}
// Allocate and fill triangles index buffer.
glGenBuffers(1, &patchTrianglesIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, patchTrianglesIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
numTrisIndices * sizeof(short), &(trisIndices[0]), GL_STATIC_DRAW);
#endif
*/
}
} // end namespace OPENSUBDIV_VERSION