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 <RE/RE_VertexArray.h>
17 
19 {
20 public:
21  GR_PrimPacked(const GR_RenderInfo *info,
22  const char *cache_name,
23  const GT_PrimitiveHandle &packed_prim,
24  const GT_PrimitiveHandle &instanced_prim,
25  const GU_ConstDetailHandle &instanced_gdp,
26  int prim_index = -1);
27 
28  ~GR_PrimPacked() override;
29 
30  const char *className() const override { return "GR_PrimPacked"; }
31 
33  { return GR_BASE_PRIM_PACKED; }
35  { return myInstancedPrim; }
36 
37  const GT_PrimitiveHandle &instancePrim() const { return myInstancedPrim; }
38  const GT_PrimitiveHandle &packedPrim() const { return myPackedPrim; }
39 
40  void setPackedPrim(const GT_PrimitiveHandle &packed_prim);
41  void setInstancedPrim(const GT_PrimitiveHandle &instance,
42  const GU_ConstDetailHandle &inst_gdp);
43  void setPrimIndex(int pindex)
44  { myPrimIndex = pindex; }
45 
47  int geo_type,
48  const GT_PrimitiveHandle &ph,
49  const GEO_Primitive *prim) override;
50 
51  void update(RE_Render *r,
52  const GT_PrimitiveHandle &primh,
53  const GR_UpdateParms &p) override;
54 
55  void checkForDeferredDraw(const RE_Render *r,
58  const GR_DrawParms &dp,
59  const UT_Matrix4D &proj_view,
60  const UT_Matrix4D &object,
61  const UT_Vector2F &min_proj_size,
62  bool &visible,
63  bool &defer) override;
64 
65  void render(RE_Render *r,
66  GR_RenderMode render_mode,
68  GR_DrawParms dp) override;
69 
71  GR_Decoration decor,
72  const GR_DecorationParms &parms) override;
73  int renderPick(RE_Render *r,
74  const GR_DisplayOption *opt,
75  unsigned int pick_type,
76  GR_PickStyle pick_style,
77  bool has_pick_map) override;
78 
79  bool checkForTransformChange();
80 
81  // Delegate these to the child prim.
82  GR_DispOptChange displayOptionChange(
83  const GR_DisplayOption &opts,
84  bool first_init) override;
85  bool updateOnViewChange(
86  const GR_DisplayOption &) const override;
87  void viewUpdate(
88  RE_Render *r,
89  const GR_ViewUpdateParms &parms) override;
90  bool needsGLStateCheck(
91  const GR_DisplayOption &opts) const override;
92  bool checkGLState(
93  RE_Render *r,
94  const GR_DisplayOption &opt) override;
95  bool setup(const GR_DisplayOption *) override;
96  void cleanup(RE_Render *r) override;
97 
98  bool requiresAlphaPass() const override;
99  const GA_Primitive *getGAPrimitive(const GU_Detail *gdp,
100  exint primitive_id) const override;
101  exint getGAVertex(const GU_Detail *gdp,
102  exint vertex_id) const override;
104  bool renderInAlphaPass(GR_AlphaPass a) override;
105  bool inViewFrustum(
106  const UT_Matrix4D &objviewproj,
107  const UT_BoundingBoxD *bbox = nullptr) override;
108  bool isRasterizedInView(
109  const UT_Matrix4F &objviewproj,
110  const UT_Vector2F &min_proj_size,
111  const UT_BoundingBoxF *bbox) override;
112  bool getBoundingBox(UT_BoundingBoxD &bbox) const override;
113 
114  exint getNumGLPrimitives(const GR_DisplayOption *) override;
115  void retirePrimitive() override;
116 
117  GR_SelectMode getSelectionMode(const GU_Detail &gdp,
119 
120  void setPickID(GA_Index prim_id, GA_Index point_id);
121 
122  void setInstanceHookPrim(GR_Primitive *prim);
123 
124  void setPrimVisible(bool v) { myPrimVisible = v; }
125 
126 protected:
127  virtual int getNumInstances() const { return 1; }
128  virtual UT_Matrix4D getTransform(int ) const
129  { return myInstancePrimTransform; }
130  virtual bool isFragment() const { return false; }
131  virtual bool getSingleTransform(UT_Matrix4D &mat) const
132  { mat = myInstancePrimTransform; return true; }
133 
134  bool updateCacheName(const GT_PrimitiveHandle &iph,
135  const GR_UpdateParms &p,
136  bool fallback);
137  void updateInstanceGeometry(RE_Render *r,
138  const GT_PrimitiveHandle &container_prim,
139  const GR_UpdateParms &p,
140  bool build_anchors,
141  GR_UpdateReason full_update);
142 
143  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
144  virtual void buildAnchorsGL3(RE_Render *r,
145  const GR_UpdateParms &p,
146  GR_UpdateReason full_reason,
147  const GT_PrimitiveHandle &xforms);
148  void buildPickID(const GT_PrimitiveHandle &pid);
149  RE_Geometry *buildPickBBox(RE_Render *r) const;
150  void buildInstPrimTransform();
151 
152  // Given the packed geometry handle and the update reason for the packed
153  // primitive, determine the update reason for the packed geometry.
154  GR_UpdateReason checkForPackedGeoChanges(const GT_PrimitiveHandle &ph,
155  GR_UpdateReason reason);
156  GR_UpdateParms checkForPackedMaterialAssignment(const GR_UpdateParms &p);
157 
158  void updateLightLinking();
159  void updateLinkMap(const UT_StringRef &attrib_name,
160  UT_StringMap<int> &link_map,
161  UT_StringArray &list,
162  bool &has_link);
163  bool setLightLinkMask(GR_DrawParms &dp,
164  int &prev_mask) const;
165  void restoreLightLinkMask(GR_DrawParms &dp,
166  int prev_mask) const;
167 
168 
169  // Packed primitive
174 
175  // Instanced (contained) primitive
187 
195 
202 
211 
214 
220 
222  mutable bool myCachedBBoxValid;
223 
224  // light linking in lops
231 
232  // For GR_PrimPacked only
234 
237 
239  // --------
240 };
241 
243 {
244 public:
246  const char *cache_name,
247  const GT_PrimitiveHandle &packed_prim,
248  const GT_PrimitiveHandle &instanced_prim,
249  const GU_ConstDetailHandle &instanced_gdp)
250  : GR_PrimPacked(info, cache_name,packed_prim,instanced_prim,instanced_gdp)
251  {}
252 
253 
254  const char *className() const override { return "GR_PrimPackedMesh"; }
255 
257  { return GR_BASE_PRIM_PACKED_MESH; }
258 };
259 
260 
263  bool first_init)
264 {
265  if(myInstance)
266  return myInstance->checkDisplayOptionChange(opts);
267  return DISPLAY_UNCHANGED;
268 }
269 
270 inline bool
272 {
273  if(myInstance)
274  return myInstance->updateOnViewChange(opt);
275  return false;
276 }
277 
278 inline void
280 {
281  if(myInstance)
282  myInstance->viewUpdate(r, parms);
283 }
284 
285 inline bool
287 {
288  if(myInstance)
289  return myInstance->needsGLStateCheck(opts);
290  return false;
291 }
292 
293 inline bool
295 {
296  if(myInstance)
297  return myInstance->checkGLState(r,opts);
298  return false;
299 }
300 
301 inline bool
303 {
304  if(myInstance)
305  return myInstance->setup(d);
306  return false;
307 }
308 
309 inline void
311 {
312  if(myInstance)
313  myInstance->cleanup(r);
314 }
315 
316 
317 inline bool
319 {
320  if(myInstance)
321  return myInstance->requiresAlphaPass();
322  return false;
323 }
324 
325 inline const GA_Primitive *
327  exint primitive_id) const
328 {
329  if(myInstance)
330  return myInstance->getGAPrimitive(gdp, primitive_id);
331  return NULL;
332 }
333 
334 inline exint
336  exint vertex_id) const
337 {
338  if(myInstance)
339  return myInstance->getGAVertex(gdp, vertex_id);
340  return exint(-1);
341 }
342 
343 inline RE_Geometry *
345 {
346  return NULL;
347 }
348 
349 inline bool
351 {
352  if(myInstance)
353  return myInstance->renderInAlphaPass(a);
354  return true;
355 }
356 
357 inline bool
359  const UT_BoundingBoxD *bbox)
360 {
361  if(myInstance)
362  return myInstance->inViewFrustum(objviewproj, bbox);
363  // if no instance, no point in rendering nothing, so cull
364  return false;
365 }
366 
367 inline bool
369  const UT_Vector2F &min_proj_size,
370  const UT_BoundingBoxF *bbox)
371 {
372  if(myInstance)
373  return myInstance->isRasterizedInView(objviewproj, min_proj_size,bbox);
374  // if no instance, no point in rendering nothing, so cull
375  return false;
376 }
377 
378 inline bool
380 {
381  return myInstance ? myInstance->getBoundingBox(bbox) : false;
382 }
383 
384 inline exint
386 {
387  return myInstance ? myInstance->getNumGLPrimitives(opt) : 0;
388 }
389 
390 #endif
391 
GT_API const UT_StringHolder selection
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr)
Definition: GR_Primitive.h:191
virtual bool getSingleTransform(UT_Matrix4D &mat) const
bool isRasterizedInView(const UT_Matrix4F &objviewproj, const UT_Vector2F &min_proj_size, const UT_BoundingBoxF *bbox) override
virtual bool updateOnViewChange(const GR_DisplayOption &) const
If this primitive requires an update when the view changes, return true.
Definition: GR_Primitive.h:119
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
virtual bool requiresAlphaPass() const
Return true if this primitive requires an alpha pass.
Definition: GR_Primitive.h:210
Unsorted map container.
Definition: UT_Map.h:83
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().
GLenum mode
Definition: glew.h:2163
RE_VertexArray * mySelectionVA
GR_PrimitivePtr myInstance
GT_DataArrayHandle myPointIDs
bool myPrimTypeChanged
GA_Index myPrimID
RE_VertexArrayRef myCenterPointP
bool myIsConsolidatedMesh
virtual void cleanup(RE_Render *r)
Definition: GR_Primitive.h:184
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
bool myQueuedDrawValid
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2864
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
const GLdouble * v
Definition: glew.h:1391
virtual bool checkGLState(RE_Render *r, const GR_DisplayOption &opts)
Definition: GR_Primitive.h:150
GR_Decoration
Definition: GR_Defines.h:142
void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms) override
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:110
A class that manages material assignments to different groups of primitives.
virtual int renderPick(RE_Render *r, const GR_DisplayOption *opt, unsigned int pick_type, GR_PickStyle pick_style, bool has_pick_map)=0
RE_CacheVersion myCenterPointCacheVersion
bool setup(const GR_DisplayOption *) override
void setPrimVisible(bool v)
virtual void render(RE_Render *r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp)=0
set of parameters sent to GR_Primitive::update()
GT_DataArrayHandle myPrimIDs
UT_BoundingBox * myAssignedBBox
GT_PrimitiveHandle getInstancePrim() const override
Definition: GR_PrimPacked.h:34
GT_API const UT_StringHolder point_id
UT_StringArray myShadowMasks
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
void cleanup(RE_Render *r) override
GR_RenderMode
Definition: GR_Defines.h:44
UT_Map< int, UT_IntArray > myMaterialGroups
GR_BasePrimType
Definition: GR_Defines.h:339
RE_VertexArrayRef myCenterPrimP
const char * className() const override
Return a string version of this class's name.
Definition: GR_PrimPacked.h:30
virtual UT_Matrix4D getTransform(int) const
RE_VertexArrayRef myCenterPrimInstMat
virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const
Definition: GR_Primitive.h:148
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.
GR_BasePrimType getBasePrimType() const override
The base primitive type is usually NORMAL unless this is a packed type.
Definition: GR_PrimPacked.h:32
RE_Geometry * myCenterPrims
virtual RE_Geometry * getDecorationGeometry()
Definition: GR_Primitive.h:298
bool myPrimSwappedFlag
UT_StringArray myLightLinks
#define GR_API
Definition: GR_API.h:10
GR_UpdateReason
Definition: GR_Defines.h:289
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:220
GA_Index myOverridePrimID
UT_Matrix4D myInstancePrimTransform
virtual bool setup(const GR_DisplayOption *)
Definition: GR_Primitive.h:182
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:332
virtual void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms)
Definition: GR_Primitive.h:129
GR_RenderFlags
Definition: GR_Defines.h:81
RE_VertexArrayRef myCenterPointInstMat
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
UT_SharedPtr< GU_Selection > GU_SelectionHandle
virtual void checkForDeferredDraw(const RE_Render *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)
UT_BoundingBoxD myCachedBBox
GA_Index myOverridePointID
GT_PrimitiveType myInstancedPrimType
GU_ConstDetailHandle myInstancedDetail
GT_PrimitiveType
GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts, bool first_init) override
GLfloat GLfloat p
Definition: glew.h:16321
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 void update(RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p)=0
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
const GT_PrimitiveHandle & instancePrim() const
Definition: GR_PrimPacked.h:37
GR_SelectMode mySelectMode
RE_Geometry * getDecorationGeometry() override
Simple class for a mutli-integer cache tag.
bool checkGLState(RE_Render *r, const GR_DisplayOption &opt) override
bool getBoundingBox(UT_BoundingBoxD &bbox) const override
Returns the bounding box of this primitive if it can be determined.
int64 myPackedPVersion
exint getGAVertex(const GU_Detail *gdp, exint vertex_id) const override
GT_PrimitiveHandle myInstancedPrim
const GT_PrimitiveHandle & packedPrim() const
Definition: GR_PrimPacked.h:38
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)
GLdouble GLdouble t
Definition: glew.h:1398
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:43
virtual void renderDecoration(RE_Render *r, GR_Decoration decor, const GR_DecorationParms &parms)
RE_Geometry * myCenterPoints
GR_SelectMode
Definition: GR_Defines.h:220
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:231