From cee50dd0463750606fbd532830604a480323d409 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 1 Oct 2020 12:13:16 -0700 Subject: [PATCH] always register and de-register the PxrMayaHdImagingShape and its draw override While the USD proxy shape classes included in the maya-usd repo all use either the (legacy) Pixar batch renderer *or* the Viewport 2.0 render delegate, there may be other custom node types that may or may not leverage USD but still want to take advantage of aggregated drawing using Hydra. This change decouples the registration and de-registration of the PxrMayaHdImagingShape and its draw override from whether the Viewport 2.0 render delegate is enabled for proxies and instead does it unconditionally. Shapes that use PxrMayaHdImagingShape must call its GetOrCreateInstance() in their postConstructor() override in order to get setup for drawing. --- lib/mayaUsd/nodes/proxyShapePlugin.cpp | 54 ++++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/lib/mayaUsd/nodes/proxyShapePlugin.cpp b/lib/mayaUsd/nodes/proxyShapePlugin.cpp index 98596ab9e9..b88875f51a 100644 --- a/lib/mayaUsd/nodes/proxyShapePlugin.cpp +++ b/lib/mayaUsd/nodes/proxyShapePlugin.cpp @@ -102,24 +102,28 @@ MayaUsdProxyShapePlugin::initialize(MFnPlugin& plugin) MayaUsdProxyShapeBase::displayFilterLabel, UsdMayaProxyDrawOverride::drawDbClassification); CHECK_MSTATUS(status); + } - // Hybrid Hydra / VP2 rendering uses the PxrMayaHdImagingShape for draw - // aggregation of all proxy shapes. - status = plugin.registerShape( - PxrMayaHdImagingShape::typeName, - PxrMayaHdImagingShape::typeId, - PxrMayaHdImagingShape::creator, - PxrMayaHdImagingShape::initialize, - PxrMayaHdImagingShapeUI::creator, - &PxrMayaHdImagingShapeDrawOverride::drawDbClassification); - CHECK_MSTATUS(status); + // We register the PxrMayaHdImagingShape regardless of whether the Viewport + // 2.0 render delegate is enabled for the USD proxy shape node types. There + // may be other non-proxy shape node types in use that still want to + // leverage Hydra and aggregated drawing. Those shapes should call + // PxrMayaHdImagingShape::GetOrCreateInstance() in their postConstructor() + // override to create a Hydra imaging shape for drawing. + status = plugin.registerShape( + PxrMayaHdImagingShape::typeName, + PxrMayaHdImagingShape::typeId, + PxrMayaHdImagingShape::creator, + PxrMayaHdImagingShape::initialize, + PxrMayaHdImagingShapeUI::creator, + &PxrMayaHdImagingShapeDrawOverride::drawDbClassification); + CHECK_MSTATUS(status); - status = MHWRender::MDrawRegistry::registerDrawOverrideCreator( - PxrMayaHdImagingShapeDrawOverride::drawDbClassification, - _RegistrantId, - PxrMayaHdImagingShapeDrawOverride::creator); - CHECK_MSTATUS(status); - } + status = MHWRender::MDrawRegistry::registerDrawOverrideCreator( + PxrMayaHdImagingShapeDrawOverride::drawDbClassification, + _RegistrantId, + PxrMayaHdImagingShapeDrawOverride::creator); + CHECK_MSTATUS(status); return status; } @@ -145,7 +149,15 @@ MayaUsdProxyShapePlugin::finalize(MFnPlugin& plugin) MStatus status = HdVP2ShaderFragments::deregisterFragments(); CHECK_MSTATUS(status); - + + status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator( + PxrMayaHdImagingShapeDrawOverride::drawDbClassification, + _RegistrantId); + CHECK_MSTATUS(status); + + status = plugin.deregisterNode(PxrMayaHdImagingShape::typeId); + CHECK_MSTATUS(status); + if (_useVP2RenderDelegate) { status = MHWRender::MDrawRegistry::deregisterSubSceneOverrideCreator( ProxyRenderDelegate::drawDbClassification, @@ -162,14 +174,6 @@ MayaUsdProxyShapePlugin::finalize(MFnPlugin& plugin) UsdMayaProxyDrawOverride::drawDbClassification, _RegistrantId); CHECK_MSTATUS(status); - - status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator( - PxrMayaHdImagingShapeDrawOverride::drawDbClassification, - _RegistrantId); - CHECK_MSTATUS(status); - - status = plugin.deregisterNode(PxrMayaHdImagingShape::typeId); - CHECK_MSTATUS(status); } status = plugin.deregisterNode(MayaUsdProxyShapeBase::typeId);