diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index e2b22263..9873efc9 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -569,20 +569,7 @@ void GPU3D::DoSavestate(Savestate* file) noexcept } // save any renderer state that can persist through frames - if (softRenderer) - { - file->VarArray(softRenderer->StencilBuffer, sizeof(SoftRenderer::StencilBuffer)); - file->VarArray(softRenderer->ShadowRendered, sizeof(SoftRenderer::ShadowRendered)); - file->VarArray(softRenderer->ShadowRenderedi, sizeof(SoftRenderer::ShadowRenderedi)); - } - else - { - u8 ph[256*2] {}; - // placeholders for renderers that don't support the same variables - file->VarArray(ph, sizeof(SoftRenderer::StencilBuffer)); - file->VarArray(ph, sizeof(SoftRenderer::ShadowRendered)); - file->VarArray(ph, sizeof(SoftRenderer::ShadowRenderedi)); - } + CurrentRenderer->DoSavestate(file); if (softRenderer && softRenderer->IsThreaded()) { diff --git a/src/GPU3D.h b/src/GPU3D.h index 4a7cc5e0..1a8edbc0 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -346,6 +346,7 @@ public: Renderer3D& operator=(const Renderer3D&) = delete; virtual void Reset(GPU& gpu) = 0; + virtual void DoSavestate(Savestate* file) = 0; // This "Accelerated" flag currently communicates if the framebuffer should // be allocated differently and other little misc handlers. Ideally there diff --git a/src/GPU3D_Compute.cpp b/src/GPU3D_Compute.cpp index 346a6a53..a170e947 100644 --- a/src/GPU3D_Compute.cpp +++ b/src/GPU3D_Compute.cpp @@ -295,6 +295,23 @@ void ComputeRenderer::Reset(GPU& gpu) Texcache.Reset(); } +void ComputeRenderer::DoSavestate(Savestate* file) +{ + // placeholder in case we need to add anything serializable later on + /* + bool secfound = file->Section("CR3D", true); + + if (secfound) + { + + } + else + { + + } + */ +} + void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinates) { CurGLCompositor.SetScaleFactor(scale); diff --git a/src/GPU3D_Compute.h b/src/GPU3D_Compute.h index 751737b7..177fea9e 100644 --- a/src/GPU3D_Compute.h +++ b/src/GPU3D_Compute.h @@ -42,6 +42,7 @@ public: ~ComputeRenderer() override; void Reset(GPU& gpu) override; + void DoSavestate(Savestate* file) override; void SetRenderSettings(int scale, bool highResolutionCoordinates); diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 3f85db8c..8770d495 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -317,6 +317,23 @@ void GLRenderer::Reset(GPU& gpu) // except there's no such method right now. } +void GLRenderer::DoSavestate(Savestate* file) +{ + // placeholder in case we need to add anything serializable later on + /* + bool secfound = file->Section("GL3D", true); + + if (secfound) + { + + } + else + { + + } + */ +} + void GLRenderer::SetBetterPolygons(bool betterpolygons) noexcept { SetRenderSettings(betterpolygons, ScaleFactor); diff --git a/src/GPU3D_OpenGL.h b/src/GPU3D_OpenGL.h index d69af324..88d39fef 100644 --- a/src/GPU3D_OpenGL.h +++ b/src/GPU3D_OpenGL.h @@ -32,6 +32,7 @@ class GLRenderer : public Renderer3D public: ~GLRenderer() override; void Reset(GPU& gpu) override; + void DoSavestate(Savestate* file) override; void SetRenderSettings(bool betterpolygons, int scale) noexcept; void SetBetterPolygons(bool betterpolygons) noexcept; diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index 3b51d328..97e089ca 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -131,6 +131,24 @@ void SoftRenderer::Reset(GPU& gpu) EnableRenderThread(); } +void SoftRenderer::DoSavestate(Savestate* file) +{ + bool secfound = file->Section("SW3D", true); + + if (secfound) + { + file->VarArray(StencilBuffer, sizeof(StencilBuffer)); + file->VarArray(ShadowRendered, sizeof(ShadowRendered)); + file->VarArray(ShadowRenderedi, sizeof(ShadowRenderedi)); + } + else + { + memset(StencilBuffer, 0, sizeof(StencilBuffer)); + memset(ShadowRendered, 0, sizeof(ShadowRendered)); + memset(ShadowRenderedi, 0, sizeof(ShadowRenderedi)); + } +} + void SoftRenderer::SetThreaded(bool threaded, GPU& gpu) noexcept { if (Threaded != threaded) diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index d3d20f60..9be76824 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -44,6 +44,7 @@ public: SoftRenderer() noexcept; ~SoftRenderer() override; void Reset(GPU& gpu) override; + void DoSavestate(Savestate* file) override; void SetThreaded(bool threaded, GPU& gpu) noexcept; [[nodiscard]] bool IsThreaded() const noexcept { return Threaded; } diff --git a/src/Savestate.cpp b/src/Savestate.cpp index c51459d9..1dd0c564 100644 --- a/src/Savestate.cpp +++ b/src/Savestate.cpp @@ -153,9 +153,9 @@ Savestate::~Savestate() } } -void Savestate::Section(const char* magic) +bool Savestate::Section(const char* magic, bool noerror) { - if (Error || finished) return; + if (Error || finished) return false; if (Saving) { @@ -174,6 +174,7 @@ void Savestate::Section(const char* magic) // The 8 bytes afterward are reserved, so we skip them. Var32(&zero); Var32(&zero); + return true; } else { @@ -182,12 +183,14 @@ void Savestate::Section(const char* magic) if (section_offset != NO_SECTION) { buffer_offset = section_offset; + return true; } - else + else if (!noerror) { Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic); Error = true; } + return false; } } @@ -378,7 +381,6 @@ u32 Savestate::FindSection(const char* magic) const } // We've reached the end of the file without finding the requested section... - Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic); return NO_SECTION; } diff --git a/src/Savestate.h b/src/Savestate.h index dce62844..27569cce 100644 --- a/src/Savestate.h +++ b/src/Savestate.h @@ -44,7 +44,7 @@ public: u32 CurSection; - void Section(const char* magic); + bool Section(const char* magic, bool noerror = false); void Var8(u8* var) {