registry.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "../submitter.h"
  3. #include <QMatrix4x4>
  4. #include <QVector3D>
  5. #include <functional>
  6. #include <memory>
  7. #include <string>
  8. #include <unordered_map>
  9. namespace Engine::Core {
  10. class Entity;
  11. class World;
  12. } // namespace Engine::Core
  13. namespace Render::GL {
  14. class ResourceManager;
  15. class Mesh;
  16. class Texture;
  17. class Backend;
  18. class Camera;
  19. } // namespace Render::GL
  20. namespace Render::GL {
  21. enum class HumanoidLOD : uint8_t {
  22. Full = 0,
  23. Reduced = 1,
  24. Minimal = 2,
  25. Billboard = 3
  26. };
  27. enum class HorseLOD : uint8_t {
  28. Full = 0,
  29. Reduced = 1,
  30. Minimal = 2,
  31. Billboard = 3
  32. };
  33. struct DrawContext {
  34. ResourceManager *resources = nullptr;
  35. Engine::Core::Entity *entity = nullptr;
  36. Engine::Core::World *world = nullptr;
  37. QMatrix4x4 model;
  38. bool selected = false;
  39. bool hovered = false;
  40. float animation_time = 0.0F;
  41. std::string renderer_id;
  42. class Backend *backend = nullptr;
  43. const Camera *camera = nullptr;
  44. float alpha_multiplier = 1.0F;
  45. bool animation_throttled = false;
  46. };
  47. using RenderFunc = std::function<void(const DrawContext &, ISubmitter &out)>;
  48. class EntityRendererRegistry {
  49. public:
  50. void register_renderer(const std::string &type, RenderFunc func);
  51. auto get(const std::string &type) const -> RenderFunc;
  52. private:
  53. std::unordered_map<std::string, RenderFunc> m_map;
  54. };
  55. void register_built_in_entity_renderers(EntityRendererRegistry &registry);
  56. } // namespace Render::GL