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  ~GR_SpriteVK() override;
19  const char *className() const override { return "GR_SpriteVK"; }
20 
21  void update(RE_RenderContext rc,
22  const GT_PrimitiveHandle &primh,
23  const GR_UpdateParms &parms,
24  const char *cache_name) override;
25 
26  void draw(RE_RenderContext rc,
29  GR_DrawParms dp) override;
30 
31  bool hasTransparency() const override;
32 
33  exint getNumGLPrimitives() const override;
34 
35  bool hasLitSpheres() const { return myIsLitSpheres; }
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  void drawAsPoints(RE_RenderContext rc,
68  const GR_RenderMode mode,
69  const GR_RenderFlags flags,
70  const GR_DrawParms &dp,
71  const uint32 connect_idx);
72 
73  struct TexturedData
74  {
75  UT_String tex_files; // all file names concatenated into one string
76  UT_UniquePtr<RV_ShaderBlock> geo_alpha_cutoff_uniform;
78  OP_Node *parent_node;
79  };
80 
81  // myConnectGroupMats maps
82  // connect_idx -> pair{mat_id, is_idx_buffer_uploaded}. It is necessary to
83  // keep track of whether the current index buffer is uploaded because we
84  // might not know until a call to `draw` whether a connect group is
85  // translucent, because that depends on the AlphaMode material property. In
86  // this case, the index buffer won't have been uploaded in the call to
87  // `update`, so it needs to be uploaded in `draw`, despite the index buffer
88  // not needing to be sorted.
89  UT_Int32Array myConnectGroupMats;
90  UT_Array<UT_Int32Array> mySortedIndexArrays;
91  GT_DataArrayHandle myPoints;
92  struct ViewDistance {
93  fpreal32 view_distance;
94  int32 index;
95  };
96  UT_Array<ViewDistance> myViewDistances;
97  UT_UniquePtr<TexturedData> myTexturedData;
98  signed myTranslucentPassId;
99  bool myHasAlpha : 1;
100  bool myHasNormal : 1;
101  bool myHasRotation : 1;
102  bool myHasSpriteScale : 1;
103  bool myIsLitSpheres : 1;
104  bool myNeedsBlending : 1;
105 };
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:109
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:35
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
RV_API void cleanupShaders()
#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:44
GLenum mode
Definition: glcorearb.h:99
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
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:19