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 private:
87  int getNumInstances() const;
88  void buildInstancedSelection(RE_Render *r,
89  const GR_UpdateParms &p);
90  void buildInstancedColor(RE_Render *r,
91  const GR_UpdateParms &p);
92 
93  void buildPoints(RE_Render *r,
94  const GR_UpdateParms &p,
95  bool check_lod_centroid);
96 
97  void buildVisibilityInfo(RE_Render *r,
98  const GR_FrustumList &frustums);
99  void buildInstanceIndexArrays(RE_Render *r,
100  bool has_partial_vis,
101  const UT_IntArray &vis_insts);
102  GR_UpdateParms checkForPackedMaterialAssignment(GR_UpdateParms &p);
103  bool fetchBoundingBox(UT_BoundingBoxD &bbox) const;
104 
105  void renderInstances(RE_Render *r,
106  GR_RenderMode render_mode,
107  GR_RenderFlags render_flags,
108  GR_DrawParms dp);
109  void renderCentroidsOrBoxes(RE_Render *r,
110  GR_RenderMode render_mode,
111  GR_RenderFlags render_flags,
112  GR_DrawParms dp);
113 
114  // transforms from the GT prim itself. If nested, there will be more
115  // instanced transforms than the top-level transforms (it'll be a multiple)
116  UT_Matrix4DArray myInstancedTransforms;
117 
118  // Decoration transforms, if nested (otherwise used instanced transforms)
119  UT_Matrix4DArray myTopLevelTransforms;
120 
121  // GT transforms convolved with object-level instancing
122  UT_Matrix4DArray myObjectInstancedTransforms;
123 
124  int myNestLevel;
125  int myInstancesPerPrim;
126  bool myHasObjectInstancing;
127  bool myHasCentroidLOD;
128  bool myHasBBoxLOD;
129  bool myHasPointsLOD;
130  bool myHasFullLOD;
131  bool myIsInstanceFile;
132 
133  bool myHasPartialVisibility;
134  bool myVisArraysDirty;
135  UT_IntArray myVisibleInstanceIndex;
136  UT_IntArray myVisibleInstances;
137  UT_IntArray myBBoxInstances;
138  UT_IntArray myPointInstances;
139  UT_IntArray myDeferInstances;
140  UT_IntArray myDeferPointInstances;
141  UT_Array<uint8> mySelected;
142  UT_Vector3FArray myInstanceColors;
143  RE_VertexArray *myColorVA;
144 
145  int64 myNameDataId;
146 
147  UT_IntArray myMaterials;
148  UT_Map<int, UT_IntArray> myMaterialGroups;
149  UT_IntArray myMaterialGroupsVisible;
150  UT_BoundingBox *myAssignedBBox;
151  UT_Matrix4D myBBoxTransform;
152  UT_BoundingBox myPrimBBox;
153 };
154 
155 #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
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)
virtual bool updateOnViewChange(const GR_DisplayOption &dopts) const
If this primitive requires an update when the view changes, return true.