Skip to content

Commit 882ad8d

Browse files
committed
[iceshard_pipelines] Revive the projects 'image' resource compiler and asset oven.
* Fix building for webassembly. (No fonts or meshes)
1 parent 29733ff commit 882ad8d

File tree

5 files changed

+85
-25
lines changed

5 files changed

+85
-25
lines changed

source/code/modules/iceshard_pipelines/iceshard_pipelines.bff

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,10 @@
99

1010
.BaseDir = '$WorkspaceCodeDir$/modules/iceshard_pipelines'
1111

12-
.Requires = {
13-
'Windows'
14-
}
15-
1612
.Private =
1713
[
1814
.Modules = {
1915
'arctic'
20-
'assimp'
21-
'freetype'
22-
'msdfgen'
23-
'msdf_atlas_gen'
2416
'rapidxml_ns'
2517
}
2618
.Uses = {
@@ -32,5 +24,30 @@
3224
'engine'
3325
}
3426
]
27+
28+
.Rule_Monolythic =
29+
[
30+
.Name = 'Monolythic'
31+
.Requires = { 'Monolythic' }
32+
.Kind = .Kind_ObjectList
33+
]
34+
.Rule_Win32Plugins =
35+
[
36+
.Name = 'EditorPlugins'
37+
.Requires = { 'Windows' }
38+
.Private =
39+
[
40+
.Modules = {
41+
'assimp'
42+
'freetype'
43+
'msdfgen'
44+
'msdf_atlas_gen'
45+
}
46+
]
47+
]
48+
.Rules = {
49+
.Rule_Monolythic
50+
.Rule_Win32Plugins
51+
}
3552
]
3653
.Projects + .Project

source/code/modules/iceshard_pipelines/private/asset_font.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <ice/font_utils.hxx>
1111
#include <ice/task_utils.hxx>
1212

13+
#if ISP_WINDOWS
14+
1315
ISC_WARNING_PUSH
1416
ISCW_DECLARATION_HIDES_CLASS_MEMBER(ISCW_OP_DISABLE)
1517
ISCW_UNREFERENCED_INTERNAL_FUNCTION_REMOVED(ISCW_OP_DISABLE)
@@ -246,3 +248,5 @@ namespace ice
246248
}
247249

248250
} // namespace ice
251+
252+
#endif

source/code/modules/iceshard_pipelines/private/asset_image.cxx

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/// SPDX-License-Identifier: MIT
33

44
#include "asset_image.hxx"
5+
#include <ice/config.hxx>
6+
#include <ice/asset_storage.hxx>
7+
#include <ice/resource_compiler_api.hxx>
58
#include <ice/render/render_image.hxx>
69

710
#define STB_IMAGE_IMPLEMENTATION
@@ -25,17 +28,37 @@
2528
namespace ice
2629
{
2730

28-
auto asset_image_oven(
31+
32+
auto asset_image_state(
2933
void*,
30-
ice::Allocator& alloc,
31-
ice::ResourceTracker const&,
32-
ice::LooseResource const& resource,
33-
ice::Data data,
34-
ice::Memory& memory
35-
) noexcept -> ice::Task<bool>
34+
ice::AssetCategoryDefinition const&,
35+
ice::Config const& metadata,
36+
ice::URI const& uri
37+
) noexcept -> ice::AssetState
38+
{
39+
bool baked = false;
40+
if (ice::config::get(metadata, "ice.shader.baked", baked) && baked)
41+
{
42+
return AssetState::Baked;
43+
}
44+
return AssetState::Raw;
45+
}
46+
47+
auto asset_image_oven(
48+
ice::ResourceCompilerCtx& ctx,
49+
ice::ResourceHandle const& resource_handle,
50+
ice::ResourceTracker& resource_tracker,
51+
ice::Span<ice::ResourceHandle const> sources,
52+
ice::Span<ice::URI const> dependencies,
53+
ice::Allocator& result_alloc
54+
) noexcept -> ice::Task<ice::ResourceCompilerResult>
3655
{
3756
using ice::render::ImageInfo;
3857

58+
ice::ResourceResult const res = co_await resource_tracker.load_resource(resource_handle);
59+
ice::Data const data = res.data;
60+
ICE_ASSERT_CORE(res.resource_status == ResourceStatus::Loaded);
61+
3962
stbi_uc const* image_buffer_raw = reinterpret_cast<stbi_uc const*>(data.location);
4063

4164
ice::i32 width = 0;
@@ -49,11 +72,12 @@ namespace ice
4972
STBI_rgb_alpha
5073
);
5174

75+
ice::Memory image_mem{};
5276
if (image_buffer != nullptr)
5377
{
5478
ice::meminfo image_meminfo = ice::meminfo_of<ImageInfo>;
5579
ice::usize const offset_data = image_meminfo += ice::meminfo_of<stbi_uc> * width * height * 4;
56-
ice::Memory image_mem = alloc.allocate(image_meminfo);
80+
image_mem = result_alloc.allocate(image_meminfo);
5781

5882
ice::render::ImageInfo* texture = reinterpret_cast<ImageInfo*>(image_mem.location);
5983
texture->type = ice::render::ImageType::Image2D;
@@ -74,10 +98,9 @@ namespace ice
7498
);
7599

76100
stbi_image_free(image_buffer);
77-
memory = image_mem;
78101
}
79102

80-
co_return width != 0 && height != 0;
103+
co_return ResourceCompilerResult{ image_mem };
81104
}
82105

83106
auto asset_image_loader(
@@ -107,17 +130,23 @@ namespace ice
107130
co_return true;
108131
}
109132

110-
void asset_category_image_definition(ice::AssetCategoryArchive& asset_category_archive) noexcept
133+
void asset_category_image_definition(
134+
ice::AssetCategoryArchive& asset_category_archive,
135+
ice::ModuleQuery const& module_query
136+
) noexcept
111137
{
112138
static ice::String extensions[]{ ".jpg", ".png", ".jpeg", ".bmp" };
113139

114-
static ice::AssetCategoryDefinition definition{
140+
static ice::ResourceCompiler const compiler{
141+
.fn_compile_source = asset_image_oven,
142+
};
143+
144+
static ice::AssetCategoryDefinition const definition{
115145
.resource_extensions = extensions,
116-
// .fn_asset_oven = asset_image_oven,
117-
.fn_asset_loader = asset_image_loader
146+
.fn_asset_loader = asset_image_loader,
118147
};
119148

120-
asset_category_archive.register_category(ice::render::AssetCategory_Texture2D, definition);
149+
asset_category_archive.register_category(ice::render::AssetCategory_Texture2D, definition, &compiler);
121150
}
122151

123152
} // namespace ice

source/code/modules/iceshard_pipelines/private/asset_image.hxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
namespace ice
88
{
99

10-
void asset_category_image_definition(ice::AssetCategoryArchive& asset_category_archive) noexcept;
10+
void asset_category_image_definition(
11+
ice::AssetCategoryArchive& asset_category_archive,
12+
ice::ModuleQuery const& module_query
13+
) noexcept;
1114

1215
} // namespace iceshard

source/code/modules/iceshard_pipelines/private/pipelines_module.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ namespace ice
1515

1616
struct IceShardPipelinesModule : ice::Module<IceShardPipelinesModule>
1717
{
18+
static void v1_archive_api(ice::detail::asset_system::v1::AssetArchiveAPI& api) noexcept;
19+
1820
static bool on_load(ice::Allocator& alloc, ice::ModuleNegotiator auto const& negotiator) noexcept
1921
{
2022
ice::LogModule::init(alloc, negotiator);
21-
return true;
23+
return negotiator.register_api(v1_archive_api);
2224
}
2325

2426
IS_WORKAROUND_MODULE_INITIALIZATION(IceShardPipelinesModule);
2527
};
2628

29+
void IceShardPipelinesModule::v1_archive_api(ice::detail::asset_system::v1::AssetArchiveAPI& api) noexcept
30+
{
31+
api.fn_register_categories = ice::asset_category_image_definition;
32+
}
33+
2734
} // namespace ice

0 commit comments

Comments
 (0)