From d2a7a87c7f39bd423fde7f8b4228082d12839583 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 7 Nov 2019 16:30:29 -0800 Subject: [PATCH] Fix nonpacked to packed cast for OpenGL --- src/hardware/hw_cache.c | 51 ++++++++++++------------- src/hardware/hw_data.h | 4 +- src/hardware/hw_light.c | 27 +++++++------- src/hardware/hw_md2.c | 82 ++++++++++++++++++++--------------------- src/w_wad.c | 8 ++-- 5 files changed, 87 insertions(+), 85 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 5cfd0f61c..b74f949a5 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -825,10 +825,10 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) { GLPatch_t* const grpatch = patch; (void)patchnum; //unused - while (grpatch->mipmap.nextcolormap) + while (grpatch->mipmap->nextcolormap) { - GLMipmap_t *grmip = grpatch->mipmap.nextcolormap; - grpatch->mipmap.nextcolormap = grmip->nextcolormap; + GLMipmap_t *grmip = grpatch->mipmap->nextcolormap; + grpatch->mipmap->nextcolormap = grmip->nextcolormap; if (grmip->grInfo.data) Z_Free(grmip->grInfo.data); free(grmip); } @@ -1005,7 +1005,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum) { GLMipmap_t *grmip; - grmip = &HWR_GetCachedGLPatch(flatlumpnum)->mipmap; + grmip = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; if (!grmip->downloaded && !grmip->grInfo.data) HWR_CacheFlat(grmip, flatlumpnum); @@ -1088,22 +1088,22 @@ static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch) void HWR_GetPatch(GLPatch_t *gpatch) { // is it in hardware cache - if (!gpatch->mipmap.downloaded && !gpatch->mipmap.grInfo.data) + if (!gpatch->mipmap->downloaded && !gpatch->mipmap->grInfo.data) { // load the software patch, PU_STATIC or the Z_Malloc for hardware patch will // flush the software patch before the conversion! oh yeah I suffered patch_t *ptr = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); - HWR_MakePatch(ptr, gpatch, &gpatch->mipmap, true); + HWR_MakePatch(ptr, gpatch, gpatch->mipmap, true); // this is inefficient.. but the hardware patch in heap is purgeable so it should // not fragment memory, and besides the REAL cache here is the hardware memory Z_Free(ptr); } - HWD.pfnSetTexture(&gpatch->mipmap); + HWD.pfnSetTexture(gpatch->mipmap); // The system-memory patch data can be purged now. - Z_ChangeTag(gpatch->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(gpatch->mipmap->grInfo.data, PU_HWRCACHE_UNLOCKED); } @@ -1123,7 +1123,7 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap) // search for the mimmap // skip the first (no colormap translated) - for (grmip = &gpatch->mipmap; grmip->nextcolormap; ) + for (grmip = gpatch->mipmap; grmip->nextcolormap; ) { grmip = grmip->nextcolormap; if (grmip->colormap == colormap) @@ -1153,7 +1153,7 @@ void HWR_UnlockCachedPatch(GLPatch_t *gpatch) if (!gpatch) return; - Z_ChangeTag(gpatch->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(gpatch->mipmap->grInfo.data, PU_HWRCACHE_UNLOCKED); Z_ChangeTag(gpatch, PU_HWRPATCHINFO_UNLOCKED); } @@ -1241,7 +1241,7 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum) grpatch = HWR_GetCachedGLPatch(lumpnum); - if (!grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data) + if (!grpatch->mipmap->downloaded && !grpatch->mipmap->grInfo.data) { pic_t *pic; UINT8 *block; @@ -1257,19 +1257,19 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum) grpatch->topoffset = 0; // find the good 3dfx size (boring spec) - HWR_ResizeBlock (grpatch->width, grpatch->height, &grpatch->mipmap.grInfo); - grpatch->mipmap.width = (UINT16)blockwidth; - grpatch->mipmap.height = (UINT16)blockheight; + HWR_ResizeBlock (grpatch->width, grpatch->height, &grpatch->mipmap->grInfo); + grpatch->mipmap->width = (UINT16)blockwidth; + grpatch->mipmap->height = (UINT16)blockheight; if (pic->mode == PALETTE) - grpatch->mipmap.grInfo.format = textureformat; // can be set by driver + grpatch->mipmap->grInfo.format = textureformat; // can be set by driver else - grpatch->mipmap.grInfo.format = picmode2GR[pic->mode]; + grpatch->mipmap->grInfo.format = picmode2GR[pic->mode]; - Z_Free(grpatch->mipmap.grInfo.data); + Z_Free(grpatch->mipmap->grInfo.data); // allocate block - block = MakeBlock(&grpatch->mipmap); + block = MakeBlock(grpatch->mipmap); // if rounddown, rounddown patches as well as textures if (cv_grrounddown.value) @@ -1299,25 +1299,25 @@ GLPatch_t *HWR_GetPic(lumpnum_t lumpnum) if (grpatch->width == blockwidth && grpatch->height == blockheight && - format2bpp[grpatch->mipmap.grInfo.format] == format2bpp[picmode2GR[pic->mode]]) + format2bpp[grpatch->mipmap->grInfo.format] == format2bpp[picmode2GR[pic->mode]]) { // no conversion needed - M_Memcpy(grpatch->mipmap.grInfo.data, pic->data,len); + M_Memcpy(grpatch->mipmap->grInfo.data, pic->data,len); } else HWR_DrawPicInCache(block, newwidth, newheight, - blockwidth*format2bpp[grpatch->mipmap.grInfo.format], + blockwidth*format2bpp[grpatch->mipmap->grInfo.format], pic, - format2bpp[grpatch->mipmap.grInfo.format]); + format2bpp[grpatch->mipmap->grInfo.format]); Z_Unlock(pic); Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED); - grpatch->mipmap.flags = 0; + grpatch->mipmap->flags = 0; grpatch->max_s = (float)newwidth / (float)blockwidth; grpatch->max_t = (float)newheight / (float)blockheight; } - HWD.pfnSetTexture(&grpatch->mipmap); + HWD.pfnSetTexture(grpatch->mipmap); //CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grpatch->mipmap.grInfo.data, grpatch->mipmap.downloaded); return grpatch; @@ -1333,6 +1333,7 @@ GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) grpatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); grpatch->wadnum = wadnum; grpatch->lumpnum = lumpnum; + grpatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); M_AATreeSet(hwrcache, lumpnum, grpatch); } @@ -1436,7 +1437,7 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) { GLMipmap_t *grmip; - grmip = &HWR_GetCachedGLPatch(fademasklumpnum)->mipmap; + grmip = HWR_GetCachedGLPatch(fademasklumpnum)->mipmap; if (!grmip->downloaded && !grmip->grInfo.data) HWR_CacheFadeMask(grmip, fademasklumpnum); diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index 44929dd67..629861c23 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -83,8 +83,8 @@ struct GLPatch_s float max_s,max_t; UINT16 wadnum; // the software patch lump num for when the hardware patch UINT16 lumpnum; // was flushed, and we need to re-create it - GLMipmap_t mipmap; -}; + GLMipmap_t *mipmap; +} ATTRPACK; typedef struct GLPatch_s GLPatch_t; #endif //_HWR_DATA_ diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index 8f62f7763..491cb739f 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -1205,7 +1205,8 @@ void HWR_DL_AddLight(gr_vissprite_t *spr, GLPatch_t *patch) dynlights->nb++; } -static GLPatch_t lightmappatch; +static GLMipmap_t lightmappatchmipmap; +static GLPatch_t lightmappatch = { .mipmap = &lightmappatchmipmap }; void HWR_InitLight(void) { @@ -1215,7 +1216,7 @@ void HWR_InitLight(void) for (i = 0;i < NUMLIGHTS;i++) lspr[i].dynamic_sqrradius = lspr[i].dynamic_radius*lspr[i].dynamic_radius; - lightmappatch.mipmap.downloaded = false; + lightmappatch.mipmap->downloaded = false; coronalumpnum = W_CheckNumForName("CORONA"); } @@ -1226,10 +1227,10 @@ static void HWR_SetLight(void) { int i, j; - if (!lightmappatch.mipmap.downloaded && !lightmappatch.mipmap.grInfo.data) + if (!lightmappatch.mipmap->downloaded && !lightmappatch.mipmap->grInfo.data) { - UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap.grInfo.data); + UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap->grInfo.data); for (i = 0; i < 128; i++) { @@ -1242,23 +1243,23 @@ static void HWR_SetLight(void) Data[i*128+j] = 0; } } - lightmappatch.mipmap.grInfo.format = GR_TEXFMT_ALPHA_INTENSITY_88; + lightmappatch.mipmap->grInfo.format = GR_TEXFMT_ALPHA_INTENSITY_88; lightmappatch.width = 128; lightmappatch.height = 128; - lightmappatch.mipmap.width = 128; - lightmappatch.mipmap.height = 128; + lightmappatch.mipmap->width = 128; + lightmappatch.mipmap->height = 128; #ifdef GLIDE_API_COMPATIBILITY - lightmappatch.mipmap.grInfo.smallLodLog2 = GR_LOD_LOG2_128; - lightmappatch.mipmap.grInfo.largeLodLog2 = GR_LOD_LOG2_128; - lightmappatch.mipmap.grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + lightmappatch.mipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_128; + lightmappatch.mipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_128; + lightmappatch.mipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; #endif - lightmappatch.mipmap.flags = 0; //TF_WRAPXY; // DEBUG: view the overdraw ! + lightmappatch.mipmap->flags = 0; //TF_WRAPXY; // DEBUG: view the overdraw ! } - HWD.pfnSetTexture(&lightmappatch.mipmap); + HWD.pfnSetTexture(lightmappatch.mipmap); // The system-memory data can be purged now. - Z_ChangeTag(lightmappatch.mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(lightmappatch.mipmap->grInfo.data, PU_HWRCACHE_UNLOCKED); } //********************************************************** diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b847fdbc3..b53b17fcc 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -567,7 +567,7 @@ static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ //CONS_Debug(DBG_RENDER, "libpng load error on %s\n", filename); png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL); fclose(png_FILE); - Z_Free(grpatch->mipmap.grInfo.data); + Z_Free(grpatch->mipmap->grInfo.data); return 0; } #ifdef USE_FAR_KEYWORD @@ -608,7 +608,7 @@ static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ { png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr); - png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRCACHE, &grpatch->mipmap.grInfo.data); + png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRCACHE, &grpatch->mipmap->grInfo.data); png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); for (i = 0; i < height; i++) row_pointers[i] = PNG_image + i*pitch; @@ -682,7 +682,7 @@ static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h, pw = *w = header.xmax - header.xmin + 1; ph = *h = header.ymax - header.ymin + 1; - image = Z_Malloc(pw*ph*4, PU_HWRCACHE, &grpatch->mipmap.grInfo.data); + image = Z_Malloc(pw*ph*4, PU_HWRCACHE, &grpatch->mipmap->grInfo.data); if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) { @@ -730,39 +730,39 @@ static void md2_loadTexture(md2_t *model) if (model->grpatch) { grpatch = model->grpatch; - Z_Free(grpatch->mipmap.grInfo.data); + Z_Free(grpatch->mipmap->grInfo.data); } else grpatch = Z_Calloc(sizeof *grpatch, PU_HWRPATCHINFO, &(model->grpatch)); - if (!grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data) + if (!grpatch->mipmap->downloaded && !grpatch->mipmap->grInfo.data) { int w = 0, h = 0; #ifdef HAVE_PNG - grpatch->mipmap.grInfo.format = PNG_Load(filename, &w, &h, grpatch); - if (grpatch->mipmap.grInfo.format == 0) + grpatch->mipmap->grInfo.format = PNG_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap->grInfo.format == 0) #endif - grpatch->mipmap.grInfo.format = PCX_Load(filename, &w, &h, grpatch); - if (grpatch->mipmap.grInfo.format == 0) + grpatch->mipmap->grInfo.format = PCX_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap->grInfo.format == 0) return; - grpatch->mipmap.downloaded = 0; - grpatch->mipmap.flags = 0; + grpatch->mipmap->downloaded = 0; + grpatch->mipmap->flags = 0; grpatch->width = (INT16)w; grpatch->height = (INT16)h; - grpatch->mipmap.width = (UINT16)w; - grpatch->mipmap.height = (UINT16)h; + grpatch->mipmap->width = (UINT16)w; + grpatch->mipmap->height = (UINT16)h; #ifdef GLIDE_API_COMPATIBILITY // not correct! - grpatch->mipmap.grInfo.smallLodLog2 = GR_LOD_LOG2_256; - grpatch->mipmap.grInfo.largeLodLog2 = GR_LOD_LOG2_256; - grpatch->mipmap.grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + grpatch->mipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; #endif } - HWD.pfnSetTexture(&grpatch->mipmap); + HWD.pfnSetTexture(grpatch->mipmap); HWR_UnlockCachedPatch(grpatch); } @@ -780,42 +780,42 @@ static void md2_loadBlendTexture(md2_t *model) if (model->blendgrpatch) { grpatch = model->blendgrpatch; - Z_Free(grpatch->mipmap.grInfo.data); + Z_Free(grpatch->mipmap->grInfo.data); } else grpatch = Z_Calloc(sizeof *grpatch, PU_HWRPATCHINFO, &(model->blendgrpatch)); - if (!grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data) + if (!grpatch->mipmap->downloaded && !grpatch->mipmap->grInfo.data) { int w = 0, h = 0; #ifdef HAVE_PNG - grpatch->mipmap.grInfo.format = PNG_Load(filename, &w, &h, grpatch); - if (grpatch->mipmap.grInfo.format == 0) + grpatch->mipmap->grInfo.format = PNG_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap->grInfo.format == 0) #endif - grpatch->mipmap.grInfo.format = PCX_Load(filename, &w, &h, grpatch); - if (grpatch->mipmap.grInfo.format == 0) + grpatch->mipmap->grInfo.format = PCX_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap->grInfo.format == 0) { Z_Free(filename); return; } - grpatch->mipmap.downloaded = 0; - grpatch->mipmap.flags = 0; + grpatch->mipmap->downloaded = 0; + grpatch->mipmap->flags = 0; grpatch->width = (INT16)w; grpatch->height = (INT16)h; - grpatch->mipmap.width = (UINT16)w; - grpatch->mipmap.height = (UINT16)h; + grpatch->mipmap->width = (UINT16)w; + grpatch->mipmap->height = (UINT16)h; #ifdef GLIDE_API_COMPATIBILITY // not correct! - grpatch->mipmap.grInfo.smallLodLog2 = GR_LOD_LOG2_256; - grpatch->mipmap.grInfo.largeLodLog2 = GR_LOD_LOG2_256; - grpatch->mipmap.grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + grpatch->mipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; #endif } - HWD.pfnSetTexture(&grpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary + HWD.pfnSetTexture(grpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary HWR_UnlockCachedPatch(grpatch); Z_Free(filename); @@ -1029,8 +1029,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, cur = Z_Malloc(size*4, PU_HWRCACHE, &grmip->grInfo.data); memset(cur, 0x00, size*4); - image = gpatch->mipmap.grInfo.data; - blendimage = blendgpatch->mipmap.grInfo.data; + image = gpatch->mipmap->grInfo.data; + blendimage = blendgpatch->mipmap->grInfo.data; // Average all of the translation's colors if (color == SKINCOLOR_NONE || color >= MAXTRANSLATIONS) @@ -1145,13 +1145,13 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (colormap == colormaps || colormap == NULL) { // Don't do any blending - HWD.pfnSetTexture(&gpatch->mipmap); + HWD.pfnSetTexture(gpatch->mipmap); return; } // search for the mimmap // skip the first (no colormap translated) - for (grmip = &gpatch->mipmap; grmip->nextcolormap; ) + for (grmip = gpatch->mipmap; grmip->nextcolormap; ) { grmip = grmip->nextcolormap; if (grmip->colormap == colormap) @@ -1371,18 +1371,18 @@ void HWR_DrawMD2(gr_vissprite_t *spr) finalscale = md2->scale; //Hurdler: arf, I don't like that implementation at all... too much crappy gpatch = md2->grpatch; - if (!gpatch || !gpatch->mipmap.grInfo.format || !gpatch->mipmap.downloaded) + if (!gpatch || !gpatch->mipmap->grInfo.format || !gpatch->mipmap->downloaded) md2_loadTexture(md2); gpatch = md2->grpatch; // Load it again, because it isn't being loaded into gpatch after md2_loadtexture... - if ((gpatch && gpatch->mipmap.grInfo.format) // don't load the blend texture if the base texture isn't available - && (!md2->blendgrpatch || !((GLPatch_t *)md2->blendgrpatch)->mipmap.grInfo.format || !((GLPatch_t *)md2->blendgrpatch)->mipmap.downloaded)) + if ((gpatch && gpatch->mipmap->grInfo.format) // don't load the blend texture if the base texture isn't available + && (!md2->blendgrpatch || !((GLPatch_t *)md2->blendgrpatch)->mipmap->grInfo.format || !((GLPatch_t *)md2->blendgrpatch)->mipmap->downloaded)) md2_loadBlendTexture(md2); - if (gpatch && gpatch->mipmap.grInfo.format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture + if (gpatch && gpatch->mipmap->grInfo.format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture { if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE && - md2->blendgrpatch && ((GLPatch_t *)md2->blendgrpatch)->mipmap.grInfo.format + md2->blendgrpatch && ((GLPatch_t *)md2->blendgrpatch)->mipmap->grInfo.format && gpatch->width == ((GLPatch_t *)md2->blendgrpatch)->width && gpatch->height == ((GLPatch_t *)md2->blendgrpatch)->height) { INT32 skinnum = TC_DEFAULT; @@ -1413,7 +1413,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) else { // This is safe, since we know the texture has been downloaded - HWD.pfnSetTexture(&gpatch->mipmap); + HWD.pfnSetTexture(gpatch->mipmap); } } else diff --git a/src/w_wad.c b/src/w_wad.c index 51c77fd87..18781070c 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1565,22 +1565,22 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) grPatch = HWR_GetCachedGLPatchPwad(wad, lump); - if (grPatch->mipmap.grInfo.data) + if (grPatch->mipmap->grInfo.data) { if (tag == PU_CACHE) tag = PU_HWRCACHE; - Z_ChangeTag(grPatch->mipmap.grInfo.data, tag); + Z_ChangeTag(grPatch->mipmap->grInfo.data, tag); } else { patch_t *ptr = NULL; // Only load the patch if we haven't initialised the grPatch yet - if (grPatch->mipmap.width == 0) + if (grPatch->mipmap->width == 0) ptr = W_CacheLumpNumPwad(grPatch->wadnum, grPatch->lumpnum, PU_STATIC); // Run HWR_MakePatch in all cases, to recalculate some things - HWR_MakePatch(ptr, grPatch, &grPatch->mipmap, false); + HWR_MakePatch(ptr, grPatch, grPatch->mipmap, false); Z_Free(ptr); }