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

Method define_function

source/effect_codegen_glsl.cpp:978–1029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

976 return res;
977 }
978 id define_function(const location &loc, function &info) override
979 {
980 const id res = info.id = make_id();
981
982 // Name is used in other places like the entry point defines, so escape it here
983 info.unique_name = escape_name(info.unique_name);
984
985 assert(!info.unique_name.empty() && (info.unique_name[0] == 'F' || info.unique_name[0] == 'E'));
986 const bool is_entry_point = info.unique_name[0] == 'E';
987 if (!is_entry_point)
988 define_name<naming::unique>(res, info.unique_name);
989 else
990 define_name<naming::reserved>(res, "main");
991
992 assert(_current_block == 0 && (_current_function_declaration.empty() || is_entry_point));
993 std::string &code = _current_function_declaration;
994
995 write_location(code, loc);
996
997 write_type(code, info.return_type);
998 code += ' ' + id_to_name(res) + '(';
999
1000 assert(info.parameter_list.empty() || !is_entry_point);
1001
1002 for (member_type &param : info.parameter_list)
1003 {
1004 param.id = make_id();
1005 define_name<naming::unique>(param.id, param.name);
1006
1007 code += '\n';
1008 write_location(code, param.location);
1009 code += '\t';
1010 write_type<true>(code, param.type); // GLSL does not allow interpolation attributes on function parameters
1011 code += ' ' + id_to_name(param.id);
1012
1013 if (param.type.is_array())
1014 code += '[' + std::to_string(param.type.array_length) + ']';
1015
1016 code += ',';
1017 }
1018
1019 // Remove trailing comma
1020 if (!info.parameter_list.empty())
1021 code.pop_back();
1022
1023 code += ")\n";
1024
1025 _functions.push_back(std::make_unique<function>(info));
1026 _current_function = _functions.back().get();
1027
1028 return res;
1029 }
1030
1031 void define_entry_point(function &func) override
1032 {

Callers 1

parse_functionMethod · 0.45

Calls 7

escape_nameFunction · 0.85
write_locationFunction · 0.85
write_typeFunction · 0.85
id_to_nameFunction · 0.85
to_stringFunction · 0.85
is_arrayMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected