CTexture.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "GifAnimation.h"
  3. #include "Helpers/ContextAware.h"
  4. #include "TextureProvider.h"
  5. #include "WallpaperEngine/Data/Assets/Texture.h"
  6. #include "WallpaperEngine/VideoPlayback/MPV/GLPlayer.h"
  7. #include <GL/glew.h>
  8. #include <glm/vec4.hpp>
  9. #include <memory>
  10. #include <mpv/client.h>
  11. #include <mpv/render.h>
  12. #include <mpv/render_gl.h>
  13. #include <string>
  14. #include <vector>
  15. namespace WallpaperEngine::Render {
  16. class RenderContext;
  17. using namespace WallpaperEngine::Data::Assets;
  18. using namespace WallpaperEngine::VideoPlayback::MPV;
  19. /**
  20. * A normal texture file in WallpaperEngine's format
  21. */
  22. class CTexture final : public TextureProvider, public Helpers::ContextAware {
  23. public:
  24. explicit CTexture (RenderContext& context, TextureUniquePtr header);
  25. ~CTexture () override;
  26. [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
  27. [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
  28. [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override;
  29. [[nodiscard]] uint32_t getRealWidth () const override;
  30. [[nodiscard]] uint32_t getRealHeight () const override;
  31. [[nodiscard]] TextureFormat getFormat () const override;
  32. [[nodiscard]] uint32_t getFlags () const override;
  33. [[nodiscard]] const glm::vec4* getResolution () const override;
  34. [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
  35. [[nodiscard]] bool isAnimated () const override;
  36. /** For video CTextures, playback only starts once usage count goes above zero (initializes mpv if needed) */
  37. void incrementUsageCount () const override;
  38. /** For video CTextures, playback only stops once usage count reaches zero (de-initializes mpv if needed) */
  39. void decrementUsageCount () const override;
  40. void update () const override;
  41. bool isReady () const override;
  42. [[nodiscard]] GLPlayer* getPlayer () const override { return this->m_player.get (); }
  43. /** Debug label for every image of the texture, shows up in renderdoc/apitrace */
  44. void label (const std::string& name) const;
  45. /** Uploads a new parse of the same file (TEXB0004 patches), false if it doesn't fit the existing textures */
  46. bool repaint (TextureUniquePtr header);
  47. private:
  48. struct UploadFormat {
  49. GLint internalFormat;
  50. GLenum format;
  51. GLenum type;
  52. uint32_t bytesPerPixel;
  53. bool compressed;
  54. };
  55. [[nodiscard]] const Texture& getHeader () const;
  56. void setupResolution ();
  57. [[nodiscard]] UploadFormat uploadFormat () const;
  58. void setupOpenGLParameters (uint32_t textureID) const;
  59. void uploadImages (const UploadFormat& upload) const;
  60. TextureUniquePtr m_header;
  61. GLuint* m_textureID = nullptr;
  62. glm::vec4 m_resolution {};
  63. GLPlayerUniquePtr m_player;
  64. std::unique_ptr<GifAnimation> m_gif;
  65. /** g_Time of the last GIF step, a texture shared by several layers steps once per frame */
  66. mutable float m_gifTime = 0.0f;
  67. };
  68. } // namespace WallpaperEngine::Assets