CWallpaper.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include <GL/glew.h>
  3. #include <GLFW/glfw3.h>
  4. #include "WallpaperEngine/Core/CWallpaper.h"
  5. #include "WallpaperEngine/Core/CScene.h"
  6. #include "WallpaperEngine/Core/CVideo.h"
  7. #include "CFBO.h"
  8. #include "CRenderContext.h"
  9. #include "WallpaperEngine/Assets/CContainer.h"
  10. #include "WallpaperEngine/Audio/CAudioContext.h"
  11. using namespace WallpaperEngine::Assets;
  12. using namespace WallpaperEngine::Audio;
  13. namespace WallpaperEngine::Render
  14. {
  15. class CRenderContext;
  16. class CWallpaper
  17. {
  18. public:
  19. template<class T> const T* as () const { assert (is<T> ()); return (const T*) this; }
  20. template<class T> T* as () { assert (is<T> ()); return (T*) this; }
  21. template<class T> bool is () { return this->m_type == T::Type; }
  22. CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext);
  23. ~CWallpaper ();
  24. /**
  25. * Performs a render pass of the wallpaper
  26. */
  27. void render (glm::ivec4 viewport, bool vflip, bool renderFrame = true, bool newFrame = true);
  28. /**
  29. * @return The container to resolve files for this wallpaper
  30. */
  31. CContainer* getContainer () const;
  32. /**
  33. * @return The current context rendering this wallpaper
  34. */
  35. CRenderContext& getContext ();
  36. /**
  37. * @return The current audio context for this wallpaper
  38. */
  39. CAudioContext& getAudioContext ();
  40. /**
  41. * @return The scene's framebuffer
  42. */
  43. virtual GLuint getWallpaperFramebuffer () const;
  44. /**
  45. * @return The scene's texture
  46. */
  47. 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. 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. CFBO* findFBO (const std::string& name) const;
  66. /**
  67. * @return The main FBO of this wallpaper
  68. */
  69. CFBO* getFBO () const;
  70. /**
  71. * Updates the texcoord used for drawing to the used framebuffer
  72. */
  73. void updateTexCoord (GLfloat* texCoords, GLsizeiptr size) const;
  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. virtual uint32_t getWidth () const = 0;
  84. /**
  85. * @return The height of this wallpaper
  86. */
  87. 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);
  96. protected:
  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. Core::CWallpaper* getWallpaperData () const;
  107. /**
  108. * The FBO used for scene output
  109. */
  110. CFBO* m_sceneFBO;
  111. private:
  112. /**
  113. * The texture used for the scene output
  114. */
  115. GLuint m_texCoordBuffer;
  116. GLuint m_positionBuffer;
  117. GLuint m_shader;
  118. // shader variables
  119. GLint g_Texture0;
  120. GLint a_Position;
  121. GLint a_TexCoord;
  122. GLuint m_vaoBuffer;
  123. /**
  124. * The framebuffer to draw the background to
  125. */
  126. GLuint m_destFramebuffer;
  127. /**
  128. * Setups OpenGL's shaders for this wallpaper backbuffer
  129. */
  130. void setupShaders ();
  131. /**
  132. * The type of background this wallpaper is (used
  133. */
  134. std::string m_type;
  135. /**
  136. * List of FBOs registered for this wallpaper
  137. */
  138. std::map<std::string, CFBO*> m_fbos;
  139. /**
  140. * Context that is using this wallpaper
  141. */
  142. CRenderContext& m_context;
  143. /*
  144. * Audio context that is using this wallpaper
  145. */
  146. CAudioContext& m_audioContext;
  147. };
  148. }