Rename structs, turn GrTextureFormat_t into an enum

This commit is contained in:
Jaime Passos 2020-07-06 00:52:10 -03:00
parent ac04853f8c
commit 3d50bef0e5
7 changed files with 75 additions and 81 deletions

View File

@ -27,27 +27,22 @@
#include "../r_patch.h"
#include "../p_setup.h"
INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes
INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole
INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes
INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole
static const INT32 format2bpp[16] =
static INT32 format2bpp(GLTextureFormat_t format)
{
0, //0
0, //1
1, //2 GR_TEXFMT_ALPHA_8
1, //3 GR_TEXFMT_INTENSITY_8
1, //4 GR_TEXFMT_ALPHA_INTENSITY_44
1, //5 GR_TEXFMT_P_8
4, //6 GR_RGBA
0, //7
0, //8
0, //9
2, //10 GR_TEXFMT_RGB_565
2, //11 GR_TEXFMT_ARGB_1555
2, //12 GR_TEXFMT_ARGB_4444
2, //13 GR_TEXFMT_ALPHA_INTENSITY_88
2, //14 GR_TEXFMT_AP_88
};
if (format == GL_TEXFMT_RGBA)
return 4;
else if (format == GL_TEXFMT_RGB_565
|| format == GL_TEXFMT_ARGB_1555
|| format == GL_TEXFMT_ARGB_4444
|| format == GL_TEXFMT_ALPHA_INTENSITY_88
|| format == GL_TEXFMT_AP_88)
return 2;
else
return 1;
}
// This code was originally placed directly in HWR_DrawPatchInCache.
// It is now split from it for my sanity! (and the sanity of others)
@ -307,7 +302,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
yfracstep = FRACUNIT;
scale_y = FRACUNIT;
bpp = format2bpp[mipmap->format];
bpp = format2bpp(mipmap->format);
if (bpp < 1 || bpp > 4)
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
@ -400,7 +395,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap,
yfracstep = (texture->height<< FRACBITS) / pblockheight;
scale_y = (pblockheight << FRACBITS) / texture->height;
bpp = format2bpp[mipmap->format];
bpp = format2bpp(mipmap->format);
if (bpp < 1 || bpp > 4)
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
@ -431,7 +426,7 @@ static UINT8 *MakeBlock(GLMipmap_t *grMipmap)
UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX);
INT32 blocksize = (grMipmap->width * grMipmap->height);
bpp = format2bpp[grMipmap->format];
bpp = format2bpp(grMipmap->format);
block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->data));
switch (bpp)
@ -453,7 +448,7 @@ static UINT8 *MakeBlock(GLMipmap_t *grMipmap)
// Create a composite texture from patches, adapt the texture size to a power of 2
// height and width for the hardware texture cache.
//
static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex)
{
UINT8 *block;
texture_t *texture;
@ -537,7 +532,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex)
Z_Unlock(realpatch);
}
//Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :(
if (format2bpp[grtex->mipmap.format]==4)
if (format2bpp(grtex->mipmap.format)==4)
{
for (i = 3; i < blocksize*4; i += 4) // blocksize*4 because blocksize doesn't include the bpp
{
@ -608,8 +603,8 @@ void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipm
// =================================================
static size_t gr_numtextures = 0; // Texture count
static GLTexture_t *gr_textures; // For all textures
static GLTexture_t *gr_flats; // For all (texture) flats, as normal flats don't need to be cached
static GLMapTexture_t *gr_textures; // For all textures
static GLMapTexture_t *gr_flats; // For all (texture) flats, as normal flats don't need to be cached
void HWR_InitTextureCache(void)
{
@ -713,7 +708,7 @@ void HWR_SetPalette(RGBA_t *palette)
// hardware driver will flush there own cache if cache is non paletized
// now flush data texture cache so 32 bit texture are recomputed
if (patchformat == GR_RGBA || textureformat == GR_RGBA)
if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA)
{
Z_FreeTag(PU_HWRCACHE);
Z_FreeTag(PU_HWRCACHE_UNLOCKED);
@ -723,9 +718,9 @@ void HWR_SetPalette(RGBA_t *palette)
// --------------------------------------------------------------------------
// Make sure texture is downloaded and set it as the source
// --------------------------------------------------------------------------
GLTexture_t *HWR_GetTexture(INT32 tex)
GLMapTexture_t *HWR_GetTexture(INT32 tex)
{
GLTexture_t *grtex;
GLMapTexture_t *grtex;
#ifdef PARANOIA
if ((unsigned)tex >= gr_numtextures)
I_Error("HWR_GetTexture: tex >= numtextures\n");
@ -756,7 +751,7 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum)
size_t size, pflatsize;
// setup the texture info
grMipmap->format = GR_TEXFMT_P_8;
grMipmap->format = GL_TEXFMT_P_8;
grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED;
size = W_LumpLength(flatlumpnum);
@ -799,7 +794,7 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum)
UINT8 *flat;
// setup the texture info
grMipmap->format = GR_TEXFMT_P_8;
grMipmap->format = GL_TEXFMT_P_8;
grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED;
grMipmap->width = (UINT16)textures[texturenum]->width;
@ -842,7 +837,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
HWR_LiterallyGetFlat(levelflat->u.flat.lumpnum);
else if (levelflat->type == LEVELFLAT_TEXTURE)
{
GLTexture_t *grtex;
GLMapTexture_t *grtex;
INT32 texturenum = levelflat->u.texture.num;
#ifdef PARANOIA
if ((unsigned)texturenum >= gr_numtextures)
@ -986,11 +981,11 @@ void HWR_UnlockCachedPatch(GLPatch_t *gpatch)
static const INT32 picmode2GR[] =
{
GR_TEXFMT_P_8, // PALETTE
GL_TEXFMT_P_8, // PALETTE
0, // INTENSITY (unsupported yet)
GR_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this)
GL_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this)
0, // RGB24 (unsupported yet)
GR_RGBA, // RGBA32 (opengl only)
GL_TEXFMT_RGBA, // RGBA32 (opengl only)
};
static void HWR_DrawPicInCache(UINT8 *block, INT32 pblockwidth, INT32 pblockheight,
@ -1005,7 +1000,7 @@ static void HWR_DrawPicInCache(UINT8 *block, INT32 pblockwidth, INT32 pblockheig
stepy = ((INT32)SHORT(pic->height)<<FRACBITS)/pblockheight;
stepx = ((INT32)SHORT(pic->width)<<FRACBITS)/pblockwidth;
picbpp = format2bpp[picmode2GR[pic->mode]];
picbpp = format2bpp(picmode2GR[pic->mode]);
posy = 0;
for (j = 0; j < pblockheight; j++)
{
@ -1094,16 +1089,16 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum)
if (grpatch->width == SHORT(pic->width) &&
grpatch->height == SHORT(pic->height) &&
format2bpp[grpatch->mipmap->format] == format2bpp[picmode2GR[pic->mode]])
format2bpp(grpatch->mipmap->format) == format2bpp(picmode2GR[pic->mode]))
{
// no conversion needed
M_Memcpy(grpatch->mipmap->data, pic->data,len);
}
else
HWR_DrawPicInCache(block, SHORT(pic->width), SHORT(pic->height),
SHORT(pic->width)*format2bpp[grpatch->mipmap->format],
SHORT(pic->width)*format2bpp(grpatch->mipmap->format),
pic,
format2bpp[grpatch->mipmap->format]);
format2bpp(grpatch->mipmap->format));
Z_Unlock(pic);
Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED);
@ -1184,7 +1179,7 @@ static void HWR_CacheFadeMask(GLMipmap_t *grMipmap, lumpnum_t fademasklumpnum)
UINT16 fmheight = 0, fmwidth = 0;
// setup the texture info
grMipmap->format = GR_TEXFMT_ALPHA_8; // put the correct alpha levels straight in so I don't need to convert it later
grMipmap->format = GL_TEXFMT_ALPHA_8; // put the correct alpha levels straight in so I don't need to convert it later
grMipmap->flags = 0;
size = W_LumpLength(fademasklumpnum);

