CFBO.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <optional>
  3. #include <string>
  4. #include "TextureProvider.h"
  5. using namespace WallpaperEngine::Render;
  6. namespace WallpaperEngine::Render {
  7. class CFBO final : public TextureProvider {
  8. public:
  9. CFBO (
  10. std::string name, const TextureFormat format, const uint32_t flags, const float scale, uint32_t realWidth,
  11. uint32_t realHeight, uint32_t textureWidth, uint32_t textureHeight,
  12. const glm::vec4& borderColor = { 0.0f, 0.0f, 0.0f, 1.0f }, uint32_t mipLevels = 1
  13. );
  14. ~CFBO () override;
  15. /**
  16. * Parses a "RRGGBB" or "RRGGBBAA" hex color (an optional leading '#' is stripped), or
  17. * std::nullopt if value isn't a valid hex color. Used for --corner-color and its hotswap key.
  18. */
  19. static std::optional<glm::vec4> parseColor (const std::string& value);
  20. /**
  21. * Updates the border color shown outside the wallpaper's bounds when its wrap mode is
  22. * GL_CLAMP_TO_BORDER (see TextureFlags_ClampUVsBorder). Safe to call live, no reload needed.
  23. */
  24. void setBorderColor (const glm::vec4& color) const;
  25. /** Adds a depth buffer, only 3D scenes draw into the scene buffer with depth testing */
  26. void attachDepthBuffer ();
  27. /** Reallocates the storage at a new size (and mip count, 0 keeps it), cleared. Whoever holds the buffer keeps
  28. * the same object */
  29. void resize (uint32_t width, uint32_t height, uint32_t mipLevels = 0);
  30. /** Rebuilds mip levels 1 and up from level 0, only for buffers created with more than one level */
  31. void generateMipmaps () const;
  32. [[nodiscard]] uint32_t getMipLevels () const;
  33. [[nodiscard]] const std::string& getName () const;
  34. [[nodiscard]] const float& getScale () const;
  35. [[nodiscard]] TextureFormat getFormat () const override;
  36. [[nodiscard]] uint32_t getFlags () const override;
  37. [[nodiscard]] GLuint getFramebuffer () const;
  38. [[nodiscard]] GLuint getDepthbuffer () const;
  39. [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
  40. [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
  41. [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override;
  42. [[nodiscard]] uint32_t getRealWidth () const override;
  43. [[nodiscard]] uint32_t getRealHeight () const override;
  44. [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
  45. [[nodiscard]] const glm::vec4* getResolution () const override;
  46. [[nodiscard]] bool isAnimated () const override;
  47. void incrementUsageCount () const override;
  48. void decrementUsageCount () const override;
  49. void update () const override;
  50. bool isReady () const override;
  51. private:
  52. /** The bound texture becomes the depth attachment of the bound framebuffer (TextureFormat_D32f) */
  53. void setupDepthOnly (uint32_t width, uint32_t height);
  54. GLuint m_framebuffer = GL_NONE;
  55. GLuint m_depthbuffer = GL_NONE;
  56. GLuint m_texture = GL_NONE;
  57. glm::vec4 m_resolution = {};
  58. float m_scale = 0;
  59. std::string m_name = "";
  60. TextureFormat m_format = TextureFormat_UNKNOWN;
  61. uint32_t m_flags = TextureFlags_NoFlags;
  62. uint32_t m_mipLevels = 1;
  63. /** Placeholder for frames, FBOs only have ONE */
  64. std::vector<FrameSharedPtr> m_frames = {};
  65. };
  66. } // namespace WallpaperEngine::Render