diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index f76dac39e..82a5da1a2 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -48,7 +48,6 @@ #include "matrix.h" #include "emufile.h" -u32 Render3DFramesPerSecond; //instantiate static instance u16 GPUEngineBase::_brightnessUpTable555[17][0x8000]; @@ -6760,6 +6759,8 @@ GPUSubsystem::GPUSubsystem() _displayTouch = new NDSDisplay(NDSDisplayID_Touch); _displayTouch->SetEngine(_engineSub); + _videoFrameCount = 0; + _render3DFrameCount = 0; _frameNeedsFinish = false; _willAutoResolveToCustomBuffer = true; @@ -6853,6 +6854,9 @@ void GPUSubsystem::Reset() this->SetCustomFramebufferSize(this->_displayInfo.customWidth, this->_displayInfo.customHeight); } + this->_videoFrameCount = 0; + this->_render3DFrameCount = 0; + this->ClearWithColor(0xFFFF); this->_displayInfo.didPerformCustomRender[NDSDisplayID_Main] = false; @@ -6990,6 +6994,11 @@ const NDSDisplayInfo& GPUSubsystem::GetDisplayInfo() return this->_displayInfo; } +u32 GPUSubsystem::GetFPSRender3D() const +{ + return this->_render3DFrameCount; +} + void GPUSubsystem::SetDisplayDidCustomRender(NDSDisplayID displayID, bool theState) { this->_displayInfo.didPerformCustomRender[displayID] = theState; @@ -7325,30 +7334,6 @@ void GPUSubsystem::RenderLine(const u16 l, bool isFrameSkipRequested) if (!isFrameSkipRequested) { this->UpdateRenderProperties(); - - if (!isFramebufferRenderNeeded[GPUEngineID_Main]) - { - if (!CommonSettings.showGpu.main) - { - memset(this->_engineMain->renderedBuffer, 0, this->_engineMain->renderedWidth * this->_engineMain->renderedHeight * this->_displayInfo.pixelBytes); - } - else if (this->_engineMain->GetIsMasterBrightFullIntensity()) - { - this->_engineMain->ApplyMasterBrightness(); - } - } - - if (!isFramebufferRenderNeeded[GPUEngineID_Sub]) - { - if (!CommonSettings.showGpu.sub) - { - memset(this->_engineSub->renderedBuffer, 0, this->_engineSub->renderedWidth * this->_engineSub->renderedHeight * this->_displayInfo.pixelBytes); - } - else if (this->_engineSub->GetIsMasterBrightFullIntensity()) - { - this->_engineSub->ApplyMasterBrightness(); - } - } } } @@ -7399,6 +7384,14 @@ void GPUSubsystem::RenderLine(const u16 l, bool isFrameSkipRequested) this->_engineMain->FramebufferPostprocess(); this->_engineSub->FramebufferPostprocess(); + this->_videoFrameCount++; + if (this->_videoFrameCount == 60) + { + this->_render3DFrameCount = gfx3d.render3DFrameCount; + gfx3d.render3DFrameCount = 0; + this->_videoFrameCount = 0; + } + if (!isFrameSkipRequested) { if (this->_displayInfo.isCustomSizeRequested) @@ -7421,11 +7414,33 @@ void GPUSubsystem::RenderLine(const u16 l, bool isFrameSkipRequested) { this->_engineMain->ApplyMasterBrightness(); } + else + { + if (!CommonSettings.showGpu.main) + { + memset(this->_engineMain->renderedBuffer, 0, this->_engineMain->renderedWidth * this->_engineMain->renderedHeight * this->_displayInfo.pixelBytes); + } + else if (this->_engineMain->GetIsMasterBrightFullIntensity()) + { + this->_engineMain->ApplyMasterBrightness(); + } + } if (isFramebufferRenderNeeded[GPUEngineID_Sub]) { this->_engineSub->ApplyMasterBrightness(); } + else + { + if (!CommonSettings.showGpu.sub) + { + memset(this->_engineSub->renderedBuffer, 0, this->_engineSub->renderedWidth * this->_engineSub->renderedHeight * this->_displayInfo.pixelBytes); + } + else if (this->_engineSub->GetIsMasterBrightFullIntensity()) + { + this->_engineSub->ApplyMasterBrightness(); + } + } if (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev) { @@ -7440,14 +7455,6 @@ void GPUSubsystem::RenderLine(const u16 l, bool isFrameSkipRequested) } } - gfx3d._videoFrameCount++; - if (gfx3d._videoFrameCount == 60) - { - Render3DFramesPerSecond = gfx3d.render3DFrameCount; - gfx3d.render3DFrameCount = 0; - gfx3d._videoFrameCount = 0; - } - if (this->_frameNeedsFinish) { this->_frameNeedsFinish = false; diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index b983fed69..00883a3ce 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1608,6 +1608,8 @@ private: NDSDisplay *_displayMain; NDSDisplay *_displayTouch; + u32 _videoFrameCount; // Internal variable that increments when a video frame is completed. Resets every 60 video frames. + u32 _render3DFrameCount; // The current 3D rendering frame count, saved to this variable once every 60 video frames. bool _frameNeedsFinish; bool _willAutoResolveToCustomBuffer; u16 *_customVRAM; @@ -1632,6 +1634,8 @@ public: void ForceFrameStop(); const NDSDisplayInfo& GetDisplayInfo(); // Frontends need to call this whenever they need to read the video buffers from the emulator core + u32 GetFPSRender3D() const; + void SetDisplayDidCustomRender(NDSDisplayID displayID, bool theState); GPUEngineA* GetEngineMain(); diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index 0a94dd4ae..5fff9e35b 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -869,7 +869,7 @@ [super handleEmuFrameProcessed]; NDSFrameInfo frameInfo; - frameInfo.render3DFPS = Render3DFramesPerSecond; + frameInfo.render3DFPS = GPU->GetFPSRender3D(); frameInfo.frameIndex = currFrameCounter; frameInfo.lagFrameCount = TotalLagFrames; diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index bc5de5392..04a43064b 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -504,9 +504,7 @@ void gfx3d_init() gfx3d.state.fogDensityTable = MMU.ARM9_REG+0x0360; gfx3d.state.edgeMarkColorTable = (u16 *)(MMU.ARM9_REG+0x0330); - gfx3d._videoFrameCount = 0; gfx3d.render3DFrameCount = 0; - Render3DFramesPerSecond = 0; makeTables(); Render3D_Init(); @@ -607,9 +605,7 @@ void gfx3d_reset() GFX_PIPEclear(); GFX_FIFOclear(); - gfx3d._videoFrameCount = 0; gfx3d.render3DFrameCount = 0; - Render3DFramesPerSecond = 0; CurrentRenderer->Reset(); } diff --git a/desmume/src/gfx3d.h b/desmume/src/gfx3d.h index 0a4da3273..5a5bea1f0 100644 --- a/desmume/src/gfx3d.h +++ b/desmume/src/gfx3d.h @@ -667,7 +667,6 @@ struct GFX3D GFX3D() : polylist(0) , vertlist(0) - , _videoFrameCount(0) , render3DFrameCount(0) { } @@ -681,11 +680,9 @@ struct GFX3D VERTLIST* vertlist; INDEXLIST indexlist; - u32 _videoFrameCount; // Internal variable that increments when a video frame is completed. Resets every 60 video frames. u32 render3DFrameCount; // Increments when gfx3d_doFlush() is called. Resets every 60 video frames. }; extern GFX3D gfx3d; -extern u32 Render3DFramesPerSecond; // save the current 3D rendering frame count to here every 60 video frames //--------------------- diff --git a/desmume/src/gtk/main.cpp b/desmume/src/gtk/main.cpp index 2e9fa593d..5b335cafb 100644 --- a/desmume/src/gtk/main.cpp +++ b/desmume/src/gtk/main.cpp @@ -2413,7 +2413,7 @@ gboolean EmuLoop(gpointer data) // HUD display things (copied from Windows main.cpp) #ifdef HAVE_LIBAGG - Hud.fps3d = Render3DFramesPerSecond; + Hud.fps3d = GPU->GetFPSRender3D(); if(nds.idleFrameCounter==0 || oneSecond) { @@ -2446,7 +2446,7 @@ gboolean EmuLoop(gpointer data) for (i = 0; i < Frameskip; i++) { NDS_SkipNextFrame(); #ifdef HAVE_LIBAGG - Hud.fps3d = Render3DFramesPerSecond; + Hud.fps3d = GPU->GetFPSRender3D(); #endif desmume_cycle(); skipped_frames++; @@ -2459,7 +2459,7 @@ gboolean EmuLoop(gpointer data) for (i = 0; i < Frameskip; i++) { NDS_SkipNextFrame(); #ifdef HAVE_LIBAGG - Hud.fps3d = Render3DFramesPerSecond; + Hud.fps3d = GPU->GetFPSRender3D(); #endif desmume_cycle(); skipped_frames++; @@ -2481,7 +2481,7 @@ gboolean EmuLoop(gpointer data) // Aggressively skip frames to avoid delay NDS_SkipNextFrame(); #ifdef HAVE_LIBAGG - Hud.fps3d = Render3DFramesPerSecond; + Hud.fps3d = GPU->GetFPSRender3D(); #endif desmume_cycle(); skipped_frames++; diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 9f334fed3..1f7b29b1f 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -2185,7 +2185,7 @@ static void StepRunLoop_User() const int kFramesPerToolUpdate = 1; Hud.fps = mainLoopData.fps; - Hud.fps3d = Render3DFramesPerSecond; + Hud.fps3d = GPU->GetFPSRender3D(); Display();