AbstractFramebuffer.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2018 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "VideoCommon/AbstractFramebuffer.h"
  4. #include "VideoCommon/AbstractTexture.h"
  5. AbstractFramebuffer::AbstractFramebuffer(AbstractTexture* color_attachment,
  6. AbstractTexture* depth_attachment,
  7. std::vector<AbstractTexture*> additional_color_attachments,
  8. AbstractTextureFormat color_format,
  9. AbstractTextureFormat depth_format, u32 width, u32 height,
  10. u32 layers, u32 samples)
  11. : m_color_attachment(color_attachment), m_depth_attachment(depth_attachment),
  12. m_additional_color_attachments(std::move(additional_color_attachments)),
  13. m_color_format(color_format), m_depth_format(depth_format), m_width(width), m_height(height),
  14. m_layers(layers), m_samples(samples)
  15. {
  16. }
  17. AbstractFramebuffer::~AbstractFramebuffer() = default;
  18. bool AbstractFramebuffer::ValidateConfig(
  19. const AbstractTexture* color_attachment, const AbstractTexture* depth_attachment,
  20. const std::vector<AbstractTexture*>& additional_color_attachments)
  21. {
  22. // Must have at least a color or depth attachment.
  23. if (!color_attachment && !depth_attachment)
  24. return false;
  25. // Must have a color attachment if additional color attachments are defined
  26. if (!color_attachment && !additional_color_attachments.empty())
  27. return false;
  28. // Currently we only expose a single mip level for render target textures.
  29. // MSAA textures are not supported with mip levels on most backends, and it simplifies our
  30. // handling of framebuffers.
  31. auto CheckAttachment = [](const AbstractTexture* tex) {
  32. return tex->GetConfig().IsRenderTarget() && tex->GetConfig().levels == 1;
  33. };
  34. if ((color_attachment && !CheckAttachment(color_attachment)) ||
  35. (depth_attachment && !CheckAttachment(depth_attachment)))
  36. {
  37. return false;
  38. }
  39. for (auto* attachment : additional_color_attachments)
  40. {
  41. if (!CheckAttachment(attachment))
  42. {
  43. return false;
  44. }
  45. }
  46. // If both color and depth are present, their attributes must match.
  47. if (color_attachment && depth_attachment)
  48. {
  49. if (color_attachment->GetConfig().width != depth_attachment->GetConfig().width ||
  50. color_attachment->GetConfig().height != depth_attachment->GetConfig().height ||
  51. color_attachment->GetConfig().layers != depth_attachment->GetConfig().layers ||
  52. color_attachment->GetConfig().samples != depth_attachment->GetConfig().samples)
  53. {
  54. return false;
  55. }
  56. }
  57. for (auto* attachment : additional_color_attachments)
  58. {
  59. if (color_attachment->GetConfig().width != attachment->GetConfig().width ||
  60. color_attachment->GetConfig().height != attachment->GetConfig().height ||
  61. color_attachment->GetConfig().samples != attachment->GetConfig().samples)
  62. {
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. MathUtil::Rectangle<int> AbstractFramebuffer::GetRect() const
  69. {
  70. return MathUtil::Rectangle<int>(0, 0, static_cast<int>(m_width), static_cast<int>(m_height));
  71. }