#pragma once #include #include #include #include #include "TextureCache.h" #include "WallpaperEngine/Application/WallpaperApplication.h" #include "WallpaperEngine/Input/InputContext.h" #include "WallpaperEngine/Input/MouseInput.h" #include "WallpaperEngine/Render/Drivers/Output/Output.h" #include "WallpaperEngine/Render/Drivers/Output/OutputViewport.h" #include "WallpaperEngine/Render/Drivers/VideoDriver.h" namespace WallpaperEngine { namespace Application { class WallpaperApplication; } namespace Media { class MediaSource; } namespace Render { namespace Drivers { class VideoDriver; namespace Output { class Output; class OutputViewport; } // namespace Output } // namespace Drivers class CWallpaper; class TextureCache; class RenderContext { public: RenderContext (Drivers::VideoDriver& driver, WallpaperApplication& app, Media::MediaSource& mediaSource); void render (Drivers::Output::OutputViewport* viewport); /** holdPrevious keeps the old wallpaper's last frame on screen until the new one has content */ void setWallpaper (const std::string& display, std::shared_ptr wallpaper, bool holdPrevious = false); void setPause (bool newState) const; void pruneTextures () const; [[nodiscard]] Input::InputContext& getInputContext () const; [[nodiscard]] const WallpaperApplication& getApp () const; [[nodiscard]] const Drivers::VideoDriver& getDriver () const; [[nodiscard]] const Drivers::Output::Output& getOutput () const; [[nodiscard]] std::shared_ptr resolveTexture (const std::string& name, const Data::Model::Project& project) const; /** see TextureCache::iconTextureName */ [[nodiscard]] std::string iconTextureName (const std::filesystem::path& icon) const; /** see TextureCache::findLoaded */ [[nodiscard]] std::shared_ptr findLoadedTexture (const std::string& name, const Data::Model::Project& project) const; [[nodiscard]] const std::map>& getWallpapers () const; [[nodiscard]] Media::MediaSource& getMediaSource () const; /** Last frame's rect in the output framebuffer */ [[nodiscard]] std::optional getSlotRect (const std::string& slot) const; private: void renderWithStats (Drivers::Output::OutputViewport* viewport); void drawWallpapers (Drivers::Output::OutputViewport& viewport); void drawSplitScreen ( Drivers::Output::OutputViewport& viewport, const Application::ApplicationContext::SplitScreen& split ); void holdFrame (const std::string& display); void releaseHeldFrame (const std::string& display); void drawHeldFrame (const std::string& display, const glm::ivec4& rect, const CWallpaper& wallpaper); struct DrawTarget { Drivers::Output::OutputViewport* viewport = nullptr; glm::ivec4 rect {}; }; [[nodiscard]] std::optional findDrawTarget (const std::string& display) const; struct HeldFrame { GLuint framebuffer = GL_NONE; GLuint texture = GL_NONE; glm::ivec4 viewport {}; }; /** RGBA16F of the viewport's size, false on failure */ static bool allocateHeldFrame (HeldFrame& held); Drivers::VideoDriver& m_driver; std::map> m_wallpapers = {}; WallpaperApplication& m_app; Media::MediaSource& m_mediaSource; std::unique_ptr m_textureCache = nullptr; std::map m_heldFrames = {}; std::map m_slotRects = {}; }; } // namespace Render } // namespace WallpaperEngine