mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -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
@ -21,51 +21,51 @@
|
||||
#include "OpenGLSupport.h"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace melonDS
|
||||
{
|
||||
class GPU;
|
||||
struct RenderSettings;
|
||||
|
||||
class GLRenderer;
|
||||
class GLCompositor
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<GLCompositor> New(melonDS::GPU& gpu) noexcept;
|
||||
static std::optional<GLCompositor> New() noexcept;
|
||||
GLCompositor(const GLCompositor&) = delete;
|
||||
GLCompositor& operator=(const GLCompositor&) = delete;
|
||||
GLCompositor(GLCompositor&&) noexcept;
|
||||
GLCompositor& operator=(GLCompositor&&) noexcept;
|
||||
~GLCompositor();
|
||||
|
||||
void Reset();
|
||||
void SetScaleFactor(int scale) noexcept;
|
||||
[[nodiscard]] int GetScaleFactor() const noexcept { return Scale; }
|
||||
|
||||
void SetRenderSettings(const RenderSettings& settings) noexcept;
|
||||
|
||||
void Stop();
|
||||
void RenderFrame();
|
||||
void Stop(const GPU& gpu) noexcept;
|
||||
void RenderFrame(const GPU& gpu, GLRenderer& renderer) noexcept;
|
||||
void BindOutputTexture(int buf);
|
||||
private:
|
||||
GLCompositor(std::array<GLuint, 3> CompShader, melonDS::GPU& gpu) noexcept;
|
||||
melonDS::GPU& GPU;
|
||||
int Scale;
|
||||
int ScreenH, ScreenW;
|
||||
GLCompositor(std::array<GLuint, 3> CompShader) noexcept;
|
||||
int Scale = 0;
|
||||
int ScreenH = 0, ScreenW = 0;
|
||||
|
||||
std::array<GLuint, 3> CompShader;
|
||||
GLuint CompScaleLoc;
|
||||
GLuint Comp3DXPosLoc;
|
||||
std::array<GLuint, 3> CompShader {};
|
||||
GLuint CompScaleLoc = 0;
|
||||
GLuint Comp3DXPosLoc = 0;
|
||||
|
||||
GLuint CompVertexBufferID;
|
||||
GLuint CompVertexArrayID;
|
||||
GLuint CompVertexBufferID = 0;
|
||||
GLuint CompVertexArrayID = 0;
|
||||
|
||||
struct CompVertex
|
||||
{
|
||||
float Position[2];
|
||||
float Texcoord[2];
|
||||
std::array<float, 2> Position {};
|
||||
std::array<float, 2> Texcoord {};
|
||||
};
|
||||
CompVertex CompVertices[2 * 3*2];
|
||||
std::array<CompVertex, 2*3*2> CompVertices {};
|
||||
|
||||
GLuint CompScreenInputTex;
|
||||
GLuint CompScreenOutputTex[2];
|
||||
GLuint CompScreenOutputFB[2];
|
||||
GLuint CompScreenInputTex = 0;
|
||||
std::array<GLuint, 2> CompScreenOutputTex {};
|
||||
std::array<GLuint, 2> CompScreenOutputFB {};
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user