introduce video.pitch, avoid screen copying in I_FinishUpdate

This commit is contained in:
Roman Fomin 2023-12-20 14:09:26 +07:00
parent fea6833ea0
commit 9f0197338f
8 changed files with 23 additions and 44 deletions

View File

@ -55,7 +55,7 @@ static void wipe_shittyColMajorXform(byte *array, int width, int height)
static int wipe_initColorXForm(int width, int height, int ticks) static int wipe_initColorXForm(int width, int height, int ticks)
{ {
memcpy(wipe_scr, wipe_scr_start, width*height); V_PutBlock(0, 0, width, height, wipe_scr_start);
return 0; return 0;
} }
@ -94,7 +94,7 @@ static int wipe_initMelt(int width, int height, int ticks)
col_y = Z_Malloc(num_columns * sizeof(*col_y), PU_STATIC, NULL); col_y = Z_Malloc(num_columns * sizeof(*col_y), PU_STATIC, NULL);
// copy start screen to main screen // copy start screen to main screen
memcpy(wipe_scr, wipe_scr_start, width*height); V_PutBlock(0, 0, width, height, wipe_scr_start);
// makes this wipe faster (in theory) // makes this wipe faster (in theory)
// to have stuff in column-major format // to have stuff in column-major format
@ -152,14 +152,14 @@ static int wipe_doMelt(int width, int height, int ticks)
for (y = 0; y < scroff; ++y) for (y = 0; y < scroff; ++y)
{ {
*d = *s; *d = *s;
d += width; d += video.pitch;
s++; s++;
} }
s = wipe_scr_start + x * height; s = wipe_scr_start + x * height;
for (; y < height; ++y) for (; y < height; ++y)
{ {
*d = *s; *d = *s;
d += width; d += video.pitch;
s++; s++;
} }
} }

View File

