CWallpaper.h 4.7 KB

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