FBOProvider.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "FBOProvider.h"
  2. #include <algorithm>
  3. #include <cctype>
  4. #include <map>
  5. using namespace WallpaperEngine::Render;
  6. using namespace WallpaperEngine::Data::Model;
  7. namespace {
  8. // same names and fallback as wallpaper64.exe's lookup table (sub_140172ED0). the backbuffer formats
  9. // only switch to half floats in HDR scenes, which aren't supported here, so they stay 8-bit
  10. TextureFormat parseFormat (std::string name) {
  11. static const std::map<std::string, TextureFormat> formats = {
  12. { "rgba8888", TextureFormat_ARGB8888 },
  13. { "rgba_backbuffer", TextureFormat_ARGB8888 },
  14. { "rgb888", TextureFormat_RGB888 },
  15. { "rgb_backbuffer", TextureFormat_RGB888 },
  16. { "rgb565", TextureFormat_RGB565 },
  17. { "rg88", TextureFormat_RG88 },
  18. { "r8", TextureFormat_R8 },
  19. { "rg1616f", TextureFormat_RG1616f },
  20. { "r16f", TextureFormat_R16f },
  21. { "rgba16161616f", TextureFormat_RGBA16161616f },
  22. { "rgb161616f", TextureFormat_RGB161616f },
  23. };
  24. std::ranges::transform (name, name.begin (), [] (const unsigned char c) { return std::tolower (c); });
  25. const auto it = formats.find (name);
  26. return it != formats.end () ? it->second : TextureFormat_ARGB8888;
  27. }
  28. } // namespace
  29. FBOProvider::FBOProvider (const FBOProvider* parent) : m_parent (parent) { }
  30. std::shared_ptr<CFBO> FBOProvider::create (const FBO& base, uint32_t flags, const glm::vec2 size) {
  31. return this->m_fbos[base.name] = std::make_shared<CFBO> (
  32. base.name, parseFormat (base.format), flags, base.scale, size.x / base.scale, size.y / base.scale,
  33. size.x / base.scale, size.y / base.scale
  34. );
  35. }
  36. std::shared_ptr<CFBO> FBOProvider::create (
  37. const std::string& name, TextureFormat format, uint32_t flags, float scale, glm::vec2 realSize,
  38. glm::vec2 textureSize, const glm::vec4& borderColor, const uint32_t mipLevels
  39. ) {
  40. return this->m_fbos[name] = std::make_shared<CFBO> (
  41. name, format, flags, scale, realSize.x, realSize.y, textureSize.x, textureSize.y, borderColor, mipLevels
  42. );
  43. }
  44. std::shared_ptr<CFBO> FBOProvider::alias (const std::string& newName, const std::string& original) {
  45. return this->m_fbos[newName] = this->m_fbos[original];
  46. }
  47. std::shared_ptr<CFBO> FBOProvider::find (const std::string& name) const {
  48. if (const auto it = this->m_fbos.find (name); it != this->m_fbos.end ()) {
  49. return it->second;
  50. }
  51. if (this->m_parent == nullptr) {
  52. return nullptr;
  53. }
  54. return this->m_parent->find (name);
  55. }