| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #pragma once
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include "WallpaperEngine/Assets/CContainer.h"
- #include "WallpaperEngine/Audio/CAudioContext.h"
- #include "WallpaperEngine/Core/CWallpaper.h"
- #include "WallpaperEngine/Core/CScene.h"
- #include "WallpaperEngine/Core/CVideo.h"
- #include "WallpaperEngine/Render/CRenderContext.h"
- #include "WallpaperEngine/Render/CFBO.h"
- #include "WallpaperEngine/Render/Helpers/CContextAware.h"
- using namespace WallpaperEngine::Assets;
- using namespace WallpaperEngine::Audio;
- namespace WallpaperEngine::Render
- {
- namespace Helpers
- {
- class CContextAware;
- }
- class CWallpaper : public Helpers::CContextAware
- {
- public:
- template<class T> const T* as () const { assert (is<T> ()); return (const T*) this; }
- template<class T> T* as () { assert (is<T> ()); return (T*) this; }
- template<class T> bool is () { return this->m_type == T::Type; }
- ~CWallpaper ();
- /**
- * Performs a render pass of the wallpaper
- */
- void render (glm::ivec4 viewport, bool vflip);
- /**
- * @return The container to resolve files for this wallpaper
- */
- [[nodiscard]] CContainer* getContainer () const;
- /**
- * @return The current audio context for this wallpaper
- */
- CAudioContext& getAudioContext ();
- /**
- * @return The scene's framebuffer
- */
- [[nodiscard]] virtual GLuint getWallpaperFramebuffer () const;
- /**
- * @return The scene's texture
- */
- [[nodiscard]] virtual GLuint getWallpaperTexture () const;
- /**
- * Creates a new FBO for this wallpaper
- *
- * @param name The name of the FBO
- * @return
- */
- 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);
- /**
- * @return The full FBO list to work with
- */
- [[nodiscard]] const std::map<std::string, CFBO*>& getFBOs () const;
- /**
- * Searches the FBO list for the given FBO
- *
- * @param name
- * @return
- */
- [[nodiscard]] CFBO* findFBO (const std::string& name) const;
- /**
- * @return The main FBO of this wallpaper
- */
- [[nodiscard]] CFBO* getFBO () const;
- /**
- * Updates the texcoord used for drawing to the used framebuffer
- */
- void updateTexCoord (GLfloat* texCoords, GLsizeiptr size) const;
- /**
- * Updates the destination framebuffer for this wallpaper
- *
- * @param framebuffer
- */
- void setDestinationFramebuffer (GLuint framebuffer);
- /**
- * @return The width of this wallpaper
- */
- [[nodiscard]] virtual uint32_t getWidth () const = 0;
- /**
- * @return The height of this wallpaper
- */
- [[nodiscard]] virtual uint32_t getHeight () const = 0;
- /**
- * Creates a new instance of CWallpaper based on the information provided by the read backgrounds
- *
- * @param wallpaper
- *
- * @return
- */
- static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext);
- protected:
- CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext);
- /**
- * Renders a frame of the wallpaper
- */
- virtual void renderFrame (glm::ivec4 viewport) = 0;
- /**
- * Setups OpenGL's framebuffers for ping-pong and scene rendering
- */
- void setupFramebuffers ();
- Core::CWallpaper* m_wallpaperData;
- [[nodiscard]] Core::CWallpaper* getWallpaperData () const;
- /** The FBO used for scene output */
- CFBO* m_sceneFBO;
- private:
- /** The texture used for the scene output */
- GLuint m_texCoordBuffer;
- GLuint m_positionBuffer;
- GLuint m_shader;
- // shader variables
- GLint g_Texture0;
- GLint a_Position;
- GLint a_TexCoord;
- GLuint m_vaoBuffer;
- /** The framebuffer to draw the background to */
- GLuint m_destFramebuffer;
- /** Setups OpenGL's shaders for this wallpaper backbuffer */
- void setupShaders ();
- /** The type of background this wallpaper is */
- std::string m_type;
- /** List of FBOs registered for this wallpaper */
- std::map<std::string, CFBO*> m_fbos;
- /** Audio context that is using this wallpaper */
- CAudioContext& m_audioContext;
- };
- }
|