Skip to content

Commit

Permalink
- reordered a few things in the startup procedure
Browse files Browse the repository at this point in the history
Mainly done to isolate the calls that actually manipulate the global frame buffer.

V_Init alsoi initialized some palette data, which was moved to V_InitPalette and did something entirely different when running a restart as opposed to an initial start.
  • Loading branch information
coelckers committed Sep 30, 2019
1 parent a2883cd commit 2a32052
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 101 deletions.
20 changes: 19 additions & 1 deletion src/d_main.cpp
Expand Up @@ -2453,8 +2453,26 @@ void D_DoomMain (void)
I_Init ();
}

// [RH] Initialize palette management
InitPalette ();

if (!batchrun) Printf ("V_Init: allocate screen.\n");
V_Init (!!restart);
if (!restart)
{
V_InitScreenSize();
}

if (!restart)
{
// This allocates a dummy framebuffer as a stand-in until V_Init2 is called.
V_InitScreen ();
}

if (restart)
{
// Update screen palette when restarting
screen->UpdatePalette();
}

// Base systems have been inited; enable cvar callbacks
FBaseCVar::EnableCallbacks ();
Expand Down
65 changes: 65 additions & 0 deletions src/r_data/v_palette.cpp
Expand Up @@ -49,6 +49,12 @@
#include "x86.h"
#include "g_levellocals.h"

uint32_t Col2RGB8[65][256];
uint32_t *Col2RGB8_LessPrecision[65];
uint32_t Col2RGB8_Inverse[65][256];
ColorTable32k RGB32k;
ColorTable256k RGB256k;

FPalette GPalette;
FColorMatcher ColorMatcher;

Expand Down Expand Up @@ -304,6 +310,63 @@ void ReadPalette(int lumpnum, uint8_t *buffer)
}
}

//==========================================================================
//
// BuildTransTable
//
// Build the tables necessary for blending
//
//==========================================================================

static void BuildTransTable (const PalEntry *palette)
{
int r, g, b;

// create the RGB555 lookup table
for (r = 0; r < 32; r++)
for (g = 0; g < 32; g++)
for (b = 0; b < 32; b++)
RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2));
// create the RGB666 lookup table
for (r = 0; r < 64; r++)
for (g = 0; g < 64; g++)
for (b = 0; b < 64; b++)
RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4));

int x, y;

// create the swizzled palette
for (x = 0; x < 65; x++)
for (y = 0; y < 256; y++)
Col2RGB8[x][y] = (((palette[y].r*x)>>4)<<20) |
((palette[y].g*x)>>4) |
(((palette[y].b*x)>>4)<<10);

// create the swizzled palette with the lsb of red and blue forced to 0
// (for green, a 1 is okay since it never gets added into)
uint32_t Col2RGB8_2[63][256];
for (x = 1; x < 64; x++)
{
Col2RGB8_LessPrecision[x] = Col2RGB8_2[x-1];
for (y = 0; y < 256; y++)
{
Col2RGB8_2[x-1][y] = Col2RGB8[x][y] & 0x3feffbff;
}
}
Col2RGB8_LessPrecision[0] = Col2RGB8[0];
Col2RGB8_LessPrecision[64] = Col2RGB8[64];

// create the inverse swizzled palette
for (x = 0; x < 65; x++)
for (y = 0; y < 256; y++)
{
Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) |
(((255-palette[y].g)*x)>>4) |
((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff;
}
}


void InitPalette ()
{
uint8_t pal[768];
Expand All @@ -323,6 +386,8 @@ void InitPalette ()
// Colormaps have to be initialized before actors are loaded,
// otherwise Powerup.Colormap will not work.
R_InitColormaps ();
BuildTransTable (GPalette.BaseColors);

}

CCMD (testblend)
Expand Down
126 changes: 27 additions & 99 deletions src/rendering/v_video.cpp
Expand Up @@ -152,14 +152,6 @@ int DisplayWidth, DisplayHeight;

FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont;

uint32_t Col2RGB8[65][256];
uint32_t *Col2RGB8_LessPrecision[65];
uint32_t Col2RGB8_Inverse[65][256];
ColorTable32k RGB32k;
ColorTable256k RGB256k;


static uint32_t Col2RGB8_2[63][256];

// [RH] The framebuffer is no longer a mere byte array.
// There's also only one, not four.
Expand Down Expand Up @@ -482,61 +474,6 @@ int V_GetColor(const uint32_t *palette, FScanner &sc)
return V_GetColor(palette, sc.String, &scc);
}

//==========================================================================
//
// BuildTransTable
//
// Build the tables necessary for blending
//
//==========================================================================

static void BuildTransTable (const PalEntry *palette)
{
int r, g, b;

// create the RGB555 lookup table
for (r = 0; r < 32; r++)
for (g = 0; g < 32; g++)
for (b = 0; b < 32; b++)
RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2));
// create the RGB666 lookup table
for (r = 0; r < 64; r++)
for (g = 0; g < 64; g++)
for (b = 0; b < 64; b++)
RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4));

int x, y;

// create the swizzled palette
for (x = 0; x < 65; x++)
for (y = 0; y < 256; y++)
Col2RGB8[x][y] = (((palette[y].r*x)>>4)<<20) |
((palette[y].g*x)>>4) |
(((palette[y].b*x)>>4)<<10);

// create the swizzled palette with the lsb of red and blue forced to 0
// (for green, a 1 is okay since it never gets added into)
for (x = 1; x < 64; x++)
{
Col2RGB8_LessPrecision[x] = Col2RGB8_2[x-1];
for (y = 0; y < 256; y++)
{
Col2RGB8_2[x-1][y] = Col2RGB8[x][y] & 0x3feffbff;
}
}
Col2RGB8_LessPrecision[0] = Col2RGB8[0];
Col2RGB8_LessPrecision[64] = Col2RGB8[64];

// create the inverse swizzled palette
for (x = 0; x < 65; x++)
for (y = 0; y < 256; y++)
{
Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) |
(((255-palette[y].g)*x)>>4) |
((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff;
}
}

CCMD(clean)
{
Printf ("CleanXfac: %d\nCleanYfac: %d\n", CleanXfac, CleanYfac);
Expand Down Expand Up @@ -621,55 +558,46 @@ bool IVideo::SetResolution ()
// V_Init
//

void V_Init (bool restart)
void V_InitScreenSize ()
{
const char *i;
int width, height, bits;

atterm (V_Shutdown);

// [RH] Initialize palette management
InitPalette ();

if (!restart)


width = height = bits = 0;

if ( (i = Args->CheckValue ("-width")) )
width = atoi (i);

if ( (i = Args->CheckValue ("-height")) )
height = atoi (i);

if (width == 0)
{
width = height = bits = 0;

if ( (i = Args->CheckValue ("-width")) )
width = atoi (i);

if ( (i = Args->CheckValue ("-height")) )
height = atoi (i);

if (width == 0)
if (height == 0)
{
if (height == 0)
{
width = vid_defwidth;
height = vid_defheight;
}
else
{
width = (height * 8) / 6;
}
width = vid_defwidth;
height = vid_defheight;
}
else if (height == 0)
else
{
height = (width * 6) / 8;
width = (height * 8) / 6;
}
// Remember the passed arguments for the next time the game starts up windowed.
vid_defwidth = width;
vid_defheight = height;

screen = new DDummyFrameBuffer (width, height);
}
// Update screen palette when restarting
else
else if (height == 0)
{
screen->UpdatePalette();
height = (width * 6) / 8;
}
// Remember the passed arguments for the next time the game starts up windowed.
vid_defwidth = width;
vid_defheight = height;
}

BuildTransTable (GPalette.BaseColors);
void V_InitScreen()
{
screen = new DDummyFrameBuffer (vid_defwidth, vid_defheight);
}

void V_Init2()
Expand Down
3 changes: 2 additions & 1 deletion src/rendering/v_video.h
Expand Up @@ -594,7 +594,8 @@ EXTERN_CVAR (Float, Gamma)


// Allocates buffer screens, call before R_Init.
void V_Init (bool restart);
void V_InitScreenSize();
void V_InitScreen();

// Initializes graphics mode for the first time.
void V_Init2 ();
Expand Down

0 comments on commit 2a32052

Please sign in to comment.