From 3a000b68fdfb24a888764710221d6e9e61dcf35b Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 2 Oct 2017 14:55:50 -0500 Subject: [PATCH] re #59 - abuse accelerated masterbrightness processor to crudely implement LCD backlight for DD display methods --- desmume/src/frontend/windows/main.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 3886dc259..13702eab0 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -1639,7 +1639,7 @@ static void OGL_DoDisplay() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, video.width, video.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, video.finalBuffer()); } else - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, video.width,video.height,0,GL_BGRA,GL_UNSIGNED_BYTE,video.finalBuffer()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, video.width, video.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, video.finalBuffer()); //the ds screen fills the texture entirely, so we dont have garbage at edge to worry about, //but we need to make sure this is clamped for when filtering is selected @@ -1969,6 +1969,9 @@ static void DoDisplay(bool firstTime) { Lock lock (win_backbuffer_sync); + bool ddhw = (GetStyle()&DWS_DDRAW_HW)!=0; + bool ddsw = (GetStyle()&DWS_DDRAW_SW)!=0; + if(displayPostponeType && !displayNoPostponeNext && (displayPostponeType < 0 || timeGetTime() < displayPostponeUntil)) return; displayNoPostponeNext = false; @@ -1979,6 +1982,23 @@ static void DoDisplay(bool firstTime) else ColorspaceConvertBuffer888XTo8888Opaque((u32*)video.srcBuffer, video.buffer, video.srcBufferSize / 4); + if(ddhw || ddsw) + { + const NDSDisplayInfo &displayInfo = GPU->GetDisplayInfo(); + + for(int screen=0;screen<2;screen++) + { + const GLfloat backlightIntensity = displayInfo.backlightIntensity[screen]; + if(backlightIntensity == 1.0f) continue; + + //abuse accelerated masterbrightness algorithm for this + const int factor = 16-backlightIntensity*16; + const u32 screenSize = 256*video.prescaleHD*192*video.prescaleHD; + u32* dst = video.buffer + screenSize*screen; + GPU->GetEngineMain()->ApplyMasterBrightness(dst,screenSize,GPUMasterBrightMode_Down,(u8)factor); + } + } + if(firstTime) { //on single core systems, draw straight to the screen @@ -2016,9 +2036,8 @@ static void DoDisplay(bool firstTime) aggDraw.hud->clear(); } - bool hw = (GetStyle()&DWS_DDRAW_HW)!=0; - bool sw = (GetStyle()&DWS_DDRAW_SW)!=0; - if(hw || sw) + + if(ddhw || ddsw) { gldisplay.kill(); DD_DoDisplay();