diff --git a/include/GafferScene/Capsule.h b/include/GafferScene/Capsule.h index 4856bfbc4e7..fefc6913345 100644 --- a/include/GafferScene/Capsule.h +++ b/include/GafferScene/Capsule.h @@ -112,6 +112,7 @@ class GAFFERSCENE_API Capsule : public IECoreScenePreview::Procedural const ScenePlug *m_scene; ScenePlug::ScenePath m_root; Gaffer::ConstContextPtr m_context; + std::optional m_renderOptions; }; diff --git a/include/GafferScene/RenderController.h b/include/GafferScene/RenderController.h index c257cb10088..dc8e1cad1bb 100644 --- a/include/GafferScene/RenderController.h +++ b/include/GafferScene/RenderController.h @@ -126,13 +126,6 @@ class GAFFERSCENE_API RenderController : public Gaffer::Signals::Trackable AllGlobalComponents = GlobalsGlobalComponent | SetsGlobalComponent | RenderSetsGlobalComponent | CameraOptionsGlobalComponent | TransformBlurGlobalComponent | DeformationBlurGlobalComponent | IncludedPurposesGlobalComponent }; - struct Unused - { - bool unused1; - bool unused2; - Imath::V2f unused3; - }; - void plugDirtied( const Gaffer::Plug *plug ); void contextChanged( const IECore::InternedString &name ); void requestUpdate(); @@ -166,8 +159,7 @@ class GAFFERSCENE_API RenderController : public Gaffer::Signals::Trackable std::vector > m_sceneGraphs; unsigned m_dirtyGlobalComponents; unsigned m_changedGlobalComponents; - std::unique_ptr m_renderOptions; - Unused m_unused; + Private::RendererAlgo::RenderOptions m_renderOptions; Private::RendererAlgo::RenderSets m_renderSets; std::unique_ptr m_lightLinks; IECoreScenePreview::Renderer::ObjectInterfacePtr m_defaultCamera; diff --git a/src/GafferScene/Capsule.cpp b/src/GafferScene/Capsule.cpp index 221dc405fe3..76764d02791 100644 --- a/src/GafferScene/Capsule.cpp +++ b/src/GafferScene/Capsule.cpp @@ -45,8 +45,6 @@ #include "boost/bind/bind.hpp" -#include - using namespace boost::placeholders; using namespace IECore; using namespace IECoreScene; @@ -55,7 +53,6 @@ using namespace GafferScene; namespace { - Gaffer::Context *capsuleContext( const Context &context ) { Gaffer::Context *result = new Gaffer::Context( context ); @@ -65,10 +62,6 @@ namespace result->remove( ScenePlug::scenePathContextName ); return result; } - -std::mutex g_renderOptionsMutex; -std::unordered_map g_renderOptions; - } IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( Capsule ); @@ -91,8 +84,6 @@ Capsule::Capsule( Capsule::~Capsule() { - std::unique_lock renderOptionsLock( g_renderOptionsMutex ); - g_renderOptions.erase( this ); } bool Capsule::isEqualTo( const IECore::Object *other ) const @@ -113,14 +104,14 @@ void Capsule::hash( IECore::MurmurHash &h ) const Procedural::hash( h ); h.append( m_hash ); - if( auto renderOptions = getRenderOptions() ) + if( m_renderOptions ) { // Hash only what affects our rendering, not everything in // `RenderOptions::globals`. - h.append( renderOptions->transformBlur ); - h.append( renderOptions->deformationBlur ); - h.append( renderOptions->shutter ); - renderOptions->includedPurposes->hash( h ); + h.append( m_renderOptions->transformBlur ); + h.append( m_renderOptions->deformationBlur ); + h.append( m_renderOptions->shutter ); + m_renderOptions->includedPurposes->hash( h ); } } @@ -166,7 +157,7 @@ void Capsule::render( IECoreScenePreview::Renderer *renderer ) const { throwIfNoScene(); ScenePlug::GlobalScope scope( m_context.get() ); - std::optional renderOptions = getRenderOptions(); + std::optional renderOptions = m_renderOptions; if( !renderOptions ) { renderOptions = GafferScene::Private::RendererAlgo::RenderOptions( m_scene ); @@ -198,19 +189,12 @@ void Capsule::setRenderOptions( const GafferScene::Private::RendererAlgo::Render // This is not pretty, but it allows the capsule to render with the correct // motion blur and `includedPurposes`, taken from the downstream node being // rendered rather than from the capsule's own globals. - std::unique_lock renderOptionsLock( g_renderOptionsMutex ); - g_renderOptions[this] = renderOptions; + m_renderOptions = renderOptions; } std::optional Capsule::getRenderOptions() const { - std::unique_lock renderOptionsLock( g_renderOptionsMutex ); - auto it = g_renderOptions.find( this ); - if( it != g_renderOptions.end() ) - { - return it->second; - } - return std::nullopt; + return m_renderOptions; } void Capsule::throwIfNoScene() const diff --git a/src/GafferScene/RenderController.cpp b/src/GafferScene/RenderController.cpp index 5150c2c7cbb..f5a32cba0bb 100644 --- a/src/GafferScene/RenderController.cpp +++ b/src/GafferScene/RenderController.cpp @@ -380,7 +380,7 @@ class RenderController::SceneGraph // Root - get attributes from globals. if( changedGlobals & GlobalsGlobalComponent ) { - if( updateAttributes( controller->m_renderOptions->globals.get() ) ) + if( updateAttributes( controller->m_renderOptions.globals.get() ) ) { m_changedComponents |= AttributesComponent; } @@ -401,7 +401,7 @@ class RenderController::SceneGraph // If attributes have changed, need to check if this has affected our motion sample times if( ( m_changedComponents & AttributesComponent ) || ( changedGlobals & TransformBlurGlobalComponent ) ) { - if( Private::RendererAlgo::transformMotionTimes( *controller->m_renderOptions, m_fullAttributes.get(), m_transformTimes ) ) + if( Private::RendererAlgo::transformMotionTimes( controller->m_renderOptions, m_fullAttributes.get(), m_transformTimes ) ) { m_dirtyComponents |= TransformComponent; } @@ -409,7 +409,7 @@ class RenderController::SceneGraph if( ( m_changedComponents & AttributesComponent ) || ( changedGlobals & DeformationBlurGlobalComponent ) ) { - if( Private::RendererAlgo::deformationMotionTimes( *controller->m_renderOptions, m_fullAttributes.get(), m_deformationTimes ) ) + if( Private::RendererAlgo::deformationMotionTimes( controller->m_renderOptions, m_fullAttributes.get(), m_deformationTimes ) ) { m_dirtyComponents |= ObjectComponent; } @@ -442,7 +442,7 @@ class RenderController::SceneGraph if( ( m_changedComponents & AttributesComponent ) || ( changedGlobals & IncludedPurposesGlobalComponent ) ) { const bool purposeIncludedPreviously = m_purposeIncluded; - m_purposeIncluded = controller->m_renderOptions->purposeIncluded( m_fullAttributes.get() ); + m_purposeIncluded = controller->m_renderOptions.purposeIncluded( m_fullAttributes.get() ); if( m_purposeIncluded != purposeIncludedPreviously ) { // We'll need to hide or show the object by considering `m_purposeIncluded` in @@ -487,7 +487,7 @@ class RenderController::SceneGraph m_objectHash = MurmurHash(); } - if( ( m_dirtyComponents & ObjectComponent ) && updateObject( controller->m_scene->objectPlug(), type, controller->m_renderer.get(), *controller->m_renderOptions, controller->m_scene.get(), controller->m_lightLinks.get() ) ) + if( ( m_dirtyComponents & ObjectComponent ) && updateObject( controller->m_scene->objectPlug(), type, controller->m_renderer.get(), controller->m_renderOptions, controller->m_scene.get(), controller->m_lightLinks.get() ) ) { m_changedComponents |= ObjectComponent; } @@ -511,7 +511,7 @@ class RenderController::SceneGraph { // Failed to apply attributes - must replace entire object. m_objectHash = MurmurHash(); - if( updateObject( controller->m_scene->objectPlug(), type, controller->m_renderer.get(), *controller->m_renderOptions, controller->m_scene.get(), controller->m_lightLinks.get() ) ) + if( updateObject( controller->m_scene->objectPlug(), type, controller->m_renderer.get(), controller->m_renderOptions, controller->m_scene.get(), controller->m_lightLinks.get() ) ) { m_changedComponents |= ObjectComponent; controller->m_failedAttributeEdits++; @@ -1347,8 +1347,7 @@ RenderController::RenderController( const ConstScenePlugPtr &scene, const Gaffer m_updateRequested( false ), m_failedAttributeEdits( 0 ), m_dirtyGlobalComponents( NoGlobalComponent ), - m_changedGlobalComponents( NoGlobalComponent ), - m_renderOptions( make_unique() ) + m_changedGlobalComponents( NoGlobalComponent ) { for( int i = SceneGraph::FirstType; i <= SceneGraph::LastType; ++i ) { @@ -1628,43 +1627,43 @@ void RenderController::updateInternal( const ProgressCallback &callback, const I if( m_dirtyGlobalComponents & GlobalsGlobalComponent ) { RenderOptions renderOptions( m_scene.get() ); - Private::RendererAlgo::outputOptions( renderOptions.globals.get(), m_renderOptions->globals.get(), m_renderer.get() ); - Private::RendererAlgo::outputOutputs( m_scene.get(), renderOptions.globals.get(), m_renderOptions->globals.get(), m_renderer.get() ); - if( *renderOptions.globals != *m_renderOptions->globals ) + Private::RendererAlgo::outputOptions( renderOptions.globals.get(), m_renderOptions.globals.get(), m_renderer.get() ); + Private::RendererAlgo::outputOutputs( m_scene.get(), renderOptions.globals.get(), m_renderOptions.globals.get(), m_renderer.get() ); + if( *renderOptions.globals != *m_renderOptions.globals ) { m_changedGlobalComponents |= GlobalsGlobalComponent; } - if( cameraGlobalsChanged( renderOptions.globals.get(), m_renderOptions->globals.get(), m_scene.get() ) ) + if( cameraGlobalsChanged( renderOptions.globals.get(), m_renderOptions.globals.get(), m_scene.get() ) ) { m_changedGlobalComponents |= CameraOptionsGlobalComponent; } - if( *renderOptions.includedPurposes != *m_renderOptions->includedPurposes ) + if( *renderOptions.includedPurposes != *m_renderOptions.includedPurposes ) { m_changedGlobalComponents |= IncludedPurposesGlobalComponent; } - if( renderOptions.shutter != m_renderOptions->shutter || renderOptions.transformBlur != m_renderOptions->transformBlur ) + if( renderOptions.shutter != m_renderOptions.shutter || renderOptions.transformBlur != m_renderOptions.transformBlur ) { m_changedGlobalComponents |= TransformBlurGlobalComponent; } - if( renderOptions.shutter != m_renderOptions->shutter || renderOptions.deformationBlur != m_renderOptions->deformationBlur ) + if( renderOptions.shutter != m_renderOptions.shutter || renderOptions.deformationBlur != m_renderOptions.deformationBlur ) { m_changedGlobalComponents |= DeformationBlurGlobalComponent; } - if( renderOptions.shutter != m_renderOptions->shutter ) + if( renderOptions.shutter != m_renderOptions.shutter ) { m_changedGlobalComponents |= CameraOptionsGlobalComponent; } - *m_renderOptions = renderOptions; + m_renderOptions = renderOptions; } if( ( m_dirtyGlobalComponents & CameraShutterGlobalComponent ) && !( m_dirtyGlobalComponents & GlobalsGlobalComponent ) ) { // Shutter override from a camera may have changed, and won't have been covered by // the block above (because the globals weren't dirty). - const V2f shutter = SceneAlgo::shutter( m_renderOptions->globals.get(), m_scene.get() ); - if( shutter != m_renderOptions->shutter ) + const V2f shutter = SceneAlgo::shutter( m_renderOptions.globals.get(), m_scene.get() ); + if( shutter != m_renderOptions.shutter ) { - m_renderOptions->shutter = shutter; + m_renderOptions.shutter = shutter; m_changedGlobalComponents |= ( DeformationBlurGlobalComponent | TransformBlurGlobalComponent ); } } @@ -1775,7 +1774,7 @@ void RenderController::updateDefaultCamera() return; } - const StringData *cameraOption = m_renderOptions->globals->member( g_cameraGlobalName ); + const StringData *cameraOption = m_renderOptions.globals->member( g_cameraGlobalName ); m_defaultCamera = nullptr; if( cameraOption && !cameraOption->readable().empty() ) { @@ -1783,7 +1782,7 @@ void RenderController::updateDefaultCamera() } CameraPtr defaultCamera = new IECoreScene::Camera; - SceneAlgo::applyCameraGlobals( defaultCamera.get(), m_renderOptions->globals.get(), m_scene.get() ); + SceneAlgo::applyCameraGlobals( defaultCamera.get(), m_renderOptions.globals.get(), m_scene.get() ); IECoreScenePreview::Renderer::AttributesInterfacePtr defaultAttributes = m_renderer->attributes( m_scene->attributesPlug()->defaultValue() ); ConstStringDataPtr name = new StringData( "gaffer:defaultCamera" ); m_defaultCamera = m_renderer->camera( name->readable(), defaultCamera.get(), defaultAttributes.get() );