From d6b350572a10f8d1329e1e0dcdaedd020e0a5367 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 11 Dec 2022 23:16:54 +0200 Subject: [PATCH 01/14] Images: Get rid of custom Draw_GetPalette and move to pcx.c --- .gitignore | 2 ++ src/common/header/ref_shared.h | 2 ++ src/files/pcx.c | 35 +++++++++++++++++++++++++++ src/vk/vk_image.c | 44 +++------------------------------- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 641d98d..1e31926 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /build/ /release/ +*.orig +*.rej diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index bd9c1aa..4a46ac0 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -60,6 +60,8 @@ typedef enum extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 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); diff --git a/src/files/pcx.c b/src/files/pcx.c index fb9bcbf..0f23d95 100644 --- a/src/files/pcx.c +++ b/src/files/pcx.c @@ -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); +} diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index ea0d2c6..2b3b069 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1598,46 +1598,6 @@ void Vk_FreeUnusedImages (void) vulkan_memory_free_unused(); } - -/* -=============== -Draw_GetPalette -=============== -*/ -static int Draw_GetPalette (void) -{ - int i; - 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++) - { - unsigned v; - int r, g, b; - - 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; -} - - /* =============== Vk_InitImages @@ -1647,6 +1607,7 @@ void Vk_InitImages (void) { int i; float overbright; + byte *colormap; numvktextures = 0; img_loaded = 0; @@ -1671,7 +1632,8 @@ void Vk_InitImages (void) intensitytable[i] = j; } - Draw_GetPalette(); + GetPCXPalette (&colormap, d_8to24table); + free(colormap); overbright = vk_overbrightbits->value; From fa2794ef75e57d4698cba63798435272cd031b09 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 11 Dec 2022 23:32:29 +0200 Subject: [PATCH 02/14] Image: Share code for add file extension --- src/common/header/ref_shared.h | 12 ++++++------ src/files/pcx.c | 17 +++++++---------- src/files/stb.c | 25 +++++++++++++++++-------- src/files/wal.c | 15 ++++++++++----- src/vk/vk_image.c | 10 ++-------- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 4a46ac0..0c664a1 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -61,9 +61,12 @@ typedef enum extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 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); +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 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, @@ -72,9 +75,6 @@ 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); diff --git a/src/files/pcx.c b/src/files/pcx.c index 0f23d95..45022d8 100644 --- a/src/files/pcx.c +++ b/src/files/pcx.c @@ -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; @@ -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; @@ -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) @@ -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); diff --git a/src/files/stb.c b/src/files/stb.c index 7eb5043..3f5d357 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -47,6 +47,22 @@ #define STB_IMAGE_RESIZE_IMPLEMENTATION #include "stb_image_resize.h" +/* + * Add extension to file name + */ +void +FixFileExt(const char *origname, const char *ext, char *filename, size_t size) +{ + Q_strlcpy(filename, origname, size); + + /* Add the extension */ + if (strcmp(COM_FileExtension(filename), ext)) + { + Q_strlcat(filename, ".", size); + Q_strlcat(filename, ext, size); + } +} + /* * origname: the filename to be opened, might be without extension * type: extension of the type we wanna open ("jpg", "png" or "tga") @@ -57,14 +73,7 @@ LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *hei { char filename[256]; - Q_strlcpy(filename, origname, sizeof(filename)); - - /* Add the extension */ - if (strcmp(COM_FileExtension(filename), type) != 0) - { - Q_strlcat(filename, ".", sizeof(filename)); - Q_strlcat(filename, type, sizeof(filename)); - } + FixFileExt(origname, type, filename, sizeof(filename)); *pic = NULL; diff --git a/src/files/wal.c b/src/files/wal.c index ddc184c..fdb1cc8 100644 --- a/src/files/wal.c +++ b/src/files/wal.c @@ -31,12 +31,15 @@ */ void -GetWalInfo(char *name, int *width, int *height) +GetWalInfo(const char *origname, int *width, int *height) { miptex_t *mt; int size; + char filename[256]; - size = ri.FS_LoadFile(name, (void **)&mt); + FixFileExt(origname, "wal", filename, sizeof(filename)); + + size = ri.FS_LoadFile(filename, (void **)&mt); if (!mt) { @@ -58,19 +61,21 @@ GetWalInfo(char *name, int *width, int *height) } void -GetM8Info(char *name, int *width, int *height) +GetM8Info(const char *origname, int *width, int *height) { m8tex_t *mt; int size; + char filename[256]; - size = ri.FS_LoadFile(name, (void **)&mt); + FixFileExt(origname, "m8", filename, sizeof(filename)); + + size = ri.FS_LoadFile(filename, (void **)&mt); if (!mt) { return; } - if (size < sizeof(m8tex_t) || LittleLong (mt->version) != M8_VERSION) { ri.FS_FreeFile((void *)mt); diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 2b3b069..96000d2 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1253,7 +1253,7 @@ static image_t *Vk_LoadWal (char *name, imagetype_t type) } static image_t * -Vk_LoadM8(char *origname, imagetype_t type) +Vk_LoadM8(const char *origname, imagetype_t type) { m8tex_t *mt; int width, height, ofs, size; @@ -1261,13 +1261,7 @@ Vk_LoadM8(char *origname, imagetype_t type) char name[256]; unsigned char *image_buffer = NULL; - Q_strlcpy(name, origname, sizeof(name)); - - /* Add the extension */ - if (strcmp(COM_FileExtension(name), "m8")) - { - Q_strlcat(name, ".m8", sizeof(name)); - } + FixFileExt(origname, "m8", name, sizeof(name)); size = ri.FS_LoadFile(name, (void **)&mt); From 1732f4c6feae977f8ff162a14e9349e020ecffd7 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 12 Dec 2022 23:54:01 +0200 Subject: [PATCH 03/14] Image: Share code for load Wal --- src/common/header/ref_shared.h | 3 +++ src/files/wal.c | 49 +++++++++++++++++++++++++++++++--- src/vk/vk_image.c | 36 +------------------------ 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 0c664a1..4e02e84 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -61,6 +61,9 @@ typedef enum extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3))); /* Shared images load */ +typedef struct image_s* (*load_image_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, load_image_t loadImage); 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); diff --git a/src/files/wal.c b/src/files/wal.c index fdb1cc8..0a4f047 100644 --- a/src/files/wal.c +++ b/src/files/wal.c @@ -26,9 +26,52 @@ #include "../common/header/ref_shared.h" -/* - * NOTE: LoadWal() is in *_image.c because it needs the renderer-specific image_t - */ +struct image_s* +LoadWal(const char *origname, imagetype_t type, load_image_t loadImage) +{ + int width, height, ofs, size; + struct image_s *image; + char name[256]; + miptex_t *mt; + + FixFileExt(origname, "wal", name, sizeof(name)); + + size = ri.FS_LoadFile(name, (void **)&mt); + + if (!mt) + { + R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); + return NULL; + } + + if (size < sizeof(miptex_t)) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + width = LittleLong(mt->width); + height = LittleLong(mt->height); + ofs = LittleLong(mt->offsets[0]); + + if ((ofs <= 0) || (width <= 0) || (height <= 0) || + (((size - ofs) / height) < width)) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + image = loadImage(name, (byte *)mt + ofs, + width, 0, + height, 0, + (size - ofs), type, 8); + + ri.FS_FreeFile((void *)mt); + + return image; +} void GetWalInfo(const char *origname, int *width, int *height) diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 96000d2..be6e42b 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1218,40 +1218,6 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, return image; } - -/* -================ -Vk_LoadWal -================ -*/ -static image_t *Vk_LoadWal (char *name, imagetype_t type) -{ - miptex_t *mt; - int width, height, ofs; - image_t *image; - - ri.FS_LoadFile (name, (void **)&mt); - if (!mt) - { - R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); - return r_notexture; - } - - width = LittleLong (mt->width); - height = LittleLong (mt->height); - ofs = LittleLong (mt->offsets[0]); - - image = Vk_LoadPic(name, (byte *)mt + ofs, - width, width, - height, height, - height * width, - type, 8); - - ri.FS_FreeFile ((void *)mt); - - return image; -} - static image_t * Vk_LoadM8(const char *origname, imagetype_t type) { @@ -1411,7 +1377,7 @@ Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) } else if (!strcmp(ext, "wal")) { - image = Vk_LoadWal (name, type); + image = (image_t *)LoadWal(namewe, type, (load_image_t)Vk_LoadPic); } else if (!strcmp(ext, "m8")) { From 94fc74ca9d751c2ea6b0673a96958ee8744fcd76 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 00:03:20 +0200 Subject: [PATCH 04/14] Image: Share M8 --- src/common/header/ref_shared.h | 5 ++- src/files/wal.c | 72 ++++++++++++++++++++++++++++++++-- src/vk/vk_image.c | 71 +-------------------------------- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 4e02e84..6fce85c 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -61,9 +61,10 @@ typedef enum extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3))); /* Shared images load */ -typedef struct image_s* (*load_image_t)(const char *name, byte *pic, int width, int realwidth, +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, load_image_t loadImage); +extern struct image_s* LoadWal(const char *origname, imagetype_t type, loadimage_t load_image); +struct image_s* LoadM8(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); diff --git a/src/files/wal.c b/src/files/wal.c index 0a4f047..865b015 100644 --- a/src/files/wal.c +++ b/src/files/wal.c @@ -26,8 +26,8 @@ #include "../common/header/ref_shared.h" -struct image_s* -LoadWal(const char *origname, imagetype_t type, load_image_t loadImage) +struct image_s * +LoadWal(const char *origname, imagetype_t type, loadimage_t load_image) { int width, height, ofs, size; struct image_s *image; @@ -63,7 +63,7 @@ LoadWal(const char *origname, imagetype_t type, load_image_t loadImage) return NULL; } - image = loadImage(name, (byte *)mt + ofs, + image = load_image(name, (byte *)mt + ofs, width, 0, height, 0, (size - ofs), type, 8); @@ -73,6 +73,72 @@ LoadWal(const char *origname, imagetype_t type, load_image_t loadImage) return image; } +struct image_s * +LoadM8(const char *origname, imagetype_t type, loadimage_t load_image) +{ + m8tex_t *mt; + int width, height, ofs, size, i; + struct image_s *image; + char name[256]; + unsigned char *image_buffer = NULL; + + FixFileExt(origname, "m8", name, sizeof(name)); + + size = ri.FS_LoadFile(name, (void **)&mt); + + if (!mt) + { + R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); + return NULL; + } + + if (size < sizeof(m8tex_t)) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + if (LittleLong (mt->version) != M8_VERSION) + { + R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name); + ri.FS_FreeFile ((void *)mt); + return NULL; + } + + width = LittleLong(mt->width[0]); + height = LittleLong(mt->height[0]); + ofs = LittleLong(mt->offsets[0]); + + if ((ofs <= 0) || (width <= 0) || (height <= 0) || + (((size - ofs) / height) < width)) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + image_buffer = malloc ((size - ofs) * 4); + for(i=0; i<(size - ofs); i++) + { + unsigned char value = *((byte *)mt + ofs + i); + image_buffer[i * 4 + 0] = mt->palette[value].r; + image_buffer[i * 4 + 1] = mt->palette[value].g; + image_buffer[i * 4 + 2] = mt->palette[value].b; + image_buffer[i * 4 + 3] = value == 255 ? 0 : 255; + } + + image = load_image(name, image_buffer, + width, 0, + height, 0, + (size - ofs), type, 32); + free(image_buffer); + + ri.FS_FreeFile((void *)mt); + + return image; +} + void GetWalInfo(const char *origname, int *width, int *height) { diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index be6e42b..7b621f2 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1218,73 +1218,6 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, return image; } -static image_t * -Vk_LoadM8(const char *origname, imagetype_t type) -{ - m8tex_t *mt; - int width, height, ofs, size; - image_t *image; - char name[256]; - unsigned char *image_buffer = NULL; - - FixFileExt(origname, "m8", name, sizeof(name)); - - size = ri.FS_LoadFile(name, (void **)&mt); - - if (!mt) - { - R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); - return r_notexture; - } - - if (size < sizeof(m8tex_t)) - { - R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name); - ri.FS_FreeFile((void *)mt); - return r_notexture; - } - - if (LittleLong (mt->version) != M8_VERSION) - { - R_Printf(PRINT_ALL, "LoadWal: can't load %s, wrong magic value.\n", name); - ri.FS_FreeFile ((void *)mt); - return r_notexture; - } - - width = LittleLong(mt->width[0]); - height = LittleLong(mt->height[0]); - ofs = LittleLong(mt->offsets[0]); - - if ((ofs <= 0) || (width <= 0) || (height <= 0) || - (((size - ofs) / height) < width)) - { - R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name); - ri.FS_FreeFile((void *)mt); - return r_notexture; - } - - image_buffer = malloc (width * height * 4); - for(int i=0; ipalette[value].r; - image_buffer[i * 4 + 1] = mt->palette[value].g; - image_buffer[i * 4 + 2] = mt->palette[value].b; - image_buffer[i * 4 + 3] = value == 255 ? 0 : 255; - } - - image = Vk_LoadPic(name, image_buffer, - width, width, - height, height, - width * height, - type, 32); - free(image_buffer); - - ri.FS_FreeFile((void *)mt); - - return image; -} - static image_t* Vk_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type) { @@ -1377,11 +1310,11 @@ Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) } else if (!strcmp(ext, "wal")) { - image = (image_t *)LoadWal(namewe, type, (load_image_t)Vk_LoadPic); + image = (image_t *)LoadWal(namewe, type, (loadimage_t)Vk_LoadPic); } else if (!strcmp(ext, "m8")) { - image = Vk_LoadM8 (name, type); + image = (image_t *)LoadM8(namewe, type, (loadimage_t)Vk_LoadPic); } else if (!strcmp(ext, "tga")) { From ac2311f87363d7b44b1d43e17f72227a8aeb5dc2 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 00:07:36 +0200 Subject: [PATCH 05/14] Image: Add M32 support functions https://github.com/TTimo/GtkRadiant/blob/master/plugins/imagem8/m32.h --- src/common/header/files.h | 30 ++++++++++++ src/common/header/ref_shared.h | 4 +- src/files/wal.c | 83 ++++++++++++++++++++++++++++++++++ src/vk/vk_image.c | 8 ++-- 4 files changed, 120 insertions(+), 5 deletions(-) diff --git a/src/common/header/files.h b/src/common/header/files.h index 2d00a19..203425c 100644 --- a/src/common/header/files.h +++ b/src/common/header/files.h @@ -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" */ diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 6fce85c..7d36c77 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -64,13 +64,15 @@ extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (pr 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); -struct image_s* LoadM8(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, diff --git a/src/files/wal.c b/src/files/wal.c index 865b015..377d3be 100644 --- a/src/files/wal.c +++ b/src/files/wal.c @@ -139,6 +139,59 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image) return image; } +struct image_s * +LoadM32(const char *origname, imagetype_t type, loadimage_t load_image) +{ + m32tex_t *mt; + int width, height, ofs, size; + struct image_s *image; + char name[256]; + + FixFileExt(origname, "m32", name, sizeof(name)); + + size = ri.FS_LoadFile(name, (void **)&mt); + + if (!mt) + { + R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); + return NULL; + } + + if (size < sizeof(m8tex_t)) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + if (LittleLong (mt->version) != M32_VERSION) + { + R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name); + ri.FS_FreeFile ((void *)mt); + return NULL; + } + + width = LittleLong (mt->width[0]); + height = LittleLong (mt->height[0]); + ofs = LittleLong (mt->offsets[0]); + + if ((ofs <= 0) || (width <= 0) || (height <= 0) || + (((size - ofs) / height) < (width * 4))) + { + R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name); + ri.FS_FreeFile((void *)mt); + return NULL; + } + + image = load_image(name, (byte *)mt + ofs, + width, 0, + height, 0, + (size - ofs) / 4, type, 32); + ri.FS_FreeFile ((void *)mt); + + return image; +} + void GetWalInfo(const char *origname, int *width, int *height) { @@ -198,3 +251,33 @@ GetM8Info(const char *origname, int *width, int *height) return; } + +void +GetM32Info(const char *origname, int *width, int *height) +{ + m32tex_t *mt; + int size; + char filename[256]; + + FixFileExt(origname, "m32", filename, sizeof(filename)); + + size = ri.FS_LoadFile(filename, (void **)&mt); + + if (!mt) + { + return; + } + + if (size < sizeof(m32tex_t) || LittleLong (mt->version) != M32_VERSION) + { + ri.FS_FreeFile((void *)mt); + return; + } + + *width = LittleLong(mt->width[0]); + *height = LittleLong(mt->height[0]); + + ri.FS_FreeFile((void *)mt); + + return; +} diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 7b621f2..b2ee32d 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1256,10 +1256,10 @@ Vk_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t } image = Vk_LoadPic(name, pic, - width, realwidth, - height, realheight, - width * height, - type, 32); + width, realwidth, + height, realheight, + width * height, + type, 32); } } From b434562325583fda09f62e27697a563ebe562b93 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 00:11:09 +0200 Subject: [PATCH 06/14] Image: Share Hicolor --- src/common/header/ref_shared.h | 2 ++ src/files/stb.c | 56 +++++++++++++++++++++++++++++++ src/vk/vk_image.c | 60 ++++------------------------------ 3 files changed, 64 insertions(+), 54 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 7d36c77..aa6920a 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -66,6 +66,8 @@ typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, i 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 struct image_s* LoadHiColorImage(char *name, const char* namewe, const char *ext, + 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); diff --git a/src/files/stb.c b/src/files/stb.c index 3f5d357..92bdaed 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -434,3 +434,59 @@ scale3x(const byte *src, byte *dst, int width, int height) } } } + +struct image_s * +LoadHiColorImage(char *name, const char* namewe, const char *ext, + imagetype_t type, loadimage_t load_image) +{ + int realwidth = 0, realheight = 0; + int width = 0, height = 0; + struct image_s *image = NULL; + byte *pic = NULL; + + /* Get size of the original texture */ + if (strcmp(ext, "pcx") == 0) + { + GetPCXInfo(name, &realwidth, &realheight); + } + else if (strcmp(ext, "wal") == 0) + { + GetWalInfo(name, &realwidth, &realheight); + } + else if (strcmp(ext, "m8") == 0) + { + GetM8Info(name, &realwidth, &realheight); + } + else if (strcmp(ext, "m32") == 0) + { + GetM32Info(name, &realwidth, &realheight); + } + + /* try to load a tga, png or jpg (in that order/priority) */ + if ( LoadSTB(namewe, "tga", &pic, &width, &height) + || LoadSTB(namewe, "png", &pic, &width, &height) + || LoadSTB(namewe, "jpg", &pic, &width, &height) ) + { + if (width >= realwidth && height >= realheight) + { + if (realheight == 0 || realwidth == 0) + { + realheight = height; + realwidth = width; + } + + image = load_image(name, pic, + width, realwidth, + height, realheight, + width * height, + type, 32); + } + } + + if (pic) + { + free(pic); + } + + return image; +} diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index b2ee32d..419c3c9 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1218,59 +1218,6 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, return image; } -static image_t* -Vk_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type) -{ - image_t *image = NULL; - byte *pic = NULL; - int realwidth = 0, realheight = 0; - int width = 0, height = 0; - - if (strcmp(ext, "pcx") == 0) - { - /* Get size of the original texture */ - GetPCXInfo(name, &realwidth, &realheight); - } - else if (strcmp(ext, "wal") == 0) - { - /* Get size of the original texture */ - GetWalInfo(name, &realwidth, &realheight); - } - else if (strcmp(ext, "m8") == 0) - { - /* Get size of the original texture */ - GetM8Info(name, &realwidth, &realheight); - } - - /* try to load a tga, png or jpg (in that order/priority) */ - if ( LoadSTB(namewe, "tga", &pic, &width, &height) - || LoadSTB(namewe, "png", &pic, &width, &height) - || LoadSTB(namewe, "jpg", &pic, &width, &height) ) - { - if (width >= realwidth && height >= realheight) - { - if (realheight == 0 || realwidth == 0) - { - realheight = height; - realwidth = width; - } - - image = Vk_LoadPic(name, pic, - width, realwidth, - height, realheight, - width * height, - type, 32); - } - } - - if (pic) - { - free(pic); - } - - return image; -} - static image_t* Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) { @@ -1279,7 +1226,8 @@ Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) // with retexturing if (r_retexturing->value) { - image = Vk_LoadHiColorImage(name, namewe, ext, type); + image = (image_t *)LoadHiColorImage(name, namewe, ext, type, + (loadimage_t)Vk_LoadPic); } if (!image) @@ -1316,6 +1264,10 @@ Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) { image = (image_t *)LoadM8(namewe, type, (loadimage_t)Vk_LoadPic); } + else if (!strcmp(ext, "m32")) + { + image = (image_t *)LoadM32(namewe, type, (loadimage_t)Vk_LoadPic); + } else if (!strcmp(ext, "tga")) { if (!LoadSTB (namewe, "tga", &pic, &width, &height)) From 17fb10d683e1244249ffcf262e00574bf4d5471c Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 00:23:17 +0200 Subject: [PATCH 07/14] Image: Share LoadImage --- src/common/header/ref_shared.h | 4 +- src/files/stb.c | 74 +++++++++++++++++++++++++++++++++- src/files/wal.c | 3 -- src/vk/vk_image.c | 73 +-------------------------------- 4 files changed, 76 insertions(+), 78 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index aa6920a..98df990 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -66,8 +66,8 @@ typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, i 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 struct image_s* LoadHiColorImage(char *name, const char* namewe, const char *ext, - imagetype_t type, loadimage_t load_image); +extern struct image_s* LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, + qboolean r_retexturing, 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); diff --git a/src/files/stb.c b/src/files/stb.c index 92bdaed..27098fd 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -435,8 +435,8 @@ scale3x(const byte *src, byte *dst, int width, int height) } } -struct image_s * -LoadHiColorImage(char *name, const char* namewe, const char *ext, +static struct image_s * +LoadHiColorImage(const char *name, const char* namewe, const char *ext, imagetype_t type, loadimage_t load_image) { int realwidth = 0, realheight = 0; @@ -490,3 +490,73 @@ LoadHiColorImage(char *name, const char* namewe, const char *ext, return image; } + +struct image_s * +LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, + qboolean r_retexturing, loadimage_t load_image) +{ + struct image_s *image = NULL; + + // with retexturing and not skin + if (r_retexturing) + { + image = LoadHiColorImage(name, namewe, ext, type, load_image); + } + + if (!image) + { + if (!strcmp(ext, "pcx")) + { + byte *pic = NULL; + byte *palette = NULL; + int width = 0, height = 0; + + LoadPCX (namewe, &pic, &palette, &width, &height); + if (!pic) + return NULL; + + image = load_image(name, pic, + width, width, + height, height, + width * height, type, 8); + + if (palette) + { + free(palette); + } + free(pic); + } + else if (!strcmp(ext, "wal")) + { + image = LoadWal(namewe, type, load_image); + } + else if (!strcmp(ext, "m8")) + { + image = LoadM8(namewe, type, load_image); + } + else if (!strcmp(ext, "m32")) + { + image = LoadM32(namewe, type, load_image); + } + else if (!strcmp(ext, "tga") || + !strcmp(ext, "png") || + !strcmp(ext, "jpg")) + { + byte *pic = NULL; + int width = 0, height = 0; + + if (LoadSTB (namewe, ext, &pic, &width, &height) && pic) + { + image = load_image(name, pic, + width, width, + height, height, + width * height, + type, 32); + + free(pic); + } + } + } + + return image; +} diff --git a/src/files/wal.c b/src/files/wal.c index 377d3be..eded6ec 100644 --- a/src/files/wal.c +++ b/src/files/wal.c @@ -40,7 +40,6 @@ LoadWal(const char *origname, imagetype_t type, loadimage_t load_image) if (!mt) { - R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); return NULL; } @@ -88,7 +87,6 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image) if (!mt) { - R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); return NULL; } @@ -153,7 +151,6 @@ LoadM32(const char *origname, imagetype_t type, loadimage_t load_image) if (!mt) { - R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); return NULL; } diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 419c3c9..ee6cc32 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1218,76 +1218,6 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, return image; } -static image_t* -Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type) -{ - image_t *image = NULL; - - // with retexturing - if (r_retexturing->value) - { - image = (image_t *)LoadHiColorImage(name, namewe, ext, type, - (loadimage_t)Vk_LoadPic); - } - - if (!image) - { - byte *pic; - int width, height; - - // - // load the pic from disk - // - pic = NULL; - if (!strcmp(ext, "pcx")) - { - byte *palette; - palette = NULL; - - LoadPCX (name, &pic, &palette, &width, &height); - if (!pic) - return NULL; - image = Vk_LoadPic(name, pic, - width, width, - height, height, - width * height, - type, 8); - - if (palette) - free(palette); - } - else if (!strcmp(ext, "wal")) - { - image = (image_t *)LoadWal(namewe, type, (loadimage_t)Vk_LoadPic); - } - else if (!strcmp(ext, "m8")) - { - image = (image_t *)LoadM8(namewe, type, (loadimage_t)Vk_LoadPic); - } - else if (!strcmp(ext, "m32")) - { - image = (image_t *)LoadM32(namewe, type, (loadimage_t)Vk_LoadPic); - } - else if (!strcmp(ext, "tga")) - { - if (!LoadSTB (namewe, "tga", &pic, &width, &height)) - return NULL; - if (!pic) - return NULL; - image = Vk_LoadPic(name, pic, - width, width, - height, height, - width * height, - type, 32); - } - - if (pic) - free(pic); - } - - return image; -} - /* =============== Vk_FindImage @@ -1344,7 +1274,8 @@ image_t *Vk_FindImage (char *name, imagetype_t type) // // load the pic from disk // - image = Vk_LoadImage(name, namewe, ext, type); + image = (image_t *)LoadImage(name, namewe, ext, type, + r_retexturing->value, (loadimage_t)Vk_LoadPic); if (!image && r_validation->value > 0) { From 20360c5ad6ccae4604bd89b1a03d5fd9e2cb8276 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 22:45:59 +0200 Subject: [PATCH 08/14] Image: Share loadSky textures Add support of `r_palettedtextures` to all renders. --- src/common/header/ref_shared.h | 2 ++ src/files/stb.c | 38 ++++++++++++++++++++++++++++++++++ src/vk/header/local.h | 5 +++-- src/vk/vk_image.c | 22 ++++++++++++++++++-- src/vk/vk_rmain.c | 4 ++-- src/vk/vk_warp.c | 38 ++++++++++++---------------------- 6 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 98df990..a0a152b 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -95,5 +95,7 @@ extern void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilel 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); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/files/stb.c b/src/files/stb.c index 27098fd..5a942cb 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -560,3 +560,41 @@ LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t typ return image; } + +struct image_s* +GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, + findimage_t find_image) +{ + struct image_s *image = NULL; + char pathname[MAX_QPATH]; + + if (palettedtexture) + { + Com_sprintf(pathname, sizeof(pathname), "env/%s%s.pcx", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m32", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + return image; +} diff --git a/src/vk/header/local.h b/src/vk/header/local.h index 2d38c81..c7120ce 100644 --- a/src/vk/header/local.h +++ b/src/vk/header/local.h @@ -136,7 +136,7 @@ extern cvar_t *r_farsee; extern cvar_t *vk_overbrightbits; extern cvar_t *r_validation; extern cvar_t *vk_picmip; -extern cvar_t *vk_skymip; +extern cvar_t *r_palettedtexture; extern cvar_t *vk_flashblend; extern cvar_t *vk_finish; extern cvar_t *vk_shadows; @@ -240,7 +240,8 @@ struct image_s *RE_RegisterSkin (char *name); image_t *Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, int height, int realheight, size_t data_size, imagetype_t type, int bits); -image_t *Vk_FindImage (char *name, imagetype_t type); +image_t *Vk_FindImageUnsafe (const char *name, imagetype_t type); +image_t *Vk_FindImage (const char *name, imagetype_t type); void Vk_TextureMode( char *string ); void Vk_LmapTextureMode( char *string ); void Vk_ImageList_f (void); diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index ee6cc32..41c10c8 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1220,12 +1220,13 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, /* =============== -Vk_FindImage +Vk_FindImageUnsafe Finds or loads the given image or NULL =============== */ -image_t *Vk_FindImage (char *name, imagetype_t type) +image_t * +Vk_FindImageUnsafe (const char *name, imagetype_t type) { image_t *image; int i, len; @@ -1277,6 +1278,23 @@ image_t *Vk_FindImage (char *name, imagetype_t type) image = (image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)Vk_LoadPic); + return image; +} + +/* +=============== +Vk_FindImage + +Finds or loads the given image or no texture. +=============== +*/ +image_t * +Vk_FindImage (const char *name, imagetype_t type) +{ + image_t *image; + + image = Vk_FindImageUnsafe (name, type); + if (!image && r_validation->value > 0) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/vk/vk_rmain.c b/src/vk/vk_rmain.c index 38e5ccf..e714c30 100644 --- a/src/vk/vk_rmain.c +++ b/src/vk/vk_rmain.c @@ -94,7 +94,7 @@ cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level cvar_t *vk_overbrightbits; cvar_t *r_validation; cvar_t *vk_picmip; -cvar_t *vk_skymip; +cvar_t *r_palettedtexture; cvar_t *vk_flashblend; cvar_t *vk_finish; #if defined(__APPLE__) @@ -1176,7 +1176,7 @@ R_Register( void ) vk_overbrightbits = ri.Cvar_Get("vk_overbrightbits", "1.0", CVAR_ARCHIVE); r_validation = ri.Cvar_Get("r_validation", "0", CVAR_ARCHIVE); vk_picmip = ri.Cvar_Get("vk_picmip", "0", 0); - vk_skymip = ri.Cvar_Get("vk_skymip", "0", 0); + r_palettedtexture = ri.Cvar_Get("r_palettedtexture", "0", 0); vk_flashblend = ri.Cvar_Get("vk_flashblend", "0", 0); vk_finish = ri.Cvar_Get("vk_finish", "0", CVAR_ARCHIVE); r_clear = ri.Cvar_Get("r_clear", "0", CVAR_ARCHIVE); diff --git a/src/vk/vk_warp.c b/src/vk/vk_warp.c index 5c8c875..f22859a 100644 --- a/src/vk/vk_warp.c +++ b/src/vk/vk_warp.c @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // vk_warp.c -- sky and water polygons #include "header/local.h" -static char skyname[MAX_QPATH]; static float skyrotate; static vec3_t skyaxis; static image_t *sky_images[6]; @@ -683,7 +682,6 @@ void R_DrawSkyBox (void) } } - /* ============ RE_SetSky_s @@ -693,8 +691,8 @@ RE_SetSky_s static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; void RE_SetSky_s (const char *name, float rotate, const vec3_t axis) { + char skyname[MAX_QPATH]; int i; - char pathname[MAX_QPATH]; strncpy(skyname, name, sizeof(skyname) - 1); skyrotate = rotate; @@ -702,31 +700,21 @@ void RE_SetSky_s (const char *name, float rotate, const vec3_t axis) for (i = 0; i<6; i++) { - // chop down rotating skies for less memory - if (vk_skymip->value || skyrotate) - vk_picmip->value++; + image_t *image; - Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]); + image = (image_t *)GetSkyImage(skyname, suf[i], + r_palettedtexture->value, (findimage_t)Vk_FindImageUnsafe); - sky_images[i] = Vk_FindImage(pathname, it_sky); - if (!sky_images[i]) { - Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", skyname, suf[i]); - sky_images[i] = Vk_FindImage(pathname, it_sky); - } - - if (!sky_images[i]) - sky_images[i] = r_notexture; - - if (vk_skymip->value || skyrotate) - { // take less memory - vk_picmip->value--; - sky_min = 1.0 / 256; - sky_max = 255.0 / 256; - } - else + if (!image) { - sky_min = 1.0 / 512; - sky_max = 511.0 / 512; + R_Printf(PRINT_ALL, "%s: can't load %s:%s sky\n", + __func__, skyname, suf[i]); + image = r_notexture; } + + sky_images[i] = image; } + + sky_min = 1.0 / 512; + sky_max = 511.0 / 512; } From d382472026b5f5eefcdc045a32e147f845b3cdac Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 22:49:47 +0200 Subject: [PATCH 09/14] Image: Share GetTexImage --- src/common/header/ref_shared.h | 1 + src/files/stb.c | 23 +++++++++++++++++++++++ src/vk/vk_model.c | 19 +++++++------------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index a0a152b..edb9fcd 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -97,5 +97,6 @@ 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); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/files/stb.c b/src/files/stb.c index 5a942cb..f378af0 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -598,3 +598,26 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, return image; } + +struct image_s *GetTexImage(const char *name, findimage_t find_image) +{ + struct image_s *image = NULL; + char pathname[MAX_QPATH]; + + Com_sprintf(pathname, sizeof(pathname), "textures/%s.wal", name); + image = find_image(pathname, it_wall); + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "textures/%s.m32", name); + image = find_image(pathname, it_wall); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "textures/%s.m8", name); + image = find_image(pathname, it_wall); + } + + return image; +} diff --git a/src/vk/vk_model.c b/src/vk/vk_model.c index ff798ff..4059e9c 100644 --- a/src/vk/vk_model.c +++ b/src/vk/vk_model.c @@ -380,7 +380,6 @@ Mod_LoadTexinfo (model_t *loadmodel, const byte *mod_base, const lump_t *l) texinfo_t *in; mtexinfo_t *out, *step; int i, j, count; - char name[MAX_QPATH]; in = (void *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) @@ -397,6 +396,7 @@ Mod_LoadTexinfo (model_t *loadmodel, const byte *mod_base, const lump_t *l) for ( i=0 ; i 0) out->next = loadmodel->texinfo + next; else - out->next = NULL; - Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture); + out->next = NULL; - out->image = Vk_FindImage (name, it_wall); - if (!out->image || out->image == r_notexture) + image = GetTexImage(in->texture, (findimage_t)Vk_FindImageUnsafe); + if (!image) { - Com_sprintf (name, sizeof(name), "textures/%s.m8", in->texture); - out->image = Vk_FindImage (name, it_wall); + R_Printf(PRINT_ALL, "Couldn't load %s\n", in->texture); + image = r_notexture; } - if (!out->image) - { - R_Printf(PRINT_ALL, "Couldn't load %s\n", name); - out->image = r_notexture; - } + out->image = image; } // count animation frames From e9f08265821b6c3acf245dba8259db9603386a46 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 22:53:25 +0200 Subject: [PATCH 10/14] Image: Share Draw_FindPic --- src/common/header/ref_shared.h | 3 ++- src/files/pcx.c | 2 +- src/files/stb.c | 41 +++++++++++++++++++++++++++++++++- src/vk/vk_draw.c | 32 +++++++++----------------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index edb9fcd..c203838 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -87,7 +87,7 @@ 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); +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); @@ -98,5 +98,6 @@ extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, 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 *FindPic(const char *name, findimage_t find_image); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/files/pcx.c b/src/files/pcx.c index 45022d8..5468885 100644 --- a/src/files/pcx.c +++ b/src/files/pcx.c @@ -325,7 +325,7 @@ GetPCXPalette (byte **colormap, unsigned *d_8to24table) /* get the palette and colormap */ LoadPCX ("pics/colormap.pcx", colormap, &pal, NULL, NULL); - if (!colormap) + if (!*colormap || !pal) { ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx"); } diff --git a/src/files/stb.c b/src/files/stb.c index f378af0..5197deb 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -568,6 +568,7 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, struct image_s *image = NULL; char pathname[MAX_QPATH]; + /* Quake 2 */ if (palettedtexture) { Com_sprintf(pathname, sizeof(pathname), "env/%s%s.pcx", @@ -582,6 +583,7 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, image = find_image(pathname, it_sky); } + /* Heretic 2 */ if (!image) { Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m32", @@ -599,14 +601,17 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, return image; } -struct image_s *GetTexImage(const char *name, findimage_t find_image) +struct image_s * +GetTexImage(const char *name, findimage_t find_image) { struct image_s *image = NULL; char pathname[MAX_QPATH]; + /* Quake 2 */ Com_sprintf(pathname, sizeof(pathname), "textures/%s.wal", name); image = find_image(pathname, it_wall); + /* Heretic 2 */ if (!image) { Com_sprintf(pathname, sizeof(pathname), "textures/%s.m32", name); @@ -621,3 +626,37 @@ struct image_s *GetTexImage(const char *name, findimage_t find_image) return image; } + +struct image_s * +FindPic(const char *name, findimage_t find_image) +{ + struct image_s *image = NULL; + + if ((name[0] != '/') && (name[0] != '\\')) + { + char pathname[MAX_QPATH]; + + /* Quake 2 */ + Com_sprintf(pathname, sizeof(pathname), "pics/%s.pcx", name); + image = find_image(pathname, it_pic); + + /* Heretic 2 */ + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/misc/%s.m32", name); + image = find_image(pathname, it_pic); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/misc/%s.m8", name); + image = find_image(pathname, it_pic); + } + } + else + { + image = find_image(name + 1, it_pic); + } + + return image; +} diff --git a/src/vk/vk_draw.c b/src/vk/vk_draw.c index 527ff74..a0680d3 100644 --- a/src/vk/vk_draw.c +++ b/src/vk/vk_draw.c @@ -31,7 +31,7 @@ Draw_InitLocal */ void Draw_InitLocal (void) { - draw_chars = Vk_FindImage("pics/conchars.pcx", it_pic); + draw_chars = FindPic ("conchars", (findimage_t)Vk_FindImageUnsafe); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", __func__); @@ -85,19 +85,7 @@ RE_Draw_FindPic */ image_t *RE_Draw_FindPic (char *name) { - image_t *vk; - - if (name[0] != '/' && name[0] != '\\') - { - char fullname[MAX_QPATH]; - - Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name); - vk = Vk_FindImage(fullname, it_pic); - } - else - vk = Vk_FindImage(name + 1, it_pic); - - return vk; + return FindPic(name, (findimage_t)Vk_FindImageUnsafe); } /* @@ -107,17 +95,17 @@ RE_Draw_GetPicSize */ void RE_Draw_GetPicSize (int *w, int *h, char *name) { - image_t *vk; + image_t *image; - vk = RE_Draw_FindPic(name); - if (!vk) + image = FindPic(name, (findimage_t)Vk_FindImageUnsafe); + if (!image) { *w = *h = -1; return; } - *w = vk->width; - *h = vk->height; + *w = image->width; + *h = image->height; } /* @@ -132,7 +120,7 @@ void RE_Draw_StretchPic (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - vk = RE_Draw_FindPic(name); + vk = FindPic(name, (findimage_t)Vk_FindImageUnsafe); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -155,7 +143,7 @@ void RE_Draw_PicScaled (int x, int y, char *name, float scale) { image_t *vk; - vk = RE_Draw_FindPic(name); + vk = FindPic(name, (findimage_t)Vk_FindImageUnsafe); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -180,7 +168,7 @@ void RE_Draw_TileClear (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - image = RE_Draw_FindPic(name); + image = FindPic(name, (findimage_t)Vk_FindImageUnsafe); if (!image) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); From d8e77a5e82231c3c2d3754ff7c0b652ea76271df Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 23:06:38 +0200 Subject: [PATCH 11/14] Image: Check skin image before use --- src/files/pcx.c | 3 ++- src/vk/vk_draw.c | 3 ++- src/vk/vk_model.c | 7 ++++--- src/vk/vk_rmain.c | 11 ++++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/files/pcx.c b/src/files/pcx.c index 5468885..d44211f 100644 --- a/src/files/pcx.c +++ b/src/files/pcx.c @@ -327,7 +327,8 @@ GetPCXPalette (byte **colormap, unsigned *d_8to24table) LoadPCX ("pics/colormap.pcx", colormap, &pal, NULL, NULL); if (!*colormap || !pal) { - ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx"); + ri.Sys_Error (ERR_FATAL, "%s: Couldn't load pics/colormap.pcx", + __func__); } for (i=0 ; i<256 ; i++) diff --git a/src/vk/vk_draw.c b/src/vk/vk_draw.c index a0680d3..df07faf 100644 --- a/src/vk/vk_draw.c +++ b/src/vk/vk_draw.c @@ -34,7 +34,8 @@ void Draw_InitLocal (void) draw_chars = FindPic ("conchars", (findimage_t)Vk_FindImageUnsafe); if (!draw_chars) { - ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", __func__); + ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", + __func__); } } diff --git a/src/vk/vk_model.c b/src/vk/vk_model.c index 4059e9c..204a58f 100644 --- a/src/vk/vk_model.c +++ b/src/vk/vk_model.c @@ -415,7 +415,8 @@ Mod_LoadTexinfo (model_t *loadmodel, const byte *mod_base, const lump_t *l) image = GetTexImage(in->texture, (findimage_t)Vk_FindImageUnsafe); if (!image) { - R_Printf(PRINT_ALL, "Couldn't load %s\n", in->texture); + R_Printf(PRINT_ALL, "%s: Couldn't load %s\n", + __func__, in->texture); image = r_notexture; } @@ -1100,7 +1101,7 @@ Mod_ForName (const char *name, model_t *parent_model, qboolean crash) { mod->extradata = Mod_LoadMD2(mod->name, buf, modfilelen, mod->mins, mod->maxs, - (struct image_s **)mod->skins, (findimage_t)Vk_FindImage, + (struct image_s **)mod->skins, (findimage_t)Vk_FindImageUnsafe, &(mod->type)); if (!mod->extradata) { @@ -1113,7 +1114,7 @@ Mod_ForName (const char *name, model_t *parent_model, qboolean crash) case IDSPRITEHEADER: { mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen, - (struct image_s **)mod->skins, (findimage_t)Vk_FindImage, + (struct image_s **)mod->skins, (findimage_t)Vk_FindImageUnsafe, &(mod->type)); if (!mod->extradata) { diff --git a/src/vk/vk_rmain.c b/src/vk/vk_rmain.c index e714c30..1cc8437 100644 --- a/src/vk/vk_rmain.c +++ b/src/vk/vk_rmain.c @@ -195,6 +195,7 @@ void R_DrawSpriteModel (entity_t *currententity, model_t *currentmodel) dsprframe_t *frame; float *up, *right; dsprite_t *psprite; + image_t *skin; // don't even bother culling, because it's just a single // polygon without a surface cache @@ -246,7 +247,15 @@ void R_DrawSpriteModel (entity_t *currententity, model_t *currentmodel) vkCmdPushConstants(vk_activeCmdbuffer, vk_drawTexQuadPipeline[vk_state.current_renderpass].layout, VK_SHADER_STAGE_FRAGMENT_BIT, 17 * sizeof(float), sizeof(gamma), &gamma); - vkCmdBindDescriptorSets(vk_activeCmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk_drawSpritePipeline.layout, 0, 1, ¤tmodel->skins[currententity->frame]->vk_texture.descriptorSet, 0, NULL); + skin = currentmodel->skins[currententity->frame]; + if (!skin) + { + skin = r_notexture; + } + + vkCmdBindDescriptorSets(vk_activeCmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + vk_drawSpritePipeline.layout, 0, 1, + &skin->vk_texture.descriptorSet, 0, NULL); vkCmdDraw(vk_activeCmdbuffer, 6, 1, 0, 0); } From e753629e2d40784551d74442a7a8f9c902cdccae Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 23:14:45 +0200 Subject: [PATCH 12/14] Image: show missed images with r_validation --- src/vk/header/local.h | 1 - src/vk/vk_draw.c | 12 ++++++------ src/vk/vk_image.c | 21 ++------------------- src/vk/vk_model.c | 6 +++--- src/vk/vk_warp.c | 2 +- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/vk/header/local.h b/src/vk/header/local.h index c7120ce..fe297a1 100644 --- a/src/vk/header/local.h +++ b/src/vk/header/local.h @@ -240,7 +240,6 @@ struct image_s *RE_RegisterSkin (char *name); image_t *Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, int height, int realheight, size_t data_size, imagetype_t type, int bits); -image_t *Vk_FindImageUnsafe (const char *name, imagetype_t type); image_t *Vk_FindImage (const char *name, imagetype_t type); void Vk_TextureMode( char *string ); void Vk_LmapTextureMode( char *string ); diff --git a/src/vk/vk_draw.c b/src/vk/vk_draw.c index df07faf..c620e0e 100644 --- a/src/vk/vk_draw.c +++ b/src/vk/vk_draw.c @@ -31,7 +31,7 @@ Draw_InitLocal */ void Draw_InitLocal (void) { - draw_chars = FindPic ("conchars", (findimage_t)Vk_FindImageUnsafe); + draw_chars = FindPic ("conchars", (findimage_t)Vk_FindImage); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", @@ -86,7 +86,7 @@ RE_Draw_FindPic */ image_t *RE_Draw_FindPic (char *name) { - return FindPic(name, (findimage_t)Vk_FindImageUnsafe); + return FindPic(name, (findimage_t)Vk_FindImage); } /* @@ -98,7 +98,7 @@ void RE_Draw_GetPicSize (int *w, int *h, char *name) { image_t *image; - image = FindPic(name, (findimage_t)Vk_FindImageUnsafe); + image = FindPic(name, (findimage_t)Vk_FindImage); if (!image) { *w = *h = -1; @@ -121,7 +121,7 @@ void RE_Draw_StretchPic (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - vk = FindPic(name, (findimage_t)Vk_FindImageUnsafe); + vk = FindPic(name, (findimage_t)Vk_FindImage); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -144,7 +144,7 @@ void RE_Draw_PicScaled (int x, int y, char *name, float scale) { image_t *vk; - vk = FindPic(name, (findimage_t)Vk_FindImageUnsafe); + vk = FindPic(name, (findimage_t)Vk_FindImage); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -169,7 +169,7 @@ void RE_Draw_TileClear (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - image = FindPic(name, (findimage_t)Vk_FindImageUnsafe); + image = FindPic(name, (findimage_t)Vk_FindImage); if (!image) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 41c10c8..748cbec 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1220,13 +1220,13 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, /* =============== -Vk_FindImageUnsafe +Vk_FindImage Finds or loads the given image or NULL =============== */ image_t * -Vk_FindImageUnsafe (const char *name, imagetype_t type) +Vk_FindImage (const char *name, imagetype_t type) { image_t *image; int i, len; @@ -1278,23 +1278,6 @@ Vk_FindImageUnsafe (const char *name, imagetype_t type) image = (image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)Vk_LoadPic); - return image; -} - -/* -=============== -Vk_FindImage - -Finds or loads the given image or no texture. -=============== -*/ -image_t * -Vk_FindImage (const char *name, imagetype_t type) -{ - image_t *image; - - image = Vk_FindImageUnsafe (name, type); - if (!image && r_validation->value > 0) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/vk/vk_model.c b/src/vk/vk_model.c index 204a58f..69d9a13 100644 --- a/src/vk/vk_model.c +++ b/src/vk/vk_model.c @@ -412,7 +412,7 @@ Mod_LoadTexinfo (model_t *loadmodel, const byte *mod_base, const lump_t *l) else out->next = NULL; - image = GetTexImage(in->texture, (findimage_t)Vk_FindImageUnsafe); + image = GetTexImage(in->texture, (findimage_t)Vk_FindImage); if (!image) { R_Printf(PRINT_ALL, "%s: Couldn't load %s\n", @@ -1101,7 +1101,7 @@ Mod_ForName (const char *name, model_t *parent_model, qboolean crash) { mod->extradata = Mod_LoadMD2(mod->name, buf, modfilelen, mod->mins, mod->maxs, - (struct image_s **)mod->skins, (findimage_t)Vk_FindImageUnsafe, + (struct image_s **)mod->skins, (findimage_t)Vk_FindImage, &(mod->type)); if (!mod->extradata) { @@ -1114,7 +1114,7 @@ Mod_ForName (const char *name, model_t *parent_model, qboolean crash) case IDSPRITEHEADER: { mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen, - (struct image_s **)mod->skins, (findimage_t)Vk_FindImageUnsafe, + (struct image_s **)mod->skins, (findimage_t)Vk_FindImage, &(mod->type)); if (!mod->extradata) { diff --git a/src/vk/vk_warp.c b/src/vk/vk_warp.c index f22859a..4863bac 100644 --- a/src/vk/vk_warp.c +++ b/src/vk/vk_warp.c @@ -703,7 +703,7 @@ void RE_SetSky_s (const char *name, float rotate, const vec3_t axis) image_t *image; image = (image_t *)GetSkyImage(skyname, suf[i], - r_palettedtexture->value, (findimage_t)Vk_FindImageUnsafe); + r_palettedtexture->value, (findimage_t)Vk_FindImage); if (!image) { From 55330be2ae930c681e20a1e93dab2f5dc06f0a4f Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 23:24:22 +0200 Subject: [PATCH 13/14] Image: Share Mod_ReLoadSkins --- src/common/header/ref_shared.h | 32 +++++++++++++++++++++++++++----- src/files/stb.c | 6 +++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index c203838..e94a1c6 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -66,8 +66,6 @@ typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, i 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 struct image_s* LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, - qboolean r_retexturing, 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); @@ -76,7 +74,6 @@ 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); @@ -86,7 +83,30 @@ extern void scale3x(const byte *src, byte *dst, 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 */ +/* Shared models struct */ + +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]; + float mipadjust; /* FIXME: Used only by soft render */ + 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, @@ -98,6 +118,8 @@ extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, 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 *FindPic(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_ */ diff --git a/src/files/stb.c b/src/files/stb.c index 5197deb..77f9b75 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -68,7 +68,7 @@ FixFileExt(const char *origname, const char *ext, char *filename, size_t size) * type: extension of the type we wanna open ("jpg", "png" or "tga") * pic: pointer RGBA pixel data will be assigned to */ -qboolean +static qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height) { char filename[256]; @@ -492,7 +492,7 @@ LoadHiColorImage(const char *name, const char* namewe, const char *ext, } struct image_s * -LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, +R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, qboolean r_retexturing, loadimage_t load_image) { struct image_s *image = NULL; @@ -628,7 +628,7 @@ GetTexImage(const char *name, findimage_t find_image) } struct image_s * -FindPic(const char *name, findimage_t find_image) +R_FindPic(const char *name, findimage_t find_image) { struct image_s *image = NULL; From a234f687a460e21d871b7c92aa1bad02c723087f Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 23:32:31 +0200 Subject: [PATCH 14/14] Share SURF_* values between renders Reuse DRAWSKY value in soft render instead unused DRAWSKYBOX and SURF_FLOW. Move mipadjust calculation to usage place in soft render. --- src/common/header/ref_shared.h | 16 +++++++++++++++- src/vk/header/model.h | 19 ------------------- src/vk/vk_draw.c | 12 ++++++------ src/vk/vk_image.c | 2 +- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index e94a1c6..6476edf 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -85,6 +85,21 @@ extern const byte* Mod_DecompressVis(const byte *in, int row); /* 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; @@ -99,7 +114,6 @@ typedef struct medge_s typedef struct mtexinfo_s { float vecs[2][4]; - float mipadjust; /* FIXME: Used only by soft render */ int flags; int numframes; struct mtexinfo_s *next; /* animation chain */ diff --git a/src/vk/header/model.h b/src/vk/header/model.h index d459708..67a9300 100644 --- a/src/vk/header/model.h +++ b/src/vk/header/model.h @@ -41,10 +41,6 @@ BRUSH MODELS // // in memory representation // -typedef struct -{ - vec3_t position; -} mvertex_t; #define SIDE_FRONT 0 @@ -58,21 +54,6 @@ typedef struct #define SURF_DRAWBACKGROUND 0x40 #define SURF_UNDERWATER 0x80 -typedef struct -{ - 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 - image_t *image; -} mtexinfo_t; - #define VERTEXSIZE 7 typedef struct vkpoly_s diff --git a/src/vk/vk_draw.c b/src/vk/vk_draw.c index c620e0e..063b248 100644 --- a/src/vk/vk_draw.c +++ b/src/vk/vk_draw.c @@ -31,7 +31,7 @@ Draw_InitLocal */ void Draw_InitLocal (void) { - draw_chars = FindPic ("conchars", (findimage_t)Vk_FindImage); + draw_chars = R_FindPic ("conchars", (findimage_t)Vk_FindImage); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", @@ -86,7 +86,7 @@ RE_Draw_FindPic */ image_t *RE_Draw_FindPic (char *name) { - return FindPic(name, (findimage_t)Vk_FindImage); + return R_FindPic(name, (findimage_t)Vk_FindImage); } /* @@ -98,7 +98,7 @@ void RE_Draw_GetPicSize (int *w, int *h, char *name) { image_t *image; - image = FindPic(name, (findimage_t)Vk_FindImage); + image = R_FindPic(name, (findimage_t)Vk_FindImage); if (!image) { *w = *h = -1; @@ -121,7 +121,7 @@ void RE_Draw_StretchPic (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - vk = FindPic(name, (findimage_t)Vk_FindImage); + vk = R_FindPic(name, (findimage_t)Vk_FindImage); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -144,7 +144,7 @@ void RE_Draw_PicScaled (int x, int y, char *name, float scale) { image_t *vk; - vk = FindPic(name, (findimage_t)Vk_FindImage); + vk = R_FindPic(name, (findimage_t)Vk_FindImage); if (!vk) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); @@ -169,7 +169,7 @@ void RE_Draw_TileClear (int x, int y, int w, int h, char *name) if (!vk_frameStarted) return; - image = FindPic(name, (findimage_t)Vk_FindImage); + image = R_FindPic(name, (findimage_t)Vk_FindImage); if (!image) { R_Printf(PRINT_ALL, "%s(): Can't find pic: %s\n", __func__, name); diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index 748cbec..a17198d 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1275,7 +1275,7 @@ Vk_FindImage (const char *name, imagetype_t type) // // load the pic from disk // - image = (image_t *)LoadImage(name, namewe, ext, type, + image = (image_t *)R_LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)Vk_LoadPic); if (!image && r_validation->value > 0)