View File

@ -27,30 +27,29 @@
// TEXTURE INFO
// ==========================================================================
typedef unsigned long FxU32;
typedef long FxI32;
typedef FxI32 GrTextureFormat_t;
#define GR_TEXFMT_ALPHA_8 0x2 /* (0..0xFF) alpha */
#define GR_TEXFMT_INTENSITY_8 0x3 /* (0..0xFF) intensity */
#define GR_TEXFMT_ALPHA_INTENSITY_44 0x4
#define GR_TEXFMT_P_8 0x5 /* 8-bit palette */
#define GR_TEXFMT_RGB_565 0xa
#define GR_TEXFMT_ARGB_1555 0xb
#define GR_TEXFMT_ARGB_4444 0xc
#define GR_TEXFMT_ALPHA_INTENSITY_88 0xd
#define GR_TEXFMT_AP_88 0xe /* 8-bit alpha 8-bit palette */
#define GR_RGBA 0x6 // 32 bit RGBA !
typedef enum GLTextureFormat_e
{
GL_TEXFMT_ALPHA_8 = 0x2, /* (0..0xFF) alpha */
GL_TEXFMT_INTENSITY_8 = 0x3, /* (0..0xFF) intensity */
GL_TEXFMT_ALPHA_INTENSITY_44 = 0x4,
GL_TEXFMT_P_8 = 0x5, /* 8-bit palette */
GL_TEXFMT_RGBA = 0x6, /* 32 bit RGBA! */
GL_TEXFMT_RGB_565 = 0xa,
GL_TEXFMT_ARGB_1555 = 0xb,
GL_TEXFMT_ARGB_4444 = 0xc,
GL_TEXFMT_ALPHA_INTENSITY_88 = 0xd,
GL_TEXFMT_AP_88 = 0xe, /* 8-bit alpha 8-bit palette */
} GLTextureFormat_t;
// data holds the address of the graphics data cached in heap memory
// NULL if the texture is not in Doom heap cache.
struct GLMipmap_s
{
//for TexDownloadMipMap
GrTextureFormat_t format;
GLTextureFormat_t format;
void *data;
FxU32 flags;
UINT32 flags;
UINT16 height;
UINT16 width;
UINT32 downloaded; // the dll driver have it in there cache ?
@ -67,13 +66,13 @@ typedef struct GLMipmap_s GLMipmap_t;
//
// Doom texture info, as cached for hardware rendering
//
struct GLTexture_s
struct GLMapTexture_s
{
GLMipmap_t mipmap;
float scaleX; //used for scaling textures on walls
float scaleY;
};
typedef struct GLTexture_s GLTexture_t;
typedef struct GLMapTexture_s GLMapTexture_t;
// a cached patch as converted to hardware format, holding the original patch_t

View File

@ -95,7 +95,7 @@ void HWR_FreeExtraSubsectors(void);
void HWR_GetLevelFlat(levelflat_t *levelflat);
void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum);
GLTexture_t *HWR_GetTexture(INT32 tex);
GLMapTexture_t *HWR_GetTexture(INT32 tex);
void HWR_GetPatch(GLPatch_t *gpatch);
void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap);
void HWR_UnlockCachedPatch(GLPatch_t *gpatch);

