2018-01-21 03:22:45 -07:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "VideoCommon/AbstractFramebuffer.h"
|
|
|
|
#include "VideoCommon/AbstractTexture.h"
|
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
AbstractFramebuffer::AbstractFramebuffer(AbstractTexture* color_attachment,
|
|
|
|
AbstractTexture* depth_attachment,
|
|
|
|
AbstractTextureFormat color_format,
|
2018-01-21 03:22:45 -07:00
|
|
|
AbstractTextureFormat depth_format, u32 width, u32 height,
|
|
|
|
u32 layers, u32 samples)
|
2019-02-14 18:59:50 -07:00
|
|
|
: m_color_attachment(color_attachment), m_depth_attachment(depth_attachment),
|
|
|
|
m_color_format(color_format), m_depth_format(depth_format), m_width(width), m_height(height),
|
2018-01-21 03:22:45 -07:00
|
|
|
m_layers(layers), m_samples(samples)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractFramebuffer::~AbstractFramebuffer() = default;
|
|
|
|
|
|
|
|
bool AbstractFramebuffer::ValidateConfig(const AbstractTexture* color_attachment,
|
|
|
|
const AbstractTexture* depth_attachment)
|
|
|
|
{
|
|
|
|
// Must have at least a color or depth attachment.
|
|
|
|
if (!color_attachment && !depth_attachment)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Currently we only expose a single mip level for render target textures.
|
|
|
|
// MSAA textures are not supported with mip levels on most backends, and it simplifies our
|
|
|
|
// handling of framebuffers.
|
|
|
|
auto CheckAttachment = [](const AbstractTexture* tex) {
|
2019-02-14 18:59:50 -07:00
|
|
|
return tex->GetConfig().IsRenderTarget() && tex->GetConfig().levels == 1;
|
2018-01-21 03:22:45 -07:00
|
|
|
};
|
|
|
|
if ((color_attachment && !CheckAttachment(color_attachment)) ||
|
2018-03-23 07:58:19 -06:00
|
|
|
(depth_attachment && !CheckAttachment(depth_attachment)))
|
2018-01-21 03:22:45 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If both color and depth are present, their attributes must match.
|
|
|
|
if (color_attachment && depth_attachment)
|
|
|
|
{
|
|
|
|
if (color_attachment->GetConfig().width != depth_attachment->GetConfig().width ||
|
|
|
|
color_attachment->GetConfig().height != depth_attachment->GetConfig().height ||
|
|
|
|
color_attachment->GetConfig().layers != depth_attachment->GetConfig().layers ||
|
|
|
|
color_attachment->GetConfig().samples != depth_attachment->GetConfig().samples)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathUtil::Rectangle<int> AbstractFramebuffer::GetRect() const
|
|
|
|
{
|
|
|
|
return MathUtil::Rectangle<int>(0, 0, static_cast<int>(m_width), static_cast<int>(m_height));
|
|
|
|
}
|