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  virtual ~GR_PrimPacked();
29 
30  virtual const char *className() const { 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);
50 
51  virtual void update(RE_Render *r,
52  const GT_PrimitiveHandle &primh,
53  const GR_UpdateParms &p);
54 
55  virtual 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);
64 
65  virtual void render(RE_Render *r,
66  GR_RenderMode render_mode,
68  GR_DrawParms dp);
69 
70  virtual void renderDecoration(RE_Render *r,
71  GR_Decoration decor,
72  const GR_DecorationParms &parms);
73  virtual 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);
78 
79  bool checkForTransformChange();
80 
81  // Delegate these to the child prim.
82  virtual GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts,
83  bool first_init);
84  virtual bool updateOnViewChange(const GR_DisplayOption &) const;
85  virtual void viewUpdate(RE_Render *r,
86  const GR_ViewUpdateParms &parms);
87  virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const;
88  virtual bool checkGLState(RE_Render *r,const GR_DisplayOption &opt);
89  virtual bool setup(const GR_DisplayOption *);
90  virtual void cleanup(RE_Render *r);
91 
92  virtual bool requiresAlphaPass() const;
93  virtual const GA_Primitive *getGAPrimitive(const GU_Detail *gdp,
94  exint primitive_id) const;
95  virtual exint getGAVertex(const GU_Detail *gdp,
96  exint vertex_id) const;
98  virtual bool renderInAlphaPass(GR_AlphaPass a);
99  virtual bool inViewFrustum(const UT_Matrix4D &objviewproj,
100  const UT_BoundingBoxD *bbox = nullptr);
101  virtual bool isRasterizedInView(const UT_Matrix4F &objviewproj,
102  const UT_Vector2F &min_proj_size,
103  const UT_BoundingBoxF *bbox);
104  virtual bool getBoundingBox(UT_BoundingBoxD &bbox) const;
105 
106  virtual exint getNumGLPrimitives(const GR_DisplayOption *);
107  virtual void retirePrimitive();
108 
109  GR_SelectMode getSelectionMode(const GU_Detail &gdp,
111 
112  void setPickID(GA_Index prim_id, GA_Index point_id);
113 
114  void setInstanceHookPrim(GR_Primitive *prim);
115 
116  void setPrimVisible(bool v) { myPrimVisible = v; }
117 
118 protected:
119  virtual int getNumInstances() const { return 1; }
120  virtual UT_Matrix4D getTransform(int ) const
121  { return myInstancePrimTransform; }
122  virtual bool isFragment() const { return false; }
123  virtual bool getSingleTransform(UT_Matrix4D &mat) const
124  { mat = myInstancePrimTransform; return true; }
125 
126  bool updateCacheName(const GT_PrimitiveHandle &iph,
127  const GR_UpdateParms &p,
128  bool fallback);
129  void updateInstanceGeometry(RE_Render *r,
130  const GT_PrimitiveHandle &container_prim,
131  const GR_UpdateParms &p,
132  bool build_anchors);
133 
134  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
135  virtual void buildAnchorsGL3(RE_Render *r,
136  const GR_UpdateParms &p,
137  const GT_PrimitiveHandle &xforms);
138  void buildPickID(const GT_PrimitiveHandle &pid);
139  RE_Geometry *buildPickBBox(RE_Render *r) const;
140  void buildInstPrimTransform();
141 
142  // Given the packed geometry handle and the update reason for the packed
143  // primitive, determine the update reason for the packed geometry.
144  GR_UpdateReason checkForPackedGeoChanges(const GT_PrimitiveHandle &ph,
145  GR_UpdateReason reason);
146  GR_UpdateParms checkForPackedMaterialAssignment(const GR_UpdateParms &p);
147 
148  void updateLightLinking();
149  void updateLinkMap(const UT_StringRef &attrib_name,
150  UT_StringMap<int> &link_map,
151  UT_StringArray &list,
152  bool &has_link);
153  bool setLightLinkMask(GR_DrawParms &dp,
154  int &prev_mask) const;
155  void restoreLightLinkMask(GR_DrawParms &dp,
156  int prev_mask) const;
157 
158 
159  // Packed primitive
164 
165  // Instanced (contained) primitive
177 
185 
192 
201 
204 
209 
211  mutable bool myCachedBBoxValid;
212 
213  // light linking in lops
220 
221  // For GR_PrimPacked only
223 
226 
228  // --------
229 };
230 
232 {
233 public:
235  const char *cache_name,
236  const GT_PrimitiveHandle &packed_prim,
237  const GT_PrimitiveHandle &instanced_prim,
238  const GU_ConstDetailHandle &instanced_gdp)
239  : GR_PrimPacked(info, cache_name,packed_prim,instanced_prim,instanced_gdp)
240  {}
241 
242 
243  virtual const char *className() const { return "GR_PrimPackedMesh"; }
244 
246  { return GR_BASE_PRIM_PACKED_MESH; }
247 };
248 
249 
252  bool first_init)
253 {
254  if(myInstance)
255  return myInstance->checkDisplayOptionChange(opts);
256  return DISPLAY_UNCHANGED;
257 }
258 
259 inline bool
261 {
262  if(myInstance)
263  return myInstance->updateOnViewChange(opt);
264  return false;
265 }
266 
267 inline void
269 {
270  if(myInstance)
271  myInstance->viewUpdate(r, parms);
272 }
273 
274 inline bool
276 {
277  if(myInstance)
278  return myInstance->needsGLStateCheck(opts);
279  return false;
280 }
281 
282 inline bool
284 {
285  if(myInstance)
286  return myInstance->checkGLState(r,opts);
287  return false;
288 }
289 
290 inline bool
292 {
293  if(myInstance)
294  return myInstance->setup(d);
295  return false;
296 }
297 
298 inline void
300 {
301  if(myInstance)
302  myInstance->cleanup(r);
303 }
304 
305 
306 inline bool
308 {
309  if(myInstance)
310  return myInstance->requiresAlphaPass();
311  return false;
312 }
313 
314 inline const GA_Primitive *
316  exint primitive_id) const
317 {
318  if(myInstance)
319  return myInstance->getGAPrimitive(gdp, primitive_id);
320  return NULL;
321 }
322 
323 inline exint
325  exint vertex_id) const
326 {
327  if(myInstance)
328  return myInstance->getGAVertex(gdp, vertex_id);
329  return exint(-1);
330 }
331 
332 inline RE_Geometry *
334 {
335  return NULL;
336 }
337 
338 inline bool
340 {
341  if(myInstance)
342  return myInstance->renderInAlphaPass(a);
343  return true;
344 }
345 
346 inline bool
348  const UT_BoundingBoxD *bbox)
349 {
350  if(myInstance)
351  return myInstance->inViewFrustum(objviewproj, bbox);
352  // if no instance, no point in rendering nothing, so cull
353  return false;
354 }
355 
356 inline bool
358  const UT_Vector2F &min_proj_size,
359  const UT_BoundingBoxF *bbox)
360 {
361  if(myInstance)
362  return myInstance->isRasterizedInView(objviewproj, min_proj_size,bbox);
363  // if no instance, no point in rendering nothing, so cull
364  return false;
365 }
366 
367 inline bool
369 {
370  return myInstance ? myInstance->getBoundingBox(bbox) : false;
371 }
372 
373 inline exint
375 {
376  return myInstance ? myInstance->getNumGLPrimitives(opt) : 0;
377 }
378 
379 #endif
380 
virtual bool checkGLState(RE_Render *r, const GR_DisplayOption &opt)
virtual bool renderInAlphaPass(GR_AlphaPass a)
Return true if this primitive renders in the specified alpha pass.
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
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
virtual GR_BasePrimType getBasePrimType() const
The base primitive type is usually NORMAL unless this is a packed type.
RE_VertexArray * myColorVA
int64 myInstancedDetailID
int64 myInstancedDetailCacheCount
Set of parameters sent to GR_Primitive::viewUpdate().
GLenum mode
Definition: glew.h:2163
virtual const char * className() const
Return a string version of this class's name.
Definition: GR_PrimPacked.h:30
RE_VertexArray * mySelectionVA
GR_PrimitivePtr myInstance
GT_DataArrayHandle myPointIDs
bool myPrimTypeChanged
GA_Index myPrimID
RE_VertexArrayRef myCenterPointP
virtual void cleanup(RE_Render *r)
Definition: GR_Primitive.h:184
virtual const GA_Primitive * getGAPrimitive(const GU_Detail *gdp, exint primitive_id) const
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
UT_Vector3F myInstancePoint
GT_API const UT_StringHolder cache_name
virtual void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms)
GR_SelectMode myPointSelectMode
virtual GR_BasePrimType getBasePrimType() const
The base primitive type is usually NORMAL unless this is a packed type.
Definition: GR_PrimPacked.h:32
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:141
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:109
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
virtual bool getBoundingBox(UT_BoundingBoxD &bbox) const
Returns the bounding box of this primitive if it can be determined.
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_API const UT_StringHolder point_id
long long int64
Definition: SYS_Types.h:111
UT_StringArray myShadowMasks
virtual const GA_Primitive * getGAPrimitive(const GU_Detail *gdp, exint primitive_id) const
GR_RenderMode
Definition: GR_Defines.h:44
UT_Map< int, UT_IntArray > myMaterialGroups
GR_BasePrimType
Definition: GR_Defines.h:338
RE_VertexArrayRef myCenterPrimP
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.
int64 exint
Definition: SYS_Types.h:120
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
RE_Geometry * myCenterPrims
virtual RE_Geometry * getDecorationGeometry()
Definition: GR_Primitive.h:291
bool myPrimSwappedFlag
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
UT_StringArray myLightLinks
#define GR_API
Definition: GR_API.h:10
GR_UpdateReason
Definition: GR_Defines.h:288
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:331
virtual void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms)
Definition: GR_Primitive.h:129
GR_RenderFlags
Definition: GR_Defines.h:80
RE_VertexArrayRef myCenterPointInstMat
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
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
virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const
GA_Index myOverridePointID
GT_PrimitiveType myInstancedPrimType
virtual const char * className() const
Return a string version of this class's name.
GU_ConstDetailHandle myInstancedDetail
GT_PrimitiveType
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
virtual bool requiresAlphaPass() const
Return true if this primitive requires an alpha pass.
virtual GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts, bool first_init)
virtual exint getGAVertex(const GU_Detail *gdp, exint vertex_id) const
virtual RE_Geometry * getDecorationGeometry()
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
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr)
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
const GT_PrimitiveHandle & instancePrim() const
Definition: GR_PrimPacked.h:37
GR_SelectMode mySelectMode
Simple class for a mutli-integer cache tag.
int64 myPackedPVersion
GT_PrimitiveHandle myInstancedPrim
const GT_PrimitiveHandle & packedPrim() const
Definition: GR_PrimPacked.h:38
GT_DataArrayHandle myPickIDs
virtual bool isRasterizedInView(const UT_Matrix4F &objviewproj, const UT_Vector2F &min_proj_size, const UT_BoundingBoxF *bbox)
GT_API const UT_StringHolder vertex_id
virtual void cleanup(RE_Render *r)
virtual GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts, bool first_init)
virtual GT_PrimitiveHandle getInstancePrim() const
Definition: GR_PrimPacked.h:34
GLdouble GLdouble t
Definition: glew.h:1398
int64 myPrimUniqueID
GR_MaterialGroups myMatGroups
int64 myAlembicVersion
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:219
virtual exint getGAVertex(const GU_Detail *gdp, exint vertex_id) const
virtual bool updateOnViewChange(const GR_DisplayOption &) const
If this primitive requires an update when the view changes, return true.
virtual bool setup(const GR_DisplayOption *)
GR_PickStyle
Definition: GR_Defines.h:230