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

Method OccupySlot

Source/Editor/Content/PreviewsCache.cpp:169–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169SpriteHandle PreviewsCache::OccupySlot(GPUTexture* source, const Guid& id)
170{
171 if (WaitForLoaded())
172 return SpriteHandle::Invalid;
173
174 // Find this asset slot or use the first empty
175 int32 index = _assets.Find(id);
176 if (index == INVALID_INDEX)
177 index = _assets.Find(Guid::Empty);
178 if (index == INVALID_INDEX)
179 {
180 LOG(Warning, "Cannot find free slot in the asset previews atlas.");
181 return SpriteHandle::Invalid;
182 }
183
184 ASSERT(IsReady());
185
186 // Copy texture region
187 uint32 x = ASSETS_ICONS_ATLAS_MARGIN + index % ASSETS_ICONS_PER_ROW * (ASSET_ICON_SIZE + ASSETS_ICONS_ATLAS_MARGIN);
188 uint32 y = ASSETS_ICONS_ATLAS_MARGIN + index / ASSETS_ICONS_PER_ROW * (ASSET_ICON_SIZE + ASSETS_ICONS_ATLAS_MARGIN);
189 GPUDevice::Instance->GetMainContext()->CopyTexture(GetTexture(), 0, x, y, 0, source, 0);
190
191 // Occupy slot
192 _assets[index] = id;
193
194 // Get sprite handle
195 const String spriteName = StringUtils::ToString(index);
196 const auto slot = FindSprite(spriteName);
197 if (!slot.IsValid())
198 {
199 LOG(Warning, "Cannot create sprite handle for asset preview.");
200 return SpriteHandle::Invalid;
201 }
202
203 // Set dirty flag
204 _isDirty = true;
205
206 return slot;
207}
208
209bool PreviewsCache::ReleaseSlot(const Guid& id)
210{

Callers 1

OnRenderMethod · 0.80

Calls 7

GetTextureFunction · 0.85
IsReadyFunction · 0.50
ToStringFunction · 0.50
FindMethod · 0.45
CopyTextureMethod · 0.45
GetMainContextMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected