add ClearToColor util for clearing whole target bitmap, not just the clipping rectangle

Clearing the clipping rectangle can be very costly, while clearing a whole texture is often free.
This commit is contained in:
Sebastian Krzyszkowiak 2018-11-27 02:50:16 +01:00
parent d20eb28814
commit 9611be3267
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 16 additions and 0 deletions

View file

@ -128,6 +128,19 @@ SYMBOL_EXPORT void DrawCenteredTintedScaled(ALLEGRO_BITMAP* bitmap, ALLEGRO_COLO
x, y, sx, sy, 0, flags); x, y, sx, sy, 0, flags);
} }
SYMBOL_EXPORT void ClearToColor(struct Game* game, ALLEGRO_COLOR color) {
ALLEGRO_BITMAP* target = al_get_target_bitmap();
if (GetFramebuffer(game) == target && al_get_parent_bitmap(target) == al_get_backbuffer(game->display)) {
al_set_target_backbuffer(game->display);
}
int x, y, w, h;
al_get_clipping_rectangle(&x, &y, &w, &h);
al_reset_clipping_rectangle();
al_clear_to_color(color);
al_set_clipping_rectangle(x, y, w, h);
al_set_target_bitmap(target);
}
/* linear filtering code written by SiegeLord */ /* linear filtering code written by SiegeLord */
SYMBOL_EXPORT ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) { SYMBOL_EXPORT ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) {
return al_map_rgba_f(c1.r + frac * (c2.r - c1.r), return al_map_rgba_f(c1.r + frac * (c2.r - c1.r),

View file

@ -56,6 +56,9 @@ void DrawCentered(ALLEGRO_BITMAP* bitmap, int x, int y, int flags);
void DrawCenteredScaled(ALLEGRO_BITMAP* bitmap, int x, int y, double sx, double sy, int flags); void DrawCenteredScaled(ALLEGRO_BITMAP* bitmap, int x, int y, double sx, double sy, int flags);
void DrawCenteredTintedScaled(ALLEGRO_BITMAP* bitmap, ALLEGRO_COLOR tint, int x, int y, double sx, double sy, int flags); void DrawCenteredTintedScaled(ALLEGRO_BITMAP* bitmap, ALLEGRO_COLOR tint, int x, int y, double sx, double sy, int flags);
/*! \brief Clears the current target completely, without taking current clipping rectangle into account. */
void ClearToColor(struct Game* game, ALLEGRO_COLOR color);
ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac); ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac);
void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height); void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);