1 #ifndef DALI_SCENE3D_LOADERERERER_RESOURCE_BUNDLE_H_
2 #define DALI_SCENE3D_LOADERERERER_RESOURCE_BUNDLE_H_
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/rendering/shader.h>
23 #include <dali/public-api/rendering/texture-set.h>
28 #include <dali-scene3d/public-api/loader/buffer-definition.h>
29 #include <dali-scene3d/public-api/loader/environment-definition.h>
30 #include <dali-scene3d/public-api/loader/material-definition.h>
31 #include <dali-scene3d/public-api/loader/mesh-definition.h>
32 #include <dali-scene3d/public-api/loader/shader-definition.h>
33 #include <dali-scene3d/public-api/loader/skeleton-definition.h>
35 namespace Dali::Scene3D::Loader
38 * @brief The types of resources that .dli may define.
41 struct DALI_SCENE3D_API ResourceType
51 ResourceType() = delete;
55 * @brief The string value corresponding to the given resource @a type.
57 * @return The string value for type.
59 DALI_SCENE3D_API const char* GetResourceTypeName(ResourceType::Value type);
61 using ResourceRefCounts = std::vector<Vector<uint32_t>>;
64 * @brief Stores all resource definitions along with the DALi resources that
65 * could be created from them, directly indexible into with values from a dli
69 class DALI_SCENE3D_API ResourceBundle
79 ForceReload = NthBit(0), ///< Load resources [again] even if they were already loaded.
80 KeepUnused = NthBit(1) ///<s Don't reset handles to resources that had a 0 reference count.
84 using PathProvider = std::function<std::string(ResourceType::Value)>;
88 ResourceBundle(const ResourceBundle&) = delete;
89 ResourceBundle& operator=(const ResourceBundle&) = delete;
91 ResourceBundle(ResourceBundle&&) = default;
92 ResourceBundle& operator=(ResourceBundle&&) = default;
95 * @brief A ResourceRefCounts object with the correct number of entries for
96 * all resource types (based on the various resource definition vectors),
97 * with all reference counts set to 0.
99 * @return A ResourceRefCounts object.
101 ResourceRefCounts CreateRefCounter() const;
104 * @brief Based on a ResourceRefCounts, and more specifically the reference
105 * count of materials therein, it will calculate the reference count of
109 void CountEnvironmentReferences();
112 * @brief Performs the loading of all resources based on their respective reference count in @a refCounts.
114 * Resources that had a non-zero ref count will be loaded unless we already have a handle to them
115 * (OR the ForceReload option was specified).
116 * Any handles we have to resources that come in with a zero ref count will be reset,
117 * UNLESS the KeepUnused option was specified.
120 * @param[in] pathProvider path provider for resource data.
121 * @param[in] options Option to load resource
122 * @note This method creates DALi objects like Dali::Texture, Dali::Geometry, etc.
124 void LoadResources(PathProvider pathProvider,
125 Options::Type options = Options::None);
128 * @brief Loads of all resources based on their respective reference count in @a refCounts.
130 * Resources that had a non-zero ref count will be loaded unless we already have a handle to them
131 * (OR the ForceReload option was specified).
132 * Any handles we have to resources that come in with a zero ref count will be reset,
133 * UNLESS the KeepUnused option was specified.
136 * @note This method don't create any of DALi objects.
137 * @param[in] pathProvider path provider for resource data.
138 * @param[in] options Option to load resource
139 * @note This method only loads raw data from resource file, and
140 * doesn't create any of DALi objects. GenerateResources() method is required to be called
141 * after this method to create DALi objects.
143 void LoadRawResources(PathProvider pathProvider,
144 Options::Type options = Options::None);
147 * @brief Generates DALi objects from already loaded Raw Resources.
149 * @param[in] options Option to load resource
150 * @note This method generates DALi objects from raw data that is already
151 * loaded by LoadRawResources method. Therefore, LoadRawResources should be called first
152 * before this method is called.
154 void GenerateResources(Options::Type options = Options::None);
157 ResourceRefCounts mReferenceCounts;
158 EnvironmentDefinition::Vector mEnvironmentMaps;
159 ShaderDefinition::Vector mShaders;
160 MeshDefinition::Vector mMeshes;
161 MaterialDefinition::Vector mMaterials;
163 SkeletonDefinition::Vector mSkeletons;
164 BufferDefinition::Vector mBuffers;
166 bool mRawResourcesLoading;
167 bool mResourcesGenerating;
169 bool mRawResourcesLoaded;
170 bool mResourcesGenerated;
173 } // namespace Dali::Scene3D::Loader
175 #endif //DALI_SCENE3D_LOADERERERER_RESOURCE_BUNDLE_H_