MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / EnsureSize

Method EnsureSize

Source/Engine/Level/Scene/Lightmap.cpp:64–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64void Lightmap::EnsureSize(int32 size)
65{
66 ASSERT(size >= 4 && size <= 4096);
67#if USE_EDITOR
68 _size = size;
69#endif
70
71 // Check every texture
72 for (int32 textureIndex = 0; textureIndex < ARRAY_COUNT(_textures); textureIndex++)
73 {
74 auto& texture = _textures[textureIndex];
75
76 // Check if has texture linked
77 if (texture)
78 {
79 // Wait for the loading
80 if (texture->WaitForLoaded())
81 {
82 // Unlink texture that cannot be loaded
83 LOG(Warning, "Lightmap::EnsureSize failed to load texture");
84 texture = nullptr;
85 }
86 else
87 {
88 // Check if need to resize texture
89 if (texture->GetTexture()->Width() != size || texture->GetTexture()->Height() != size)
90 {
91 // Unlink texture and import new with valid size
92 LOG(Info, "Changing lightmap {0}:{1} size from {2} to {3}", _index, textureIndex, texture->GetTexture()->Size(), size);
93 texture = nullptr;
94 }
95 }
96 }
97
98 // Check if has missing texture
99 if (texture == nullptr)
100 {
101#if USE_EDITOR
102
103#if COMPILE_WITH_ASSETS_IMPORTER
104
105 Guid id = Guid::New();
106 LOG(Info, "Cannot load lightmap ({1}:{2}). Creating new one with ID={0}.", id, _index, textureIndex);
107 String assetPath;
108 _manager->GetCachedLightmapPath(&assetPath, _index, textureIndex);
109
110 // Import texture with custom options
111 ImportTexture::Options options;
112 options.Type = TextureFormatType::HdrRGBA;
113 options.IndependentChannels = true;
114#if PLATFORM_WINDOWS
115 options.Compress = _manager->GetScene()->GetLightmapSettings().CompressLightmaps;
116#else
117 options.Compress = false; // TODO: use better BC7 compressor that would handle alpha more precisely (otherwise lightmaps have artifacts, see TextureTool.stb.cpp)
118#endif
119 options.IsAtlas = false;
120 options.sRGB = false;
121 options.NeverStream = false;

Callers 1

Calls 8

WaitForLoadedMethod · 0.80
GetTextureMethod · 0.80
GetCachedLightmapPathMethod · 0.80
GetLightmapSettingsMethod · 0.80
GetSceneMethod · 0.80
NewFunction · 0.50
CreateFunction · 0.50
SizeMethod · 0.45

Tested by

no test coverage detected