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 <RE/RE_ShaderHandle.h>
19 #include <UT/UT_Map.h>
20 
21 class RV_Geometry;
22 class RV_Render;
23 class RV_ShaderProgram;
24 class GR_Material;
25 
27 {
28 public:
30  ~GR_PolySurfaceVK() override;
31 
32  const char *className() const override { return "GR_PolySurfaceVK"; }
33 
34  void getPickConnectGroup(unsigned int pick_mode,
35  GR_PickGeometry pick_geo,
36  int &out_connect_start,
37  int &out_connect_num) override;
38 
39  RV_Geometry *getVkPickGeometry(unsigned int pick_mode) override;
40 
42  PrimitiveType prim_type,
43  RV_PrimType render_prim,
44  RV_Geometry &geo,
45  int &out_connect_start,
46  int &out_connect_num) override;
47 
48  void update(RE_RenderContext rc,
49  const GT_PrimitiveHandle &primh,
50  const GR_UpdateParms &parms,
51  const char *cache_name) override;
52 
53  void draw(RE_RenderContext rc,
56  GR_DrawParms dp) override;
57 
58  exint getNumGLPrimitives() const override;
59  bool hasTransparency() const override
60  { return myHasAlpha || myHasBlendedMaterial; }
61 
62  // Enable backface culling and face winding for the draw, accounting for
63  // the winding order of this polysurface's geometry
64  void enableBackfaceCulling(RV_Render* r, bool do_cull) const;
65  bool hasReverseWinding() const { return myWindingOrder; }
66  bool hasAutoGenNormals() const { return myAutoGenNormal; }
67 
68  static bool initShaders(RV_Instance* inst);
69  static void cleanupShaders();
70 
71  const GT_PrimitiveHandle &getMesh() const { return myFlattenedMesh; }
72  const GT_PrimitiveHandle &getConvexedMesh() const {return myConvexedMesh;}
73 
74  bool supportsRayTrace() const override { return true; }
75 
77  int tag,
78  int light_id,
79  const UT_Matrix4F &obj_mat) override;
81 
82 private:
83 
84  void updateSurface(RV_Render *r,
85  GT_PrimPolygonMesh *pmesh,
86  const GR_UpdateParms &p,
87  bool needs_tangents,
88  GR_Material *material,
89  const char *cache_name);
90 
91  void convexAndFlattenMesh(GT_PrimPolygonMesh *pmesh,
92  const GR_UpdateParms &parms,
93  bool needs_tangents,
94  GT_PrimPolygonMesh* &out_cmesh,
95  bool &out_flattened);
96 
97  void buildNormals(GT_PrimPolygonMesh *pmesh,
98  const GR_UpdateParms &parms,
99  bool needs_tangents,
100  GT_PrimPolygonMesh* &out_nmesh);
101 
102  void buildSurfaceConnectivity(const GT_PrimPolygonMesh *pmesh,
103  const GR_UpdateParms &parms,
104  UT_Int32Array &connect_indices);
105 
106  void buildVertexNumbers(const GT_PrimPolygonMesh *pmesh,
107  const GR_UpdateParms &parms,
108  GT_Int8Array &vert_num);
109 
110  void buildWireframeConnectivity(
111  const GT_PrimPolygonMesh *pmesh,
112  const GR_UpdateParms &parms,
113  UT_Int32Array &connect_indices,
114  UT_Int32Array &faces,
115  bool target_vert = false);
116 
117  void buildRTSurfaceConnectivity(const GT_PrimPolygonMesh *pmesh,
118  const GR_UpdateParms &parms,
119  UT_Int32Array &connect_indices);
120 
121  void buildUVBoundaryConnectivity(
122  const GT_PrimPolygonMesh *pmesh,
123  const GR_UpdateParms &p,
124  UT_Int32Array &connect,
125  UT_Int32Array &face_list);
126 
127  void buildInstanceTransform(RV_Render *r,
128  GT_PrimitiveHandle primh,
129  const GR_UpdateParms &p,
130  RV_Geometry *geo);
131 
132  RV_ShaderProgram * fetchShader(RV_Render *r,
135  const GR_Material *mat,
136  const GR_DisplayOption *opts,
137  bool &uses_mat);
138 
139  bool updateBoneTransforms(RV_Render *r,
140  const GT_DataArrayHandle &a);
141 
142  void updateBlendShapes(RV_Render *r,
143  const GT_DataArrayHandle &a);
144 
145  bool needsSkinningOrBlendshapes(GR_RenderFlags flags) const;
146  bool applyDisplacementMap(RE_RenderContext rc,
147  const GR_UpdateParms &p,
148  GR_Material *mat);
149  void generateNormalsGPU(RV_Render *r,
150  const GR_DisplayOption &opts);
151 
152 
153  GT_PrimitiveHandle myNormalMesh; // with generated normals
154  GT_PrimitiveHandle myTangentMesh; // with generated tangents
155  GT_PrimitiveHandle myFlattenedMesh; // with only Point/Detail attribs
156 
157  GT_PrimitiveHandle myBaseMesh; // original
158  GT_PrimitiveHandle myConvexedMesh; // convexed
159 
160  GT_DataArrayHandle myGeneratedNormals;
161  GT_Owner myNormalsOwner;
162  GT_DataArrayHandle myGeneratedTangents;
163  GT_Owner myTangentsOwner;
164  GT_DataArrayHandle myGeneratedBitangents;
165  GT_Owner myBitangentsOwner;
166 
167  GT_DataArrayHandle myConvexUniformIndirect;
168  GT_DataArrayHandle myConvexVertexIndirect;
169  GT_DataArrayHandle myConvexVertexList;
170  GT_DataArrayHandle myConvexPrimInfo;
171  GT_DataArrayHandle myConvexVertInfo;
172 
173  UT_StringHolder myUVAttrib;
174  int64 myUVver;
175 
176  int myMaterialID = 0;
177  bool myHasTangents = false;
178  bool myWindingOrder = false;
179  bool myAutoGenNormal = false;
180  bool myIsFlattened = false;
181  bool myHasCd = false;
182  bool myHasAlpha = false;
183  bool myHasBlendedMaterial = false;
184  bool myHasNormalOffsets = false;
185  bool myRanDisplacement = false;
186  int myNumBlendShapes = 0;
187  int myNumBoneTransforms = 0;
188 
189  int64 myTopVersion = -1;
190  int64 myPointVer = -1;
191  UT_UniquePtr<RV_Geometry> myDisplaceGeometry;
192 
193  gr_SetCache myBoneBlendSet;
194  UT_UniquePtr<RV_ShaderBlock> myBoneTransforms;
195  UT_UniquePtr<RV_ShaderBlock> myBlendShapes;
196  bool myIsMatXMaterial = false;
197  UT_UniquePtr<GT_GEOOffsetList> myVertexOffsets;
198 
199  UT_UniquePtr<RV_VKBuffer> myNormalScratchBuffer;
200  UT_UniquePtr<RV_ShaderVariableSet> myNormalGenSet;
201  UT_UniquePtr<RV_ShaderVariableSet> myNormalMergeSet;
202 
203  UT_UniquePtr<RV_ShaderVariableSet> myTessellateInSet;
204  UT_UniquePtr<RV_ShaderVariableSet> myTessellateOutSet;
205 
206  static UT_Map<exint, RV_ShaderProgram *> theProgramMap;
207 };
208 
209 #endif
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.
virtual void getVkDecorGeometry(GR_DecorationRender::PrimitiveType prim_type, RV_PrimType render_prim, RV_Geometry &geo, int &out_connect_start, int &out_connect_num)
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
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 hasAutoGenNormals() const
GR_RenderMode
Definition: GR_Defines.h:48
RV_API void cleanupShaders()
#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:44
bool supportsRayTrace() const override
const GT_PrimitiveHandle & getConvexedMesh() const
GLenum mode
Definition: glcorearb.h:99
GT_Owner
Definition: GT_Types.h:90
RV_API bool initShaders(RV_Instance *inst)
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:424
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
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
virtual RV_VKAccelerationStructure * getAccelerationStructure()