From 9611be326745611fafae4cf5bf4a473ab68721b9 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 27 Nov 2018 02:50:16 +0100 Subject: [PATCH] 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. --- src/utils.c | 13 +++++++++++++ src/utils.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/utils.c b/src/utils.c index 646d9d1..724a589 100644 --- a/src/utils.c +++ b/src/utils.c @@ -128,6 +128,19 @@ SYMBOL_EXPORT void DrawCenteredTintedScaled(ALLEGRO_BITMAP* bitmap, ALLEGRO_COLO 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 */ 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), diff --git a/src/utils.h b/src/utils.h index 497c836..ea2ab61 100644 --- a/src/utils.h +++ b/src/utils.h @@ -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 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); void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);