View File

@ -1245,7 +1245,7 @@ static void HWR_SetLight(void)
Data[i*128+j] = 0;
}
}
lightmappatch.mipmap->format = GR_TEXFMT_ALPHA_INTENSITY_88;
lightmappatch.mipmap->format = GL_TEXFMT_ALPHA_INTENSITY_88;
lightmappatch.width = 128;
lightmappatch.height = 128;

View File

@ -1055,7 +1055,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
fixed_t worldhighslope = 0, worldlowslope = 0;
fixed_t v1x, v1y, v2x, v2y;
GLTexture_t *grTex = NULL;
GLMapTexture_t *grTex = NULL;
float cliplow = 0.0f, cliphigh = 0.0f;
INT32 gr_midtexture;
fixed_t h, l; // 3D sides and 2s middle textures
@ -5812,7 +5812,7 @@ void HWR_Startup(void)
}
if (rendermode == render_opengl)
textureformat = patchformat = GR_RGBA;
textureformat = patchformat = GL_TEXFMT_RGBA;
startupdone = true;
}

View File

@ -141,7 +141,7 @@ static void PNG_warn(png_structp PNG, png_const_charp pngtext)
CONS_Debug(DBG_RENDER, "libpng warning at %p: %s", PNG, pngtext);
}
static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_t *grpatch)
static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_t *grpatch)
{
png_structp png_ptr;
png_infop png_info_ptr;
@ -245,7 +245,7 @@ static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
fclose(png_FILE);
*w = (int)width;
*h = (int)height;
return GR_RGBA;
return GL_TEXFMT_RGBA;
}
#endif
@ -271,7 +271,7 @@ typedef struct
UINT8 filler[54];
} PcxHeader;
static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
GLPatch_t *grpatch)
{
PcxHeader header;
@ -340,7 +340,7 @@ static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
}
}
fclose(file);
return GR_RGBA;
return GL_TEXFMT_RGBA;
}
// -----------------+
@ -686,7 +686,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
// no wrap around, no chroma key
grmip->flags = 0;
// setup the texture info
grmip->format = GR_RGBA;
grmip->format = GL_TEXFMT_RGBA;
}
if (grmip->data)

