diff --git a/src/liboslexec/batched_rendservices.cpp b/src/liboslexec/batched_rendservices.cpp index fbff377b2..878d02f3f 100644 --- a/src/liboslexec/batched_rendservices.cpp +++ b/src/liboslexec/batched_rendservices.cpp @@ -14,6 +14,15 @@ using namespace OSL::pvt; OSL_NAMESPACE_ENTER +#ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED +namespace { +std::mutex shared_texturesys_mutex; +std::shared_ptr shared_texturesys; +} // namespace +#endif + + + template BatchedRendererServices::BatchedRendererServices(TextureSystem* texsys) : m_texturesys(texsys) @@ -27,7 +36,17 @@ BatchedRendererServices::BatchedRendererServices(TextureSystem* texsys) OSL_ASSERT( 0 && "RendererServices was not passed a working TextureSystem*"); #else +# ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED + { + std::lock_guard lock(shared_texturesys_mutex); + if (!shared_texturesys) { + shared_texturesys = TextureSystem::create(true /* shared */); + } + m_texturesys = shared_texturesys.get(); + } +# else m_texturesys = TextureSystem::create(true /* shared */); +# endif // Make some good guesses about default options m_texturesys->attribute("automip", 1); m_texturesys->attribute("autotile", 64);