diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 31f262c07..7788e7c2d 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -632,6 +632,13 @@ GPUEngineBase::GPUEngineBase() _deferredIndexCustom = NULL; _deferredColorCustom = NULL; + _enableEngine = true; + _enableBGLayer[GPULayerID_BG0] = true; + _enableBGLayer[GPULayerID_BG1] = true; + _enableBGLayer[GPULayerID_BG2] = true; + _enableBGLayer[GPULayerID_BG3] = true; + _enableBGLayer[GPULayerID_OBJ] = true; + _didPassWindowTestCustomMasterPtr = NULL; _didPassWindowTestCustom[GPULayerID_BG0] = NULL; _didPassWindowTestCustom[GPULayerID_BG1] = NULL; @@ -704,12 +711,12 @@ void GPUEngineBase::_Reset_Base() memset(this->_renderLineLayerIDCustom, 0, dispInfo.customWidth * _gpuLargestDstLineCount * 4 * sizeof(u8)); } - this->_enableLayer[GPULayerID_BG0] = false; - this->_enableLayer[GPULayerID_BG1] = false; - this->_enableLayer[GPULayerID_BG2] = false; - this->_enableLayer[GPULayerID_BG3] = false; - this->_enableLayer[GPULayerID_OBJ] = false; - this->_isAnyBGLayerEnabled = false; + this->_isBGLayerShown[GPULayerID_BG0] = false; + this->_isBGLayerShown[GPULayerID_BG1] = false; + this->_isBGLayerShown[GPULayerID_BG2] = false; + this->_isBGLayerShown[GPULayerID_BG3] = false; + this->_isBGLayerShown[GPULayerID_OBJ] = false; + this->_isAnyBGLayerShown = false; this->_BGLayer[GPULayerID_BG0].BGnCNT = this->_IORegisterMap->BG0CNT; this->_BGLayer[GPULayerID_BG1].BGnCNT = this->_IORegisterMap->BG1CNT; @@ -933,13 +940,13 @@ void GPUEngineBase::_ResortBGLayers() #define OP ^ ! // if we untick boxes, layers become invisible //#define OP && - this->_enableLayer[GPULayerID_BG0] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG0] OP(this->_BGLayer[GPULayerID_BG0].isVisible); - this->_enableLayer[GPULayerID_BG1] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG1] OP(this->_BGLayer[GPULayerID_BG1].isVisible); - this->_enableLayer[GPULayerID_BG2] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG2] OP(this->_BGLayer[GPULayerID_BG2].isVisible); - this->_enableLayer[GPULayerID_BG3] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG3] OP(this->_BGLayer[GPULayerID_BG3].isVisible); - this->_enableLayer[GPULayerID_OBJ] = CommonSettings.dispLayers[this->_engineID][GPULayerID_OBJ] OP(DISPCNT.OBJ_Enable); + this->_isBGLayerShown[GPULayerID_BG0] = this->_enableBGLayer[GPULayerID_BG0] OP(this->_BGLayer[GPULayerID_BG0].isVisible); + this->_isBGLayerShown[GPULayerID_BG1] = this->_enableBGLayer[GPULayerID_BG1] OP(this->_BGLayer[GPULayerID_BG1].isVisible); + this->_isBGLayerShown[GPULayerID_BG2] = this->_enableBGLayer[GPULayerID_BG2] OP(this->_BGLayer[GPULayerID_BG2].isVisible); + this->_isBGLayerShown[GPULayerID_BG3] = this->_enableBGLayer[GPULayerID_BG3] OP(this->_BGLayer[GPULayerID_BG3].isVisible); + this->_isBGLayerShown[GPULayerID_OBJ] = this->_enableBGLayer[GPULayerID_OBJ] OP(DISPCNT.OBJ_Enable); - this->_isAnyBGLayerEnabled = this->_enableLayer[GPULayerID_BG0] || this->_enableLayer[GPULayerID_BG1] || this->_enableLayer[GPULayerID_BG2] || this->_enableLayer[GPULayerID_BG3]; + this->_isAnyBGLayerShown = this->_isBGLayerShown[GPULayerID_BG0] || this->_isBGLayerShown[GPULayerID_BG1] || this->_isBGLayerShown[GPULayerID_BG2] || this->_isBGLayerShown[GPULayerID_BG3]; // KISS ! lower priority first, if same then lower num for (i = 0; i < NB_PRIORITIES; i++) @@ -952,7 +959,7 @@ void GPUEngineBase::_ResortBGLayers() for (i = NB_BG; i > 0; ) { i--; - if (!this->_enableLayer[i]) continue; + if (!this->_isBGLayerShown[i]) continue; prio = this->_BGLayer[i].priority; item = &(this->_itemsForPriority[prio]); item->BGs[item->nbBGs]=i; @@ -1654,7 +1661,7 @@ void GPUEngineBase::RenderLine(const size_t l) void GPUEngineBase::UpdatePropertiesWithoutRender(const u16 l) { // Update BG2/BG3 parameters for Affine and AffineExt modes - if ( this->_enableLayer[GPULayerID_BG2] && + if ( this->_isBGLayerShown[GPULayerID_BG2] && ((this->_BGLayer[GPULayerID_BG2].baseType == BGType_Affine) || (this->_BGLayer[GPULayerID_BG2].baseType == BGType_AffineExt)) ) { IOREG_BG2Parameter &BG2Param = this->_IORegisterMap->BG2Param; @@ -1663,7 +1670,7 @@ void GPUEngineBase::UpdatePropertiesWithoutRender(const u16 l) BG2Param.BG2Y.value += BG2Param.BG2PD.value; } - if ( this->_enableLayer[GPULayerID_BG3] && + if ( this->_isBGLayerShown[GPULayerID_BG3] && ((this->_BGLayer[GPULayerID_BG3].baseType == BGType_Affine) || (this->_BGLayer[GPULayerID_BG3].baseType == BGType_AffineExt)) ) { IOREG_BG3Parameter &BG3Param = this->_IORegisterMap->BG3Param; @@ -1713,6 +1720,11 @@ bool GPUEngineBase::GetEnableState() return CommonSettings.showGpu.screens[this->_engineID]; } +bool GPUEngineBase::GetEnableStateApplied() +{ + return this->_enableEngine; +} + void GPUEngineBase::SetEnableState(bool theState) { CommonSettings.showGpu.screens[this->_engineID] = theState; @@ -1726,7 +1738,28 @@ bool GPUEngineBase::GetLayerEnableState(const size_t layerIndex) void GPUEngineBase::SetLayerEnableState(const size_t layerIndex, bool theState) { CommonSettings.dispLayers[this->_engineID][layerIndex] = theState; - this->_ResortBGLayers(); +} + +void GPUEngineBase::ApplySettings() +{ + this->_enableEngine = CommonSettings.showGpu.screens[this->_engineID]; + + bool needResortBGLayers = ( (this->_enableBGLayer[GPULayerID_BG0] != CommonSettings.dispLayers[this->_engineID][GPULayerID_BG0]) || + (this->_enableBGLayer[GPULayerID_BG1] != CommonSettings.dispLayers[this->_engineID][GPULayerID_BG1]) || + (this->_enableBGLayer[GPULayerID_BG2] != CommonSettings.dispLayers[this->_engineID][GPULayerID_BG2]) || + (this->_enableBGLayer[GPULayerID_BG3] != CommonSettings.dispLayers[this->_engineID][GPULayerID_BG3]) || + (this->_enableBGLayer[GPULayerID_OBJ] != CommonSettings.dispLayers[this->_engineID][GPULayerID_OBJ]) ); + + if (needResortBGLayers) + { + this->_enableBGLayer[GPULayerID_BG0] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG0]; + this->_enableBGLayer[GPULayerID_BG1] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG1]; + this->_enableBGLayer[GPULayerID_BG2] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG2]; + this->_enableBGLayer[GPULayerID_BG3] = CommonSettings.dispLayers[this->_engineID][GPULayerID_BG3]; + this->_enableBGLayer[GPULayerID_OBJ] = CommonSettings.dispLayers[this->_engineID][GPULayerID_OBJ]; + + this->_ResortBGLayers(); + } } template @@ -4233,7 +4266,7 @@ void GPUEngineBase::_RenderLine_Layers(const size_t l) this->_RenderLine_Clear(compInfo); // for all the pixels in the line - if (this->_enableLayer[GPULayerID_OBJ]) + if (this->_isBGLayerShown[GPULayerID_OBJ]) { this->vramBlockOBJAddress = 0; this->_RenderLine_SetupSprites(compInfo); @@ -4251,13 +4284,13 @@ void GPUEngineBase::_RenderLine_Layers(const size_t l) prio--; item = &(this->_itemsForPriority[prio]); // render BGs - if (this->_isAnyBGLayerEnabled) + if (this->_isAnyBGLayerShown) { for (size_t i = 0; i < item->nbBGs; i++) { const GPULayerID layerID = (GPULayerID)item->BGs[i]; - if (this->_enableLayer[layerID]) + if (this->_isBGLayerShown[layerID]) { compInfo.renderState.selectedLayerID = layerID; compInfo.renderState.selectedBGLayer = &this->_BGLayer[layerID]; @@ -4316,7 +4349,7 @@ void GPUEngineBase::_RenderLine_Layers(const size_t l) } // render sprite Pixels - if ( this->_enableLayer[GPULayerID_OBJ] && (item->nbPixelsX > 0) ) + if ( this->_isBGLayerShown[GPULayerID_OBJ] && (item->nbPixelsX > 0) ) { compInfo.renderState.selectedLayerID = GPULayerID_OBJ; compInfo.renderState.selectedBGLayer = NULL; @@ -4864,7 +4897,7 @@ void GPUEngineBase::_PerformWindowTesting(GPUEngineCompositorInfo &compInfo) for (size_t layerID = GPULayerID_BG0; layerID <= GPULayerID_OBJ; layerID++) { - if (!this->_enableLayer[layerID]) + if (!this->_isBGLayerShown[layerID]) { continue; } @@ -5791,7 +5824,7 @@ void GPUEngineA::SetCustomFramebufferSize(size_t w, size_t h) bool GPUEngineA::WillRender3DLayer() { - return ( this->_enableLayer[GPULayerID_BG0] && (this->_IORegisterMap->DISPCNT.BG0_3D != 0) ); + return ( this->_isBGLayerShown[GPULayerID_BG0] && (this->_IORegisterMap->DISPCNT.BG0_3D != 0) ); } bool GPUEngineA::WillCapture3DLayerDirect(const size_t l) @@ -7352,6 +7385,9 @@ GPUSubsystem::GPUSubsystem() _display[NDSDisplayID_Touch] = new NDSDisplay(NDSDisplayID_Touch); _display[NDSDisplayID_Touch]->SetEngine(_engineSub); + _pending3DRendererID = RENDERID_NULL; + _needChange3DRenderer = false; + _videoFrameCount = 0; _render3DFrameCount = 0; _frameNeedsFinish = false; @@ -7765,6 +7801,9 @@ void GPUSubsystem::SetCustomFramebufferSize(size_t w, size_t h) _gpuDstToSrcSSSE3_u16_8e = newGpuDstToSrcSSSE3_u16_8e; _gpuDstToSrcSSSE3_u32_4e = newGpuDstToSrcSSSE3_u32_4e; + CurrentRenderer->RenderFinish(); + CurrentRenderer->SetRenderNeedsFinish(false); + this->_displayInfo.isCustomSizeRequested = ( (w != GPU_FRAMEBUFFER_NATIVE_WIDTH) || (h != GPU_FRAMEBUFFER_NATIVE_HEIGHT) ); this->_displayInfo.customWidth = w; this->_displayInfo.customHeight = h; @@ -7807,10 +7846,14 @@ void GPUSubsystem::SetCustomFramebufferSize(size_t w, size_t h) void GPUSubsystem::SetColorFormat(const NDSColorFormat outputFormat) { - //check for no-op - if(this->_displayInfo.colorFormat == outputFormat) + if (this->_displayInfo.colorFormat == outputFormat) + { return; - + } + + CurrentRenderer->RenderFinish(); + CurrentRenderer->SetRenderNeedsFinish(false); + this->_displayInfo.colorFormat = outputFormat; this->_displayInfo.pixelBytes = (outputFormat == NDSColorFormat_BGR555_Rev) ? sizeof(u16) : sizeof(FragmentColor); @@ -7904,6 +7947,81 @@ void GPUSubsystem::_AllocateFramebuffers(NDSColorFormat outputFormat, size_t w, free_aligned(oldCustomVRAM); } +int GPUSubsystem::Get3DRendererID() +{ + return this->_pending3DRendererID; +} + +void GPUSubsystem::Set3DRendererByID(int rendererID) +{ + Render3DInterface *newRenderInterface = core3DList[rendererID]; + if (newRenderInterface->NDS_3D_Init == NULL) + { + return; + } + + this->_pending3DRendererID = rendererID; + this->_needChange3DRenderer = true; +} + +bool GPUSubsystem::Change3DRendererByID(int rendererID) +{ + bool result = false; + + // Whether pass or fail, the 3D renderer will have only one chance to be + // lazily changed via the flag set by Set3DRendererByID(). + this->_needChange3DRenderer = false; + + Render3DInterface *newRenderInterface = core3DList[rendererID]; + if (newRenderInterface->NDS_3D_Init == NULL) + { + return result; + } + + // Some resources are shared between renderers, such as the texture cache, + // so we need to shut down the current renderer now to ensure that any + // shared resources aren't in use. + const bool didRenderBegin = CurrentRenderer->GetRenderNeedsFinish(); + CurrentRenderer->RenderFinish(); + gpu3D->NDS_3D_Close(); + gpu3D = &gpu3DNull; + cur3DCore = RENDERID_NULL; + BaseRenderer->SetRenderNeedsFinish(didRenderBegin); + CurrentRenderer = BaseRenderer; + + Render3D *newRenderer = newRenderInterface->NDS_3D_Init(); + if (newRenderer == NULL) + { + return result; + } + + newRenderer->RequestColorFormat(GPU->GetDisplayInfo().colorFormat); + + Render3DError error = newRenderer->SetFramebufferSize(GPU->GetCustomFramebufferWidth(), GPU->GetCustomFramebufferHeight()); + if (error != RENDER3DERROR_NOERR) + { + return result; + } + + gpu3D = newRenderInterface; + cur3DCore = rendererID; + newRenderer->SetRenderNeedsFinish( BaseRenderer->GetRenderNeedsFinish() ); + CurrentRenderer = newRenderer; + + result = true; + return result; +} + +bool GPUSubsystem::Change3DRendererIfNeeded() +{ + if (!this->_needChange3DRenderer) + { + return true; + } + + return this->Change3DRendererByID(this->_pending3DRendererID); +} + void* GPUSubsystem::GetCustomVRAMBuffer() { return this->_customVRAM; @@ -8023,6 +8141,11 @@ void GPUSubsystem::RenderLine(const size_t l) targetBufferIndex = (targetBufferIndex + 1) & 0x01; } + this->_event->DidApplyGPUSettingsBegin(); + this->_engineMain->ApplySettings(); + this->_engineSub->ApplySettings(); + this->_event->DidApplyGPUSettingsEnd(); + this->_event->DidFrameBegin(this->_willFrameSkip, targetBufferIndex, l); this->_frameNeedsFinish = true; } @@ -8031,7 +8154,7 @@ void GPUSubsystem::RenderLine(const size_t l) this->_engineSub->UpdateRenderStates(l); const bool isDisplayCaptureNeeded = this->_engineMain->WillDisplayCapture(l); - const bool isFramebufferRenderNeeded[2] = { CommonSettings.showGpu.main, CommonSettings.showGpu.sub }; + const bool isFramebufferRenderNeeded[2] = { this->_engineMain->GetEnableStateApplied(), this->_engineSub->GetEnableStateApplied() }; if (l == 0) { @@ -8113,8 +8236,8 @@ void GPUSubsystem::RenderLine(const size_t l) this->_displayInfo.engineID[NDSDisplayID_Main] = this->_display[NDSDisplayID_Main]->GetEngineID(); this->_displayInfo.engineID[NDSDisplayID_Touch] = this->_display[NDSDisplayID_Touch]->GetEngineID(); - this->_displayInfo.isDisplayEnabled[NDSDisplayID_Main] = CommonSettings.showGpu.screens[this->_displayInfo.engineID[NDSDisplayID_Main]]; - this->_displayInfo.isDisplayEnabled[NDSDisplayID_Touch] = CommonSettings.showGpu.screens[this->_displayInfo.engineID[NDSDisplayID_Touch]]; + this->_displayInfo.isDisplayEnabled[NDSDisplayID_Main] = this->_display[NDSDisplayID_Main]->GetEngine()->GetEnableStateApplied(); + this->_displayInfo.isDisplayEnabled[NDSDisplayID_Touch] = this->_display[NDSDisplayID_Touch]->GetEngine()->GetEnableStateApplied(); this->_displayInfo.needConvertColorFormat[NDSDisplayID_Main] = (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev); this->_displayInfo.needConvertColorFormat[NDSDisplayID_Touch] = (OUTPUTFORMAT == NDSColorFormat_BGR666_Rev); diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 53c6813b7..945b0e6ef 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -58,6 +58,7 @@ class GPUEngineBase; class EMUFILE; struct MMU_struct; +struct Render3DInterface; //#undef FORCEINLINE //#define FORCEINLINE @@ -1383,8 +1384,11 @@ protected: u8 *_deferredIndexCustom; u16 *_deferredColorCustom; - bool _enableLayer[5]; - bool _isAnyBGLayerEnabled; + bool _enableEngine; + bool _enableBGLayer[5]; + + bool _isBGLayerShown[5]; + bool _isAnyBGLayerShown; itemsForPriority_t _itemsForPriority[NB_PRIORITIES]; struct MosaicColor { @@ -1574,10 +1578,13 @@ public: void GetMasterBrightnessAtLineZero(GPUMasterBrightMode &outMode, u8 &outIntensity); bool GetEnableState(); + bool GetEnableStateApplied(); void SetEnableState(bool theState); bool GetLayerEnableState(const size_t layerIndex); void SetLayerEnableState(const size_t layerIndex, bool theState); + void ApplySettings(); + void UpdateMasterBrightnessDisplayInfo(NDSDisplayInfo &mutableInfo); template void ApplyMasterBrightness(const NDSDisplayInfo &displayInfo); template void ApplyMasterBrightness(void *dst, const size_t pixCount, const GPUMasterBrightMode mode, const u8 intensity); @@ -1716,6 +1723,8 @@ public: virtual void DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &latestDisplayInfo) = 0; virtual void DidRender3DBegin() = 0; virtual void DidRender3DEnd() = 0; + virtual void DidApplyGPUSettingsBegin() = 0; + virtual void DidApplyGPUSettingsEnd() = 0; virtual void DidApplyRender3DSettingsBegin() = 0; virtual void DidApplyRender3DSettingsEnd() = 0; }; @@ -1730,6 +1739,8 @@ public: virtual void DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &latestDisplayInfo) {}; virtual void DidRender3DBegin() {}; virtual void DidRender3DEnd() {}; + virtual void DidApplyGPUSettingsBegin() {}; + virtual void DidApplyGPUSettingsEnd() {}; virtual void DidApplyRender3DSettingsBegin() {}; virtual void DidApplyRender3DSettingsEnd() {}; }; @@ -1745,6 +1756,9 @@ private: NDSDisplay *_display[2]; float _backlightIntensityTotal[2]; + int _pending3DRendererID; + bool _needChange3DRenderer; + 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; @@ -1790,6 +1804,11 @@ public: void SetColorFormat(const NDSColorFormat outputFormat); NDSColorFormat GetColorFormat() const; + int Get3DRendererID(); + void Set3DRendererByID(int rendererID); + bool Change3DRendererByID(int rendererID); + bool Change3DRendererIfNeeded(); + bool GetWillFrameSkip() const; void SetWillFrameSkip(const bool willFrameSkip); void SetDisplayCaptureEnable(); diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.mm b/desmume/src/frontend/cocoa/cocoa_GPU.mm index 4ed857a94..7bbee2b9c 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.mm +++ b/desmume/src/frontend/cocoa/cocoa_GPU.mm @@ -54,6 +54,7 @@ private: pthread_rwlock_t _rwlockFrame; pthread_mutex_t _mutex3DRender; + pthread_mutex_t _mutexApplyGPUSettings; pthread_mutex_t _mutexApplyRender3DSettings; bool _render3DNeedsFinish; @@ -69,6 +70,8 @@ public: void FramebufferUnlock(); void Render3DLock(); void Render3DUnlock(); + void ApplyGPUSettingsLock(); + void ApplyGPUSettingsUnlock(); void ApplyRender3DSettingsLock(); void ApplyRender3DSettingsUnlock(); @@ -79,6 +82,8 @@ public: virtual void DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &latestDisplayInfo); virtual void DidRender3DBegin(); virtual void DidRender3DEnd(); + virtual void DidApplyGPUSettingsBegin(); + virtual void DidApplyGPUSettingsEnd(); virtual void DidApplyRender3DSettingsBegin(); virtual void DidApplyRender3DSettingsEnd(); }; @@ -323,20 +328,20 @@ public: [(MacClientSharedObject *)fetchObject->GetClientData() setOutputList:theOutputList mutex:theMutex]; } -- (void) setRender3DRenderingEngine:(NSInteger)methodID +- (void) setRender3DRenderingEngine:(NSInteger)rendererID { - gpuEvent->Render3DLock(); - NDS_3D_ChangeCore(methodID); - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsLock(); + GPU->Set3DRendererByID(rendererID); + gpuEvent->ApplyRender3DSettingsUnlock(); } - (NSInteger) render3DRenderingEngine { - gpuEvent->Render3DLock(); - const NSInteger methodID = (NSInteger)cur3DCore; - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsLock(); + const NSInteger rendererID = (NSInteger)GPU->Get3DRendererID(); + gpuEvent->ApplyRender3DSettingsUnlock(); - return methodID; + return rendererID; } - (void) setRender3DHighPrecisionColorInterpolation:(BOOL)state @@ -433,25 +438,25 @@ public: numberCores = numberThreads; } - const NSInteger renderingEngineID = [self render3DRenderingEngine]; + const RendererID renderingEngineID = (RendererID)[self render3DRenderingEngine]; - gpuEvent->Render3DLock(); + gpuEvent->ApplyRender3DSettingsLock(); CommonSettings.num_cores = numberCores; - if (renderingEngineID == CORE3DLIST_SWRASTERIZE) + if (renderingEngineID == RENDERID_SOFTRASTERIZER) { - NDS_3D_ChangeCore(renderingEngineID); + GPU->Set3DRendererByID(renderingEngineID); } - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsUnlock(); } - (NSUInteger) render3DThreads { - gpuEvent->Render3DLock(); + gpuEvent->ApplyRender3DSettingsLock(); const NSUInteger numberThreads = isCPUCoreCountAuto ? 0 : (NSUInteger)CommonSettings.num_cores; - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsUnlock(); return numberThreads; } @@ -571,9 +576,9 @@ public: - (void) setLayerMainGPU:(BOOL)gpuState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetEnableState((gpuState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (gpuState) ? (gpuStateFlags | GPUSTATE_MAIN_GPU_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_GPU_MASK); @@ -582,18 +587,18 @@ public: - (BOOL) layerMainGPU { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL gpuState = GPU->GetEngineMain()->GetEnableState() ? YES : NO; - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return gpuState; } - (void) setLayerMainBG0:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetLayerEnableState(GPULayerID_BG0, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG0_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG0_MASK); @@ -602,18 +607,18 @@ public: - (BOOL) layerMainBG0 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineMain()->GetLayerEnableState(GPULayerID_BG0); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerMainBG1:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetLayerEnableState(GPULayerID_BG1, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG1_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG1_MASK); @@ -622,18 +627,18 @@ public: - (BOOL) layerMainBG1 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineMain()->GetLayerEnableState(GPULayerID_BG1); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerMainBG2:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetLayerEnableState(GPULayerID_BG2, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG2_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG2_MASK); @@ -642,18 +647,18 @@ public: - (BOOL) layerMainBG2 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineMain()->GetLayerEnableState(GPULayerID_BG2); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerMainBG3:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetLayerEnableState(GPULayerID_BG3, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG3_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG3_MASK); @@ -662,18 +667,18 @@ public: - (BOOL) layerMainBG3 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineMain()->GetLayerEnableState(GPULayerID_BG3); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerMainOBJ:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineMain()->SetLayerEnableState(GPULayerID_OBJ, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_OBJ_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_OBJ_MASK); @@ -682,18 +687,18 @@ public: - (BOOL) layerMainOBJ { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineMain()->GetLayerEnableState(GPULayerID_OBJ); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerSubGPU:(BOOL)gpuState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetEnableState((gpuState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (gpuState) ? (gpuStateFlags | GPUSTATE_SUB_GPU_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_GPU_MASK); @@ -702,18 +707,18 @@ public: - (BOOL) layerSubGPU { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL gpuState = GPU->GetEngineSub()->GetEnableState() ? YES : NO; - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return gpuState; } - (void) setLayerSubBG0:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetLayerEnableState(GPULayerID_BG0, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG0_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG0_MASK); @@ -722,18 +727,18 @@ public: - (BOOL) layerSubBG0 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineSub()->GetLayerEnableState(GPULayerID_BG0); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerSubBG1:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetLayerEnableState(GPULayerID_BG1, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG1_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG1_MASK); @@ -742,18 +747,18 @@ public: - (BOOL) layerSubBG1 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineSub()->GetLayerEnableState(GPULayerID_BG1); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerSubBG2:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetLayerEnableState(GPULayerID_BG2, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG2_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG2_MASK); @@ -762,18 +767,18 @@ public: - (BOOL) layerSubBG2 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineSub()->GetLayerEnableState(GPULayerID_BG2); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerSubBG3:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetLayerEnableState(GPULayerID_BG3, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG3_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG3_MASK); @@ -782,18 +787,18 @@ public: - (BOOL) layerSubBG3 { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineSub()->GetLayerEnableState(GPULayerID_BG3); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } - (void) setLayerSubOBJ:(BOOL)layerState { - gpuEvent->FramebufferLockWrite(); + gpuEvent->ApplyGPUSettingsLock(); GPU->GetEngineSub()->SetLayerEnableState(GPULayerID_OBJ, (layerState) ? true : false); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_OBJ_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_OBJ_MASK); @@ -802,9 +807,9 @@ public: - (BOOL) layerSubOBJ { - gpuEvent->FramebufferLockRead(); + gpuEvent->ApplyGPUSettingsLock(); const BOOL layerState = GPU->GetEngineSub()->GetLayerEnableState(GPULayerID_OBJ); - gpuEvent->FramebufferUnlock(); + gpuEvent->ApplyGPUSettingsUnlock(); return layerState; } @@ -818,18 +823,18 @@ public: { NSString *theString = @"Uninitialized"; - gpuEvent->Render3DLock(); + gpuEvent->ApplyRender3DSettingsLock(); - if(gpu3D == NULL) + if (gpu3D == NULL) { - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsUnlock(); return theString; } const char *theName = gpu3D->name; theString = [NSString stringWithCString:theName encoding:NSUTF8StringEncoding]; - gpuEvent->Render3DUnlock(); + gpuEvent->ApplyRender3DSettingsUnlock(); return theString; } @@ -1217,6 +1222,7 @@ GPUEventHandlerOSX::GPUEventHandlerOSX() _render3DNeedsFinish = false; pthread_rwlock_init(&_rwlockFrame, NULL); pthread_mutex_init(&_mutex3DRender, NULL); + pthread_mutex_init(&_mutexApplyGPUSettings, NULL); pthread_mutex_init(&_mutexApplyRender3DSettings, NULL); } @@ -1229,6 +1235,7 @@ GPUEventHandlerOSX::~GPUEventHandlerOSX() pthread_rwlock_destroy(&this->_rwlockFrame); pthread_mutex_destroy(&this->_mutex3DRender); + pthread_mutex_destroy(&this->_mutexApplyGPUSettings); pthread_mutex_destroy(&this->_mutexApplyRender3DSettings); } @@ -1288,6 +1295,16 @@ void GPUEventHandlerOSX::DidRender3DEnd() this->Render3DUnlock(); } +void GPUEventHandlerOSX::DidApplyGPUSettingsBegin() +{ + this->ApplyGPUSettingsLock(); +} + +void GPUEventHandlerOSX::DidApplyGPUSettingsEnd() +{ + this->ApplyGPUSettingsUnlock(); +} + void GPUEventHandlerOSX::DidApplyRender3DSettingsBegin() { this->ApplyRender3DSettingsLock(); @@ -1323,6 +1340,16 @@ void GPUEventHandlerOSX::Render3DUnlock() pthread_mutex_unlock(&this->_mutex3DRender); } +void GPUEventHandlerOSX::ApplyGPUSettingsLock() +{ + pthread_mutex_lock(&this->_mutexApplyGPUSettings); +} + +void GPUEventHandlerOSX::ApplyGPUSettingsUnlock() +{ + pthread_mutex_unlock(&this->_mutexApplyGPUSettings); +} + void GPUEventHandlerOSX::ApplyRender3DSettingsLock() { pthread_mutex_lock(&this->_mutexApplyRender3DSettings); diff --git a/desmume/src/frontend/posix/cli/main.cpp b/desmume/src/frontend/posix/cli/main.cpp index 4767683d1..d34fe5c1c 100644 --- a/desmume/src/frontend/posix/cli/main.cpp +++ b/desmume/src/frontend/posix/cli/main.cpp @@ -630,7 +630,10 @@ int main(int argc, char ** argv) { SPU_ChangeSoundCore(SNDCORE_SDL, 735 * 4); } - NDS_3D_ChangeCore(my_config.engine_3d); + if (!GPU->Change3DRendererByID(my_config.engine_3d)) { + GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); + fprintf(stderr, "3D renderer initialization failed!\nFalling back to 3D core: %s\n", core3DList[RENDERID_SOFTRASTERIZER]->name); + } backup_setManualBackupType(my_config.savetype); diff --git a/desmume/src/frontend/posix/gtk-glade/main.cpp b/desmume/src/frontend/posix/gtk-glade/main.cpp index 220ff4b32..72f852455 100755 --- a/desmume/src/frontend/posix/gtk-glade/main.cpp +++ b/desmume/src/frontend/posix/gtk-glade/main.cpp @@ -488,9 +488,10 @@ common_gtk_glade_main( struct configured_features *my_config) { engine = 0; } #endif - NDS_3D_ChangeCore(engine); - if(my_config->engine_3d != 0 && gpu3D == GPU3D_NULL) - fprintf(stderr, _("Failed to setup 3D engine; removing 3D support\n")); + if (!GPU->Change3DRendererByID(engine)) { + GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); + fprintf(stderr, _("3D renderer initialization failed!\nFalling back to 3D core: %s\n"), core3DList[RENDERID_SOFTRASTERIZER]->name); + } } // on_menu_tileview_activate(NULL,NULL); diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index e167ffac1..84262f26b 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -2311,10 +2311,13 @@ static void GraphicsSettingsDialog() { init_glx_3Demu(); } #endif - if (NDS_3D_ChangeCore(sel3DCore)) { - config.core3D = sel3DCore; + + if (GPU->Change3DRendererByID(sel3DCore)) { + config.core3D = sel3DCore } else { - g_printerr("Failed to change the 3D Core!"); + GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); + g_printerr("3D renderer initialization failed!\nFalling back to 3D core: %s\n", core3DList[RENDERID_SOFTRASTERIZER]->name); + config.core3D = RENDERID_SOFTRASTERIZER; } } @@ -3417,15 +3420,15 @@ common_gtk_main( class configured_features *my_config) #elif defined(HAVE_GL_GLX) core = init_glx_3Demu() #endif - ? 2 : GPU3D_NULL; + ? 2 : RENDERID_NULL; } #endif - NDS_3D_ChangeCore(core); - if(core != 0 && gpu3D == &gpu3DNull) { - g_printerr("Failed to initialise openGL 3D emulation; " - "removing 3D support\n"); - } + if (!GPU->Change3DRendererByID(core)) { + GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); + g_printerr("3D renderer initialization failed!\nFalling back to 3D core: %s\n", core3DList[RENDERID_SOFTRASTERIZER]->name); + my_config->engine_3d = RENDERID_SOFTRASTERIZER; + } CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation; CommonSettings.GFX3D_Renderer_Multisample = config.multisampling; diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 840112e23..c288f08c5 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -2911,7 +2911,7 @@ static void SyncGpuBpp() GPU->SetColorFormat(NDSColorFormat_BGR888_Rev); } -#define GPU3D_NULL_SAVED -1 +#define RENDERID_NULL_SAVED -1 #define GPU3D_DEFAULT GPU3D_SWRAST DWORD wmTimerRes; @@ -3361,12 +3361,12 @@ int _main() hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); cur3DCore = GetPrivateProfileInt("3D", "Renderer", GPU3D_DEFAULT, IniName); - if(cur3DCore == GPU3D_NULL_SAVED) - cur3DCore = GPU3D_NULL; - else if(cur3DCore == GPU3D_NULL) // this value shouldn't be saved anymore + if(cur3DCore == RENDERID_NULL_SAVED) + cur3DCore = RENDERID_NULL; + else if(cur3DCore == RENDERID_NULL) // this value shouldn't be saved anymore cur3DCore = GPU3D_DEFAULT; - if(cmdline.render3d == COMMANDLINE_RENDER3D_NONE) cur3DCore = GPU3D_NULL; + if(cmdline.render3d == COMMANDLINE_RENDER3D_NONE) cur3DCore = RENDERID_NULL; if(cmdline.render3d == COMMANDLINE_RENDER3D_SW) cur3DCore = GPU3D_SWRAST; if(cmdline.render3d == COMMANDLINE_RENDER3D_OLDGL) cur3DCore = GPU3D_OPENGL_OLD; if(cmdline.render3d == COMMANDLINE_RENDER3D_GL) cur3DCore = GPU3D_OPENGL_3_2; //no way of forcing it, at least not right now. I dont care. @@ -6329,13 +6329,13 @@ void Change3DCoreWithFallbackAndSave(int newCore) if(newCore == GPU3D_SWRAST) goto TRY_SWRAST; - if(newCore == GPU3D_NULL) + if(newCore == RENDERID_NULL) { - NDS_3D_ChangeCore(GPU3D_NULL); + GPU->Change3DRendererByID(RENDERID_NULL); goto DONE; } - if(!NDS_3D_ChangeCore(GPU3D_OPENGL_3_2)) + if(!GPU->Change3DRendererByID(GPU3D_OPENGL_3_2)) { printf("falling back to 3d core: %s\n",core3DList[GPU3D_OPENGL_OLD]->name); goto TRY_OGL_OLD; @@ -6343,7 +6343,7 @@ void Change3DCoreWithFallbackAndSave(int newCore) goto DONE; TRY_OGL_OLD: - if(!NDS_3D_ChangeCore(GPU3D_OPENGL_OLD)) + if(!GPU->Change3DRendererByID(GPU3D_OPENGL_OLD)) { printf("falling back to 3d core: %s\n",core3DList[GPU3D_SWRAST]->name); goto TRY_SWRAST; @@ -6351,10 +6351,10 @@ TRY_OGL_OLD: goto DONE; TRY_SWRAST: - NDS_3D_ChangeCore(GPU3D_SWRAST); + GPU->Change3DRendererByID(GPU3D_SWRAST); DONE: - int gpu3dSaveValue = ((cur3DCore != GPU3D_NULL) ? cur3DCore : GPU3D_NULL_SAVED); + int gpu3dSaveValue = ((cur3DCore != RENDERID_NULL) ? cur3DCore : RENDERID_NULL_SAVED); WritePrivateProfileInt("3D", "Renderer", gpu3dSaveValue, IniName); } diff --git a/desmume/src/frontend/windows/main.h b/desmume/src/frontend/windows/main.h index c7cdec69d..4b756052d 100644 --- a/desmume/src/frontend/windows/main.h +++ b/desmume/src/frontend/windows/main.h @@ -52,7 +52,6 @@ extern bool frameCounterDisplay; extern bool FpsDisplay; extern bool ShowLagFrameCounter; -#define GPU3D_NULL 0 #define GPU3D_OPENGL_3_2 1 #define GPU3D_SWRAST 2 #define GPU3D_OPENGL_OLD 3 diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 204d8ac8c..a92361bb2 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -2395,6 +2395,7 @@ void gfx3d_VBlankEndSignal(bool skipFrame) drawPending = FALSE; GPU->GetEventHandler()->DidApplyRender3DSettingsBegin(); + GPU->Change3DRendererIfNeeded(); CurrentRenderer->ApplyRenderingSettings(gfx3d.renderState); GPU->GetEventHandler()->DidApplyRender3DSettingsEnd(); @@ -2402,7 +2403,7 @@ void gfx3d_VBlankEndSignal(bool skipFrame) CurrentRenderer->SetRenderNeedsFinish(true); //the timing of powering on rendering may not be exactly right here. - if (CommonSettings.showGpu.main && nds.power_render) + if (GPU->GetEngineMain()->GetEnableStateApplied() && nds.power_render) { CurrentRenderer->SetTextureProcessingProperties(); CurrentRenderer->Render(gfx3d); diff --git a/desmume/src/render3D.cpp b/desmume/src/render3D.cpp index da4d9457e..9c7ed822b 100644 --- a/desmume/src/render3D.cpp +++ b/desmume/src/render3D.cpp @@ -31,7 +31,7 @@ #include "./filter/xbrz.h" -int cur3DCore = GPU3D_NULL; +int cur3DCore = RENDERID_NULL; GPU3DInterface gpu3DNull = { "None", @@ -53,7 +53,7 @@ void Render3D_Init() if (CurrentRenderer == NULL) { gpu3D = &gpu3DNull; - cur3DCore = GPU3D_NULL; + cur3DCore = RENDERID_NULL; CurrentRenderer = BaseRenderer; } } @@ -65,50 +65,6 @@ void Render3D_DeInit() BaseRenderer = NULL; } -bool NDS_3D_ChangeCore(int newCore) -{ - bool result = false; - - Render3DInterface *newRenderInterface = core3DList[newCore]; - if (newRenderInterface->NDS_3D_Init == NULL) - { - return result; - } - - // Some resources are shared between renderers, such as the texture cache, - // so we need to shut down the current renderer now to ensure that any - // shared resources aren't in use. - const bool didRenderBegin = CurrentRenderer->GetRenderNeedsFinish(); - CurrentRenderer->RenderFinish(); - gpu3D->NDS_3D_Close(); - gpu3D = &gpu3DNull; - cur3DCore = GPU3D_NULL; - BaseRenderer->SetRenderNeedsFinish(didRenderBegin); - CurrentRenderer = BaseRenderer; - - Render3D *newRenderer = newRenderInterface->NDS_3D_Init(); - if (newRenderer == NULL) - { - return result; - } - - newRenderer->RequestColorFormat(GPU->GetDisplayInfo().colorFormat); - - Render3DError error = newRenderer->SetFramebufferSize(GPU->GetCustomFramebufferWidth(), GPU->GetCustomFramebufferHeight()); - if (error != RENDER3DERROR_NOERR) - { - return result; - } - - gpu3D = newRenderInterface; - cur3DCore = newCore; - newRenderer->SetRenderNeedsFinish( BaseRenderer->GetRenderNeedsFinish() ); - CurrentRenderer = newRenderer; - - result = true; - return result; -} - Render3D* Render3DBaseCreate() { BaseRenderer->Reset(); diff --git a/desmume/src/render3D.h b/desmume/src/render3D.h index 7912acd4e..074e8f2b9 100644 --- a/desmume/src/render3D.h +++ b/desmume/src/render3D.h @@ -42,7 +42,6 @@ extern int cur3DCore; extern GPU3DInterface *core3DList[]; // Default null plugin -#define GPU3D_NULL 0 extern GPU3DInterface gpu3DNull; // Extern pointer @@ -55,7 +54,6 @@ void Render3DBaseDestroy(); void Render3D_Init(); void Render3D_DeInit(); -bool NDS_3D_ChangeCore(int newCore); enum RendererID {