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 <GT/GT_PrimPointMesh.h>
14 
16 public:
18  const char *className() const override { return "GR_SpriteVK"; }
19 
20  void update(RE_RenderContext rc,
21  const GT_PrimitiveHandle &primh,
22  const GR_UpdateParms &parms,
23  const char *cache_name) override;
24 
25  void draw(RE_RenderContext rc,
28  GR_DrawParms dp) override;
29 
30  bool hasTransparency() const override;
31 
32  exint getNumGLPrimitives() const override;
33 
34  bool hasLitSpheres() const { return myIsLitSpheres; }
35 
36  void getPickConnectGroup(unsigned int pick_mode,
38  int &out_connect_start,
39  int &out_connect_num) 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  static bool initShaders(RV_Instance* inst);
49  static void cleanupShaders();
50 
51 private:
52  // maps material id -> connect group index
53  typedef UT_Map<uint32, uint32> ConnectsMap;
54  void uploadIndexBuffer(RV_Render&, const uint32 connect_idx);
55  RV_ShaderProgram *getShader(exint shader_bits, const char *for_what);
56  void fillGeoAlphaBlock(RV_Render&,
57  bool geo_use_blend,
58  const GT_DataArrayHandle sprite_cutoff_attr);
59  // returns whether successful
60  void groupByMaterial(const GT_PrimPointMesh&,
61  const GR_MaterialAtlas&,
62  UT_Int32Array *opaque_mat_group_idxs);
63  void drawMaterialGroup(RE_RenderContext, RV_Render&, GR_RenderMode,
65  uint32 connect_idx);
66  void drawAsPoints(RE_RenderContext rc,
67  const GR_RenderMode mode,
68  const GR_RenderFlags flags,
69  const GR_DrawParms &dp,
70  const uint32 connect_idx);
71 
72  struct TexturedData
73  {
74  UT_String tex_files; // all file names concatenated into one string
75  UT_UniquePtr<RV_ShaderBlock> geo_alpha_cutoff_uniform;
77  OP_Node *parent_node;
78  };
79 
80  // myConnectGroupMats maps
81  // connect_idx -> pair{mat_id, is_idx_buffer_uploaded}. It is necessary to
82  // keep track of whether the current index buffer is uploaded because we
83  // might not know until a call to `draw` whether a connect group is
84  // translucent, because that depends on the AlphaMode material property. In
85  // this case, the index buffer won't have been uploaded in the call to
86  // `update`, so it needs to be uploaded in `draw`, despite the index buffer
87  // not needing to be sorted.
88  UT_Int32Array myConnectGroupMats;
89  UT_Array<UT_Int32Array> mySortedIndexArrays;
90  GT_DataArrayHandle myPoints;
91  struct ViewDistance {
92  fpreal32 view_distance;
93  int32 index;
94  };
95  UT_Array<ViewDistance> myViewDistances;
96  UT_UniquePtr<TexturedData> myTexturedData;
97  signed myTranslucentPassId;
98  bool myHasAlpha : 1;
99  bool myHasNormal : 1;
100  bool myHasRotation : 1;
101  bool myHasSpriteScale : 1;
102  bool myIsLitSpheres : 1;
103  bool myNeedsBlending : 1;
104 };
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:107
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
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:34
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
#define GR_API
Definition: GR_API.h:10
A mesh of unconnected points.
GR_RenderFlags
Definition: GR_Defines.h:86
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:38
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:367
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:18