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

Method define_variable

source/effect_codegen_glsl.cpp:936–977  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

934 return res;
935 }
936 id define_variable(const location &loc, const type &type, std::string name, bool global, id initializer_value) override
937 {
938 // Constant variables with a constant initializer can just point to the initializer SSA variable, since they cannot be modified anyway, thus saving an unnecessary assignment
939 if (initializer_value != 0 && type.has(type::q_const) &&
940 std::find_if(_constant_lookup.begin(), _constant_lookup.end(),
941 [initializer_value](const auto &x) {
942 return initializer_value == std::get<2>(x);
943 }) != _constant_lookup.end())
944 return initializer_value;
945
946 const id res = make_id();
947
948 // GLSL does not allow local sampler variables, so try to remap those
949 if (!global && type.is_sampler())
950 {
951 _remapped_sampler_variables[res] = 0;
952 return res;
953 }
954
955 if (!name.empty())
956 define_name<naming::general>(res, name);
957
958 std::string &code = _blocks.at(_current_block);
959
960 write_location(code, loc);
961
962 if (!global)
963 code += '\t';
964
965 write_type(code, type);
966 code += ' ' + id_to_name(res);
967
968 if (type.is_array())
969 code += '[' + std::to_string(type.array_length) + ']';
970
971 if (initializer_value != 0)
972 code += " = " + id_to_name(initializer_value);
973
974 code += ";\n";
975
976 return res;
977 }
978 id define_function(const location &loc, function &info) override
979 {
980 const id res = info.id = make_id();

Callers 2

parse_variableMethod · 0.45

Calls 8

write_locationFunction · 0.85
write_typeFunction · 0.85
id_to_nameFunction · 0.85
to_stringFunction · 0.85
is_samplerMethod · 0.80
atMethod · 0.80
is_arrayMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected