diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index a563ca4c2..33589003c 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -4033,6 +4033,7 @@ void GPUEngineBase::ApplyMasterBrightness() if (this->_willApplyMasterBrightnessPerScanline) { const bool isNativeSize = (this->nativeLineOutputCount == GPU_FRAMEBUFFER_NATIVE_HEIGHT); + bool needsApply = false; for (size_t line = 0; line < GPU_FRAMEBUFFER_NATIVE_HEIGHT; line++) { @@ -4047,16 +4048,20 @@ void GPUEngineBase::ApplyMasterBrightness() pixCount, compInfo.renderState.masterBrightnessMode, compInfo.renderState.masterBrightnessIntensity); - + } + else + { if ( (compInfo.renderState.masterBrightnessIntensity != 0) && ((compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Up) || (compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Down)) ) { - dispInfoMutable.isMasterBrightnessApplied[this->_targetDisplayID] = true; + needsApply = true; } } dispInfoMutable.masterBrightnessMode[this->_targetDisplayID][line] = compInfo.renderState.masterBrightnessMode; dispInfoMutable.masterBrightnessIntensity[this->_targetDisplayID][line] = compInfo.renderState.masterBrightnessIntensity; } + + dispInfoMutable.needApplyMasterBrightness[this->_targetDisplayID] = dispInfoMutable.needApplyMasterBrightness[this->_targetDisplayID] && needsApply; } else { @@ -4068,8 +4073,10 @@ void GPUEngineBase::ApplyMasterBrightness() this->renderedWidth * this->renderedHeight, compInfo.renderState.masterBrightnessMode, compInfo.renderState.masterBrightnessIntensity); - - dispInfoMutable.isMasterBrightnessApplied[this->_targetDisplayID] = (compInfo.renderState.masterBrightnessIntensity != 0) && ((compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Up) || (compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Down)); + } + else + { + dispInfoMutable.needApplyMasterBrightness[this->_targetDisplayID] = (compInfo.renderState.masterBrightnessIntensity != 0) && ((compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Up) || (compInfo.renderState.masterBrightnessMode == GPUMasterBrightMode_Down)); } for (size_t line = 0; line < GPU_FRAMEBUFFER_NATIVE_HEIGHT; line++) @@ -6799,6 +6806,7 @@ GPUSubsystem::GPUSubsystem() _displayInfo.isCustomSizeRequested = false; _displayInfo.customWidth = GPU_FRAMEBUFFER_NATIVE_WIDTH; _displayInfo.customHeight = GPU_FRAMEBUFFER_NATIVE_HEIGHT; + _displayInfo.isMasterBrightnessAutoApplyRequested = true; _customVRAM = NULL; _customVRAMBlank = NULL; @@ -7344,6 +7352,7 @@ bool GPUSubsystem::GetWillAutoApplyMasterBrightness() const void GPUSubsystem::SetWillAutoApplyMasterBrightness(const bool willAutoApply) { this->_willAutoApplyMasterBrightness = willAutoApply; + this->_displayInfo.isMasterBrightnessAutoApplyRequested = willAutoApply; } bool GPUSubsystem::GetWillAutoConvertRGB666ToRGB888() const @@ -7466,8 +7475,8 @@ void GPUSubsystem::RenderLine(const size_t l) this->_displayInfo.isDisplayEnabled[NDSDisplayID_Main] = CommonSettings.showGpu.main; this->_displayInfo.isDisplayEnabled[NDSDisplayID_Touch] = CommonSettings.showGpu.sub; - this->_displayInfo.isMasterBrightnessApplied[NDSDisplayID_Main] = false; - this->_displayInfo.isMasterBrightnessApplied[NDSDisplayID_Touch] = false; + this->_displayInfo.needApplyMasterBrightness[NDSDisplayID_Main] = !this->_displayInfo.isMasterBrightnessAutoApplyRequested; + this->_displayInfo.needApplyMasterBrightness[NDSDisplayID_Touch] = !this->_displayInfo.isMasterBrightnessAutoApplyRequested; if (CommonSettings.showGpu.main) { diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 9ca53df60..a7b75922a 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1078,7 +1078,7 @@ typedef struct // true - The emulator itself will apply the master brightness. This is the default option. // false - The output framebuffer will not have master brightness applied. Clients will need to // apply the master brightness themselves in a post-processing pass. Clients should use - // the isMasterBrightnessApplied, masterBrightnessMode, masterBrightnessIntensity and + // the needApplyMasterBrightness, masterBrightnessMode, masterBrightnessIntensity and // isDisplayEnabled properties to determine how to apply the master brightness on their // end. @@ -1107,10 +1107,10 @@ typedef struct // true - The display performed a custom-sized render. // false - The display performed a native-sized render. - bool isMasterBrightnessApplied[2]; // Reports if a display has master brightness applied. This will be false if the user requested to - // turn off auto-apply via GPUSubsystem::SetWillAutoApplyMasterBrightness(), or if the NDS applied - // a master brightness intensity of 0 for all lines. - GPUMasterBrightMode masterBrightnessMode[2][GPU_FRAMEBUFFER_NATIVE_HEIGHT]; // The master brightness mode of each display line. + bool needApplyMasterBrightness[2]; // Reports if a display still needs to apply the master brightness. This will be true if the + // isMasterBrightnessAutoApplyRequested flag is false and if the NDS has a master brightness + // intensity of non-zero for at least one line. + u8 masterBrightnessMode[2][GPU_FRAMEBUFFER_NATIVE_HEIGHT]; // The master brightness mode of each display line. u8 masterBrightnessIntensity[2][GPU_FRAMEBUFFER_NATIVE_HEIGHT]; // The master brightness intensity of each display line. } NDSDisplayInfo;