Skip to content

Commit d7bc037

Browse files
DynamicTextureAtlas: added growth factor parameter
1 parent 48f769e commit d7bc037

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Graphics/GraphicsTools/interface/DynamicTextureAtlas.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -224,10 +224,13 @@ struct DynamicTextureAtlasCreateInfo
224224
/// The number of extra slices.
225225

226226
/// When non-zero, the array will be expanded by the specified number of slices every time
227-
/// there is insufficient space. If zero, the array size will be doubled when
228-
/// more space is needed.
227+
/// there is insufficient space. If zero, the array size will be expanded by the growth factor.
229228
Uint32 ExtraSliceCount = 0;
230229

230+
/// Growth factor.
231+
232+
/// If ExtraSliceCount is zero, defines the factor by which the array size will be expanded.
233+
float GrowthFactor = 2.0f;
231234

232235
/// Maximum number of slices in texture array.
233236
Uint32 MaxSliceCount = 2048;

Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -384,6 +384,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
384384
// clang-format off
385385
m_MinAlignment {CreateInfo.MinAlignment},
386386
m_ExtraSliceCount {CreateInfo.ExtraSliceCount},
387+
m_GrowthFactor {clamp(CreateInfo.GrowthFactor, 1.f, 2.f)},
387388
m_MaxSliceCount {CreateInfo.Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY ? std::min(CreateInfo.MaxSliceCount, Uint32{2048}) : 1},
388389
m_Silent {CreateInfo.Silent},
389390
m_SuballocationsAllocator
@@ -688,7 +689,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
688689
{
689690
const auto ExtraSliceCount = m_ExtraSliceCount != 0 ?
690691
m_ExtraSliceCount :
691-
std::max(m_TexArraySize.load(), 1u);
692+
std::max(static_cast<Uint32>(static_cast<float>(m_TexArraySize.load()) * m_GrowthFactor), 1u);
692693

693694
m_TexArraySize.store(std::min(m_TexArraySize + ExtraSliceCount, m_MaxSliceCount));
694695
}
@@ -721,6 +722,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
721722

722723
const Uint32 m_MinAlignment;
723724
const Uint32 m_ExtraSliceCount;
725+
const float m_GrowthFactor;
724726
const Uint32 m_MaxSliceCount;
725727
const bool m_Silent;
726728

0 commit comments

Comments
 (0)