CWallpaper.h 4.1 KB

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