Renaming PtexCoord as PatchParam and general cleanup of the ptex name where it

doesn't belong
This commit is contained in:
manuelk 2013-05-17 09:47:44 -07:00
parent c2cec239cd
commit 3869be18b7
10 changed files with 204 additions and 127 deletions

View File

@ -679,8 +679,8 @@ getNumPtexFaces(HbrMesh<T> const * hmesh) {
}
// Computes per-face or per-patch local ptex texture coordinates.
template <class T> FarPtexCoord *
computePtexCoordinate(HbrFace<T> const *f, FarPtexCoord *coord) {
template <class T> FarPatchParam *
computePatchParam(HbrFace<T> const *f, FarPatchParam *coord) {
short u,v;
unsigned short ofs = 1;

View File

@ -639,10 +639,10 @@ FarMultiMeshFactory<T, U>::splicePatchTables(FarMeshVector const &meshes) {
FarPatchTables::PatchArray const *parray = ptables->GetPatchArray(*it);
if (not parray) continue;
copyWithPtexFaceOffset(std::back_inserter(result->_ptexTable),
ptables->_ptexTable,
parray->GetPatchIndex(),
parray->GetNumPatches(), ptexFaceOffset);
copyWithPtexFaceOffset(std::back_inserter(result->_paramTable),
result->_paramTable,
parray->GetPatchIndex(),
parray->GetNumPatches(), ptexFaceOffset);
ptexFaceOffset += meshes[i]->GetNumPtexFaces();
}

157
opensubdiv/far/patchParam.h Normal file
View File

@ -0,0 +1,157 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#ifndef FAR_PATCH_PARAM_H
#define FAR_PATCH_PARAM_H
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
/// \brief Local patch parameterization descriptor
///
/// Coarse mesh faces are split into sets of patches in both uniform and feature
/// adaptive modes. In order to maintain local patch parameterization, it is
/// necessary to retain some information, such as level of subdivision, face-
/// winding status... This parameterization is directly applicable to ptex textures,
/// but has to be remapped to a specific layout for uv textures.
///
/// Bitfield layout :
///
/// level:4 - the subdivision level of the patch
/// nonquad:1; - whether the patch is the child of a non-quad face
/// rotation:2; - patch rotations necessary to match CCW face-winding
/// v:10; - log2 value of u parameter at first patch corner
/// u:10; - log2 value of v parameter at first patch corner
/// reserved1:5; - padding
///
/// Note : the bitfield is not expanded in the struct due to differences in how
/// GPU & CPU compilers pack bit-fields and endian-ness.
///
struct FarPatchParam {
unsigned int faceIndex:32; // Ptex face index
struct BitField {
unsigned int field:32;
/// Sets the values of the bit fields
///
/// @param u value of the u parameter for the first corner of the face
/// @param v value of the v parameter for the first corner of the face
///
/// @param rots rotations required to reproduce CCW face-winding
/// @param depth subdivision level of the patch
/// @param nonquad true if the root face is not a quad
///
void Set( short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
field = (u << 17) |
(v << 7) |
(rots << 5) |
((nonquad ? 1:0) << 4) |
(nonquad ? depth+1 : depth);
}
/// Returns the log2 value of the u parameter at the top left corner of
/// the patch
unsigned short GetU() const { return (field >> 17) & 0x3ff; }
/// Returns the log2 value of the v parameter at the top left corner of
/// the patch
unsigned short GetV() const { return (field >> 7) & 0x3ff; }
/// Returns the rotation of the patch (the number of CCW parameter winding)
unsigned char GetRotation() const { return (field >> 5) & 0x3; }
/// True if the parent coarse face is a non-quad
bool NonQuadRoot() const { return (field >> 4) & 0x1; }
/// Returns the level of subdivision of the patch
unsigned char GetDepth() const { return (field & 0xf); }
/// Resets the values to 0
void Clear() { field = 0; }
} bitField;
/// Sets the values of the bit fields
///
/// @param faceid ptex face index
///
/// @param u value of the u parameter for the first corner of the face
/// @param v value of the v parameter for the first corner of the face
///
/// @param rots rotations required to reproduce CCW face-winding
/// @param depth subdivision level of the patch
/// @param nonquad true if the root face is not a quad
///
void Set( unsigned int faceid, short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
faceIndex = faceid;
bitField.Set(u,v,rots,depth,nonquad);
}
/// Resets everything to 0
void Clear() {
faceIndex = 0;
bitField.Clear();
}
};
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* FAR_PATCH_PARAM */

View File

@ -60,6 +60,8 @@
#include "../version.h"
#include "../far/patchParam.h"
#include <cstdlib>
#include <cassert>
#include <vector>
@ -67,88 +69,6 @@
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
/// \brief Flattened ptex coordinates indexing system
///
/// Bitfield layout :
///
/// level:4 - the subdivision level of the patch
/// nonquad:1; - whether the patch is the child of a non-quad face
/// rotation:2; - patch rotations necessary to match CCW face-winding
/// v:10; - log2 value of u parameter at first patch corner
/// u:10; - log2 value of v parameter at first patch corner
/// reserved1:5; - padding
///
/// Note : the bitfield is not expanded in the struct due to differences in how
/// GPU & CPU compilers pack bit-fields and endian-ness.
///
struct FarPtexCoord {
unsigned int faceIndex:32; // Ptex face index
struct BitField {
unsigned int field:32;
/// Sets the values of the bit fields
///
/// @param u value of the u parameter for the first corner of the face
/// @param v value of the v parameter for the first corner of the face
///
/// @param rots rotations required to reproduce CCW face-winding
/// @param depth subdivision level of the patch
/// @param nonquad true if the root face is not a quad
///
void Set( short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
field = (u << 17) |
(v << 7) |
(rots << 5) |
((nonquad ? 1:0) << 4) |
(nonquad ? depth+1 : depth);
}
/// Returns the log2 value of the u parameter at the top left corner of
/// the patch
unsigned short GetU() const { return (field >> 17) & 0x3ff; }
/// Returns the log2 value of the v parameter at the top left corner of
/// the patch
unsigned short GetV() const { return (field >> 7) & 0x3ff; }
/// Returns the rotation of the patch (the number of CCW parameter winding)
unsigned char GetRotation() const { return (field >> 5) & 0x3; }
/// True if the parent coarse face is a non-quad
bool NonQuadRoot() const { return (field >> 4) & 0x1; }
/// Returns the level of subdivision of the patch
unsigned char GetDepth() const { return (field & 0xf); }
/// Resets the values to 0
void Clear() { field = 0; }
} bitField;
/// Sets the values of the bit fields
///
/// @param faceid ptex face index
///
/// @param u value of the u parameter for the first corner of the face
/// @param v value of the v parameter for the first corner of the face
///
/// @param rots rotations required to reproduce CCW face-winding
/// @param depth subdivision level of the patch
/// @param nonquad true if the root face is not a quad
///
void Set( unsigned int faceid, short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
faceIndex = faceid;
bitField.Set(u,v,rots,depth,nonquad);
}
/// Resets everything to 0
void Clear() {
faceIndex = 0;
bitField.Clear();
}
};
/// \brief Container for patch vertex indices tables
///
/// FarPatchTables contain the lists of vertices for each patch of an adaptive
@ -160,7 +80,7 @@ public:
typedef std::vector<unsigned int> PTable;
typedef std::vector<int> VertexValenceTable;
typedef std::vector<unsigned int> QuadOffsetTable;
typedef std::vector<FarPtexCoord> PtexCoordinateTable;
typedef std::vector<FarPatchParam> PatchParamTable;
typedef std::vector<float> FVarDataTable;
enum Type {
@ -388,7 +308,7 @@ public:
}
/// Returns the global index of the first patch in this array (Used to
/// access ptex / fvar table data)
/// access param / fvar table data)
unsigned int GetPatchIndex() const {
return _range.patchIndex;
}
@ -458,8 +378,8 @@ public:
/// Returns a quad offsets table used by Gregory patches
QuadOffsetTable const & GetQuadOffsetTable() const { return _quadOffsetTable; }
/// Returns a PtexCoordinateTable for each type of patch
PtexCoordinateTable const & GetPtexCoordinatesTable() const { return _ptexTable; }
/// Returns a PatchParamTable for each type of patch
PatchParamTable const & GetPatchParamTable() const { return _paramTable; }
/// Returns an FVarDataTable for each type of patch
/// The data is stored as a run of totalFVarWidth floats per-vertex per-face
@ -513,7 +433,7 @@ private:
QuadOffsetTable _quadOffsetTable; // quad offsets table (for Gregory patches)
PtexCoordinateTable _ptexTable;
PatchParamTable _paramTable;
FVarDataTable _fvarTable;

View File

@ -177,10 +177,10 @@ private:
};
// Useful typedefs
typedef PatchTypes<unsigned int*> CVPointers;
typedef PatchTypes<FarPtexCoord *> PtexPointers;
typedef PatchTypes<float *> FVarPointers;
typedef PatchTypes<int> Counter;
typedef PatchTypes<unsigned int*> CVPointers;
typedef PatchTypes<FarPatchParam *> ParamPointers;
typedef PatchTypes<float *> FVarPointers;
typedef PatchTypes<int> Counter;
// Creates a PatchArray and appends it to a vector and keeps track of both
// vertex and patch offsets
@ -260,7 +260,7 @@ FarPatchTablesFactory<T>::allocateTables( FarPatchTables * tables, int fvarwidth
tables->_patches.resize( nverts );
// Allocate memory for the ptex coord tables
tables->_ptexTable.resize( npatches );
tables->_paramTable.resize( npatches );
if (fvarwidth>0) {
tables->_fvarTable.resize( npatches * 4 * fvarwidth );
@ -303,9 +303,9 @@ FarPatchTablesFactory<T>::Create( HbrMesh<T> const * mesh, FacesList const & fli
allocateTables( result, fvarwidth );
unsigned int * iptr = &result->_patches[0];
FarPtexCoord * pptr = &result->_ptexTable[0];
float * fptr = requireFVarData ? &result->_fvarTable[0] : 0;
unsigned int * iptr = &result->_patches[0];
FarPatchParam * pptr = &result->_paramTable[0];
float * fptr = requireFVarData ? &result->_fvarTable[0] : 0;
for (int level=firstArray; level<(int)flist.size(); ++level) {
@ -317,7 +317,7 @@ FarPatchTablesFactory<T>::Create( HbrMesh<T> const * mesh, FacesList const & fli
*iptr++ = remapTable[f->GetVertex(j)->GetID()];
}
pptr = computePtexCoordinate(f, pptr);
pptr = computePatchParam(f, pptr);
if (requireFVarData)
fptr = computeFVarData(f, fvarwidth, fptr, /*isAdaptive=*/false);
@ -687,7 +687,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
// Setup convenience pointers at the beginning of each patch array for each
// table (patches, ptex, fvar)
CVPointers iptrs[6];
PtexPointers pptrs[6];
ParamPointers pptrs[6];
FVarPointers fptrs[6];
for (Descriptor::iterator it=Descriptor::begin(); it!=Descriptor::end(); ++it) {
@ -698,7 +698,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
continue;
iptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_patches[pa->GetVertIndex()];
pptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_ptexTable[pa->GetPatchIndex()];
pptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_paramTable[pa->GetPatchIndex()];
if (requireFVarData)
fptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_fvarTable[pa->GetPatchIndex() * 4 * fvarwidth];
}
@ -719,7 +719,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
case 0 : { // Regular Patch (16 CVs)
getOneRing(f, 16, remapRegular, iptrs[0].R);
iptrs[0].R+=16;
pptrs[0].R = computePtexCoordinate(f, pptrs[0].R);
pptrs[0].R = computePatchParam(f, pptrs[0].R);
fptrs[0].R = computeFVarData(f, fvarwidth, fptrs[0].R, /*isAdaptive=*/true);
} break;
@ -727,7 +727,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
f->_adaptiveFlags.brots = (f->_adaptiveFlags.rots+1)%4;
getOneRing(f, 12, remapRegularBoundary, iptrs[0].B[0]);
iptrs[0].B[0]+=12;
pptrs[0].B[0] = computePtexCoordinate(f, pptrs[0].B[0]);
pptrs[0].B[0] = computePatchParam(f, pptrs[0].B[0]);
fptrs[0].B[0] = computeFVarData(f, fvarwidth, fptrs[0].B[0], /*isAdaptive=*/true);
} break;
@ -735,7 +735,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
f->_adaptiveFlags.brots = (f->_adaptiveFlags.rots+1)%4;
getOneRing(f, 9, remapRegularCorner, iptrs[0].C[0]);
iptrs[0].C[0]+=9;
pptrs[0].C[0] = computePtexCoordinate(f, pptrs[0].C[0]);
pptrs[0].C[0] = computePatchParam(f, pptrs[0].C[0]);
fptrs[0].C[0] = computeFVarData(f, fvarwidth, fptrs[0].C[0], /*isAdaptive=*/true);
} break;
@ -752,7 +752,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
iptrs[0].G[0]+=4;
getQuadOffsets(f, quad_G_C0_P);
quad_G_C0_P += 4;
pptrs[0].G[0] = computePtexCoordinate(f, pptrs[0].G[0]);
pptrs[0].G[0] = computePatchParam(f, pptrs[0].G[0]);
fptrs[0].G[0] = computeFVarData(f, fvarwidth, fptrs[0].G[0], /*isAdaptive=*/true);
} else {
@ -762,7 +762,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
iptrs[0].G[1]+=4;
getQuadOffsets(f, quad_G_C1_P);
quad_G_C1_P += 4;
pptrs[0].G[1] = computePtexCoordinate(f, pptrs[0].G[1]);
pptrs[0].G[1] = computePatchParam(f, pptrs[0].G[1]);
fptrs[0].G[1] = computeFVarData(f, fvarwidth, fptrs[0].G[1], /*isAdaptive=*/true);
}
} else {
@ -783,7 +783,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
getOneRing(f, 16, remapRegular, iptrs[tcase].R);
iptrs[tcase].R+=16;
pptrs[tcase].R = computePtexCoordinate(f, pptrs[tcase].R);
pptrs[tcase].R = computePatchParam(f, pptrs[tcase].R);
fptrs[tcase].R = computeFVarData(f, fvarwidth, fptrs[tcase].R, /*isAdaptive=*/true);
} break;
@ -791,7 +791,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
unsigned rot = f->_adaptiveFlags.brots;
getOneRing(f, 12, remapRegularBoundary, iptrs[tcase].B[rot]);
iptrs[tcase].B[rot]+=12;
pptrs[tcase].B[rot] = computePtexCoordinate(f, pptrs[tcase].B[rot]);
pptrs[tcase].B[rot] = computePatchParam(f, pptrs[tcase].B[rot]);
fptrs[tcase].B[rot] = computeFVarData(f, fvarwidth, fptrs[tcase].B[rot], /*isAdaptive=*/true);
} break;
@ -799,7 +799,7 @@ FarPatchTablesFactory<T>::Create( int maxlevel, int maxvalence, bool requireFVar
unsigned rot = f->_adaptiveFlags.brots;
getOneRing(f, 9, remapRegularCorner, iptrs[tcase].C[rot]);
iptrs[tcase].C[rot]+=9;
pptrs[tcase].C[rot] = computePtexCoordinate(f, pptrs[tcase].C[rot]);
pptrs[tcase].C[rot] = computePatchParam(f, pptrs[tcase].C[rot]);
fptrs[tcase].C[rot] = computeFVarData(f, fvarwidth, fptrs[tcase].C[rot], /*isAdaptive=*/true);
} break;
}

