Skip to content

Commit e6beea8

Browse files
committed
most assets should convert (todo: shaders)
1 parent f364bac commit e6beea8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+652
-613
lines changed

cmake/cage_assets.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function(cage_assets_init)
4747
endif()
4848
cage_assets_add_schemes_path("${cage_assets_current_list_dir}/../schemes")
4949
cage_assets_add_data_path("${cage_assets_current_list_dir}/../data")
50-
configure_file("${cage_assets_current_list_dir}/../sources/include/cage-engine/shaderConventions.h" "${cage_assets_intermediate_path}/data/cage/shaders/" COPYONLY)
5150
cage_assets_generate_config()
5251
endfunction(cage_assets_init)
5352

data/cage/textures/textures.assets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ helper.jpg
1616

1717
[]
1818
scheme = texture
19-
target = 2dArray
2019
srgb = true
2120
progressbar/$.png
2221

schemes/texture.scheme

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ index = 11
55
[target]
66
display = texture type
77
type = enum
8-
values = 2d, 3d, 2dArray, cubeMap
9-
default = 2d
8+
values = regular, cubeMap, volume
9+
default = regular
1010

1111
[channels]
1212
display = change channels count
@@ -16,6 +16,11 @@ min = 0
1616
max = 4
1717
default = 0
1818

19+
[mipmaps]
20+
display = generate mipmaps
21+
type = bool
22+
default = true
23+
1924
[convert]
2025
display = re-purpose the texture
2126
type = enum
@@ -68,59 +73,3 @@ default = bcn
6873
display = vertical flip
6974
type = bool
7075
default = false
71-
72-
[invertRed]
73-
display = invert red channel
74-
type = bool
75-
default = false
76-
77-
[invertGreen]
78-
display = invert green channel
79-
type = bool
80-
default = false
81-
82-
[invertBlue]
83-
display = invert blue channel
84-
type = bool
85-
default = false
86-
87-
[invertAlpha]
88-
display = invert alpha channel
89-
type = bool
90-
default = false
91-
92-
[filterMin]
93-
display = minification filter
94-
type = enum
95-
values = nearestMipmapNearest, linearMipmapNearest, nearestMipmapLinear, linearMipmapLinear, nearest, linear
96-
default = linearMipmapLinear
97-
98-
[filterMag]
99-
display = magnification filter
100-
type = enum
101-
values = nearest, linear
102-
default = linear
103-
104-
[filterAniso]
105-
display = anisotropic filter
106-
type = enum
107-
values = 0, 2, 4, 8, 16, 32, 64
108-
default = 16
109-
110-
[wrapX]
111-
display = wrap x
112-
type = enum
113-
values = clampToEdge, clampToBorder, mirroredRepeat, repeat
114-
default = repeat
115-
116-
[wrapY]
117-
display = wrap y
118-
type = enum
119-
values = clampToEdge, clampToBorder, mirroredRepeat, repeat
120-
default = repeat
121-
122-
[wrapZ]
123-
display = wrap z
124-
type = enum
125-
values = clampToEdge, clampToBorder, mirroredRepeat, repeat
126-
default = repeat

sources/asset-processor/font.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include FT_FREETYPE_H
77
#include <msdfgen/ext/import-font.h>
88
#include <msdfgen/msdfgen.h>
9+
#include <webgpu/webgpu_cpp.h>
910

1011
#include "processor.h"
1112

@@ -16,7 +17,7 @@
1617
#include <cage-core/imageAlgorithms.h>
1718
#include <cage-core/rectPacking.h>
1819
#include <cage-core/tasks.h>
19-
//#include <cage-engine/texture.h>
20+
#include <cage-engine/texture.h>
2021

