MCPcopy Create free account
hub / github.com/crosire/reshade / write_constant

Method write_constant

source/effect_codegen_glsl.cpp:483–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

481 }
482 }
483 void write_constant(std::string &s, const type &data_type, const constant &data) const
484 {
485 if (data_type.is_array())
486 {
487 assert(data_type.is_bounded_array());
488
489 type elem_type = data_type;
490 elem_type.array_length = 0;
491
492 write_type<false, false>(s, elem_type);
493 s += '[' + std::to_string(data_type.array_length) + "](";
494
495 for (unsigned int a = 0; a < data_type.array_length; ++a)
496 {
497 write_constant(s, elem_type, a < static_cast<unsigned int>(data.array_data.size()) ? data.array_data[a] : constant {});
498 s += ", ";
499 }
500
501 // Remove trailing ", "
502 s.erase(s.size() - 2);
503
504 s += ')';
505 return;
506 }
507
508 // There can only be numeric constants
509 assert(data_type.is_numeric());
510
511 if (!data_type.is_scalar())
512 write_type<false, false>(s, data_type), s += '(';
513
514 for (unsigned int i = 0; i < data_type.components(); ++i)
515 {
516 switch (data_type.base)
517 {
518 case type::t_bool:
519 s += data.as_uint[i] ? "true" : "false";
520 break;
521 case type::t_min16int:
522 case type::t_int:
523 s += std::to_string(data.as_int[i]);
524 break;
525 case type::t_min16uint:
526 case type::t_uint:
527 s += std::to_string(data.as_uint[i]) + 'u';
528 break;
529 case type::t_min16float:
530 case type::t_float:
531 if (std::isnan(data.as_float[i])) {
532 s += "0.0/0.0/*nan*/";
533 break;
534 }
535 if (std::isinf(data.as_float[i])) {
536 s += std::signbit(data.as_float[i]) ? "1.0/0.0/*inf*/" : "-1.0/0.0/*-inf*/";
537 break;
538 }
539 {
540 char temp[64];

Callers

nothing calls this directly

Calls 9

to_stringFunction · 0.85
write_constantFunction · 0.85
is_arrayMethod · 0.80
is_bounded_arrayMethod · 0.80
is_numericMethod · 0.80
is_scalarMethod · 0.80
componentsMethod · 0.80
eraseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected