2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2017-01-23 09:20:20 -07:00
|
|
|
#include "VideoBackends/Software/SWRenderer.h"
|
|
|
|
|
2014-06-02 23:08:54 -06:00
|
|
|
#include <string>
|
2014-05-02 20:47:04 -06:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
2017-05-18 06:59:38 -06:00
|
|
|
#include "Core/Config/GraphicsSettings.h"
|
2015-10-09 12:50:36 -06:00
|
|
|
#include "Core/HW/Memmap.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
2015-10-09 12:50:36 -06:00
|
|
|
#include "VideoBackends/Software/EfbCopy.h"
|
2017-11-18 22:16:22 -07:00
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
2015-09-26 02:07:48 -06:00
|
|
|
#include "VideoBackends/Software/SWOGLWindow.h"
|
2017-09-30 00:25:36 -06:00
|
|
|
#include "VideoBackends/Software/SWTexture.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
#include "VideoCommon/AbstractPipeline.h"
|
|
|
|
#include "VideoCommon/AbstractShader.h"
|
2015-10-09 12:50:36 -06:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2017-01-23 09:20:20 -07:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2015-10-09 12:50:36 -06:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2013-04-12 23:48:53 -06:00
|
|
|
|
2017-03-03 23:40:08 -07:00
|
|
|
SWRenderer::SWRenderer()
|
|
|
|
: ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-30 00:25:36 -06:00
|
|
|
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config)
|
|
|
|
{
|
|
|
|
return std::make_unique<SW::SWTexture>(config);
|
|
|
|
}
|
|
|
|
|
2017-10-21 08:49:40 -06:00
|
|
|
std::unique_ptr<AbstractStagingTexture>
|
|
|
|
SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
|
|
|
|
{
|
|
|
|
return std::make_unique<SW::SWStagingTexture>(type, config);
|
|
|
|
}
|
|
|
|
|
2018-01-21 03:22:45 -07:00
|
|
|
std::unique_ptr<AbstractFramebuffer>
|
|
|
|
SWRenderer::CreateFramebuffer(const AbstractTexture* color_attachment,
|
|
|
|
const AbstractTexture* depth_attachment)
|
|
|
|
{
|
|
|
|
return SW::SWFramebuffer::Create(static_cast<const SW::SWTexture*>(color_attachment),
|
|
|
|
static_cast<const SW::SWTexture*>(depth_attachment));
|
|
|
|
}
|
|
|
|
|
2015-10-09 12:50:36 -06:00
|
|
|
void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 color)
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
SWOGLWindow::s_instance->PrintText(pstr, left, top, color);
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
class SWShader final : public AbstractShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
|
|
|
|
~SWShader() = default;
|
|
|
|
|
|
|
|
bool HasBinary() const override { return false; }
|
|
|
|
BinaryData GetBinary() const override { return {}; }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<AbstractShader>
|
|
|
|
SWRenderer::CreateShaderFromSource(ShaderStage stage, const char* source, size_t length)
|
|
|
|
{
|
|
|
|
return std::make_unique<SWShader>(stage);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<AbstractShader> SWRenderer::CreateShaderFromBinary(ShaderStage stage,
|
|
|
|
const void* data, size_t length)
|
|
|
|
{
|
|
|
|
return std::make_unique<SWShader>(stage);
|
|
|
|
}
|
|
|
|
|
|
|
|
class SWPipeline final : public AbstractPipeline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SWPipeline() : AbstractPipeline() {}
|
|
|
|
~SWPipeline() override = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config)
|
|
|
|
{
|
|
|
|
return std::make_unique<SWPipeline>();
|
|
|
|
}
|
|
|
|
|
2013-08-20 05:51:39 -06:00
|
|
|
// Called on the GPU thread
|
2017-10-01 10:19:29 -06:00
|
|
|
void SWRenderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region, u64 ticks,
|
|
|
|
float Gamma)
|
2013-08-20 05:51:39 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
OSD::DoCallbacks(OSD::CallbackType::OnFrame);
|
|
|
|
|
2017-11-22 23:53:44 -07:00
|
|
|
if (!IsHeadless())
|
|
|
|
{
|
|
|
|
DrawDebugText();
|
|
|
|
SWOGLWindow::s_instance->ShowImage(texture, xfb_region);
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
UpdateActiveConfig();
|
2015-10-09 12:50:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
u32 value = 0;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2017-01-23 00:51:46 -07:00
|
|
|
case EFBAccessType::PeekZ:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
value = EfbInterface::GetDepth(x, y);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 00:51:46 -07:00
|
|
|
case EFBAccessType::PeekColor:
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-09-21 16:53:13 -06:00
|
|
|
const u32 color = EfbInterface::GetColor(x, y);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// rgba to argb
|
|
|
|
value = (color >> 8) | (color & 0xff) << 24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2015-10-09 12:50:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 SWRenderer::BBoxRead(int index)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return BoundingBox::coords[index];
|
2015-10-09 12:50:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SWRenderer::BBoxWrite(int index, u16 value)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
BoundingBox::coords[index] = value;
|
2015-10-09 12:50:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetRectangle SWRenderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
TargetRectangle result;
|
|
|
|
result.left = rc.left;
|
|
|
|
result.top = rc.top;
|
|
|
|
result.right = rc.right;
|
|
|
|
result.bottom = rc.bottom;
|
|
|
|
return result;
|
2015-10-09 12:50:36 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SWRenderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable,
|
|
|
|
bool zEnable, u32 color, u32 z)
|
2015-10-09 12:50:36 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
EfbCopy::ClearEfb();
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|