| 34 | } |
| 35 | |
| 36 | int32 TexturesStreamingHandler::CalculateResidency(StreamableResource* resource, float quality) |
| 37 | { |
| 38 | if (quality < ZeroTolerance) |
| 39 | return 0; |
| 40 | ASSERT(resource); |
| 41 | auto& texture = *(StreamingTexture*)resource; |
| 42 | ASSERT(texture.IsInitialized()); |
| 43 | const TextureHeader& header = *texture.GetHeader(); |
| 44 | |
| 45 | const int32 totalMipLevels = texture.TotalMipLevels(); |
| 46 | int32 mipLevels = Math::CeilToInt(quality * (float)totalMipLevels); |
| 47 | |
| 48 | if (header.TextureGroup >= 0 && header.TextureGroup < Streaming::TextureGroups.Count()) |
| 49 | { |
| 50 | const TextureGroup& group = Streaming::TextureGroups[header.TextureGroup]; |
| 51 | mipLevels = Math::Clamp(mipLevels + group.MipLevelsBias, group.MipLevelsMin, group.MipLevelsMax); |
| 52 | #if USE_EDITOR |
| 53 | // Simulate per-platform limit in Editor |
| 54 | int32 max; |
| 55 | if (group.MipLevelsMaxPerPlatform.TryGet(PLATFORM_TYPE, max)) |
| 56 | mipLevels = Math::Min(mipLevels, max); |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | if (mipLevels > 0 && mipLevels < texture._minMipCountBlockCompressed && texture._isBlockCompressed) |
| 61 | { |
| 62 | // Block compressed textures require minimum size of block size (eg. 4 for BC formats) |
| 63 | mipLevels = texture._minMipCountBlockCompressed; |
| 64 | } |
| 65 | |
| 66 | return Math::Clamp(mipLevels, 0, totalMipLevels); |
| 67 | } |
| 68 | |
| 69 | int32 TexturesStreamingHandler::CalculateRequestedResidency(StreamableResource* resource, int32 targetResidency) |
| 70 | { |
no test coverage detected