RenderContext.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include <glm/vec4.hpp>
  3. #include <memory>
  4. #include <optional>
  5. #include <vector>
  6. #include "TextureCache.h"
  7. #include "WallpaperEngine/Application/WallpaperApplication.h"
  8. #include "WallpaperEngine/Input/InputContext.h"
  9. #include "WallpaperEngine/Input/MouseInput.h"
  10. #include "WallpaperEngine/Render/Drivers/Output/Output.h"
  11. #include "WallpaperEngine/Render/Drivers/Output/OutputViewport.h"
  12. #include "WallpaperEngine/Render/Drivers/VideoDriver.h"
  13. namespace WallpaperEngine {
  14. namespace Application {
  15. class WallpaperApplication;
  16. }
  17. namespace Media {
  18. class MediaSource;
  19. }
  20. namespace Render {
  21. namespace Drivers {
  22. class VideoDriver;
  23. namespace Output {
  24. class Output;
  25. class OutputViewport;
  26. } // namespace Output
  27. } // namespace Drivers
  28. class CWallpaper;
  29. class TextureCache;
  30. class RenderContext {
  31. public:
  32. RenderContext (Drivers::VideoDriver& driver, WallpaperApplication& app, Media::MediaSource& mediaSource);
  33. void render (Drivers::Output::OutputViewport* viewport);
  34. /** holdPrevious keeps the old wallpaper's last frame on screen until the new one has content */
  35. void
  36. setWallpaper (const std::string& display, std::shared_ptr<CWallpaper> wallpaper, bool holdPrevious = false);
  37. void setPause (bool newState) const;
  38. void pruneTextures () const;
  39. [[nodiscard]] Input::InputContext& getInputContext () const;
  40. [[nodiscard]] const WallpaperApplication& getApp () const;
  41. [[nodiscard]] const Drivers::VideoDriver& getDriver () const;
  42. [[nodiscard]] const Drivers::Output::Output& getOutput () const;
  43. [[nodiscard]] std::shared_ptr<const TextureProvider>
  44. resolveTexture (const std::string& name, const Data::Model::Project& project) const;
  45. /** see TextureCache::iconTextureName */
  46. [[nodiscard]] std::string iconTextureName (const std::filesystem::path& icon) const;
  47. /** see TextureCache::findLoaded */
  48. [[nodiscard]] std::shared_ptr<const TextureProvider>
  49. findLoadedTexture (const std::string& name, const Data::Model::Project& project) const;
  50. [[nodiscard]] const std::map<std::string, std::shared_ptr<CWallpaper>>& getWallpapers () const;
  51. [[nodiscard]] Media::MediaSource& getMediaSource () const;
  52. /** Last frame's rect in the output framebuffer */
  53. [[nodiscard]] std::optional<glm::ivec4> getSlotRect (const std::string& slot) const;
  54. private:
  55. void renderWithStats (Drivers::Output::OutputViewport* viewport);
  56. void drawWallpapers (Drivers::Output::OutputViewport& viewport);
  57. void drawSplitScreen (
  58. Drivers::Output::OutputViewport& viewport, const Application::ApplicationContext::SplitScreen& split
  59. );
  60. void holdFrame (const std::string& display);
  61. void releaseHeldFrame (const std::string& display);
  62. void drawHeldFrame (const std::string& display, const glm::ivec4& rect, const CWallpaper& wallpaper);
  63. struct DrawTarget {
  64. Drivers::Output::OutputViewport* viewport = nullptr;
  65. glm::ivec4 rect {};
  66. };
  67. [[nodiscard]] std::optional<DrawTarget> findDrawTarget (const std::string& display) const;
  68. struct HeldFrame {
  69. GLuint framebuffer = GL_NONE;
  70. GLuint texture = GL_NONE;
  71. glm::ivec4 viewport {};
  72. };
  73. /** RGBA16F of the viewport's size, false on failure */
  74. static bool allocateHeldFrame (HeldFrame& held);
  75. Drivers::VideoDriver& m_driver;
  76. std::map<std::string, std::shared_ptr<CWallpaper>> m_wallpapers = {};
  77. WallpaperApplication& m_app;
  78. Media::MediaSource& m_mediaSource;
  79. std::unique_ptr<TextureCache> m_textureCache = nullptr;
  80. std::map<std::string, HeldFrame> m_heldFrames = {};
  81. std::map<std::string, glm::ivec4> m_slotRects = {};
  82. };
  83. } // namespace Render
  84. } // namespace WallpaperEngine