Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed May 19, 2018
1 parent 05fd83e commit 4e13d2e
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/cdogs/grafx_bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,33 @@ void GrafxMakeRandomBackground(
CampaignSettingTerminate(&co->Setting);
}

static void DrawBackgroundWithRenderer(
GraphicsDevice *g, SDL_Renderer *renderer, SDL_Texture *target,
SDL_Texture *src, DrawBuffer *buffer,
const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra);
void GrafxDrawBackground(
GraphicsDevice *g, DrawBuffer *buffer,
const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra)
{
DrawBackgroundWithRenderer(
g, g->gameWindow.renderer, g->bkgTgt, g->bkg, buffer, tint, pos, extra);
if (g->cachedConfig.SecondWindow)
{
DrawBackgroundWithRenderer(
g, g->secondWindow.renderer, g->bkgTgt2, g->bkg2, buffer, tint, pos,
extra);
}
}
static void DrawBackground(
GraphicsDevice *g, SDL_Texture *tTgt, SDL_Texture *t, DrawBuffer *buffer,
Map *map, const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra);
void GrafxDrawBackground(
GraphicsDevice *g, DrawBuffer *buffer,
static void DrawBackgroundWithRenderer(
GraphicsDevice *g, SDL_Renderer *renderer, SDL_Texture *target,
SDL_Texture *src, DrawBuffer *buffer,
const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra)
{
SDL_RendererInfo ri;
if (SDL_GetRendererInfo(g->gameWindow.renderer, &ri) != 0)
if (SDL_GetRendererInfo(renderer, &ri) != 0)
{
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
}
Expand All @@ -80,34 +98,12 @@ void GrafxDrawBackground(
"renderer does not support render to texture");
}
}
if (SDL_SetRenderTarget(g->gameWindow.renderer, g->bkgTgt) != 0)
if (SDL_SetRenderTarget(renderer, target) != 0)
{
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
}
if (g->cachedConfig.SecondWindow)
{
if (SDL_SetRenderTarget(g->secondWindow.renderer, g->bkgTgt2) != 0)
{
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s",
SDL_GetError());
}
DrawBackground(
g, g->bkgTgt, g->bkg, buffer, &gMap, tint,
svec2(pos.x - g->cachedConfig.Res.x / 2, pos.y), extra);
DrawBackground(
g, g->bkgTgt2, g->bkg2, buffer, &gMap, tint,
svec2(pos.x + g->cachedConfig.Res.x / 2, pos.y), extra);
if (SDL_SetRenderTarget(g->secondWindow.renderer, NULL) != 0)
{
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s",
SDL_GetError());
}
}
else
{
DrawBackground(g, g->bkgTgt, g->bkg, buffer, &gMap, tint, pos, extra);
}
if (SDL_SetRenderTarget(g->gameWindow.renderer, NULL) != 0)
DrawBackground(g, target, src, buffer, &gMap, tint, pos, extra);
if (SDL_SetRenderTarget(renderer, NULL) != 0)
{
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
}
Expand Down

0 comments on commit 4e13d2e

Please sign in to comment.