Image: Share Draw_GetPalette between renders

This commit is contained in:
Denis Pauk 2022-10-12 22:03:20 +03:00
parent 7f05cefbcf
commit 768139ad6a
10 changed files with 51 additions and 116 deletions

View file

@ -315,3 +315,38 @@ GetPCXInfo(char *filename, int *width, int *height)
return;
}
/*
===============
GetPCXPalette
===============
*/
void
GetPCXPalette (byte **colormap, unsigned *d_8to24table)
{
byte *pal;
int i;
/* get the palette and colormap */
LoadPCX ("pics/colormap.pcx", colormap, &pal, NULL, NULL);
if (!colormap)
{
ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx");
}
for (i=0 ; i<256 ; i++)
{
unsigned v;
int r, g, b;
r = pal[i*3+0];
g = pal[i*3+1];
b = pal[i*3+2];
v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
d_8to24table[i] = LittleLong(v);
}
d_8to24table[255] &= LittleLong(0xffffff); // 255 is transparent
free (pal);
}

View file

@ -517,39 +517,3 @@ RDraw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data)
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
int
Draw_GetPalette(void)
{
int i;
int r, g, b;
unsigned v;
byte *pic, *pal;
int width, height;
/* get the palette */
LoadPCX("pics/colormap.pcx", &pic, &pal, &width, &height);
if (!pal)
{
ri.Sys_Error(ERR_FATAL, "Couldn't load pics/colormap.pcx");
}
for (i = 0; i < 256; i++)
{
r = pal[i * 3 + 0];
g = pal[i * 3 + 1];
b = pal[i * 3 + 2];
v = (255u << 24) + (r << 0) + (g << 8) + (b << 16);
d_8to24table[i] = LittleLong(v);
}
d_8to24table[255] &= LittleLong(0xffffff); /* 255 is transparent */
free(pic);
free(pal);
return 0;
}

View file

@ -53,8 +53,6 @@ int gl_tex_alpha_format = GL_RGBA;
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
int gl_filter_max = GL_LINEAR;
int Draw_GetPalette(void);
typedef struct
{
char *name;
@ -1443,6 +1441,7 @@ R_ImageHasFreeSpace(void)
void
R_InitImages(void)
{
byte *colormap;
int i, j;
registration_sequence = 1;
@ -1458,7 +1457,9 @@ R_InitImages(void)
gl_state.inverse_intensity = 1 / intensity->value;
Draw_GetPalette(); // FIXME: I think this is redundant - RI_Init() already calls that!
// FIXME: I think this is redundant - RI_Init() already calls that!
GetPCXPalette (&colormap, d_8to24table);
free(colormap);
if (gl_config.palettedtexture)
{

View file

@ -536,7 +536,7 @@ R_DrawParticles(void)
int i;
YQ2_ALIGNAS_TYPE(unsigned) byte color[4];
const particle_t *p;
YQ2_VLA(GLfloat, vtx, 3 * r_newrefdef.num_particles);
YQ2_VLA(GLfloat, clr, 4 * r_newrefdef.num_particles);
@ -1403,6 +1403,7 @@ qboolean
RI_Init(void)
{
int j;
byte *colormap;
extern float r_turbsin[256];
Swap_Init();
@ -1415,7 +1416,8 @@ RI_Init(void)
R_Printf(PRINT_ALL, "Refresh: " REF_VERSION "\n");
R_Printf(PRINT_ALL, "Client: " YQ2VERSION "\n\n");
Draw_GetPalette();
GetPCXPalette (&colormap, d_8to24table);
free(colormap);
R_Register();

View file

@ -281,8 +281,6 @@ void COM_StripExtension(char *in, char *out);
void R_SwapBuffers(int);
int Draw_GetPalette(void);
image_t *R_LoadPic(char *name, byte *pic, int width, int realwidth,
int height, int realheight, imagetype_t type, int bits);
image_t *R_FindImage(char *name, imagetype_t type);

View file

@ -411,38 +411,3 @@ GL3_Draw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data)
GL3_Bind(0);
}
int
GL3_Draw_GetPalette(void)
{
int i;
int r, g, b;
unsigned v;
byte *pic, *pal;
int width, height;
/* get the palette */
LoadPCX("pics/colormap.pcx", &pic, &pal, &width, &height);
if (!pal)
{
ri.Sys_Error(ERR_FATAL, "Couldn't load pics/colormap.pcx");
}
for (i = 0; i < 256; i++)
{
r = pal[i * 3 + 0];
g = pal[i * 3 + 1];
b = pal[i * 3 + 2];
v = (255u << 24) + (r << 0) + (g << 8) + (b << 16);
d_8to24table[i] = LittleLong(v);
}
d_8to24table[255] &= LittleLong(0xffffff); /* 255 is transparent */
free(pic);
free(pal);
return 0;
}

View file

@ -452,6 +452,8 @@ enum { QGL_POINT_SPRITE = 0x8861 };
static qboolean
GL3_Init(void)
{
byte *colormap;
Swap_Init(); // FIXME: for fucks sake, this doesn't have to be done at runtime!
R_Printf(PRINT_ALL, "Refresh: " REF_VERSION "\n");
@ -466,7 +468,8 @@ GL3_Init(void)
return false;
}
GL3_Draw_GetPalette();
GetPCXPalette (&colormap, d_8to24table);
free(colormap);
GL3_Register();

View file

@ -413,7 +413,6 @@ extern void GL3_Draw_InitLocal(void);
extern void GL3_Draw_ShutdownLocal(void);
extern gl3image_t * GL3_Draw_FindPic(char *name);
extern void GL3_Draw_GetPicSize(int *w, int *h, char *pic);
extern int GL3_Draw_GetPalette(void);
extern void GL3_Draw_PicScaled(int x, int y, char *pic, float factor);
extern void GL3_Draw_StretchPic(int x, int y, int w, int h, char *pic);

View file

@ -77,6 +77,8 @@ typedef enum
extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
/* Shared images load */
extern void GetPCXPalette (byte **colormap, unsigned *d_8to24table);
extern void LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height);
extern void GetPCXInfo(char *filename, int *width, int *height);

View file

@ -210,7 +210,6 @@ int cachewidth;
pixel_t *d_viewbuffer;
zvalue_t *d_pzbuffer;
static void Draw_GetPalette (void);
static void RE_BeginFrame( float camera_separation );
static void Draw_BuildGammaTable(void);
static void RE_FlushFrame(int vmin, int vmax);
@ -465,7 +464,8 @@ RE_Init(void)
r_aliasuvscale = 1.0;
Draw_GetPalette ();
GetPCXPalette (&vid_colormap, (unsigned *)d_8to24table);
vid_alphamap = vid_colormap + 64*256;
/* set our "safe" mode */
sw_state.prev_mode = 4;
@ -1746,40 +1746,6 @@ RE_SetSky (char *name, float rotate, vec3_t axis)
}
}
/*
===============
Draw_GetPalette
===============
*/
static void
Draw_GetPalette (void)
{
byte *pal, *out;
int i;
/* get the palette and colormap */
LoadPCX ("pics/colormap.pcx", &vid_colormap, &pal, NULL, NULL);
if (!vid_colormap)
ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx");
vid_alphamap = vid_colormap + 64*256;
out = d_8to24table;
for (i=0 ; i<256 ; i++, out+=4)
{
int r, g, b;
r = pal[i*3+0];
g = pal[i*3+1];
b = pal[i*3+2];
out[0] = r;
out[1] = g;
out[2] = b;
}
free (pal);
}
/*
===============
RE_RegisterSkin