2012-08-22 23:22:08 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifndef OSD_DRAW_CONTEXT_H
|
|
|
|
#define OSD_DRAW_CONTEXT_H
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../version.h"
|
2013-06-10 22:54:40 +00:00
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
#include "../far/patchTables.h"
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <string>
|
2012-08-22 23:22:08 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// \brief Base DrawContext class
|
|
|
|
///
|
|
|
|
/// OsdDrawContext derives several sub-classes with API specific functionality
|
|
|
|
/// (GL, D3D11, ...).
|
|
|
|
///
|
|
|
|
/// Current specificiation GPU hardware tessellation limitations require transition
|
|
|
|
/// patches to be split-up into several triangular bi-cubic sub-patches.
|
|
|
|
/// OsdDrawContext processes FarPatchArrays from FarPatchTables and generates the
|
|
|
|
/// additional sets of sub-patches.
|
|
|
|
///
|
|
|
|
/// Contexts interface the serialized topological data pertaining to the
|
|
|
|
/// geometric primitives with the capabilities of the selected discrete
|
|
|
|
/// compute device.
|
|
|
|
///
|
2013-03-08 01:50:15 +00:00
|
|
|
class OsdDrawContext {
|
2013-05-10 18:18:41 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
public:
|
2013-05-10 18:18:41 +00:00
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
class PatchDescriptor {
|
|
|
|
public:
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param farDesc Patch type descriptor
|
|
|
|
///
|
|
|
|
/// @param maxValence Highest vertex valence in the primitive
|
|
|
|
///
|
|
|
|
/// @param subPatch Index of the triangulated sub-patch for the given
|
|
|
|
/// transition pattern. Transition patches need to be
|
|
|
|
/// split into multiple sub-patches in order to be
|
|
|
|
/// rendered with hardware tessellation.
|
|
|
|
///
|
|
|
|
/// @param numElements The size of the vertex and varying data per-vertex
|
|
|
|
/// (in floats)
|
|
|
|
///
|
2013-05-09 20:14:02 +00:00
|
|
|
PatchDescriptor(FarPatchTables::Descriptor farDesc, unsigned char maxValence,
|
|
|
|
unsigned char subPatch, unsigned char numElements) :
|
|
|
|
_farDesc(farDesc), _maxValence(maxValence), _subPatch(subPatch), _numElements(numElements) { }
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the type of the patch
|
|
|
|
FarPatchTables::Type GetType() const {
|
|
|
|
return _farDesc.GetType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the transition pattern of the patch if any (5 types)
|
|
|
|
FarPatchTables::TransitionPattern GetPattern() const {
|
|
|
|
return _farDesc.GetPattern();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the rotation of the patch (4 rotations)
|
|
|
|
unsigned char GetRotation() const {
|
|
|
|
return _farDesc.GetRotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of control vertices expected for a patch of the
|
|
|
|
/// type described
|
|
|
|
int GetNumControlVertices() const {
|
|
|
|
return _farDesc.GetNumControlVertices();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the max valence
|
|
|
|
int GetMaxValence() const {
|
|
|
|
return _maxValence;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the subpatch id
|
|
|
|
int GetSubPatch() const {
|
|
|
|
return _subPatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of vertex elements
|
|
|
|
int GetNumElements() const {
|
|
|
|
return _numElements;
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Set the number of vertex elements
|
|
|
|
void SetNumElements(int numElements) {
|
|
|
|
_numElements = numElements;
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
/// Allows ordering of patches by type
|
|
|
|
bool operator < ( PatchDescriptor const other ) const;
|
|
|
|
|
|
|
|
/// True if the descriptors are identical
|
|
|
|
bool operator == ( PatchDescriptor const other ) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FarPatchTables::Descriptor _farDesc;
|
|
|
|
unsigned char _maxValence;
|
|
|
|
unsigned char _subPatch;
|
|
|
|
unsigned char _numElements;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PatchArray {
|
|
|
|
public:
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param desc Patch descriptor defines the type, pattern, rotation of
|
|
|
|
/// the patches in the array
|
|
|
|
///
|
2013-05-16 00:53:40 +00:00
|
|
|
/// @param range The range of vertex indices
|
2013-05-10 18:18:41 +00:00
|
|
|
///
|
2013-05-09 20:14:02 +00:00
|
|
|
PatchArray(PatchDescriptor desc, FarPatchTables::PatchArray::ArrayRange const & range) :
|
|
|
|
_desc(desc), _range(range) { }
|
|
|
|
|
|
|
|
/// Returns a patch descriptor defining the type of patches in the array
|
|
|
|
PatchDescriptor GetDescriptor() const {
|
|
|
|
return _desc;
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Update a patch descriptor
|
|
|
|
void SetDescriptor(PatchDescriptor desc) {
|
|
|
|
_desc = desc;
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
/// Returns a array range struct
|
|
|
|
FarPatchTables::PatchArray::ArrayRange const & GetArrayRange() const {
|
|
|
|
return _range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the index of the first control vertex of the first patch
|
|
|
|
/// of this array in the global PTable
|
|
|
|
unsigned int GetVertIndex() const {
|
|
|
|
return _range.vertIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the global index of the first patch in this array (Used to
|
|
|
|
/// access ptex / fvar table data)
|
|
|
|
unsigned int GetPatchIndex() const {
|
|
|
|
return _range.patchIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of patches in the array
|
|
|
|
unsigned int GetNumPatches() const {
|
|
|
|
return _range.npatches;
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:48:00 +00:00
|
|
|
/// Returns the number of patch indices in the array
|
|
|
|
unsigned int GetNumIndices() const {
|
|
|
|
return _range.npatches * _desc.GetNumControlVertices();
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Returns the offset of quad offset table
|
2013-05-09 20:14:02 +00:00
|
|
|
unsigned int GetQuadOffsetIndex() const {
|
|
|
|
return _range.quadOffsetIndex;
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Set num patches (used at batch glomming)
|
|
|
|
void SetNumPatches(int npatches) {
|
|
|
|
_range.npatches = npatches;
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
private:
|
|
|
|
PatchDescriptor _desc;
|
|
|
|
FarPatchTables::PatchArray::ArrayRange _range;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<PatchArray> PatchArrayVector;
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Constructor
|
2013-05-09 16:23:01 +00:00
|
|
|
OsdDrawContext() : _isAdaptive(false) {}
|
2013-05-10 18:18:41 +00:00
|
|
|
|
|
|
|
/// Descrtuctor
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual ~OsdDrawContext();
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Returns true if the primitive attached to the context uses feature adaptive
|
|
|
|
/// subdivision
|
2013-05-09 16:23:01 +00:00
|
|
|
bool IsAdaptive() const { return _isAdaptive; }
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
// processes FarPatchArrays and inserts requisite sub-patches for the arrays
|
|
|
|
// containing transition patches
|
2013-05-10 02:16:51 +00:00
|
|
|
static void ConvertPatchArrays(FarPatchTables::PatchArrayVector const &farPatchArrays,
|
|
|
|
OsdDrawContext::PatchArrayVector &osdPatchArrays,
|
|
|
|
int maxValence, int numElements);
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
public:
|
|
|
|
// XXXX: move to private member
|
2013-05-09 20:14:02 +00:00
|
|
|
PatchArrayVector patchArrays;
|
2013-05-09 17:53:58 +00:00
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
protected:
|
2013-05-09 17:53:58 +00:00
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
bool _isAdaptive;
|
2012-08-22 23:22:08 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
// Allows ordering of patches by type
|
|
|
|
inline bool
|
|
|
|
OsdDrawContext::PatchDescriptor::operator < ( PatchDescriptor const other ) const
|
|
|
|
{
|
|
|
|
return _farDesc < other._farDesc or (_farDesc == other._farDesc and
|
|
|
|
(_subPatch < other._subPatch or ((_subPatch == other._subPatch) and
|
|
|
|
(_maxValence < other._maxValence or ((_maxValence == other._maxValence) and
|
|
|
|
(_numElements < other._numElements))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
// True if the descriptors are identical
|
|
|
|
inline bool
|
|
|
|
OsdDrawContext::PatchDescriptor::operator == ( PatchDescriptor const other ) const
|
|
|
|
{
|
|
|
|
return _farDesc == other._farDesc and
|
|
|
|
_subPatch == other._subPatch and
|
|
|
|
_maxValence == other._maxValence and
|
|
|
|
_numElements == other._numElements;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-22 23:22:08 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif /* OSD_DRAW_CONTEXT_H */
|