diff options
author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-11-29 09:23:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 15:23:11 +0100 |
commit | 7caddf9615875e54b725bd7df266361c46d47b6f (patch) | |
tree | 966698578db1f764715ff4ee5e8ee4c787cbeb10 /src/GPU2D_Soft.cpp | |
parent | e973236203292637eb7bd009a4cfbd6fd785181f (diff) |
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`
Diffstat (limited to 'src/GPU2D_Soft.cpp')
-rw-r--r-- | src/GPU2D_Soft.cpp | 71 |
1 files changed, 5 insertions, 66 deletions
diff --git a/src/GPU2D_Soft.cpp b/src/GPU2D_Soft.cpp index 9e7d849..6d0252c 100644 --- a/src/GPU2D_Soft.cpp +++ b/src/GPU2D_Soft.cpp @@ -27,68 +27,7 @@ namespace GPU2D SoftRenderer::SoftRenderer(melonDS::GPU& gpu) : Renderer2D(), GPU(gpu) { - // initialize mosaic table - for (int m = 0; m < 16; m++) - { - for (int x = 0; x < 256; x++) - { - int offset = x % (m+1); - MosaicTable[m][x] = offset; - } - } -} - -u32 SoftRenderer::ColorBlend4(u32 val1, u32 val2, u32 eva, u32 evb) -{ - u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb) + 0x000008) >> 4; - u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb) + 0x000800) >> 4) & 0x007F00; - u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb) + 0x080000) >> 4) & 0x7F0000; - - if (r > 0x00003F) r = 0x00003F; - if (g > 0x003F00) g = 0x003F00; - if (b > 0x3F0000) b = 0x3F0000; - - return r | g | b | 0xFF000000; -} - -u32 SoftRenderer::ColorBlend5(u32 val1, u32 val2) -{ - u32 eva = ((val1 >> 24) & 0x1F) + 1; - u32 evb = 32 - eva; - - if (eva == 32) return val1; - - u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb) + 0x000010) >> 5; - u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb) + 0x001000) >> 5) & 0x007F00; - u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb) + 0x100000) >> 5) & 0x7F0000; - - if (r > 0x00003F) r = 0x00003F; - if (g > 0x003F00) g = 0x003F00; - if (b > 0x3F0000) b = 0x3F0000; - - return r | g | b | 0xFF000000; -} - -u32 SoftRenderer::ColorBrightnessUp(u32 val, u32 factor, u32 bias) -{ - u32 rb = val & 0x3F003F; - u32 g = val & 0x003F00; - - rb += (((((0x3F003F - rb) * factor) + (bias*0x010001)) >> 4) & 0x3F003F); - g += (((((0x003F00 - g ) * factor) + (bias*0x000100)) >> 4) & 0x003F00); - - return rb | g | 0xFF000000; -} - -u32 SoftRenderer::ColorBrightnessDown(u32 val, u32 factor, u32 bias) -{ - u32 rb = val & 0x3F003F; - u32 g = val & 0x003F00; - - rb -= ((((rb * factor) + (bias*0x010001)) >> 4) & 0x3F003F); - g -= ((((g * factor) + (bias*0x000100)) >> 4) & 0x003F00); - - return rb | g | 0xFF000000; + // mosaic table is initialized at compile-time } u32 SoftRenderer::ColorComposite(int i, u32 val1, u32 val2) @@ -365,11 +304,11 @@ void SoftRenderer::DrawScanline(u32 line, Unit* unit) void SoftRenderer::VBlankEnd(Unit* unitA, Unit* unitB) { #ifdef OGLRENDERER_ENABLED - if (GPU.GPU3D.IsRendererAccelerated()) + if (Renderer3D& renderer3d = GPU.GPU3D.GetCurrentRenderer(); renderer3d.Accelerated) { if ((unitA->CaptureCnt & (1<<31)) && (((unitA->CaptureCnt >> 29) & 0x3) != 1)) { - reinterpret_cast<GLRenderer*>(GPU.GPU3D.GetCurrentRenderer())->PrepareCaptureFrame(); + renderer3d.PrepareCaptureFrame(); } } #endif @@ -779,7 +718,7 @@ void SoftRenderer::DrawScanline_BGOBJ(u32 line) memset(WindowMask, 0xFF, 256); ApplySpriteMosaicX(); - CurBGXMosaicTable = MosaicTable[CurUnit->BGMosaicSize[0]]; + CurBGXMosaicTable = MosaicTable[CurUnit->BGMosaicSize[0]].data(); switch (CurUnit->DispCnt & 0x7) { @@ -1564,7 +1503,7 @@ void SoftRenderer::ApplySpriteMosaicX() u32* objLine = OBJLine[CurUnit->Num]; - u8* curOBJXMosaicTable = MosaicTable[CurUnit->OBJMosaicSize[1]]; + u8* curOBJXMosaicTable = MosaicTable[CurUnit->OBJMosaicSize[1]].data(); u32 lastcolor = objLine[0]; |