CWallpaper.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. using namespace WallpaperEngine::Assets;
  9. namespace WallpaperEngine::Irrlicht
  10. {
  11. class CContext;
  12. };
  13. namespace WallpaperEngine::Render
  14. {
  15. class CWallpaper
  16. {
  17. public:
  18. template<class T> const T* as () const { assert (is<T> ()); return (const T*) this; }
  19. template<class T> T* as () { assert (is<T> ()); return (T*) this; }
  20. template<class T> bool is () { return this->m_type == T::Type; }
  21. CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CContainer* container);
  22. ~CWallpaper ();
  23. /**
  24. * Performs a render pass of the wallpaper
  25. */
  26. void render (glm::vec4 viewport, bool newFrame = true);
  27. /**
  28. * @return The container to resolve files for this wallpaper
  29. */
  30. CContainer* getContainer () const;
  31. /**
  32. * Performs a ping-pong on the available framebuffers to be able to continue rendering things to them
  33. *
  34. * @param drawTo The framebuffer to use
  35. * @param asInput The last texture used as output (if needed)
  36. */
  37. void pinpongFramebuffer (GLuint* drawTo, GLuint* inputTexture);
  38. /**
  39. * @return The scene's framebuffer
  40. */
  41. GLuint getWallpaperFramebuffer () const;
  42. /**
  43. * @return The scene's texture
  44. */
  45. GLuint getWallpaperTexture () const;
  46. protected:
  47. /**
  48. * Renders a frame of the wallpaper
  49. */
  50. virtual void renderFrame () = 0;
  51. /**
  52. * Setups OpenGL's framebuffers for ping-pong and scene rendering
  53. */
  54. void setupFramebuffers ();
  55. void createFramebuffer (GLuint* framebuffer, GLuint* depthbuffer, GLuint* texture);
  56. CContainer* m_container;
  57. Core::CWallpaper* m_wallpaperData;
  58. Core::CWallpaper* getWallpaperData ();
  59. /**
  60. * The main framebuffer
  61. */
  62. GLuint m_mainFramebuffer;
  63. /**
  64. * The sub framebuffer
  65. */
  66. GLuint m_subFramebuffer;
  67. /**
  68. * The main depth render buffer
  69. */
  70. GLuint m_mainDepthBuffer;
  71. /**
  72. * The sub depth render buffer
  73. */
  74. GLuint m_subDepthBuffer;
  75. /**
  76. * The main texture used on the framebuffer
  77. */
  78. GLuint m_mainTexture;
  79. /**
  80. * The sub texture used on the framebuffer
  81. */
  82. GLuint m_subTexture;
  83. /**
  84. * The framebuffer used for the scene output
  85. */
  86. GLuint m_sceneFramebuffer;
  87. /**
  88. * The depthbuffer used for the scene output
  89. */
  90. GLuint m_sceneDepthBuffer;
  91. private:
  92. /**
  93. * The texture used for the scene output
  94. */
  95. GLuint m_sceneTexture;
  96. GLuint m_texCoordBuffer;
  97. GLuint m_positionBuffer;
  98. GLuint m_shader;
  99. // shader variables
  100. GLint g_Texture0;
  101. GLint a_Position;
  102. GLint a_TexCoord;
  103. /**
  104. * Setups OpenGL's shaders for this wallpaper backbuffer
  105. */
  106. void setupShaders ();
  107. /**
  108. * The type of background this wallpaper is (used
  109. */
  110. std::string m_type;
  111. };
  112. }