View File

@ -1662,8 +1662,8 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
w = pTexInfo->width;
h = pTexInfo->height;
if ((pTexInfo->format == GR_TEXFMT_P_8) ||
(pTexInfo->format == GR_TEXFMT_AP_88))
if ((pTexInfo->format == GL_TEXFMT_P_8) ||
(pTexInfo->format == GL_TEXFMT_AP_88))
{
const GLubyte *pImgData = (const GLubyte *)pTexInfo->data;
INT32 i, j;
@ -1691,7 +1691,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
pImgData++;
if (pTexInfo->format == GR_TEXFMT_AP_88)
if (pTexInfo->format == GL_TEXFMT_AP_88)
{
if (!(pTexInfo->flags & TF_CHROMAKEYED))
tex[w*j+i].s.alpha = *pImgData;
@ -1701,13 +1701,13 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
}
}
}
else if (pTexInfo->format == GR_RGBA)
else if (pTexInfo->format == GL_TEXFMT_RGBA)
{
// corona test : passed as ARGB 8888, which is not in glide formats
// Hurdler: not used for coronas anymore, just for dynamic lighting
ptex = pTexInfo->data;
}
else if (pTexInfo->format == GR_TEXFMT_ALPHA_INTENSITY_88)
else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88)
{
const GLubyte *pImgData = (const GLubyte *)pTexInfo->data;
INT32 i, j;
@ -1725,7 +1725,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
}
}
}
else if (pTexInfo->format == GR_TEXFMT_ALPHA_8) // Used for fade masks
else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks
{
const GLubyte *pImgData = (const GLubyte *)pTexInfo->data;
INT32 i, j;
@ -1761,7 +1761,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
}
if (pTexInfo->format == GR_TEXFMT_ALPHA_INTENSITY_88)
if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88)
{
//pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
if (MipMap)
@ -1782,7 +1782,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
}
}
else if (pTexInfo->format == GR_TEXFMT_ALPHA_8)
else if (pTexInfo->format == GL_TEXFMT_ALPHA_8)
{
//pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
if (MipMap)
@ -2969,13 +2969,13 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void)
// follows format2bpp in hw_cache.c
int bpp = 1;
int format = tmp->format;
if (format == GR_RGBA)
if (format == GL_TEXFMT_RGBA)
bpp = 4;
else if (format == GR_TEXFMT_RGB_565
|| format == GR_TEXFMT_ARGB_1555
|| format == GR_TEXFMT_ARGB_4444
|| format == GR_TEXFMT_ALPHA_INTENSITY_88
|| format == GR_TEXFMT_AP_88)
else if (format == GL_TEXFMT_RGB_565
|| format == GL_TEXFMT_ARGB_1555
|| format == GL_TEXFMT_ARGB_4444
|| format == GL_TEXFMT_ALPHA_INTENSITY_88
|| format == GL_TEXFMT_AP_88)
bpp = 2;
// Add it up!