| 640 | } |
| 641 | |
| 642 | int Shaders::returnProgram(std::string name, OptionalShaders optional_shaders) { |
| 643 | std::string short_name; |
| 644 | if (name.find(' ') != std::string::npos) { |
| 645 | short_name = name.substr(0, name.find(' ')); |
| 646 | } else { |
| 647 | short_name = name; |
| 648 | } |
| 649 | |
| 650 | unsigned num_programs = programs.size(); |
| 651 | for (unsigned i = 0; i < num_programs; ++i) { |
| 652 | if (name == programs[i].name) { |
| 653 | return i; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | PROFILER_ZONE(g_profiler_ctx, "Assemble shader program"); |
| 658 | |
| 659 | programs.push_back(Program()); |
| 660 | Program &program = programs.back(); |
| 661 | |
| 662 | program.name = name; |
| 663 | program.gl_program = UNLOADED_SHADER_ID; |
| 664 | |
| 665 | std::vector<std::string> definitions; |
| 666 | size_t name_len = name.length() + 1; |
| 667 | int def_start = -1; |
| 668 | const int min_definition_length = 3; // Must be at least 3 letters long |
| 669 | |
| 670 | for (size_t i = 0; i < name_len; ++i) { |
| 671 | switch (name[i]) { |
| 672 | case '#': |
| 673 | def_start = i + 1; |
| 674 | break; |
| 675 | case ' ': |
| 676 | case '\0': |
| 677 | if (def_start != -1 && def_start < static_cast<int>(i) - (min_definition_length - 1)) { |
| 678 | definitions.push_back( |
| 679 | std::string(&name[def_start], i - def_start)); |
| 680 | } |
| 681 | def_start = -1; |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | std::string vertex_path = GetShaderPath(short_name, shader_dir_path, _vertex); |
| 687 | std::string fragment_path = GetShaderPath(short_name, shader_dir_path, _fragment); |
| 688 | std::string geom_path = GetShaderPath(short_name, shader_dir_path, _geom); |
| 689 | std::string tess_eval_path = GetShaderPath(short_name, shader_dir_path, _tess_eval); |
| 690 | std::string tess_ctrl_path = GetShaderPath(short_name, shader_dir_path, _tess_ctrl); |
| 691 | |
| 692 | if (optional_shaders & kGeometry && FileExists(geom_path.c_str(), kDataPaths | kModPaths)) { |
| 693 | definitions.push_back("HAS_GEOM"); |
| 694 | } |
| 695 | |
| 696 | if (optional_shaders & kTesselation) { |
| 697 | if (FileExists(tess_eval_path.c_str(), kDataPaths | kModPaths)) { |
| 698 | definitions.push_back("HAS_TESS_EVAL"); |
| 699 | } |
no test coverage detected