All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UsdMayaGLBatchRenderer Class Reference

UsdMayaGLBatchRenderer is a singleton that shapes can use to get consistent batched drawing via Hydra in Maya, regardless of legacy viewport or Viewport 2.0 usage. More...

+ Inheritance diagram for UsdMayaGLBatchRenderer:

Public Member Functions

PXRUSDMAYAGL_API HdRenderIndexGetRenderIndex () const
 Get the render index owned by the batch renderer. More...
 
PXRUSDMAYAGL_API SdfPath GetDelegatePrefix (const bool isViewport2) const
 Get the delegate ID prefix for the specified viewport. More...
 
PXRUSDMAYAGL_API bool AddShapeAdapter (PxrMayaHdShapeAdapter *shapeAdapter)
 Add the given shape adapter for batched rendering and selection. More...
 
PXRUSDMAYAGL_API bool RemoveShapeAdapter (PxrMayaHdShapeAdapter *shapeAdapter)
 Remove the given shape adapter from batched rendering and selection. More...
 
PXRUSDMAYAGL_API bool PopulateCustomPrimFilter (const MDagPath &dagPath, PxrMayaHdPrimFilter &primFilter)
 Replaces the contents of the given primFilter with dagPath, if a shape adapter for dagPath has already been batched. More...
 
PXRUSDMAYAGL_API void Draw (const MDrawRequest &request, M3dView &view)
 Render batch or bounding box in the legacy viewport based on request. More...
 
PXRUSDMAYAGL_API void Draw (const MHWRender::MDrawContext &context, const MUserData *userData)
 Render batch or bounding box in Viewport 2.0 based on userData. More...
 
PXRUSDMAYAGL_API GfVec2i GetSelectionResolution () const
 Gets the resolution of the draw target used for computing selections. More...
 
PXRUSDMAYAGL_API void SetSelectionResolution (const GfVec2i &widthHeight)
 Sets the resolution of the draw target used for computing selections. More...
 
PXRUSDMAYAGL_API bool IsDepthSelectionEnabled () const
 Gets whether depth selection has been enabled. More...
 
PXRUSDMAYAGL_API void SetDepthSelectionEnabled (const bool enabled)
 Sets whether to enable depth selection. More...
 
PXRUSDMAYAGL_API const
HdxPickHitVector * 
TestIntersection (const PxrMayaHdShapeAdapter *shapeAdapter, MSelectInfo &selectInfo)
 Tests the object from the given shape adapter for intersection with a given selection context in the legacy viewport. More...
 
PXRUSDMAYAGL_API const
HdxPickHitVector * 
TestIntersection (const PxrMayaHdShapeAdapter *shapeAdapter, const MHWRender::MSelectionInfo &selectionInfo, const MHWRender::MDrawContext &context)
 Tests the object from the given shape adapter for intersection with a given draw context in Viewport 2.0. More...
 
PXRUSDMAYAGL_API bool TestIntersectionCustomPrimFilter (const PxrMayaHdPrimFilter &primFilter, const GfMatrix4d &viewMatrix, const GfMatrix4d &projectionMatrix, HdxPickHitVector *outResult)
 Tests the contents of the given prim filter (previously obtained via PopulateCustomFilter) for intersection with the current OpenGL context. More...
 
PXRUSDMAYAGL_API int GetInstancerIndexForHit (const HdxPickHit &hit) const
 Returns the index within the point instancer for hit. More...
 
PXRUSDMAYAGL_API bool GetObjectSoftSelectEnabled ()
 Returns whether soft selection for proxy shapes is currently enabled. More...
 
PXRUSDMAYAGL_API void StartBatchingFrameDiagnostics ()
 Starts batching all diagnostics until the end of the current frame draw. More...
 
- Public Member Functions inherited from TfWeakBase
 TfWeakBase (const TfWeakBase &)
 
const TfWeakBase__GetTfWeakBase__ () const
 
const TfWeakBaseoperator= (const TfWeakBase &)
 
void EnableNotification2 () const
 
TF_API void const * GetUniqueIdentifier () const
 

Static Public Member Functions

static PXRUSDMAYAGL_API void Init ()
 Initialize the batch renderer. More...
 
static PXRUSDMAYAGL_API
UsdMayaGLBatchRenderer
GetInstance ()
 Get the singleton instance of the batch renderer. More...
 
static PXRUSDMAYAGL_API void Reset ()
 Reset the internal state of the global UsdMayaGLBatchRenderer. More...
 
static PXRUSDMAYAGL_API const
HdxPickHit
GetNearestHit (const HdxPickHitVector *hitSet)
 Utility function for finding the nearest hit (in terms of ndcDepth) in the given hitSet. More...
 
- Static Public Member Functions inherited from TfSingleton< UsdMayaGLBatchRenderer >
static UsdMayaGLBatchRendererGetInstance ()
 Return a reference to an object of type T, creating it if necessary. More...
 
static bool CurrentlyExists ()
 Return whether or not the single object of type T is currently in existence. More...
 
static void SetInstanceConstructed (UsdMayaGLBatchRenderer &instance)
 Indicate that the sole instance object has already been created. More...
 
static void DeleteInstance ()
 Destroy the sole instance object of type T, if it exists. More...
 

Friends

class TfSingleton< UsdMayaGLBatchRenderer >
 

Additional Inherited Members

- Protected Member Functions inherited from TfWeakBase
TfRefPtr< Tf_Remnant > _Register () const
 
template<class T >
TfRefPtr< Tf_Remnant > _Register (T *tempRmnt) const
 
bool _HasRemnant () const
 

Detailed Description

UsdMayaGLBatchRenderer is a singleton that shapes can use to get consistent batched drawing via Hydra in Maya, regardless of legacy viewport or Viewport 2.0 usage.

Typical usage is as follows:

Objects that manage drawing and selection of Maya shapes (e.g. classes derived from MPxSurfaceShapeUI or MPxDrawOverride) should construct and maintain a PxrMayaHdShapeAdapter. Those objects should call AddShapeAdapter() to add their shape for batched drawing and selection.

In preparation for drawing, the shape adapter should be synchronized to populate it with data from its shape and from the viewport display state. A user data object should also be created/obtained for the shape by calling the shape adapter's GetMayaUserData() method.

In the draw stage, Draw() must be called for each draw request to complete the render.

Draw/selection management objects should be sure to call RemoveShapeAdapter() (usually in the destructor) when they no longer wish for their shape to participate in batched drawing and selection.

Definition at line 95 of file batchRenderer.h.

Member Function Documentation

PXRUSDMAYAGL_API bool AddShapeAdapter ( PxrMayaHdShapeAdapter shapeAdapter)

Add the given shape adapter for batched rendering and selection.

Returns true if the shape adapter had not been previously added, or false otherwise.

PXRUSDMAYAGL_API void Draw ( const MDrawRequest &  request,
M3dView &  view 
)

Render batch or bounding box in the legacy viewport based on request.

PXRUSDMAYAGL_API void Draw ( const MHWRender::MDrawContext &  context,
const MUserData *  userData 
)

Render batch or bounding box in Viewport 2.0 based on userData.

PXRUSDMAYAGL_API SdfPath GetDelegatePrefix ( const bool  isViewport2) const

Get the delegate ID prefix for the specified viewport.

The batch renderer has a root SdfPath under which it maintains separate hierarchies for shape adapter delegates based on whether they are for the legacy viewport or for Viewport 2.0. Shape adapters should use this method to request the appropriate prefix from the batch renderer when building the ID for their delegate.

static PXRUSDMAYAGL_API UsdMayaGLBatchRenderer& GetInstance ( )
static

Get the singleton instance of the batch renderer.

PXRUSDMAYAGL_API int GetInstancerIndexForHit ( const HdxPickHit hit) const

Returns the index within the point instancer for hit.

Returns -1 if unable to get the instanceIndex.

static PXRUSDMAYAGL_API const HdxPickHit* GetNearestHit ( const HdxPickHitVector *  hitSet)
static

Utility function for finding the nearest hit (in terms of ndcDepth) in the given hitSet.

If hitSet is nullptr or is empty, nullptr is returned. Otherwise a pointer to the nearest hit in hitSet is returned.

PXRUSDMAYAGL_API bool GetObjectSoftSelectEnabled ( )
inline

Returns whether soft selection for proxy shapes is currently enabled.

Definition at line 265 of file batchRenderer.h.

PXRUSDMAYAGL_API HdRenderIndex* GetRenderIndex ( ) const

Get the render index owned by the batch renderer.

Clients of the batch renderer should use this render index to construct their delegates.

PXRUSDMAYAGL_API GfVec2i GetSelectionResolution ( ) const

Gets the resolution of the draw target used for computing selections.

The resolution is specified as (width, height).

static PXRUSDMAYAGL_API void Init ( )
static

Initialize the batch renderer.

This should be called at least once and it is OK to call it multiple times. This handles things like initializing OpenGL/Glew.

PXRUSDMAYAGL_API bool IsDepthSelectionEnabled ( ) const

Gets whether depth selection has been enabled.

PXRUSDMAYAGL_API bool PopulateCustomPrimFilter ( const MDagPath &  dagPath,
PxrMayaHdPrimFilter &  primFilter 
)

Replaces the contents of the given primFilter with dagPath, if a shape adapter for dagPath has already been batched.

Returns true if successful. Otherwise, does not modify the primFilter, and returns false.

The primFilter is used by Hydra to determine which prims should be present in the render path. It consists of a collection (which prim paths to include/exclude) and Render Tags (which prim purposes to include).

Note that the VP2 shape adapters are searched first, followed by the Legacy shape adapters. You cannot rely on the shape adapters being associated with a specific viewport.

PXRUSDMAYAGL_API bool RemoveShapeAdapter ( PxrMayaHdShapeAdapter shapeAdapter)

Remove the given shape adapter from batched rendering and selection.

Returns true if the shape adapter was removed from internal caches, or false otherwise.

static PXRUSDMAYAGL_API void Reset ( )
static

Reset the internal state of the global UsdMayaGLBatchRenderer.

In particular, it's important that this happen when switching to a new Maya scene so that any UsdImagingDelegates held by shape adapters that have been populated with USD stages can have those stages released, since the delegates hold a strong pointer to their stages.

PXRUSDMAYAGL_API void SetDepthSelectionEnabled ( const bool  enabled)

Sets whether to enable depth selection.

PXRUSDMAYAGL_API void SetSelectionResolution ( const GfVec2i widthHeight)

Sets the resolution of the draw target used for computing selections.

The resolution should be specified as (width, height).

Smaller values yield better performance but may miss selecting very small objects. Larger values will be slower but more accurate. The default resolution is (256, 256) for performance.

PXRUSDMAYAGL_API void StartBatchingFrameDiagnostics ( )

Starts batching all diagnostics until the end of the current frame draw.

The batch renderer will automatically release the diagnostics when Maya is done rendering the frame.

PXRUSDMAYAGL_API const HdxPickHitVector* TestIntersection ( const PxrMayaHdShapeAdapter shapeAdapter,
MSelectInfo &  selectInfo 
)

Tests the object from the given shape adapter for intersection with a given selection context in the legacy viewport.

Returns a pointer to a hit set if there was an intersection, or nullptr otherwise.

The returned HitSet is owned by the batch renderer, and it will be erased at the next selection, so clients should make copies if they need the data to persist.

PXRUSDMAYAGL_API const HdxPickHitVector* TestIntersection ( const PxrMayaHdShapeAdapter shapeAdapter,
const MHWRender::MSelectionInfo &  selectionInfo,
const MHWRender::MDrawContext &  context 
)

Tests the object from the given shape adapter for intersection with a given draw context in Viewport 2.0.

Returns a pointer to a hit set if there was an intersection, or nullptr otherwise.

The returned HitSet is owned by the batch renderer, and it will be erased at the next selection, so clients should make copies if they need the data to persist.

PXRUSDMAYAGL_API bool TestIntersectionCustomPrimFilter ( const PxrMayaHdPrimFilter &  primFilter,
const GfMatrix4d viewMatrix,
const GfMatrix4d projectionMatrix,
HdxPickHitVector *  outResult 
)

Tests the contents of the given prim filter (previously obtained via PopulateCustomFilter) for intersection with the current OpenGL context.

The caller is responsible for ensuring that an appropriate OpenGL context is available; this function is not appropriate for interesecting using the Maya viewport.

If hit(s) are found, returns true and populates *outResult with the intersection result.


The documentation for this class was generated from the following file: