From 39b2c5abe4ab02136f5063f7b2ccc1ed95d3105c Mon Sep 17 00:00:00 2001 From: gewlitys Date: Fri, 14 Feb 2003 23:03:05 +0000 Subject: [PATCH] SDL_UpdateRect now uses partial update information too; fixed "crossfades not finished" problem; scalers now alter dimensions of passed rectangle directly git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@750 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 2 + sc2/src/sc2code/libs/graphics/sdl/2xscalers.c | 80 ++++++++++--------- sc2/src/sc2code/libs/graphics/sdl/2xscalers.h | 1 - sc2/src/sc2code/libs/graphics/sdl/opengl.c | 10 +-- sc2/src/sc2code/libs/graphics/sdl/opengl.h | 2 +- sc2/src/sc2code/libs/graphics/sdl/pure.c | 30 ++++--- sc2/src/sc2code/libs/graphics/sdl/pure.h | 2 +- .../sc2code/libs/graphics/sdl/sdl_common.c | 14 ++-- .../sc2code/libs/graphics/sdl/sdl_common.h | 2 +- 9 files changed, 77 insertions(+), 66 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 370259c91..89b75927a 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.2: +- Pure mode partial screen updates are now more efficient; + fixed 'crossfades not finished' problem -Mika - Graduated colours for crew in shipyard, from Nic - Alien dialog fixes: Talking Pet, Utwig, Mycon, Syreen -fOSSiL - Updated all game, menu, melee and weapon sounds to original 3DO diff --git a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c index df056044f..a5b84b3d3 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c +++ b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c @@ -286,7 +286,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) const int w = src->w, h = src->h, dw = dst->w; int xend, yend; int dsrc, ddst; - SDL_Rect region = *r; + SDL_Rect *region = r; SDL_Rect limits; SDL_PixelFormat *fmt = dst->format; @@ -297,12 +297,12 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) limits.y = 0; limits.w = src->w; limits.h = src->h; - Scale_ExpandRect (®ion, 2, &limits); + Scale_ExpandRect (region, 2, &limits); - xend = region.x + region.w; - yend = region.y + region.h; - dsrc = w - region.w; - ddst = (dw - region.w) * 2; + xend = region->x + region->w; + yend = region->y + region->h; + dsrc = w - region->w; + ddst = (dw - region->w) * 2; switch (fmt->BytesPerPixel) { @@ -316,12 +316,12 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) Uint32 pixval_tl, pixval_tr, pixval_bl, pixval_br; // move ptrs to the first updated pixel - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { pixval_tl = BIADAPT_GETPIX (src_p); @@ -514,12 +514,12 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) Uint32 pixval_tl, pixval_tr, pixval_bl, pixval_br; // move ptrs to the first updated pixel - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { pixval_tl = BIADAPT_GETPIX (src_p); @@ -712,12 +712,12 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) Uint32 pixval_tl, pixval_tr, pixval_bl, pixval_br; // move ptrs to the first updated pixel - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { pixval_tl = BIADAPT_GETPIX (src_p); @@ -912,7 +912,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) const int w = src->w, h = src->h, dw = dst->w; int xend, yend; int dsrc, ddst; - SDL_Rect region = *r; + SDL_Rect *region = r; SDL_Rect limits; SDL_PixelFormat *fmt = dst->format; // for clarity purposes, the 'pixels' array here is transposed @@ -960,12 +960,12 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) limits.y = 0; limits.w = src->w; limits.h = src->h; - Scale_ExpandRect (®ion, 2, &limits); + Scale_ExpandRect (region, 2, &limits); - xend = region.x + region.w; - yend = region.y + region.h; - dsrc = w - region.w; - ddst = (dw - region.w) * 2; + xend = region->x + region->w; + yend = region->y + region->h; + dsrc = w - region->w; + ddst = (dw - region->w) * 2; switch (fmt->BytesPerPixel) { @@ -977,12 +977,12 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { // pixel eqaulity counter int cmatch; @@ -1429,12 +1429,12 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { // pixel eqaulity counter int cmatch; @@ -1881,12 +1881,12 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; - src_p += w * region.y + region.x; - dst_p += (dw * region.y + region.x) * 2; + src_p += w * region->y + region->x; + dst_p += (dw * region->y + region->x) * 2; - for (y = region.y; y < yend; ++y, dst_p += ddst, src_p += dsrc) + for (y = region->y; y < yend; ++y, dst_p += ddst, src_p += dsrc) { - for (x = region.x; x < xend; ++x, ++src_p, ++dst_p) + for (x = region->x; x < xend; ++x, ++src_p, ++dst_p) { // pixel eqaulity counter int cmatch; @@ -2435,6 +2435,14 @@ void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) const int w = dst->w, h = dst->h; SDL_PixelFormat *fmt = dst->format; + // TODO: support for partial updates, expand weight matrix in the code + // so that compiler can optimize the mults? + + r->x = 0; + r->y = 0; + r->w = src->w; + r->h = src->h; + switch (dst->format->BytesPerPixel) { case 2: diff --git a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.h b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.h index 7dbdbe64f..903a75bd1 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.h +++ b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.h @@ -19,7 +19,6 @@ #define _2XSCALERS_H_ void Scale_PrepYUV (void); -void Scale_ExpandRect (SDL_Rect* rect, int expansion, SDL_Rect* limits); void Scale_Nearest (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r); void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r); void Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r); diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.c b/sc2/src/sc2code/libs/graphics/sdl/opengl.c index 0376ddbe6..5df929596 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.c +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.c @@ -269,7 +269,7 @@ TFB_GL_DrawQuad (void) } void -TFB_GL_SwapBuffers (void) +TFB_GL_SwapBuffers (int force_full_redraw) { int fade_amount; int transition_amount; @@ -296,19 +296,11 @@ TFB_GL_SwapBuffers (void) if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT || GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV) { - SDL_Rect limits; - if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT) Scale_BiAdaptFilter (SDL_Screen, scaled_display, &updated); else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV) Scale_BiAdaptAdvFilter (SDL_Screen, scaled_display, &updated); - limits.x = 0; - limits.y = 0; - limits.w = ScreenWidth; - limits.h = ScreenHeight; - Scale_ExpandRect (&updated, 2, &limits); - glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth * 2); glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y * 2); glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x * 2); diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.h b/sc2/src/sc2code/libs/graphics/sdl/opengl.h index 809bd8196..438c07d0c 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.h +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.h @@ -23,7 +23,7 @@ int TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp); void TFB_GL_UploadTransitionScreen (void); -void TFB_GL_SwapBuffers (void); +void TFB_GL_SwapBuffers (int force_full_redraw); SDL_Surface* TFB_GL_DisplayFormatAlpha (SDL_Surface *surface); diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.c b/sc2/src/sc2code/libs/graphics/sdl/pure.c index 065e8b306..3e4f07af5 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.c +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.c @@ -25,6 +25,7 @@ static SDL_Surface *fade_black; static SDL_Surface *fade_white; static SDL_Surface *fade_temp; static int gfx_flags; +static int last_fade_amount = 255, last_transition_amount = 255; static SDL_Surface * Create_Screen (SDL_Surface *template) @@ -220,18 +221,25 @@ static void ScanLines (SDL_Surface *dst) } void -TFB_Pure_SwapBuffers () +TFB_Pure_SwapBuffers (int force_full_redraw) { int fade_amount = FadeAmount; int transition_amount = TransitionAmount; SDL_Rect updated; - updated.x = TFB_BBox.region.corner.x; - updated.y = TFB_BBox.region.corner.y; - updated.w = TFB_BBox.region.extent.width; - updated.h = TFB_BBox.region.extent.height; - - if ((transition_amount != 255) || (fade_amount != 255)) + if (last_fade_amount != 255 || last_transition_amount != 255) + force_full_redraw = 1; + last_fade_amount = fade_amount; + last_transition_amount = transition_amount; + + if (!force_full_redraw) + { + updated.x = TFB_BBox.region.corner.x; + updated.y = TFB_BBox.region.corner.y; + updated.w = TFB_BBox.region.extent.width; + updated.h = TFB_BBox.region.extent.height; + } + else { updated.x = updated.y = 0; updated.w = ScreenWidth; @@ -276,7 +284,7 @@ TFB_Pure_SwapBuffers () SDL_LockSurface (SDL_Video); SDL_LockSurface (backbuffer); - + if (gfx_flags & TFB_GFXFLAGS_SCALE_BILINEAR) Scale_BilinearFilter (backbuffer, SDL_Video, &updated); else if (gfx_flags & TFB_GFXFLAGS_SCALE_BIADAPT) @@ -291,6 +299,8 @@ TFB_Pure_SwapBuffers () SDL_UnlockSurface (backbuffer); SDL_UnlockSurface (SDL_Video); + + SDL_UpdateRect (SDL_Video, updated.x * 2, updated.y * 2, updated.w * 2, updated.h * 2); } else { @@ -317,9 +327,9 @@ TFB_Pure_SwapBuffers () SDL_BlitSurface (fade_white, NULL, SDL_Video, NULL); } } - } - SDL_UpdateRect (SDL_Video, 0, 0, 0, 0); + SDL_UpdateRect (SDL_Video, updated.x, updated.y, updated.w, updated.h); + } } #endif diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.h b/sc2/src/sc2code/libs/graphics/sdl/pure.h index b63dd631b..86c8d6d12 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.h +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.h @@ -22,6 +22,6 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp); -void TFB_Pure_SwapBuffers (); +void TFB_Pure_SwapBuffers (int force_full_redraw); #endif diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 651cd9aa0..3d1c65acb 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -120,7 +120,7 @@ TFB_ProcessEvents () // TODO break; case SDL_VIDEOEXPOSE: /* Screen needs to be redrawn */ - TFB_SwapBuffers (); + TFB_SwapBuffers (1); break; default: break; @@ -129,15 +129,15 @@ TFB_ProcessEvents () } void -TFB_SwapBuffers () +TFB_SwapBuffers (int force_full_redraw) { #ifdef HAVE_OPENGL if (GraphicsDriver == TFB_GFXDRIVER_SDL_OPENGL) - TFB_GL_SwapBuffers (); + TFB_GL_SwapBuffers (force_full_redraw); else - TFB_Pure_SwapBuffers (); + TFB_Pure_SwapBuffers (force_full_redraw); #else - TFB_Pure_SwapBuffers (); + TFB_Pure_SwapBuffers (force_full_redraw); #endif } @@ -460,7 +460,7 @@ TFB_FlushGraphics () // Only call from main thread!! if ((current_fade != 255 && current_fade != last_fade) || (current_transition != 255 && current_transition != last_transition)) { - TFB_SwapBuffers(); // if fading, redraw every frame + TFB_SwapBuffers (1); // if fading, redraw every frame } else { @@ -664,7 +664,7 @@ TFB_FlushGraphics () // Only call from main thread!! Unlock_DCQ (); } - TFB_SwapBuffers (); + TFB_SwapBuffers (0); RenderedFrames++; BroadcastCondVar (RenderingCond); } diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h index 206eb9df5..58cc3130f 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h @@ -46,7 +46,7 @@ extern int GfxFlags; void ScreenOrigin (FRAME Display, COORD sx, COORD sy); void LoadDisplay (PDISPLAY_INTERFACE *pDisplay); -void TFB_SwapBuffers (); +void TFB_SwapBuffers (int force_full_redraw); SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface); void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, int blend_numer, int blend_denom);