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  const UT_Vector2F &min_proj_size,
62  bool &visible,
63  bool &defer);
64 
65  virtual void update(RE_Render *r,
66  const GT_PrimitiveHandle &primh,
67  const GR_UpdateParms &p);
68 
69  virtual void render(RE_Render *r,
70  GR_RenderMode render_mode,
72  GR_DrawParms dp);
73 
74  virtual bool inViewFrustum(const UT_Matrix4D &objviewprojj,
75  const UT_BoundingBoxD *bbox = nullptr);
76 
77  virtual exint getNumGLPrimitives(const GR_DisplayOption *);
78 
79  virtual bool getSingleTransform(UT_Matrix4D &mat) const
80  {
81  if(getNumInstances() == 1)
82  {
83  mat = myInstancedTransforms(0);
84  return true;
85  }
86  return false;
87  }
88 
89  int getNumTopTransforms() const
90  {
91  if(myTopLevelTransforms.entries())
92  return myTopLevelTransforms.entries();
93  return myInstancedTransforms.entries();
94  }
95  int getNumTransforms() const
96  {
97  return myInstancedTransforms.entries();
98  }
99 
100  void setInstancer(const GT_PrimitiveHandle &ph);
101 
102 private:
103  virtual int getNumInstances() const;
104  virtual UT_Matrix4D getTransform(int instance_index) const
105  { return myInstancedTransforms(instance_index); }
106 
107  void buildInstancedSelection(RE_Render *r,
108  const GR_UpdateParms &p);
109  void buildInstancedColor(RE_Render *r,
110  const GR_UpdateParms &p);
111 
112  void buildPoints(RE_Render *r,
113  const GR_UpdateParms &p,
114  bool check_lod_centroid);
115 
116  void buildVisibilityInfo(RE_Render *r,
117  const GR_DisplayOption &opts,
118  const GR_FrustumList &frustums);
119  void buildInstanceIndexArrays(RE_Render *r,
120  bool has_partial_vis,
121  const UT_IntArray &vis_insts);
122 
123  void renderInstances(RE_Render *r,
124  GR_RenderMode render_mode,
125  GR_RenderFlags render_flags,
126  GR_DrawParms dp);
127  void renderCentroidsOrBoxes(RE_Render *r,
128  GR_RenderMode render_mode,
129  GR_RenderFlags render_flags,
130  GR_DrawParms dp);
131  GR_SelectMode buildSelectionFromAttrib(RE_Render *r,
132  RE_Geometry *geo,
133  const GR_UpdateParms &p,
134  const GT_DataArrayHandle &sel);
135  void buildLODInfo();
136  void buildNestedInstancing();
137  void buildNestedVisibility(RE_Render *r,
138  const GR_DisplayOption &opts,
139  const UT_Matrix4FArray &frustums,
140  const UT_BoundingBoxD &bbox);
141 
142  void determineNestedVisibility(int offset,
143  int level,
144  int index,
145  int mult,
146  const UT_Matrix4F &pxform,
147  const UT_Array<UT_BoundingBoxF> &bboxes,
148  const UT_Matrix4FArray &frustums);
149 
150  // transforms from the GT prim itself. If nested, there will be more
151  // instanced transforms than the top-level transforms (it'll be a multiple)
152  UT_Matrix4DArray myInstancedTransforms;
153 
154  // Decoration transforms, if nested (otherwise used instanced transforms)
155  UT_Matrix4DArray myTopLevelTransforms;
156 
157  // GT transforms convolved with object-level instancing
158  UT_Matrix4DArray myObjectInstancedTransforms;
159 
160  int myNestLevel;
161  int myInstancesPerPrim;
162  bool myHasObjectInstancing;
163  bool myHasCentroidLOD;
164  bool myHasBBoxLOD;
165  bool myHasPointsLOD;
166  bool myHasFullLOD;
167  bool myIsInstanceFile;
168  bool myQueuedPointIDValid;
169 
170  bool myHasPartialVisibility;
171  bool myHasPartialBBoxVisibility;
172  bool myVisArraysDirty;
173  UT_IntArray myVisibleInstanceIndex;
174  UT_Array<uint8> myVisibleInstances;
175  UT_Array<uint8> myVisibleBBoxes;
176  UT_IntArray myDeferInstances;
177  UT_IntArray myDeferPointInstances;
178  UT_Vector2i myDeferInstanceRange;
179  UT_Vector2i myDeferPointInstanceRange;
180  UT_IntArray myFullInstances;
181  UT_IntArray myBBoxVisibleInstances;
182  UT_Array<uint8> mySelected;
183  UT_Vector3FArray myInstanceColors;
184 
185  int64 myNameDataId;
186  int64 myInstanceId;
187 
188  UT_IntArray myMaterials;
189  UT_IntArray myMaterialGroupsVisible;
190  UT_IntArray myNestedInstanceLevels;
191  UT_BoundingBox myPrimBBox;
192 };
193 
194 #endif
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)
virtual void render(RE_Render *r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp)
Set of parameters sent to GR_Primitive::viewUpdate().
GLenum mode
Definition: glew.h:2163
GLuint index
Definition: glew.h:1814
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2864
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)
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:111
GR_RenderMode
Definition: GR_Defines.h:44
GR_BasePrimType
Definition: GR_Defines.h:338
virtual UT_Matrix4D getTransform(int) const
int64 exint
Definition: SYS_Types.h:120
virtual exint getNumGLPrimitives(const GR_DisplayOption *)
#define GR_API
Definition: GR_API.h:10
GR_RenderFlags
Definition: GR_Defines.h:80
virtual const char * className() const
Return a string version of this class's name.
void setTopTransforms(const UT_Matrix4DArray &top_xforms)
GLfloat GLfloat p
Definition: glew.h:16321
virtual bool getSingleTransform(UT_Matrix4D &mat) const
virtual int getNumInstances() const
virtual bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr)
int getNumTransforms() const
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
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.
GLint level
Definition: glew.h:1252
GR_SelectMode
Definition: GR_Defines.h:219
GLintptr offset
Definition: glew.h:1682