MCPcopy Create free account
hub / github.com/crownengine/crown / parse_decl_comment

Method parse_decl_comment

src/resource/shader_resource.cpp:2382–2432  ·  view source on GitHub ↗

Parse uniform/sampler declaration comment.

Source from the content-addressed store, hash-verified

2380
2381 // Parse uniform/sampler declaration comment.
2382 s32 parse_decl_comment(UniformMetadata &um, const char *comment, CompileOptions &opts)
2383 {
2384 TempAllocator1024 ta;
2385 DynamicString meta_str(ta);
2386 JsonObject meta(ta);
2387
2388 um.val = VECTOR4_ZERO;
2389
2390 meta_str.set(comment + 2, strlen32(comment + 2));
2391 meta_str.trim();
2392
2393 if (!meta_str.has_prefix("{")) {
2394 um.type = UniformType::COUNT; // Do not add to metadata.
2395 return 0;
2396 }
2397
2398 RETURN_IF_ERROR(sjson::parse(meta, meta_str.c_str()));
2399
2400 auto cur = json_object::begin(meta);
2401 auto end = json_object::end(meta);
2402 for (; cur != end; ++cur) {
2403 JSON_OBJECT_SKIP_HOLE(meta, cur);
2404
2405 if (cur->first == "val") {
2406 if (json::type(cur->second) == JsonValueType::ARRAY) {
2407 JsonArray arr(ta);
2408
2409 RETURN_IF_ERROR(sjson::parse_array(arr, cur->second));
2410
2411 const u32 val_size = array::size(arr);
2412 RETURN_IF_FALSE(SHADER_RESOURCE, val_size <= 4 || val_size == 0
2413 , opts
2414 , "Invalid 'val' array size"
2415 );
2416
2417 for (u32 i = 0; i < array::size(arr); ++i) {
2418 *(&um.val.x + i) = RETURN_IF_ERROR(sjson::parse_float(arr[i]));
2419 }
2420 const UniformType::Enum map[] = { UniformType::COUNT, UniformType::FLOAT, UniformType::VECTOR2, UniformType::VECTOR3, UniformType::VECTOR4 };
2421 um.type = map[val_size];
2422 } else if (json::type(cur->second) == JsonValueType::NUMBER) {
2423 um.val.x = RETURN_IF_ERROR(sjson::parse_float(cur->second));
2424 um.type = UniformType::FLOAT;
2425 } else {
2426 RETURN_IF_FALSE(SHADER_RESOURCE, false, opts, "'val' must be either an array of numbers or a number");
2427 }
2428 }
2429 }
2430
2431 return 0;
2432 }
2433
2434 s32 parse_uniform_decl(UniformMetadata &um, const char *decl, CompileOptions &opts)
2435 {

Callers

nothing calls this directly

Calls 10

trimMethod · 0.80
parseFunction · 0.70
beginFunction · 0.50
endFunction · 0.50
typeFunction · 0.50
parse_arrayFunction · 0.50
sizeFunction · 0.50
parse_floatFunction · 0.50
setMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected