mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Simplify Flip Mode rendering code with SDL_RenderCopyEx
Previously, Flip Mode rendering had to be complicated and allocate another buffer to call FlipSurfaceVerticle, and it was just a mess. Instead, why not just do SDL_RenderCopyEx, and let SDL flip the screen for us? This ends up pretty massively simplifying the rendering code.
This commit is contained in:
parent
23a2f57a70
commit
c58c357a81
4 changed files with 29 additions and 70 deletions
|
@ -3038,41 +3038,14 @@ void Graphics::setcol( int t )
|
|||
|
||||
void Graphics::menuoffrender(void)
|
||||
{
|
||||
SDL_Rect offsetRect1;
|
||||
setRect (offsetRect1, 0, 0, backBuffer->w ,backBuffer->h);
|
||||
const int usethisoffset = lerp(oldmenuoffset, menuoffset);
|
||||
SDL_Rect offsetRect = {0, usethisoffset, backBuffer->w, backBuffer->h};
|
||||
|
||||
//put the back buffer in the menubuffer
|
||||
BlitSurfaceStandard(backBuffer, NULL, menubuffer, NULL);
|
||||
BlitSurfaceStandard(tempBuffer, NULL, backBuffer, NULL);
|
||||
BlitSurfaceStandard(menubuffer, NULL, backBuffer, &offsetRect);
|
||||
|
||||
|
||||
|
||||
int usethisoffset = lerp(oldmenuoffset, menuoffset);
|
||||
if(flipmode)
|
||||
{
|
||||
SDL_Surface* tempbufferFlipped = FlipSurfaceVerticle(tempBuffer);
|
||||
//put the stored backbuffer in the backbuffer.
|
||||
ClearSurface(backBuffer);
|
||||
BlitSurfaceStandard(tempbufferFlipped, NULL, backBuffer, NULL);
|
||||
SDL_FreeSurface(tempbufferFlipped);
|
||||
SDL_Rect offsetRect;
|
||||
setRect (offsetRect, 0, -usethisoffset, backBuffer->w ,backBuffer->h);
|
||||
SDL_Surface* temp = FlipSurfaceVerticle(menubuffer);
|
||||
BlitSurfaceStandard(temp,NULL,backBuffer,&offsetRect);
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
//put the stored backbuffer in the backbuffer.
|
||||
BlitSurfaceStandard(tempBuffer, NULL, backBuffer, NULL);
|
||||
|
||||
SDL_Rect offsetRect;
|
||||
setRect (offsetRect, 0, usethisoffset, backBuffer->w ,backBuffer->h);
|
||||
BlitSurfaceStandard(menubuffer,NULL,backBuffer,&offsetRect);
|
||||
}
|
||||
|
||||
SDL_Rect rect;
|
||||
setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
|
||||
screenbuffer->UpdateScreen(backBuffer,&rect);
|
||||
screenbuffer->UpdateScreen(backBuffer, NULL);
|
||||
ClearSurface(backBuffer);
|
||||
}
|
||||
|
||||
|
@ -3192,20 +3165,8 @@ void Graphics::flashlight(void)
|
|||
|
||||
void Graphics::screenshake(void)
|
||||
{
|
||||
if(flipmode)
|
||||
{
|
||||
SDL_Rect shakeRect;
|
||||
setRect(shakeRect,screenshake_x, screenshake_y, backBuffer->w, backBuffer->h);
|
||||
SDL_Surface* flipBackBuffer = FlipSurfaceVerticle(backBuffer);
|
||||
screenbuffer->UpdateScreen( flipBackBuffer, &shakeRect);
|
||||
SDL_FreeSurface(flipBackBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect shakeRect;
|
||||
setRect(shakeRect,screenshake_x, screenshake_y, backBuffer->w, backBuffer->h);
|
||||
screenbuffer->UpdateScreen( backBuffer, &shakeRect);
|
||||
}
|
||||
SDL_Rect shakeRect = {screenshake_x, screenshake_y, backBuffer->w, backBuffer->h};
|
||||
screenbuffer->UpdateScreen(backBuffer, &shakeRect);
|
||||
|
||||
ClearSurface(backBuffer);
|
||||
}
|
||||
|
@ -3218,27 +3179,12 @@ void Graphics::updatescreenshake(void)
|
|||
|
||||
void Graphics::render(void)
|
||||
{
|
||||
if(screenbuffer == NULL)
|
||||
if (screenbuffer == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(flipmode)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
|
||||
SDL_Surface* tempsurface = FlipSurfaceVerticle(backBuffer);
|
||||
if(tempsurface != NULL)
|
||||
{
|
||||
screenbuffer->UpdateScreen( tempsurface, &rect);
|
||||
SDL_FreeSurface(tempsurface);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect;
|
||||
setRect(rect, 0, 0, backBuffer->w, backBuffer->h);
|
||||
screenbuffer->UpdateScreen( backBuffer, &rect);
|
||||
}
|
||||
|
||||
screenbuffer->UpdateScreen(backBuffer, NULL);
|
||||
}
|
||||
|
||||
void Graphics::renderwithscreeneffects(void)
|
||||
|
|
|
@ -306,19 +306,32 @@ const SDL_PixelFormat* Screen::GetFormat(void)
|
|||
return m_screen->format;
|
||||
}
|
||||
|
||||
void Screen::FlipScreen(void)
|
||||
void Screen::FlipScreen(const bool flipmode)
|
||||
{
|
||||
SDL_RendererFlip flip_flags;
|
||||
if (flipmode)
|
||||
{
|
||||
flip_flags = SDL_FLIP_VERTICAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
flip_flags = SDL_FLIP_NONE;
|
||||
}
|
||||
|
||||
SDL_UpdateTexture(
|
||||
m_screenTexture,
|
||||
NULL,
|
||||
m_screen->pixels,
|
||||
m_screen->pitch
|
||||
);
|
||||
SDL_RenderCopy(
|
||||
SDL_RenderCopyEx(
|
||||
m_renderer,
|
||||
m_screenTexture,
|
||||
isFiltered ? &filterSubrect : NULL,
|
||||
NULL
|
||||
NULL,
|
||||
0.0,
|
||||
NULL,
|
||||
flip_flags
|
||||
);
|
||||
SDL_RenderPresent(m_renderer);
|
||||
SDL_RenderClear(m_renderer);
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
void GetWindowSize(int* x, int* y);
|
||||
|
||||
void UpdateScreen(SDL_Surface* buffer, SDL_Rect* rect);
|
||||
void FlipScreen(void);
|
||||
void FlipScreen(bool flipmode);
|
||||
|
||||
const SDL_PixelFormat* GetFormat(void);
|
||||
|
||||
|
|
|
@ -750,7 +750,7 @@ static void inline deltaloop(void)
|
|||
{
|
||||
implfunc->func();
|
||||
|
||||
gameScreen.FlipScreen();
|
||||
gameScreen.FlipScreen(graphics.flipmode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -781,7 +781,7 @@ static void unfocused_run(void)
|
|||
#undef FLIP
|
||||
}
|
||||
graphics.render();
|
||||
gameScreen.FlipScreen();
|
||||
gameScreen.FlipScreen(graphics.flipmode);
|
||||
//We are minimised, so lets put a bit of a delay to save CPU
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_Delay(100);
|
||||
|
|
Loading…
Reference in a new issue