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

Function parse_uniforms

src/resource/material_resource.cpp:247–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245 }
246
247 static s32 parse_uniforms(Data &data, const char *json, CompileOptions &opts)
248 {
249 TempAllocator4096 ta;
250 JsonObject obj(ta);
251 RETURN_IF_ERROR(sjson::parse(obj, json));
252
253 auto cur = json_object::begin(obj);
254 auto end = json_object::end(obj);
255 for (; cur != end; ++cur) {
256 JSON_OBJECT_SKIP_HOLE(obj, cur);
257
258 const StringView key = cur->first;
259 const char *value = cur->second;
260
261 JsonObject uniform(ta);
262 RETURN_IF_ERROR(sjson::parse_object(uniform, value));
263
264 DynamicString type(ta);
265 RETURN_IF_ERROR(sjson::parse_string(type, uniform["type"]));
266
267 const UniformType::Enum ut = name_to_uniform_type(type.c_str());
268 RETURN_IF_FALSE(MATERIAL_RESOURCE, ut != UniformType::COUNT
269 , opts
270 , "Unknown uniform type: '%s'"
271 , type.c_str()
272 );
273
274 UniformValue val;
275 memset(&val, 0, sizeof(val));
276 s32 err = 0;
277
278 switch (ut) {
279 case UniformType::FLOAT:
280 val.v.x = RETURN_IF_ERROR(sjson::parse_float(uniform["value"]));
281 err = data.check_uniform(key, ut, val, opts);
282 break;
283
284 case UniformType::VECTOR2: {
285 const Vector2 v = RETURN_IF_ERROR(sjson::parse_vector2(uniform["value"]));
286 val.v.x = v.x;
287 val.v.y = v.y;
288 err = data.check_uniform(key, ut, val, opts);
289 break;
290 }
291
292 case UniformType::VECTOR3: {
293 const Vector3 v = RETURN_IF_ERROR(sjson::parse_vector3(uniform["value"]));
294 val.v.x = v.x;
295 val.v.y = v.y;
296 val.v.z = v.z;
297 err = data.check_uniform(key, ut, val, opts);
298 break;
299 }
300
301 case UniformType::VECTOR4:
302 val.v = RETURN_IF_ERROR(sjson::parse_vector4(uniform["value"]));
303 err = data.check_uniform(key, ut, val, opts);
304 break;

Callers 1

compileFunction · 0.85

Calls 14

name_to_uniform_typeFunction · 0.85
memsetFunction · 0.85
parse_vector2Function · 0.85
parse_vector3Function · 0.85
parse_vector4Function · 0.85
parse_matrix4x4Function · 0.85
check_uniformMethod · 0.80
parseFunction · 0.70
beginFunction · 0.50
endFunction · 0.50
parse_objectFunction · 0.50
parse_stringFunction · 0.50

Tested by

no test coverage detected