HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 private:
99  int getNumInstances() const;
100  void buildInstancedSelection(RE_Render *r,
101  const GR_UpdateParms &p);
102  void buildInstancedColor(RE_Render *r,
103  const GR_UpdateParms &p);
104 
105  void buildPoints(RE_Render *r,
106  const GR_UpdateParms &p,
107  bool check_lod_centroid);
108 
109  void buildVisibilityInfo(RE_Render *r,
110  const GR_FrustumList &frustums);
111  void buildInstanceIndexArrays(RE_Render *r,
112  bool has_partial_vis,
113  const UT_IntArray &vis_insts);
114  GR_UpdateParms checkForPackedMaterialAssignment(GR_UpdateParms &p);
115  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
116 
117  void renderInstances(RE_Render *r,
118  GR_RenderMode render_mode,
119  GR_RenderFlags render_flags,
120  GR_DrawParms dp);
121  void renderCentroidsOrBoxes(RE_Render *r,
122  GR_RenderMode render_mode,
123  GR_RenderFlags render_flags,
124  GR_DrawParms dp);
125 
126  // transforms from the GT prim itself. If nested, there will be more
127  // instanced transforms than the top-level transforms (it'll be a multiple)
128  UT_Matrix4DArray myInstancedTransforms;
129 
130  // Decoration transforms, if nested (otherwise used instanced transforms)
131  UT_Matrix4DArray myTopLevelTransforms;
132 
133  // GT transforms convolved with object-level instancing
134  UT_Matrix4DArray myObjectInstancedTransforms;
135 
136  int myNestLevel;
137  int myInstancesPerPrim;
138  bool myHasObjectInstancing;
139  bool myHasCentroidLOD;
140  bool myHasBBoxLOD;
141  bool myHasPointsLOD;
142  bool myHasFullLOD;
143  bool myIsInstanceFile;
144 
145  bool myHasPartialVisibility;
146  bool myVisArraysDirty;
147  UT_IntArray myVisibleInstanceIndex;
148  UT_IntArray myVisibleInstances;
149  UT_IntArray myBBoxInstances;
150  UT_IntArray myPointInstances;
151  UT_IntArray myDeferInstances;
152  UT_IntArray myDeferPointInstances;
153  UT_Array<uint8> mySelected;
154  UT_Vector3FArray myInstanceColors;
155 
156  int64 myNameDataId;
157 
158  UT_IntArray myMaterials;
159  UT_Map<int, UT_IntArray> myMaterialGroups;
160  UT_IntArray myMaterialGroupsVisible;
161  UT_BoundingBox *myAssignedBBox;
162  UT_Matrix4D myBBoxTransform;
163  UT_BoundingBox myPrimBBox;
164 };
165 
166 #endif
Unsorted map container.
Definition: UT_Map.h:83
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)
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:100
GR_RenderMode
Definition: GR_Defines.h:42
GR_BasePrimType
Definition: GR_Defines.h:327
int64 exint
Definition: SYS_Types.h:109
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
#define GR_API
Definition: GR_API.h:10
GR_RenderFlags
Definition: GR_Defines.h:77
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
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.