| 209 | } |
| 210 | |
| 211 | static RefCntAutoPtr<GLTF::ResourceManager> CreateResourceManager(const HnRenderDelegate::CreateInfo& CI) |
| 212 | { |
| 213 | // Initial vertex and index counts are not important as the |
| 214 | // real number of vertices and indices will be determined after |
| 215 | // all meshes are synced for the first time. |
| 216 | static constexpr Uint32 InitialVertexCount = 1024; |
| 217 | static constexpr Uint32 InitialIndexCount = 1024; |
| 218 | |
| 219 | GLTF::ResourceManager::CreateInfo ResMgrCI; |
| 220 | |
| 221 | ResMgrCI.IndexAllocatorCI.Desc = {"Hydrogent index pool", sizeof(Uint32) * InitialIndexCount, BIND_INDEX_BUFFER, USAGE_DEFAULT}; |
| 222 | ResMgrCI.IndexAllocatorCI.MaxSize = Uint64{1024} << Uint64{20}; |
| 223 | |
| 224 | ResMgrCI.DefaultPoolDesc.VertexCount = InitialVertexCount; |
| 225 | ResMgrCI.DefaultPoolDesc.Usage = USAGE_DEFAULT; |
| 226 | |
| 227 | if (CI.TextureBindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS) |
| 228 | { |
| 229 | Uint32 TextureAtlasDim = CI.TextureAtlasDim; |
| 230 | |
| 231 | if (TextureAtlasDim != 0) |
| 232 | { |
| 233 | constexpr Uint32 MinAtlasDim = 512; |
| 234 | constexpr Uint32 MaxAtlasDim = 16384; |
| 235 | if (TextureAtlasDim < MinAtlasDim) |
| 236 | { |
| 237 | LOG_ERROR_MESSAGE("Texture atlas dimension (", TextureAtlasDim, ") must be at least ", MinAtlasDim); |
| 238 | TextureAtlasDim = MinAtlasDim; |
| 239 | } |
| 240 | else if (TextureAtlasDim > MaxAtlasDim) |
| 241 | { |
| 242 | LOG_ERROR_MESSAGE("Texture atlas dimension (", TextureAtlasDim, ") must be at most ", MaxAtlasDim); |
| 243 | TextureAtlasDim = MaxAtlasDim; |
| 244 | } |
| 245 | if (!IsPowerOfTwo(TextureAtlasDim)) |
| 246 | { |
| 247 | LOG_ERROR_MESSAGE("Texture atlas dimension (", TextureAtlasDim, ") must be a power of two"); |
| 248 | const auto MSB = PlatformMisc::GetMSB(TextureAtlasDim); |
| 249 | TextureAtlasDim = (MSB >= 13) ? 16384 : (1 << (MSB + 1)); |
| 250 | } |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | TextureAtlasDim = 2048; |
| 255 | } |
| 256 | |
| 257 | ResMgrCI.DefaultAtlasDesc.Desc.Name = "Hydrogent texture atlas"; |
| 258 | ResMgrCI.DefaultAtlasDesc.Desc.Type = RESOURCE_DIM_TEX_2D_ARRAY; |
| 259 | ResMgrCI.DefaultAtlasDesc.Desc.Usage = USAGE_DEFAULT; |
| 260 | ResMgrCI.DefaultAtlasDesc.Desc.BindFlags = BIND_SHADER_RESOURCE; |
| 261 | ResMgrCI.DefaultAtlasDesc.Desc.Width = TextureAtlasDim; |
| 262 | ResMgrCI.DefaultAtlasDesc.Desc.Height = TextureAtlasDim; |
| 263 | ResMgrCI.DefaultAtlasDesc.Desc.MipLevels = 6; |
| 264 | // Since texture atlas is resized only once, we can add one |
| 265 | // slice at a time to avoid wasting memory. |
| 266 | ResMgrCI.DefaultAtlasDesc.ExtraSliceCount = 1; |
| 267 | |
| 268 | ResMgrCI.DefaultAtlasDesc.MinAlignment = 64; |