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  UT_Array<uint> extractEdgeIndices(
134  const UT_Array<uint>& edge_pair_vertices) const;
135  bool getRefinedEdgeDrawRange(
136  uint point0,
137  uint point1,
138  exint &draw_offset,
139  exint &draw_size) const;
140 
141  UT_Int32Array extractSharedIndexBuffer(uint subd_level) const;
142 
143  uint getNumFaces(uint subd_level) const;
144  uint getNumEdges(uint subd_level) const;
146  { return myNumVertices; }
148  { return myNumFVarVertices; }
149 
150 protected:
151  static UT_Int32Array buildCoarsePrimIDs(
152  const GT_PrimitiveHandle &primh,
153  const GU_ConstDetailHandle &geometry,
154  exint num_coarse_faces);
155 
156 private:
157  void buildStencilData(const GT_OSDStencilTable& stencil_table,
158  StencilData& stencil_table_data);
159  /// extract the fine level edges from coarse level edges
160  template <int BranchingFactor, typename ChildGetterFunc>
161  void extractSubdComponents(
162  UT_Array<UT_Array<uint>> &elements_per_level,
163  ChildGetterFunc get_children) const;
164 
165  template <int BranchingFactor, typename VertexGetterFunc>
166  UT_Array<uint> extractSubdComponentVertices(
167  const UT_Array<UT_Array<uint>> &elements_per_level,
168  VertexGetterFunc get_vertices) const;
169 
170  GT_PrimitiveHandle myFullMeshPrimh;
171  GU_ConstDetailHandle myFullMeshGeometry;
172 
173  uint myNumVertices;
174  uint myNumFVarVertices;
175 
176  GT_OSDOptions myOSDOptions;
177  GT_OSDTopology myOSDTopology;
178 
179  GT_OSDStencilTable myOSDVertexStencilTable;
180  GT_OSDStencilTable myOSDFVarStencilTable;
181 
182  StencilData myVertexStencilData;
183  StencilData myFVarStencilData;
184 
185  mutable UT_Array<uint> myAllPointVertices;
186  mutable UT_Array<uint> myAllEdgeVertices;
187  mutable bool myAllPointVerticesBuilt = false;
188  mutable bool myAllEdgeVerticesBuilt = false;
189 
190 #if ENABLE_FAS
191  void extractPatchArrays(const GT_OSDPatchTable& patch_table);
192  void extractPatchIndices(const GT_OSDPatchTable& patch_table);
193  void extractPatchParam(const GT_OSDPatchTable& patch_table);
194 
195  GT_OSDStencilTable myOSDLocalPointStencilTable;
196  GT_OSDPatchTable myOSDPatchTable;
197 
198  StencilData myLocalPointStencilData;
199  PatchData myPatchData;
200 #endif
201  /* GPU implementation end */
202 
204  GT_PrimitiveHandle mySurface;
205  int64 myVertexAttributeDataIdHash = -1;
206  bool myReducedLOD = false;
207  int mySubdLevel = 0;
208  int myTopID = 0;
209 };
210 
211 #endif
UT_Array< float > weight
int getSubdivisionLevel() const
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