diff --git a/src/appleseed.studio/mainwindow/mainwindow.cpp b/src/appleseed.studio/mainwindow/mainwindow.cpp index 380444ed29..55ebcf1f19 100644 --- a/src/appleseed.studio/mainwindow/mainwindow.cpp +++ b/src/appleseed.studio/mainwindow/mainwindow.cpp @@ -1254,6 +1254,9 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode) rendering_mode == RenderingMode::InteractiveRendering ? "interactive" : "final"; const ParamArray params = get_project_params(configuration_name); + if (!project->has_texture_store()) + project->initialize_texture_store(params.child("texture_store")); + // Effectively start rendering. m_rendering_manager.start_rendering( project, diff --git a/src/appleseed.studio/mainwindow/rendering/materialdrophandler.cpp b/src/appleseed.studio/mainwindow/rendering/materialdrophandler.cpp index a68b25dcdb..86b86e8841 100644 --- a/src/appleseed.studio/mainwindow/rendering/materialdrophandler.cpp +++ b/src/appleseed.studio/mainwindow/rendering/materialdrophandler.cpp @@ -43,15 +43,15 @@ namespace appleseed { namespace studio { MaterialDropHandler::MaterialDropHandler( - const renderer::Project& project, - RenderingManager& rendering_manager) + const renderer::Project& project, + RenderingManager& rendering_manager) : m_project(project), m_rendering_manager(rendering_manager) { } void MaterialDropHandler::slot_material_dropped( - const foundation::Vector2d& drop_pos, - const QString& material_name) + const foundation::Vector2d& drop_pos, + const QString& material_name) { m_drop_pos = drop_pos; m_material_name = material_name.toStdString(); diff --git a/src/appleseed.studio/mainwindow/rendering/materialdrophandler.h b/src/appleseed.studio/mainwindow/rendering/materialdrophandler.h index 6a1c77330e..bc3b047b4b 100644 --- a/src/appleseed.studio/mainwindow/rendering/materialdrophandler.h +++ b/src/appleseed.studio/mainwindow/rendering/materialdrophandler.h @@ -55,19 +55,19 @@ class MaterialDropHandler public: MaterialDropHandler( - const renderer::Project& project, - RenderingManager& rendering_manager); + const renderer::Project& project, + RenderingManager& rendering_manager); public slots: void slot_material_dropped( - const foundation::Vector2d& drop_pos, - const QString& material_name); + const foundation::Vector2d& drop_pos, + const QString& material_name); private: - const renderer::Project& m_project; - RenderingManager& m_rendering_manager; - foundation::Vector2d m_drop_pos; - std::string m_material_name; + const renderer::Project& m_project; + RenderingManager& m_rendering_manager; + foundation::Vector2d m_drop_pos; + std::string m_material_name; void assign_material(const renderer::ObjectInstance::Side side); diff --git a/src/appleseed.studio/mainwindow/rendering/rendertab.cpp b/src/appleseed.studio/mainwindow/rendering/rendertab.cpp index 7552f27ca9..b47f7a8aff 100644 --- a/src/appleseed.studio/mainwindow/rendering/rendertab.cpp +++ b/src/appleseed.studio/mainwindow/rendering/rendertab.cpp @@ -498,7 +498,6 @@ void RenderTab::recreate_handlers() // Set initial state. m_pixel_inspector_handler->set_enabled(false); m_camera_controller->set_enabled(false); - m_scene_picking_handler->set_enabled(true); } } // namespace studio diff --git a/src/appleseed/foundation/string/internedstring.h b/src/appleseed/foundation/string/internedstring.h index 6e9f1e5eb8..6735b0a929 100644 --- a/src/appleseed/foundation/string/internedstring.h +++ b/src/appleseed/foundation/string/internedstring.h @@ -49,7 +49,7 @@ namespace foundation // // There are also some disadvantages: // -// - Constructing an interned string can be slower that a normal string. +// - Constructing an interned string can be slower than a normal string. // - Memory for the string characters is never freed. // // This implementation relies internally on OpenImageIO's ustring class. diff --git a/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp b/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp index 261d07ace8..80c40f1ed3 100644 --- a/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp +++ b/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp @@ -59,7 +59,7 @@ CPURenderDevice::CPURenderDevice( Project& project, const ParamArray& params) : RenderDeviceBase(project, params) - , m_texture_store(*project.get_scene(), params.child("texture_store")) + , m_texture_store(project.get_texture_store()) { m_error_handler = new OIIOErrorHandler(); #ifndef NDEBUG diff --git a/src/appleseed/renderer/device/cpu/cpurenderdevice.h b/src/appleseed/renderer/device/cpu/cpurenderdevice.h index f295e9c4c7..5e83f95f21 100644 --- a/src/appleseed/renderer/device/cpu/cpurenderdevice.h +++ b/src/appleseed/renderer/device/cpu/cpurenderdevice.h @@ -31,7 +31,6 @@ // appleseed.renderer headers. #include "renderer/device/cpu/cpurendercontext.h" #include "renderer/device/renderdevicebase.h" -#include "renderer/kernel/texturing/texturestore.h" #include "renderer/modeling/shadergroup/shadercompiler.h" // appleseed.foundation headers. @@ -47,6 +46,7 @@ namespace renderer { class OIIOTextureSystem; } namespace renderer { class OSLShadingSystem; } namespace renderer { class RendererComponents; } namespace renderer { class RendererServices; } +namespace renderer { class TextureStore; } namespace renderer { @@ -99,7 +99,7 @@ class CPURenderDevice RendererServices* m_renderer_services; OSLShadingSystem* m_shading_system; foundation::auto_release_ptr m_osl_compiler; - TextureStore m_texture_store; + TextureStore& m_texture_store; std::unique_ptr m_components; }; diff --git a/src/appleseed/renderer/kernel/intersection/assemblytree.cpp b/src/appleseed/renderer/kernel/intersection/assemblytree.cpp index 5dac26b63c..95fdcea1c7 100644 --- a/src/appleseed/renderer/kernel/intersection/assemblytree.cpp +++ b/src/appleseed/renderer/kernel/intersection/assemblytree.cpp @@ -40,6 +40,7 @@ #include "renderer/modeling/object/meshobject.h" #include "renderer/modeling/object/object.h" #include "renderer/modeling/object/proceduralobject.h" +#include "renderer/modeling/project/project.h" #include "renderer/modeling/scene/assemblyinstance.h" #include "renderer/modeling/scene/objectinstance.h" #include "renderer/modeling/scene/scene.h" @@ -77,9 +78,9 @@ namespace renderer // AssemblyTree class implementation. // -AssemblyTree::AssemblyTree(const Scene& scene) +AssemblyTree::AssemblyTree(const Project& project) : TreeType(AlignedAllocator(System::get_l1_data_cache_line_size())) - , m_scene(scene) + , m_project(project) #ifdef APPLESEED_WITH_EMBREE , m_use_embree(false) , m_dirty(false) @@ -163,7 +164,7 @@ void AssemblyTree::rebuild_assembly_tree() RENDERER_LOG_INFO("collecting assembly instances..."); AABBVector assembly_instance_bboxes; collect_assembly_instances( - m_scene.assembly_instances(), + m_project.get_scene()->assembly_instances(), TransformSequence(), assembly_instance_bboxes); @@ -185,7 +186,7 @@ void AssemblyTree::rebuild_assembly_tree() Builder builder; builder.build(*this, partitioner, m_items.size(), AssemblyTreeMaxLeafSize); statistics.insert_time("build time", builder.get_build_time()); - statistics.merge(bvh::TreeStatistics(*this, AABB3d(m_scene.compute_bbox()))); + statistics.merge(bvh::TreeStatistics(*this, AABB3d(m_project.get_scene()->compute_bbox()))); if (!m_items.empty()) { @@ -407,7 +408,7 @@ void AssemblyTree::create_triangle_tree(const Assembly& assembly) std::unique_ptr> triangle_tree_factory( new TriangleTreeFactory( TriangleTree::Arguments( - m_scene, + m_project, assembly.get_uid(), assembly_bbox, assembly))); @@ -435,7 +436,7 @@ void AssemblyTree::create_curve_tree(const Assembly& assembly) std::unique_ptr> curve_tree_factory( new CurveTreeFactory( CurveTree::Arguments( - m_scene, + *m_project.get_scene(), assembly.get_uid(), assembly_bbox, assembly))); @@ -473,7 +474,7 @@ void AssemblyTree::create_embree_scene(const Assembly& assembly) std::unique_ptr> embree_scene_factory( new EmbreeSceneFactory( EmbreeScene::Arguments( - m_scene.get_embree_device(), + m_project.get_scene()->get_embree_device(), assembly ))); diff --git a/src/appleseed/renderer/kernel/intersection/assemblytree.h b/src/appleseed/renderer/kernel/intersection/assemblytree.h index baa5daa81c..456c6af99f 100644 --- a/src/appleseed/renderer/kernel/intersection/assemblytree.h +++ b/src/appleseed/renderer/kernel/intersection/assemblytree.h @@ -58,7 +58,7 @@ // Forward declarations. namespace foundation { class Statistics; } namespace renderer { class AssemblyInstance; } -namespace renderer { class Scene; } +namespace renderer { class Project; } namespace renderer { class ShadingPoint; } namespace renderer @@ -77,7 +77,7 @@ class AssemblyTree { public: // Constructor, builds the tree for a given scene. - explicit AssemblyTree(const Scene& scene); + explicit AssemblyTree(const Project& project); // Destructor. ~AssemblyTree(); @@ -126,7 +126,7 @@ class AssemblyTree typedef std::vector AssemblyVector; typedef std::map AssemblyVersionMap; - const Scene& m_scene; + const Project& m_project; ItemVector m_items; AssemblyVersionMap m_assembly_versions; diff --git a/src/appleseed/renderer/kernel/intersection/tracecontext.cpp b/src/appleseed/renderer/kernel/intersection/tracecontext.cpp index 9080ee5d48..7254b2921b 100644 --- a/src/appleseed/renderer/kernel/intersection/tracecontext.cpp +++ b/src/appleseed/renderer/kernel/intersection/tracecontext.cpp @@ -56,9 +56,9 @@ namespace renderer // TraceContext class implementation. // -TraceContext::TraceContext(const Scene& scene) - : m_scene(scene) - , m_assembly_tree(new AssemblyTree(scene)) +TraceContext::TraceContext(const Project& project) + : m_project(project) + , m_assembly_tree(new AssemblyTree(project)) { RENDERER_LOG_DEBUG( "data structures size:\n" diff --git a/src/appleseed/renderer/kernel/intersection/tracecontext.h b/src/appleseed/renderer/kernel/intersection/tracecontext.h index 2ec597bb46..17d398492e 100644 --- a/src/appleseed/renderer/kernel/intersection/tracecontext.h +++ b/src/appleseed/renderer/kernel/intersection/tracecontext.h @@ -32,6 +32,9 @@ // appleseed.foundation headers. #include "foundation/core/concepts/noncopyable.h" +// appleseed.renderer headers. +#include "renderer/modeling/project/project.h" + // appleseed.main headers. #include "main/dllsymbol.h" @@ -54,7 +57,7 @@ class APPLESEED_DLLSYMBOL TraceContext { public: // Constructor, initializes the trace context for a given scene. - explicit TraceContext(const Scene& scene); + explicit TraceContext(const Project& project); // Destructor. ~TraceContext(); @@ -73,7 +76,7 @@ class APPLESEED_DLLSYMBOL TraceContext #endif private: - const Scene& m_scene; + const Project& m_project; AssemblyTree* m_assembly_tree; }; @@ -84,7 +87,7 @@ class APPLESEED_DLLSYMBOL TraceContext inline const Scene& TraceContext::get_scene() const { - return m_scene; + return *m_project.get_scene(); } inline const AssemblyTree& TraceContext::get_assembly_tree() const diff --git a/src/appleseed/renderer/kernel/intersection/triangletree.cpp b/src/appleseed/renderer/kernel/intersection/triangletree.cpp index e6ca78d54b..ad010a0f32 100644 --- a/src/appleseed/renderer/kernel/intersection/triangletree.cpp +++ b/src/appleseed/renderer/kernel/intersection/triangletree.cpp @@ -46,6 +46,7 @@ #include "renderer/modeling/object/meshobject.h" #include "renderer/modeling/object/object.h" #include "renderer/modeling/object/triangle.h" +#include "renderer/modeling/project/project.h" #include "renderer/modeling/scene/assembly.h" #include "renderer/modeling/scene/containers.h" #include "renderer/modeling/scene/objectinstance.h" @@ -383,11 +384,11 @@ namespace } TriangleTree::Arguments::Arguments( - const Scene& scene, + const Project& project, const UniqueID triangle_tree_uid, const GAABB3& bbox, const Assembly& assembly) - : m_scene(scene) + : m_project(project) , m_triangle_tree_uid(triangle_tree_uid) , m_bbox(bbox) , m_assembly(assembly) @@ -1262,8 +1263,7 @@ void TriangleTree::update_intersection_filters() object_instances_to_filter_keys); // Create missing intersection filters and update existing ones. - TextureStore texture_store(m_arguments.m_scene); - TextureCache texture_cache(texture_store); + TextureCache texture_cache(m_arguments.m_project.get_texture_store()); create_missing_intersection_filters( texture_cache, filter_keys, diff --git a/src/appleseed/renderer/kernel/intersection/triangletree.h b/src/appleseed/renderer/kernel/intersection/triangletree.h index 8222f1599e..883a7ddad6 100644 --- a/src/appleseed/renderer/kernel/intersection/triangletree.h +++ b/src/appleseed/renderer/kernel/intersection/triangletree.h @@ -59,7 +59,7 @@ namespace foundation { class Statistics; } namespace renderer { class Assembly; } namespace renderer { class IntersectionFilter; } namespace renderer { class ParamArray; } -namespace renderer { class Scene; } +namespace renderer { class Project; } namespace renderer { class ShadingPoint; } namespace renderer @@ -83,14 +83,14 @@ class TriangleTree // Construction arguments. struct Arguments { - const Scene& m_scene; + const Project& m_project; const foundation::UniqueID m_triangle_tree_uid; const GAABB3 m_bbox; const Assembly& m_assembly; // Constructor. Arguments( - const Scene& scene, + const Project& project, const foundation::UniqueID triangle_tree_uid, const GAABB3& bbox, const Assembly& assembly); diff --git a/src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp b/src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp index 06e8ce70f6..7717fbe419 100644 --- a/src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp +++ b/src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp @@ -178,7 +178,7 @@ BackwardLightSampler::BackwardLightSampler( } else { - // Prepare the light-emitting shapes CDF for smapling. + // Prepare the light-emitting shapes CDF for sampling. if (m_emitting_shapes_cdf.valid()) m_emitting_shapes_cdf.prepare(); diff --git a/src/appleseed/renderer/kernel/rendering/scenepicker.cpp b/src/appleseed/renderer/kernel/rendering/scenepicker.cpp index 3b9bedfa5b..96184db5aa 100644 --- a/src/appleseed/renderer/kernel/rendering/scenepicker.cpp +++ b/src/appleseed/renderer/kernel/rendering/scenepicker.cpp @@ -36,7 +36,6 @@ #include "renderer/kernel/intersection/tracecontext.h" #include "renderer/kernel/shading/shadingray.h" #include "renderer/kernel/texturing/texturecache.h" -#include "renderer/kernel/texturing/texturestore.h" #include "renderer/modeling/bsdf/bsdftraits.h" #include "renderer/modeling/bssrdf/bssrdftraits.h" #include "renderer/modeling/camera/camera.h" @@ -57,6 +56,9 @@ #include #include +// Forward declarations. +namespace renderer { class TextureStore; } + using namespace foundation; namespace renderer @@ -66,14 +68,14 @@ struct ScenePicker::Impl { const Project& m_project; const TraceContext& m_trace_context; - TextureStore m_texture_store; + TextureStore& m_texture_store; TextureCache m_texture_cache; Intersector m_intersector; explicit Impl(const Project& project) : m_project(project) , m_trace_context(m_project.get_trace_context()) - , m_texture_store(m_trace_context.get_scene()) + , m_texture_store(m_project.get_texture_store()) , m_texture_cache(m_texture_store) , m_intersector(m_trace_context, m_texture_cache) { diff --git a/src/appleseed/renderer/meta/tests/test_intersector.cpp b/src/appleseed/renderer/meta/tests/test_intersector.cpp index b7e39e6b23..4bb9a78794 100644 --- a/src/appleseed/renderer/meta/tests/test_intersector.cpp +++ b/src/appleseed/renderer/meta/tests/test_intersector.cpp @@ -34,7 +34,6 @@ #include "renderer/kernel/shading/shadingpoint.h" #include "renderer/kernel/shading/shadingray.h" #include "renderer/kernel/texturing/texturecache.h" -#include "renderer/kernel/texturing/texturestore.h" #include "renderer/modeling/object/object.h" #include "renderer/modeling/scene/assembly.h" #include "renderer/modeling/scene/assemblyinstance.h" @@ -53,6 +52,9 @@ #include "foundation/memory/autoreleaseptr.h" #include "foundation/utility/test.h" +// Forward declarations. +namespace renderer { class TextureStore; } + using namespace foundation; using namespace renderer; @@ -96,13 +98,13 @@ TEST_SUITE(Renderer_Kernel_Intersection_Intersector) : public StaticTestSceneContext { TraceContext m_trace_context; - TextureStore m_texture_store; + TextureStore& m_texture_store; TextureCache m_texture_cache; Intersector m_intersector; Fixture() - : m_trace_context(m_scene) - , m_texture_store(m_scene) + : m_trace_context(m_project) + , m_texture_store(m_project.get_texture_store()) , m_texture_cache(m_texture_store) , m_intersector(m_trace_context, m_texture_cache) { diff --git a/src/appleseed/renderer/meta/tests/test_tracer.cpp b/src/appleseed/renderer/meta/tests/test_tracer.cpp index 10c252cfc1..90ba4e4c0f 100644 --- a/src/appleseed/renderer/meta/tests/test_tracer.cpp +++ b/src/appleseed/renderer/meta/tests/test_tracer.cpp @@ -40,7 +40,6 @@ #include "renderer/kernel/shading/shadingray.h" #include "renderer/kernel/texturing/oiiotexturesystem.h" #include "renderer/kernel/texturing/texturecache.h" -#include "renderer/kernel/texturing/texturestore.h" #include "renderer/modeling/camera/pinholecamera.h" #include "renderer/modeling/color/colorentity.h" #include "renderer/modeling/entity/onframebeginrecorder.h" @@ -79,6 +78,9 @@ // Standard headers. #include +// Forward declarations. +namespace renderer { class TextureStore; } + using namespace foundation; using namespace renderer; @@ -216,7 +218,7 @@ TEST_SUITE(Renderer_Kernel_Lighting_Tracer) : public StaticTestSceneContext { TraceContext m_trace_context; - TextureStore m_texture_store; + TextureStore& m_texture_store; TextureCache m_texture_cache; Intersector m_intersector; std::shared_ptr m_texture_system; @@ -228,8 +230,8 @@ TEST_SUITE(Renderer_Kernel_Lighting_Tracer) Tracer m_tracer; Fixture() - : m_trace_context(FixtureParams::FixtureBaseClass::m_scene) - , m_texture_store(FixtureParams::FixtureBaseClass::m_scene) + : m_trace_context(FixtureParams::FixtureBaseClass::m_project) + , m_texture_store(FixtureParams::FixtureBaseClass::m_project.get_texture_store()) , m_texture_cache(m_texture_store) , m_intersector(m_trace_context, m_texture_cache) , m_texture_system( diff --git a/src/appleseed/renderer/modeling/project/project.cpp b/src/appleseed/renderer/modeling/project/project.cpp index e1f5f11dfe..d11ed0cebe 100644 --- a/src/appleseed/renderer/modeling/project/project.cpp +++ b/src/appleseed/renderer/modeling/project/project.cpp @@ -34,6 +34,7 @@ #include "renderer/global/globallogger.h" #include "renderer/kernel/intersection/tracecontext.h" #include "renderer/kernel/lighting/lightpathrecorder.h" +#include "renderer/kernel/texturing/texturestore.h" #include "renderer/modeling/aov/aovfactoryregistrar.h" #include "renderer/modeling/bsdf/bsdffactoryregistrar.h" #include "renderer/modeling/bssrdf/bssrdffactoryregistrar.h" @@ -126,6 +127,7 @@ struct Project::Impl LightPathRecorder m_light_path_recorder; std::unique_ptr m_trace_context; RenderingTimer m_rendering_timer; + std::unique_ptr m_texture_store; explicit Impl(const Project& project) : m_format_revision(ProjectFormatRevision) @@ -358,10 +360,7 @@ bool Project::has_trace_context() const const TraceContext& Project::get_trace_context() const { if (!impl->m_trace_context) - { - assert(impl->m_scene.get()); - impl->m_trace_context.reset(new TraceContext(*impl->m_scene)); - } + impl->m_trace_context.reset(new TraceContext(*this)); return *impl->m_trace_context; } @@ -436,6 +435,25 @@ void Project::on_frame_end( impl->m_rendering_timer.measure(); } +void Project::initialize_texture_store(const ParamArray& params) +{ + assert(impl->m_scene.get()); + + impl->m_texture_store.reset(new TextureStore(*impl->m_scene, params)); +} + +bool Project::has_texture_store() const +{ + return impl->m_texture_store.get() != nullptr; +} + +TextureStore& Project::get_texture_store() const +{ + assert(impl->m_texture_store); + + return *impl->m_texture_store; +} + void Project::add_base_configurations() { impl->m_configurations.insert(BaseConfigurationFactory::create_base_final()); diff --git a/src/appleseed/renderer/modeling/project/project.h b/src/appleseed/renderer/modeling/project/project.h index 3855f717f7..4e58c92733 100644 --- a/src/appleseed/renderer/modeling/project/project.h +++ b/src/appleseed/renderer/modeling/project/project.h @@ -80,11 +80,13 @@ namespace renderer { class LightPathRecorder; } namespace renderer { class Material; } namespace renderer { class Object; } namespace renderer { class OnFrameBeginRecorder; } +namespace renderer { class ParamArray; } namespace renderer { class PluginStore; } namespace renderer { class PostProcessingStage; } namespace renderer { class Scene; } namespace renderer { class SurfaceShader; } namespace renderer { class Texture; } +namespace renderer { class TextureStore; } namespace renderer { class TraceContext; } namespace renderer { class Volume; } @@ -192,6 +194,15 @@ class APPLESEED_DLLSYMBOL Project const Project& project, const BaseGroup* parent) override; + // Initialize the texture store. + void initialize_texture_store(const ParamArray& params); + + // Return true if the texture store has already been initialized. + bool has_texture_store() const; + + // Get the texture store. + TextureStore& get_texture_store() const; + private: friend class ProjectFactory;