CWallpaper.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #pragma once
  2. #include <GL/glew.h>
  3. #include <GLFW/glfw3.h>
  4. #include "WallpaperEngine/Assets/CContainer.h"
  5. #include "WallpaperEngine/Audio/CAudioContext.h"
  6. #include "WallpaperEngine/Core/CWallpaper.h"
  7. #include "WallpaperEngine/Core/Wallpapers/CScene.h"
  8. #include "WallpaperEngine/Core/Wallpapers/CVideo.h"
  9. #include "WallpaperEngine/Render/CFBO.h"
  10. #include "WallpaperEngine/Render/CRenderContext.h"
  11. #include "WallpaperEngine/Render/Helpers/CContextAware.h"
  12. #include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
  13. #include "CWallpaperState.h"
  14. using namespace WallpaperEngine::Assets;
  15. using namespace WallpaperEngine::Audio;
  16. using namespace WallpaperEngine::WebBrowser;
  17. namespace WallpaperEngine::Render {
  18. namespace Helpers {
  19. class CContextAware;
  20. }
  21. class CWallpaper : public Helpers::CContextAware {
  22. public:
  23. template <class T> const T* as () const {
  24. assert (is<T> ());
  25. return reinterpret_cast<const T*> (this);
  26. }
  27. template <class T> T* as () {
  28. assert (is<T> ());
  29. return reinterpret_cast<T*> (this);
  30. }
  31. template <class T> bool is () {
  32. return this->m_type == T::Type;
  33. }
  34. ~CWallpaper () override;
  35. /**
  36. * Performs a render pass of the wallpaper
  37. */
  38. void render (glm::ivec4 viewport, bool vflip);
  39. /**
  40. * Pause the renderer
  41. */
  42. virtual void setPause (bool newState);
  43. /**
  44. * @return The container to resolve files for this wallpaper
  45. */
  46. [[nodiscard]] CContainer* getContainer () const;
  47. /**
  48. * @return The current audio context for this wallpaper
  49. */
  50. CAudioContext& getAudioContext ();
  51. /**
  52. * @return The scene's framebuffer
  53. */
  54. [[nodiscard]] virtual GLuint getWallpaperFramebuffer () const;
  55. /**
  56. * @return The scene's texture
  57. */
  58. [[nodiscard]] virtual GLuint getWallpaperTexture () const;
  59. /**
  60. * Creates a new FBO for this wallpaper
  61. *
  62. * @param name The name of the FBO
  63. * @param format
  64. * @param flags
  65. * @param scale
  66. * @param realWidth
  67. * @param realHeight
  68. * @param textureWidth
  69. * @param textureHeight
  70. * @return
  71. */
  72. CFBO* createFBO (const std::string& name, ITexture::TextureFormat format, ITexture::TextureFlags flags, float scale,
  73. uint32_t realWidth, uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight);
  74. /**
  75. * Creates an alias of an existing fbo
  76. * @param alias
  77. * @param original
  78. */
  79. void aliasFBO (const std::string& alias, CFBO* original);
  80. /**
  81. * @return The full FBO list to work with
  82. */
  83. [[nodiscard]] const std::map<std::string, CFBO*>& getFBOs () const;
  84. /**
  85. * Searches the FBO list for the given FBO
  86. *
  87. * @param name
  88. * @return
  89. */
  90. [[nodiscard]] CFBO* findFBO (const std::string& name) const;
  91. /**
  92. * @return The main FBO of this wallpaper
  93. */
  94. [[nodiscard]] CFBO* getFBO () const;
  95. /**
  96. * Updates the UVs coordinates if window/screen/vflip/projection has changed
  97. */
  98. void updateUVs (const glm::ivec4& viewport, const bool vflip);
  99. /**
  100. * Updates the destination framebuffer for this wallpaper
  101. *
  102. * @param framebuffer
  103. */
  104. void setDestinationFramebuffer (GLuint framebuffer);
  105. /**
  106. * @return The width of this wallpaper
  107. */
  108. [[nodiscard]] virtual int getWidth () const = 0;
  109. /**
  110. * @return The height of this wallpaper
  111. */
  112. [[nodiscard]] virtual int getHeight () const = 0;
  113. /**
  114. * Creates a new instance of CWallpaper based on the information provided by the read backgrounds
  115. *
  116. * @param wallpaper
  117. * @param context
  118. * @param audioContext
  119. * @param scalingMode
  120. *
  121. * @return
  122. */
  123. static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext,
  124. CWebBrowserContext& browserContext,
  125. const CWallpaperState::TextureUVsScaling& scalingMode);
  126. protected:
  127. CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext,
  128. const CWallpaperState::TextureUVsScaling& scalingMode);
  129. /**
  130. * Renders a frame of the wallpaper
  131. */
  132. virtual void renderFrame (glm::ivec4 viewport) = 0;
  133. /**
  134. * Setups OpenGL's framebuffers for ping-pong and scene rendering
  135. */
  136. void setupFramebuffers ();
  137. Core::CWallpaper* m_wallpaperData;
  138. [[nodiscard]] Core::CWallpaper* getWallpaperData () const;
  139. /** The FBO used for scene output */
  140. CFBO* m_sceneFBO;
  141. private:
  142. /** The texture used for the scene output */
  143. GLuint m_texCoordBuffer;
  144. GLuint m_positionBuffer;
  145. GLuint m_shader;
  146. // shader variables
  147. GLint g_Texture0;
  148. GLint a_Position;
  149. GLint a_TexCoord;
  150. GLuint m_vaoBuffer;
  151. /** The framebuffer to draw the background to */
  152. GLuint m_destFramebuffer;
  153. /** Setups OpenGL's shaders for this wallpaper backbuffer */
  154. void setupShaders ();
  155. /** The type of background this wallpaper is */
  156. std::string m_type;
  157. /** List of FBOs registered for this wallpaper */
  158. std::map<std::string, CFBO*> m_fbos;
  159. /** Audio context that is using this wallpaper */
  160. CAudioContext& m_audioContext;
  161. /** Current Wallpaper state */
  162. CWallpaperState m_state;
  163. };
  164. } // namespace WallpaperEngine::Render