manager.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // manager.hpp
  3. // graphics
  4. //
  5. // Created by Sam Jaffe on 5/25/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <memory>
  10. #include <unordered_map>
  11. #include "game/graphics/graphics_fwd.h"
  12. #include "game/math/math_fwd.hpp"
  13. namespace graphics {
  14. class manager {
  15. public:
  16. manager();
  17. ~manager();
  18. /**
  19. * @brief Load a material - from either cache or by fetching data from the
  20. * given arguments - and return its identifier.
  21. * A material is a linkage of shader(s) and texture(s), that desribe the
  22. * needed details to draw it on a page.
  23. * @param program The shader program that should be used to paint this
  24. * material.
  25. * @param texture The path to an image file for this material
  26. * @param uniform The name of the uniform to use as a fallback texture
  27. */
  28. identity<material> get(identity<shader_program> program,
  29. std::string const & texture,
  30. std::string const & uniform) const;
  31. /**
  32. * @brief Load a shader - from either cache or by fetching data from the
  33. * given arguments - and return its identifier.
  34. * A shader is a type of program that is run on the GPU by a library like
  35. * OpenGL.
  36. * @param type A shader type describe what it draws...
  37. * @param path The path to the shader's source code file.
  38. */
  39. identity<shader> get(shaders::type type, std::string const & path) const;
  40. /**
  41. * @brief Load a shader_program - from either cache or by fetching data from
  42. * the given arguments - and return its identifier.
  43. * @param fragment The file path to the fragment shader code.
  44. * @param vertex The file path to the vertex shader code.
  45. */
  46. identity<shader_program> get(std::string const & fragment,
  47. std::string const & vertex) const;
  48. /**
  49. * @brief Load a texture - from either cache or by fetching data from the
  50. * given arguments - and return its identifier.
  51. * @param path The file path to an imagefile that contains one or more
  52. * drawings of the object to be rendered.
  53. */
  54. identity<texture> get(std::string const & path) const;
  55. // TODO: This is kinda dumb...
  56. object create_object(identity<material> fromMaterial, math::vec2 atPosition,
  57. math::vec2 frameWidth, float scale) const;
  58. /**
  59. * @brief Translate a material identity into an actual object.
  60. * Used for internal linkage with the implementation code.
  61. */
  62. material const & get(identity<material> identity) const;
  63. /**
  64. * @brief Translate a texture identity into an actual object.
  65. * Used for internal linkage with the implementation code.
  66. */
  67. texture const & get(identity<texture> identity) const;
  68. private:
  69. void prepare_uniforms() const;
  70. identity<texture> texture_or_uniform(std::string const & path,
  71. std::string const & uniform) const;
  72. virtual shader compile(shaders::type type,
  73. std::string const & path) const = 0;
  74. virtual shader_program compile(identity<shader> fragment,
  75. identity<shader> vertex) const = 0;
  76. virtual texture compile(textures::format color, math::vec2i size,
  77. void const * buffer) const = 0;
  78. std::unique_ptr<struct manager_cache> pcache_;
  79. };
  80. }