| 167 | } |
| 168 | |
| 169 | SpriteHandle 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 | |
| 209 | bool PreviewsCache::ReleaseSlot(const Guid& id) |
| 210 | { |
no test coverage detected