2122
#define FT_CALL(FNC, ...) \
2223
if (const FT_Error err = FNC(__VA_ARGS__)) \
@@ -208,27 +209,11 @@ namespace
208209
void saveTexture(uint32 index, const Image *img)
209210
{
210211
TextureHeader data;
211-
detail::memset(&data, 0, sizeof(TextureHeader));
212-
/*
213-
data.target = GL_TEXTURE_2D;
214212
data.resolution = Vec3i(img->width(), img->height(), 1);
215213
data.channels = img->channels();
216-
data.filterMin = GL_LINEAR;
217-
data.filterMag = GL_LINEAR;
218-
data.filterAniso = 0;
219-
data.wrapX = GL_CLAMP_TO_EDGE;
220-
data.wrapY = GL_CLAMP_TO_EDGE;
221-
data.wrapZ = GL_CLAMP_TO_EDGE;
222-
data.swizzle[0] = TextureSwizzleEnum::R;
223-
data.swizzle[1] = TextureSwizzleEnum::G;
224-
data.swizzle[2] = TextureSwizzleEnum::B;
225-
data.swizzle[3] = TextureSwizzleEnum::A;
226-
data.containedLevels = 1;
227-
data.mipmapLevels = 1;
228-
data.copyType = GL_UNSIGNED_BYTE;
229-
data.internalFormat = GL_RGB8;
230-
data.copyFormat = GL_RGB;
231-
*/
214+
data.mipLevels = 1;
215+
data.usage = (uint64)(wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::TextureBinding);
216+
data.format = (uint32)wgpu::TextureFormat::RGBA8Unorm;
232217

233218
MemoryBuffer inputBuffer;
234219
Serializer ser(inputBuffer);
@@ -238,7 +223,7 @@ namespace
238223
ser.write(bufferCast(img->rawViewU8()));
239224

240225
AssetHeader h = processor->initializeAssetHeader();
241-
//h.scheme = AssetSchemeIndexTexture;
226+
h.scheme = AssetSchemeIndexTexture;
242227
h.originalSize = inputBuffer.size();
243228
Holder<PointerRange<char>> outputBuffer = memoryCompress(inputBuffer);
244229
h.compressedSize = outputBuffer.size();

sources/asset-processor/model.cpp

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cage-core/meshAlgorithms.h>
1010
#include <cage-core/meshImport.h>
1111
#include <cage-core/skeletalAnimation.h>
12-
#include <cage-engine/shaderConventions.h>
12+
#include <cage-engine/model.h>
1313

1414
MeshImportConfig meshImportConfig()
1515
{
@@ -164,26 +164,9 @@ uint32 meshImportSelectIndex(const MeshImportResult &result)
164164

165165
namespace
166166
{
167-
enum class ModelDataFlags : uint32
167+
void setFlags(MeshComponentsFlags &flags, MeshComponentsFlags idx, bool available, const char *name)
168168
{
169-
None = 0,
170-
Normals = 1 << 0,
171-
Bones = 1 << 1,
172-
Uvs2 = 1 << 2,
173-
Uvs3 = 1 << 3,
174-
};
175-
}
176-
177-
namespace cage
178-
{
179-
GCHL_ENUM_BITS(ModelDataFlags);
180-
}
181-
182-
namespace
183-
{
184-
void setFlags(ModelDataFlags &flags, ModelDataFlags idx, bool available, const char *name)
185-
{
186-
bool requested = toBool(processor->property(name));
169+
const bool requested = toBool(processor->property(name));
187170
if (requested && !available)
188171
{
189172
CAGE_LOG_THROW(cage::String("requested feature: ") + name);
@@ -219,13 +202,13 @@ namespace
219202
}
220203
}
221204

222-
void validateFlags(const ModelHeader &dsm, const ModelDataFlags flags, const MeshRenderFlags renderFlags, const MeshImportMaterial &mat)
205+
void validateFlags(const ModelHeader &dsm, const MeshComponentsFlags flags, const MeshRenderFlags renderFlags, const MeshImportMaterial &mat)
223206
{
224207
{
225208
uint32 texCount = 0;
226209
for (uint32 i = 0; i < MaxTexturesCountPerMaterial; i++)
227210
texCount += dsm.textureNames[i] == 0 ? 0 : 1;
228-
if (texCount && none(flags & (ModelDataFlags::Uvs2 | ModelDataFlags::Uvs3)))
211+
if (texCount && none(flags & (MeshComponentsFlags::Uvs2 | MeshComponentsFlags::Uvs3)))
229212
{
230213
if (dsm.shaderName)
231214
CAGE_LOG(SeverityEnum::Warning, "assetProcessor", "material has a texture but no uvs");
@@ -237,7 +220,7 @@ namespace
237220
if (any(renderFlags & MeshRenderFlags::CutOut) + any(renderFlags & MeshRenderFlags::Transparent) + any(renderFlags & MeshRenderFlags::Fade) > 1)
238221
CAGE_THROW_ERROR(Exception, "material has multiple transparency flags (cutOut, transparent, fade)");
239222

240-
if (dsm.textureNames[CAGE_SHADER_TEXTURE_NORMAL] != 0 && none(flags & ModelDataFlags::Normals))
223+
if (dsm.textureNames[2] != 0 && none(flags & MeshComponentsFlags::Normals))
241224
CAGE_THROW_ERROR(Exception, "model uses normal map texture but has no normals");
242225
}
243226

@@ -301,29 +284,29 @@ void processModel()
301284
if (part.mesh->verticesCount() == 0)
302285
CAGE_THROW_ERROR(Exception, "the mesh is empty");
303286

304-
ModelDataFlags flags = ModelDataFlags::None;
305-
setFlags(flags, ModelDataFlags::Uvs2, !part.mesh->uvs().empty() || !part.mesh->uvs3().empty(), "uvs");
306-
setFlags(flags, ModelDataFlags::Normals, !part.mesh->normals().empty(), "normals");
307-
setFlags(flags, ModelDataFlags::Bones, !part.mesh->boneIndices().empty(), "bones");
287+
MeshComponentsFlags flags = MeshComponentsFlags::None;
288+
setFlags(flags, MeshComponentsFlags::Uvs2, !part.mesh->uvs().empty() || !part.mesh->uvs3().empty(), "uvs");
289+
setFlags(flags, MeshComponentsFlags::Normals, !part.mesh->normals().empty(), "normals");
290+
setFlags(flags, MeshComponentsFlags::Bones, !part.mesh->boneIndices().empty(), "bones");
308291

309292
if (!part.mesh->uvs3().empty())
310293
{
311294
CAGE_ASSERT(part.mesh->uvs().empty());
312-
flags &= ~ModelDataFlags::Uvs2;
313-
flags |= ModelDataFlags::Uvs3;
295+
flags &= ~MeshComponentsFlags::Uvs2;
296+
flags |= MeshComponentsFlags::Uvs3;
314297
}
315-
if (any(flags & ModelDataFlags::Uvs2))
298+
if (any(flags & MeshComponentsFlags::Uvs2))
316299
CAGE_LOG(SeverityEnum::Info, "assetProcessor", "using 2D uvs");
317-
if (any(flags & ModelDataFlags::Uvs3))
300+
if (any(flags & MeshComponentsFlags::Uvs3))
318301
CAGE_LOG(SeverityEnum::Info, "assetProcessor", "using 3D uvs");
319302

320-
if (none(flags & ModelDataFlags::Uvs2))
303+
if (none(flags & MeshComponentsFlags::Uvs2))
321304
part.mesh->uvs({});
322-
if (none(flags & ModelDataFlags::Uvs3))
305+
if (none(flags & MeshComponentsFlags::Uvs3))
323306
part.mesh->uvs3({});
324-
if (none(flags & ModelDataFlags::Normals))
307+
if (none(flags & MeshComponentsFlags::Normals))
325308
part.mesh->normals({});
326-
if (none(flags & ModelDataFlags::Bones))
309+
if (none(flags & MeshComponentsFlags::Bones))
327310
{
328311
part.mesh->boneIndices(PointerRange<Vec4i>());
329312
part.mesh->boneWeights(PointerRange<Vec4>());
@@ -342,13 +325,13 @@ void processModel()
342325
switch (t.type)
343326
{
344327
case MeshImportTextureType::Albedo:
345-
dsm.textureNames[CAGE_SHADER_TEXTURE_ALBEDO] = n;
328+
dsm.textureNames[0] = n;
346329
break;
347330
case MeshImportTextureType::Special:
348-
dsm.textureNames[CAGE_SHADER_TEXTURE_SPECIAL] = n;
331+
dsm.textureNames[1] = n;
349332
break;
350333
case MeshImportTextureType::Normal:
351-
dsm.textureNames[CAGE_SHADER_TEXTURE_NORMAL] = n;
334+
dsm.textureNames[2] = n;
352335
break;
353336
case MeshImportTextureType::Custom:
354337
dsm.textureNames[3] = n;
@@ -388,7 +371,7 @@ void processModel()
388371
h.dependenciesCount++;
389372
h.dependenciesCount += !!dsm.shaderName;
390373

391-
cage::MemoryBuffer buffer;
374+
MemoryBuffer buffer;
392375
Serializer ser(buffer);
393376
ser << dsm;
394377
ser << mat;

sources/asset-processor/processor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cage-core/assetHeader.h>
22
#include <cage-core/assetProcessor.h>
3+
#include <cage-core/assetsSchemes.h>
34
#include <cage-core/config.h>
45
#include <cage-core/files.h>
56
#include <cage-core/geometry.h>
@@ -8,7 +9,8 @@
89
#include <cage-core/memoryCompression.h>
910
#include <cage-core/serialization.h>
1011
#include <cage-core/string.h>
11-
#include <cage-engine/assetStructs.h>
12+
#include <cage-engine/assetsSchemes.h>
13+
#include <cage-engine/assetsStructs.h>
1214

1315
using namespace cage;
1416

sources/asset-processor/shader.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <cage-core/hashString.h>
99
#include <cage-core/timer.h>
10-
#include <cage-engine/assetStructs.h>
1110

1211
namespace
1312
{
@@ -242,20 +241,12 @@ namespace
242241

243242
uint32 shaderType(const String &name)
244243
{
245-
/*
246244
if (name == "vertex")
247-
return GL_VERTEX_SHADER;
245+
return 1;
248246
if (name == "fragment")
249-
return GL_FRAGMENT_SHADER;
250-
if (name == "geometry")
251-
return GL_GEOMETRY_SHADER;
252-
if (name == "control")
253-
return GL_TESS_CONTROL_SHADER;
254-
if (name == "evaluation")
255-
return GL_TESS_EVALUATION_SHADER;
247+
return 2;
256248
if (name == "compute")
257-
return GL_COMPUTE_SHADER;
258-
*/
249+
return 3;
259250
return 0;
260251
}
261252

@@ -267,13 +258,6 @@ namespace
267258
return true;
268259
}
269260

270-
bool allowParsingHash()
271-
{
272-
if (defines.count("allowParsingHash") == 0)
273-
return false;
274-
return toBool(defines["allowParsingHash"]);
275-
}
276-
277261
void parse(const String &filename)
278262
{
279263
Holder<File> file = readFile(filename);
@@ -292,7 +276,7 @@ namespace
292276
output("");
293277
continue;
294278
}
295-
if (line[0] == '$' || (allowParsingHash() && line[0] == '#'))
279+
if (line[0] == '$')
296280
{
297281
line = trim(subString(line, 1, m));
298282
String cmd = split(line);
@@ -481,9 +465,8 @@ void processShader()
481465
}
482466

483467
{
484-
ShaderProgramHeader header;
485-
header.keywordsCount = keywords.size();
486-
header.stagesCount = codes.size();
468+
MultiShaderHeader header;
469+
header.variantsCount = codes.size();
487470
if (defines.count("customDataCount"))
488471
{
489472
const uint32 cdc = toUint32(defines["customDataCount"]);
@@ -493,11 +476,13 @@ void processShader()
493476
MemoryBuffer buff;
494477
Serializer ser(buff);
495478
ser << header;
479+
/*
496480
for (const auto &it : keywords)
497481
{
498482
CAGE_LOG(SeverityEnum::Info, "assetProcessor", Stringizer() + "keyword: " + it);
499483
ser << it;
500484
}
485+
*/
501486
for (const auto &it : codes)
502487
{
503488
ser << (uint32)shaderType(it.first);

0 commit comments

Comments
 (0)