Win32: rework hi-res blending

Only blend on filters that do not blend themself.
This commit is contained in:
OV2 2011-03-02 23:13:02 +01:00
parent 41dc2fbb61
commit 481bf0647f
6 changed files with 66 additions and 51 deletions

View File

@ -220,15 +220,21 @@ void RenderBlarggNTSCComposite(SSurface Src, SSurface Dst, RECT *);
void RenderBlarggNTSCSvideo(SSurface Src, SSurface Dst, RECT *); void RenderBlarggNTSCSvideo(SSurface Src, SSurface Dst, RECT *);
void RenderBlarggNTSCRgb(SSurface Src, SSurface Dst, RECT *); void RenderBlarggNTSCRgb(SSurface Src, SSurface Dst, RECT *);
void RenderBlarggNTSC(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 // Contains the pointer to the now active render method
TRenderMethod RenderMethod = RenderPlain; typedef void (*TRenderMethod)( SSurface Src, SSurface Dst, RECT *);
TRenderMethod RenderMethodHiRes = RenderPlain; TRenderMethod _RenderMethod = RenderPlain;
TRenderMethod _RenderMethodHiRes = RenderPlain;
// Used as change log // Used as change log
static uint8 ChangeLog1 [EXT_PITCH * MAX_SNES_HEIGHT]; static uint8 ChangeLog1 [EXT_PITCH * MAX_SNES_HEIGHT];
static uint8 ChangeLog2 [EXT_PITCH * MAX_SNES_HEIGHT]; static uint8 ChangeLog2 [EXT_PITCH * MAX_SNES_HEIGHT];
static uint8 ChangeLog3 [EXT_PITCH * MAX_SNES_HEIGHT]; static uint8 ChangeLog3 [EXT_PITCH * MAX_SNES_HEIGHT];
BYTE *BlendBuf = NULL;
BYTE *BlendBuffer = NULL;
uint8 *ChangeLog [3] = { uint8 *ChangeLog [3] = {
ChangeLog1, ChangeLog2, ChangeLog3 ChangeLog1, ChangeLog2, ChangeLog3
}; };
@ -237,6 +243,11 @@ START_EXTERN_C
uint8 snes9x_clear_change_log = 0; uint8 snes9x_clear_change_log = 0;
END_EXTERN_C END_EXTERN_C
enum BlarggMode { UNINITIALIZED,BLARGGCOMPOSITE,BLARGGSVIDEO,BLARGGRGB };
snes_ntsc_t *ntsc = NULL;
BlarggMode blarggMode = UNINITIALIZED;
TRenderMethod FilterToMethod(RenderFilter filterID) TRenderMethod FilterToMethod(RenderFilter filterID)
{ {
switch(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() void SelectRenderMethod()
{ {
TRenderMethod OldRenderMethod = RenderMethod; TRenderMethod OldRenderMethod = _RenderMethod;
TRenderMethod OldRenderMethodHiRes = RenderMethodHiRes; TRenderMethod OldRenderMethodHiRes = _RenderMethodHiRes;
RenderMethod = FilterToMethod(GUI.Scale); _RenderMethod = FilterToMethod(GUI.Scale);
RenderMethodHiRes = FilterToMethod(GUI.ScaleHiRes); _RenderMethodHiRes = FilterToMethod(GUI.ScaleHiRes);
if (OldRenderMethod != RenderMethod || OldRenderMethodHiRes != RenderMethodHiRes) if (OldRenderMethod != _RenderMethod || OldRenderMethodHiRes != _RenderMethodHiRes)
snes9x_clear_change_log = GUI.NumFlipFrames; snes9x_clear_change_log = GUI.NumFlipFrames;
GUI.DepthConverted = !GUI.NeedDepthConvert; 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 #define R5G6B5 // windows port uses RGB565
#ifdef R5G6B5 #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)) #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++) for (register int y = 0; y < height; y++)
{ {
register uint16 *input = (uint16 *) ((uint8 *) src + y * pitch); register uint16 *input = (uint16 *) ((uint8 *) src + y * srcPitch);
register uint16 *output = (uint16 *) ((uint8 *) dst + y * pitch); register uint16 *output = (uint16 *) ((uint8 *) dst + y * dstPitch);
register uint16 l, r; register uint16 l, r;
l = 0; 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) void RenderBlarggNTSCComposite( SSurface Src, SSurface Dst, RECT *rect)
{ {
if(!ntsc) {
ntsc = (snes_ntsc_t *)malloc(sizeof(snes_ntsc_t));
}
if(blarggMode!=BLARGGCOMPOSITE) { if(blarggMode!=BLARGGCOMPOSITE) {
snes_ntsc_setup_t setup = snes_ntsc_composite; snes_ntsc_setup_t setup = snes_ntsc_composite;
setup.merge_fields = 1; setup.merge_fields = 1;
@ -2560,9 +2600,6 @@ void RenderBlarggNTSCComposite( SSurface Src, SSurface Dst, RECT *rect)
void RenderBlarggNTSCSvideo( 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) { if(blarggMode!=BLARGGSVIDEO) {
snes_ntsc_setup_t setup = snes_ntsc_svideo; snes_ntsc_setup_t setup = snes_ntsc_svideo;
setup.merge_fields = 1; setup.merge_fields = 1;
@ -2574,9 +2611,6 @@ void RenderBlarggNTSCSvideo( SSurface Src, SSurface Dst, RECT *rect)
void RenderBlarggNTSCRgb( 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) { if(blarggMode!=BLARGGRGB) {
snes_ntsc_setup_t setup = snes_ntsc_rgb; snes_ntsc_setup_t setup = snes_ntsc_rgb;
setup.merge_fields = 1; setup.merge_fields = 1;

View File

@ -191,13 +191,9 @@ struct SSurface {
unsigned int Width, Height; unsigned int Width, Height;
}; };
typedef void (*TRenderMethod)( SSurface Src, SSurface Dst, RECT *); void RenderMethod(SSurface Src, SSurface Dst, RECT *);
void SelectRenderMethod(); void SelectRenderMethod();
void InitLUTsWin32(); void InitRenderFilters();
void RenderMergeHires(void *src, void* dst, int pitch, unsigned int &width, unsigned int &height);
extern TRenderMethod RenderMethod;
extern TRenderMethod RenderMethodHiRes;
#endif #endif

View File

@ -204,9 +204,7 @@
#include <math.h> #include <math.h>
BYTE *ScreenBuf = NULL; BYTE *ScreenBuf = NULL;
BYTE *ScreenBufBlend = NULL;
BYTE *ScreenBuffer = NULL; BYTE *ScreenBuffer = NULL;
BYTE *ScreenBufferBlend = NULL;
struct SJoyState Joystick [16]; struct SJoyState Joystick [16];
uint32 joypads [8]; uint32 joypads [8];
@ -979,12 +977,8 @@ void InitSnes9X( void)
Memory.PostRomInitFunc = S9xPostRomInit; Memory.PostRomInitFunc = S9xPostRomInit;
ScreenBuf = new BYTE [EXT_PITCH * EXT_HEIGHT]; ScreenBuf = new BYTE [EXT_PITCH * EXT_HEIGHT];
ScreenBufBlend = new BYTE [EXT_PITCH * EXT_HEIGHT];
ScreenBuffer = ScreenBuf + EXT_OFFSET; ScreenBuffer = ScreenBuf + EXT_OFFSET;
ScreenBufferBlend = ScreenBufBlend + EXT_OFFSET;
memset (ScreenBuf, 0, EXT_PITCH * EXT_HEIGHT); memset (ScreenBuf, 0, EXT_PITCH * EXT_HEIGHT);
memset (ScreenBufBlend, 0, EXT_PITCH * EXT_HEIGHT);
GFX.Pitch = EXT_PITCH; GFX.Pitch = EXT_PITCH;
GFX.RealPPL = EXT_PITCH; GFX.RealPPL = EXT_PITCH;
@ -1008,8 +1002,7 @@ void DeinitS9x()
{ {
if(ScreenBuf) if(ScreenBuf)
delete [] ScreenBuf; delete [] ScreenBuf;
if(ScreenBufBlend)
delete [] ScreenBufBlend;
DeleteCriticalSection(&GUI.SoundCritSect); DeleteCriticalSection(&GUI.SoundCritSect);
CoUninitialize(); CoUninitialize();
if(GUI.GunSight) if(GUI.GunSight)

View File

@ -222,13 +222,6 @@ void WinRefreshDisplay(void)
SelectRenderMethod (); 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); S9xDisplayOutput->Render(Src);
GUI.FlipCounter++; GUI.FlipCounter++;
} }

View File

@ -183,7 +183,6 @@
#include <vector> #include <vector>
#define IsHiRes(x) ((x.Height > SNES_HEIGHT_EXTENDED || x.Width == 512)) #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) #define CurrentScale (IsHiRes(Src) ? GUI.ScaleHiRes : GUI.Scale)
void WinRefreshDisplay(void); void WinRefreshDisplay(void);

View File

@ -3217,7 +3217,7 @@ int WINAPI WinMain(
SetMenu (GUI.hWnd, NULL); SetMenu (GUI.hWnd, NULL);
} }
InitLUTsWin32(); // init win hq2x InitRenderFilters();
GUI.ControlForced = 0xff; GUI.ControlForced = 0xff;