CWallpaper.h 4.9 KB

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