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 { return myHasAlpha; }
31 
32  exint getNumGLPrimitives() const override;
33 
34 
35 
36 
37  void getPickConnectGroup(unsigned int pick_mode,
39  int &out_connect_start,
40  int &out_connect_num) override;
41 
43  PrimitiveType prim_type,
44  RV_PrimType render_prim,
45  RV_Geometry &geo,
46  int &out_connect_start,
47  int &out_connect_num) override;
48 
49  static bool initShaders(RV_Instance* inst);
50  static void cleanupShaders();
51 
52 private:
53  // maps material id -> connect group index
54  typedef UT_Map<uint32, uint32> ConnectsMap;
55  void uploadIndexBuffer(RV_Render&, const uint32 connect_idx);
56  RV_ShaderProgram *getShader(exint shader_bits, const char *for_what);
57  void fillGeoAlphaBlock(RV_Render&,
58  bool geo_use_blend,
59  const GT_DataArrayHandle sprite_cutoff_attr);
60  // returns whether successful
61  void groupByMaterial(const GT_PrimPointMesh&,
62  const GR_MaterialAtlas&,
63  UT_Int32Array *opaque_mat_group_idxs);
64  void drawMaterialGroup(RE_RenderContext, RV_Render&, GR_RenderMode,
66  uint32 connect_idx);
67 
68  struct TexturedData
69  {
70  UT_String tex_files; // all file names concatenated into one string
71  UT_UniquePtr<RV_ShaderBlock> geo_alpha_cutoff_uniform;
73  OP_Node *parent_node;
74  };
75 
76  // myConnectGroupMats maps
77  // connect_idx -> pair{mat_id, is_idx_buffer_uploaded}. It is necessary to
78  // keep track of whether the current index buffer is uploaded because we
79  // might not know until a call to `draw` whether a connect group is
80  // translucent, because that depends on the AlphaMode material property. In
81  // this case, the index buffer won't have been uploaded in the call to
82  // `update`, so it needs to be uploaded in `draw`, despite the index buffer
83  // not needing to be sorted.
84  UT_Int32Array myConnectGroupMats;
85  UT_Array<UT_Int32Array> mySortedIndexArrays;
86  GT_DataArrayHandle myPoints;
87  struct ViewDistance {
88  fpreal32 view_distance;
89  int32 index;
90  };
91  UT_Array<ViewDistance> myViewDistances;
92  UT_UniquePtr<TexturedData> myTexturedData;
93  signed myTranslucentPassId;
94  bool myHasAlpha : 1;
95  bool myHasNormal : 1;
96  bool myHasRotation : 1;
97  bool myHasSpriteScale : 1;
98  bool myIsLitSpheres : 1;
99  bool myCanUseBlending : 1;
100 };
bool hasTransparency() const override
returns true if this drawable renders some transparent elements
Definition: GR_SpriteVK.h:30
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:164
float fpreal32
Definition: SYS_Types.h:200
Temporary container for either a RV_Render and an RE_Render.
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()
GR_RenderMode
Definition: GR_Defines.h:47
#define GR_API
Definition: GR_API.h:10
A mesh of unconnected points.
GR_RenderFlags
Definition: GR_Defines.h:85
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:36
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:345
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