2013-05-17 16:47:44 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2013-05-17 16:47:44 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2013-05-17 16:47:44 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2013-05-17 16:47:44 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2013-05-17 16:47:44 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2013-05-17 16:47:44 +00:00
|
|
|
//
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#ifndef OPENSUBDIV3_FAR_PATCH_PARAM_H
|
|
|
|
#define OPENSUBDIV3_FAR_PATCH_PARAM_H
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2013-06-12 00:25:54 +00:00
|
|
|
#include "../version.h"
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
#include "../far/types.h"
|
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Far {
|
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
/// \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 :
|
2014-11-25 20:41:19 +00:00
|
|
|
///
|
|
|
|
/// Field | Bits | Content
|
2013-07-11 01:51:43 +00:00
|
|
|
/// -----------|:----:|------------------------------------------------------
|
2015-04-17 14:42:53 +00:00
|
|
|
/// level | 3 | the subdivision level of the patch
|
2014-11-25 20:41:19 +00:00
|
|
|
/// nonquad | 1 | whether the patch is the child of a non-quad face
|
2015-04-17 14:42:53 +00:00
|
|
|
/// boundary | 4 | boundary edge mask encoding
|
|
|
|
/// transition | 4 | transition edge mask encoding
|
2014-11-25 20:41:19 +00:00
|
|
|
/// v | 10 | log2 value of u parameter at first patch corner
|
|
|
|
/// u | 10 | log2 value of v parameter at first patch corner
|
|
|
|
///
|
2013-05-17 16:47:44 +00:00
|
|
|
/// Note : the bitfield is not expanded in the struct due to differences in how
|
|
|
|
/// GPU & CPU compilers pack bit-fields and endian-ness.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
struct PatchParam {
|
2014-10-09 21:48:50 +00:00
|
|
|
Index faceIndex:32; // Ptex face index
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
struct BitField {
|
|
|
|
unsigned int field:32;
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Sets the values of the bit fields
|
2013-05-17 16:47:44 +00:00
|
|
|
///
|
|
|
|
/// @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
|
|
|
|
///
|
2015-04-17 14:42:53 +00:00
|
|
|
void Set( short u, short v, unsigned char depth, bool nonquad,
|
|
|
|
unsigned short boundary, unsigned short transition );
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the log2 value of the u parameter at the top left corner of
|
2013-05-17 16:47:44 +00:00
|
|
|
/// the patch
|
2015-04-17 14:42:53 +00:00
|
|
|
unsigned short GetU() const { return (unsigned short)((field >> 22) & 0x3ff); }
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the log2 value of the v parameter at the top left corner of
|
2013-05-17 16:47:44 +00:00
|
|
|
/// the patch
|
2015-04-17 14:42:53 +00:00
|
|
|
unsigned short GetV() const { return (unsigned short)((field >> 12) & 0x3ff); }
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
/// \brief Returns the transition edge encoding for the patch.
|
|
|
|
unsigned short GetTransition() const { return (unsigned short)((field >> 8) & 0xf); }
|
|
|
|
|
|
|
|
/// \brief Returns the boundary edge encoding for the patch.
|
|
|
|
unsigned short GetBoundary() const { return (unsigned short)((field >> 4) & 0xf); }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief True if the parent coarse face is a non-quad
|
2015-04-17 14:42:53 +00:00
|
|
|
bool NonQuadRoot() const { return (field >> 3) & 0x1; }
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
/// \brief Returns the fratcion of normalized parametric space covered by the
|
2013-06-11 22:59:43 +00:00
|
|
|
/// sub-patch.
|
|
|
|
float GetParamFraction() const;
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
/// \brief Returns the level of subdivision of the patch
|
2015-04-17 14:42:53 +00:00
|
|
|
unsigned char GetDepth() const { return (unsigned char)(field & 0x7); }
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
/// The (u,v) pair is normalized to this sub-parametric space.
|
2013-06-05 18:44:30 +00:00
|
|
|
///
|
|
|
|
/// @param u u parameter
|
|
|
|
/// @param v v parameter
|
|
|
|
///
|
2013-06-13 20:58:23 +00:00
|
|
|
void Normalize( float & u, float & v ) const;
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Resets the values to 0
|
2013-05-17 16:47:44 +00:00
|
|
|
void Clear() { field = 0; }
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
} bitField;
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Sets the values of the bit fields
|
2013-05-17 16:47:44 +00:00
|
|
|
///
|
|
|
|
/// @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
|
|
|
|
///
|
2015-04-17 14:42:53 +00:00
|
|
|
void Set( Index faceid, short u, short v, unsigned char depth, bool nonquad ,
|
|
|
|
unsigned short boundary, unsigned short transition );
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Resets everything to 0
|
2015-01-06 02:56:24 +00:00
|
|
|
void Clear();
|
2013-05-17 16:47:44 +00:00
|
|
|
};
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
typedef std::vector<PatchParam> PatchParamTable;
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
typedef Vtr::Array<PatchParam> PatchParamArray;
|
|
|
|
typedef Vtr::ConstArray<PatchParam> ConstPatchParamArray;
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
inline void
|
2015-04-17 14:42:53 +00:00
|
|
|
PatchParam::BitField::Set( short u, short v, unsigned char depth, bool nonquad,
|
|
|
|
unsigned short boundary, unsigned short transition ) {
|
|
|
|
field = (u << 22) |
|
|
|
|
(v << 12) |
|
|
|
|
(transition << 8) |
|
|
|
|
(boundary << 4) |
|
|
|
|
((nonquad ? 1:0) << 3) |
|
2014-11-25 20:41:19 +00:00
|
|
|
(nonquad ? depth+1 : depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline float
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchParam::BitField::GetParamFraction( ) const {
|
2013-06-05 18:44:30 +00:00
|
|
|
if (NonQuadRoot()) {
|
2013-06-11 22:59:43 +00:00
|
|
|
return 1.0f / float( 1 << (GetDepth()-1) );
|
2013-06-05 18:44:30 +00:00
|
|
|
} else {
|
2013-06-11 22:59:43 +00:00
|
|
|
return 1.0f / float( 1 << GetDepth() );
|
2013-06-05 18:44:30 +00:00
|
|
|
}
|
2013-06-11 22:59:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 20:58:23 +00:00
|
|
|
inline void
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchParam::BitField::Normalize( float & u, float & v ) const {
|
2013-06-11 22:59:43 +00:00
|
|
|
|
|
|
|
float frac = GetParamFraction();
|
2013-06-05 18:44:30 +00:00
|
|
|
|
2013-06-13 20:58:23 +00:00
|
|
|
// top left corner
|
2013-06-05 18:44:30 +00:00
|
|
|
float pu = (float)GetU()*frac;
|
|
|
|
float pv = (float)GetV()*frac;
|
|
|
|
|
|
|
|
// normalize u,v coordinates
|
|
|
|
u = (u - pu) / frac,
|
|
|
|
v = (v - pv) / frac;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
inline void
|
2015-04-17 14:42:53 +00:00
|
|
|
PatchParam::Set( Index faceid, short u, short v, unsigned char depth, bool nonquad,
|
|
|
|
unsigned short boundary, unsigned short transition ) {
|
2015-01-06 02:56:24 +00:00
|
|
|
faceIndex = faceid;
|
2015-04-17 14:42:53 +00:00
|
|
|
bitField.Set(u,v,depth,nonquad,boundary,transition);
|
2015-01-06 02:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
PatchParam::Clear() {
|
|
|
|
faceIndex = 0;
|
|
|
|
bitField.Clear();
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Far
|
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
|