HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PolySurfaceVK.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_PolySurfaceVK ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Line and ribbon primitive.
10  */
11 #ifndef GR_PolySurfaceVK_h
12 #define GR_PolySurfaceVK_h
13 
14 #include "GR_API.h"
15 #include "GR_GeoRenderVK.h"
16 #include <GT/GT_PrimPolygonMesh.h>
17 #include <RV/RV_Geometry.h>
18 #include <UT/UT_Map.h>
19 
20 class RV_Geometry;
21 class RV_Render;
22 class RV_ShaderProgram;
23 class GR_Material;
24 class RV_VKBuffer;
25 
26 namespace GR_Utils
27 {
28 class RadixSortGPU;
29 }
30 
32 {
33 public:
35  ~GR_PolySurfaceVK() override;
36 
37  const char *className() const override { return "GR_PolySurfaceVK"; }
38 
39  void getPickConnectGroup(unsigned int pick_mode,
40  GR_PickGeometry pick_geo,
41  int &out_connect_start,
42  int &out_connect_num) override;
43 
44  RV_Geometry *getVkPickGeometry(unsigned int pick_mode) override;
45 
46  void getVkDecorConnectGroup(RV_PrimType render_prim,
47  bool is_uv_view,
48  int &out_connect_start,
49  int &out_connect_num) override;
50 
51  void update(RE_RenderContext rc,
52  const GT_PrimitiveHandle &primh,
53  const GR_UpdateParms &parms,
54  const char *cache_name) override;
56  const GR_DisplayOption &opts,
57  const char *cache_name,
58  RE_CacheVersion geo_version,
59  RE_CacheVersion select_version) override;
60 
61  void draw(RE_RenderContext rc,
64  GR_DrawParms dp) override;
65 
66  exint getNumGLPrimitives() const override;
67  bool hasTransparency() const override
68  { return myHasAlpha || myHasBlendedMaterial; }
69  bool needsViewUpdate() const { return myTransparencySort; }
70 
71  // Enable backface culling and face winding for the draw, accounting for
72  // the winding order of this polysurface's geometry
73  void enableBackfaceCulling(RV_Render* r, bool do_cull) const;
74  bool hasReverseWinding() const { return myWindingOrder; }
75  bool hasAutoGenNormals() const { return myAutoGenNormal; }
76  void setTransparencyFlags(bool sort_enabled)
77  {
78  myUseParentTransparencyFlags = true;
79  myParentTransparencySort = sort_enabled;
80  }
81 
82  static bool initShaders(RV_Instance* inst);
83  static void cleanupShaders();
84 
85  const GT_PrimitiveHandle &getMesh() const { return myFlattenedMesh; }
86  const GT_PrimitiveHandle &getConvexedMesh() const {return myConvexedMesh;}
87 
88  bool supportsRayTrace() const override { return true; }
89  void retireGeometry() override;
90 
92  int tag,
93  int light_id,
94  const UT_Matrix4F &obj_mat) override;
96 
97 protected:
98  // This function takes exclusive ownership of the subdivision geometry
99  // object, which will be used to draw subdivided surface by PolySurfaceVK.
100  // Called after subdivision surface setup in OSDSubdSurfaceVK::update().
101  void setupSubDGeometry(UT_UniquePtr<RV_Geometry> geo);
103  { return std::move(mySubDGeometry); }
105  { return mySubDGeometry.get(); }
106 
107  // Update only the draw state needed for subdivision path. Returns false when
108  // the caller should fall back to the full PolySurfaceVK::update().
109  bool syncSubDRenderState(RE_RenderContext rc,
110  GT_PrimPolygonMesh *pmesh,
111  const GR_UpdateParms &p);
112 
113 private:
114  void clearTransparencySortGPU();
115  void setupTransparencySortGPU(RV_Render *r,
116  const GT_PrimPolygonMesh *pmesh,
117  exint tri_count);
118 
119  void updateSurface(RV_Render *r,
120  GT_PrimPolygonMesh *pmesh,
121  const GR_UpdateParms &p,
122  bool needs_tangents,
123  GR_Material *material,
124  const char *cache_name);
125 
126  void convexAndFlattenMesh(GT_PrimPolygonMesh *pmesh,
128  bool needs_tangents,
129  GT_PrimPolygonMesh* &out_cmesh,
130  bool &out_flattened);
131 
132  void buildNormals(GT_PrimPolygonMesh *pmesh,
133  const GR_UpdateParms &parms,
134  bool needs_tangents,
135  GT_PrimPolygonMesh* &out_nmesh);
136 
137  void buildSurfaceConnectivity(const GT_PrimPolygonMesh *pmesh,
138  const GR_UpdateParms &parms,
139  UT_Int32Array &connect_indices);
140 
141  void buildVertexNumbers(const GT_PrimPolygonMesh *pmesh,
142  const GR_UpdateParms &parms,
143  GT_Int8Array &vert_num);
144 
145  void buildWireframeConnectivity(
146  const GT_PrimPolygonMesh *pmesh,
147  const GR_UpdateParms &parms,
148  UT_Int32Array &connect_indices,
149  UT_Int32Array &faces,
150  bool target_vert = false);
151 
152  void buildRTSurfaceConnectivity(const GT_PrimPolygonMesh *pmesh,
153  const GR_UpdateParms &parms,
154  UT_Int32Array &connect_indices);
155 
156  void buildUVBoundaryConnectivity(
157  const GT_PrimPolygonMesh *pmesh,
158  const GR_UpdateParms &p,
159  UT_Int32Array &connect,
160  UT_Int32Array &face_list);
161 
162  void buildInstanceTransform(RV_Render *r,
163  GT_PrimitiveHandle primh,
164  const GR_UpdateParms &p,
165  RV_Geometry *geo);
166 
167  RV_ShaderProgram * fetchShader(RV_Render *r,
170  const GR_Material *mat,
171  const GR_DisplayOption *opts,
172  bool &uses_mat);
173 
174  bool updateBoneTransforms(RV_Render *r,
175  const GT_DataArrayHandle &a);
176 
177  void updateBlendShapes(RV_Render *r,
178  const GT_DataArrayHandle &a);
179 
180  bool needsSkinningOrBlendshapes(GR_RenderFlags flags) const;
181  bool applyDisplacementMap(RE_RenderContext rc,
182  const GR_UpdateParms &p,
183  GR_Material *mat);
184 
185 
186  GT_PrimitiveHandle myNormalMesh; // with generated normals
187  GT_PrimitiveHandle myTangentMesh; // with generated tangents
188  GT_PrimitiveHandle myFlattenedMesh; // with only Point/Detail attribs
189 
190  GT_PrimitiveHandle myBaseMesh; // original
191  GT_PrimitiveHandle myConvexedMesh; // convexed
192  GT_PrimitiveHandle myTransparencySortMesh;
193 
194  GT_DataArrayHandle myGeneratedNormals;
195  GT_Owner myNormalsOwner;
196  GT_DataArrayHandle myGeneratedTangents;
197  GT_Owner myTangentsOwner;
198  GT_DataArrayHandle myGeneratedBitangents;
199  GT_Owner myBitangentsOwner;
200 
201  GT_DataArrayHandle myConvexUniformIndirect;
202  GT_DataArrayHandle myConvexVertexIndirect;
203  GT_DataArrayHandle myConvexVertexList;
204  GT_DataArrayHandle myConvexPrimInfo;
205  GT_DataArrayHandle myConvexVertInfo;
206 
207  UT_StringHolder myUVAttrib;
208  int64 myUVver;
209 
210  int myMaterialID = 0;
211  bool myHasTangents = false;
212  bool myWindingOrder = false;
213  bool myAutoGenNormal = false;
214  bool myIsFlattened = false;
215  bool myHasCd = false;
216  bool myHasAlpha = false;
217  bool myHasBlendedMaterial = false;
218  bool myTransparencySort = false;
219  bool myUseParentTransparencyFlags = false;
220  bool myParentTransparencySort = false;
221  bool myHasNormalOffsets = false;
222  bool myRanDisplacement = false;
223  int myNumBlendShapes = 0;
224  int myNumBoneTransforms = 0;
225 
226  int64 myTopVersion = -1;
227  int64 myPointVer = -1;
228  UT_UniquePtr<RV_Geometry> myDisplaceGeometry;
229 
230  UT_UniquePtr<RV_Geometry> mySubDGeometry;
231 
232  gr_SetCache myBoneBlendSet;
233  UT_UniquePtr<RV_ShaderBlock> myBoneTransforms;
234  UT_UniquePtr<RV_ShaderBlock> myBlendShapes;
235  bool myIsMatXMaterial = false;
236  UT_UniquePtr<GT_GEOOffsetList> myVertexOffsets;
237 
238  UT_UniquePtr<RV_ShaderVariableSet> myTessellateInSet;
239  UT_UniquePtr<RV_ShaderVariableSet> myTessellateOutSet;
240  UT_UniquePtr<RV_ShaderVariableSet> myTransparencySortKeysInSet;
241  UT_UniquePtr<RV_ShaderVariableSet> myTransparencySortKeysOutSet;
242  UT_UniquePtr<RV_ShaderVariableSet> myTransparencySortRebuildInSet;
243  UT_UniquePtr<RV_ShaderVariableSet> myTransparencySortRebuildOutSet;
244  UT_UniquePtr<RV_VKBuffer> myTransparencySourceIndexBuffer;
245  UT_UniquePtr<RV_VKBuffer> myTransparencyVertexIndexBuffer;
246  UT_UniquePtr<RV_VKBuffer> myTransparencySortKeysBuffer;
247  UT_UniquePtr<RV_VKBuffer> myTransparencySortPrimitiveBuffer;
248  UT_UniquePtr<RV_VKBuffer> myTransparencySortedIndexBuffer;
249  UT_UniquePtr<GR_Utils::RadixSortGPU> myTransparencyRadixSort;
250  UT_Int32Array myTransparencySortIndices;
251  exint myTransparencySortPrimitiveCount = 0;
252 
253  static UT_Map<exint, RV_ShaderProgram *> theProgramMap;
254 };
255 
256 #endif
void setTransparencyFlags(bool sort_enabled)
GLbitfield flags
Definition: glcorearb.h:1596
const char * className() const override
virtual void draw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, GR_DrawParms draw_parms)=0
Normal drawing method. Only issue rendering commands.
const GT_PrimitiveHandle & getMesh() const
A mesh of polygons.
static bool initShaders(RV_Instance *inst)
int64 exint
Definition: SYS_Types.h:125
GT_API const UT_StringHolder cache_name
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
RV_Geometry * getSubDGeometry() const
bool hasReverseWinding() const
Temporary container for either a RV_Render and an RE_Render.
virtual RV_Geometry * getVkPickGeometry(unsigned int pick_mode)
Definition: GR_GeoRender.h:128
virtual exint getNumGLPrimitives() const =0
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
set of parameters sent to GR_Primitive::update()
bool needsViewUpdate() const
bool hasAutoGenNormals() const
GR_RenderMode
Definition: GR_Defines.h:48
UT_UniquePtr< RV_Geometry > takeSubDGeometry()
virtual void getVkDecorConnectGroup(RV_PrimType render_prim, bool is_uv_view, int &out_connect_start, int &out_connect_num)
#define GR_API
Definition: GR_API.h:10
long long int64
Definition: SYS_Types.h:116
virtual void updateAccelerationStructure(RV_Render *r, int tag, int light_id, const UT_Matrix4F &obj_mat)
GR_RenderFlags
Definition: GR_Defines.h:88
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
bool supportsRayTrace() const override
const GT_PrimitiveHandle & getConvexedMesh() const
GLenum mode
Definition: glcorearb.h:99
GT_Owner
Definition: GT_Types.h:90
virtual void retireGeometry()
Definition: GR_GeoRender.h:86
virtual void getPickConnectGroup(unsigned int pick_mode, GR_PickGeometry pick_geo, int &out_connect_start, int &out_connect_num)
Definition: GR_GeoRender.h:100
GR_PickGeometry
Definition: GR_PickRecord.h:60
RV_PrimType
Definition: RV_Type.h:356
GA_API const UT_StringHolder parms
bool hasTransparency() const override
returns true if this drawable renders some transparent elements
An array of numeric values (int32, int64, fpreal16, fpreal32, fpreal64)
Definition: GT_DANumeric.h:23
Simple class for a mutli-integer cache tag.
virtual void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const char *cache_name)=0
GLboolean r
Definition: glcorearb.h:1222
A vulkan buffer object.
Definition: RV_VKBuffer.h:75
virtual RV_VKAccelerationStructure * getAccelerationStructure()
static void cleanupShaders()
virtual void viewUpdate(RE_RenderContext r, const GR_DisplayOption &opts, const char *cache_name, RE_CacheVersion geo_version, RE_CacheVersion select_version)
Definition: GR_GeoRender.h:64