Files
dolphin/Source/Core/VideoBackends/Software/SWRenderer.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

193 lines
5.7 KiB
C++
Raw Normal View History

// Copyright 2009 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2010-06-09 01:37:08 +00:00
2017-01-23 11:20:20 -05:00
#include "VideoBackends/Software/SWRenderer.h"
2014-06-03 01:08:54 -04:00
#include <string>
2014-09-07 20:06:58 -05:00
#include "Common/CommonTypes.h"
#include "Common/GL/GLContext.h"
2015-10-09 20:50:36 +02:00
#include "Core/HW/Memmap.h"
2015-10-09 20:50:36 +02:00
#include "VideoBackends/Software/EfbCopy.h"
#include "VideoBackends/Software/EfbInterface.h"
2021-11-09 18:38:24 -08:00
#include "VideoBackends/Software/Rasterizer.h"
2021-06-09 07:42:21 -04:00
#include "VideoBackends/Software/SWBoundingBox.h"
2015-09-26 10:07:48 +02:00
#include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/AbstractPipeline.h"
#include "VideoCommon/AbstractShader.h"
#include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/PixelEngine.h"
2017-01-23 11:20:20 -05:00
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoCommon.h"
namespace SW
{
2018-10-03 23:03:26 +10:00
SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window)
2021-05-22 19:58:27 -07:00
: ::Renderer(static_cast<int>(std::max(window->GetContext()->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(window->GetContext()->GetBackBufferHeight(), 1u)), 1.0f,
AbstractTextureFormat::RGBA8),
2018-10-03 23:03:26 +10:00
m_window(std::move(window))
{
}
bool SWRenderer::IsHeadless() const
{
2018-10-03 23:03:26 +10:00
return m_window->IsHeadless();
}
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWTexture>(config);
}
std::unique_ptr<AbstractStagingTexture>
SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
{
return std::make_unique<SWStagingTexture>(type, config);
}
std::unique_ptr<AbstractFramebuffer>
SWRenderer::CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment)
{
return SWFramebuffer::Create(static_cast<SWTexture*>(color_attachment),
static_cast<SWTexture*>(depth_attachment));
}
2021-05-22 19:58:27 -07:00
void SWRenderer::BindBackbuffer(const ClearColor& clear_color)
{
// Look for framebuffer resizes
if (!m_surface_resized.TestAndClear())
return;
GLContext* context = m_window->GetContext();
context->Update();
m_backbuffer_width = context->GetBackBufferWidth();
m_backbuffer_height = context->GetBackBufferHeight();
}
class SWShader final : public AbstractShader
{
public:
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
~SWShader() = default;
BinaryData GetBinary() const override { return {}; }
};
std::unique_ptr<AbstractShader>
SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWShader>(stage);
}
std::unique_ptr<AbstractShader>
SWRenderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWShader>(stage);
}
class SWPipeline final : public AbstractPipeline
{
public:
2019-03-02 19:42:25 +01:00
SWPipeline() = default;
~SWPipeline() override = default;
};
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data,
size_t cache_data_length)
{
return std::make_unique<SWPipeline>();
}
2013-08-20 23:51:39 +12:00
// Called on the GPU thread
void SWRenderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc)
2013-08-20 23:51:39 +12:00
{
2017-11-23 16:53:44 +10:00
if (!IsHeadless())
m_window->ShowImage(source_texture, source_rc);
2015-10-09 20:50:36 +02:00
}
u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
{
u32 value = 0;
switch (type)
{
case EFBAccessType::PeekZ:
2015-10-09 20:50:36 +02:00
{
value = EfbInterface::GetDepth(x, y);
break;
}
case EFBAccessType::PeekColor:
2015-10-09 20:50:36 +02:00
{
const u32 color = EfbInterface::GetColor(x, y);
2015-10-09 20:50:36 +02:00
// rgba to argb
value = (color >> 8) | (color & 0xff) << 24;
// check what to do with the alpha channel (GX_PokeAlphaRead)
PixelEngine::AlphaReadMode alpha_read_mode = PixelEngine::GetAlphaReadMode();
if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadNone)
{
// value is OK as it is
}
else if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadFF)
{
value |= 0xFF000000;
}
else
{
if (alpha_read_mode != PixelEngine::AlphaReadMode::Read00)
{
PanicAlertFmt("Invalid PE alpha read mode: {}", static_cast<u16>(alpha_read_mode));
}
value &= 0x00FFFFFF;
}
2015-10-09 20:50:36 +02:00
break;
}
default:
break;
}
return value;
}
2021-06-09 07:42:21 -04:00
std::unique_ptr<BoundingBox> SWRenderer::CreateBoundingBox() const
2015-10-09 20:50:36 +02:00
{
2021-06-09 07:42:21 -04:00
return std::make_unique<SWBoundingBox>();
2015-10-09 20:50:36 +02:00
}
void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
2015-10-09 20:50:36 +02:00
bool zEnable, u32 color, u32 z)
{
EfbCopy::ClearEfb();
}
std::unique_ptr<NativeVertexFormat>
SWRenderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{
return std::make_unique<NativeVertexFormat>(vtx_decl);
}
2021-11-09 18:38:24 -08:00
void SWRenderer::SetScissorRect(const MathUtil::Rectangle<int>& rc)
{
// BPFunctions calls SetScissorRect with the "best" scissor rect whenever the viewport or scissor
// changes. However, the software renderer is actually able to use multiple scissor rects (which
// is necessary in a few renderering edge cases, such as with Major Minor's Majestic March).
// Thus, we use this as a signal to update the list of scissor rects, but ignore the parameter.
Rasterizer::ScissorChanged();
}
} // namespace SW