RenderContext.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <iostream>
  2. #include <GL/glew.h>
  3. #include "CWallpaper.h"
  4. #include "RenderContext.h"
  5. #include "WallpaperEngine/Data/Model/Project.h"
  6. namespace WallpaperEngine::Render {
  7. RenderContext::RenderContext (Drivers::VideoDriver& driver, WallpaperApplication& app) :
  8. m_driver (driver), m_app (app), m_textureCache (new TextureCache (*this)) { }
  9. void RenderContext::render (Drivers::Output::OutputViewport* viewport) {
  10. viewport->makeCurrent ();
  11. #if !NDEBUG
  12. const std::string str = "Rendering to output " + viewport->name;
  13. glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ());
  14. #endif /* DEBUG */
  15. // search the background in the viewport selection
  16. // render the background
  17. if (const auto ref = this->m_wallpapers.find (viewport->name); ref != this->m_wallpapers.end ()) {
  18. ref->second->render (viewport->viewport, this->getOutput ().renderVFlip ());
  19. }
  20. #if !NDEBUG
  21. glPopDebugGroup ();
  22. #endif /* DEBUG */
  23. viewport->swapOutput ();
  24. }
  25. void RenderContext::setWallpaper (const std::string& display, std::shared_ptr<CWallpaper> wallpaper) {
  26. this->m_wallpapers.insert_or_assign (display, wallpaper);
  27. }
  28. void RenderContext::setPause (const bool newState) const {
  29. for (const auto& wallpaper : this->m_wallpapers | std::views::values) {
  30. wallpaper->setPause (newState);
  31. }
  32. }
  33. Input::InputContext& RenderContext::getInputContext () const { return this->m_driver.getInputContext (); }
  34. const WallpaperApplication& RenderContext::getApp () const { return this->m_app; }
  35. const Drivers::VideoDriver& RenderContext::getDriver () const { return this->m_driver; }
  36. const Drivers::Output::Output& RenderContext::getOutput () const { return this->m_driver.getOutput (); }
  37. std::shared_ptr<const TextureProvider> RenderContext::resolveTexture (const std::string& name) const {
  38. return this->m_textureCache->resolve (name);
  39. }
  40. const std::map<std::string, std::shared_ptr<CWallpaper>>& RenderContext::getWallpapers () const {
  41. return this->m_wallpapers;
  42. }
  43. } // namespace WallpaperEngine::Render