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  bool mapPointIndexToCoarseVertex(
138  uint point, uint &vertex) const;
139  UT_Array<uint> mapPrimIndicesToCoarseFaces(
140  const UT_Array<uint> &prim_indices) const;
141  UT_Array<uint> mapPointIndicesToCoarseVertices(
142  const UT_Array<uint> &point_indices) const;
143  UT_Array<uint> mapEdgePointPairsToCoarseVertices(
144  const UT_Array<uint> &point_pairs) const;
145 
146  UT_Array<uint> extractEdgeIndices(
147  const UT_Array<uint>& edge_pair_vertices) const;
148  bool getRefinedEdgeDrawRange(
149  uint point0,
150  uint point1,
151  exint &draw_offset,
152  exint &draw_size) const;
153 
154  UT_Int32Array extractSharedIndexBuffer(uint subd_level) const;
155 
156  uint getNumFaces(uint subd_level) const;
157  uint getNumEdges(uint subd_level) const;
159  { return myNumVertices; }
161  { return myNumFVarVertices; }
162 
163 protected:
164  static UT_Int32Array buildCoarsePrimIDs(
165  const GT_PrimitiveHandle &primh,
166  const GU_ConstDetailHandle &geometry,
167  exint num_coarse_faces);
168  static UT_Int32Array buildCoarsePointIDs(
169  const GT_PrimitiveHandle &primh,
170  const GU_ConstDetailHandle &geometry,
171  exint num_coarse_points);
172 
173 private:
174  void buildStencilData(const GT_OSDStencilTable& stencil_table,
175  StencilData& stencil_table_data);
176  /// extract the fine level edges from coarse level edges
177  template <int BranchingFactor, typename ChildGetterFunc>
178  void extractSubdComponents(
179  UT_Array<UT_Array<uint>> &elements_per_level,
180  ChildGetterFunc get_children) const;
181 
182  template <int BranchingFactor, typename VertexGetterFunc>
183  UT_Array<uint> extractSubdComponentVertices(
184  const UT_Array<UT_Array<uint>> &elements_per_level,
185  VertexGetterFunc get_vertices) const;
186 
187  void buildPrimIDToCoarseFaceMap(
188  exint num_coarse_faces) const;
189  void buildPointIDToCoarseVertexMap(
190  exint num_coarse_points) const;
191 
192  GT_PrimitiveHandle myFullMeshPrimh;
193  GU_ConstDetailHandle myFullMeshGeometry;
194 
195  uint myNumVertices;
196  uint myNumFVarVertices;
197 
198  GT_OSDOptions myOSDOptions;
199  GT_OSDTopology myOSDTopology;
200 
201  GT_OSDStencilTable myOSDVertexStencilTable;
202  GT_OSDStencilTable myOSDFVarStencilTable;
203 
204  StencilData myVertexStencilData;
205  StencilData myFVarStencilData;
206 
207  mutable UT_Array<uint> myAllPointVertices;
208  mutable UT_Array<uint> myAllEdgeVertices;
209  mutable bool myAllPointVerticesBuilt = false;
210  mutable bool myAllEdgeVerticesBuilt = false;
211 
212  mutable UT_Map<int32, uint> myPrimIDToCoarseFace;
213  mutable bool myPrimIDToCoarseFaceBuilt = false;
214  mutable UT_Map<int32, uint> myPointIDToCoarseVertex;
215  mutable bool myPointIDToCoarseVertexBuilt = false;
216 
217 #if ENABLE_FAS
218  void extractPatchArrays(const GT_OSDPatchTable& patch_table);
219  void extractPatchIndices(const GT_OSDPatchTable& patch_table);
220  void extractPatchParam(const GT_OSDPatchTable& patch_table);
221 
222  GT_OSDStencilTable myOSDLocalPointStencilTable;
223  GT_OSDPatchTable myOSDPatchTable;
224 
225  StencilData myLocalPointStencilData;
226  PatchData myPatchData;
227 #endif
228  /* GPU implementation end */
229 
231  GT_PrimitiveHandle mySurface;
232  int64 myVertexAttributeDataIdHash = -1;
233  bool myReducedLOD = false;
234  int mySubdLevel = 0;
235  int myTopID = 0;
236 };
237 
238 #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