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_RenderContext r);
188  void cleanupGeometry(RE_RenderContext r);
189  void fastSetupGeometry(RE_RenderContext 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  bool handle_pick_radius);
227  /// Box, lasso or paint select components.
228  /// @param contained only return results completely inside area
229  /// @param interactive if true, only return "visible" results, ignoring
230  /// primitives which rasterize to less than a single pixel.
231  int boxPickComponent(RE_Render *r,
232  const UT_DimRect &area,
233  uint8 *texture,
234  UT_Array<GR_PickRecord> &pick_records,
235  bool sort_records,
236  unsigned pickmask,
238  bool visible_only,
239  bool contained,
240  bool interactive,
241  const GUI_DetailList *geos);
242 
243  // Return the raw pick buffer textures that are used for visible
244  // component picking. These buffer may be used for picking or
245  // rendering purposes.
246  bool getComponentPickBuffers(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,
362 
363  /// Our floor or construction plane.
364  void renderFloor(RE_RenderContext r, int x, int y);
365  /// Render construction plane in overlayRender.
366  void overlayRenderFloor(RE_Render *r, int x, int y);
367  /// Check if the floor still needs to be rendered and then clear it.
369  {
370  bool floor = myDrawFloorTransientFlag;
371  myDrawFloorTransientFlag = false;
372  return floor;
373  }
374 
375  const DM_FloorInterface *getFloorInterface() const
376  { return myFloorInterface; }
377  DM_FloorInterface *getFloorInterface() { return myFloorInterface; }
378 
379  /// Interface to viewport hooks (render and mouse)
380  DM_ViewportHooks &hooks() const { return *myViewportHooks; }
381 
382  bool needsOverlayRender() const
383  { return myNeedsOverlayRender; }
384 
385  /// Methods to process mouse movement
386  /// @{
387  bool hasLocates();
388  void handleLocateEvent(UI_Event *e);
389  /// @}
390 
391  /// @brief Access displayed objects in the viewport
392  /// Return a handle to an object displayed in the viewport. Do not cache
393  /// these over several redraws, as they may become invalid. get*Object()'s
394  /// index parameter can be 0 to getNum*Objects()-1.
395  /// @{
396  int getNumOpaqueObjects() const;
397  DM_GeoDetail getOpaqueObject(int index) const;
398 
399  int getNumTransparentObjects() const;
400  DM_GeoDetail getTransparentObject(int index) const;
401 
402  int getNumUnlitObjects() const;
403  DM_GeoDetail getUnlitObject(int index) const;
404 
405  int getNumXRayObjects() const;
406  DM_GeoDetail getXRayObject(int index) const;
407  /// @}
408 
409  /// Returns the current detail within the object, when at SOP/POP/DOP level.
410  DM_GeoDetail getCurrentDetail() const;
411 
412  void initGPUTimers(RE_Render *r);
413  void collectGPUTimers(RE_Render *r);
414 
415  GUI_RotoView getRotoViewType();
416 
417  void markGeoSetup(bool setup,
418  DM_Viewport *setup_port = NULL);
419  bool isGeoSetup() const { return mySetupFlag; }
420 
421  // All lights in the scene, for the material render codepath.
422  void setGlobalLightArray(const UT_Array<OBJ_Ambient *> &l);
423  void setGlobalLightArray(const UT_ValArray<RE_Light*> &l);
424 
425  // Get and set lighting information.
426  bool setupLights(RE_RenderContext r, GUI_DisplayOption *opt);
427  void cleanupLights();
428 
430  { return myMaterialLights; }
431 
432  GR_LightingPass getLightingPass() const { return myLightingPass; }
433  void setLightingPass(GR_LightingPass p) { myLightingPass=p;}
434 
435  // Returns the approximate memory usage of the viewport at the current size
436  // given hdr on/off, high quality lighting on/off, transparency > low,
437  // and aa at 1,2,4 or 8x.
438  int64 getFramebufferUsageKB(bool hdr, bool hql, bool trans,
439  int aa);
440 
441  // using zt[0] / (Z + zt[1]) will transform zbuffer values into viewspace Z
442  // If light is specified, then the shadowmap range of that light is computed
443  void getZBufferTransform(float zt[2],RE_Light *light=NULL);
444 
445  // Handle a change in which geometry is displayed.
446  // For keeping track of what type of UVs to show in UV mode.
447  void handleNewGeometryEvent(UI_Event *e);
448  void updateAttributeOptions(const GU_DetailHandle &gdh);
449 
450  // ---------------------------------------------------------------------
451  // the following methods should be treated as private to DM.
452 
453  /// Methods for starting and stopping events
454  /// in the old performance monitor.
455  void startPerfMonTimer(RE_RenderContext r,
456  RE_GPUTimer &timer,
457  const char *msg) const;
458  void stopPerfMonTimer(RE_RenderContext r,
459  RE_GPUTimer &timer) const;
460 
461  // setup proper winding and culling, returning a set of flags to use for
462  // the cleanup method.
463  int setupBackfaceAndWinding(RE_Render *r,
464  const GUI_DisplayOption *opts);
465  void cleanupBackfaceAndWinding(RE_Render *r,
466  int setup_flags);
467 
468  // resolve the AA Z buffer to a single sample, taking the further sample
469  bool resolveDepthBuffer(RE_Render *r,
470  RE_Texture *aa_depth_tex,
471  RE_Texture *depth_tex) const;
472 
473  int64 getSceneVersion(fpreal t, bool shadow, bool &timedep);
474 
475  // access to parent viewport
476  const DM_Viewport *getDisplay() const { return myDisplay; }
477  DM_Viewport *getDisplay() { return myDisplay; }
478 
479  // for transparency
480  int getTransparencyLayers(RE_RenderContext r,
481  const GUI_DisplayOption *disp);
482  void prepareStencilRouting(RE_RenderContext r,int nsamples);
483  void prepareABufferFront(RE_RenderContext r, int nsamples);
484 
485  void updateTimeDependentLook(fpreal t);
486 
487  bool isToolbarLinked() const; // see .C file note
488 
489  const GUI_DetailPtrList &getDetails() const;
490  const GUI_DetailPtrList &getDetails();
491 
492  void setupViewUniforms(RE_RenderContext rc);
493  void cleanupViewUniforms(RE_RenderContext rc);
494  void setupViewUniformsGL(RE_Render *r);
495  void cleanupViewUniformsGL(RE_Render *r);
496 
497  // Looks through the lights for an environment map
498  void applyEnvMapOverride(RE_Render *r) const;
499 
500  // Helper methods to determine if a GUI_DetailLook, or OBJ_Node, should be
501  // hidden as a view cam object when hiding view cam geometry.
502  static bool shouldHideAsViewCamObject(const DM_Viewport &vport,
503  const GUI_DetailLook &look);
504  static bool shouldHideAsViewCamObject(const DM_Viewport &vport,
505  const OBJ_Node &node);
506 
507  // For DM_RenderHighQuality.
508  bool needsToDrawFloor() const
509  { return myDrawFloorTransientFlag; }
510  void initFogVolume(RE_Render *r,
511  DM_Viewport *vport,
512  GUI_FogMode fog,
513  const RE_Texture *zdepth) const;
514  RE_Texture *getFogVolumeTexture() const;
515  RE_Texture *getRandomDitherTexture(RE_Render *r);
516 
517  const DM_SceneManager &modeler() const
518  { return mySceneManager; }
519 
520  void renderBackgroundImage(RE_RenderContext r);
521  void renderForegroundImage(RE_RenderContext r);
522 
523  void resolveBeautyColorPass(RE_Render *r,
524  RE_Texture *aa_color,
525  RE_Texture *aa_depth,
526  RE_Texture *aa_nml,
527  bool xray) const;
528 
529  // If true, render to VK images rather than GL-interop VK images.
530  void renderToVulkanImages();
531 
532  void renderVulkan(RE_RenderContext r, UT_Vector2i res);
533 
534  // These only work for Vulkan images (if the above is set to true).
535  UT_UniquePtr<PXL_Raster> extractColorImage(RE_RenderContext r);
536  UT_UniquePtr<PXL_Raster> extractDepthImage(RE_RenderContext r);
537 
538 protected:
539  friend class dm_SetupTask;
540 
541 private:
542 
543  RE_RenderContext getVulkanContext(RE_Render *r, int thread_index=0) const;
544 
545  DM_SceneManager &modeler()
546  { return mySceneManager; }
547 
548  const GUI_SceneLook *getLook() const { return mySceneLook.get(); }
549  GUI_SceneLook *getLook() { return mySceneLook.get(); }
550 
551  bool shouldDisplayObject(const DM_Viewport &vport,
552  GUI_DetailLook *look,
553  OBJ_Node *node);
554 
555  bool shouldVisualizeObject(const DM_Viewport &vport,
556  GUI_DetailLook *look,
557  OBJ_Node *node);
558 
559  bool shouldShowComponentSelections(const GUI_DetailLook &look,
560  const GUI_DisplayOption &d) const;
561 
562  enum DM_BufferBlend
563  {
564  ACCUM_ADD,
565  ACCUM_REPLACE,
566  ACCUM_ALPHA_BLEND
567  };
568 
569  // prints a message in the viewer (centrally justified) on a given line
570  void renderMessage( RE_Render *ren, int x, int y,
571  const char* msg, int line );
572  // renders true viewer name
573  void doRenderCurrentName(RE_Render *r, int x, int y);
574  // renders the snapshot label
575  void doRenderSnapshotName(RE_Render *r, int x, int y);
576 
577  // prints a message in the viewer for camera (central, bottom justified)
578  void renderCameraMessage( RE_Render *ren, int x, int y,
579  const char* msg);
580 
581  // Render a mask over the parts of the viewport outside of the view
582  // subregion.
583  void renderViewMask(RE_Render *r, int x, int y);
584 
585  bool resizeBeautyPassBuffer(RE_RenderContext r,
586  int width, int height,
587  bool hdr, bool needs_aa);
588  void destroyBeautyPassBuffer();
589  RE_OGLFramebuffer *getBeautyPassBuffer(bool allow_aa);
590 
591  // initializes the view and projection to a 1:1 pixel transform.
592  void pushIdentityOrthoView(RE_Render *r);
593  void popIdentityOrthoView(RE_Render *r);
594 
595  // Render the viewport name.
596  void doRenderName(RE_Render *r, int x, int y,
597  bool snapshot_name = false);
598  // Render the current state information.
599  void doRenderStateStatus(RE_Render *r);
600  // Render a mask over the parts of the viewport outside of the view
601  // subregion.
602  void doRenderViewMask(RE_Render *r, int x, int y);
603 
604  // Draw the view overview gadget.
605  void doRenderViewOverview(RE_Render *r, int x, int y);
606 
607  // Common utility methods to setup lights and the z buffer.
608  void setupForRender(RE_RenderContext ren,
609  bool allow_smooth = true);
610  void cleanupAfterRender(RE_RenderContext ren);
611 
612 
613  void setGammaPass(bool b) { myGammaPass = b?1:0; }
614 
615  void doRenderNoHookUnlitObjects(RE_RenderContext r,
616  int x, int y,
617  bool xray_pass);
618  void doRenderUnlitObjects(RE_RenderContext r, int x, int y);
619 
620  // Render the camera's mask (bars and anything else inside the mask)
621  void doRenderMask(RE_Render *r, int, int);
622 
623  // Render outlines
624  void doRenderOutlines(RE_RenderContext r);
625  // Render separate outlines for objects that have them
626  void doRenderSeparateOutline(RE_RenderContext r,
627  const UT_IntArray &indices);
628  void destroySelectionBuffer();
629 
630  void startBeautyPass(RE_RenderContext r,
631  bool allow_aa=true);
632  void endBeautyPass(RE_RenderContext r, bool allow_aa=true);
633  bool isBeautyPassAA(bool allow_aa = true);
634 
635  // helper methods for setting up stereo passes
636  void setupStereo3d(RE_Render *r);
637  void setupStereoVR(RE_Render *r);
638  void cleanupStereo3d(RE_Render *r);
639  void interruptStereo(RE_Render *r);
640  void resumeStereo(RE_Render *r);
641  void setupStereo3dForLeftCamera(RE_Render *r,
642  bool uniforms_for_3d);
643  void setupStereo3dForRightCamera(RE_Render *r,
644  bool uniforms_for_3d);
645  void updateStereoViewUniforms(RE_Render *r, bool left);
646  void assignStereoLeft(RE_Render *r,
647  const GUI_ViewState::GUI_ViewType vt);
648  void assignStereoRight(RE_Render *r,
649  const GUI_ViewState::GUI_ViewType vt);
650  void assignStereoTop(RE_Render *r,
651  const GUI_ViewState::GUI_ViewType vt);
652  void assignStereoBottom(RE_Render *r,
653  const GUI_ViewState::GUI_ViewType vt);
654 
655  bool setupTransparentBuffers(RE_RenderContext r, int hdr);
656  void destroyTransparentBuffers();
657 
658  void renderViewport(RE_RenderContext r, int x, int y);
659  void renderSceneView(RE_RenderContext r, int x, int y);
660 
661  // Render the transparent bars defined by the camera's mask parameters
662  void renderCameraMask(RE_Render *r);
663 
664  // Render the object that goes on top of the camera mask
665  void renderCameraMaskOverlay(RE_Render *, int, int);
666 
667  void renderTransparentGeometry(
669  GUI_DisplayOption *dispopt);
670  bool renderHQTransparencyPass(
671  RE_RenderContext r, int x, int y,
672  GUI_DisplayOption *dispopt,
673  const UT_Array<GUI_DetailLook *> *geos = NULL,
674  bool for_xray = false);
675  bool setupHQTransparentBuffers(
676  RE_RenderContext r, int nsamples,
677  bool hdr);
678  void destroyHQTransparentBuffers();
679 
680  void initStencilABuffer(RE_RenderContext r, int nsamples);
681 
682  bool setupUnlitAlphaBuffer(RE_RenderContext r, bool zbuf);
683  void destroyUnlitAlphaBuffer();
684 
685  // Geometry pick code
686  bool createPickBuffer(RE_RenderContext r);
687  bool renderPickBuffer(RE_RenderContext r,
688  bool object_pick,
689  bool enable_occlusion,
690  unsigned int pickmask,
692  const GUI_DetailList *geos,
693  const GR_ObjectPickFlags &pick_flags);
694 
695  // Query the pick buffer. Returns true on a hit.
696  // allow_geo - allow geometry picks (either obj or component
697  // depending on geo_is_object)
698  // allow_handle - allow handle picks
699  // geo_is_object - geometry records are objects instead of
700  // components
701  // geo_ignore_depth - avoid scanning samples looking for a closer
702  // hit (only when !geo_is_object)
703  // geo_prioritize - scan samples looking for a higher priority
704  // component pick (only when !geo_is_object)
705  // floor_prioritize - scan samples looking for a higher priority
706  // floor component pick (only when allow_handle
707  // and does not differentiate between different
708  // floors)
709  // overlap_dist - the distance at which to consider picks to
710  // be essentially overlapping and employ some
711  // heuristics to pick the best one
712  bool pickFromBuffer(RE_RenderContext r,
713  RE_PickBuffer *pick_buffer,
714  int x, int y,
715  bool allow_geo,
716  bool allow_handle,
717  bool geo_is_object,
718  bool geo_ignore_depth,
719  bool geo_prioritize,
720  bool floor_prioritize,
721  int pick_dist,
722  int overlap_dist,
724  UT_Array<GR_PickRecord> *results,
725  UT_Vector2i *result_offset,
726  fpreal *depth,
727  const GUI_DetailList *geos);
728 
729  int filterPickData(int32 *pick_base_data,
730  int32 *pick_component_data,
731  int npicks,
732  UT_Array<GR_PickRecord> &pick_records);
733  int subtractPickData(const UT_Vector3iArray &base,
734  const UT_Vector3iArray &comp,
735  const UT_Array<GR_PickRecord> &outside,
736  UT_Array<GR_PickRecord> &results);
737  void objectPickRender(RE_RenderContext r,
738  unsigned int pickmask,
740  const GUI_DetailList *geos,
741  const GR_ObjectPickFlags &pick_flags);
742  void doObjectBoxPick(RE_RenderContext r,
743  const UT_DimRect &area,
744  UT_Array<GR_PickRecord> &pick_records,
745  bool visible_only,
746  bool invert_mask,
747  bool use_texture,
748  bool clip_edges,
749  const GUI_DetailList *geos);
750 
751  int componentPickRender(RE_RenderContext r,
752  unsigned int pickmask,
753  unsigned int xray_pickmask,
755  const GUI_DetailList *geos,
756  GR_PickStyle pickstyle,
757  bool invert_mask,
758  UT_Array<GR_PickRecord> *pick_rec);
759  int boxPickVisibleComponent(RE_RenderContext r,
760  const UT_DimRect &area,
761  uint8 *texture,
762  UT_Array<GR_PickRecord> &pick_records,
763  unsigned pickmask,
765  const GUI_DetailList *geos,
766  bool contained);
767  int boxPickFrustumComponent(RE_RenderContext r,
768  const UT_DimRect &area,
769  uint8 *texture,
770  UT_Array<GR_PickRecord> &pick_records,
771  unsigned pickmask,
773  const GUI_DetailList *geos,
774  bool visible_only,
775  bool contained);
776 
777 #ifdef USE_VULKAN
778  void doObjectBoxPickVK(RE_RenderContext r,
779  const UT_DimRect &area,
780  UT_Array<GR_PickRecord> &pick_records,
781  bool visible_only,
782  bool invert_mask,
783  bool use_texture,
784  bool clip_edges,
785  const GUI_DetailList *geos);
786 
787  void doPickBufferRenderVK(RE_RenderContext r,
788  bool object_pick,
789  bool enable_occlusion,
790  unsigned int pickmask,
792  const GUI_DetailList *geos,
793  const GR_ObjectPickFlags &pick_flags);
794 
795  void doSnapBufferRenderVK(RE_RenderContext r,
796  unsigned int snapmask,
797  unsigned int xray_snapmask,
799  const GUI_DetailList *geos,
800  bool hide_selected,
801  bool enable_occlusion,
802  bool do_current,
803  bool do_guides);
804 
805  void objectPickRenderVK(RE_RenderContext r,
806  unsigned int pickmask,
808  const GUI_DetailList *geos,
809  const GR_ObjectPickFlags &pick_flags);
810 
811  int componentPickRenderVK(RE_RenderContext r,
812  unsigned int pickmask,
813  unsigned int xray_pickmask,
815  const GUI_DetailList *geos,
816  GR_PickStyle pickstyle,
817  bool invert_mask,
818  bool has_pick_map,
819  UT_Array<GR_PickRecord> *pick_rec);
820 
821  int boxPickFrustumComponentVK(RE_RenderContext r,
822  const UT_DimRect &area,
823  uint8 *texture,
824  UT_Array<GR_PickRecord> &pick_records,
825  unsigned pickmask,
827  const GUI_DetailList *geos,
828  bool visible_only,
829  bool contained);
830 
831  void renderOffsetDepthPassVK(RE_RenderContext r,
832  bool skip_obj_sel_looks,
833  bool skip_guide_looks,
834  bool skip_nonsnappable_looks,
835  bool skip_current_look);
836 
837 #endif
838  void renderOffsetDepthPass(RE_RenderContext r,
839  bool skip_obj_sel_looks = false,
840  bool skip_guide_looks = false,
841  bool skip_nonsnappable_looks = false,
842  bool skip_current_look = false);
843  void flattenAlphaPass(RE_RenderContext r,
844  const GUI_DisplayOption *dispopt,
845  int num_layers);
846  // end pick code
847 
848  // Snapping and handle pick code
849  bool createSnapHandleBuffer(RE_RenderContext r);
850  bool renderHandleBuffer(RE_RenderContext r);
851  bool renderSnapBuffer(RE_RenderContext r,
852  unsigned int snapmask,
854  const GUI_DetailList *geos,
855  bool hide_selected,
856  bool enable_occlusion,
857  bool do_current,
858  bool do_xray, bool do_guides,
859  bool extend_floor);
860  // end snapping and handle pick code
861 
862  bool sampleDepth(RE_Render *r, int x, int y, fpreal &z,
863  RE_Texture *depth_texture);
864 
865  void renderXray(RE_RenderContext r,
866  GUI_DisplayOption *dispopts);
867  void resolveXrayBeautyPass(RE_RenderContext r) const;
868  void renderOnionSkin(RE_RenderContext r,
869  GUI_DisplayOption *dispopts);
870 
871  bool renderBeautyPass(RE_RenderContext r, int x, int y,
872  GUI_DisplayOption *dispopt,
873  bool &needs_lighting);
874  bool renderTransparencyPass(RE_RenderContext r,
875  int x, int y,
876  GUI_DisplayOption *dispopt);
877  bool renderEnvironmentMaps(RE_RenderContext r,
878  bool query_only);
879  void renderEnvMap(RE_RenderContext r,
880  RE_OGLTexture *cubemap,
881  int cubemap_unit) const;
882  void compositePasses(RE_RenderContext r,
883  const GUI_DisplayOption *dispopt,
884  bool has_trans_pass,
885  bool has_alpha_buffers);
886 
887  void normalQualityRender(
889  GUI_DisplayOption *dispopt,
890  GR_AlphaPass alpha_pass,
892  const UT_Array<GUI_DetailLook*> *geos=NULL);
893 
894  bool isUsingHQLighting(RE_RenderContext r,
895  const GUI_DisplayOption *dispopt);
896 
897  void renderOverlappingUV(RE_RenderContext r,
898  GUI_DisplayOption *disp);
899  bool setupOverlappingUVBuffer(RE_RenderContext r,
900  int w, int h);
901  void destroyOverlappingUVBuffer();
902 
903  void renderCoincidentPoints(RE_Render *r,
904  GUI_DisplayOption *disp);
905  bool setupCoincidentBuffer(RE_Render *r, int w, int h);
906  void destroyCoincidentBuffer();
907 
908  void subtractFromSelection(UT_Array<GR_PickRecord> &results,
910  exint start_subtracting_at,
912 #ifdef MBSD_COCOA
913  void dmOSXDepthBufferWorkaround(RE_Render *r,
914  RE_Texture *tex);
915 #endif
916  void updateVisibleBoundariesAndViews(int vis_display_sets);
917 
918  void redrawNeeded(UI_Event *);
919 
920  mutable RE_ShaderHandle *myDepthResolveShader;
921 
922  UT_Array<RE_Light *> myMaterialLights;
923 
924  RE_OGLFramebuffer *myBeautyPassBuffer;
925  RE_OGLFramebuffer *myBeautyPassAABuffer;
926  RE_Texture *myBeautyColorTexture;
927  RE_Texture *myBeautyDepthTexture;
928  RE_Texture *myBeautyPassAACTexture;
929  RE_Texture *myBeautyPassAAZTexture;
930  int myBeautyPassSamples;
931  bool myBeautyPassHDR;
932 
933  RE_OGLFramebuffer *myTransparentFBO;
934  RE_Texture *myTransparentColorTex;
935  RE_Texture *myTransparentZTex;
936  bool myTransparentHDR;
937 
938  RE_OGLFramebuffer *mySelectionIDFBO;
939  RE_Texture *mySelectionIDTex;
940  RE_Texture *mySelectionZTex;
941 
942  UT_UniquePtr<RE_Texture> myOutlineColorsTex;
943  UT_Vector4FArray myOutlineColorsArray;
944 
945  UT_UniquePtr<RE_OGLFramebuffer> myOutlineBitmaskFBO;
946  UT_UniquePtr<RE_Texture> myOutlineBitmaskTex;
947 
948 #ifdef USE_VULKAN // WIP: make private, and make heleper func
949  // so access in DM_Viewport insn't needed
950 public:
952 
953 private:
954  // extra data for box picking
955  UT_UniquePtr<RV_Geometry> myBoxPickObjectGeometryVK;
956  UT_UniquePtr<RV_VKImage> myBoxPickMaskTextureVK;
957 
958  UT_UniquePtr<RV_ShaderVariableSet> myBoxPickSetVK;
959  UT_UniquePtr<RV_Framebuffer> myBoxPickFramebufferVK;
960  UT_UniquePtr<RV_VKImage> myImageFallbackVK;
961  UT_UniquePtr<RV_VKImage> myBoxPickDepthVK;
962 #endif
963  DM_RenderHighQuality *myHQRender;
964  DM_PostEffects *myPostEffects;
965 
966  RE_Texture *myRandomDitherTexture;
967  RE_TextureMap *myRandomDitherTextureMap;
968 
969  PXL_Lookup myLookup;
970  UT_String myLUTFile;
971  UT_String myOCIODisplay;
972  exint myOCIOSerial;
973 
974  bool myIsBeautyPass;
975  GR_LightingPass myLightingPass;
976  bool myIsAlphaPass;
977  bool myUseUnlitMask;
978  bool myHighQualityMode;
979  bool myNeedsXRayResolve;
980  bool myHasGILight;
981  bool myHasEnvLight;
982  bool myHasCascadingShadowLight;
983  bool myNeedsOverlayRender;
984  uint64 myStandaloneFlag;
985  int myStereoMode;
986  GR_DecorationOverride myDecorationOverride;
987  UT_StringHolder myDisplayedUVAttrib;
988 
989  mutable RE_OGLFramebuffer *myDepthResolveFBO;
990  mutable unsigned int myDepthResolveShaderFailed : 1,
991  myZCompositeShaderFailed : 1;
992 
993  DM_FloorInterface *myFloorInterface;
994  UT_IntArray mySetupLookShowSelection;
995  bool myHasSelectionsShown;
996  bool myDrawFloorTransientFlag;
997  int myDecorLocateMask;
998  int myDecorVisibleMask;
999  int myGammaPass;
1000 
1001  RE_GPUTimer myBGTimer;
1002  RE_GPUTimer myFGTimer;
1003  RE_GPUTimer myGeoCleanupTimer;
1004  RE_GPUTimer myUnlitTimer;
1005 
1006  DM_ViewportType myType;
1007  int myRenderCount;
1008  RE_OGLContext myInitContext;
1009 
1010  UT_Array<GUI_DetailLookPtr> mySetupLooks;
1011  UT_Array<OBJ_Node *> mySetupObjects;
1012  UT_Array<GUI_DetailLook *> myUnlitLooks;
1013  UT_Array<GUI_DetailLook *> myXRayLooks;
1014  UT_Array<GUI_DetailLook *> myOnionSkinLooks;
1015  UT_Array<GUI_DetailLook *> myTransparentLooks;
1016  UT_Array<OBJ_Node *> myTransparentObjects;
1017 
1018  bool mySavedAntiAliasOption;
1019  UI_XPtr<GUI_SceneLook> mySceneLook;
1020  DM_SceneManager &mySceneManager;
1021  DM_Viewport *myDisplay;
1022  bool mySetupFlag;
1023 
1024  // Buffers for picking geometry.
1025  UT_UniquePtr<dm_PickBuffer> myPickBuffer;
1026  UT_TokenString *myPickBufferTestHash;
1027 
1028  // Extra data for box picking.
1029  RE_ShaderHandle myBoxPickObjectShader;
1030  RE_Geometry *myBoxPickObjectGeometry;
1031  RE_Texture *myBoxPickMaskTexture;
1032 
1033  // Buffers for snapping to components.
1034  UT_UniquePtr<dm_PickBuffer> mySnapHandleBuffer;
1035  UT_TokenString *mySnapHandleBufferTestHash;
1036 
1037  // General position/orientation snapping
1038  DM_SnapBuffer *mySnapBuffer;
1039  bool mySnapHasValidData;
1040 
1041  RE_LightList myGLLightList;
1042  UT_Array<RE_Light *> myNormalQualityLights;
1043 
1044  RE_OGLFramebuffer *myUnlitAlphaFBO;
1045  RE_Texture *myUnlitAlphaTexture;
1046  RE_Texture *myUnlitDepthTexture;
1047 
1048  static RE_ShaderHandle theBeautyCompShader;
1049  static RE_ShaderHandle theBeautyCompAAShader;
1050  static RE_ShaderHandle theBeautyCompHQAlpha8Shader;
1051  static RE_ShaderHandle theBeautyCompHQAlpha8AAShader;
1052  static RE_ShaderHandle theBeautyCompHQAlpha16Shader;
1053  static RE_ShaderHandle theBeautyCompHQAlpha16AAShader;
1054  static RE_ShaderHandle theDepthCompShader;
1055  static RE_ShaderHandle theDepthComp8Shader;
1056  static RE_ShaderHandle theDepthComp16Shader;
1057  static RE_ShaderHandle theAlphaFlatten8Shader;
1058  static RE_ShaderHandle theAlphaFlatten16Shader;
1059  static RE_ShaderHandle theUnlitAlphaShader;
1060  static RE_ShaderHandle theUnlitDepthShader;
1061  static RE_ShaderHandle theXRayShader;
1062 
1063  int myDecorLocateRawPos[2];
1064  int myDecorLocatePos[2];
1065  RE_ShaderHandle mySampleDepthShader;
1066 
1067  RE_OGLFramebuffer *myHQTransparentFBO;
1068  RE_Texture *myHQTransparentColorTex;
1069  RE_Texture *myHQTransparentStencil;
1070  bool myHQTransparentHDR;
1071 
1072  UT_UniquePtr<RE_Geometry> myCubeGeo;
1073 
1074  RE_OGLFramebuffer *myCoincidentBuffer;
1075  RE_Texture *myCoincidentTexture;
1076  RE_OGLFramebuffer *myOverlappingUVBuffer;
1077 
1078  bool myRampUnitPushed;
1079 
1080  RE_RenderWait *myBeautyPassSync;
1081 
1082  RE_GPUTimer myPreRenderTimer;
1083  RE_GPUTimer myPostRenderTimer;
1084  RE_GPUTimer myXRayTimer;
1085  RE_GPUTimer myOnionSkinTimer;
1086  RE_GPUTimer myCompositeTimer;
1087  RE_GPUTimer myBGEnvMapTimer;
1088  RE_GPUTimer myDecorTimer;
1089  RE_GPUTimer myHandleTimer;
1090 
1091  bool myUseHQLighting;
1092  bool myHasPerLookPickPriority;
1093 
1094  DM_ViewportHooks *myViewportHooks;
1095  UT_IntArray myViewportConfig;
1096  UI_Value myRedrawNotify;
1097  int myCurrentObjectID;
1098 };
1099 #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:219
IMATH_HOSTDEVICE constexpr int floor(T x) IMATH_NOEXCEPT
Definition: ImathFun.h:112
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:121
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:130
GR_RenderMode
Definition: GR_Defines.h:48
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
GA_API const UT_StringHolder trans
GR_ThreadingPass
Definition: GR_Defines.h:139
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:38
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
bool checkAndClearTransientFloorFlag()
Check if the floor still needs to be rendered and then clear it.
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:146
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:952
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:251