From d0ab5a10ecda925e8fd5641aef3fdd9e035492f8 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 8 Feb 2016 20:15:16 +0100 Subject: [PATCH] added test code for using bitmaps instead of textures for global animations --- src/libgame/sdl.c | 26 ++++++++++++++++++++++++-- src/libgame/sdl.h | 2 ++ src/libgame/system.c | 33 +++++++++++++++++++++++++++++++++ src/libgame/system.h | 6 ++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 0759b549..182126f1 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -54,6 +54,7 @@ static void UpdateScreen(SDL_Rect *rect) { static unsigned int update_screen_delay = 0; unsigned int update_screen_delay_value = 20; /* (milliseconds) */ + SDL_Surface *screen = backbuffer->surface; if (limit_screen_updates && !DelayReached(&update_screen_delay, update_screen_delay_value)) @@ -78,10 +79,29 @@ static void UpdateScreen(SDL_Rect *rect) } #endif +#if USE_FINAL_SCREEN_BITMAP + if (gfx.final_screen_bitmap != NULL) // may not be initialized yet + { + // !!! TEST !!! + // draw global animations using bitmaps instead of using textures + // to prevent texture scaling artefacts (this is potentially slower) + + BlitBitmap(backbuffer, gfx.final_screen_bitmap, 0, 0, + gfx.win_xsize, gfx.win_ysize, 0, 0); + + // copy global animations to render target buffer, if defined + if (gfx.draw_global_anim_function != NULL) + gfx.draw_global_anim_function(); + + screen = gfx.final_screen_bitmap->surface; + + // force full window redraw + rect = NULL; + } +#endif + #if defined(TARGET_SDL2) #if USE_RENDERER - SDL_Surface *screen = backbuffer->surface; - if (rect) { int bytes_x = screen->pitch / video.width; @@ -105,9 +125,11 @@ static void UpdateScreen(SDL_Rect *rect) // copy backbuffer to render target buffer SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); +#if !USE_FINAL_SCREEN_BITMAP // copy global animations to render target buffer, if defined if (gfx.draw_global_anim_function != NULL) gfx.draw_global_anim_function(); +#endif // show render target buffer on screen SDL_RenderPresent(sdl_renderer); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index ad21926c..7cc3b459 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -58,6 +58,8 @@ #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE #endif +#define USE_FINAL_SCREEN_BITMAP FALSE + #define CURSOR_MAX_WIDTH 32 #define CURSOR_MAX_HEIGHT 32 diff --git a/src/libgame/system.c b/src/libgame/system.c index a1fbad08..d1cb4d35 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -207,6 +207,9 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize) gfx.background_bitmap_mask = REDRAW_NONE; ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); +#if USE_FINAL_SCREEN_BITMAP + ReCreateBitmap(&gfx.final_screen_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); +#endif } void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) @@ -742,6 +745,36 @@ void BlitTextureMasked(Bitmap *bitmap, BLIT_MASKED); } +void BlitToScreen(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + +#if USE_FINAL_SCREEN_BITMAP + BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y, + width, height, dst_x, dst_y); +#else + BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y); +#endif +} + +void BlitToScreenMasked(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + +#if USE_FINAL_SCREEN_BITMAP + BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y, + width, height, dst_x, dst_y); +#else + BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y); +#endif +} + void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y) { diff --git a/src/libgame/system.h b/src/libgame/system.h index a27653da..875a6540 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -804,6 +804,10 @@ struct GfxInfo Bitmap *background_bitmap; int background_bitmap_mask; +#if USE_FINAL_SCREEN_BITMAP + Bitmap *final_screen_bitmap; +#endif + boolean clipping_enabled; int clip_x, clip_y; int clip_width, clip_height; @@ -1351,6 +1355,8 @@ boolean DrawingAreaChanged(); void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int, int); void BlitTexture(Bitmap *, int, int, int, int, int, int); void BlitTextureMasked(Bitmap *, int, int, int, int, int, int); +void BlitToScreen(Bitmap *, int, int, int, int, int, int); +void BlitToScreenMasked(Bitmap *, int, int, int, int, int, int); void DrawSimpleBlackLine(Bitmap *, int, int, int, int); void DrawSimpleWhiteLine(Bitmap *, int, int, int, int); void DrawLines(Bitmap *, struct XY *, int, Pixel); -- 2.34.1