FBOProvider.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // sub_1401E7170: backbuffer names (any case) are the scene's format, the rest go through sub_1401E53A0's table,
  9. // unknown names are RGBA8
  10. TextureFormat parseFormat (const std::string& name, const bool hdr) {
  11. static const std::map<std::string, TextureFormat> formats = {
  12. { "rgba8888", TextureFormat_ARGB8888 },
  13. { "rgb888", TextureFormat_RGB888 },
  14. { "rg88", TextureFormat_RG88 },
  15. { "r8", TextureFormat_R8 },
  16. { "rgb565", TextureFormat_RGB565 },
  17. { "bc7", TextureFormat_BC7 },
  18. { "dxt5", TextureFormat_DXT5 },
  19. { "dxt3", TextureFormat_DXT3 },
  20. { "dxt1", TextureFormat_DXT1 },
  21. { "rgba16161616f", TextureFormat_RGBA16161616f },
  22. { "rgb161616f", TextureFormat_RGB161616f },
  23. { "rg1616f", TextureFormat_RG1616f },
  24. { "r16f", TextureFormat_R16f },
  25. { "rgba16161616", TextureFormat_RGBA16161616 },
  26. { "rgb161616", TextureFormat_RGB161616 },
  27. { "rgba16161616S", TextureFormat_RGBA16161616S },
  28. { "rgb161616S", TextureFormat_RGB161616S },
  29. { "rgba8888s", TextureFormat_RGBA8888S },
  30. { "rgba1010102", TextureFormat_RGBa1010102 },
  31. };
  32. const auto equalsIgnoringCase = [&name] (const std::string_view other) {
  33. return std::ranges::equal (name, other, [] (const unsigned char a, const unsigned char b) {
  34. return std::tolower (a) == std::tolower (b);
  35. });
  36. };
  37. if (equalsIgnoringCase ("rgba_backbuffer")) {
  38. return hdr ? TextureFormat_RGBA16161616f : TextureFormat_ARGB8888;
  39. }
  40. if (equalsIgnoringCase ("rgb_backbuffer")) {
  41. return hdr ? TextureFormat_RGB161616f : TextureFormat_RGB888;
  42. }
  43. const auto it = formats.find (name);
  44. return it != formats.end () ? it->second : TextureFormat_ARGB8888;
  45. }
  46. } // namespace
  47. FBOProvider::FBOProvider (const FBOProvider* parent) : m_parent (parent) { }
  48. std::shared_ptr<CFBO> FBOProvider::create (const FBO& base, const glm::vec2 objectSize, const bool hdr) {
  49. // clamped unless uvs is "repeat" (sub_1401EA500)
  50. const uint32_t flags = base.repeat ? TextureFlags_NoFlags : TextureFlags_ClampUVs;
  51. const glm::uvec2 size = base.bufferSize (objectSize);
  52. return this->m_fbos[base.name] = std::make_shared<CFBO> (
  53. base.name, parseFormat (base.format, hdr), flags, std::max (base.scale, 1.0f), size.x, size.y, size.x,
  54. size.y
  55. );
  56. }
  57. std::shared_ptr<CFBO> FBOProvider::create (
  58. const std::string& name, TextureFormat format, uint32_t flags, float scale, glm::vec2 realSize,
  59. glm::vec2 textureSize, const glm::vec4& borderColor, const uint32_t mipLevels
  60. ) {
  61. return this->m_fbos[name] = std::make_shared<CFBO> (
  62. name, format, flags, scale, realSize.x, realSize.y, textureSize.x, textureSize.y, borderColor, mipLevels
  63. );
  64. }
  65. std::shared_ptr<CFBO> FBOProvider::alias (const std::string& newName, const std::string& original) {
  66. return this->m_fbos[newName] = this->m_fbos[original];
  67. }
  68. std::shared_ptr<CFBO> FBOProvider::find (const std::string& name) const {
  69. if (const auto it = this->m_fbos.find (name); it != this->m_fbos.end ()) {
  70. return it->second;
  71. }
  72. if (this->m_parent == nullptr) {
  73. return nullptr;
  74. }
  75. return this->m_parent->find (name);
  76. }