View File

@ -98,12 +98,12 @@ OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh<OsdVertex> const * farmes
_patchBitFields.reserve(npatches);
FarPatchTables::PtexCoordinateTable const & ptxTable =
patchTables->GetPtexCoordinatesTable();
FarPatchTables::PatchParamTable const & ptxTable =
patchTables->GetPatchParamTable();
if ( not ptxTable.empty() ) {
FarPtexCoord const * pptr = &ptxTable[0];
FarPatchParam const * pptr = &ptxTable[0];
for (int arrayId = 0; arrayId < (int)_patchArrays.size(); ++arrayId) {

View File

@ -152,7 +152,7 @@ public:
}
/// Returns the vector of per-patch parametric data
const std::vector<FarPtexCoord::BitField> & GetPatchBitFields() const {
const std::vector<FarPatchParam::BitField> & GetPatchBitFields() const {
return _patchBitFields;
}
@ -220,12 +220,12 @@ public:
FarPatchTables::PatchArrayVector const & patchArrays =
patchTables.GetPatchArrayVector();
FarPatchTables::PtexCoordinateTable const & ptxTable =
patchTables.GetPtexCoordinatesTable();
FarPatchTables::PatchParamTable const & paramTable =
patchTables.GetPatchParamTable();
int nfaces =0;
assert( not ptxTable.empty() );
assert( not paramTable.empty() );
for (int arrayid = 0; arrayid < (int)patchArrays.size(); ++arrayid) {
@ -235,7 +235,7 @@ public:
for (unsigned int j=0; j < pa.GetNumPatches(); ++j) {
int faceId = ptxTable[pa.GetPatchIndex()+j].faceIndex;
int faceId = paramTable[pa.GetPatchIndex()+j].faceIndex;
Handle handle = { arrayid, j*ringsize, (unsigned int)mmap.size() };
@ -290,9 +290,9 @@ protected:
private:
// Topology data for a mesh
FarPatchTables::PatchArrayVector _patchArrays; // patch descriptor for each patch in the mesh
FarPatchTables::PTable _patches; // patch control vertices
std::vector<FarPtexCoord::BitField> _patchBitFields; // per-patch parametric info
FarPatchTables::PatchArrayVector _patchArrays; // patch descriptor for each patch in the mesh
FarPatchTables::PTable _patches; // patch control vertices
std::vector<FarPatchParam::BitField> _patchBitFields; // per-patch parametric info
FarPatchTables::VertexValenceTable _vertexValenceBuffer; // extra Gregory patch data buffers
FarPatchTables::QuadOffsetTable _quadOffsetBuffer;

View File

@ -91,7 +91,7 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c
FarPatchTables::PatchHandle const & handle = patchHandles[i];
FarPtexCoord::BitField bits = context->GetPatchBitFields()[ handle.serialIndex ];
FarPatchParam::BitField bits = context->GetPatchBitFields()[ handle.serialIndex ];
float frac = 1.0f / float( 1 << bits.GetDepth() );

View File

@ -183,7 +183,7 @@ OsdD3D11DrawContext::allocate(FarPatchTables const *patchTables,
ConvertPatchArrays(patchTables->GetAllPatchArrays(), patchArrays, patchTables->GetMaxValence(), 0);
FarPatchTables::PTable const & ptables = patchTables->GetPatchTable();
FarPatchTables::PtexCoordinateTable const & ptexCoordTables = patchTables->GetPtexCoordinatesTable();
FarPatchTables::PatchParamTable const & ptexCoordTables = patchTables->GetPatchParamTable();
int totalPatchIndices = (int)ptables.size();
int totalPatches = (int)ptexCoordTables.size();

View File

@ -226,8 +226,8 @@ OsdGLDrawContext::create(FarPatchTables const * patchTables, bool requireFVarDat
// create ptex coordinate buffer
FarPatchTables::PtexCoordinateTable const &
ptexCoordTables = patchTables->GetPtexCoordinatesTable();
FarPatchTables::PatchParamTable const &
ptexCoordTables = patchTables->GetPatchParamTable();
if (not ptexCoordTables.empty())
ptexCoordinateTextureBuffer = createTextureBuffer(ptexCoordTables, GL_RG32I);