From 481bf0647f1ef64128572de14c7a18d839971935 Mon Sep 17 00:00:00 2001 From: OV2 Date: Wed, 2 Mar 2011 23:13:02 +0100 Subject: [PATCH] Win32: rework hi-res blending Only blend on filters that do not blend themself. --- win32/render.cpp | 90 ++++++++++++++++++++++++++++------------- win32/render.h | 8 +--- win32/win32.cpp | 9 +---- win32/win32_display.cpp | 7 ---- win32/win32_display.h | 1 - win32/wsnes9x.cpp | 2 +- 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/win32/render.cpp b/win32/render.cpp index e1c8b25c..57ab5530 100644 --- a/win32/render.cpp +++ b/win32/render.cpp @@ -220,15 +220,21 @@ void RenderBlarggNTSCComposite(SSurface Src, SSurface Dst, RECT *); void RenderBlarggNTSCSvideo(SSurface Src, SSurface Dst, RECT *); void RenderBlarggNTSCRgb(SSurface Src, SSurface Dst, RECT *); void RenderBlarggNTSC(SSurface Src, SSurface Dst, RECT *); +void RenderMergeHires(void *src, int srcPitch , void* dst, int dstPitch, unsigned int width, unsigned int height); +void InitLUTsWin32(void); // Contains the pointer to the now active render method -TRenderMethod RenderMethod = RenderPlain; -TRenderMethod RenderMethodHiRes = RenderPlain; +typedef void (*TRenderMethod)( SSurface Src, SSurface Dst, RECT *); +TRenderMethod _RenderMethod = RenderPlain; +TRenderMethod _RenderMethodHiRes = RenderPlain; // Used as change log static uint8 ChangeLog1 [EXT_PITCH * MAX_SNES_HEIGHT]; static uint8 ChangeLog2 [EXT_PITCH * MAX_SNES_HEIGHT]; static uint8 ChangeLog3 [EXT_PITCH * MAX_SNES_HEIGHT]; +BYTE *BlendBuf = NULL; +BYTE *BlendBuffer = NULL; + uint8 *ChangeLog [3] = { ChangeLog1, ChangeLog2, ChangeLog3 }; @@ -237,6 +243,11 @@ START_EXTERN_C uint8 snes9x_clear_change_log = 0; END_EXTERN_C +enum BlarggMode { UNINITIALIZED,BLARGGCOMPOSITE,BLARGGSVIDEO,BLARGGRGB }; + +snes_ntsc_t *ntsc = NULL; +BlarggMode blarggMode = UNINITIALIZED; + TRenderMethod FilterToMethod(RenderFilter filterID) { switch(filterID) @@ -381,15 +392,30 @@ inline static bool GetFilter32BitSupport(RenderFilter filterID) } } +inline static bool GetFilterBlendSupport(RenderFilter filterID) +{ + switch(filterID) + { + case FILTER_SIMPLE1X: + case FILTER_BLARGGCOMP: + case FILTER_BLARGGSVID: + case FILTER_BLARGGRGB: + return true; + + default: + return false; + } +} + void SelectRenderMethod() { - TRenderMethod OldRenderMethod = RenderMethod; - TRenderMethod OldRenderMethodHiRes = RenderMethodHiRes; + TRenderMethod OldRenderMethod = _RenderMethod; + TRenderMethod OldRenderMethodHiRes = _RenderMethodHiRes; - RenderMethod = FilterToMethod(GUI.Scale); - RenderMethodHiRes = FilterToMethod(GUI.ScaleHiRes); + _RenderMethod = FilterToMethod(GUI.Scale); + _RenderMethodHiRes = FilterToMethod(GUI.ScaleHiRes); - if (OldRenderMethod != RenderMethod || OldRenderMethodHiRes != RenderMethodHiRes) + if (OldRenderMethod != _RenderMethod || OldRenderMethodHiRes != _RenderMethodHiRes) snes9x_clear_change_log = GUI.NumFlipFrames; GUI.DepthConverted = !GUI.NeedDepthConvert; @@ -402,6 +428,32 @@ void SelectRenderMethod() } } +void RenderMethod(SSurface Src, SSurface Dst, RECT * rect) +{ + if(Src.Height > SNES_HEIGHT_EXTENDED || Src.Width == 512) { + if(GUI.BlendHiRes && Src.Width == 512 && !GetFilterBlendSupport(GUI.ScaleHiRes)) { + RenderMergeHires(Src.Surface,Src.Pitch,BlendBuffer,EXT_PITCH,Src.Width,Src.Height); + Src.Surface = BlendBuffer; + } + _RenderMethodHiRes(Src,Dst,rect); + } else { + _RenderMethod(Src,Dst,rect); + } +} + +void InitRenderFilters(void) +{ + InitLUTsWin32(); + if(!ntsc) { + ntsc = new snes_ntsc_t; + } + if(!BlendBuf) { + BlendBuf = new BYTE [EXT_PITCH * EXT_HEIGHT]; + BlendBuffer = BlendBuf + EXT_OFFSET; + memset(BlendBuf, 0, EXT_PITCH * EXT_HEIGHT); + } +} + #define R5G6B5 // windows port uses RGB565 #ifdef R5G6B5 @@ -550,15 +602,12 @@ inline void SetRect(RECT* rect, int width, int height, int scale) } #define AVERAGE_565(el0, el1) (((el0) & (el1)) + ((((el0) ^ (el1)) & 0xF7DE) >> 1)) -void RenderMergeHires(void *src, void* dst, int pitch, unsigned int &width, unsigned int &height) +void RenderMergeHires(void *src, int srcPitch , void* dst, int dstPitch, unsigned int width, unsigned int height) { - if (width <= 256) - return; - for (register int y = 0; y < height; y++) { - register uint16 *input = (uint16 *) ((uint8 *) src + y * pitch); - register uint16 *output = (uint16 *) ((uint8 *) dst + y * pitch); + register uint16 *input = (uint16 *) ((uint8 *) src + y * srcPitch); + register uint16 *output = (uint16 *) ((uint8 *) dst + y * dstPitch); register uint16 l, r; l = 0; @@ -2538,17 +2587,8 @@ void RenderSimple4X( SSurface Src, SSurface Dst, RECT *rect) } } - -enum BlarggMode { UNINITIALIZED,BLARGGCOMPOSITE,BLARGGSVIDEO,BLARGGRGB }; - -snes_ntsc_t *ntsc = NULL; -BlarggMode blarggMode = UNINITIALIZED; - void RenderBlarggNTSCComposite( SSurface Src, SSurface Dst, RECT *rect) { - if(!ntsc) { - ntsc = (snes_ntsc_t *)malloc(sizeof(snes_ntsc_t)); - } if(blarggMode!=BLARGGCOMPOSITE) { snes_ntsc_setup_t setup = snes_ntsc_composite; setup.merge_fields = 1; @@ -2560,9 +2600,6 @@ void RenderBlarggNTSCComposite( SSurface Src, SSurface Dst, RECT *rect) void RenderBlarggNTSCSvideo( SSurface Src, SSurface Dst, RECT *rect) { - if(!ntsc) { - ntsc = (snes_ntsc_t *)malloc(sizeof(snes_ntsc_t)); - } if(blarggMode!=BLARGGSVIDEO) { snes_ntsc_setup_t setup = snes_ntsc_svideo; setup.merge_fields = 1; @@ -2574,9 +2611,6 @@ void RenderBlarggNTSCSvideo( SSurface Src, SSurface Dst, RECT *rect) void RenderBlarggNTSCRgb( SSurface Src, SSurface Dst, RECT *rect) { - if(!ntsc) { - ntsc = (snes_ntsc_t *)malloc(sizeof(snes_ntsc_t)); - } if(blarggMode!=BLARGGRGB) { snes_ntsc_setup_t setup = snes_ntsc_rgb; setup.merge_fields = 1; diff --git a/win32/render.h b/win32/render.h index 6d760443..292562ef 100644 --- a/win32/render.h +++ b/win32/render.h @@ -191,13 +191,9 @@ struct SSurface { unsigned int Width, Height; }; -typedef void (*TRenderMethod)( SSurface Src, SSurface Dst, RECT *); +void RenderMethod(SSurface Src, SSurface Dst, RECT *); void SelectRenderMethod(); -void InitLUTsWin32(); -void RenderMergeHires(void *src, void* dst, int pitch, unsigned int &width, unsigned int &height); - -extern TRenderMethod RenderMethod; -extern TRenderMethod RenderMethodHiRes; +void InitRenderFilters(); #endif diff --git a/win32/win32.cpp b/win32/win32.cpp index cb09edf5..f444c56f 100644 --- a/win32/win32.cpp +++ b/win32/win32.cpp @@ -204,9 +204,7 @@ #include BYTE *ScreenBuf = NULL; -BYTE *ScreenBufBlend = NULL; BYTE *ScreenBuffer = NULL; -BYTE *ScreenBufferBlend = NULL; struct SJoyState Joystick [16]; uint32 joypads [8]; @@ -979,12 +977,8 @@ void InitSnes9X( void) Memory.PostRomInitFunc = S9xPostRomInit; ScreenBuf = new BYTE [EXT_PITCH * EXT_HEIGHT]; - ScreenBufBlend = new BYTE [EXT_PITCH * EXT_HEIGHT]; - ScreenBuffer = ScreenBuf + EXT_OFFSET; - ScreenBufferBlend = ScreenBufBlend + EXT_OFFSET; memset (ScreenBuf, 0, EXT_PITCH * EXT_HEIGHT); - memset (ScreenBufBlend, 0, EXT_PITCH * EXT_HEIGHT); GFX.Pitch = EXT_PITCH; GFX.RealPPL = EXT_PITCH; @@ -1008,8 +1002,7 @@ void DeinitS9x() { if(ScreenBuf) delete [] ScreenBuf; - if(ScreenBufBlend) - delete [] ScreenBufBlend; + DeleteCriticalSection(&GUI.SoundCritSect); CoUninitialize(); if(GUI.GunSight) diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index 45c55272..bc385c2a 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -222,13 +222,6 @@ void WinRefreshDisplay(void) SelectRenderMethod (); - Src.Surface = (BYTE *)GFX.Screen; - - if(Src.Width > SNES_WIDTH && GUI.BlendHiRes) { - RenderMergeHires(Src.Surface,ScreenBufferBlend,Src.Pitch,Src.Width,Src.Height); - Src.Surface = ScreenBufferBlend; - } - S9xDisplayOutput->Render(Src); GUI.FlipCounter++; } diff --git a/win32/win32_display.h b/win32/win32_display.h index b7f50fda..1ee30fbb 100644 --- a/win32/win32_display.h +++ b/win32/win32_display.h @@ -183,7 +183,6 @@ #include #define IsHiRes(x) ((x.Height > SNES_HEIGHT_EXTENDED || x.Width == 512)) -#define RenderMethod (IsHiRes(Src) ? RenderMethodHiRes : RenderMethod) #define CurrentScale (IsHiRes(Src) ? GUI.ScaleHiRes : GUI.Scale) void WinRefreshDisplay(void); diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index 115ddc30..70a380d4 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -3217,7 +3217,7 @@ int WINAPI WinMain( SetMenu (GUI.hWnd, NULL); } - InitLUTsWin32(); // init win hq2x + InitRenderFilters(); GUI.ControlForced = 0xff;