Skip to content

Commit e8271b0

Browse files
committed
[iceshard] Implemented texture preview for the ImageStorage trait.
1 parent 6035277 commit e8271b0

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// Copyright 2025 - 2025, Dandielo <dandielo@iceshard.net>
2+
/// SPDX-License-Identifier: MIT
3+
4+
#pragma once
5+
#include <ice/engine_types.hxx>
6+
#include <ice/asset_category.hxx>
7+
8+
namespace ice
9+
{
10+
11+
static constexpr ice::AssetCategory AssetCategory_StaticObject = ice::make_asset_category("ice/object/static-object");
12+
static constexpr ice::AssetCategory AssetCategory_DynamicObject = ice::make_asset_category("ice/object/dynamic-object");
13+
static constexpr ice::AssetCategory AssetCategory_Tileset = ice::make_asset_category("ice/object/tileset");
14+
15+
} // namespace ice

source/code/iceshard/iceshard/private/gfx/traits/iceshard_gfx_image_storage_trait.cxx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,51 @@ namespace ice::gfx
3636

3737
Trait_GfxImageStorage::Trait_GfxImageStorage(ice::TraitContext& ctx, ice::Allocator& alloc) noexcept
3838
: ice::Trait{ ctx }
39+
, ice::TraitDevUI{ {.category = "Engine/Gfx", .name = "Images"} }
3940
, _allocator{ alloc, "gfx-image-storage" }
4041
, _loaded_images{ _allocator }
4142
{
4243
_context.bind<&Trait_GfxImageStorage::gfx_update, Render>(ice::gfx::ShardID_RenderFrameUpdate);
4344
_context.bind<&Trait_GfxImageStorage::gfx_shutdown, Render>(ice::gfx::ShardID_GfxShutdown);
4445
}
4546

47+
void Trait_GfxImageStorage::build_content() noexcept
48+
{
49+
static ice::i32 selected = -1;
50+
ice::Span<GfxImageEntry const> images = ice::hashmap::values(_loaded_images);
51+
52+
ice::String const preview = selected < 0 ? "<asset-uri>" : ice::stringid_hint(images[selected].asset.name());
53+
54+
if (ImGui::BeginCombo("Loaded Image", ice::string::begin(preview)))
55+
{
56+
if (ImGui::Selectable("##empty"))
57+
{
58+
selected = -1;
59+
}
60+
61+
ice::i32 idx = 0;
62+
for (GfxImageEntry const& entry : images)
63+
{
64+
if (ImGui::Selectable(ice::stringid_hint(entry.asset.name()), selected == idx))
65+
{
66+
selected = idx;
67+
}
68+
idx += 1;
69+
}
70+
ImGui::EndCombo();
71+
}
72+
73+
if (selected >= 0)
74+
{
75+
GfxImageEntry const& selected_entry = images[selected];
76+
ImTextureRef const ref{ ImTextureID(selected_entry.image) };
77+
float const avail_width = ImGui::GetContentRegionAvail().x;
78+
ImVec2 const size{ avail_width, avail_width };
79+
80+
ImGui::Image(ref, size);
81+
}
82+
}
83+
4684
auto Trait_GfxImageStorage::on_asset_released(ice::Asset const& asset) noexcept -> ice::Task<>
4785
{
4886
GfxImageEntry* entry = ice::hashmap::try_get(_loaded_images, ice::hash(asset.name()));
@@ -206,12 +244,14 @@ namespace ice::gfx
206244
// Allocates a handle for it... (TODO: Rework?)
207245
resolve_success.memory = uploaded_request->allocate(ice::size_of<Image>);
208246
*reinterpret_cast<Image*>(resolve_success.memory.location) = created_images[idx];
247+
248+
ice::u64 const asset_hash = ice::hash(uploaded_request->asset_name());
209249
ice::Asset asset = uploaded_request->resolve(resolve_success);
210250

211251
// Save the image handle
212252
ice::hashmap::set(
213253
_loaded_images,
214-
ice::hash(uploaded_request->asset_name()),
254+
asset_hash,
215255
{ .asset = ice::move(asset), .image = created_images[idx] }
216256
);
217257
}

source/code/iceshard/iceshard/private/gfx/traits/iceshard_gfx_image_storage_trait.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ namespace ice::gfx
2222

2323
class Trait_GfxImageStorage final
2424
: public ice::Trait
25+
, public ice::TraitDevUI
2526
, public ice::AssetRequestResolver
27+
, public ice::InterfaceSelectorOf<Trait_GfxImageStorage, ice::TraitDevUI>
2628
{
2729
public: // Implementation of: ice::Trait
2830
Trait_GfxImageStorage(ice::TraitContext& ctx, ice::Allocator& alloc) noexcept;
2931
~Trait_GfxImageStorage() noexcept override = default;
3032

33+
public: // Implementation of: ice::TraitDevUI
34+
auto trait_name() const noexcept -> ice::String override { return "Gfx.ImageStorage"; }
35+
void build_content() noexcept override;
36+
3137
public: // Implementation of: ice::AssetRequestResolver
3238
auto on_asset_released(ice::Asset const& asset) noexcept -> ice::Task<> override;
3339

0 commit comments

Comments
 (0)