2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-08-22 23:22:08 +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:
|
2012-08-22 23:22:08 +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.
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-08-22 23:22:08 +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.
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#ifndef OPENSUBDIV3_OSD_DRAW_CONTEXT_H
|
|
|
|
#define OPENSUBDIV3_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
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
#include "../far/patchDescriptor.h"
|
|
|
|
#include "../far/types.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 {
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
namespace Far {
|
|
|
|
class PatchTables;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Osd {
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// \brief Base DrawContext class
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
/// DrawContext derives several sub-classes with API specific functionality
|
|
|
|
/// (GL, D3D11, ...).
|
2013-05-10 18:18:41 +00:00
|
|
|
///
|
|
|
|
/// Current specificiation GPU hardware tessellation limitations require transition
|
2014-09-05 22:07:46 +00:00
|
|
|
/// patches to be split-up into several triangular bi-cubic sub-patches.
|
|
|
|
/// DrawContext processes FarPatchArrays from Far::PatchTables and generates the
|
2013-05-10 18:18:41 +00:00
|
|
|
/// additional sets of sub-patches.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
/// Contexts interface the serialized topological data pertaining to the
|
|
|
|
/// geometric primitives with the capabilities of the selected discrete
|
2013-05-10 18:18:41 +00:00
|
|
|
/// compute device.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
class DrawContext {
|
2013-05-10 18:18:41 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
public:
|
2014-11-25 20:41:19 +00:00
|
|
|
typedef Far::Index Index;
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
class PatchArray {
|
|
|
|
public:
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Constructor
|
|
|
|
///
|
2014-11-25 20:41:19 +00:00
|
|
|
/// @param desc Patch descriptor defines the type, pattern, rotation of
|
|
|
|
/// the patches in the array
|
|
|
|
///
|
|
|
|
/// @param npatches The number of patches in the array
|
|
|
|
///
|
|
|
|
/// @param vertIndex Index of the first control vertex in the array
|
|
|
|
///
|
|
|
|
/// @param patchIndex Index of the first patch in the array
|
2013-05-10 18:18:41 +00:00
|
|
|
///
|
2014-11-25 20:41:19 +00:00
|
|
|
/// @param qoIndex Index of the first quad-offset entry
|
2013-05-10 18:18:41 +00:00
|
|
|
///
|
2015-05-12 01:06:46 +00:00
|
|
|
PatchArray(Far::PatchDescriptor desc, int npatches,
|
2014-11-25 20:41:19 +00:00
|
|
|
Index vertIndex, Index patchIndex, Index qoIndex) :
|
|
|
|
_desc(desc), _npatches(npatches),
|
|
|
|
_vertIndex(vertIndex), _patchIndex(patchIndex), _quadOffsetIndex(qoIndex) { }
|
2013-05-09 20:14:02 +00:00
|
|
|
|
|
|
|
/// Returns a patch descriptor defining the type of patches in the array
|
2015-05-12 01:06:46 +00:00
|
|
|
Far::PatchDescriptor GetDescriptor() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _desc;
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Update a patch descriptor
|
2015-05-12 01:06:46 +00:00
|
|
|
void SetDescriptor(Far::PatchDescriptor desc) {
|
2013-05-10 02:16:51 +00:00
|
|
|
_desc = desc;
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
/// Returns the index of the first control vertex of the first patch
|
|
|
|
/// of this array in the global PTable
|
|
|
|
unsigned int GetVertIndex() const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return _vertIndex;
|
2013-05-09 20:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the global index of the first patch in this array (Used to
|
|
|
|
/// access ptex / fvar table data)
|
|
|
|
unsigned int GetPatchIndex() const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return _patchIndex;
|
2013-05-09 20:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of patches in the array
|
|
|
|
unsigned int GetNumPatches() const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return _npatches;
|
2013-05-09 20:14:02 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 20:48:00 +00:00
|
|
|
/// Returns the number of patch indices in the array
|
|
|
|
unsigned int GetNumIndices() const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return _npatches * _desc.GetNumControlVertices();
|
2013-05-09 20:48:00 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2014-11-25 20:41:19 +00:00
|
|
|
return _quadOffsetIndex;
|
2013-05-09 20:14:02 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 02:16:51 +00:00
|
|
|
/// Set num patches (used at batch glomming)
|
|
|
|
void SetNumPatches(int npatches) {
|
2014-11-25 20:41:19 +00:00
|
|
|
_npatches = npatches;
|
2013-05-10 02:16:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
private:
|
2015-05-12 01:06:46 +00:00
|
|
|
Far::PatchDescriptor _desc;
|
2014-11-25 20:41:19 +00:00
|
|
|
int _npatches;
|
|
|
|
Index _vertIndex,
|
|
|
|
_patchIndex,
|
|
|
|
_quadOffsetIndex;
|
2013-05-09 20:14:02 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Constructor
|
2015-05-12 01:06:46 +00:00
|
|
|
DrawContext(int maxValence) : _isAdaptive(false), _maxValence(maxValence) {}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Descrtuctor
|
2014-09-05 22:07:46 +00:00
|
|
|
virtual ~DrawContext();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
/// Returns true if the primitive attached to the context uses feature adaptive
|
|
|
|
/// subdivision
|
2014-09-05 22:07:46 +00:00
|
|
|
bool IsAdaptive() const {
|
|
|
|
return _isAdaptive;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::vector<PatchArray> PatchArrayVector;
|
|
|
|
|
|
|
|
PatchArrayVector const & GetPatchArrays() const {
|
|
|
|
return _patchArrays;
|
|
|
|
}
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2014-09-10 22:24:16 +00:00
|
|
|
/// The writable accessor to the internal patch array (tentative).
|
|
|
|
/// We should have a different api something like ConvertPatchArrays().
|
|
|
|
PatchArrayVector &GetPatchArrays() {
|
|
|
|
return _patchArrays;
|
|
|
|
}
|
|
|
|
|
2013-05-10 18:18:41 +00:00
|
|
|
// processes FarPatchArrays and inserts requisite sub-patches for the arrays
|
|
|
|
// containing transition patches
|
2014-11-25 20:41:19 +00:00
|
|
|
static void ConvertPatchArrays(Far::PatchTables const &patchTables,
|
2015-05-12 01:06:46 +00:00
|
|
|
DrawContext::PatchArrayVector &osdPatchArrays);
|
2013-05-10 02:16:51 +00:00
|
|
|
|
2015-05-12 01:06:46 +00:00
|
|
|
// maxValence is needed for legacy gregorypatch drawing
|
|
|
|
int GetMaxValence() const {
|
|
|
|
return _maxValence;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
typedef std::vector<float> FVarData;
|
2013-05-09 17:53:58 +00:00
|
|
|
|
2015-05-12 01:06:46 +00:00
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
protected:
|
2013-05-09 17:53:58 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
static void packPatchVerts(Far::PatchTables const & patchTables,
|
|
|
|
std::vector<Index> & dst);
|
|
|
|
|
2015-02-09 01:31:55 +00:00
|
|
|
static void packSharpnessValues(Far::PatchTables const & patchTables,
|
|
|
|
std::vector<unsigned int> & dst);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static void packFVarData(Far::PatchTables const & patchTables,
|
2014-11-25 20:41:19 +00:00
|
|
|
int fvarWidth, FVarData const & src, FVarData & dst);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// XXXX: move to private member
|
|
|
|
PatchArrayVector _patchArrays;
|
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
bool _isAdaptive;
|
2013-05-10 18:18:41 +00:00
|
|
|
|
2015-05-12 01:06:46 +00:00
|
|
|
int _maxValence;
|
|
|
|
};
|
2013-05-10 18:18:41 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Osd
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
2012-08-22 23:22:08 +00:00
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#endif /* OPENSUBDIV3_OSD_DRAW_CONTEXT_H */
|