1 // Copyright 2018 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #include "VideoCommon/AbstractFramebuffer.h"
6 #include "VideoCommon/AbstractTexture.h"
7 
AbstractFramebuffer(AbstractTexture * color_attachment,AbstractTexture * depth_attachment,AbstractTextureFormat color_format,AbstractTextureFormat depth_format,u32 width,u32 height,u32 layers,u32 samples)8 AbstractFramebuffer::AbstractFramebuffer(AbstractTexture* color_attachment,
9                                          AbstractTexture* depth_attachment,
10                                          AbstractTextureFormat color_format,
11                                          AbstractTextureFormat depth_format, u32 width, u32 height,
12                                          u32 layers, u32 samples)
13     : m_color_attachment(color_attachment), m_depth_attachment(depth_attachment),
14       m_color_format(color_format), m_depth_format(depth_format), m_width(width), m_height(height),
15       m_layers(layers), m_samples(samples)
16 {
17 }
18 
19 AbstractFramebuffer::~AbstractFramebuffer() = default;
20 
ValidateConfig(const AbstractTexture * color_attachment,const AbstractTexture * depth_attachment)21 bool AbstractFramebuffer::ValidateConfig(const AbstractTexture* color_attachment,
22                                          const AbstractTexture* depth_attachment)
23 {
24   // Must have at least a color or depth attachment.
25   if (!color_attachment && !depth_attachment)
26     return false;
27 
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 
40   // If both color and depth are present, their attributes must match.
41   if (color_attachment && depth_attachment)
42   {
43     if (color_attachment->GetConfig().width != depth_attachment->GetConfig().width ||
44         color_attachment->GetConfig().height != depth_attachment->GetConfig().height ||
45         color_attachment->GetConfig().layers != depth_attachment->GetConfig().layers ||
46         color_attachment->GetConfig().samples != depth_attachment->GetConfig().samples)
47     {
48       return false;
49     }
50   }
51 
52   return true;
53 }
54 
GetRect() const55 MathUtil::Rectangle<int> AbstractFramebuffer::GetRect() const
56 {
57   return MathUtil::Rectangle<int>(0, 0, static_cast<int>(m_width), static_cast<int>(m_height));
58 }
59