HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PrimInstance.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_PrimInstance.h (GR Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef __GR_PrimInstance__
11 #define __GR_PrimInstance__
12 
13 #include "GR_PrimPacked.h"
14 
16 {
17 public:
18  GR_PrimInstance(const GR_RenderInfo *info,
19  const char *cache_name,
20  const GT_PrimitiveHandle &instance_prim,
21  const GT_PrimitiveHandle &instancer,
22  const UT_Matrix4DArray &instance_transforms,
23  const GU_ConstDetailHandle &instance_gdp,
24  int nest_level,
25  int prim_index = -1,
26  const UT_BoundingBox *bbox = nullptr);
27  virtual ~GR_PrimInstance();
28 
29  virtual const char *className() const { return "GR_PrimInstance"; }
30 
32  { return GR_BASE_PRIM_INSTANCE; }
33 
34  void setTransforms(const UT_Matrix4DArray &inst_transforms);
35 
36  void setNestLevel(int nest_level)
37  {
38  myNestLevel = nest_level;
39  if(nest_level == 0)
40  myTopLevelTransforms.entries(0);
41  }
42 
43  // when nested, the top-level transforms are needed to position the point
44  // and primitive decorations.
45  void setTopTransforms(const UT_Matrix4DArray &top_xforms)
46  { myTopLevelTransforms = top_xforms; }
47 
48  virtual bool updateOnViewChange(const GR_DisplayOption &dopts) const
49  { return ((getNumInstances() > 1) ||
50  (myInstance?myInstance->updateOnViewChange(dopts):false)); }
51 
52  virtual void viewUpdate(RE_Render *r,
53  const GR_ViewUpdateParms &parms);
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  bool &visible,
62  bool &defer);
63 
64  virtual void update(RE_Render *r,
65  const GT_PrimitiveHandle &primh,
66  const GR_UpdateParms &p);
67 
68  virtual void render(RE_Render *r,
69  GR_RenderMode render_mode,
71  GR_DrawParms dp);
72 
73  virtual bool inViewFrustum(const UT_Matrix4D &objviewproj);
74 
75  virtual exint getNumGLPrimitives(const GR_DisplayOption *);
76 
77  virtual bool getSingleTransform(UT_Matrix4D &mat) const
78  {
79  if(getNumInstances() == 1)
80  {
81  mat = myInstancedTransforms(0);
82  return true;
83  }
84  return false;
85  }
86 
87  int getNumTopTransforms() const
88  {
89  if(myTopLevelTransforms.entries())
90  return myTopLevelTransforms.entries();
91  return myInstancedTransforms.entries();
92  }
93  int getNumTransforms() const
94  {
95  return myInstancedTransforms.entries();
96  }
97 
98  void setInstancer(const GT_PrimitiveHandle &ph);
99 
100 private:
101  virtual int getNumInstances() const;
102  virtual UT_Matrix4D getTransform(int instance_index) const
103  { return myInstancedTransforms(instance_index); }
104 
105  void buildInstancedSelection(RE_Render *r,
106  const GR_UpdateParms &p);
107  void buildInstancedColor(RE_Render *r,
108  const GR_UpdateParms &p);
109 
110  void buildPoints(RE_Render *r,
111  const GR_UpdateParms &p,
112  bool check_lod_centroid);
113 
114  void buildVisibilityInfo(RE_Render *r,
115  const GR_DisplayOption &opts,
116  const GR_FrustumList &frustums);
117  void buildInstanceIndexArrays(RE_Render *r,
118  bool has_partial_vis,
119  const UT_IntArray &vis_insts);
120 
121  void renderInstances(RE_Render *r,
122  GR_RenderMode render_mode,
123  GR_RenderFlags render_flags,
124  GR_DrawParms dp);
125  void renderCentroidsOrBoxes(RE_Render *r,
126  GR_RenderMode render_mode,
127  GR_RenderFlags render_flags,
128  GR_DrawParms dp);
129  GR_SelectMode buildSelectionFromAttrib(RE_Render *r,
130  RE_Geometry *geo,
131  const GR_UpdateParms &p,
132  const GT_DataArrayHandle &sel);
133 
134  // transforms from the GT prim itself. If nested, there will be more
135  // instanced transforms than the top-level transforms (it'll be a multiple)
136  UT_Matrix4DArray myInstancedTransforms;
137 
138  // Decoration transforms, if nested (otherwise used instanced transforms)
139  UT_Matrix4DArray myTopLevelTransforms;
140 
141  // GT transforms convolved with object-level instancing
142  UT_Matrix4DArray myObjectInstancedTransforms;
143 
144  int myNestLevel;
145  int myInstancesPerPrim;
146  bool myHasObjectInstancing;
147  bool myHasCentroidLOD;
148  bool myHasBBoxLOD;
149  bool myHasPointsLOD;
150  bool myHasFullLOD;
151  bool myIsInstanceFile;
152 
153  bool myHasPartialVisibility;
154  bool myVisArraysDirty;
155  UT_IntArray myVisibleInstanceIndex;
156  UT_IntArray myVisibleInstances;
157  UT_IntArray myDeferInstances;
158  UT_IntArray myDeferPointInstances;
159  UT_Array<uint8> mySelected;
160  UT_Vector3FArray myInstanceColors;
161 
162  int64 myNameDataId;
163  int64 myInstanceId;
164 
165  UT_IntArray myMaterials;
166  UT_IntArray myMaterialGroupsVisible;
167  UT_BoundingBox myPrimBBox;
168 };
169 
170 #endif
virtual void render(RE_Render *r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp)
Set of parameters sent to GR_Primitive::viewUpdate().
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
GT_API const UT_StringHolder cache_name
virtual void viewUpdate(RE_Render *r, const GR_ViewUpdateParms &parms)
GLbitfield flags
Definition: glcorearb.h:1595
void setNestLevel(int nest_level)
virtual GR_BasePrimType getBasePrimType() const
The base primitive type is usually NORMAL unless this is a packed type.
set of parameters sent to GR_Primitive::update()
long long int64
Definition: SYS_Types.h:107
GR_RenderMode
Definition: GR_Defines.h:44
GR_BasePrimType
Definition: GR_Defines.h:335
virtual UT_Matrix4D getTransform(int) const
int64 exint
Definition: SYS_Types.h:116
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
#define GR_API
Definition: GR_API.h:10
GR_RenderFlags
Definition: GR_Defines.h:79
virtual const char * className() const
Return a string version of this class's name.
GLenum mode
Definition: glcorearb.h:98
void setTopTransforms(const UT_Matrix4DArray &top_xforms)
virtual bool getSingleTransform(UT_Matrix4D &mat) const
virtual int getNumInstances() const
int getNumTransforms() const
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
virtual void update(RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p)
int getNumTopTransforms() const
virtual bool updateOnViewChange(const GR_DisplayOption &dopts) const
If this primitive requires an update when the view changes, return true.
GR_SelectMode
Definition: GR_Defines.h:217