improved pixel rendering

This commit is contained in:
dborth 2012-01-11 18:48:39 +00:00
parent fb508312c7
commit e27bc00241
3 changed files with 56 additions and 60 deletions

View File

@ -37,7 +37,6 @@ bool SaveState (char * filepath, bool silent)
if(!FindDevice(filepath, &device))
return 0;
// save screenshot - I would prefer to do this from gameScreenTex
if(gameScreenPngSize > 0)
{
char screenpath[1024];

View File

@ -57,7 +57,6 @@ static unsigned char texturemem[TEX_WIDTH * TEX_HEIGHT * 4] ATTRIBUTE_ALIGN (32)
static int UpdateVideo = 1;
static bool vmode_60hz = true;
u8 * gameScreenTex = NULL; // a GX texture screen capture of the game
u8 * gameScreenPng = NULL;
int gameScreenPngSize = 0;
@ -191,6 +190,8 @@ static GXRModeObj NTSC_240p =
}
};
static GXRModeObj TV_Custom;
/* TV Modes table */
static GXRModeObj *tvmodes[2] = {
&NTSC_240p, &PAL_240p
@ -411,7 +412,7 @@ UpdateScaling()
}
else // unfiltered and filtered mode
{
xscale = vmode->fbWidth / 2;
xscale = 256;
yscale = vmode->efbHeight / 2;
}
@ -625,6 +626,14 @@ ResetVideo_Emu ()
else
{
rmode = FindVideoMode();
if (!GCSettings.widescreen)
{
memcpy(&TV_Custom, rmode, sizeof(TV_Custom));
rmode = &TV_Custom;
rmode->fbWidth = 512;
}
UpdateSampleRate(48130);
SetSampleRate();
}
@ -641,7 +650,7 @@ ResetVideo_Emu ()
GX_SetDispCopySrc (0, 0, rmode->fbWidth, rmode->efbHeight);
GX_SetDispCopyDst (rmode->fbWidth, rmode->xfbHeight);
GX_SetCopyFilter (rmode->aa, rmode->sample_pattern, (GCSettings.render == 1) ? GX_TRUE : GX_FALSE, rmode->vfilter); // deflicker ON only for filtered mode
GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, (rmode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE, rmode->vfilter);
GX_SetFieldMode (rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
@ -919,16 +928,15 @@ void RenderStereoFrames(unsigned char *XBufLeft, unsigned char *XBufRight)
***************************************************************************/
void TakeScreenshot()
{
int texSize = vmode->fbWidth * vmode->efbHeight * 4;
IMGCTX pngContext = PNGU_SelectImageFromBuffer(savebuffer);
if(gameScreenTex) free(gameScreenTex);
gameScreenTex = (u8 *)memalign(32, texSize);
if(gameScreenTex == NULL) return;
GX_SetTexCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight);
GX_SetTexCopyDst(vmode->fbWidth, vmode->efbHeight, GX_TF_RGBA8, GX_FALSE);
GX_CopyTex(gameScreenTex, GX_FALSE);
GX_PixModeSync();
DCFlushRange(gameScreenTex, texSize);
if (pngContext != NULL)
{
gameScreenPngSize = PNGU_EncodeFromEFB(pngContext, vmode->fbWidth, vmode->efbHeight);
PNGU_ReleaseImageContext(pngContext);
gameScreenPng = (u8 *)malloc(gameScreenPngSize);
memcpy(gameScreenPng, savebuffer, gameScreenPngSize);
}
}
/****************************************************************************

View File

@ -51,8 +51,8 @@ static GuiTrigger * trigA = NULL;
static GuiTrigger * trig2 = NULL;
static GuiButton * btnLogo = NULL;
static GuiImageData * gameScreen = NULL;
static GuiImage * gameScreenImg = NULL;
static GuiImage * bgImg = NULL;
static GuiImage * bgTopImg = NULL;
static GuiImage * bgBottomImg = NULL;
static GuiSound * bgMusic = NULL;
@ -860,11 +860,7 @@ static void WindowCredits(void * ptr)
{
UpdatePads();
if(gameScreenImg)
gameScreenImg->Draw();
else
bgImg->Draw();
gameScreenImg->Draw();
bgBottomImg->Draw();
bgTopImg->Draw();
creditsWindow.Draw();
@ -1440,19 +1436,17 @@ static int MenuGame()
{
if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))
{
if(gameScreenImg)
{
mainWindow->Remove(gameScreenImg);
delete gameScreenImg;
gameScreenImg = NULL;
}
if(gameScreenTex)
{
free(gameScreenTex);
gameScreenTex = NULL;
gameScreenPngSize = 0;
}
bgImg->SetVisible(true);
HaltGui();
mainWindow->Remove(gameScreenImg);
delete gameScreenImg;
delete gameScreen;
gameScreen = NULL;
free(gameScreenPng);
gameScreenPng = NULL;
gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){240, 225, 230, 255});
gameScreenImg->ColorStripe(10);
mainWindow->Insert(gameScreenImg, 0);
ResumeGui();
#ifndef NO_SOUND
bgMusic->Play(); // startup music
#endif
@ -3810,29 +3804,27 @@ MainMenu (int menu)
mainWindow = new GuiWindow(screenwidth, screenheight);
bgImg = new GuiImage(screenwidth, screenheight, (GXColor){240, 225, 230, 255});
bgImg->ColorStripe(10);
mainWindow->Append(bgImg);
if(gameScreenTex)
if(menu == MENU_GAME)
{
IMGCTX pngContext = PNGU_SelectImageFromBuffer(gameScreenPng);
if (pngContext != NULL)
{
gameScreenPngSize = PNGU_EncodeFromGXTexture(pngContext, vmode->fbWidth, vmode->efbHeight, gameScreenTex, 0);
PNGU_ReleaseImageContext(pngContext);
DCFlushRange(gameScreenPng, 512*1024);
}
gameScreenImg = new GuiImage(gameScreenTex, vmode->fbWidth, vmode->efbHeight);
gameScreen = new GuiImageData(gameScreenPng);
gameScreenImg = new GuiImage(gameScreen);
gameScreenImg->SetAlpha(192);
gameScreenImg->ColorStripe(30);
gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth);
if (GCSettings.render > 0 && !GCSettings.widescreen)
gameScreenImg->SetScaleX(screenwidth/(vmode->fbWidth*0.8));
else
gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth);
gameScreenImg->SetScaleY(screenheight/(float)vmode->efbHeight);
mainWindow->Append(gameScreenImg);
bgImg->SetVisible(false);
}
else
{
gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){240, 225, 230, 255});
gameScreenImg->ColorStripe(10);
}
mainWindow->Append(gameScreenImg);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
@ -3970,23 +3962,20 @@ MainMenu (int menu)
#endif
delete btnLogo;
delete bgImg;
delete gameScreenImg;
delete bgTopImg;
delete bgBottomImg;
delete mainWindow;
mainWindow = NULL;
if(gameScreenImg)
if(gameScreen)
delete gameScreen;
if(gameScreenPng)
{
delete gameScreenImg;
gameScreenImg = NULL;
}
if(gameScreenTex)
{
free(gameScreenTex);
gameScreenTex = NULL;
gameScreenPngSize = 0;
free(gameScreenPng);
gameScreenPng = NULL;
}
// wait for keys to be depressed