HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_SpriteVK.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_SpriteVK (GR Library, C++)
7  *
8  * COMMENTS:
9  * Sprite (view-aligned textured quads) rendering for Vulkan.
10  */
11 
12 #include "GR_GeoRenderVK.h"
13 #include "GR_UtilsVK.h"
14 #include <GT/GT_PrimPointMesh.h>
15 
16 #define GPU_SORT
17 
19 public:
21  ~GR_SpriteVK() override;
22  const char *className() const override { return "GR_SpriteVK"; }
23 
24  void update(RE_RenderContext rc,
25  const GT_PrimitiveHandle &primh,
26  const GR_UpdateParms &parms,
27  const char *cache_name) override;
28 
29  void draw(RE_RenderContext rc,
32  GR_DrawParms dp) override;
33 
34  bool hasTransparency() const override;
35 
36  exint getNumGLPrimitives() const override;
37 
38  bool hasLitSpheres() const { return myIsLitSpheres; }
39 
40  void getPickConnectGroup(unsigned int pick_mode,
42  int &out_connect_start,
43  int &out_connect_num) override;
44 
45  void getVkDecorConnectGroup(RV_PrimType render_prim,
46  bool is_uv_view,
47  int &out_connect_start,
48  int &out_connect_num) override;
49 
50  static bool initShaders(RV_Instance* inst);
51  static void cleanupShaders();
52 
53 private:
54  // maps material id -> connect group index
55  typedef UT_Map<uint32, uint32> ConnectsMap;
56  void uploadIndexBuffer(RV_Render&, const uint32 connect_idx);
57  RV_ShaderProgram *getShader(exint shader_bits, const char *for_what);
58  void fillGeoAlphaBlock(RV_Render&,
59  bool geo_use_blend,
60  const GT_DataArrayHandle sprite_cutoff_attr);
61  // returns whether successful
62  void groupByMaterial(const GT_PrimPointMesh&,
63  const GR_MaterialAtlas&,
64  UT_Int32Array *opaque_mat_group_idxs);
65  void drawMaterialGroup(RE_RenderContext, RV_Render&, GR_RenderMode,
67  uint32 connect_idx);
68  void drawAsPoints(RE_RenderContext rc,
69  const GR_RenderMode mode,
70  const GR_RenderFlags flags,
71  const GR_DrawParms &dp,
72  const uint32 connect_idx);
73 
74  struct TexturedData
75  {
76  UT_String tex_files; // all file names concatenated into one string
77  UT_UniquePtr<RV_ShaderBlock> geo_alpha_cutoff_uniform;
79  OP_Node *parent_node;
80  };
81 
82  // myConnectGroupMats maps
83  // connect_idx -> pair{mat_id, is_idx_buffer_uploaded}. It is necessary to
84  // keep track of whether the current index buffer is uploaded because we
85  // might not know until a call to `draw` whether a connect group is
86  // translucent, because that depends on the AlphaMode material property. In
87  // this case, the index buffer won't have been uploaded in the call to
88  // `update`, so it needs to be uploaded in `draw`, despite the index buffer
89  // not needing to be sorted.
90  UT_Int32Array myConnectGroupMats;
91  UT_Array<UT_Int32Array> mySortedIndexArrays;
92  GT_DataArrayHandle myPoints;
93  struct ViewDistance {
94  fpreal32 view_distance;
95  int32 index;
96  };
97  UT_Array<ViewDistance> myViewDistances;
98  UT_UniquePtr<TexturedData> myTexturedData;
99  signed myTranslucentPassId;
100  bool myHasAlpha : 1;
101  bool myHasNormal : 1;
102  bool myHasRotation : 1;
103  bool myHasSpriteScale : 1;
104  bool myIsLitSpheres : 1;
105  bool myNeedsBlending : 1;
106 
107 #ifdef GPU_SORT
109  UT_UniquePtr<RV_VKBuffer> myDistanceBuffer;
110  UT_UniquePtr<RV_VKBuffer> myIndicesBuffer;
111 #endif
112 };
GLbitfield flags
Definition: glcorearb.h:1596
virtual void draw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, GR_DrawParms draw_parms)=0
Normal drawing method. Only issue rendering commands.
int int32
Definition: SYS_Types.h:39
Unsorted map container.
Definition: UT_Map.h:114
static bool initShaders(RV_Instance *inst)
int64 exint
Definition: SYS_Types.h:125
GT_API const UT_StringHolder cache_name
float fpreal32
Definition: SYS_Types.h:200
Temporary container for either a RV_Render and an RE_Render.
virtual exint getNumGLPrimitives() const =0
bool hasLitSpheres() const
Definition: GR_SpriteVK.h:38
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()
GR_RenderMode
Definition: GR_Defines.h:48
virtual bool hasTransparency() const
returns true if this drawable renders some transparent elements
Definition: GR_GeoRender.h:89
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
A mesh of unconnected points.
GR_RenderFlags
Definition: GR_Defines.h:88
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLenum mode
Definition: glcorearb.h:99
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
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
virtual void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const char *cache_name)=0
const char * className() const override
Definition: GR_SpriteVK.h:22
static void cleanupShaders()