Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True-color rendering #132

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
43 changes: 30 additions & 13 deletions src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,10 +1445,10 @@ static void AM_clearFB(int color)
{
// [Nugget] Minimap: take `f_x` and `f_y` into account
int h = f_h;
byte *src = I_VideoBuffer + ((f_y * video.pitch) + f_x);
pixel_t *src = I_VideoBuffer + ((f_y * video.pitch) + f_x);
while (h--)
{
memset(src, color, f_w);
V_IndexSet(src, color, f_w);
src += video.pitch;
}
}
Expand Down Expand Up @@ -1601,7 +1601,7 @@ static void PUTDOT(int xx, int yy, int cc)

// [Nugget] Minimap: take `f_x` and `f_y` into account
if ((f_x <= xx && xx < f_x+f_w) && (f_y <= yy && yy < f_y+f_h))
I_VideoBuffer[(yy) * video.pitch + (xx)] = (cc);
I_VideoBuffer[(yy) * video.pitch + (xx)] = V_IndexToRGB(cc);
}


Expand Down Expand Up @@ -1697,19 +1697,26 @@ static void AM_putWuDot(int x, int y, int color, int weight)
{
if (STRICTMODE(flip_levels)) { x = f_x*2 + f_w - 1 - x; } // [Nugget] Flip levels

byte *dest = &I_VideoBuffer[y * video.pitch + x];
unsigned int *fg2rgb = Col2RGB8[weight];
unsigned int *bg2rgb = Col2RGB8[64 - weight];
unsigned int fg, bg;

// [Nugget] Minimap: take `f_x` and `f_y` into account
if (!((f_x <= x && x < f_x+f_w) && (f_y <= y && y < f_y+f_h)))
{ return; }

fg = fg2rgb[color];
bg = bg2rgb[*dest];
fg = (fg + bg) | 0x1f07c1f;
*dest = RGB32k[0][0][fg & (fg >> 15)];
pixel_t *dest = &I_VideoBuffer[y * video.pitch + x];

if (truecolor_rendering)
{
if (weight) { *dest = V_LerpRGB(*dest, V_IndexToRGB(color), weight, 64); }
}
else {
unsigned int *fg2rgb = Col2RGB8[weight];
unsigned int *bg2rgb = Col2RGB8[64 - weight];
unsigned int fg, bg;

fg = fg2rgb[color];
bg = bg2rgb[V_IndexFromRGB(*dest)];
fg = (fg + bg) | 0x1f07c1f;
*dest = V_IndexToRGB(RGB32k[0][0][fg & (fg >> 15)]);
}
}


