Make the initial 3D renderer configurable via NDSArgs (#1913)

* Allow 3D renderers to be created without passing `GPU` to the constructor

* Make the initial 3D renderer configurable via `NDSArgs`

* Fix a compiler error
This commit is contained in:
Jesse Talavera
2023-12-15 08:53:31 -05:00
committed by GitHub
parent 6f47c9ed4c
commit c867a7f1c0
12 changed files with 259 additions and 246 deletions

View File

@ -29,19 +29,19 @@ namespace melonDS
class SoftRenderer : public Renderer3D
{
public:
SoftRenderer(melonDS::GPU& gpu, bool threaded = false) noexcept;
SoftRenderer(bool threaded = false) noexcept;
~SoftRenderer() override;
void Reset() override;
void Reset(GPU& gpu) override;
void SetThreaded(bool threaded) noexcept;
void SetThreaded(bool threaded, GPU& gpu) noexcept;
[[nodiscard]] bool IsThreaded() const noexcept { return Threaded; }
void VCount144() override;
void RenderFrame() override;
void RestartFrame() override;
void VCount144(GPU& gpu) override;
void RenderFrame(GPU& gpu) override;
void RestartFrame(GPU& gpu) override;
u32* GetLine(int line) override;
void SetupRenderThread();
void SetupRenderThread(GPU& gpu);
void StopRenderThread();
private:
// Notes on the interpolator:
@ -429,16 +429,16 @@ private:
};
template <typename T>
inline T ReadVRAM_Texture(u32 addr) const
inline T ReadVRAM_Texture(u32 addr, const GPU& gpu) const
{
return *(T*)&GPU.VRAMFlat_Texture[addr & 0x7FFFF];
return *(T*)&gpu.VRAMFlat_Texture[addr & 0x7FFFF];
}
template <typename T>
inline T ReadVRAM_TexPal(u32 addr) const
inline T ReadVRAM_TexPal(u32 addr, const GPU& gpu) const
{
return *(T*)&GPU.VRAMFlat_TexPal[addr & 0x1FFFF];
return *(T*)&gpu.VRAMFlat_TexPal[addr & 0x1FFFF];
}
u32 AlphaBlend(u32 srccolor, u32 dstcolor, u32 alpha) const noexcept;
u32 AlphaBlend(const GPU3D& gpu3d, u32 srccolor, u32 dstcolor, u32 alpha) const noexcept;
struct RendererPolygon
{
@ -452,23 +452,22 @@ private:
};
melonDS::GPU& GPU;
RendererPolygon PolygonList[2048];
void TextureLookup(u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha) const;
u32 RenderPixel(const Polygon* polygon, u8 vr, u8 vg, u8 vb, s16 s, s16 t) const;
void PlotTranslucentPixel(u32 pixeladdr, u32 color, u32 z, u32 polyattr, u32 shadow);
void TextureLookup(const GPU& gpu, u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha) const;
u32 RenderPixel(const GPU& gpu, const Polygon* polygon, u8 vr, u8 vg, u8 vb, s16 s, s16 t) const;
void PlotTranslucentPixel(const GPU3D& gpu3d, u32 pixeladdr, u32 color, u32 z, u32 polyattr, u32 shadow);
void SetupPolygonLeftEdge(RendererPolygon* rp, s32 y) const;
void SetupPolygonRightEdge(RendererPolygon* rp, s32 y) const;
void SetupPolygon(RendererPolygon* rp, Polygon* polygon) const;
void RenderShadowMaskScanline(RendererPolygon* rp, s32 y);
void RenderPolygonScanline(RendererPolygon* rp, s32 y);
void RenderScanline(s32 y, int npolys);
u32 CalculateFogDensity(u32 pixeladdr) const;
void ScanlineFinalPass(s32 y);
void ClearBuffers();
void RenderPolygons(bool threaded, Polygon** polygons, int npolys);
void RenderShadowMaskScanline(const GPU3D& gpu3d, RendererPolygon* rp, s32 y);
void RenderPolygonScanline(const GPU& gpu, RendererPolygon* rp, s32 y);
void RenderScanline(const GPU& gpu, s32 y, int npolys);
u32 CalculateFogDensity(const GPU3D& gpu3d, u32 pixeladdr) const;
void ScanlineFinalPass(const GPU3D& gpu3d, s32 y);
void ClearBuffers(const GPU& gpu);
void RenderPolygons(const GPU& gpu, bool threaded, Polygon** polygons, int npolys);
void RenderThreadFunc();
void RenderThreadFunc(GPU& gpu);
// buffer dimensions are 258x194 to add a offscreen 1px border
// which simplifies edge marking tests