From e126d0677786bc2a76f4b8dfcbc1be81bd5d9d1b Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 20 Jan 2016 00:12:01 +0100 Subject: [PATCH] added blitting of textures for global animations --- src/libgame/sdl.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/libgame/sdl.h | 1 + src/libgame/system.c | 22 ++++++++++++++++++++++ src/libgame/system.h | 2 ++ 4 files changed, 68 insertions(+) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 71f6cf17..0b2e1c16 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -98,10 +98,22 @@ static void UpdateScreen(SDL_Rect *rect) { SDL_UpdateTexture(sdl_texture, NULL, screen->pixels, screen->pitch); } + + // clear render target buffer SDL_RenderClear(sdl_renderer); + + // copy backbuffer to render target buffer SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); + + // copy global animations to render target buffer, if defined + if (gfx.draw_global_anim_function != NULL) + gfx.draw_global_anim_function(); + + // show render target buffer on screen SDL_RenderPresent(sdl_renderer); + #else + if (rect) SDL_UpdateWindowSurfaceRects(sdl_window, rect, 1); else @@ -961,6 +973,37 @@ void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif } +void SDLBlitTexture(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y, int mask_mode) +{ +#if defined(TARGET_SDL2) +#if USE_RENDERER + SDL_Texture *texture; + SDL_Rect src_rect; + SDL_Rect dst_rect; + + texture = + (mask_mode == BLIT_MASKED ? bitmap->texture_masked : bitmap->texture); + + if (texture == NULL) + return; + + src_rect.x = src_x; + src_rect.y = src_y; + src_rect.w = width; + src_rect.h = height; + + dst_rect.x = dst_x; + dst_rect.y = dst_y; + dst_rect.w = width; + dst_rect.h = height; + + SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect); +#endif +#endif +} + void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, int width, int height, Uint32 color) { diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index c881a3df..ad21926c 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -451,6 +451,7 @@ boolean SDLSetVideoMode(DrawBuffer **, boolean); void SDLCreateBitmapContent(Bitmap *, int, int, int); void SDLFreeBitmapPointers(Bitmap *); void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); +void SDLBlitTexture(Bitmap *, int, int, int, int, int, int, int); void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32); void SDLFadeRectangle(Bitmap *, int, int, int, int, int, int, int, void (*draw_border_function)(void)); diff --git a/src/libgame/system.c b/src/libgame/system.c index a4d3f9e8..a1fbad08 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -720,6 +720,28 @@ void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, dst_x, dst_y); } +void BlitTexture(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + + SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y, + BLIT_OPAQUE); +} + +void BlitTextureMasked(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + + SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y, + BLIT_MASKED); +} + 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 f8aa8296..9fd22f15 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1337,6 +1337,8 @@ void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int); boolean DrawingOnBackground(int, int); 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 DrawSimpleBlackLine(Bitmap *, int, int, int, int); void DrawSimpleWhiteLine(Bitmap *, int, int, int, int); void DrawLines(Bitmap *, struct XY *, int, Pixel); -- 2.34.1