mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
VideoCommon: Abstract bounding box
This moves much of the duplicated bounding box code into VideoCommon, leaving only the specific buffer implementations in each backend.
This commit is contained in:
@ -14,6 +14,8 @@ add_library(videosoftware
|
||||
SetupUnit.cpp
|
||||
SetupUnit.h
|
||||
SWmain.cpp
|
||||
SWBoundingBox.cpp
|
||||
SWBoundingBox.h
|
||||
SWOGLWindow.cpp
|
||||
SWOGLWindow.h
|
||||
SWRenderer.cpp
|
||||
|
66
Source/Core/VideoBackends/Software/SWBoundingBox.cpp
Normal file
66
Source/Core/VideoBackends/Software/SWBoundingBox.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "VideoBackends/Software/SWBoundingBox.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace BBoxManager
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// Current bounding box coordinates.
|
||||
std::array<u16, 4> s_coordinates{};
|
||||
} // Anonymous namespace
|
||||
|
||||
u16 GetCoordinate(Coordinate coordinate)
|
||||
{
|
||||
return s_coordinates[static_cast<u32>(coordinate)];
|
||||
}
|
||||
|
||||
void SetCoordinate(Coordinate coordinate, u16 value)
|
||||
{
|
||||
s_coordinates[static_cast<u32>(coordinate)] = value;
|
||||
}
|
||||
|
||||
void Update(u16 left, u16 right, u16 top, u16 bottom)
|
||||
{
|
||||
const u16 new_left = std::min(left, GetCoordinate(Coordinate::Left));
|
||||
const u16 new_right = std::max(right, GetCoordinate(Coordinate::Right));
|
||||
const u16 new_top = std::min(top, GetCoordinate(Coordinate::Top));
|
||||
const u16 new_bottom = std::max(bottom, GetCoordinate(Coordinate::Bottom));
|
||||
|
||||
SetCoordinate(Coordinate::Left, new_left);
|
||||
SetCoordinate(Coordinate::Right, new_right);
|
||||
SetCoordinate(Coordinate::Top, new_top);
|
||||
SetCoordinate(Coordinate::Bottom, new_bottom);
|
||||
}
|
||||
|
||||
} // namespace BBoxManager
|
||||
|
||||
namespace SW
|
||||
{
|
||||
std::vector<BBoxType> SWBoundingBox::Read(u32 index, u32 length)
|
||||
{
|
||||
std::vector<BBoxType> values(length);
|
||||
|
||||
for (u32 i = 0; i < length; i++)
|
||||
{
|
||||
values[i] = BBoxManager::GetCoordinate(static_cast<BBoxManager::Coordinate>(index + i));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
void SWBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
|
||||
{
|
||||
for (size_t i = 0; i < values.size(); i++)
|
||||
{
|
||||
BBoxManager::SetCoordinate(static_cast<BBoxManager::Coordinate>(index + i), values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SW
|
43
Source/Core/VideoBackends/Software/SWBoundingBox.h
Normal file
43
Source/Core/VideoBackends/Software/SWBoundingBox.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
#include "VideoCommon/BoundingBox.h"
|
||||
|
||||
namespace BBoxManager
|
||||
{
|
||||
// Indicates a coordinate of the bounding box.
|
||||
enum class Coordinate
|
||||
{
|
||||
Left, // The X coordinate of the left side of the bounding box.
|
||||
Right, // The X coordinate of the right side of the bounding box.
|
||||
Top, // The Y coordinate of the top of the bounding box.
|
||||
Bottom, // The Y coordinate of the bottom of the bounding box.
|
||||
};
|
||||
|
||||
// Gets a particular coordinate for the bounding box.
|
||||
u16 GetCoordinate(Coordinate coordinate);
|
||||
|
||||
// Sets a particular coordinate for the bounding box.
|
||||
void SetCoordinate(Coordinate coordinate, u16 value);
|
||||
|
||||
// Updates all bounding box coordinates.
|
||||
void Update(u16 left, u16 right, u16 top, u16 bottom);
|
||||
} // namespace BBoxManager
|
||||
|
||||
namespace SW
|
||||
{
|
||||
class SWBoundingBox final : public BoundingBox
|
||||
{
|
||||
public:
|
||||
bool Initialize() override { return true; }
|
||||
|
||||
protected:
|
||||
std::vector<BBoxType> Read(u32 index, u32 length) override;
|
||||
void Write(u32 index, const std::vector<BBoxType>& values) override;
|
||||
};
|
||||
|
||||
} // namespace SW
|
@ -12,13 +12,13 @@
|
||||
|
||||
#include "VideoBackends/Software/EfbCopy.h"
|
||||
#include "VideoBackends/Software/EfbInterface.h"
|
||||
#include "VideoBackends/Software/SWBoundingBox.h"
|
||||
#include "VideoBackends/Software/SWOGLWindow.h"
|
||||
#include "VideoBackends/Software/SWTexture.h"
|
||||
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
#include "VideoCommon/AbstractTexture.h"
|
||||
#include "VideoCommon/BoundingBox.h"
|
||||
#include "VideoCommon/NativeVertexFormat.h"
|
||||
#include "VideoCommon/VideoBackendBase.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
@ -141,14 +141,9 @@ u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
||||
return value;
|
||||
}
|
||||
|
||||
u16 SWRenderer::BBoxReadImpl(int index)
|
||||
std::unique_ptr<BoundingBox> SWRenderer::CreateBoundingBox() const
|
||||
{
|
||||
return BoundingBox::GetCoordinate(static_cast<BoundingBox::Coordinate>(index));
|
||||
}
|
||||
|
||||
void SWRenderer::BBoxWriteImpl(int index, u16 value)
|
||||
{
|
||||
BoundingBox::SetCoordinate(static_cast<BoundingBox::Coordinate>(index), value);
|
||||
return std::make_unique<SWBoundingBox>();
|
||||
}
|
||||
|
||||
void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
|
||||
class BoundingBox;
|
||||
class SWOGLWindow;
|
||||
|
||||
namespace SW
|
||||
@ -43,8 +44,6 @@ public:
|
||||
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
|
||||
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
|
||||
u16 BBoxReadImpl(int index) override;
|
||||
void BBoxWriteImpl(int index, u16 value) override;
|
||||
|
||||
void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
|
||||
const AbstractTexture* source_texture,
|
||||
@ -59,6 +58,9 @@ public:
|
||||
const AbstractTexture* src_texture,
|
||||
const MathUtil::Rectangle<int>& src_rect) override;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<BoundingBox> CreateBoundingBox() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SWOGLWindow> m_window;
|
||||
};
|
||||
|
@ -53,6 +53,10 @@ void SWVertexLoader::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_
|
||||
break;
|
||||
}
|
||||
|
||||
// Flush bounding box here because software overrides the base function
|
||||
if (g_renderer->IsBBoxEnabled())
|
||||
g_renderer->BBoxFlush();
|
||||
|
||||
m_setup_unit.Init(primitiveType);
|
||||
|
||||
// set all states with are stored within video sw
|
||||
|
@ -83,6 +83,7 @@ void VideoSoftware::InitBackendInfo()
|
||||
g_Config.backend_info.bSupportsLogicOp = true;
|
||||
g_Config.backend_info.bSupportsShaderBinaries = false;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
||||
g_Config.backend_info.bSupportsBBox = true;
|
||||
|
||||
// aamodes
|
||||
g_Config.backend_info.AAModes = {1};
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/Software/DebugUtil.h"
|
||||
#include "VideoBackends/Software/EfbInterface.h"
|
||||
#include "VideoBackends/Software/SWBoundingBox.h"
|
||||
#include "VideoBackends/Software/TextureSampler.h"
|
||||
|
||||
#include "VideoCommon/BoundingBox.h"
|
||||
#include "VideoCommon/PerfQueryBase.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
@ -839,7 +839,7 @@ void Tev::Draw()
|
||||
|
||||
// The GC/Wii GPU rasterizes in 2x2 pixel groups, so bounding box values will be rounded to the
|
||||
// extents of these groups, rather than the exact pixel.
|
||||
BoundingBox::Update(static_cast<u16>(Position[0] & ~1), static_cast<u16>(Position[0] | 1),
|
||||
BBoxManager::Update(static_cast<u16>(Position[0] & ~1), static_cast<u16>(Position[0] | 1),
|
||||
static_cast<u16>(Position[1] & ~1), static_cast<u16>(Position[1] | 1));
|
||||
|
||||
#if ALLOW_TEV_DUMPS
|
||||
|
Reference in New Issue
Block a user