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 #include <GT/GT_PrimInstance.h>
15 
17 {
18 public:
19  GR_PrimInstance(const GR_RenderInfo *info,
20  const char *cache_name,
21  const GT_PrimitiveHandle &instance_prim,
22  const GT_PrimitiveHandle &instancer,
23  const UT_Matrix4DArray &instance_transforms,
24  const GU_ConstDetailHandle &instance_gdp,
25  int nest_level,
26  int prim_index = -1,
27  const UT_BoundingBox *bbox = nullptr);
28  ~GR_PrimInstance() override;
29 
30  const char *className() const override { return "GR_PrimInstance"; }
31 
33  { return GR_BASE_PRIM_INSTANCE; }
34 
35  void setTransforms(const UT_Matrix4DArray &inst_transforms);
36 
37  void setNestLevel(int nest_level)
38  {
39  myNestLevel = nest_level;
40  if(nest_level == 0)
41  myTopLevelTransforms.entries(0);
42  }
43 
44  // when nested, the top-level transforms are needed to position the point
45  // and primitive decorations.
46  void setTopTransforms(const UT_Matrix4DArray &top_xforms)
47  { myTopLevelTransforms = top_xforms; }
48  void setBounds(const UT_BoundingBox &bbox);
50  const GR_DisplayOption &dopts) const override
51  { return ((getNumInstances() > 1) ||
52  (myInstance?myInstance->updateOnViewChange(dopts):false)); }
53 
55  const GR_ViewUpdateParms &parms) override;
56 
60  const GR_DrawParms &dp,
61  const UT_Matrix4D &proj_view,
62  const UT_Matrix4D &object,
63  const UT_Vector2F &min_proj_size,
64  bool &visible,
65  bool &defer) override;
66 
68  const GT_PrimitiveHandle &primh,
69  const GR_UpdateParms &p) override;
70 
72  GR_RenderMode render_mode,
74  GR_DrawParms dp) override;
75 
76  bool inViewFrustum(
77  const UT_Matrix4D &objviewprojj,
78  const UT_BoundingBoxD *bbox = nullptr) override;
79 
80  exint getNumGLPrimitives(const GR_DisplayOption *) override;
81 
82  bool getSingleTransform(UT_Matrix4D &mat) const override
83  {
84  if(getNumInstances() == 1)
85  {
86  mat = myInstancedTransforms(0);
87  return true;
88  }
89  return false;
90  }
91 
92  int getNumTopTransforms() const
93  {
94  if(myTopLevelTransforms.entries())
95  return myTopLevelTransforms.entries();
96  return myInstancedTransforms.entries();
97  }
98  int getNumTransforms() const
99  {
100  return myInstancedTransforms.entries();
101  }
102 
103  void setInstancer(const GT_PrimitiveHandle &ph);
104 
108  { return myExtractTransfomCache; }
109 
111  { return myInstancedTransforms; }
112 
113 private:
114  int getNumInstances() const override;
115  UT_Matrix4D getTransform(int instance_index) const override
116  { return myInstancedTransforms(instance_index); }
117 
118  void buildInstancedSelection(RE_RenderContext r,
119  const GR_UpdateParms &p);
120  void buildInstancedColor(RE_RenderContext r,
121  const GR_UpdateParms &p);
122 
123  void buildPoints(RE_RenderContext r,
124  const GR_UpdateParms &p,
125  bool check_lod_centroid);
126 
127  void buildVisibilityInfo(RE_RenderContext r,
128  const GR_DisplayOption &opts,
129  const GR_FrustumList &frustums);
130  void buildInstanceIndexArrays(RE_RenderContext r,
131  bool has_partial_vis,
132  bool has_culled_instances,
133  const UT_IntArray &vis_insts);
134 
135  void renderInstances(RE_RenderContext r,
136  GR_RenderMode render_mode,
137  GR_RenderFlags render_flags,
138  GR_DrawParms dp);
139  void renderCentroidsOrBoxes(RE_RenderContext r,
140  GR_RenderMode render_mode,
141  GR_RenderFlags render_flags,
142  GR_DrawParms dp);
143 
144  GR_SelectMode buildSelectionFromAttrib(const GT_DataArrayHandle &sel);
145 
146  GR_SelectMode buildSelectionFromAttrib(RE_RenderContext r,
147  RE_Geometry *geo,
148  const GR_UpdateParms &p,
149  const GT_DataArrayHandle &sel);
150 
151  GR_SelectMode buildSelectionFromAttrib(RE_RenderContext r,
152  RV_Geometry *geo,
153  const GR_UpdateParms &p,
154  const GT_DataArrayHandle &sel);
155 
156  void buildLODInfo();
157  void buildNestedInstancing();
158  void buildNestedVisibility(RE_RenderContext r,
159  const GR_DisplayOption &opts,
160  const UT_Matrix4FArray &frustums,
161  const UT_BoundingBoxD &bbox);
162 
163  void determineNestedVisibility(int offset,
164  int level,
165  int index,
166  int mult,
167  const UT_Matrix4F &pxform,
168  const UT_Array<UT_BoundingBoxF> &bboxes,
169  const UT_Matrix4FArray &frustums);
170 
171  // transforms from the GT prim itself. If nested, there will be more
172  // instanced transforms than the top-level transforms (it'll be a multiple)
173  UT_Matrix4DArray myInstancedTransforms;
174 
175  // Decoration transforms, if nested (otherwise used instanced transforms)
176  UT_Matrix4DArray myTopLevelTransforms;
177 
178  // GT transforms convolved with object-level instancing
179  UT_Matrix4DArray myObjectInstancedTransforms;
180 
181  ExtractTransformCache myExtractTransfomCache;
182 
183  int myNestLevel;
184  int myInstancesPerPrim;
185  bool myHasObjectInstancing;
186  bool myHasCentroidLOD;
187  bool myHasBBoxLOD;
188  bool myHasPointsLOD;
189  bool myHasFullLOD;
190  bool myIsInstanceFile;
191  bool myQueuedPointIDValid;
192  bool myRenderFullLOD;
193 
194  bool myHasPartialVisibility;
195  bool myHasPartialBBoxVisibility;
196  bool myVisArraysDirty;
197  UT_IntArray myVisibleInstanceIndex;
198  UT_Array<uint8> myVisibleInstances;
199  UT_Array<uint8> myVisibleBBoxes;
200  UT_IntArray myDeferInstances;
201  UT_IntArray myDeferPointInstances;
202  UT_Vector2i myDeferInstanceRange;
203  UT_Vector2i myDeferPointInstanceRange;
204  UT_IntArray myFullInstances;
205  UT_IntArray myBBoxVisibleInstances;
206  UT_Array<uint8> mySelected;
207  UT_Vector3FArray myInstanceColors;
208 
209  int64 myNameDataId;
210  int64 myInstanceId;
211 
212  UT_IntArray myMaterials;
213  UT_IntArray myMaterialGroupsVisible;
214  UT_IntArray myNestedInstanceLevels;
215  UT_BoundingBox myPrimBBox;
216 };
217 
218 #endif
ExtractTransformCache & getExtractTransformCache()
GLbitfield flags
Definition: glcorearb.h:1596
bool getSingleTransform(UT_Matrix4D &mat) const override
void render(RE_RenderContext r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp) override
Set of parameters sent to GR_Primitive::viewUpdate().
const char * className() const override
Return a string version of this class's name.
void viewUpdate(RE_RenderContext r, const GR_ViewUpdateParms &parms) override
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
int64 exint
Definition: SYS_Types.h:125
GLint level
Definition: glcorearb.h:108
GT_API const UT_StringHolder cache_name
exint getNumGLPrimitives(const GR_DisplayOption *) override
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
void setNestLevel(int nest_level)
bool updateOnViewChange(const GR_DisplayOption &dopts) const override
If this primitive requires an update when the view changes, return true.
Temporary container for either a RV_Render and an RE_Render.
GT_PrimInstance::ExtractTransformEntry ExtractTransformEntry
set of parameters sent to GR_Primitive::update()
GLintptr offset
Definition: glcorearb.h:665
GR_RenderMode
Definition: GR_Defines.h:48
GR_BasePrimType
Definition: GR_Defines.h:366
virtual UT_Matrix4D getTransform(int) const
#define GR_API
Definition: GR_API.h:10
long long int64
Definition: SYS_Types.h:116
GT_PrimInstance::ExtractTransformCache ExtractTransformCache
GR_RenderFlags
Definition: GR_Defines.h:86
GR_BasePrimType getBasePrimType() const override
The base primitive type is usually NORMAL unless this is a packed type.
GLenum mode
Definition: glcorearb.h:99
void setTopTransforms(const UT_Matrix4DArray &top_xforms)
void checkForDeferredDraw(const RE_RenderContext 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) override
UT_Matrix4DArray & getInstancedTransforms()
virtual int getNumInstances() const
GLuint index
Definition: glcorearb.h:786
int getNumTransforms() const
void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p) override
GLboolean r
Definition: glcorearb.h:1222
int getNumTopTransforms() const
bool inViewFrustum(const UT_Matrix4D &objviewproj, const UT_BoundingBoxD *bbox=nullptr) override
GR_SelectMode
Definition: GR_Defines.h:241