@ -436,20 +436,6 @@ void I_StartFrame(void)
static void UpdateRender(void) static void UpdateRender(void)
{ {
int i;
// Copy linear video buffer to rectangle on surface
byte *dest = screenbuffer->pixels;
const pixel_t *src = I_VideoBuffer;
for (i = 0; i < blit_rect.h; ++i)
{
memcpy(dest, src, blit_rect.w);
dest += screenbuffer->w;
src += blit_rect.w;
}
SDL_LowerBlit(screenbuffer, &blit_rect, argbbuffer, &blit_rect); SDL_LowerBlit(screenbuffer, &blit_rect, argbbuffer, &blit_rect);
SDL_UpdateTexture(texture, &blit_rect, argbbuffer->pixels, argbbuffer->pitch); SDL_UpdateTexture(texture, &blit_rect, argbbuffer->pixels, argbbuffer->pitch);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
@ -639,9 +625,9 @@ void I_FinishUpdate(void)
// I_ReadScreen // I_ReadScreen
// //
void I_ReadScreen(byte *scr) void I_ReadScreen(byte *dst)
{ {
memcpy(scr, I_VideoBuffer, video.width * video.height * sizeof(*I_VideoBuffer)); V_GetBlock(0, 0, video.width, video.height, dst);
} }
// //
@ -1381,6 +1367,8 @@ static void CreateSurfaces(void)
w = (w + 3) & ~3; w = (w + 3) & ~3;
h = (h + 3) & ~3; h = (h + 3) & ~3;
video.pitch = w;
// [FG] create paletted frame buffer // [FG] create paletted frame buffer
if (screenbuffer != NULL) if (screenbuffer != NULL)
@ -1393,14 +1381,12 @@ static void CreateSurfaces(void)
0, 0, 0, 0); 0, 0, 0, 0);
SDL_FillRect(screenbuffer, NULL, 0); SDL_FillRect(screenbuffer, NULL, 0);
if (I_VideoBuffer != NULL) I_VideoBuffer = screenbuffer->pixels;
{
Z_Free(I_VideoBuffer);
}
I_VideoBuffer = Z_Calloc(1, w * h * sizeof(*I_VideoBuffer), PU_STATIC, NULL);
V_RestoreBuffer(); V_RestoreBuffer();
// Clear the screen to black.
memset(I_VideoBuffer, 0, w * h * sizeof(*I_VideoBuffer));
if (argbbuffer != NULL) if (argbbuffer != NULL)
{ {
SDL_FreeSurface(argbbuffer); SDL_FreeSurface(argbbuffer);

View File

@ -21,7 +21,6 @@
#include "doomtype.h" #include "doomtype.h"
#include "doomstat.h" #include "doomstat.h"
#include "i_video.h"
#include "m_io.h" #include "m_io.h"
#include "v_video.h" #include "v_video.h"
#include "r_main.h" #include "r_main.h"
@ -123,7 +122,7 @@ static void M_TakeSnapshot (void)
{ {
for (x = video.deltaw; x < NONWIDEWIDTH + video.deltaw; x++) for (x = video.deltaw; x < NONWIDEWIDTH + video.deltaw; x++)
{ {
*p++ = s[V_ScaleY(y) * video.width + V_ScaleX(x)]; *p++ = s[V_ScaleY(y) * video.pitch + V_ScaleX(x)];
} }
} }
@ -164,7 +163,7 @@ boolean M_DrawSnapshot (int n, int x, int y, int w, int h)
const fixed_t step_x = (SCREENWIDTH << FRACBITS) / rect.sw; const fixed_t step_x = (SCREENWIDTH << FRACBITS) / rect.sw;
const fixed_t step_y = (SCREENHEIGHT << FRACBITS) / rect.sh; const fixed_t step_y = (SCREENHEIGHT << FRACBITS) / rect.sh;
byte *dest = I_VideoBuffer + rect.sy * video.width + rect.sx; byte *dest = I_VideoBuffer + rect.sy * video.pitch + rect.sx;
fixed_t srcx, srcy; fixed_t srcx, srcy;
int destx, desty; int destx, desty;
@ -172,7 +171,7 @@ boolean M_DrawSnapshot (int n, int x, int y, int w, int h)
for (desty = 0, srcy = 0; desty < rect.sh; desty++, srcy += step_y) for (desty = 0, srcy = 0; desty < rect.sh; desty++, srcy += step_y)
{ {
destline = dest + desty * video.width; destline = dest + desty * video.pitch;
srcline = snapshots[n] + (srcy >> FRACBITS) * SCREENWIDTH; srcline = snapshots[n] + (srcy >> FRACBITS) * SCREENWIDTH;
for (destx = 0, srcx = 0; destx < rect.sw; destx++, srcx += step_x) for (destx = 0, srcx = 0; destx < rect.sw; destx++, srcx += step_x)

View File

@ -47,7 +47,7 @@ int viewwindowx;
int viewwindowy; int viewwindowy;
static byte **ylookup = NULL; static byte **ylookup = NULL;
static int *columnofs = NULL; static int *columnofs = NULL;
static int linesize = SCREENWIDTH; // killough 11/98 static int linesize; // killough 11/98
// Color tables for different players, // Color tables for different players,
// translate a limited part to another // translate a limited part to another
@ -824,7 +824,7 @@ void R_InitBuffer(void)
{ {
int i; int i;
linesize = video.width; // killough 11/98 linesize = video.pitch; // killough 11/98
// Handle resize, // Handle resize,
// e.g. smaller view windows // e.g. smaller view windows

View File

@ -813,7 +813,7 @@ static void VX_DrawColumn (vissprite_t * spr, int x, int y)
boolean shadow = ((spr->mobjflags & MF_SHADOW) != 0); boolean shadow = ((spr->mobjflags & MF_SHADOW) != 0);
int linesize = video.width; int linesize = video.pitch;
byte * dest = I_VideoBuffer + viewwindowy * linesize + viewwindowx; byte * dest = I_VideoBuffer + viewwindowy * linesize + viewwindowx;
// iterate over screen columns // iterate over screen columns

View File

@ -342,7 +342,7 @@ static void ST_DrawSolidBackground(int st_x)
{ {
for (x = 0; x < depth; x++) for (x = 0; x < depth; x++)
{ {
byte *c = st_backing_screen + V_ScaleY(y) * video.width + V_ScaleX(x + offset); byte *c = st_backing_screen + V_ScaleY(y) * video.pitch + V_ScaleX(x + offset);
r += pal[3 * c[0] + 0]; r += pal[3 * c[0] + 0];
g += pal[3 * c[0] + 1]; g += pal[3 * c[0] + 1];
b += pal[3 * c[0] + 2]; b += pal[3 * c[0] + 2];
@ -1327,14 +1327,7 @@ void ST_Init(void)
void ST_InitRes(void) void ST_InitRes(void)
{ {
vrect_t rect; int height = V_ScaleY(StatusBarBufferHeight());
rect.x = 0;
rect.y = 0;
rect.w = video.unscaledw;
rect.h = StatusBarBufferHeight();
V_ScaleRect(&rect);
if (st_backing_screen) if (st_backing_screen)
{ {
@ -1342,7 +1335,7 @@ void ST_InitRes(void)
} }
// killough 11/98: allocate enough for hires // killough 11/98: allocate enough for hires
st_backing_screen = Z_Malloc(rect.sw * rect.sh * sizeof(*st_backing_screen), PU_STATIC, 0); st_backing_screen = Z_Malloc(video.pitch * height * sizeof(*st_backing_screen), PU_STATIC, 0);
} }
void ST_Warnings(void) void ST_Warnings(void)

View File

@ -970,7 +970,7 @@ void V_Init(void)
int i; int i;
fixed_t frac, lastfrac; fixed_t frac, lastfrac;
linesize = video.width; linesize = video.pitch;
video.xscale = (video.width << FRACBITS) / video.unscaledw; video.xscale = (video.width << FRACBITS) / video.unscaledw;
video.yscale = (video.height << FRACBITS) / SCREENHEIGHT; video.yscale = (video.height << FRACBITS) / SCREENHEIGHT;

View File

@ -93,6 +93,7 @@ typedef struct
{ {
int width; int width;
int height; int height;
int pitch;
int unscaledw; // unscaled width with correction for widecreen int unscaledw; // unscaled width with correction for widecreen
int deltaw; // widescreen delta int deltaw; // widescreen delta