Expand Down Expand Up @@ -2795,7 +2802,17 @@ void AM_shadeScreen(void)
for (int y = f_y; y < f_y+f_h; y++)
{
const int pixel = y * video.pitch + x;
I_VideoBuffer[pixel] = colormaps[0][automap_overlay_darkening * 256 + I_VideoBuffer[pixel]];

if (truecolor_rendering)
{
I_VideoBuffer[pixel] = V_ShadeRGB(I_VideoBuffer[pixel], automap_overlay_darkening, 32);
}
else
{
I_VideoBuffer[pixel] = V_IndexToRGB(
colormaps[0][automap_overlay_darkening * 256 + V_IndexFromRGB(I_VideoBuffer[pixel])]
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/doomtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef enum {false, true} boolean;

typedef uint8_t byte;

typedef byte pixel_t;
typedef uint32_t pixel_t;

// This could be wider for >8 bit display. Indeed, true color support is
// posibble precalculating 24bpp lightmap/colormap LUT. from darkening PLAYPAL
Expand Down
40 changes: 23 additions & 17 deletions src/f_wipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ static int wipe_columns;
// SCREEN WIPE PACKAGE
//

static byte *wipe_scr_start;
static byte *wipe_scr_end;
static byte *wipe_scr;
static pixel_t *wipe_scr_start;
static pixel_t *wipe_scr_end;
static pixel_t *wipe_scr;

// [FG] cross-fading screen wipe implementation

Expand All @@ -76,20 +76,26 @@ static int wipe_doColorXForm(int width, int height, int ticks)

for (int y = 0; y < height; y++)
{
byte *sta = wipe_scr_start + y * width;
byte *end = wipe_scr_end + y * width;
byte *dst = wipe_scr + y * video.pitch;
pixel_t *sta = wipe_scr_start + y * width;
pixel_t *end = wipe_scr_end + y * width;
pixel_t *dst = wipe_scr + y * video.pitch;

for (int x = 0; x < width; x++)
{
unsigned int *fg2rgb = Col2RGB8[fade_tick];
unsigned int *bg2rgb = Col2RGB8[64 - fade_tick];
unsigned int fg, bg;

fg = fg2rgb[end[x]];
bg = bg2rgb[sta[x]];
fg = (fg + bg) | 0x1f07c1f;
dst[x] = RGB32k[0][0][fg & (fg >> 15)];
if (truecolor_rendering)
{
if (fade_tick) { dst[x] = V_LerpRGB(sta[x], end[x], fade_tick, 64); }
}
else {
unsigned int *fg2rgb = Col2RGB8[fade_tick];
unsigned int *bg2rgb = Col2RGB8[64 - fade_tick];
unsigned int fg, bg;

fg = fg2rgb[V_IndexFromRGB(end[x])];
bg = bg2rgb[V_IndexFromRGB(sta[x])];
fg = (fg + bg) | 0x1f07c1f;
dst[x] = V_IndexToRGB(RGB32k[0][0][fg & (fg >> 15)]);
}
}
}

Expand Down Expand Up @@ -417,12 +423,12 @@ static int wipe_doFizzle(int width, int height, int ticks)
vrect_t rect = {x, y, 1, 1};
V_ScaleRect(&rect);

byte *src = wipe_scr_end + rect.sy * width + rect.sx;
byte *dest = wipe_scr + rect.sy * video.pitch + rect.sx;
pixel_t *src = wipe_scr_end + rect.sy * width + rect.sx;
pixel_t *dest = wipe_scr + rect.sy * video.pitch + rect.sx;

while (rect.sh--)
{
memcpy(dest, src, rect.sw);
V_RGBCopy(dest, src, rect.sw);
src += width;
dest += video.pitch;
}
Expand Down
55 changes: 22 additions & 33 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ static boolean disk_icon; // killough 10/98

// [Nugget] /-----------------------------------------------------------------

truecolormode_t truecolor_rendering;

static const char *sdl_renderdriver = "";

static int red_intensity, green_intensity, blue_intensity;
static int color_saturation, color_contrast;
int red_intensity, green_intensity, blue_intensity;
int color_saturation, color_contrast;

// [Nugget] -----------------------------------------------------------------/

Expand Down Expand Up @@ -897,7 +899,7 @@ void I_FinishUpdate(void)
// I_ReadScreen
//

void I_ReadScreen(byte *dst)
void I_ReadScreen(pixel_t *dst)
{
V_GetBlock(0, 0, video.width, video.height, dst);
}
Expand Down Expand Up @@ -997,36 +999,10 @@ static void I_RestoreDiskBackground(void)

int gamma2;

// [Nugget]:
// [JN] Saturation percent array.
// 0.66 = 0% saturation, 0.0 = 100% saturation.
const float I_SaturationPercent[101] =
{
0.660000f, 0.653400f, 0.646800f, 0.640200f, 0.633600f,
0.627000f, 0.620400f, 0.613800f, 0.607200f, 0.600600f,
0.594000f, 0.587400f, 0.580800f, 0.574200f, 0.567600f,
0.561000f, 0.554400f, 0.547800f, 0.541200f, 0.534600f,
0.528000f, 0.521400f, 0.514800f, 0.508200f, 0.501600f,
0.495000f, 0.488400f, 0.481800f, 0.475200f, 0.468600f,
0.462000f, 0.455400f, 0.448800f, 0.442200f, 0.435600f,
0.429000f, 0.422400f, 0.415800f, 0.409200f, 0.402600f,
0.396000f, 0.389400f, 0.382800f, 0.376200f, 0.369600f,
0.363000f, 0.356400f, 0.349800f, 0.343200f, 0.336600f,
0.330000f, 0.323400f, 0.316800f, 0.310200f, 0.303600f,
0.297000f, 0.290400f, 0.283800f, 0.277200f, 0.270600f,
0.264000f, 0.257400f, 0.250800f, 0.244200f, 0.237600f,
0.231000f, 0.224400f, 0.217800f, 0.211200f, 0.204600f,
0.198000f, 0.191400f, 0.184800f, 0.178200f, 0.171600f,
0.165000f, 0.158400f, 0.151800f, 0.145200f, 0.138600f,
0.132000f, 0.125400f, 0.118800f, 0.112200f, 0.105600f,
0.099000f, 0.092400f, 0.085800f, 0.079200f, 0.072600f,
0.066000f, 0.059400f, 0.052800f, 0.046200f, 0.039600f,
0.033000f, 0.026400f, 0.019800f, 0.013200f, 0,
0
};

void I_SetPalette(byte *palette)
{
#if 0

// haleyjd
int i;
const byte *const gamma = gammatable[gamma2];
Expand Down Expand Up @@ -1080,11 +1056,18 @@ void I_SetPalette(byte *palette)

SDL_SetPaletteColors(screenbuffer->format->palette, colors, 0, 256);

#endif

V_InitPalsColors();

if (vga_porch_flash)
{
// "flash" the pillars/letterboxes with palette changes,
// emulating VGA "porch" behaviour
SDL_SetRenderDrawColor(renderer, colors[0].r, colors[0].g, colors[0].b,
SDL_SetRenderDrawColor(renderer,
V_RedFromRGB(palscolors[0][0]),
V_GreenFromRGB(palscolors[0][0]),
V_BlueFromRGB(palscolors[0][0]),
SDL_ALPHA_OPAQUE);
}
}
Expand Down Expand Up @@ -1851,7 +1834,8 @@ static void CreateSurfaces(int w, int h)
SDL_FreeSurface(screenbuffer);
}

screenbuffer = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
screenbuffer = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ARGB8888);
SDL_SetSurfaceBlendMode(screenbuffer, SDL_BLENDMODE_NONE);
SDL_FillRect(screenbuffer, NULL, 0);

I_VideoBuffer = screenbuffer->pixels;
Expand Down Expand Up @@ -1975,6 +1959,11 @@ void I_InitGraphics(void)

void I_BindVideoVariables(void)
{
// [Nugget] True color
BIND_NUM_GENERAL(truecolor_rendering,
TRUECOLOR_OFF, TRUECOLOR_OFF, NUM_TRUECOLOR_MODES-1,
"True-color rendering (0 = Off; 1 = Hybrid; 2 = Full");

M_BindNum("current_video_height", &default_current_video_height,
&current_video_height, 600, 200, UL, ss_none, wad_no,
"Vertical resolution");
Expand Down
20 changes: 18 additions & 2 deletions src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void I_SetPalette(byte *palette);

void I_FinishUpdate(void);

void I_ReadScreen(byte *dst);
void I_ReadScreen(pixel_t *dst);

void I_ResetScreen(void); // killough 10/98
void I_ToggleVsync(void); // [JN] Calls native SDL vsync toggle
Expand All @@ -81,10 +81,26 @@ extern boolean toggle_exclusive_fullscreen;
extern boolean correct_aspect_ratio;
extern boolean screenvisible;

// [Nugget]
// [Nugget] /-----------------------------------------------------------------

typedef enum truecolormode_s {
TRUECOLOR_OFF,
TRUECOLOR_HYBRID,
TRUECOLOR_FULL,

NUM_TRUECOLOR_MODES
} truecolormode_t;

extern truecolormode_t truecolor_rendering;

extern int red_intensity, green_intensity, blue_intensity;
extern int color_saturation, color_contrast;

#define GAMMA2MAX 30
extern const float gammalevels[GAMMA2MAX+1];

// [Nugget] -----------------------------------------------------------------/

extern int gamma2;
byte I_GetNearestColor(byte *palette, int r, int g, int b);

Expand Down
4 changes: 2 additions & 2 deletions src/m_cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@

// [Nugget] Testing cheat /------------

//#define NUGMAGIC
#define NUGMAGIC

#ifdef NUGMAGIC

static void cheat_magic(void)
{

displaymsg("Light %s", (diminished_lighting = !diminished_lighting) ? "ON" : "OFF");
}

static void cheat_magic2(void)
Expand Down
12 changes: 11 additions & 1 deletion src/mn_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ enum

// [Nugget] --------------------------------------------------------------

str_truecolor_mode,
str_bobbing_style,
str_force_carousel,
str_crosshair_lockon,
Expand Down Expand Up @@ -2669,6 +2670,11 @@ static setup_tab_t gen_tabs[] = {
{NULL}
};

// [Nugget] True color
static const char *truecolor_mode_strings[] = {
"Off", "Hybrid", "Full"
};

static int resolution_scale;

static const char **GetResolutionScaleStrings(void)
Expand Down Expand Up @@ -2803,7 +2809,10 @@ void MN_ResetGamma(void)

static setup_menu_t gen_settings1[] = {

// [Nugget] These first three items now report
{"True-color Rendering", S_CHOICE, CNTR_X, M_SPC, {"truecolor_rendering"},
.strings_id = str_truecolor_mode},

// [Nugget] The following three items now report
// the current resolution when sitting on them

{"Resolution Scale", S_THERMO | S_THRM_SIZE11 | S_ACTION | S_RES, CNTR_X,
Expand Down Expand Up @@ -5605,6 +5614,7 @@ static const char **selectstrings[] = {

// [Nugget] --------------------------------------------------------------

truecolor_mode_strings,
bobbing_style_strings,
force_carousel_strings,
crosshair_lockon_strings,
Expand Down
14 changes: 7 additions & 7 deletions src/mn_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

static const char snapshot_str[] = "NUGGETDOOM_SNAPSHOT";
static const int snapshot_len = arrlen(snapshot_str);
static const int snapshot_size = SCREENWIDTH * SCREENHEIGHT;
static const int snapshot_size = (SCREENWIDTH * SCREENHEIGHT) * sizeof(pixel_t);

static byte *snapshots[10];
static byte *current_snapshot;
static pixel_t *snapshots[10];
static pixel_t *current_snapshot;
static char savegametimes[10][32];

const int MN_SnapshotDataSize(void)
Expand Down Expand Up @@ -132,9 +132,9 @@ static void TakeSnapshot(void)
current_snapshot = malloc(snapshot_size * sizeof(**snapshots));
}

byte *p = current_snapshot;
pixel_t *p = current_snapshot;

const byte *s = I_VideoBuffer;
const pixel_t *s = I_VideoBuffer;

int x, y;
for (y = 0; y < SCREENHEIGHT; y++)
Expand Down Expand Up @@ -181,11 +181,11 @@ boolean MN_DrawSnapshot(int n, int x, int y, int w, int h)
const fixed_t step_x = (SCREENWIDTH << FRACBITS) / rect.sw;
const fixed_t step_y = (SCREENHEIGHT << FRACBITS) / rect.sh;

byte *dest = I_VideoBuffer + rect.sy * video.pitch + rect.sx;
pixel_t *dest = I_VideoBuffer + rect.sy * video.pitch + rect.sx;

fixed_t srcx, srcy;
int destx, desty;
byte *destline, *srcline;
pixel_t *destline, *srcline;

for (desty = 0, srcy = 0; desty < rect.sh; desty++, srcy += step_y)
{
Expand Down
Loading