mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 07:10:00 -06:00
Clean up the 3D renderer for enhanced flexibility (#1895)
* Give `GPU2D::Unit` a virtual destructor - Undefined behavior avoided! * Add an `array2d` alias * Move various parts of `GPU2D::SoftRenderer` to `constexpr` - `SoftRenderer::MosaicTable` is now initialized at compile-time - Most of the `SoftRenderer::Color*` functions are now `constexpr` - The aforementioned functions are used with a constant value in at least one place, so they'll be at least partially computed at compile-time * Generalize `GLRenderer::PrepareCaptureFrame` - Declare it in the base `Renderer3D` class, but make it empty * Remove unneeded `virtual` specifiers * Store `Framebuffer`'s memory in `unique_ptr`s - Reduce the risk of leaks this way * Clean up how `GLCompositor` is initialized - Return it as an `std::optional` instead of a `std::unique_ptr` - Make `GLCompositor` movable - Replace `GLCompositor`'s plain arrays with `std::array` to simplify moving * Pass `GPU` to `GLCompositor`'s important functions instead of passing it to the constructor * Move `GLCompositor` to be a field within `GLRenderer` - Some methods were moved up and made `virtual` * Fix some linker errors * Set the renderer in the frontend * Remove unneeded `virtual` specifiers * Remove `RenderSettings` in favor of just exposing the relevant member variables * Update the frontend to accommodate the core changes * Add `constexpr` and `const` to places in the interpolator * Qualify references to `size_t` * Construct the `optional` directly instead of using `make_optional` - It makes the Linux build choke - I think it's because `GLCompositor`'s constructor is `private`
This commit is contained in:

committed by
GitHub

parent
e973236203
commit
7caddf9615
36
src/GPU.h
36
src/GPU.h
@ -25,10 +25,6 @@
|
||||
#include "GPU3D.h"
|
||||
#include "NonStupidBitfield.h"
|
||||
|
||||
#ifdef OGLRENDERER_ENABLED
|
||||
#include "GPU_OpenGL.h"
|
||||
#endif
|
||||
|
||||
namespace melonDS
|
||||
{
|
||||
class GPU3D;
|
||||
@ -56,33 +52,30 @@ struct VRAMTrackingSet
|
||||
NonStupidBitField<Size/VRAMDirtyGranularity> DeriveState(u32* currentMappings, GPU& gpu);
|
||||
};
|
||||
|
||||
struct RenderSettings
|
||||
{
|
||||
bool Soft_Threaded;
|
||||
|
||||
int GL_ScaleFactor;
|
||||
bool GL_BetterPolygons;
|
||||
};
|
||||
|
||||
class GPU
|
||||
{
|
||||
public:
|
||||
GPU(melonDS::NDS& nds) noexcept;
|
||||
explicit GPU(melonDS::NDS& nds, std::unique_ptr<Renderer3D>&& renderer3d = nullptr, std::unique_ptr<GPU2D::Renderer2D>&& renderer2d = nullptr) noexcept;
|
||||
~GPU() noexcept;
|
||||
void Reset() noexcept;
|
||||
void Stop() noexcept;
|
||||
|
||||
void DoSavestate(Savestate* file) noexcept;
|
||||
|
||||
[[deprecated("Set the renderer directly instead of using an integer code")]] void InitRenderer(int renderer) noexcept;
|
||||
void DeInitRenderer() noexcept;
|
||||
void ResetRenderer() noexcept;
|
||||
|
||||
void SetRenderSettings(int renderer, RenderSettings& settings) noexcept;
|
||||
/// Sets the active renderer to the renderer given in the provided pointer.
|
||||
/// The pointer is moved-from, so it will be \c nullptr after this method is called.
|
||||
/// If the pointer is \c nullptr, the renderer is reset to the default renderer.
|
||||
void SetRenderer3D(std::unique_ptr<Renderer3D>&& renderer) noexcept;
|
||||
[[nodiscard]] const Renderer3D& GetRenderer3D() const noexcept { return GPU3D.GetCurrentRenderer(); }
|
||||
[[nodiscard]] Renderer3D& GetRenderer3D() noexcept { return GPU3D.GetCurrentRenderer(); }
|
||||
|
||||
u8* GetUniqueBankPtr(u32 mask, u32 offset) noexcept;
|
||||
const u8* GetUniqueBankPtr(u32 mask, u32 offset) const noexcept;
|
||||
|
||||
void SetRenderer2D(std::unique_ptr<GPU2D::Renderer2D>&& renderer) noexcept { GPU2D_Renderer = std::move(renderer); }
|
||||
[[nodiscard]] const GPU2D::Renderer2D& GetRenderer2D() const noexcept { return *GPU2D_Renderer; }
|
||||
[[nodiscard]] GPU2D::Renderer2D& GetRenderer2D() noexcept { return *GPU2D_Renderer; }
|
||||
|
||||
void MapVRAM_AB(u32 bank, u8 cnt) noexcept;
|
||||
void MapVRAM_CD(u32 bank, u8 cnt) noexcept;
|
||||
void MapVRAM_E(u32 bank, u8 cnt) noexcept;
|
||||
@ -578,7 +571,7 @@ public:
|
||||
u8* VRAMPtr_BOBJ[0x8] {};
|
||||
|
||||
int FrontBuffer = 0;
|
||||
u32* Framebuffer[2][2] {};
|
||||
std::unique_ptr<u32[]> Framebuffer[2][2] {};
|
||||
|
||||
GPU2D::Unit GPU2D_A;
|
||||
GPU2D::Unit GPU2D_B;
|
||||
@ -611,11 +604,6 @@ public:
|
||||
|
||||
u8 VRAMFlat_Texture[512*1024] {};
|
||||
u8 VRAMFlat_TexPal[128*1024] {};
|
||||
|
||||
int Renderer = 0;
|
||||
#ifdef OGLRENDERER_ENABLED
|
||||
std::unique_ptr<GLCompositor> CurGLCompositor = nullptr;
|
||||
#endif
|
||||
private:
|
||||
void ResetVRAMCache() noexcept;
|
||||
void AssignFramebuffers() noexcept;
|
||||
|
Reference in New Issue
Block a user