Skip to content

Commit

Permalink
Merge pull request #36 from yquake2/shared_images
Browse files Browse the repository at this point in the history
Reuse image load with other renders
  • Loading branch information
0lvin authored Dec 15, 2022
2 parents 3da1dd3 + a234f68 commit 879808a
Show file tree
Hide file tree
Showing 13 changed files with 633 additions and 387 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build/
/release/
*.orig
*.rej
30 changes: 30 additions & 0 deletions src/common/header/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,36 @@ typedef struct m8tex_s
int value;
} m8tex_t;

/* .M32 texture file format */

#define M32_VERSION 0x4
#define M32_MIP_LEVELS 16

typedef struct m32tex_s
{
int version;
char name[128];
char altname[128]; // texture substitution
char animname[128]; // next frame in animation chain
char damagename[128]; // image that should be shown when damaged
unsigned width[M32_MIP_LEVELS], height[M32_MIP_LEVELS];
unsigned offsets[M32_MIP_LEVELS];
int flags;
int contents;
int value;
float scale_x, scale_y;
int mip_scale;

// detail texturing info
char dt_name[128]; // detailed texture name
float dt_scale_x, dt_scale_y;
float dt_u, dt_v;
float dt_alpha;
int dt_src_blend_mode, dt_dst_blend_mode;

int unused[20]; // future expansion to maintain compatibility with h2
} m32tex_t;

/* .BSP file format */

#define IDBSPHEADER (('P' << 24) + ('S' << 16) + ('B' << 8) + 'I') /* little-endian "IBSP" */
Expand Down
66 changes: 58 additions & 8 deletions src/common/header/ref_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,80 @@ typedef enum

extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3)));

extern void LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height);
extern void GetPCXInfo(char *filename, int *width, int *height);
/* Shared images load */
typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, int realwidth,
int height, int realheight, size_t data_size, imagetype_t type, int bits);
extern struct image_s* LoadWal(const char *origname, imagetype_t type, loadimage_t load_image);
extern struct image_s* LoadM8(const char *origname, imagetype_t type, loadimage_t load_image);
extern struct image_s* LoadM32(const char *origname, imagetype_t type, loadimage_t load_image);
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
extern void GetPCXPalette(byte **colormap, unsigned *d_8to24table);
extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height);
extern void GetPCXInfo(const char *origname, int *width, int *height);
extern void GetWalInfo(const char *name, int *width, int *height);
extern void GetM8Info(const char *name, int *width, int *height);
extern void GetM32Info(const char *name, int *width, int *height);

extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height);
extern qboolean ResizeSTB(const byte *input_pixels, int input_width, int input_height,
byte *output_pixels, int output_width, int output_height);
extern void SmoothColorImage(unsigned *dst, size_t size, size_t rstep);
extern void scale2x(const byte *src, byte *dst, int width, int height);
extern void scale3x(const byte *src, byte *dst, int width, int height);

extern void GetWalInfo(char *name, int *width, int *height);
extern void GetM8Info(char *name, int *width, int *height);

extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
extern const byte* Mod_DecompressVis(const byte *in, int row);

/* Shared models load */
typedef struct image_s* (*findimage_t)(char *name, imagetype_t type);
/* Shared models struct */

enum {
SIDE_FRONT = 0,
SIDE_BACK = 1,
SIDE_ON = 2
};

// FIXME: differentiate from texinfo SURF_ flags
enum {
SURF_PLANEBACK = 0x02,
SURF_DRAWSKY = 0x04, // sky brush face
SURF_DRAWTURB = 0x10,
SURF_DRAWBACKGROUND = 0x40,
SURF_UNDERWATER = 0x80
};

typedef struct mvertex_s
{
vec3_t position;
} mvertex_t;

typedef struct medge_s
{
unsigned short v[2];
unsigned int cachededgeoffset;
} medge_t;

typedef struct mtexinfo_s
{
float vecs[2][4];
int flags;
int numframes;
struct mtexinfo_s *next; /* animation chain */
struct image_s *image;
} mtexinfo_t;

/* Shared models func */
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s **skins,
findimage_t find_image, modtype_t *type);
extern void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
struct image_s **skins, findimage_t find_image, modtype_t *type);
extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image,
void *extradata, modtype_t type);
extern struct image_s *GetSkyImage(const char *skyname, const char* surfname,
qboolean palettedtexture, findimage_t find_image);
extern struct image_s *GetTexImage(const char *name, findimage_t find_image);
extern struct image_s *R_FindPic(const char *name, findimage_t find_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type,
qboolean r_retexturing, loadimage_t load_image);

#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */
53 changes: 43 additions & 10 deletions src/files/pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fixQuitScreen(byte* px)
}

void
LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height)
{
byte *raw;
pcx_t *pcx;
Expand All @@ -129,13 +129,7 @@ LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
byte *out, *pix;
char filename[256];

Q_strlcpy(filename, origname, sizeof(filename));

/* Add the extension */
if (strcmp(COM_FileExtension(filename), "pcx"))
{
Q_strlcat(filename, ".pcx", sizeof(filename));
}
FixFileExt(origname, "pcx", filename, sizeof(filename));

*pic = NULL;

Expand Down Expand Up @@ -276,7 +270,7 @@ LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
*pic = NULL;
}
else if(pcx_width == 319 && pcx_height == 239
&& Q_strcasecmp(origname, "pics/quit.pcx") == 0
&& Q_strcasecmp(filename, "pics/quit.pcx") == 0
&& Com_BlockChecksum(pcx, len) == 3329419434u)
{
// it's the quit screen, and the baseq2 one (identified by checksum)
Expand All @@ -293,10 +287,13 @@ LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
}

void
GetPCXInfo(char *filename, int *width, int *height)
GetPCXInfo(const char *origname, int *width, int *height)
{
pcx_t *pcx;
byte *raw;
char filename[256];

FixFileExt(origname, "pcx", filename, sizeof(filename));

ri.FS_LoadFile(filename, (void **)&raw);

Expand All @@ -315,3 +312,39 @@ 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 || !pal)
{
ri.Sys_Error (ERR_FATAL, "%s: Couldn't load pics/colormap.pcx",
__func__);
}

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);
}
Loading

0 comments on commit 879808a

Please sign in to comment.