HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GR_InstanceManager.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_InstanceManager (C++)
7  *
8  * COMMENTS:
9  * Global instance cache and global draw pass management
10  *
11  */
12 #ifndef GR_InstanceManager_h
13 #define GR_InstanceManager_h
14 
15 
16 #include "GR_API.h"
17 
18 #include <GT/GT_Primitive.h>
19 #include <UT/UT_BoundingBox.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_StringMap.h>
22 #include <UT/UT_NonCopyable.h>
23 #include <UT/UT_StringHolder.h>
24 
25 #include "GR_Defines.h"
26 #include "GR_CommonDispOption.h"
27 #include "GR_DrawParms.h"
28 
29 class RE_Render;
30 
32 {
33 public:
34  static GR_InstanceManager &get() { return *theInstance; }
35 
36  // ------------------------------------------------------------------
37  // Deferred Instance logging
38  //
39  // This allows you to register what you will be drawing, have everything
40  // be globally processed to ensure a max poly count is respected, and get
41  // the results of that
42  // The bouding box, matrices, and arrays must not be deleted until the
43  // request has been processed and you call getDrawRequestResult().
44 
45  bool isActive() const { return myIsActive; }
46 
47  bool canQueueRequests() const
48  { return myIsActive && myInteractiveMode; }
49 
50  /// For primitives that cannot be culled, this at least notifies the
51  /// manager of the GL primitive count so it can be taken into account.
52  void queueUncullableDraw(int num_gl_prims);
53 
54  // Submit a draw request of a single object with 'nprims' GL primitives
55  // within bounding box 'box' and having a full world transform of
56  // 'world_mat'. Returns an ID which is used to fetch the results.
57  int queueDrawRequest(const RE_Render *r,
58  int num_gl_prims,
59  const UT_BoundingBox &box,
60  const UT_Matrix4D &world_mat,
61  GR_RenderMode rmode,
62  GR_RenderFlags rflags,
63  const GR_DrawParms &dp,
64  bool wireframe,
65  int32 prim_id,
66  bool selected,
67  UT_Vector3F *color = nullptr);
68 
69  // queue a list of instances to draw with different transforms.
70  // If only some of the draws should be performed, 'result_visible_indices'
71  // will indicte which ones.
72  int queueInstanceDrawRequest(const RE_Render *r,
73  int num_gl_prims,
74  const UT_BoundingBox &box,
75  const UT_Matrix4D &obj_transform,
76  const UT_Matrix4DArray &instances,
77  UT_IntArray &result_visible_indices,
78  GR_RenderMode rmode,
79  GR_RenderFlags rflags,
80  const GR_DrawParms &dp,
81  bool wireframe,
82  const GT_DataArrayHandle &prim_ids,
83  const UT_Array<uint8> *selected,
84  const UT_Vector3FArray *colors,
85  bool all_selected = false);
86 
87  // queue a partial list of instances to draw from a full list.
88  // 'visible_indices' must refer to entries in the 'instances' array.
89  // If only some of the draws should be performed, 'result_visible_indices'
90  // will indicte which ones.
91  int queuePartialInstanceDrawRequest(const RE_Render *r,
92  int num_gl_prims,
93  const UT_BoundingBox &box,
94  const UT_Matrix4D &obj_transform,
95  const UT_Matrix4DArray &instances,
96  const UT_IntArray &visible_indices,
97  UT_IntArray &result_visible_indices,
98  GR_RenderMode rmode,
99  GR_RenderFlags rflags,
100  const GR_DrawParms &dp,
101  bool wireframe,
102  const GT_DataArrayHandle &prim_ids,
103  const UT_Array<uint8> *selected,
104  const UT_Vector3FArray *colors,
105  bool all_selected = false);
106 
107  // Queue a single bounding box to be drawn.
108  void queueBBoxDraw(const RE_Render *r,
109  const UT_BoundingBox &box,
110  const UT_Matrix4D &obj_transform,
111  bool wireframe,
112  int32 prim_id,
113  bool selected,
114  UT_Vector3F *color = nullptr);
115 
116  // Queue a list of bounding boxes to be drawn (one bounding box transormed)
117  void queueBBoxDraw(const RE_Render *r,
118  const UT_BoundingBox &box,
119  const UT_Matrix4D &obj_transform,
120  const UT_Matrix4DArray &instances,
121  bool wireframe,
122  const GT_DataArrayHandle &prim_ids, //size of 'instances'
123  const UT_Array<uint8> *selected, //size of 'instances'
124  const UT_Vector3FArray *colors, //size of 'instances'
125  bool all_selected = false); // everything selected
126 
127  // Queue a partial list of bounding boxes to be drawn (one bbox transformed
128  // by some of the transforms, indexed by visible_instances).
129  void queuePartialBBoxDraw(
130  const RE_Render *r,
131  const UT_BoundingBox &box,
132  const UT_Matrix4D &obj_transform,
133  const UT_Matrix4DArray &instances,
134  const UT_IntArray &visible_indices,
135  bool wireframe,
136  const GT_DataArrayHandle &prim_ids, //size of 'instances'
137  const UT_Array<uint8> *selected, //size of 'instances'
138  const UT_Vector3FArray *colors, // size of ^^
139  bool all_selected = false); // everything selected
140 
142  {
143  NO_DRAW, // no instances to draw
144  PARTIAL_DRAW, // some instances, flagged ones drawn
145  POINTS_ONLY_DRAW, // draw all as points only
146  FULL_DRAW, // draw all instances as full geometry
147 
148  ERROR_NO_SUCH_ID, // the draw_id passed is invalid.
149  ERROR_NOT_PROCESSED // called too early, before all requests were
150  }; // processed.
151 
152  // Get the result of the global processing. 'visible instances' from the
153  // queued draw requests will only be set if the result is PARTIAL_DRAW.
154  // If it is somehow visible, the render mode, flags and draw parms will be
155  // set.
156  gr_DrawRequestResult getDrawRequestResult(int draw_id,
159  GR_DrawParms &parms) const;
160 
161 private:
162  void beginPass(const GR_CommonDispOption &opts);
163  void processDrawRequests(RE_Render *r,
164  const GR_CommonDispOption &opts);
165  void processQueuedBBoxes(RE_Render *r,
166  const GR_CommonDispOption &opts);
167  void endPass(RE_Render *r, const GR_CommonDispOption &opts);
168  void updateBBoxes(RE_Render *r);
169  void drawBBoxes(RE_Render *r, const GR_CommonDispOption &opts);
170  void generatePickID(const RE_Render *r, UT_Vector4i &pick_id);
171  bool determineBBoxMode(bool wire_req) const;
172 
173 
174  static void initialize();
175 
177  virtual ~GR_InstanceManager();
178 
179  class gr_Instance
180  {
181  public:
182  GT_PrimitiveHandle myInstance;
183  UT_BoundingBoxF myBBox;
184  int64 myLRU;
185  int64 myVersion;
186  int64 mySize;
187  int myUsage;
188  };
189 
191  int64 myLRU;
192 
193 public:
195  {
196  public:
198  const UT_Matrix4D *si,
199  const UT_Matrix4DArray *insts,
200  const UT_BoundingBox &bb,
201  const UT_IntArray *vi,
202  UT_IntArray *vr,
203  GR_RenderMode rm,
204  GR_RenderFlags rf,
205  GR_DrawParms dp)
206  : num_prims(np), single_inst(si), instances(insts), bbox(&bb),
207  visible_instances(vi), visible_result(vr), selected(false),
208  result(ERROR_NOT_PROCESSED), rmode(rm), rflags(rf), dparms(dp),
209  colors(nullptr), color(nullptr), selected_prims(nullptr),
210  wireframe(false) {}
211 
227  bool selected;
228  bool wireframe;
229  };
230 
232  {
233  public:
235  const UT_Matrix4DArray *insts,
236  const UT_BoundingBox &bb,
237  const UT_IntArray *vi)
238  : single_inst(si),instances(insts),bbox(&bb),visible_instances(vi),
239  offset(0), bucket(0), selected_prims(nullptr),
240  colors(nullptr), selected(false), wireframe(false), color(nullptr)
241  {}
251  bool selected;
252  bool wireframe;
253 
254  // the list to write to.
255  int offset;
256  int bucket;
257  };
258 
259 private:
260  UT_Array<gr_DrawRequest> myDrawRequests;
261  UT_Array<gr_BBoxRequest> myBBoxRequests;
262  UT_Matrix4FArray myBBoxTransforms;
263  UT_Array<int8> myBBoxCategories;
264  UT_Array<const UT_Vector3F *> myBBoxColors;
265  int64 myGLPrimCount;
266  fpreal myLastZ;
267  fpreal myLastMinZ;
268  bool myReducedDraws;
269  bool myIsActive;
270  bool myInteractiveMode;
271  UT_Vector3F mySelectionColor;
273 
274  static GR_InstanceManager *theInstance;
275 
276  // These two are friends for the pass management and initialization.
277  friend class GUI_SceneFeel;
278  friend class DM_VPortAgent;
279 };
280 
281 #endif
const UT_Array< uint8 > * selected_prims
bool isActive() const
const UT_Array< uint8 > * selected_prims
GLuint color
Definition: glcorearb.h:1260
const UT_Matrix4DArray * instances
GLbitfield flags
Definition: glcorearb.h:1595
gr_DrawRequest(int np, const UT_Matrix4D *si, const UT_Matrix4DArray *insts, const UT_BoundingBox &bb, const UT_IntArray *vi, UT_IntArray *vr, GR_RenderMode rm, GR_RenderFlags rf, GR_DrawParms dp)
long long int64
Definition: SYS_Types.h:106
GR_RenderMode
Definition: GR_Defines.h:42
const UT_Matrix4DArray * instances
GLintptr offset
Definition: glcorearb.h:664
#define GR_API
Definition: GR_API.h:10
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
int int32
Definition: SYS_Types.h:34
GR_RenderFlags
Definition: GR_Defines.h:77
GLenum mode
Definition: glcorearb.h:98
gr_BBoxRequest(const UT_Matrix4D *si, const UT_Matrix4DArray *insts, const UT_BoundingBox &bb, const UT_IntArray *vi)
double fpreal
Definition: SYS_Types.h:269
bool canQueueRequests() const
GLboolean r
Definition: glcorearb.h:1221