💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_GL_SHADER_PROGRAM_HPP
  20. #define ANTKEEPER_GL_SHADER_PROGRAM_HPP
  21. #include <cstdlib>
  22. #include <list>
  23. #include <map>
  24. #include <string>
  25. namespace gl {
  26. class shader_object;
  27. class rasterizer;
  28. class shader_input;
  29. class shader_program
  30. {
  31. public:
  32. /**
  33. * Creates a shader program.
  34. *
  35. * @param shaders List of shaders to be linked to the program. Note that after the shader program has been created, these shaders can be deleted if desired with no effect on the shader program.
  36. */
  37. explicit shader_program(const std::list<shader_object*>& shaders);
  38. ~shader_program();
  39. shader_program(const shader_program&) = delete;
  40. shader_program& operator=(const shader_program&) = delete;
  41. const std::list<shader_input*>* get_inputs() const;
  42. const shader_input* get_input(const std::string& name) const;
  43. private:
  44. friend class rasterizer;
  45. void find_inputs();
  46. std::string get_info_log() const;
  47. unsigned int gl_program_id;
  48. std::list<shader_input*> inputs;
  49. std::map<std::string, shader_input*> input_map;
  50. };
  51. inline const std::list<shader_input*>* shader_program::get_inputs() const
  52. {
  53. return &inputs;
  54. }
  55. inline const shader_input* shader_program::get_input(const std::string& name) const
  56. {
  57. auto it = input_map.find(name);
  58. if (it == input_map.end())
  59. {
  60. return nullptr;
  61. }
  62. return it->second;
  63. }
  64. } // namespace gl
  65. #endif // ANTKEEPER_GL_SHADER_PROGRAM_HPP