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 
39  void setPackedPrim(const GT_PrimitiveHandle &packed_prim);
40  void setInstancedPrim(const GT_PrimitiveHandle &instance,
41  const GU_ConstDetailHandle &instance_gdp)
42  {
43  myInstancedPrim = instance;
44  myInstancedDetail = instance_gdp;
45  }
46  void setPrimIndex(int pindex)
47  { myPrimIndex = pindex; }
48 
50  int geo_type,
51  const GT_PrimitiveHandle &ph,
52  const GEO_Primitive *prim);
53 
54  virtual void update(RE_Render *r,
55  const GT_PrimitiveHandle &primh,
56  const GR_UpdateParms &p);
57 
58  virtual void checkForDeferredDraw(const RE_Render *r,
61  const GR_DrawParms &dp,
62  const UT_Matrix4D &proj_view,
63  const UT_Matrix4D &object,
64  bool &visible,
65  bool &defer);
66 
67  virtual void render(RE_Render *r,
68  GR_RenderMode render_mode,
70  GR_DrawParms dp);
71 
72  virtual void renderDecoration(RE_Render *r,
73  GR_Decoration decor,
74  const GR_DecorationParms &parms);
75  virtual int renderPick(RE_Render *r,
76  const GR_DisplayOption *opt,
77  unsigned int pick_type,
78  GR_PickStyle pick_style,
79  bool has_pick_map);
80 
81  bool checkForTransformChange();
82 
83  // Delegate these to the child prim.
84  virtual GR_DispOptChange displayOptionChange(const GR_DisplayOption &opts,
85  bool first_init);
86  virtual bool updateOnViewChange(const GR_DisplayOption &) const;
87  virtual void viewUpdate(RE_Render *r,
88  const GR_ViewUpdateParms &parms);
89  virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const;
90  virtual bool checkGLState(RE_Render *r,const GR_DisplayOption &opt);
91  virtual bool setup(const GR_DisplayOption *);
92  virtual void cleanup(RE_Render *r);
93 
94  virtual bool requiresAlphaPass() const;
95  virtual const GA_Primitive *getGAPrimitive(const GU_Detail *gdp,
96  exint primitive_id) const;
97  virtual exint getGAVertex(const GU_Detail *gdp,
98  exint vertex_id) const;
100  virtual bool renderInAlphaPass(GR_AlphaPass a);
101  virtual bool inViewFrustum(const UT_Matrix4D &objviewproj);
102  virtual bool getBoundingBox(UT_BoundingBoxD &bbox) const;
103 
104  virtual exint getNumGLPrimitives(const GR_DisplayOption *);
105  virtual void retirePrimitive();
106 
107  GR_SelectMode getSelectionMode(const GU_Detail &gdp,
109 
110  void setPickID(GA_Index prim_id, GA_Index point_id);
111 
112  void setInstanceHookPrim(GR_Primitive *prim);
113 protected:
114  virtual int getNumInstances() const { return 1; }
115  virtual UT_Matrix4D getTransform(int ) const
116  { return myInstancePrimTransform; }
117  virtual bool isFragment() const { return false; }
118  virtual bool getSingleTransform(UT_Matrix4D &mat) const
119  { mat = myInstancePrimTransform; return true; }
120 
121  bool updateCacheName(const GT_PrimitiveHandle &iph,
122  const GR_UpdateParms &p,
123  bool fallback);
124  void updateInstanceGeometry(RE_Render *r,
125  const GT_PrimitiveHandle &container_prim,
126  const GR_UpdateParms &p,
127  bool build_anchors);
128 
129  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
130  virtual void buildAnchorsGL3(RE_Render *r,
131  const GR_UpdateParms &p,
132  const GT_PrimitiveHandle &xforms);
133  void buildPickID(const GT_PrimitiveHandle &pid);
134  RE_Geometry *buildPickBBox(RE_Render *r) const;
135  void buildInstPrimTransform();
136 
137  // Given the packed geometry handle and the update reason for the packed
138  // primitive, determine the update reason for the packed geometry.
139  GR_UpdateReason checkForPackedGeoChanges(const GT_PrimitiveHandle &ph,
140  GR_UpdateReason reason);
141  GR_UpdateParms checkForPackedMaterialAssignment(const GR_UpdateParms &p);
142 
143 
144  // Packed primitive
149 
150  // Instanced (contained) primitive
162 
170 
177 
184 
187 
190 
191  // For GR_PrimPacked only
193 
196 
198  // --------
199 };
200 
202 {
203 public:
205  const char *cache_name,
206  const GT_PrimitiveHandle &packed_prim,
207  const GT_PrimitiveHandle &instanced_prim,
208  const GU_ConstDetailHandle &instanced_gdp)
209  : GR_PrimPacked(info, cache_name,packed_prim,instanced_prim,instanced_gdp)
210  {}
211 
212 
213  virtual const char *className() const { return "GR_PrimPackedMesh"; }
214 
216  { return GR_BASE_PRIM_PACKED_MESH; }
217 };
218 
219 
222  bool first_init)
223 {
224  if(myInstance)
225  return myInstance->checkDisplayOptionChange(opts);
226  return DISPLAY_UNCHANGED;
227 }
228 
229 inline bool
231 {
232  if(myInstance)
233  return myInstance->updateOnViewChange(opt);
234  return false;
235 }
236 
237 inline void
239 {
240  if(myInstance)
241  myInstance->viewUpdate(r, parms);
242 }
243 
244 inline bool
246 {
247  if(myInstance)
248  return myInstance->needsGLStateCheck(opts);
249  return false;
250 }
251 
252 inline bool
254 {
255  if(myInstance)
256  return myInstance->checkGLState(r,opts);
257  return false;
258 }
259 
260 inline bool
262 {
263  if(myInstance)
264  return myInstance->setup(d);
265  return false;
266 }
267 
268 inline void
270 {
271  if(myInstance)
272  myInstance->cleanup(r);
273 }
274 
275 
276 inline bool
278 {
279  if(myInstance)
280  return myInstance->requiresAlphaPass();
281  return false;
282 }
283 
284 inline const GA_Primitive *
286  exint primitive_id) const
287 {
288  if(myInstance)
289  return myInstance->getGAPrimitive(gdp, primitive_id);
290  return NULL;
291 }
292 
293 inline exint
295  exint vertex_id) const
296 {
297  if(myInstance)
298  return myInstance->getGAVertex(gdp, vertex_id);
299  return exint(-1);
300 }
301 
302 inline RE_Geometry *
304 {
305  return NULL;
306 }
307 
308 inline bool
310 {
311  if(myInstance)
312  return myInstance->renderInAlphaPass(a);
313  return true;
314 }
315 
316 inline bool
318 {
319  if(myInstance)
320  return myInstance->inViewFrustum(objviewproj);
321  // if no instance, no point in rendering nothing, so cull
322  return false;
323 }
324 
325 inline bool
327 {
328  return myInstance ? myInstance->getBoundingBox(bbox) : false;
329 }
330 
331 inline exint
333 {
334  return myInstance ? myInstance->getNumGLPrimitives(opt) : 0;
335 }
336 
337 #endif
338 
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 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:118
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
virtual bool requiresAlphaPass() const
Return true if this primitive requires an alpha pass.
Definition: GR_Primitive.h:201
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().
virtual const char * className() const
Return a string version of this class's name.
Definition: GR_PrimPacked.h:30
GR_DispOptChange checkDisplayOptionChange(const GR_DisplayOption &opts)
Definition: GR_Primitive.h:556
GT_DataArrayHandle myPointIDs
GA_Index myPrimID
RE_VertexArrayRef myCenterPointP
virtual void cleanup(RE_Render *r)
Definition: GR_Primitive.h:183
virtual const GA_Primitive * getGAPrimitive(const GU_Detail *gdp, exint primitive_id) const
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj)
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
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLbitfield flags
Definition: glcorearb.h:1595
virtual GR_BasePrimType getBasePrimType() const
The base primitive type is usually NORMAL unless this is a packed type.
Definition: GR_PrimPacked.h:32
virtual bool checkGLState(RE_Render *r, const GR_DisplayOption &opts)
Definition: GR_Primitive.h:149
GR_Decoration
Definition: GR_Defines.h:139
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.
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:107
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:335
RE_VertexArrayRef myCenterPrimP
virtual UT_Matrix4D getTransform(int) const
RE_VertexArrayRef myCenterPrimInstMat
virtual bool needsGLStateCheck(const GR_DisplayOption &opts) const
Definition: GR_Primitive.h:147
virtual bool renderInAlphaPass(GR_AlphaPass a)
Return true if this primitive renders in the specified alpha pass.
int64 exint
Definition: SYS_Types.h:116
virtual void retirePrimitive()
Called when a node is no longer actively displayed, but still cached.
GT_API const UT_StringHolder primitive_id
RE_Geometry * myCenterPrims
virtual RE_Geometry * getDecorationGeometry()
Definition: GR_Primitive.h:275
bool myPrimSwappedFlag
void setInstancedPrim(const GT_PrimitiveHandle &instance, const GU_ConstDetailHandle &instance_gdp)
Definition: GR_PrimPacked.h:40
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
#define GR_API
Definition: GR_API.h:10
GR_UpdateReason
Definition: GR_Defines.h:286
virtual bool getBoundingBox(UT_BoundingBoxD &bbox) const
Returns the bounding box of this primitive if it can be determined.
Definition: GR_Primitive.h:210
GA_Index myOverridePrimID
UT_Matrix4D myInstancePrimTransform
virtual bool setup(const GR_DisplayOption *)
Definition: GR_Primitive.h:181
UT_Matrix4D myBBoxTransform
GR_PrimAcceptResult
Definition: GR_Defines.h:328
virtual void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms)
Definition: GR_Primitive.h:128
GR_RenderFlags
Definition: GR_Defines.h:79
RE_VertexArrayRef myCenterPointInstMat
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
UT_SharedPtr< GU_Selection > GU_SelectionHandle
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
GLenum mode
Definition: glcorearb.h:98
GR_Primitive * myInstance
GT_PrimitiveType
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 bool inViewFrustum(const UT_Matrix4D &objviewproj)
Definition: GR_Primitive.h:189
virtual RE_Geometry * getDecorationGeometry()
GT_DataArrayHandle myLODMask
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
const GT_PrimitiveHandle & instancePrim() const
Definition: GR_PrimPacked.h:37
GR_SelectMode mySelectMode
Simple class for a mutli-integer cache tag.
int64 myPackedPVersion
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, bool &visible, bool &defer)
GLboolean r
Definition: glcorearb.h:1221
GT_PrimitiveHandle myInstancedPrim
GT_DataArrayHandle myPickIDs
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
int64 myPrimUniqueID
GR_MaterialGroups myMatGroups
int64 myAlembicVersion
void setPrimIndex(int pindex)
Definition: GR_PrimPacked.h:46
virtual void renderDecoration(RE_Render *r, GR_Decoration decor, const GR_DecorationParms &parms)
RE_Geometry * myCenterPoints
GR_SelectMode
Definition: GR_Defines.h:217
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:228