HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_OSDSubdData.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_OSDSubdData.C ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Class for subdivision surface data shared between GL and Vulkan.
10  */
11 #ifndef GR_OSDSubdData_h
12 #define GR_OSDSubdData_h
13 
14 #include <GA/GA_EdgeGroup.h>
15 #include <GU/GU_DetailHandle.h>
16 #include <GT/GT_OSD3.h>
17 #include <GT/GT_UtilOpenSubdiv.h>
18 
19 #include "GR_API.h"
20 
21 #define ENABLE_FAS 0
22 
23 class GR_UpdateParms;
24 class GR_PickRecord;
25 
27 {
28 public:
29  struct StencilData
30  {
37 
38  void reset()
39  {
40  sizes.clear();
41  offsets.clear();
42  indices.clear();
43  weight.clear();
44  }
45  };
46 
47 #if ENABLE_FAS
48  struct PatchArray
49  {
50  uint patchType;
51  uint cvPerPatch;
52  uint numPatches;
53  uint patchBase;
54  uint patchIndicesBase;
55  };
56 
57  struct PatchCoord
58  {
59  int arrayIndex;
60  int patchIndex;
61  int vertIndex;
62  float s;
63  float t;
64  };
65 
66  using PatchParam = UT_Vector2T<uint>;
67 
68  struct PatchData
69  {
70  int numArrays;
71  int numTotalPatches;
72  UT_Array<PatchArray> patchArray;
73  UT_Array<uint> patchIndices;
74  UT_Array<UT_Vector2i> patchParams;
75  UT_Array<PatchCoord> patchCoords;
76 
77  void reset()
78  {
79  patchArray.clear();
80  patchIndices.clear();
81  patchParams.clear();
82  }
83  };
84 #endif
85 
86 public:
87  void preUpdate(const GT_PrimitiveHandle &primh,
88  GR_UpdateParms &p);
89 
90  bool isReducedLOD() const { return myReducedLOD; }
91  int getSubdivisionLevel() const { return mySubdLevel; }
92  const GT_PrimitiveHandle &surface() { return mySurface; }
93 
94  void resetSubdivision();
95 
96  /* GPU implementation start */
97  void createStaticOSDContext(
98  const GT_PrimitiveHandle& primh,
99  const GU_ConstDetailHandle &geometry,
100  const uint subdiv_level,
101  bool use_adaptive = false);
102 
104  { return myFullMeshPrimh; }
105 
106  void buildVertexStencilData();
107  void buildFVarStencilData();
108 #if ENABLE_FAS
109  const StencilData* extractLocalPointStencilTableData();
110  const PatchData* extractPatchTableData();
111 #endif
112 
114  { return &myVertexStencilData; }
116  { return &myFVarStencilData; }
117  UT_Int32Array extractVertexPointIndices(uint subdiv_level) const;
118  UT_Int32Array extractFVarVertexIndices(uint subdiv_level) const;
119  UT_Int32Array extractFaceParentIndices(uint subdiv_level) const;
120  const UT_Array<uint> &getAllPointVertices() const;
121  const UT_Array<uint> &getAllEdgeVertices() const;
122  UT_Int32Array extractAllPointCoarsePointIDs() const;
123  UT_Int32Array extractAllEdgeCoarsePointIDs() const;
124  UT_Vector4iArray extractAllEdgePrimInfo() const;
125 
126  UT_Array<uint> extractPointVertices(
127  const UT_Array<uint> &points) const;
128  UT_Array<uint> extractEdgeVertices(
129  const UT_Array<uint> &edges) const;
130  UT_Array<uint> extractFaceVertices(
131  const UT_Array<uint> &faces) const;
132 
133  /// Translate source detail primitive/point/edge indices into the coarse
134  /// OSD face/point/edge indices. The two spaces differ whenever the refined
135  /// mesh only holds a subset of the detail's primitives (for example when
136  /// some are hidden).
137  UT_Array<uint> mapPrimIndicesToCoarseFaces(
138  const UT_Array<uint> &prim_indices) const;
139  UT_Array<uint> mapPointIndicesToCoarseVertices(
140  const UT_Array<uint> &point_indices) const;
141  UT_Array<uint> mapEdgePointPairsToCoarseVertices(
142  const UT_Array<uint> &point_pairs) const;
143 
144  UT_Array<uint> extractEdgeIndices(
145  const UT_Array<uint>& edge_pair_vertices) const;
146  bool getRefinedEdgeDrawRange(
147  uint point0,
148  uint point1,
149  exint &draw_offset,
150  exint &draw_size) const;
151 
152  UT_Int32Array extractSharedIndexBuffer(uint subd_level) const;
153 
154  uint getNumFaces(uint subd_level) const;
155  uint getNumEdges(uint subd_level) const;
157  { return myNumVertices; }
159  { return myNumFVarVertices; }
160 
161 protected:
162  static UT_Int32Array buildCoarsePrimIDs(
163  const GT_PrimitiveHandle &primh,
164  const GU_ConstDetailHandle &geometry,
165  exint num_coarse_faces);
166  static UT_Int32Array buildCoarsePointIDs(
167  const GT_PrimitiveHandle &primh,
168  const GU_ConstDetailHandle &geometry,
169  exint num_coarse_points);
170 
171 private:
172  void buildStencilData(const GT_OSDStencilTable& stencil_table,
173  StencilData& stencil_table_data);
174  /// extract the fine level edges from coarse level edges
175  template <int BranchingFactor, typename ChildGetterFunc>
176  void extractSubdComponents(
177  UT_Array<UT_Array<uint>> &elements_per_level,
178  ChildGetterFunc get_children) const;
179 
180  template <int BranchingFactor, typename VertexGetterFunc>
181  UT_Array<uint> extractSubdComponentVertices(
182  const UT_Array<UT_Array<uint>> &elements_per_level,
183  VertexGetterFunc get_vertices) const;
184 
185  void buildPrimIDToCoarseFaceMap(
186  exint num_coarse_faces) const;
187  void buildPointIDToCoarseVertexMap(
188  exint num_coarse_points) const;
189  bool mapPointIndexToCoarseVertex(
190  uint point,
191  uint &vertex) const;
192 
193  GT_PrimitiveHandle myFullMeshPrimh;
194  GU_ConstDetailHandle myFullMeshGeometry;
195 
196  uint myNumVertices;
197  uint myNumFVarVertices;
198 
199  GT_OSDOptions myOSDOptions;
200  GT_OSDTopology myOSDTopology;
201 
202  GT_OSDStencilTable myOSDVertexStencilTable;
203  GT_OSDStencilTable myOSDFVarStencilTable;
204 
205  StencilData myVertexStencilData;
206  StencilData myFVarStencilData;
207 
208  mutable UT_Array<uint> myAllPointVertices;
209  mutable UT_Array<uint> myAllEdgeVertices;
210  mutable bool myAllPointVerticesBuilt = false;
211  mutable bool myAllEdgeVerticesBuilt = false;
212 
213  mutable UT_Map<int32, uint> myPrimIDToCoarseFace;
214  mutable bool myPrimIDToCoarseFaceBuilt = false;
215  mutable UT_Map<int32, uint> myPointIDToCoarseVertex;
216  mutable bool myPointIDToCoarseVertexBuilt = false;
217 
218 #if ENABLE_FAS
219  void extractPatchArrays(const GT_OSDPatchTable& patch_table);
220  void extractPatchIndices(const GT_OSDPatchTable& patch_table);
221  void extractPatchParam(const GT_OSDPatchTable& patch_table);
222 
223  GT_OSDStencilTable myOSDLocalPointStencilTable;
224  GT_OSDPatchTable myOSDPatchTable;
225 
226  StencilData myLocalPointStencilData;
227  PatchData myPatchData;
228 #endif
229  /* GPU implementation end */
230 
232  GT_PrimitiveHandle mySurface;
233  int64 myVertexAttributeDataIdHash = -1;
234  bool myReducedLOD = false;
235  int mySubdLevel = 0;
236  int myTopID = 0;
237 };
238 
239 #endif
UT_Array< float > weight
int getSubdivisionLevel() const
SIM_API const UT_StringHolder vertex
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
const GT_PrimitiveHandle & surface()
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
2D Vector class.
Definition: UT_Vector2.h:162
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
set of parameters sent to GR_Primitive::update()
GLboolean reset
Definition: glad.h:5138
uint getNumFVarVertices() const
#define GR_API
Definition: GR_API.h:10
long long int64
Definition: SYS_Types.h:116
uint getNumVertices() const
GLdouble t
Definition: glad.h:2397
const GT_PrimitiveHandle getFullMeshPrimh() const
const StencilData * getFVarStencilData() const
const StencilData * getVertexStencilData() const
bool isReducedLOD() const
Topology definition for opensubdiv classes.
Definition: GT_OSD3.h:190
unsigned int uint
Definition: SYS_Types.h:45
Options for topology and refinement.
Definition: GT_OSD3.h:41