Skip to content

Commit

Permalink
DynamicTextureAtlas: added growth factor parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 15, 2024
1 parent 48f769e commit d7bc037
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Graphics/GraphicsTools/interface/DynamicTextureAtlas.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -224,10 +224,13 @@ struct DynamicTextureAtlasCreateInfo
/// The number of extra slices.

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

/// Growth factor.

/// If ExtraSliceCount is zero, defines the factor by which the array size will be expanded.
float GrowthFactor = 2.0f;

/// Maximum number of slices in texture array.
Uint32 MaxSliceCount = 2048;
Expand Down
6 changes: 4 additions & 2 deletions Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -384,6 +384,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
// clang-format off
m_MinAlignment {CreateInfo.MinAlignment},
m_ExtraSliceCount {CreateInfo.ExtraSliceCount},
m_GrowthFactor {clamp(CreateInfo.GrowthFactor, 1.f, 2.f)},
m_MaxSliceCount {CreateInfo.Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY ? std::min(CreateInfo.MaxSliceCount, Uint32{2048}) : 1},
m_Silent {CreateInfo.Silent},
m_SuballocationsAllocator
Expand Down Expand Up @@ -688,7 +689,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
{
const auto ExtraSliceCount = m_ExtraSliceCount != 0 ?
m_ExtraSliceCount :
std::max(m_TexArraySize.load(), 1u);
std::max(static_cast<Uint32>(static_cast<float>(m_TexArraySize.load()) * m_GrowthFactor), 1u);

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

const Uint32 m_MinAlignment;
const Uint32 m_ExtraSliceCount;
const float m_GrowthFactor;
const Uint32 m_MaxSliceCount;
const bool m_Silent;

Expand Down

0 comments on commit d7bc037

Please sign in to comment.