HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PrimPacked.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_PrimPacked.h (GR Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef __GR_PrimPacked__
11 #define __GR_PrimPacked__
12 
13 #include "GR_Primitive.h"
14 #include "GR_MaterialGroups.h"
15 
16 #include <UT/UT_UniquePtr.h>
17 #include <RE/RE_VertexArray.h>
18 
19 #ifdef USE_VULKAN
20 class GR_InstanceBuffer;
21 class GR_GeoRender;
22 typedef UT_UniquePtr<GR_InstanceBuffer> GR_InstanceBufferPtr;
23 #endif
24 
26 {
27 public:
28  GR_PrimPacked(const GR_RenderInfo *info,
29  const char *cache_name,
30  const GT_PrimitiveHandle &packed_prim,
31  const GT_PrimitiveHandle &instanced_prim,
32  const GU_ConstDetailHandle &instanced_gdp,
33  int prim_index = -1);
34 
35  ~GR_PrimPacked() override;
36 
37  const char *className() const override { return "GR_PrimPacked"; }
38 
40  { return GR_BASE_PRIM_PACKED; }
42  { return myInstancedPrim; }
43 
44  const GT_PrimitiveHandle &instancePrim() const { return myInstancedPrim; }
45  const GT_PrimitiveHandle &packedPrim() const { return myPackedPrim; }
46 
47  void setPackedPrim(const GT_PrimitiveHandle &packed_prim);
48  void setInstancedPrim(const GT_PrimitiveHandle &instance,
49  const GU_ConstDetailHandle &inst_gdp);
50  void setPrimIndex(int pindex)
51  { myPrimIndex = pindex; }
52 
54  int geo_type,
55  const GT_PrimitiveHandle &ph,
56  const GEO_Primitive *prim) override;
57 
59  const GT_PrimitiveHandle &primh,
60  const GR_UpdateParms &p) override;
61 
65  const GR_DrawParms &dp,
66  const UT_Matrix4D &proj_view,
67  const UT_Matrix4D &object,
68  const UT_Vector2F &min_proj_size,
69  bool &visible,
70  bool &defer) override;
71 
73  GR_RenderMode render_mode,
75  GR_DrawParms dp) override;
76 
78  GR_Decoration decor,
79  const GR_DecorationParms &parms) override;
81  const GR_DisplayOption *opt,
82  unsigned int pick_type,
83  GR_PickStyle pick_style,
84  bool has_pick_map) override;
85 
86  bool checkForTransformChange();
87 
88  // Delegate these to the child prim.
89  GR_DispOptChange displayOptionChange(
90  const GR_DisplayOption &opts,
91  bool first_init) override;
92  bool updateOnViewChange(
93  const GR_DisplayOption &) const override;
94  void viewUpdate(
96  const GR_ViewUpdateParms &parms) override;
97  bool needsGLStateCheck(
98  const GR_DisplayOption &opts) const override;
99  bool checkGLState(
101  const GR_DisplayOption &opt) override;
102  bool setup(const GR_DisplayOption *) override;
103  void cleanup(RE_RenderContext r) override;
104 
105  bool requiresAlphaPass() const override;
106  const GA_Primitive *getGAPrimitive(const GU_Detail *gdp,
107  exint primitive_id) const override;
108  exint getGAVertex(const GU_Detail *gdp,
109  exint vertex_id) const override;
111  bool renderInAlphaPass(GR_AlphaPass a) override;
112  bool inViewFrustum(
113  const UT_Matrix4D &objviewproj,
114  const UT_BoundingBoxD *bbox = nullptr) override;
115  bool isRasterizedInView(
116  const UT_Matrix4F &objviewproj,
117  const UT_Vector2F &min_proj_size,
118  const UT_BoundingBoxF *bbox) override;
119  bool getBoundingBox(UT_BoundingBoxD &bbox) const override;
120 
121  exint getNumGLPrimitives(const GR_DisplayOption *) override;
122  void retirePrimitive() override;
123 
124  GR_SelectMode getSelectionMode(const GU_Detail &gdp,
126 
127  void setPickID(GA_Index prim_id, GA_Index point_id);
128 
129  void setInstanceHookPrim(GR_Primitive *prim);
130 
131  bool isPrimVisible() const override
132  { return myPrimVisible; }
133  void setPrimVisible(bool v)
134  { myPrimVisible = v; }
135 
136 
137  bool supportsParallelDraw() const override;
138 
139 protected:
140  virtual int getNumInstances() const { return 1; }
141  virtual UT_Matrix4D getTransform(int ) const
142  { return myInstancePrimTransform; }
143  virtual bool isFragment() const { return false; }
144  virtual bool getSingleTransform(UT_Matrix4D &mat) const
145  { mat = myInstancePrimTransform; return true; }
146 
147  bool updateCacheName(const GT_PrimitiveHandle &iph,
148  const GR_UpdateParms &p,
149  bool fallback);
150  void updateInstanceGeometry(RE_RenderContext r,
151  const GT_PrimitiveHandle &container_prim,
152  const GR_UpdateParms &p,
153  bool build_anchors,
154  GR_UpdateReason full_update);
155 
156  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
157  virtual void buildAnchorsGL3(RE_RenderContext r,
158  const GR_UpdateParms &p,
159  GR_UpdateReason full_reason,
160  const GT_PrimitiveHandle &xforms);
161  void buildPickID(const GT_PrimitiveHandle &pid);
162  RE_Geometry *buildPickBBox(RE_RenderContext r) const;
163  void buildInstPrimTransform();
164 
165  // Given the packed geometry handle and the update reason for the packed
166  // primitive, determine the update reason for the packed geometry.
167  GR_UpdateReason checkForPackedGeoChanges(const GT_PrimitiveHandle &ph,
168  GR_UpdateReason reason);
169  GR_UpdateParms checkForPackedMaterialAssignment(const GR_UpdateParms &p);
170 
171  void updateLightLinking();
172  void updateLinkMap(const UT_StringRef &attrib_name,
173  UT_StringMap<int> &link_map,
174  UT_StringArray &list,
175  bool &has_link);
176  bool setLightLinkMask(RE_RenderContext rc,
177  GR_DrawParms &dp,
178  int &prev_mask) const;
179  void restoreLightLinkMask(RE_RenderContext rc,
180  GR_DrawParms &dp,
181  int prev_mask) const;
182 
183 
184  // Packed primitive
191 
192  // Instanced (contained) primitive
204 #ifdef USE_VULKAN
205  GR_InstanceBufferPtr myColorBuf;
206 #endif
207 
215 
222 
228 #ifdef USE_VULKAN
229  GR_InstanceBufferPtr mySelectionBuf;
230 #endif
234 
237 
243 
245  mutable bool myCachedBBoxValid;
246 
247  // light linking in lops
254 
255  // For GR_PrimPacked only
257 
260 
262  // --------
263 };
264 
266 {
267 public:
269  const char *cache_name,
270  const GT_PrimitiveHandle &packed_prim,
271  const GT_PrimitiveHandle &instanced_prim,
272  const GU_ConstDetailHandle &instanced_gdp)
273  : GR_PrimPacked(info, cache_name,packed_prim,instanced_prim,instanced_gdp)
274  {}
275 
276 
277  const char *className() const override { return "GR_PrimPackedMesh"; }
278 
280  { return GR_BASE_PRIM_PACKED_MESH; }
281 };
282 
283 
286  bool first_init)
287 {
288  if(myInstance)
289  return myInstance->checkDisplayOptionChange(opts);
290  return DISPLAY_UNCHANGED;
291 }
292 
293 inline bool
295 {
296  if(myInstance)
297  return myInstance->updateOnViewChange(opt);
298  return false;
299 }
300 
301 inline void
303 {
304  if(myInstance)
305  myInstance->viewUpdate(r, parms);
306 }
307 
308 inline bool
310 {
311  if(myInstance)
312  return myInstance->needsGLStateCheck(opts);
313  return false;
314 }
315 
316 inline bool
318 {
319  if(myInstance)
320  return myInstance->checkGLState(r,opts);
321  return false;
322 }
323 
324 inline bool
326 {
327  if(myInstance)
328  return myInstance->setup(d);
329  return false;
330 }
331 
332 inline void
334 {
335  if(myInstance)
336  myInstance->cleanup(r);
337 }
338 
339 
340 inline bool
342 {
343  if(myInstance)
344  return myInstance->requiresAlphaPass();
345  return false;
346 }
347 
348 inline const GA_Primitive *
350  exint primitive_id) const
351 {
352  if(myInstance)
353  return myInstance->getGAPrimitive(gdp, primitive_id);
354  return NULL;
355 }
356 
357 inline exint
359  exint vertex_id) const
360 {
361  if(myInstance)
362  return myInstance->getGAVertex(gdp, vertex_id);
363  return exint(-1);
364 }
365 
366 inline RE_Geometry *
368 {
369  return NULL;
370 }
371 
372 inline bool
374 {
375  if(myInstance)
376  return myInstance->renderInAlphaPass(a);
377  return true;
378 }
379 
380 inline bool
382  const UT_BoundingBoxD *bbox)
383 {
384  if(myInstance)
385  return myInstance->inViewFrustum(objviewproj, bbox);
386  // if no instance, no point in rendering nothing, so cull
387  return false;
388 }
389 
390 inline bool
392  const UT_Vector2F &min_proj_size,
393  const UT_BoundingBoxF *bbox)
394 {
395  if(myInstance)
396  return myInstance->isRasterizedInView(objviewproj, min_proj_size,bbox);
397  // if no instance, no point in rendering nothing, so cull
398  return false;
399 }
400 
401 inline bool
403 {
404  return myInstance ? myInstance->getBoundingBox(bbox) : false;
405 }
406 
407 inline exint
409 {
410  return myInstance ? myInstance->getNumGLPrimitives(opt) : 0;
411 }
412 
413 #endif
414 
GT_API const UT_StringHolder selection
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr)
Definition: GR_Primitive.h:204
virtual bool getSingleTransform(UT_Matrix4D &mat) const
GLbitfield flags
Definition: glcorearb.h:1596
virtual void render(RE_RenderContext r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp)=0
bool isRasterizedInView(const UT_Matrix4F &objviewproj, const UT_Vector2F &min_proj_size, const UT_BoundingBoxF *bbox) override
void cleanup(RE_RenderContext r) override
virtual bool updateOnViewChange(const GR_DisplayOption &) const
If this primitive requires an update when the view changes, return true.
Definition: GR_Primitive.h:124
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
virtual bool requiresAlphaPass() const
Return true if this primitive requires an alpha pass.
Definition: GR_Primitive.h:223
Unsorted map container.
Definition: UT_Map.h:107
UT_IntArray myBBoxInstances
RE_VertexArray * myColorVA
int64 myInstancedDetailID
int64 myInstancedDetailCacheCount
const GA_Primitive * getGAPrimitive(const GU_Detail *gdp, exint primitive_id) const override
bool needsGLStateCheck(const GR_DisplayOption &opts) const override
Set of parameters sent to GR_Primitive::viewUpdate().
RE_VertexArray * mySelectionVA
GR_PrimitivePtr myInstance
const GLdouble * v
Definition: glcorearb.h:837
GT_DataArrayHandle myPointIDs
bool myPrimTypeChanged
virtual bool supportsParallelDraw() const
Definition: GR_Primitive.h:264
GA_Index myPrimID
RE_VertexArrayRef myCenterPointP
bool myIsConsolidatedMesh
void viewUpdate(RE_RenderContext r, const GR_ViewUpdateParms &parms) override
bool myQueuedDrawValid
GT_PrimitiveHandle myPackedPrim
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
int64 exint
Definition: SYS_Types.h:125
UT_Vector3F myInstancePoint
GT_API const UT_StringHolder cache_name
exint getNumGLPrimitives(const GR_DisplayOption *) override
GR_SelectMode myPointSelectMode
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
UT_UniquePtr< GR_GeoRender > myCenterPrimsGeo
GR_Decoration
Definition: GR_Defines.h:162
GR_PrimPackedMesh(const GR_RenderInfo *info, const char *cache_name, const GT_PrimitiveHandle &packed_prim, const GT_PrimitiveHandle &instanced_prim, const GU_ConstDetailHandle &instanced_gdp)
GR_AlphaPass
Definition: GR_Defines.h:121
A class that manages material assignments to different groups of primitives.
RE_CacheVersion myCenterPointCacheVersion
Temporary container for either a RV_Render and an RE_Render.
bool setup(const GR_DisplayOption *) override
virtual void viewUpdate(RE_RenderContext r, const GR_ViewUpdateParms &parms)
Definition: GR_Primitive.h:134
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void setPrimVisible(bool v)
set of parameters sent to GR_Primitive::update()
GT_DataArrayHandle myPrimIDs
UT_BoundingBox * myAssignedBBox
GT_PrimitiveHandle getInstancePrim() const override
Definition: GR_PrimPacked.h:41
GT_API const UT_StringHolder point_id
virtual int renderPick(RE_RenderContext r, const GR_DisplayOption *opt, unsigned int pick_type, GR_PickStyle pick_style, bool has_pick_map)=0
UT_StringArray myShadowMasks
virtual void checkForDeferredDraw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, const GR_DrawParms &dp, const UT_Matrix4D &proj_view, const UT_Matrix4D &object, const UT_Vector2F &min_proj_size, bool &visible, bool &defer)
bool requiresAlphaPass() const override
Return true if this primitive requires an alpha pass.
virtual const GA_Primitive * getGAPrimitive(const GU_Detail *gdp, exint primitive_id) const
bool isPrimVisible() const override
GR_RenderMode
Definition: GR_Defines.h:48
UT_Map< int, UT_IntArray > myMaterialGroups
GR_BasePrimType
Definition: GR_Defines.h:366
RE_VertexArrayRef myCenterPrimP
const char * className() const override
Return a string version of this class's name.
Definition: GR_PrimPacked.h:37
virtual UT_Matrix4D getTransform(int) const
RE_VertexArrayRef myCenterPrimInstMat
virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const
Definition: GR_Primitive.h:160
virtual bool renderInAlphaPass(GR_AlphaPass a)
Return true if this primitive renders in the specified alpha pass.
virtual void retirePrimitive()
Called when a node is no longer actively displayed, but still cached.
UT_StringMap< int > myShadowMaskMap
GT_API const UT_StringHolder primitive_id
bool updateOnViewChange(const GR_DisplayOption &) const override
If this primitive requires an update when the view changes, return true.
bool checkGLState(RE_RenderContext r, const GR_DisplayOption &opt) override
GR_BasePrimType getBasePrimType() const override
The base primitive type is usually NORMAL unless this is a packed type.
Definition: GR_PrimPacked.h:39
RE_Geometry * myCenterPrims
virtual RE_Geometry * getDecorationGeometry()
Definition: GR_Primitive.h:315
bool myPrimSwappedFlag
UT_StringArray myLightLinks
#define GR_API
Definition: GR_API.h:10
GR_UpdateReason
Definition: GR_Defines.h:312
long long int64
Definition: SYS_Types.h:116
virtual bool getBoundingBox(UT_BoundingBoxD &bbox) const
Returns the bounding box of this primitive if it can be determined.
Definition: GR_Primitive.h:233
GA_Index myOverridePrimID
virtual void cleanup(RE_RenderContext r)
Definition: GR_Primitive.h:197
UT_Matrix4D myInstancePrimTransform
virtual void renderDecoration(RE_RenderContext r, GR_Decoration decor, const GR_DecorationParms &parms)
virtual bool setup(const GR_DisplayOption *)
Definition: GR_Primitive.h:195
UT_StringMap< int > myLightLinkMap
virtual bool isRasterizedInView(const UT_Matrix4F &objviewproj, const UT_Vector2F &min_proj_size, const UT_BoundingBoxF *bbox=nullptr)
UT_Matrix4D myBBoxTransform
GR_PrimAcceptResult
Definition: GR_Defines.h:359
GR_RenderFlags
Definition: GR_Defines.h:86
RE_VertexArrayRef myCenterPointInstMat
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
UT_SharedPtr< GU_Selection > GU_SelectionHandle
UT_BoundingBoxD myCachedBBox
GA_Index myOverridePointID
GLdouble t
Definition: glad.h:2397
GT_PrimitiveType myInstancedPrimType
GU_ConstDetailHandle myInstancedDetail
GLenum mode
Definition: glcorearb.h:99
GT_PrimitiveType
GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts, bool first_init) override
virtual GR_PrimAcceptResult acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle &ph, const GEO_Primitive *prim)=0
GT_DataArrayHandle myLODMask
bool myCachedBBoxValid
virtual int getNumInstances() const
UT_IntArray myPointInstances
virtual bool isFragment() const
virtual bool checkGLState(RE_RenderContext r, const GR_DisplayOption &opts)
Definition: GR_Primitive.h:162
virtual void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p)=0
const GT_PrimitiveHandle & instancePrim() const
Definition: GR_PrimPacked.h:44
GR_SelectMode mySelectMode
UT_UniquePtr< GR_GeoRender > myCenterPointsGeo
RE_Geometry * getDecorationGeometry() override
Simple class for a mutli-integer cache tag.
bool getBoundingBox(UT_BoundingBoxD &bbox) const override
Returns the bounding box of this primitive if it can be determined.
int64 myPackedPVersion
GLboolean r
Definition: glcorearb.h:1222
exint getGAVertex(const GU_Detail *gdp, exint vertex_id) const override
GT_PrimitiveHandle myInstancedPrim
const GT_PrimitiveHandle & packedPrim() const
Definition: GR_PrimPacked.h:45
GT_DataArrayHandle myPickIDs
const char * className() const override
Return a string version of this class's name.
bool renderInAlphaPass(GR_AlphaPass a) override
Return true if this primitive renders in the specified alpha pass.
GT_API const UT_StringHolder vertex_id
virtual GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts, bool first_init)
int64 myPrimUniqueID
GR_MaterialGroups myMatGroups
int64 myAlembicVersion
bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr) override
void setPrimIndex(int pindex)
Definition: GR_PrimPacked.h:50
RE_Geometry * myCenterPoints
GR_SelectMode
Definition: GR_Defines.h:241
virtual exint getGAVertex(const GU_Detail *gdp, exint vertex_id) const
GR_BasePrimType getBasePrimType() const override
The base primitive type is usually NORMAL unless this is a packed type.
GR_PickStyle
Definition: GR_Defines.h:252