HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DM_VPortAgent.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: DM_VPortAgent.h ( DM Library, C++)
7  *
8  * COMMENTS:
9  * DM_VPortAgent is the class for the 2D & 3D viewport agents.
10  * Viewport agents encapsulate the viewport functionality that is
11  * specific to a particular kind of viewport, such as
12  * rendering. There is one agent for each viewport.
13  */
14 
15 #ifndef __DM_VPortAgent__
16 #define __DM_VPortAgent__
17 
18 #include "DM_API.h"
19 #include "DM_Defines.h"
20 #include "DM_GeoDetail.h"
21 #include "DM_ViewportType.h"
22 
23 #include <UI/UI_Object.h>
24 #include <UI/UI_XPtr.h>
25 #include <OP/OP_Bundle.h>
26 #include <GEO/GEO_PrimTypeCompat.h>
27 #include <GR/GR_Defines.h>
28 #include <GR/GR_Light.h>
29 #include <GUI/GUI_RenderCommon.h>
30 #include <GUI/GUI_ViewParameter.h>
31 #include <GUI/GUI_ViewState.h>
32 #include <RE/RE_Texture.h>
33 #include <RE/RE_LightList.h>
34 #include <RE/RE_TimerQuery.h>
35 #include <RE/RE_PickBuffer.h>
36 #include <RE/RE_OGLFramebuffer.h>
37 #include <PXL/PXL_Lookup.h>
38 #include <UT/UT_UniquePtr.h>
39 #include <UT/UT_VectorTypes.h>
40 
41 #ifdef USE_VULKAN
42 #include <RV/RV_Geometry.h>
43 #include <RV/RV_VKFramebuffer.h>
44 #endif
45 
46 class RE_RenderWait;
47 class RE_RenderContext;
48 class RV_Instance;
49 class RV_Render;
50 class UI_Event;
51 class OBJ_Ambient;
52 class GR_PickRecord;
53 class GR_Uniforms;
54 class GUI_DisplayOption;
55 class GUI_GeoRender;
56 class GUI_SceneLook;
57 class GUI_ViewState;
58 class DM_FloorInterface;
59 class dm_PickBuffer;
60 class DM_PostEffects;
61 class DM_RenderHighQuality;
62 class DM_SceneManager;
63 class DM_SnapBuffer;
64 class DM_Viewport;
65 class DM_ViewportHooks;
66 
67 #ifdef USE_VULKAN
68 class DM_RenderVulkan;
69 #endif
70 
72 {
73 public:
74  DM_VPortAgent(DM_SceneManager &app,
75  DM_Viewport *display,
78  ~DM_VPortAgent() override;
79 
80  /// Each viewport has a unique integer id used to differentiate them.
81  int getUniqueId() const;
82 
83  /// Compute bounding box of the scene.
84  int getBoundingBox(UT_BoundingBox &bbox,
85  const UT_Matrix3R *rot,
86  bool non_templated_only,
87  bool skip_view_cam,
88  const DM_Viewport &viewport) const;
89 
90  /// Called by DM_Viewport to initialize and retire the viewport agent
91  /// when opening and closing. Treat as private.
92  void setupViewport();
93  void cleanupViewport();
94 
95  void refresh() const;
96 
97  /// The projection type of this viewport
98  DM_ViewportType getViewType() const { return myType; }
99 
100  /// For ortho viewports, the projection type (top, front, right, etc)
101  GUI_ViewParameter::axis getHomeAxis() const;
102 
103  /// Projection type, ortho or perspective
104  int isOrtho() const;
105 
106  /// Returns true if user interaction is occuring (drag, tumble, XCF).
107  bool isActiveRender() const;
108 
109  /// Returns true if this is rendering LOPs, and false if Obj,SOPs or DOPs.
110  bool isLopsView() const;
111 
112  /// The view state contains transform, projection and display options
113  const GUI_ViewState &getViewStateRef() const;
114  GUI_ViewState &getViewStateRef();
115 
116  /// Given a look id, and possibly a GUI_DetailList, find the GUI_DetailLook
117  /// with the supplied id.
118  GUI_DetailLookPtr getDetailLook(int look_id, const GUI_DetailList *geos);
119  GUI_DetailLookPtr getDetailLook(int node_id) const;
120  GUI_DetailLookPtr getDetailLookByIndex(int index) const;
121 
122  /// Fetch the detail of the current SOP or POP
123  const GUI_DetailLook*currentDetail() const;
124  GUI_DetailLook *currentDetail();
125 
126  // Return the op node the viewport is looking through (camera or light)
127  OP_Node *currentCamera() const;
128 
129  /// turn on/off the background elements
130  void drawBackground(bool draw);
131 
132  /// Called when loading a new hip file or File>New
133  void resetForNew();
134 
135  /// handle a change in our display options
136  void handleDisplayOptionEvent(UI_Event *e);
137 
138  /// handle a change in our view parameters
139  void handleViewParameterEvent(UI_Event *e);
140 
141  /// render all elements in this viewport
142  void doRender(RE_Render *r, int x, int y);
143 
144  /// render any transient overlay elements in the viewport
145  void overlayRender(RE_Render *r, int x, int y);
146 
147  /// render all handles present in the viewport
148  void renderHandles(RE_Render *r, int x, int y,
149  unsigned mask);
150 
151  /// Change the type of the viewport to a different projection or 2D/3D
152  void changeType(UI_Object *by, DM_ViewportType new_type);
153 
154  /// Called when the viewport closes, but is not deleted (such as a pane tab
155  /// switch).
156  void close();
157 
158  /// Request a deferred redraw.
159  void requestDraw() { myRedrawNotify.changed(nullptr); }
160 
161  /// @brief Access the beauty pass textures
162  /// Get a texture containing the color or depth of the beauty pass buffer.
163  /// This texture is always single-sampled.
164  RE_Texture *getBeautyPassTexture(RE_Render *r,
165  bool resolve_aa = true) const;
166  RE_Texture *getBeautyPassDepthTexture(RE_Render *r,
167  bool resolve_aa = true) const;
168 
169  /// copy the beauty pass to 'dst_texture'.
170  bool copyBeautyToTexture(RE_Render *r,
171  UT_DimRect src_area,
172  RE_Texture *dst_texture,
173  int dst_layer) const;
174 
176 
177  /// Returns the LUT for the beauty pass, if any.
178  PXL_Lookup *getBeautyLUT();
179  UT_UniquePtr<TIL_Raster> getBeautyPassImage(RE_Render *r);
180  UT_UniquePtr<TIL_Raster> getBeautyPassDepthImage(RE_Render *r);
181  bool getBeautyPassHDR() const;
182  void setBeautyPassConsolidate(bool con);
183 
184  /// ensure all geometry is up to date before a redraw, and cleanup after
185  void preSetupGeometry(RE_Render *r);
186  void postCleanupGeometry(RE_Render *r);
187  void setupGeometry(RE_Render* r);
188  void cleanupGeometry(RE_RenderContext r);
189  void fastSetupGeometry(RE_Render* r);
190 
191  /// returns a single pick result from the x,y mouse coords. The pick buffer
192  /// must be rendered first. Returns false if nothing was picked.
193  bool singlePickObject(RE_Render *r, int x, int y,
195  const GR_ObjectPickFlags &pick_flags,
196  fpreal *depth,
197  const GUI_DetailList *geos);
198 
199  /// Check for a pick on a handle. Returns true if a handle was picked.
200  bool singlePickHandle(RE_Render *r, int x, int y,
202  fpreal *depth);
203 
204  /// @brief Area select objects, possibly with a matte.
205  /// returns a list of object IDs for those objects picked. This does not
206  /// pick handles or SOP geometry. The return value is the length of the pick
207  /// list.
208  int boxPickObject(RE_Render *r,
209  const UT_DimRect &area,
210  uint8 *texture,
211  UT_Array<GR_PickRecord> &pick_records,
212  bool visible_only,
213  bool wholy_contained,
214  const GUI_DetailList *geos);
215 
216  /// @brief Single select a geomerty element.
217  /// Returns a single pick result for components in objects 'geos'.
218  bool singlePickComponent(RE_Render *r,
219  int x, int y,
221  unsigned pickmask,
223  fpreal *depth,
224  const GUI_DetailList *geos,
225  bool enable_occlusion);
226  /// Box, lasso or paint select components.
227  /// @param contained only return results completely inside area
228  /// @param interactive if true, only return "visible" results, ignoring
229  /// primitives which rasterize to less than a single pixel.
230  int boxPickComponent(RE_Render *r,
231  const UT_DimRect &area,
232  uint8 *texture,
233  UT_Array<GR_PickRecord> &pick_records,
234  bool sort_records,
235  unsigned pickmask,
237  bool visible_only,
238  bool contained,
239  bool interactive,
240  const GUI_DetailList *geos);
241 
242  // Return the raw pick buffer textures that are used for visible
243  // component picking. These buffer may be used for picking or
244  // rendering purposes.
245  void getComponentPickBuffers(RE_Render *r,
246  UT_SharedPtr<RE_Texture> &pickhigh,
247  UT_SharedPtr<RE_Texture> &picklow,
249 
250  // Return the objects that should be rendered into the pick buffer
251  // for an object level pick
252  void getObjectPickGeos( const GUI_DetailList *looks,
253  UT_Array<GUI_GeoRender *> &out_all_geos,
254  UT_Array<GUI_GeoRender *> &out_xray_geos,
255  UT_Array<GUI_GeoRender *> &out_xray_sec_geos);
256 
257  // Return the objects that should be rendered into the pick buffer
258  // for an component pick
259  void getComponentPickGeos(const GUI_DetailList *looks,
260  unsigned int xray_pickmask,
261  UT_Array<GUI_GeoRender *> &out_all_geos,
262  UT_Array<GUI_GeoRender *> &out_xray_geos);
263 
264  /// @brief Single select a geometry element to snap to.
265  /// Returns a single snap result for components in objects 'geos'.
266  bool singleSnapComponent(RE_Render *r,
267  int x, int y,
268  bool hide_selected, bool enable_occlusion,
269  bool do_current,
270  bool do_xray, bool do_guides,
271  bool extend_floor,
273  UT_Vector2i *result_offset,
274  UT_Array<GR_PickRecord> &near_results,
275  unsigned pickmask, int gravity,
277  const GUI_DetailList *geos=NULL);
278 
279  /// @brief Single select a peanut element to snap to.
280  /// Returns a single snap result for peanuts.
281  bool singleSnapPeanut(RE_Render *r,
282  int x, int y,
283  bool hide_selected, bool enable_occlusion,
284  bool do_xray, bool do_guides,
285  bool extend_floor,
287  UT_Vector2i *result_offset,
288  unsigned pickmask,
290  const GUI_DetailList *geos=NULL);
291 
292  // Currently only for scene graph view.
293  bool snapGeometry(RE_RenderContext r,
294  int x, int y,
295  int pnt_rad, int edge_rad, int face_rad,
296  bool occlusion,
297  bool orient_normals,
298  DM_SnapSelection snap_sel,
299  UT_Vector3D &p,
300  UT_Vector3D &n,
301  int64 serial);
302 
303  // `RV_Render` pick renders
304 #ifdef USE_VULKAN
305  /// @brief Area select objects, possibly with a matte.
306  /// returns a list of object IDs for those objects picked. This does not
307  /// pick handles or SOP geometry. The return value is the length of the pick
308  /// list.
309  int boxPickObjectVK(RE_RenderContext r,
310  const UT_DimRect &area,
311  uint8 *texture,
312  UT_Array<GR_PickRecord> &pick_records,
313  bool visible_only,
314  bool wholy_contained,
315  const GUI_DetailList *geos);
316 
317  static bool initShaders(RV_Instance* inst);
318  static void cleanupShaders();
319 #endif
320 
321  /// Call to manually invalidate any cached pick/snap buffers when the
322  /// automatic detection is insufficient.
323  void invalidatePickBuffers();
324 
325  /// Box, lasso or paint select components.
326  /// Render all geometry in the viewport using render mode 'render_type'.
327  GUI_RenderPassFlags renderGeometry(RE_RenderContext r,
328  GR_RenderMode render_type,
329  GR_ShadingPass shade_pass,
330  GR_AlphaPass apass,
331  OP_Bundle *visible_objs = NULL,
333 
334  /// @brief Draw geometry decorations and markers
335  /// Render all decorations. If 'hover_decorations' is true, only the
336  /// locate-style decorations will be drawn.
337  void renderDecorations(RE_RenderContext r,
338  GUI_DisplayOption *dispopt,
339  bool hover_decorations);
340 
341  /// Render geometry corresponding to the OP_Nodes is the passed list.
342  GUI_RenderPassFlags renderSomeGeometry(
344  int x, int y,
345  const UT_Array<OP_Node*> &nodes,
346  const UT_IntArray *detail_indexes,
347  GR_RenderMode render_type,
348  GR_ShadingPass shade_pass,
349  GR_AlphaPass apass,
350  bool do_geometry_setup);
351 
352  /// Render a single geometry using render mode 'render_type'.
353  GUI_RenderPassFlags renderSingleGeo(
355  GUI_GeoRender *gr,
356  GR_RenderMode render_type,
357  GR_ShadingPass shading_pass,
358  GR_AlphaPass ap,
359  bool init_lights,
360  bool treat_uv_viewport_as_3d = false);
361 
362  /// Our floor or construction plane.
363  void renderFloor(RE_Render *r, int x, int y);
364  /// Render construction plane in overlayRender.
365  void overlayRenderFloor(RE_Render *r, int x, int y);
366 
367  const DM_FloorInterface *getFloorInterface() const
368  { return myFloorInterface; }
369  DM_FloorInterface *getFloorInterface() { return myFloorInterface; }
370 
371  /// Interface to viewport hooks (render and mouse)
372  DM_ViewportHooks &hooks() const { return *myViewportHooks; }
373 
374  bool needsOverlayRender() const
375  { return myNeedsOverlayRender; }
376 
377  /// Methods to process mouse movement
378  /// @{
379  bool hasLocates();
380  void handleLocateEvent(UI_Event *e);
381  /// @}
382 
383  /// @brief Access displayed objects in the viewport
384  /// Return a handle to an object displayed in the viewport. Do not cache
385  /// these over several redraws, as they may become invalid. get*Object()'s
386  /// index parameter can be 0 to getNum*Objects()-1.
387  /// @{
388  int getNumOpaqueObjects() const;
389  DM_GeoDetail getOpaqueObject(int index) const;
390 
391  int getNumTransparentObjects() const;
392  DM_GeoDetail getTransparentObject(int index) const;
393 
394  int getNumUnlitObjects() const;
395  DM_GeoDetail getUnlitObject(int index) const;
396 
397  int getNumXRayObjects() const;
398  DM_GeoDetail getXRayObject(int index) const;
399  /// @}
400 
401  /// Returns the current detail within the object, when at SOP/POP/DOP level.
402  DM_GeoDetail getCurrentDetail() const;
403 
404  void initGPUTimers(RE_Render *r);
405  void collectGPUTimers(RE_Render *r);
406 
407  GUI_RotoView getRotoViewType();
408 
409  void markGeoSetup(bool setup,
410  DM_Viewport *setup_port = NULL);
411  bool isGeoSetup() const { return mySetupFlag; }
412 
413  // All lights in the scene, for the material render codepath.
414  void setGlobalLightArray(const UT_Array<OBJ_Ambient *> &l);
415  void setGlobalLightArray(const UT_ValArray<RE_Light*> &l);
416 
417  // Get and set lighting information.
418  bool setupLights(RE_Render *r, GUI_DisplayOption *opt);
419  void cleanupLights(RE_Render *r);
420 
422  { return myMaterialLights; }
423 
424  GR_LightingPass getLightingPass() const { return myLightingPass; }
425  void setLightingPass(GR_LightingPass p) { myLightingPass=p;}
426 
427  // Returns the approximate memory usage of the viewport at the current size
428  // given hdr on/off, high quality lighting on/off, transparency > low,
429  // and aa at 1,2,4 or 8x.
430  int64 getFramebufferUsageKB(bool hdr, bool hql, bool trans,
431  int aa);
432 
433  // using zt[0] / (Z + zt[1]) will transform zbuffer values into viewspace Z
434  // If light is specified, then the shadowmap range of that light is computed
435  void getZBufferTransform(float zt[2],RE_Light *light=NULL);
436 
437  // Handle a change in which geometry is displayed.
438  // For keeping track of what type of UVs to show in UV mode.
439  void handleNewGeometryEvent(UI_Event *e);
440  void updateAttributeOptions(const GU_DetailHandle &gdh);
441 
442  // ---------------------------------------------------------------------
443  // the following methods should be treated as private to DM.
444 
445  /// Methods for starting and stopping events
446  /// in the old performance monitor.
447  void startPerfMonTimer(RE_Render *r,
448  RE_GPUTimer &timer,
449  const char *msg) const;
450  void stopPerfMonTimer(RE_Render *r,
451  RE_GPUTimer &timer) const;
452 
453  // setup proper winding and culling, returning a set of flags to use for
454  // the cleanup method.
455  int setupBackfaceAndWinding(RE_Render *r,
456  const GUI_DisplayOption *opts);
457  void cleanupBackfaceAndWinding(RE_Render *r,
458  int setup_flags);
459 
460  // resolve the AA Z buffer to a single sample, taking the further sample
461  bool resolveDepthBuffer(RE_Render *r,
462  RE_Texture *aa_depth_tex,
463  RE_Texture *depth_tex) const;
464 
465  int64 getSceneVersion(fpreal t, bool shadow, bool &timedep);
466 
467  // access to parent viewport
468  const DM_Viewport *getDisplay() const { return myDisplay; }
469  DM_Viewport *getDisplay() { return myDisplay; }
470 
471  // for transparency
472  int getTransparencyLayers(RE_RenderContext r,
473  const GUI_DisplayOption *disp);
474  void prepareStencilRouting(RE_RenderContext r,int nsamples);
475  void prepareABufferFront(RE_RenderContext r, int nsamples);
476 
477  void updateTimeDependentLook(fpreal t);
478 
479  bool isToolbarLinked() const; // see .C file note
480 
481  const GUI_DetailPtrList &getDetails() const;
482  const GUI_DetailPtrList &getDetails();
483 
484  void setupViewUniforms(RE_Render *r);
485  void cleanupViewUniforms(RE_Render *r);
486 
487  // Looks through the lights for an environment map
488  void applyEnvMapOverride(RE_Render *r) const;
489 
490  // Helper methods to determine if a GUI_DetailLook, or OBJ_Node, should be
491  // hidden as a view cam object when hiding view cam geometry.
492  static bool shouldHideAsViewCamObject(const DM_Viewport &vport,
493  const GUI_DetailLook &look);
494  static bool shouldHideAsViewCamObject(const DM_Viewport &vport,
495  const OBJ_Node &node);
496 
497  // For DM_RenderHighQuality.
498  bool needsToDrawFloor() const
499  { return myDrawFloorTransientFlag; }
500  void initFogVolume(RE_Render *r,
501  DM_Viewport *vport,
502  GUI_FogMode fog,
503  const RE_Texture *zdepth) const;
504  RE_Texture *getFogVolumeTexture() const;
505  RE_Texture *getRandomDitherTexture(RE_Render *r);
506 
507  const DM_SceneManager &modeler() const
508  { return mySceneManager; }
509 
510  void renderBackgroundImage(RE_RenderContext r);
511  void renderForegroundImage(RE_RenderContext r);
512 
513  void resolveBeautyColorPass(RE_Render *r,
514  RE_Texture *aa_color,
515  RE_Texture *aa_depth,
516  RE_Texture *aa_nml,
517  bool xray) const;
518 protected:
519  friend class dm_SetupTask;
520 
521 private:
522 
523  RE_RenderContext getVulkanContext(RE_Render *r, int thread_index=0) const;
524 
525  DM_SceneManager &modeler()
526  { return mySceneManager; }
527 
528  const GUI_SceneLook *getLook() const { return mySceneLook.get(); }
529  GUI_SceneLook *getLook() { return mySceneLook.get(); }
530 
531  bool shouldDisplayObject(const DM_Viewport &vport,
532  GUI_DetailLook *look,
533  OBJ_Node *node);
534 
535  bool shouldVisualizeObject(const DM_Viewport &vport,
536  GUI_DetailLook *look,
537  OBJ_Node *node);
538 
539  bool shouldShowComponentSelections(const GUI_DetailLook &look,
540  const GUI_DisplayOption &d) const;
541 
542  enum DM_BufferBlend
543  {
544  ACCUM_ADD,
545  ACCUM_REPLACE,
546  ACCUM_ALPHA_BLEND
547  };
548 
549  // prints a message in the viewer (centrally justified) on a given line
550  void renderMessage( RE_Render *ren, int x, int y,
551  const char* msg, int line );
552  // renders true viewer name
553  void doRenderCurrentName(RE_Render *r, int x, int y);
554  // renders the snapshot label
555  void doRenderSnapshotName(RE_Render *r, int x, int y);
556 
557  // prints a message in the viewer for camera (central, bottom justified)
558  void renderCameraMessage( RE_Render *ren, int x, int y,
559  const char* msg);
560 
561  // Render a mask over the parts of the viewport outside of the view
562  // subregion.
563  void renderViewMask(RE_Render *r, int x, int y);
564 
565  bool resizeBeautyPassBuffer(RE_RenderContext r,
566  int width, int height,
567  bool hdr, bool needs_aa);
568  void destroyBeautyPassBuffer();
569  RE_OGLFramebuffer *getBeautyPassBuffer(bool allow_aa);
570 
571  // initializes the view and projection to a 1:1 pixel transform.
572  void pushIdentityOrthoView(RE_Render *r);
573  void popIdentityOrthoView(RE_Render *r);
574 
575  // Render the viewport name.
576  void doRenderName(RE_Render *r, int x, int y,
577  bool snapshot_name = false);
578  // Render the current state information.
579  void doRenderStateStatus(RE_Render *r);
580  // Render a mask over the parts of the viewport outside of the view
581  // subregion.
582  void doRenderViewMask(RE_Render *r, int x, int y);
583 
584  // Draw the view overview gadget.
585  void doRenderViewOverview(RE_Render *r, int x, int y);
586 
587  // Common utility methods to setup lights and the z buffer.
588  void setupForRender(RE_RenderContext ren,
589  bool allow_smooth = true);
590  void cleanupAfterRender(RE_RenderContext ren);
591 
592 
593  void setGammaPass(bool b) { myGammaPass = b?1:0; }
594 
595  void doRenderNoHookUnlitObjects(RE_RenderContext r,
596  int x, int y,
597  bool xray_pass);
598  void doRenderUnlitObjects(RE_RenderContext r, int x, int y);
599 
600  // Render the camera's mask (bars and anything else inside the mask)
601  void doRenderMask(RE_Render *r, int, int);
602 
603  // Render outlines
604  void doRenderOutlines(RE_RenderContext r);
605  // Render separate outlines for objects that have them
606  void doRenderSeparateOutline(RE_RenderContext r,
607  const UT_IntArray &indices);
608  void destroySelectionBuffer();
609 
610  void startBeautyPass(RE_RenderContext r,
611  bool allow_aa=true);
612  void endBeautyPass(RE_RenderContext r, bool allow_aa=true);
613  bool isBeautyPassAA(bool allow_aa = true);
614 
615  // helper methods for setting up stereo passes
616  void setupStereo3d(RE_Render *r);
617  void setupStereoVR(RE_Render *r);
618  void cleanupStereo3d(RE_Render *r);
619  void interruptStereo(RE_Render *r);
620  void resumeStereo(RE_Render *r);
621  void setupStereo3dForLeftCamera(RE_Render *r,
622  bool uniforms_for_3d);
623  void setupStereo3dForRightCamera(RE_Render *r,
624  bool uniforms_for_3d);
625  void updateStereoViewUniforms(RE_Render *r, bool left);
626  void assignStereoLeft(RE_Render *r,
627  const GUI_ViewState::GUI_ViewType vt);
628  void assignStereoRight(RE_Render *r,
629  const GUI_ViewState::GUI_ViewType vt);
630  void assignStereoTop(RE_Render *r,
631  const GUI_ViewState::GUI_ViewType vt);
632  void assignStereoBottom(RE_Render *r,
633  const GUI_ViewState::GUI_ViewType vt);
634 
635  bool setupTransparentBuffers(RE_RenderContext r, int hdr);
636  void destroyTransparentBuffers();
637 
638  void renderViewport(RE_RenderContext r, int x, int y);
639  void renderSceneView(RE_RenderContext r, int x, int y);
640 
641  // Render the transparent bars defined by the camera's mask parameters
642  void renderCameraMask(RE_Render *r);
643 
644  // Render the object that goes on top of the camera mask
645  void renderCameraMaskOverlay(RE_Render *, int, int);
646 
647  void renderTransparentGeometry(
649  GUI_DisplayOption *dispopt);
650  bool renderHQTransparencyPass(
651  RE_RenderContext r, int x, int y,
652  GUI_DisplayOption *dispopt,
653  const UT_Array<GUI_DetailLook *> *geos = NULL,
654  bool for_xray = false);
655  bool setupHQTransparentBuffers(
656  RE_RenderContext r, int nsamples,
657  bool hdr);
658  void destroyHQTransparentBuffers();
659 
660  void initStencilABuffer(RE_RenderContext r, int nsamples);
661 
662  bool setupUnlitAlphaBuffer(RE_RenderContext r, bool zbuf);
663  void destroyUnlitAlphaBuffer();
664 
665  // Geometry pick code
666  bool createPickBuffer(RE_RenderContext r);
667  bool renderPickBuffer(RE_RenderContext r,
668  bool object_pick,
669  bool enable_occlusion,
670  unsigned int pickmask,
672  const GUI_DetailList *geos,
673  const GR_ObjectPickFlags &pick_flags);
674 
675  // Query the pick buffer. Returns true on a hit.
676  // allow_geo - allow geometry picks (either obj or component
677  // depending on geo_is_object)
678  // allow_handle - allow handle picks
679  // geo_is_object - geometry records are objects instead of
680  // components
681  // geo_ignore_depth - avoid scanning samples looking for a closer
682  // hit (only when !geo_is_object)
683  // geo_prioritize - scan samples looking for a higher priority
684  // component pick (only when !geo_is_object)
685  // floor_prioritize - scan samples looking for a higher priority
686  // floor component pick (only when allow_handle
687  // and does not differentiate between different
688  // floors)
689  // overlap_dist - the distance at which to consider picks to
690  // be essentially overlapping and employ some
691  // heuristics to pick the best one
692  bool pickFromBuffer(RE_RenderContext r,
693  RE_PickBuffer *pick_buffer,
694  int x, int y,
695  bool allow_geo,
696  bool allow_handle,
697  bool geo_is_object,
698  bool geo_ignore_depth,
699  bool geo_prioritize,
700  bool floor_prioritize,
701  int pick_dist,
702  int overlap_dist,
704  UT_Array<GR_PickRecord> *results,
705  UT_Vector2i *result_offset,
706  fpreal *depth,
707  const GUI_DetailList *geos);
708 
709  int filterPickData(int32 *pick_base_data,
710  int32 *pick_component_data,
711  int npicks,
712  UT_Array<GR_PickRecord> &pick_records);
713  int subtractPickData(const UT_Vector3iArray &base,
714  const UT_Vector3iArray &comp,
715  const UT_Array<GR_PickRecord> &outside,
716  UT_Array<GR_PickRecord> &results);
717  void objectPickRender(RE_RenderContext r,
718  unsigned int pickmask,
720  const GUI_DetailList *geos,
721  const GR_ObjectPickFlags &pick_flags);
722  void doObjectBoxPick(RE_RenderContext r,
723  const UT_DimRect &area,
724  UT_Array<GR_PickRecord> &pick_records,
725  bool visible_only,
726  bool invert_mask,
727  bool use_texture,
728  bool clip_edges,
729  const GUI_DetailList *geos);
730 
731  int componentPickRender(RE_RenderContext r,
732  unsigned int pickmask,
733  unsigned int xray_pickmask,
735  const GUI_DetailList *geos,
736  GR_PickStyle pickstyle,
737  bool invert_mask,
738  UT_Array<GR_PickRecord> *pick_rec);
739  int boxPickVisibleComponent(RE_RenderContext r,
740  const UT_DimRect &area,
741  uint8 *texture,
742  UT_Array<GR_PickRecord> &pick_records,
743  unsigned pickmask,
745  const GUI_DetailList *geos,
746  bool contained);
747  int boxPickFrustumComponent(RE_RenderContext r,
748  const UT_DimRect &area,
749  uint8 *texture,
750  UT_Array<GR_PickRecord> &pick_records,
751  unsigned pickmask,
753  const GUI_DetailList *geos,
754  bool visible_only,
755  bool contained);
756 
757 #ifdef USE_VULKAN
758  void doObjectBoxPickVK(RE_RenderContext r,
759  const UT_DimRect &area,
760  UT_Array<GR_PickRecord> &pick_records,
761  bool visible_only,
762  bool invert_mask,
763  bool use_texture,
764  bool clip_edges,
765  const GUI_DetailList *geos);
766 
767  void doPickBufferRenderVK(RE_RenderContext r,
768  bool object_pick,
769  bool enable_occlusion,
770  unsigned int pickmask,
772  const GUI_DetailList *geos,
773  const GR_ObjectPickFlags &pick_flags);
774 
775  void doSnapBufferRenderVK(RE_RenderContext r,
776  unsigned int snapmask,
777  unsigned int xray_snapmask,
779  const GUI_DetailList *geos,
780  bool hide_selected,
781  bool enable_occlusion,
782  bool do_current,
783  bool do_guides);
784 
785  void objectPickRenderVK(RE_RenderContext r,
786  unsigned int pickmask,
788  const GUI_DetailList *geos,
789  const GR_ObjectPickFlags &pick_flags);
790 
791  int componentPickRenderVK(RE_RenderContext r,
792  unsigned int pickmask,
793  unsigned int xray_pickmask,
795  const GUI_DetailList *geos,
796  GR_PickStyle pickstyle,
797  bool invert_mask,
798  bool has_pick_map,
799  UT_Array<GR_PickRecord> *pick_rec);
800 
801  int boxPickFrustumComponentVK(RE_RenderContext r,
802  const UT_DimRect &area,
803  uint8 *texture,
804  UT_Array<GR_PickRecord> &pick_records,
805  unsigned pickmask,
807  const GUI_DetailList *geos,
808  bool visible_only,
809  bool contained);
810 
811  void renderOffsetDepthPassVK(RE_RenderContext r,
812  bool skip_obj_sel_looks,
813  bool skip_guide_looks,
814  bool skip_nonsnappable_looks,
815  bool skip_current_look);
816 
817 #endif
818  void renderOffsetDepthPass(RE_RenderContext r,
819  bool skip_obj_sel_looks = false,
820  bool skip_guide_looks = false,
821  bool skip_nonsnappable_looks = false,
822  bool skip_current_look = false);
823  void flattenAlphaPass(RE_RenderContext r,
824  const GUI_DisplayOption *dispopt,
825  int num_layers);
826  // end pick code
827 
828  // Snapping and handle pick code
829  bool createSnapHandleBuffer(RE_RenderContext r);
830  bool renderHandleBuffer(RE_RenderContext r);
831  bool renderSnapBuffer(RE_RenderContext r,
832  unsigned int snapmask,
834  const GUI_DetailList *geos,
835  bool hide_selected,
836  bool enable_occlusion,
837  bool do_current,
838  bool do_xray, bool do_guides,
839  bool extend_floor);
840  // end snapping and handle pick code
841 
842  bool sampleDepth(RE_Render *r, int x, int y, fpreal &z,
843  RE_Texture *depth_texture);
844 
845  void renderXray(RE_RenderContext r,
846  GUI_DisplayOption *dispopts);
847  void resolveXrayBeautyPass(RE_RenderContext r) const;
848  void renderOnionSkin(RE_RenderContext r,
849  GUI_DisplayOption *dispopts);
850 
851  bool renderBeautyPass(RE_RenderContext r, int x, int y,
852  GUI_DisplayOption *dispopt,
853  bool &needs_lighting);
854  bool renderTransparencyPass(RE_RenderContext r,
855  int x, int y,
856  GUI_DisplayOption *dispopt);
857  bool renderEnvironmentMaps(RE_RenderContext r,
858  bool query_only);
859  void renderEnvMap(RE_RenderContext r,
860  RE_OGLTexture *cubemap,
861  int cubemap_unit) const;
862  void compositePasses(RE_RenderContext r,
863  const GUI_DisplayOption *dispopt,
864  bool has_trans_pass,
865  bool has_alpha_buffers);
866 
867  void normalQualityRender(
869  GUI_DisplayOption *dispopt,
870  GR_AlphaPass alpha_pass,
872  const UT_Array<GUI_DetailLook*> *geos=NULL);
873 
874  bool isUsingHQLighting(RE_RenderContext r,
875  const GUI_DisplayOption *dispopt);
876 
877  void renderOverlappingUV(RE_RenderContext r,
878  GUI_DisplayOption *disp);
879  bool setupOverlappingUVBuffer(RE_RenderContext r,
880  int w, int h);
881  void destroyOverlappingUVBuffer();
882 
883  void renderCoincidentPoints(RE_Render *r,
884  GUI_DisplayOption *disp);
885  bool setupCoincidentBuffer(RE_Render *r, int w, int h);
886  void destroyCoincidentBuffer();
887 
888  void subtractFromSelection(UT_Array<GR_PickRecord> &results,
890  exint start_subtracting_at,
892 #ifdef MBSD_COCOA
893  void dmOSXDepthBufferWorkaround(RE_Render *r,
894  RE_Texture *tex);
895 #endif
896  void updateVisibleBoundariesAndViews(int vis_display_sets);
897 
898  void redrawNeeded(UI_Event *);
899 
900  mutable RE_ShaderHandle *myDepthResolveShader;
901 
902  UT_Array<RE_Light *> myMaterialLights;
903 
904  RE_OGLFramebuffer *myBeautyPassBuffer;
905  RE_OGLFramebuffer *myBeautyPassAABuffer;
906  RE_Texture *myBeautyColorTexture;
907  RE_Texture *myBeautyDepthTexture;
908  RE_Texture *myBeautyPassAACTexture;
909  RE_Texture *myBeautyPassAAZTexture;
910  int myBeautyPassSamples;
911  bool myBeautyPassHDR;
912 
913  RE_OGLFramebuffer *myTransparentFBO;
914  RE_Texture *myTransparentColorTex;
915  RE_Texture *myTransparentZTex;
916  bool myTransparentHDR;
917 
918  RE_OGLFramebuffer *mySelectionIDFBO;
919  RE_Texture *mySelectionIDTex;
920  RE_Texture *mySelectionZTex;
921 
922  UT_UniquePtr<RE_Texture> myOutlineColorsTex;
923  UT_Vector4FArray myOutlineColorsArray;
924 
925  UT_UniquePtr<RE_OGLFramebuffer> myOutlineBitmaskFBO;
926  UT_UniquePtr<RE_Texture> myOutlineBitmaskTex;
927 
928 #ifdef USE_VULKAN // WIP: make private, and make heleper func
929  // so access in DM_Viewport insn't needed
930 public:
932 
933 private:
934  // extra data for box picking
935  UT_UniquePtr<RV_Geometry> myBoxPickObjectGeometryVK;
936  UT_UniquePtr<RV_VKImage> myBoxPickMaskTextureVK;
937 
938  UT_UniquePtr<RV_ShaderVariableSet> myBoxPickSetVK;
939  UT_UniquePtr<RV_Framebuffer> myBoxPickFramebufferVK;
940  UT_UniquePtr<RV_VKImage> myImageFallbackVK;
941  UT_UniquePtr<RV_VKImage> myBoxPickDepthVK;
942 #endif
943  DM_RenderHighQuality *myHQRender;
944  DM_PostEffects *myPostEffects;
945 
946  RE_Texture *myRandomDitherTexture;
947  RE_TextureMap *myRandomDitherTextureMap;
948 
949  PXL_Lookup myLookup;
950  UT_String myLUTFile;
951  UT_String myOCIODisplay;
952  exint myOCIOSerial;
953 
954  bool myIsBeautyPass;
955  GR_LightingPass myLightingPass;
956  bool myIsAlphaPass;
957  bool myUseUnlitMask;
958  bool myHighQualityMode;
959  bool myNeedsXRayResolve;
960  bool myHasGILight;
961  bool myHasEnvLight;
962  bool myHasCascadingShadowLight;
963  bool myNeedsOverlayRender;
964  uint64 myStandaloneFlag;
965  int myStereoMode;
966  GR_DecorationOverride myDecorationOverride;
967  UT_StringHolder myDisplayedUVAttrib;
968 
969  mutable RE_OGLFramebuffer *myDepthResolveFBO;
970  mutable unsigned int myDepthResolveShaderFailed : 1,
971  myZCompositeShaderFailed : 1;
972 
973  DM_FloorInterface *myFloorInterface;
974  UT_IntArray mySetupLookShowSelection;
975  bool myHasSelectionsShown;
976  bool myDrawFloorTransientFlag;
977  int myDecorLocateMask;
978  int myDecorVisibleMask;
979  int myGammaPass;
980 
981  RE_GPUTimer myBGTimer;
982  RE_GPUTimer myFGTimer;
983  RE_GPUTimer myGeoCleanupTimer;
984  RE_GPUTimer myUnlitTimer;
985 
986  DM_ViewportType myType;
987  int myRenderCount;
988  RE_OGLContext myInitContext;
989 
990  UT_Array<GUI_DetailLookPtr> mySetupLooks;
991  UT_Array<OBJ_Node *> mySetupObjects;
992  UT_Array<GUI_DetailLook *> myUnlitLooks;
993  UT_Array<GUI_DetailLook *> myXRayLooks;
994  UT_Array<GUI_DetailLook *> myOnionSkinLooks;
995  UT_Array<GUI_DetailLook *> myTransparentLooks;
996  UT_Array<OBJ_Node *> myTransparentObjects;
997 
998  bool mySavedAntiAliasOption;
999  UI_XPtr<GUI_SceneLook> mySceneLook;
1000  DM_SceneManager &mySceneManager;
1001  DM_Viewport *myDisplay;
1002  bool mySetupFlag;
1003 
1004  // Buffers for picking geometry.
1005  UT_UniquePtr<dm_PickBuffer> myPickBuffer;
1006  UT_TokenString *myPickBufferTestHash;
1007 
1008  // Extra data for box picking.
1009  RE_ShaderHandle myBoxPickObjectShader;
1010  RE_Geometry *myBoxPickObjectGeometry;
1011  RE_Texture *myBoxPickMaskTexture;
1012 
1013  // Buffers for snapping to components.
1014  UT_UniquePtr<dm_PickBuffer> mySnapHandleBuffer;
1015  UT_TokenString *mySnapHandleBufferTestHash;
1016 
1017  // General position/orientation snapping
1018  DM_SnapBuffer *mySnapBuffer;
1019  bool mySnapHasValidData;
1020 
1021  RE_LightList myGLLightList;
1022  UT_Array<RE_Light *> myNormalQualityLights;
1023 
1024  RE_OGLFramebuffer *myUnlitAlphaFBO;
1025  RE_Texture *myUnlitAlphaTexture;
1026  RE_Texture *myUnlitDepthTexture;
1027 
1028  static RE_ShaderHandle theBeautyCompShader;
1029  static RE_ShaderHandle theBeautyCompAAShader;
1030  static RE_ShaderHandle theBeautyCompHQAlpha8Shader;
1031  static RE_ShaderHandle theBeautyCompHQAlpha8AAShader;
1032  static RE_ShaderHandle theBeautyCompHQAlpha16Shader;
1033  static RE_ShaderHandle theBeautyCompHQAlpha16AAShader;
1034  static RE_ShaderHandle theDepthCompShader;
1035  static RE_ShaderHandle theDepthComp8Shader;
1036  static RE_ShaderHandle theDepthComp16Shader;
1037  static RE_ShaderHandle theAlphaFlatten8Shader;
1038  static RE_ShaderHandle theAlphaFlatten16Shader;
1039  static RE_ShaderHandle theUnlitAlphaShader;
1040  static RE_ShaderHandle theUnlitDepthShader;
1041  static RE_ShaderHandle theXRayShader;
1042 
1043  int myDecorLocateRawPos[2];
1044  int myDecorLocatePos[2];
1045  RE_ShaderHandle mySampleDepthShader;
1046 
1047  RE_OGLFramebuffer *myHQTransparentFBO;
1048  RE_Texture *myHQTransparentColorTex;
1049  RE_Texture *myHQTransparentStencil;
1050  bool myHQTransparentHDR;
1051 
1052  UT_UniquePtr<RE_Geometry> myCubeGeo;
1053 
1054  RE_OGLFramebuffer *myCoincidentBuffer;
1055  RE_Texture *myCoincidentTexture;
1056  RE_OGLFramebuffer *myOverlappingUVBuffer;
1057 
1058  bool myRampUnitPushed;
1059 
1060  RE_RenderWait *myBeautyPassSync;
1061 
1062  RE_GPUTimer myPreRenderTimer;
1063  RE_GPUTimer myPostRenderTimer;
1064  RE_GPUTimer myXRayTimer;
1065  RE_GPUTimer myOnionSkinTimer;
1066  RE_GPUTimer myCompositeTimer;
1067  RE_GPUTimer myBGEnvMapTimer;
1068  RE_GPUTimer myDecorTimer;
1069  RE_GPUTimer myHandleTimer;
1070 
1071  bool myUseHQLighting;
1072  bool myHasPerLookPickPriority;
1073 
1074  DM_ViewportHooks *myViewportHooks;
1075  UT_IntArray myViewportConfig;
1076  UI_Value myRedrawNotify;
1077  int myCurrentObjectID;
1078 };
1079 #endif
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
void requestDraw()
Request a deferred redraw.
int int32
Definition: SYS_Types.h:39
bool isGeoSetup() const
GR_DecorationOverride
Definition: GR_Defines.h:208
GLint left
Definition: glcorearb.h:2005
const DM_Viewport * getDisplay() const
GA_API const UT_StringHolder rot
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
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 y
Definition: glcorearb.h:103
const UT_Array< RE_Light * > & getAllLights() const
**But if you need a result
Definition: thread.h:613
const DM_FloorInterface * getFloorInterface() const
void close() override
unsigned long long uint64
Definition: SYS_Types.h:117
GR_AlphaPass
Definition: GR_Defines.h:117
Temporary container for either a RV_Render and an RE_Render.
DM_ViewportHooks & hooks() const
Interface to viewport hooks (render and mouse)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define DM_API
Definition: DM_API.h:10
DM_ViewportType getViewType() const
The projection type of this viewport.
Definition: DM_VPortAgent.h:98
unsigned char uint8
Definition: SYS_Types.h:36
void setLightingPass(GR_LightingPass p)
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLdouble n
Definition: glcorearb.h:2008
ImageBuf OIIO_API sub(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GR_ShadingPass
Definition: GR_Defines.h:126
GR_RenderMode
Definition: GR_Defines.h:47
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
GA_API const UT_StringHolder trans
GLint GLuint mask
Definition: glcorearb.h:124
GUI_RenderPassFlags
long long int64
Definition: SYS_Types.h:116
const DM_SceneManager & modeler() const
GUI_FogMode
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:36
GLint GLenum GLint x
Definition: glcorearb.h:409
bool needsToDrawFloor() const
GLdouble t
Definition: glad.h:2397
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
DM_SnapSelection
Definition: DM_Defines.h:208
DM_FloorInterface * getFloorInterface()
Contains transitional objects to provide some backward compatibility for code that references old GEO...
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GUI_RotoView
Viewport type for Rotoscope settings.
bool needsOverlayRender() const
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
DM_GeoSortMode
Definition: DM_Defines.h:150
GR_LightingPass
Definition: GR_Defines.h:135
GLint GLsizei width
Definition: glcorearb.h:103
Definition: core.h:982
GLuint texture
Definition: glcorearb.h:415
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define DM_VIEWPORT_PERSPECTIVE
GR_LightingPass getLightingPass() const
GLboolean r
Definition: glcorearb.h:1222
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:941
type
Definition: core.h:1059
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334
DM_Viewport * getDisplay()
int DM_ViewportType
UT_UniquePtr< TIL_Raster > RasterPtr
GA_API const UT_StringHolder area
Simple interface to building a shader from a .prog file.
GR_PickStyle
Definition: GR_Defines.h:240