CRenderContext.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "common.h"
  2. #include <iostream>
  3. #include <GL/glew.h>
  4. #include "CRenderContext.h"
  5. #include "CVideo.h"
  6. #include "CWallpaper.h"
  7. namespace WallpaperEngine::Render
  8. {
  9. CRenderContext::CRenderContext (
  10. Drivers::CVideoDriver& driver, Input::CInputContext& input,
  11. CWallpaperApplication& app
  12. ) :
  13. m_defaultWallpaper (nullptr),
  14. m_driver (driver),
  15. m_app (app),
  16. m_input (input),
  17. m_textureCache (new CTextureCache (*this))
  18. {
  19. }
  20. void CRenderContext::render (Drivers::Output::COutputViewport* viewport)
  21. {
  22. viewport->makeCurrent ();
  23. #if !NDEBUG
  24. std::string str = "Rendering to output " + viewport->name;
  25. glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 0, -1, str.c_str ());
  26. #endif /* DEBUG */
  27. // search the background in the viewport selection
  28. auto ref = this->m_wallpapers.find (viewport->name);
  29. // render the background
  30. if (ref != this->m_wallpapers.end ())
  31. ref->second->render (viewport->viewport, this->getOutput ().renderVFlip ());
  32. else
  33. this->m_defaultWallpaper->render (viewport->viewport, this->getOutput ().renderVFlip ());
  34. #if !NDEBUG
  35. glPopDebugGroup ();
  36. #endif /* DEBUG */
  37. viewport->swapOutput ();
  38. }
  39. void CRenderContext::setDefaultWallpaper (CWallpaper* wallpaper)
  40. {
  41. this->m_defaultWallpaper = wallpaper;
  42. }
  43. void CRenderContext::setWallpaper (const std::string& display, CWallpaper* wallpaper)
  44. {
  45. this->m_wallpapers.insert_or_assign (display, wallpaper);
  46. }
  47. Input::CInputContext& CRenderContext::getInputContext () const
  48. {
  49. return this->m_input;
  50. }
  51. const CWallpaperApplication& CRenderContext::getApp () const
  52. {
  53. return this->m_app;
  54. }
  55. const Drivers::CVideoDriver& CRenderContext::getDriver () const
  56. {
  57. return this->m_driver;
  58. }
  59. const Drivers::Output::COutput& CRenderContext::getOutput () const
  60. {
  61. return this->m_driver.getOutput ();
  62. }
  63. const ITexture* CRenderContext::resolveTexture (const std::string& name)
  64. {
  65. return this->m_textureCache->resolve (name);
  66. }
  67. }