port srb2s patch refactor
still needs all the new purge tags then we should hopefully be free of use after frees and everything
This commit is contained in:
1 parent
1ccd50fffa
commit
9eb34006c2
19 files changed
+644
-397
No files matched your search
+1
-1
@@ -794,7 +794,7 @@ void D_SRB2Loop(void)
|
||||
COM_ImmedExecute("cls;version");
|
||||
|
||||
if (rendermode == render_soft)
|
||||
V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, (patch_t *)W_CacheLumpNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL);
|
||||
V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL);
|
||||
I_FinishUpdate(); // page flip or blit buffer
|
||||
|
||||
for (;;)
|
||||
|
||||
+141
-114
@@ -191,7 +191,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
|
||||
// Draw each column to the block cache
|
||||
for (; ncols--; block += bpp, xfrac += xfracstep)
|
||||
{
|
||||
patchcol = (const column_t *)((const UINT8 *)realpatch + LONG(realpatch->columnofs[xfrac>>FRACBITS]));
|
||||
patchcol = (const column_t *)((const UINT8 *)realpatch->columns + (realpatch->columnofs[xfrac>>FRACBITS]));
|
||||
|
||||
HWR_DrawColumnInCache(patchcol, block, mipmap,
|
||||
pblockheight, blockmodulo,
|
||||
@@ -205,7 +205,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
|
||||
static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap,
|
||||
INT32 pblockwidth, INT32 pblockheight,
|
||||
texture_t *texture, texpatch_t *patch,
|
||||
const patch_t *realpatch)
|
||||
const softwarepatch_t *realpatch)
|
||||
{
|
||||
INT32 x, x1, x2;
|
||||
INT32 col, ncols;
|
||||
@@ -313,7 +313,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
|
||||
UINT8 *block;
|
||||
texture_t *texture;
|
||||
texpatch_t *patch;
|
||||
patch_t *realpatch;
|
||||
softwarepatch_t *realpatch;
|
||||
UINT8 *pdata;
|
||||
INT32 blockwidth, blockheight, blocksize;
|
||||
|
||||
INT32 i, idx;
|
||||
@@ -371,12 +372,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
|
||||
// Composite the columns together.
|
||||
for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++)
|
||||
{
|
||||
realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
realpatch = (softwarepatch_t *)pdata;
|
||||
|
||||
if (realpatch != NULL)
|
||||
{
|
||||
HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch);
|
||||
//Z_ChangeTag(realpatch, PU_HWRCACHE_UNLOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,20 +401,11 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
|
||||
// patch may be NULL if glMipmap has been initialised already and makebitmap is false
|
||||
void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap)
|
||||
{
|
||||
// don't do it twice (like a cache)
|
||||
if (glMipmap->width == 0)
|
||||
{
|
||||
// save the original patch header so that the GLPatch can be casted
|
||||
// into a standard patch_t struct and the existing code can get the
|
||||
// orginal patch dimensions and offsets.
|
||||
glPatch->width = SHORT(patch->width);
|
||||
glPatch->height = SHORT(patch->height);
|
||||
glPatch->leftoffset = SHORT(patch->leftoffset);
|
||||
glPatch->topoffset = SHORT(patch->topoffset);
|
||||
|
||||
glMipmap->width = glMipmap->height = 1;
|
||||
while (glMipmap->width < glPatch->width) glMipmap->width <<= 1;
|
||||
while (glMipmap->height < glPatch->height) glMipmap->height <<= 1;
|
||||
while (glMipmap->width < patch->width) glMipmap->width <<= 1;
|
||||
while (glMipmap->height < patch->height) glMipmap->height <<= 1;
|
||||
|
||||
// no wrap around, no chroma key
|
||||
glMipmap->flags = 0;
|
||||
@@ -421,9 +413,8 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo
|
||||
// setup the texture info
|
||||
glMipmap->format = patchformat;
|
||||
|
||||
//glPatch->max_s = glPatch->max_t = 1.0f;
|
||||
glPatch->max_s = (float)glPatch->width / (float)glMipmap->width;
|
||||
glPatch->max_t = (float)glPatch->height / (float)glMipmap->height;
|
||||
glPatch->max_s = (float)patch->width / (float)glMipmap->width;
|
||||
glPatch->max_t = (float)patch->height / (float)glMipmap->height;
|
||||
}
|
||||
|
||||
Z_Free(glMipmap->data);
|
||||
@@ -435,7 +426,7 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo
|
||||
|
||||
HWR_DrawPatchInCache(glMipmap,
|
||||
glMipmap->width, glMipmap->height,
|
||||
glPatch->width, glPatch->height,
|
||||
patch->width, patch->height,
|
||||
patch);
|
||||
}
|
||||
}
|
||||
@@ -444,22 +435,58 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo
|
||||
// CACHING HANDLING
|
||||
// =================================================
|
||||
|
||||
static size_t gl_numtextures;
|
||||
static size_t gl_numtextures = 0; // Texture count
|
||||
static GLMapTexture_t *gl_textures; // For all textures
|
||||
|
||||
void HWR_InitTextureCache(void)
|
||||
void HWR_FreeTextureData(patch_t *patch)
|
||||
{
|
||||
gl_numtextures = 0;
|
||||
gl_textures = NULL;
|
||||
GLPatch_t *grPatch;
|
||||
|
||||
if (!patch || !patch->hardware)
|
||||
return;
|
||||
|
||||
grPatch = patch->hardware;
|
||||
|
||||
if (vid.glstate == VID_GL_LIBRARY_LOADED)
|
||||
GL_DeleteTexture(grPatch->mipmap);
|
||||
if (grPatch->mipmap->data)
|
||||
Z_Free(grPatch->mipmap->data);
|
||||
}
|
||||
|
||||
// Callback function for HWR_FreeTextureCache.
|
||||
static void FreeMipmapColormap(INT32 patchnum, void *patch)
|
||||
void HWR_FreeTexture(patch_t *patch)
|
||||
{
|
||||
GLPatch_t* const pat = patch;
|
||||
(void)patchnum; //unused
|
||||
if (!patch)
|
||||
return;
|
||||
|
||||
if (patch->hardware)
|
||||
{
|
||||
GLPatch_t *glPatch = patch->hardware;
|
||||
|
||||
HWR_FreeTextureColormaps(patch);
|
||||
|
||||
if (glPatch->mipmap)
|
||||
{
|
||||
HWR_FreeTextureData(patch);
|
||||
Z_Free(glPatch->mipmap);
|
||||
}
|
||||
|
||||
Z_Free(patch->hardware);
|
||||
}
|
||||
|
||||
patch->hardware = NULL;
|
||||
}
|
||||
|
||||
// Called by HWR_FreePatchCache.
|
||||
void HWR_FreeTextureColormaps(patch_t *patch)
|
||||
{
|
||||
GLPatch_t *pat;
|
||||
|
||||
// The patch must be valid, obviously
|
||||
if (!patch)
|
||||
return;
|
||||
|
||||
pat = patch->hardware;
|
||||
|
||||
if (!pat)
|
||||
return;
|
||||
|
||||
@@ -481,9 +508,6 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch)
|
||||
|
||||
// Set the first colormap to the one that comes after it.
|
||||
next = pat->mipmap->nextcolormap;
|
||||
if (!next)
|
||||
break;
|
||||
|
||||
pat->mipmap->nextcolormap = next->nextcolormap;
|
||||
|
||||
// Free image data from memory.
|
||||
@@ -497,28 +521,51 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch)
|
||||
}
|
||||
}
|
||||
|
||||
void HWR_FreeMipmapCache(void)
|
||||
static void HWR_FreePatchCache(boolean freeall)
|
||||
{
|
||||
INT32 i;
|
||||
// free references to the textures
|
||||
GL_ClearMipMapCache();
|
||||
|
||||
// free all hardware-converted graphics cached in the heap
|
||||
// our gool is only the textures since user of the texture is the texture cache
|
||||
Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE);
|
||||
Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED);
|
||||
|
||||
// Alam: free the Z_Blocks before freeing it's users
|
||||
|
||||
// free all patch colormaps after each level: must be done after ClearMipMapCache!
|
||||
for (i = 0; i < numwadfiles; i++)
|
||||
M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap);
|
||||
{
|
||||
INT32 j = 0;
|
||||
for (; j < wadfiles[i]->numlumps; j++)
|
||||
(freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]);
|
||||
}
|
||||
}
|
||||
|
||||
void HWR_FreeTextureCache(void)
|
||||
// free all textures after each level
|
||||
void HWR_ClearAllTextures(void)
|
||||
{
|
||||
// free references to the textures
|
||||
HWR_FreeMipmapCache();
|
||||
GL_ClearMipMapCache();
|
||||
HWR_FreePatchCache(true);
|
||||
}
|
||||
|
||||
void HWR_FreeColormapCache(void)
|
||||
{
|
||||
HWR_FreePatchCache(false);
|
||||
}
|
||||
|
||||
void HWR_InitMapTextures(void)
|
||||
{
|
||||
gl_textures = NULL;
|
||||
}
|
||||
|
||||
static void FreeMapTexture(GLMapTexture_t *tex)
|
||||
{
|
||||
GL_DeleteTexture(&tex->mipmap);
|
||||
if (tex->mipmap.data)
|
||||
Z_Free(tex->mipmap.data);
|
||||
}
|
||||
|
||||
void HWR_FreeMapTextures(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < gl_numtextures; i++)
|
||||
{
|
||||
FreeMapTexture(&gl_textures[i]);
|
||||
}
|
||||
|
||||
// now the heap don't have any 'user' pointing to our
|
||||
// texturecache info, we can free it
|
||||
@@ -702,7 +749,7 @@ static void HWR_PrecacheLevelTextures(void)
|
||||
|
||||
static void HWR_PrecacheLevelSprites(void)
|
||||
{
|
||||
GLPatch_t *spritepatch;
|
||||
patch_t *spritepatch;
|
||||
char *spritepresent;
|
||||
size_t i, j, k;
|
||||
lumpnum_t lump;
|
||||
@@ -741,7 +788,7 @@ static void HWR_PrecacheLevelSprites(void)
|
||||
|
||||
#define cacheang(a) {\
|
||||
lump = sf->lumppat[a];\
|
||||
spritepatch = (GLPatch_t *)W_CachePatchNum(lump, PU_CACHE);\
|
||||
spritepatch = (patch_t *)W_CachePatchNum(lump, PU_CACHE);\
|
||||
if (spritepatch != NULL)\
|
||||
HWR_GetPatch(spritepatch);\
|
||||
}
|
||||
@@ -782,11 +829,12 @@ void HWR_PrecacheLevel(void)
|
||||
HWR_PrecacheLevelSprites();
|
||||
}
|
||||
|
||||
void HWR_LoadTextures(size_t pnumtextures)
|
||||
void HWR_LoadMapTextures(size_t pnumtextures)
|
||||
{
|
||||
// we must free it since numtextures changed
|
||||
HWR_FreeTextureCache();
|
||||
HWR_FreeMapTextures();
|
||||
|
||||
// Why not Z_Malloc?
|
||||
gl_numtextures = pnumtextures;
|
||||
#ifdef GLENCORE
|
||||
gl_textures = calloc(pnumtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore)
|
||||
@@ -794,7 +842,7 @@ void HWR_LoadTextures(size_t pnumtextures)
|
||||
gl_textures = calloc(pnumtextures, sizeof (*gl_textures));
|
||||
#endif
|
||||
if (gl_textures == NULL)
|
||||
I_Error("HWR_LoadTextures: ran out of memory for OpenGL textures. Sad!");
|
||||
I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@@ -812,15 +860,20 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore)
|
||||
tex = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Every texture in memory, stored in the
|
||||
// hardware renderer's bit depth format. Wow!
|
||||
#ifdef GLENCORE
|
||||
gltex = &gl_textures[tex*2 + (encoremap && !noencore ? 0 : 1)];
|
||||
#else
|
||||
gltex = &gl_textures[tex];
|
||||
#endif
|
||||
|
||||
// Generate texture if missing from the cache
|
||||
if (!gltex->mipmap.data && !gltex->mipmap.downloaded)
|
||||
HWR_GenerateTexture(tex, gltex, noencore);
|
||||
|
||||
// If hardware does not have the texture, then call pfnSetTexture to upload it
|
||||
// If hardware does not have the texture, then call GL_SetTexture to upload it
|
||||
if (!gltex->mipmap.downloaded)
|
||||
GL_SetTexture(&gltex->mipmap);
|
||||
HWR_SetCurrentTexture(&gltex->mipmap);
|
||||
@@ -869,6 +922,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum)
|
||||
pflatsize = 64;
|
||||
break;
|
||||
}
|
||||
|
||||
glMipmap->width = (UINT16)pflatsize;
|
||||
glMipmap->height = (UINT16)pflatsize;
|
||||
|
||||
@@ -891,11 +945,13 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum)
|
||||
void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
|
||||
{
|
||||
GLMipmap_t *glMipmap;
|
||||
patch_t *patch;
|
||||
|
||||
if (flatlumpnum == LUMPERROR)
|
||||
return;
|
||||
|
||||
glMipmap = HWR_GetCachedGLPatch(flatlumpnum)->mipmap;
|
||||
patch = HWR_GetCachedGLPatch(flatlumpnum);
|
||||
glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap;
|
||||
|
||||
glMipmap->colormap = colormaps;
|
||||
|
||||
@@ -916,27 +972,16 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
|
||||
Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED);
|
||||
}
|
||||
|
||||
//
|
||||
// HWR_LoadMappedPatch(): replace the skin color of the sprite in cache
|
||||
// : load it first in doom cache if not already
|
||||
//
|
||||
static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch)
|
||||
// --------------------+
|
||||
// HWR_LoadPatchMipmap : Generates a patch into a mipmap, usually the mipmap inside the patch itself
|
||||
// --------------------+
|
||||
static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap)
|
||||
{
|
||||
GLPatch_t *glPatch = patch->hardware;
|
||||
|
||||
if (!glMipmap->downloaded && !glMipmap->data)
|
||||
{
|
||||
patch_t *patch = glPatch->rawpatch;
|
||||
if (!patch)
|
||||
patch = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC);
|
||||
|
||||
HWR_MakePatch(patch, glPatch, glMipmap, true);
|
||||
|
||||
// You can't free rawpatch for some reason?
|
||||
// (Obviously I can't, sprite rotation needs that...)
|
||||
|
||||
if (!glPatch->rawpatch)
|
||||
Z_Free(patch);
|
||||
}
|
||||
|
||||
// If hardware does not have the texture, then call pfnSetTexture to upload it
|
||||
if (!glMipmap->downloaded)
|
||||
GL_SetTexture(glMipmap);
|
||||
@@ -949,46 +994,29 @@ static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch)
|
||||
// -----------------+
|
||||
// HWR_GetPatch : Downloads a patch to the hardware cache and make it ready for use
|
||||
// -----------------+
|
||||
void HWR_GetPatch(GLPatch_t *glPatch)
|
||||
void HWR_GetPatch(patch_t *patch)
|
||||
{
|
||||
// is it in hardware cache
|
||||
if (!glPatch->mipmap->downloaded && !glPatch->mipmap->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 = glPatch->rawpatch;
|
||||
if (!ptr)
|
||||
ptr = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC);
|
||||
|
||||
HWR_MakePatch(ptr, glPatch, glPatch->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
|
||||
if (!glPatch->rawpatch)
|
||||
Z_Free(ptr);
|
||||
}
|
||||
|
||||
// If hardware does not have the texture, then call pfnSetTexture to upload it
|
||||
if (!glPatch->mipmap->downloaded)
|
||||
GL_SetTexture(glPatch->mipmap);
|
||||
HWR_SetCurrentTexture(glPatch->mipmap);
|
||||
|
||||
// The system-memory patch data can be purged now.
|
||||
Z_ChangeTag(glPatch->mipmap->data, PU_HWRCACHE_UNLOCKED);
|
||||
if (!patch->hardware)
|
||||
Patch_CreateGL(patch);
|
||||
HWR_LoadPatchMipmap(patch, ((GLPatch_t *)patch->hardware)->mipmap);
|
||||
}
|
||||
|
||||
|
||||
// -------------------+
|
||||
// HWR_GetMappedPatch : Same as HWR_GetPatch for sprite color
|
||||
// -------------------+
|
||||
void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap)
|
||||
void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
|
||||
{
|
||||
GLPatch_t *glPatch;
|
||||
GLMipmap_t *glMipmap, *newMipmap;
|
||||
|
||||
if (!patch->hardware)
|
||||
Patch_CreateGL(patch);
|
||||
glPatch = patch->hardware;
|
||||
|
||||
if (colormap == colormaps || colormap == NULL)
|
||||
{
|
||||
// Load the default (green) color in doom cache (temporary?) AND hardware cache
|
||||
HWR_GetPatch(glPatch);
|
||||
// Load the default (green) color in hardware cache
|
||||
HWR_GetPatch(patch);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1000,7 +1028,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap)
|
||||
|
||||
if (UNLIKELY(glMipmap->colormap == colormap))
|
||||
{
|
||||
HWR_LoadMappedPatch(glMipmap, glPatch);
|
||||
HWR_LoadPatchMipmap(patch, glMipmap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1009,7 +1037,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap)
|
||||
|
||||
//BP: WARNING: don't free it manually without clearing the cache of harware renderer
|
||||
// (it have a liste of mipmap)
|
||||
// this malloc is cleared in HWR_FreeTextureCache
|
||||
// this malloc is cleared in HWR_FreeColormapCache
|
||||
// (...) unfortunately z_malloc fragment alot the memory :(so malloc is better
|
||||
newMipmap = calloc(1, sizeof (*newMipmap));
|
||||
if (newMipmap == NULL)
|
||||
@@ -1017,7 +1045,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap)
|
||||
glMipmap->nextcolormap = newMipmap;
|
||||
|
||||
newMipmap->colormap = colormap;
|
||||
HWR_LoadMappedPatch(newMipmap, glPatch);
|
||||
HWR_LoadPatchMipmap(patch, newMipmap);
|
||||
}
|
||||
|
||||
void HWR_UnlockCachedPatch(GLPatch_t *glPatch)
|
||||
@@ -1028,24 +1056,20 @@ void HWR_UnlockCachedPatch(GLPatch_t *glPatch)
|
||||
Z_ChangeTag(glPatch->mipmap->data, PU_HWRCACHE_UNLOCKED);
|
||||
}
|
||||
|
||||
GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
|
||||
patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
|
||||
{
|
||||
aatree_t *hwrcache = wadfiles[wadnum]->hwrcache;
|
||||
GLPatch_t *glPatch;
|
||||
|
||||
if (!(glPatch = M_AATreeGet(hwrcache, lumpnum)))
|
||||
lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache;
|
||||
if (!lumpcache[lumpnum])
|
||||
{
|
||||
glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL);
|
||||
glPatch->wadnum = wadnum;
|
||||
glPatch->lumpnum = lumpnum;
|
||||
glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL);
|
||||
M_AATreeSet(hwrcache, lumpnum, glPatch);
|
||||
void *ptr = Z_Calloc(sizeof(patch_t), PU_CACHE, &lumpcache[lumpnum]);
|
||||
Patch_Create(NULL, 0, ptr);
|
||||
Patch_AllocateHardwarePatch(ptr);
|
||||
}
|
||||
|
||||
return glPatch;
|
||||
return (patch_t *)(lumpcache[lumpnum]);
|
||||
}
|
||||
|
||||
GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum)
|
||||
patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum)
|
||||
{
|
||||
return HWR_GetCachedGLPatchPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum));
|
||||
}
|
||||
@@ -1139,8 +1163,11 @@ static void HWR_CacheFadeMask(GLMipmap_t *glMipmap, lumpnum_t fademasklumpnum)
|
||||
void HWR_GetFadeMask(lumpnum_t fademasklumpnum)
|
||||
{
|
||||
GLMipmap_t *glMipmap;
|
||||
patch_t *patch;
|
||||
|
||||
patch = HWR_GetCachedGLPatch(fademasklumpnum);
|
||||
glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap;
|
||||
|
||||
glMipmap = HWR_GetCachedGLPatch(fademasklumpnum)->mipmap;
|
||||
|
||||
if (!glMipmap->downloaded && !glMipmap->data)
|
||||
HWR_CacheFadeMask(glMipmap, fademasklumpnum);
|
||||
|
||||
+1
-14
@@ -62,24 +62,11 @@ struct GLMapTexture_s
|
||||
};
|
||||
typedef struct GLMapTexture_s GLMapTexture_t;
|
||||
|
||||
// a cached patch as converted to hardware format, holding the original patch_t
|
||||
// header so that the existing code can retrieve ->width, ->height as usual
|
||||
// This is returned by W_CachePatchNum()/W_CachePatchName(), when rendermode
|
||||
// is 'render_opengl'. Else it returns the normal patch_t data.
|
||||
// a cached patch as converted to hardware format
|
||||
struct GLPatch_s
|
||||
{
|
||||
// the 4 first fields come right away from the original patch_t
|
||||
INT16 width;
|
||||
INT16 height;
|
||||
INT16 leftoffset; // pixels to the left of origin
|
||||
INT16 topoffset; // pixels below the origin
|
||||
//
|
||||
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
|
||||
void *rawpatch; // :^)
|
||||
GLMipmap_t *mipmap;
|
||||
|
||||
boolean notfound; // if the texture file was not found, mark it here (used in model texture loading)
|
||||
};
|
||||
typedef struct GLPatch_s GLPatch_t;
|
||||
|
||||
+41
-38
@@ -71,10 +71,11 @@ static const float FLOATBASEVIDHEIGHT = (float)BASEVIDHEIGHT;
|
||||
// Notes : x,y : positions relative to the original Doom resolution
|
||||
// : textes(console+score) + menus + status bar
|
||||
// -----------------+
|
||||
void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
|
||||
void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option)
|
||||
{
|
||||
FOutVector v[4];
|
||||
FBITFIELD flags;
|
||||
GLPatch_t *hwrPatch;
|
||||
|
||||
// 3--2
|
||||
// | /|
|
||||
@@ -87,6 +88,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
|
||||
|
||||
// make patch ready in hardware cache
|
||||
HWR_GetPatch(gpatch);
|
||||
hwrPatch = ((GLPatch_t *)gpatch->hardware);
|
||||
|
||||
switch (option & V_SCALEPATCHMASK)
|
||||
{
|
||||
@@ -106,17 +108,17 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
|
||||
if (option & V_NOSCALESTART)
|
||||
sdupx = sdupy = 2.0f;
|
||||
|
||||
v[0].x = v[3].x = (x*sdupx-SHORT(gpatch->leftoffset)*pdupx)/vid.width - 1;
|
||||
v[2].x = v[1].x = (x*sdupx+(SHORT(gpatch->width)-SHORT(gpatch->leftoffset))*pdupx)/vid.width - 1;
|
||||
v[0].y = v[1].y = 1-(y*sdupy-SHORT(gpatch->topoffset)*pdupy)/vid.height;
|
||||
v[2].y = v[3].y = 1-(y*sdupy+(SHORT(gpatch->height)-SHORT(gpatch->topoffset))*pdupy)/vid.height;
|
||||
v[0].x = v[3].x = (x*sdupx-(gpatch->leftoffset)*pdupx)/vid.width - 1;
|
||||
v[2].x = v[1].x = (x*sdupx+((gpatch->width)-(gpatch->leftoffset))*pdupx)/vid.width - 1;
|
||||
v[0].y = v[1].y = 1-(y*sdupy-(gpatch->topoffset)*pdupy)/vid.height;
|
||||
v[2].y = v[3].y = 1-(y*sdupy+((gpatch->height)-(gpatch->topoffset))*pdupy)/vid.height;
|
||||
|
||||
v[0].z = v[1].z = v[2].z = v[3].z = 1.0f;
|
||||
|
||||
v[0].s = v[3].s = 0.0f;
|
||||
v[2].s = v[1].s = gpatch->max_s;
|
||||
v[2].s = v[1].s = hwrPatch->max_s;
|
||||
v[0].t = v[1].t = 0.0f;
|
||||
v[2].t = v[3].t = gpatch->max_t;
|
||||
v[2].t = v[3].t = hwrPatch->max_t;
|
||||
|
||||
flags = PF_Translucent|PF_NoDepthTest;
|
||||
|
||||
@@ -129,7 +131,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
|
||||
GL_DrawPolygon(NULL, v, 4, flags);
|
||||
}
|
||||
|
||||
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags)
|
||||
void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags)
|
||||
{
|
||||
FOutVector v[4];
|
||||
FBITFIELD flags;
|
||||
@@ -137,6 +139,7 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
float cy = FIXED_TO_FLOAT(y);
|
||||
UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT);
|
||||
UINT8 blendmode = ((bflags & V_BLENDMASK) >> V_BLENDSHIFT);
|
||||
GLPatch_t *hwrPatch;
|
||||
|
||||
// 3--2
|
||||
// | /|
|
||||
@@ -156,6 +159,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
else
|
||||
HWR_GetMappedPatch(gpatch, colormap);
|
||||
|
||||
hwrPatch = ((GLPatch_t *)gpatch->hardware);
|
||||
|
||||
dupx = (float)vid.dupx;
|
||||
dupy = (float)vid.dupy;
|
||||
|
||||
@@ -186,13 +191,13 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
|
||||
// left offset
|
||||
if (option & V_FLIP)
|
||||
offsetx = (float)(SHORT(gpatch->width) - SHORT(gpatch->leftoffset)) * fscalew;
|
||||
offsetx = (float)((gpatch->width) - (gpatch->leftoffset)) * fscalew;
|
||||
else
|
||||
offsetx = (float)SHORT(gpatch->leftoffset) * fscalew;
|
||||
offsetx = (float)(gpatch->leftoffset) * fscalew;
|
||||
|
||||
// top offset
|
||||
// TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!?
|
||||
offsety = (float)SHORT(gpatch->topoffset) * fscaleh;
|
||||
offsety = (float)(gpatch->topoffset) * fscaleh;
|
||||
|
||||
if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs
|
||||
{
|
||||
@@ -220,17 +225,15 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
// if it's meant to cover the whole screen, black out the rest
|
||||
// cx and cy are possibly *slightly* off from float maths
|
||||
// This is done before here compared to software because we directly alter cx and cy to centre
|
||||
if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT)
|
||||
if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT)
|
||||
{
|
||||
// Need to temporarily cache the real patch to get the colour of the top left pixel
|
||||
patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC);
|
||||
const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0]));
|
||||
const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0]));
|
||||
|
||||
if (!column->topdelta)
|
||||
{
|
||||
const UINT8 *source = (const UINT8 *)(column) + 3;
|
||||
HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0]));
|
||||
}
|
||||
Z_Free(realpatch);
|
||||
}
|
||||
// centre screen
|
||||
if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f)
|
||||
@@ -252,8 +255,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
}
|
||||
}
|
||||
|
||||
fwidth = (float)SHORT(gpatch->width) * fscalew * dupx;
|
||||
fheight = (float)SHORT(gpatch->height) * fscaleh * dupy;
|
||||
fwidth = (float)(gpatch->width) * fscalew * dupx;
|
||||
fheight = (float)(gpatch->height) * fscaleh * dupy;
|
||||
|
||||
// positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1
|
||||
cx = -1.0f + (cx / (fvw / 2.0f));
|
||||
@@ -274,17 +277,17 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
|
||||
if (option & V_FLIP)
|
||||
{
|
||||
v[0].s = v[3].s = gpatch->max_s;
|
||||
v[0].s = v[3].s = hwrPatch->max_s;
|
||||
v[2].s = v[1].s = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
v[0].s = v[3].s = 0.0f;
|
||||
v[2].s = v[1].s = gpatch->max_s;
|
||||
v[2].s = v[1].s = hwrPatch->max_s;
|
||||
}
|
||||
|
||||
v[0].t = v[1].t = 0.0f;
|
||||
v[2].t = v[3].t = gpatch->max_t;
|
||||
v[2].t = v[3].t = hwrPatch->max_t;
|
||||
|
||||
// clip it since it is used for bunny scroll in doom I
|
||||
if (blendmode)
|
||||
@@ -314,13 +317,14 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
|
||||
GL_DrawPolygon(NULL, v, 4, flags);
|
||||
}
|
||||
|
||||
void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h)
|
||||
void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h)
|
||||
{
|
||||
FOutVector v[4];
|
||||
FBITFIELD flags;
|
||||
float cx = FIXED_TO_FLOAT(x);
|
||||
float cy = FIXED_TO_FLOAT(y);
|
||||
UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT);
|
||||
GLPatch_t *hwrPatch;
|
||||
|
||||
// 3--2
|
||||
// | /|
|
||||
@@ -336,6 +340,7 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
|
||||
|
||||
// make patch ready in hardware cache
|
||||
HWR_GetPatch(gpatch);
|
||||
hwrPatch = ((GLPatch_t *)gpatch->hardware);
|
||||
|
||||
dupx = (float)vid.dupx;
|
||||
dupy = (float)vid.dupy;
|
||||
@@ -358,8 +363,8 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
|
||||
dupx = dupy = (dupx < dupy ? dupx : dupy);
|
||||
fscale = FIXED_TO_FLOAT(pscale);
|
||||
|
||||
cy -= (float)SHORT(gpatch->topoffset) * fscale;
|
||||
cx -= (float)SHORT(gpatch->leftoffset) * fscale;
|
||||
cy -= (float)(gpatch->topoffset) * fscale;
|
||||
cx -= (float)(gpatch->leftoffset) * fscale;
|
||||
|
||||
if (!(option & V_NOSCALESTART))
|
||||
{
|
||||
@@ -371,17 +376,15 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
|
||||
// if it's meant to cover the whole screen, black out the rest
|
||||
// cx and cy are possibly *slightly* off from float maths
|
||||
// This is done before here compared to software because we directly alter cx and cy to centre
|
||||
if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT)
|
||||
if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT)
|
||||
{
|
||||
// Need to temporarily cache the real patch to get the colour of the top left pixel
|
||||
patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC);
|
||||
const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0]));
|
||||
const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0]));
|
||||
|
||||
if (!column->topdelta)
|
||||
{
|
||||
const UINT8 *source = (const UINT8 *)(column) + 3;
|
||||
HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0]));
|
||||
}
|
||||
Z_Free(realpatch);
|
||||
}
|
||||
// centre screen
|
||||
if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f)
|
||||
@@ -412,11 +415,11 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
|
||||
if (fheight > h - sy)
|
||||
fheight = h - sy;
|
||||
|
||||
if (fwidth > SHORT(gpatch->width))
|
||||
fwidth = SHORT(gpatch->width);
|
||||
if (fwidth > (gpatch->width))
|
||||
fwidth = (gpatch->width);
|
||||
|
||||
if (fheight > SHORT(gpatch->height))
|
||||
fheight = SHORT(gpatch->height);
|
||||
if (fheight > (gpatch->height))
|
||||
fheight = (gpatch->height);
|
||||
|
||||
if (pscale != FRACUNIT)
|
||||
{
|
||||
@@ -446,10 +449,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
|
||||
|
||||
v[0].z = v[1].z = v[2].z = v[3].z = 1.0f;
|
||||
|
||||
v[0].s = v[3].s = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s;
|
||||
v[2].s = v[1].s = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s;
|
||||
v[0].t = v[1].t = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t;
|
||||
v[2].t = v[3].t = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t;
|
||||
v[0].s = v[3].s = ((sx)/(float)(gpatch->width) )*hwrPatch->max_s;
|
||||
v[2].s = v[1].s = ((w )/(float)(gpatch->width) )*hwrPatch->max_s;
|
||||
v[0].t = v[1].t = ((sy)/(float)(gpatch->height))*hwrPatch->max_t;
|
||||
v[2].t = v[3].t = ((h )/(float)(gpatch->height))*hwrPatch->max_t;
|
||||
|
||||
flags = PF_Translucent|PF_NoDepthTest;
|
||||
|
||||
@@ -664,7 +667,7 @@ void HWR_DrawViewBorder(INT32 clearlines)
|
||||
INT32 top, side;
|
||||
INT32 baseviewwidth, baseviewheight;
|
||||
INT32 basewindowx, basewindowy;
|
||||
GLPatch_t *patch;
|
||||
patch_t *patch;
|
||||
|
||||
// if (gl_viewwidth == vid.width)
|
||||
// return;
|
||||
|
||||
+21
-12
@@ -32,7 +32,7 @@ typedef struct gl_vissprite_s
|
||||
float scale;
|
||||
float spritexscale, spriteyscale;
|
||||
float spritexoffset, spriteyoffset;
|
||||
GLPatch_t *gpatch;
|
||||
patch_t *gpatch;
|
||||
boolean flip;
|
||||
UINT8 translucency; //alpha level 0-255
|
||||
mobj_t *mobj;
|
||||
@@ -56,29 +56,38 @@ void HWR_FreeExtraSubsectors(void);
|
||||
// --------
|
||||
// hw_cache.c
|
||||
// --------
|
||||
void HWR_InitTextureCache(void);
|
||||
void HWR_FreeTextureCache(void);
|
||||
void HWR_FreeMipmapCache(void);
|
||||
void HWR_InitMapTextures(void);
|
||||
void HWR_LoadMapTextures(size_t pnumtextures);
|
||||
void HWR_FreeMapTextures(void);
|
||||
|
||||
patch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump);
|
||||
patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum);
|
||||
|
||||
void HWR_GetPatch(patch_t *gpatch);
|
||||
void HWR_GetMappedPatch(patch_t *gpatch, const UINT8 *colormap);
|
||||
void HWR_MakePatch(patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap);
|
||||
void HWR_GetFadeMask(lumpnum_t fademasklumpnum);
|
||||
|
||||
void HWR_PrecacheLevel(void);
|
||||
|
||||
GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore);
|
||||
void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap);
|
||||
// ^ some flats must NOT be remapped to encore, since we remap them as we cache them for ease, adding a toggle here seems wise.
|
||||
|
||||
GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore);
|
||||
void HWR_GetPatch(GLPatch_t *gpatch);
|
||||
void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap);
|
||||
void HWR_MakePatch(patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap);
|
||||
void HWR_FreeTexture(patch_t *patch);
|
||||
void HWR_FreeTextureData(patch_t *patch);
|
||||
void HWR_FreeTextureColormaps(patch_t *patch);
|
||||
void HWR_ClearAllTextures(void);
|
||||
void HWR_FreeColormapCache(void);
|
||||
void HWR_UnlockCachedPatch(GLPatch_t *gpatch);
|
||||
void HWR_SetPalette(RGBA_t *palette);
|
||||
|
||||
RGBA_t *HWR_GetTexturePalette(void);
|
||||
void HWR_SetPalette(RGBA_t *palette);
|
||||
void HWR_SetMapPalette(void);
|
||||
UINT32 HWR_CreateLightTable(UINT8 *lighttable);
|
||||
UINT32 HWR_GetLightTableID(extracolormap_t *colormap);
|
||||
void HWR_ClearLightTables(void);
|
||||
GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump);
|
||||
GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum);
|
||||
void HWR_GetFadeMask(lumpnum_t fademasklumpnum);
|
||||
|
||||
|
||||
// --------
|
||||
// hw_draw.c
|
||||
|
||||
+31
-37
@@ -855,7 +855,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
|
||||
{
|
||||
FOutVector wallVerts[4];
|
||||
wallsplat_t *splat;
|
||||
GLPatch_t *gpatch;
|
||||
patch_t *gpatch;
|
||||
fixed_t i;
|
||||
// seg bbox
|
||||
fixed_t segbbox[4];
|
||||
@@ -3348,7 +3348,7 @@ static gl_vissprite_t *HWR_NewVisSprite(void)
|
||||
return floorz;
|
||||
}
|
||||
|
||||
static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, GLPatch_t *gpatch)
|
||||
static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch)
|
||||
{
|
||||
float this_scale = 1.0f;
|
||||
FOutVector swallVerts[4];
|
||||
@@ -3608,7 +3608,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
{
|
||||
FOutVector wallVerts[4];
|
||||
FOutVector baseWallVerts[4]; // This is what the verts should end up as
|
||||
GLPatch_t *gpatch;
|
||||
patch_t *gpatch;
|
||||
GLPatch_t *hwrpatch;
|
||||
FSurfaceInfo Surf;
|
||||
extracolormap_t *colormap;
|
||||
INT32 lightlevel;
|
||||
@@ -3630,7 +3631,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
fixed_t v1x, v1y, v2x, v2y;
|
||||
INT32 shader = SHADER_NONE;
|
||||
|
||||
gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE);
|
||||
gpatch = spr->gpatch;
|
||||
hwrpatch = (GLPatch_t *)(gpatch->hardware);
|
||||
|
||||
// cache the patch in the graphics card memory
|
||||
//12/12/99: Hurdler: same comment as above (for md2)
|
||||
@@ -3664,25 +3666,25 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
|
||||
if (spr->flip)
|
||||
{
|
||||
baseWallVerts[0].s = baseWallVerts[3].s = gpatch->max_s;
|
||||
baseWallVerts[0].s = baseWallVerts[3].s = hwrpatch->max_s;
|
||||
baseWallVerts[2].s = baseWallVerts[1].s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseWallVerts[0].s = baseWallVerts[3].s = 0;
|
||||
baseWallVerts[2].s = baseWallVerts[1].s = gpatch->max_s;
|
||||
baseWallVerts[2].s = baseWallVerts[1].s = hwrpatch->max_s;
|
||||
}
|
||||
|
||||
// flip the texture coords (look familiar?)
|
||||
if (spr->vflip)
|
||||
{
|
||||
baseWallVerts[3].t = baseWallVerts[2].t = gpatch->max_t;
|
||||
baseWallVerts[3].t = baseWallVerts[2].t = hwrpatch->max_t;
|
||||
baseWallVerts[0].t = baseWallVerts[1].t = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseWallVerts[3].t = baseWallVerts[2].t = 0;
|
||||
baseWallVerts[0].t = baseWallVerts[1].t = gpatch->max_t;
|
||||
baseWallVerts[0].t = baseWallVerts[1].t = hwrpatch->max_t;
|
||||
}
|
||||
|
||||
// push it toward the camera to mitigate floor-clipping sprites
|
||||
@@ -3881,7 +3883,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite)
|
||||
static void HWR_DrawSprite(gl_vissprite_t *spr)
|
||||
{
|
||||
FOutVector wallVerts[4];
|
||||
GLPatch_t *gpatch; // sprite patch converted to hardware
|
||||
patch_t *gpatch; // sprite patch converted to hardware
|
||||
GLPatch_t *hwrpatch;
|
||||
FSurfaceInfo Surf;
|
||||
FBITFIELD blend = 0;
|
||||
|
||||
@@ -3905,7 +3908,8 @@ static void HWR_DrawSprite(gl_vissprite_t *spr)
|
||||
// sure to do it the right way. So actually, we keep normal sprite
|
||||
// in memory and we add the md2 model if it exists for that sprite
|
||||
|
||||
gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE);
|
||||
gpatch = spr->gpatch;
|
||||
hwrpatch = (GLPatch_t *)(gpatch->hardware);
|
||||
|
||||
// create the sprite billboard
|
||||
//
|
||||
@@ -3927,25 +3931,25 @@ static void HWR_DrawSprite(gl_vissprite_t *spr)
|
||||
|
||||
if (spr->flip)
|
||||
{
|
||||
wallVerts[0].s = wallVerts[3].s = gpatch->max_s;
|
||||
wallVerts[0].s = wallVerts[3].s = hwrpatch->max_s;
|
||||
wallVerts[2].s = wallVerts[1].s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
wallVerts[0].s = wallVerts[3].s = 0;
|
||||
wallVerts[2].s = wallVerts[1].s = gpatch->max_s;
|
||||
wallVerts[2].s = wallVerts[1].s = hwrpatch->max_s;
|
||||
}
|
||||
|
||||
// flip the texture coords (look familiar?)
|
||||
if (spr->vflip)
|
||||
{
|
||||
wallVerts[3].t = wallVerts[2].t = gpatch->max_t;
|
||||
wallVerts[3].t = wallVerts[2].t = hwrpatch->max_t;
|
||||
wallVerts[0].t = wallVerts[1].t = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
wallVerts[3].t = wallVerts[2].t = 0;
|
||||
wallVerts[0].t = wallVerts[1].t = gpatch->max_t;
|
||||
wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t;
|
||||
}
|
||||
|
||||
// cache the patch in the graphics card memory
|
||||
@@ -4031,7 +4035,8 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
|
||||
{
|
||||
FBITFIELD blend = 0;
|
||||
FOutVector wallVerts[4];
|
||||
GLPatch_t *gpatch; // sprite patch converted to hardware
|
||||
patch_t *gpatch; // sprite patch converted to hardware
|
||||
GLPatch_t *hwrpatch;
|
||||
FSurfaceInfo Surf;
|
||||
|
||||
INT32 shader = SHADER_NONE;
|
||||
@@ -4040,7 +4045,8 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
|
||||
return;
|
||||
|
||||
// cache sprite graphics
|
||||
gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE);
|
||||
gpatch = spr->gpatch;
|
||||
hwrpatch = (GLPatch_t *)(gpatch->hardware);
|
||||
|
||||
// create the sprite billboard
|
||||
//
|
||||
@@ -4061,10 +4067,10 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
|
||||
HWR_RotateSpritePolyToAim(spr, wallVerts, true, false);
|
||||
|
||||
wallVerts[0].s = wallVerts[3].s = 0;
|
||||
wallVerts[2].s = wallVerts[1].s = gpatch->max_s;
|
||||
wallVerts[2].s = wallVerts[1].s = hwrpatch->max_s;
|
||||
|
||||
wallVerts[3].t = wallVerts[2].t = 0;
|
||||
wallVerts[0].t = wallVerts[1].t = gpatch->max_t;
|
||||
wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t;
|
||||
|
||||
// cache the patch in the graphics card memory
|
||||
//12/12/99: Hurdler: same comment as above (for md2)
|
||||
@@ -4936,10 +4942,10 @@ static void HWR_ProjectSprite(mobj_t *thing)
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
if (rotsprite != NULL)
|
||||
vis->gpatch = (GLPatch_t *)rotsprite;
|
||||
vis->gpatch = (patch_t *)rotsprite;
|
||||
else
|
||||
#endif
|
||||
vis->gpatch = (GLPatch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE);
|
||||
vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE);
|
||||
|
||||
vis->mobj = thing;
|
||||
|
||||
@@ -5107,7 +5113,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
|
||||
vis->z2 = z2;
|
||||
vis->tz = tz;
|
||||
vis->dispoffset = 0; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST
|
||||
vis->gpatch = (GLPatch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE);
|
||||
vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE);
|
||||
vis->flip = flip;
|
||||
vis->mobj = (mobj_t *)thing;
|
||||
|
||||
@@ -5584,9 +5590,9 @@ static void HWR_RenderFrame(player_t *player, boolean skybox)
|
||||
if (splitscreen == 2 && player == &players[displayplayers[2]])
|
||||
{
|
||||
// V_DrawPatchFill, but for the fourth screen only
|
||||
GLPatch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE);
|
||||
patch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE);
|
||||
INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy);
|
||||
INT32 x, y, pw = SHORT(gpatch->width) * dupz, ph = SHORT(gpatch->height) * dupz;
|
||||
INT32 x, y, pw = (gpatch->width) * dupz, ph = (gpatch->height) * dupz;
|
||||
|
||||
for (x = vid.width>>1; x < vid.width; x += pw)
|
||||
{
|
||||
@@ -5739,17 +5745,6 @@ static void HWR_CheckForHorizonLines(void)
|
||||
|
||||
void HWR_LoadLevel(void)
|
||||
{
|
||||
// Lactozilla (December 8, 2019)
|
||||
// Level setup used to free EVERY mipmap from memory.
|
||||
// Even mipmaps that aren't related to level textures.
|
||||
// Presumably, the hardware render code used to store textures as level data.
|
||||
// Meaning, they had memory allocated and marked with the PU_LEVEL tag.
|
||||
// Level textures are only reloaded after R_LoadTextures, which is
|
||||
// when the texture list is loaded.
|
||||
|
||||
// Sal: Unfortunately, NOT freeing them causes the dreaded Color Bug.
|
||||
HWR_FreeMipmapCache();
|
||||
|
||||
HWR_CreatePlanePolygons((INT32)numnodes - 1);
|
||||
|
||||
// Build the sky dome
|
||||
@@ -5860,7 +5855,7 @@ void HWR_Startup(void)
|
||||
CONS_Printf("HWR_Startup()...\n");
|
||||
textureformat = patchformat = GL_TEXFMT_RGBA;
|
||||
|
||||
HWR_InitTextureCache();
|
||||
HWR_InitMapTextures();
|
||||
HWR_InitMD2();
|
||||
|
||||
gl_shadersavailable = HWR_InitShaders();
|
||||
@@ -5952,8 +5947,7 @@ void HWR_Shutdown(void)
|
||||
{
|
||||
CONS_Printf("HWR_Shutdown()\n");
|
||||
HWR_FreeExtraSubsectors();
|
||||
HWR_FreeMipmapCache();
|
||||
HWR_FreeTextureCache();
|
||||
HWR_FreeMapTextures();
|
||||
GL_FlushScreenTextures();
|
||||
#ifdef USE_FBO_OGL
|
||||
GL_Framebuffer_Disable();
|
||||
|
||||
@@ -90,9 +90,9 @@ extern boolean havepazrcst;
|
||||
extern boolean havefaytpad;
|
||||
|
||||
// hw_draw.c
|
||||
void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option);
|
||||
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags);
|
||||
void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h);
|
||||
void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option);
|
||||
void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags);
|
||||
void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h);
|
||||
void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color);
|
||||
void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 options); // Lat: separate flags from color since color needs to be an uint to work right.
|
||||
void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color);
|
||||
@@ -176,10 +176,6 @@ void HWR_ProcessSeg(void); // Sort of like GLWall::Process in GZDoom
|
||||
void HWR_CreatePlanePolygons(INT32 bspnum);
|
||||
extern boolean gl_maphasportals;
|
||||
|
||||
// hw_cache.c
|
||||
void HWR_LoadTextures(size_t pnumtextures);
|
||||
RGBA_t *HWR_GetTexturePalette(void);
|
||||
|
||||
// Console variables
|
||||
extern CV_PossibleValue_t glanisotropicmode_cons_t[];
|
||||
|
||||
|
||||
+106
-68
@@ -366,43 +366,49 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
|
||||
// -----------------+
|
||||
static void md2_loadTexture(md2_t *model)
|
||||
{
|
||||
GLPatch_t *glpatch;
|
||||
patch_t *patch;
|
||||
GLPatch_t *glPatch = NULL;
|
||||
|
||||
const char *filename = model->filename;
|
||||
|
||||
if (model->glpatch)
|
||||
{
|
||||
glpatch = model->glpatch;
|
||||
Z_Free(glpatch->mipmap->data);
|
||||
patch = model->glpatch;
|
||||
glPatch = (GLPatch_t *)(patch->hardware);
|
||||
if (glPatch)
|
||||
Z_Free(glPatch->mipmap->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
glpatch = Z_Calloc(sizeof *glpatch, PU_HWRPATCHINFO,
|
||||
&(model->glpatch));
|
||||
glpatch->mipmap = Z_Calloc(sizeof (GLMipmap_t), PU_HWRPATCHINFO, NULL);
|
||||
}
|
||||
model->glpatch = patch = Patch_Create(NULL, 0, NULL);
|
||||
|
||||
if (!glpatch->mipmap->downloaded && !glpatch->mipmap->data)
|
||||
if (!patch->hardware)
|
||||
Patch_AllocateHardwarePatch(patch);
|
||||
|
||||
if (glPatch == NULL)
|
||||
glPatch = (GLPatch_t *)(patch->hardware);
|
||||
|
||||
if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
glpatch->mipmap->format = PNG_Load(filename, &w, &h, glpatch);
|
||||
if (glpatch->mipmap->format == 0)
|
||||
glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch);
|
||||
if (glPatch->mipmap->format == 0)
|
||||
#endif
|
||||
glpatch->mipmap->format = PCX_Load(filename, &w, &h, glpatch);
|
||||
if (glpatch->mipmap->format == 0)
|
||||
glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch);
|
||||
if (glPatch->mipmap->format == 0)
|
||||
{
|
||||
glpatch->notfound = true;// mark it so its not searched for again repeatedly
|
||||
glPatch->notfound = true;// mark it so its not searched for again repeatedly
|
||||
return;
|
||||
}
|
||||
|
||||
glpatch->mipmap->downloaded = 0;
|
||||
glpatch->mipmap->flags = 0;
|
||||
glPatch->mipmap->downloaded = 0;
|
||||
glPatch->mipmap->flags = 0;
|
||||
|
||||
glpatch->width = (INT16)w;
|
||||
glpatch->height = (INT16)h;
|
||||
glpatch->mipmap->width = (UINT16)w;
|
||||
glpatch->mipmap->height = (UINT16)h;
|
||||
patch->width = (INT16)w;
|
||||
patch->height = (INT16)h;
|
||||
glPatch->mipmap->width = (UINT16)w;
|
||||
glPatch->mipmap->height = (UINT16)h;
|
||||
|
||||
// for palette rendering, color cube is applied in post-processing instead of here
|
||||
if (!HWR_ShouldUsePaletteRendering())
|
||||
@@ -410,7 +416,7 @@ static void md2_loadTexture(md2_t *model)
|
||||
UINT32 size;
|
||||
RGBA_t *image;
|
||||
// Lactozilla: Apply colour cube
|
||||
image = glpatch->mipmap->data;
|
||||
image = glPatch->mipmap->data;
|
||||
size = w*h;
|
||||
while (size--)
|
||||
{
|
||||
@@ -419,8 +425,8 @@ static void md2_loadTexture(md2_t *model)
|
||||
}
|
||||
}
|
||||
}
|
||||
GL_SetTexture(glpatch->mipmap);
|
||||
HWR_UnlockCachedPatch(glpatch);
|
||||
GL_SetTexture(glPatch->mipmap);
|
||||
HWR_UnlockCachedPatch(glPatch);
|
||||
}
|
||||
|
||||
// -----------------+
|
||||
@@ -428,49 +434,56 @@ static void md2_loadTexture(md2_t *model)
|
||||
// -----------------+
|
||||
static void md2_loadBlendTexture(md2_t *model)
|
||||
{
|
||||
GLPatch_t *glpatch;
|
||||
patch_t *patch;
|
||||
GLPatch_t *glPatch = NULL;
|
||||
|
||||
char *filename = Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL);
|
||||
|
||||
strcpy(filename, model->filename);
|
||||
|
||||
FIL_ForceExtension(filename, "_blend.png");
|
||||
|
||||
if (model->blendglpatch)
|
||||
{
|
||||
glpatch = model->blendglpatch;
|
||||
Z_Free(glpatch->mipmap->data);
|
||||
patch = model->blendglpatch;
|
||||
glPatch = (GLPatch_t *)(patch->hardware);
|
||||
if (glPatch)
|
||||
Z_Free(glPatch->mipmap->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
glpatch = Z_Calloc(sizeof *glpatch, PU_HWRPATCHINFO,
|
||||
&(model->blendglpatch));
|
||||
glpatch->mipmap = Z_Calloc(sizeof (GLMipmap_t), PU_HWRPATCHINFO, NULL);
|
||||
}
|
||||
model->blendglpatch = patch = Patch_Create(NULL, 0, NULL);
|
||||
|
||||
if (!glpatch->mipmap->downloaded && !glpatch->mipmap->data)
|
||||
if (!patch->hardware)
|
||||
Patch_AllocateHardwarePatch(patch);
|
||||
|
||||
if (glPatch == NULL)
|
||||
glPatch = (GLPatch_t *)(patch->hardware);
|
||||
|
||||
if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
#ifdef HAVE_PNG
|
||||
glpatch->mipmap->format = PNG_Load(filename, &w, &h, glpatch);
|
||||
if (glpatch->mipmap->format == 0)
|
||||
glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch);
|
||||
if (glPatch->mipmap->format == 0)
|
||||
#endif
|
||||
glpatch->mipmap->format = PCX_Load(filename, &w, &h, glpatch);
|
||||
if (glpatch->mipmap->format == 0)
|
||||
glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch);
|
||||
if (glPatch->mipmap->format == 0)
|
||||
{
|
||||
glpatch->notfound = true;// mark it so its not searched for again repeatedly
|
||||
glPatch->notfound = true;// mark it so its not searched for again repeatedly
|
||||
Z_Free(filename);
|
||||
return;
|
||||
}
|
||||
|
||||
glpatch->mipmap->downloaded = 0;
|
||||
glpatch->mipmap->flags = 0;
|
||||
glPatch->mipmap->downloaded = 0;
|
||||
glPatch->mipmap->flags = 0;
|
||||
|
||||
glpatch->width = (INT16)w;
|
||||
glpatch->height = (INT16)h;
|
||||
glpatch->mipmap->width = (UINT16)w;
|
||||
glpatch->mipmap->height = (UINT16)h;
|
||||
patch->width = (INT16)w;
|
||||
patch->height = (INT16)h;
|
||||
glPatch->mipmap->width = (UINT16)w;
|
||||
glPatch->mipmap->height = (UINT16)h;
|
||||
}
|
||||
GL_SetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary
|
||||
HWR_UnlockCachedPatch(glpatch);
|
||||
GL_SetTexture(glPatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary
|
||||
HWR_UnlockCachedPatch(glPatch);
|
||||
|
||||
Z_Free(filename);
|
||||
}
|
||||
@@ -682,8 +695,10 @@ spritemd2found:
|
||||
#define SETBRIGHTNESS(brightness,r,g,b) \
|
||||
brightness = (UINT8)(((1063*(UINT32)(r))/5000) + ((3576*(UINT32)(g))/5000) + ((361*(UINT32)(b))/5000))
|
||||
|
||||
static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, GLMipmap_t *glMipmap, INT32 skinnum, skincolors_t color)
|
||||
static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMipmap_t *glMipmap, INT32 skinnum, skincolors_t color)
|
||||
{
|
||||
GLPatch_t *hwrPatch = gpatch->hardware;
|
||||
GLPatch_t *hwrBlendPatch = blendgpatch->hardware;
|
||||
UINT16 w = gpatch->width, h = gpatch->height;
|
||||
UINT32 size = w*h;
|
||||
RGBA_t *image, *blendimage, *cur, blendcolor;
|
||||
@@ -718,8 +733,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
||||
cur = Z_Malloc(size*4, PU_HWRCACHE, &glMipmap->data);
|
||||
memset(cur, 0x00, size*4);
|
||||
|
||||
image = gpatch->mipmap->data;
|
||||
blendimage = blendgpatch->mipmap->data;
|
||||
image = hwrPatch->mipmap->data;
|
||||
blendimage = hwrBlendPatch->mipmap->data;
|
||||
|
||||
// TC_METALSONIC includes an actual skincolor translation, on top of its flashing.
|
||||
if (skinnum == TC_METALSONIC)
|
||||
@@ -1042,21 +1057,32 @@ skippixel:
|
||||
|
||||
#undef SETBRIGHTNESS
|
||||
|
||||
static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
|
||||
static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
|
||||
{
|
||||
// mostly copied from HWR_GetMappedPatch, hence the similarities and comment
|
||||
GLPatch_t *glPatch = patch->hardware;
|
||||
GLPatch_t *glBlendPatch = NULL;
|
||||
GLMipmap_t *glMipmap, *newMipmap;
|
||||
|
||||
if (colormap == colormaps || colormap == NULL)
|
||||
|
||||
if (blendgpatch == NULL || colormap == colormaps || colormap == NULL)
|
||||
{
|
||||
// Don't do any blending
|
||||
GL_SetTexture(gpatch->mipmap);
|
||||
GL_SetTexture(glPatch->mipmap);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((blendgpatch && (glBlendPatch = blendgpatch->hardware) && glBlendPatch->mipmap->format)
|
||||
&& (patch->width != blendgpatch->width || patch->height != blendgpatch->height))
|
||||
{
|
||||
// Blend image exists, but it's bad.
|
||||
GL_SetTexture(glPatch->mipmap);
|
||||
return;
|
||||
}
|
||||
|
||||
// search for the Mipmap
|
||||
// skip the first (no colormap translated)
|
||||
for (glMipmap = gpatch->mipmap; glMipmap->nextcolormap; )
|
||||
for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap; )
|
||||
{
|
||||
glMipmap = glMipmap->nextcolormap;
|
||||
|
||||
@@ -1084,7 +1110,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT
|
||||
glMipmap->nextcolormap = newMipmap;
|
||||
newMipmap->colormap = colormap;
|
||||
|
||||
HWR_CreateBlendedTexture(gpatch, blendgpatch, newMipmap, skinnum, color);
|
||||
HWR_CreateBlendedTexture(patch, blendgpatch, newMipmap, skinnum, color);
|
||||
|
||||
GL_SetTexture(newMipmap);
|
||||
Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED);
|
||||
@@ -1154,7 +1180,8 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
|
||||
|
||||
// Look at HWR_ProjectSprite for more
|
||||
{
|
||||
GLPatch_t *gpatch;
|
||||
patch_t *gpatch, *blendgpatch;
|
||||
GLPatch_t *hwrPatch = NULL, *hwrBlendPatch = NULL;
|
||||
INT32 durs = spr->mobj->state->tics;
|
||||
INT32 tics = spr->mobj->tics;
|
||||
//mdlframe_t *next = NULL;
|
||||
@@ -1264,21 +1291,33 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
|
||||
}
|
||||
//Hurdler: arf, I don't like that implementation at all... too much crappy
|
||||
gpatch = md2->glpatch;
|
||||
if (!gpatch || ((!gpatch->mipmap->format || !gpatch->mipmap->downloaded) && !gpatch->notfound))
|
||||
md2_loadTexture(md2);
|
||||
gpatch = md2->glpatch; // Load it again, because it isn't being loaded into gpatch after md2_loadtexture...
|
||||
if (gpatch)
|
||||
hwrPatch = ((GLPatch_t *)gpatch->hardware);
|
||||
|
||||
if ((gpatch && gpatch->mipmap->format) // don't load the blend texture if the base texture isn't available
|
||||
&& (!md2->blendglpatch
|
||||
|| ((!((GLPatch_t *)md2->blendglpatch)->mipmap->format || !((GLPatch_t *)md2->blendglpatch)->mipmap->downloaded)
|
||||
&& !((GLPatch_t *)md2->blendglpatch)->notfound)))
|
||||
if (!gpatch || !hwrPatch
|
||||
|| ((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !hwrPatch->notfound))
|
||||
md2_loadTexture(md2);
|
||||
|
||||
// Load it again, because it isn't being loaded into gpatch after md2_loadtexture...
|
||||
gpatch = md2->glpatch;
|
||||
if (gpatch)
|
||||
hwrPatch = ((GLPatch_t *)gpatch->hardware);
|
||||
|
||||
// Load blend texture
|
||||
blendgpatch = md2->blendglpatch;
|
||||
if (blendgpatch)
|
||||
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
|
||||
|
||||
if ((gpatch && hwrPatch && hwrPatch->mipmap->format) // don't load the blend texture if the base texture isn't available
|
||||
&& (!blendgpatch || !hwrBlendPatch
|
||||
|| ((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !hwrPatch->notfound)))
|
||||
md2_loadBlendTexture(md2);
|
||||
|
||||
if (gpatch && gpatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture
|
||||
if (gpatch && hwrPatch && hwrPatch->mipmap->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->blendglpatch && ((GLPatch_t *)md2->blendglpatch)->mipmap->format
|
||||
&& gpatch->width == ((GLPatch_t *)md2->blendglpatch)->width && gpatch->height == ((GLPatch_t *)md2->blendglpatch)->height)
|
||||
md2->blendglpatch && (hwrBlendPatch->mipmap->format
|
||||
&& gpatch->width == (blendgpatch->width && gpatch->height == (blendgpatch->height))))
|
||||
{
|
||||
INT32 tcskinnum = TC_DEFAULT;
|
||||
if ((spr->mobj->flags & MF_BOSS) && (spr->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash"
|
||||
@@ -1303,19 +1342,18 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
|
||||
}
|
||||
else tcskinnum = TC_DEFAULT;
|
||||
}
|
||||
HWR_GetBlendedTexture(gpatch, (GLPatch_t *)md2->blendglpatch, tcskinnum, spr->colormap, (skincolors_t)spr->mobj->color);
|
||||
HWR_GetBlendedTexture(gpatch, blendgpatch, tcskinnum, spr->colormap, (skincolors_t)spr->mobj->color);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is safe, since we know the texture has been downloaded
|
||||
GL_SetTexture(gpatch->mipmap);
|
||||
GL_SetTexture(hwrPatch->mipmap);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sprite
|
||||
gpatch = spr->gpatch; //gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE);
|
||||
HWR_GetMappedPatch(gpatch, spr->colormap);
|
||||
HWR_GetMappedPatch(spr->gpatch, spr->colormap);
|
||||
}
|
||||
|
||||
if (spr->mobj->frame & FF_ANIMATE)
|
||||
|
||||
+15
-2
@@ -3040,6 +3040,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate)
|
||||
R_FlushTranslationColormapCache();
|
||||
|
||||
#ifdef HWRENDER
|
||||
// Free GPU textures before freeing patches.
|
||||
if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED))
|
||||
HWR_ClearAllTextures();
|
||||
|
||||
// Delete light table textures
|
||||
HWR_ClearLightTables();
|
||||
#endif
|
||||
@@ -3114,7 +3118,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate)
|
||||
{
|
||||
HWR_FreeExtraSubsectors();
|
||||
|
||||
// stuff like HWR_CreatePlanePolygons is called there
|
||||
// Create plane polygons.
|
||||
HWR_LoadLevel();
|
||||
}
|
||||
#endif
|
||||
@@ -3329,13 +3333,22 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local)
|
||||
if (!devparm && digmreplaces)
|
||||
CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces));
|
||||
|
||||
R_LoadTexturesPwad(wadnum);
|
||||
#ifdef HWRENDER
|
||||
// Free GPU textures before freeing patches.
|
||||
if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED))
|
||||
HWR_ClearAllTextures();
|
||||
#endif
|
||||
|
||||
//
|
||||
// search for sprite replacements
|
||||
//
|
||||
R_AddSpriteDefs(wadnum);
|
||||
|
||||
// Reload it all anyway, just in case they
|
||||
// added some textures but didn't insert a
|
||||
// TEXTURES/etc. list.
|
||||
R_LoadTexturesPwad(wadnum);
|
||||
|
||||
// everything from MultiSetupWadFile until ST_Start was here originally
|
||||
|
||||
//
|
||||
|
||||
+26
-7
@@ -303,8 +303,8 @@ static UINT8 *R_GenerateTexture(size_t texnum)
|
||||
UINT8 *blocktex;
|
||||
texture_t *texture;
|
||||
texpatch_t *patch;
|
||||
patch_t *realpatch;
|
||||
int x, x1, x2, i;
|
||||
softwarepatch_t *realpatch;
|
||||
int x, x1, x2, i, width, height;
|
||||
size_t blocksize;
|
||||
column_t *patchcol;
|
||||
UINT8 *colofs;
|
||||
@@ -323,16 +323,21 @@ static UINT8 *R_GenerateTexture(size_t texnum)
|
||||
{
|
||||
boolean holey = false;
|
||||
patch = texture->patches;
|
||||
realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
|
||||
realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
|
||||
// Check the patch for holes.
|
||||
if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height))
|
||||
holey = true;
|
||||
|
||||
colofs = (UINT8 *)realpatch->columnofs;
|
||||
|
||||
for (x = 0; x < texture->width && !holey; x++)
|
||||
{
|
||||
column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2]));
|
||||
|
||||
INT32 topdelta, prevdelta = -1, y = 0;
|
||||
|
||||
while (col->topdelta != 0xff)
|
||||
{
|
||||
topdelta = col->topdelta;
|
||||
@@ -344,6 +349,7 @@ static UINT8 *R_GenerateTexture(size_t texnum)
|
||||
y = topdelta + col->length + 1;
|
||||
col = (column_t *)((UINT8 *)col + col->length + 4);
|
||||
}
|
||||
|
||||
if (y < texture->height)
|
||||
holey = true; // this texture is HOLEy! D:
|
||||
}
|
||||
@@ -376,7 +382,7 @@ static UINT8 *R_GenerateTexture(size_t texnum)
|
||||
texturememory += blocksize;
|
||||
block = Z_Malloc(blocksize+1, PU_STATIC, &texturecache[texnum]);
|
||||
|
||||
memset(block, 0xF7, blocksize+1); // Transparency hack
|
||||
memset(block, TRANSPARENTPIXEL, blocksize+1); // Transparency hack
|
||||
|
||||
// columns lookup table
|
||||
colofs = block;
|
||||
@@ -388,20 +394,33 @@ static UINT8 *R_GenerateTexture(size_t texnum)
|
||||
// Composite the columns together.
|
||||
for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++)
|
||||
{
|
||||
realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
|
||||
|
||||
// Well, it's not valid...
|
||||
if (realpatch == NULL)
|
||||
continue;
|
||||
|
||||
x1 = patch->originx;
|
||||
x2 = x1 + SHORT(realpatch->width);
|
||||
width = SHORT(realpatch->width);
|
||||
height = SHORT(realpatch->height);
|
||||
x2 = x1 + width;
|
||||
|
||||
if (x1 > texture->width || x2 < 0)
|
||||
continue; // patch not located within texture's x bounds, ignore
|
||||
|
||||
if (patch->originy > texture->height || (patch->originy + height) < 0)
|
||||
continue; // patch not located within texture's y bounds, ignore
|
||||
|
||||
// patch is actually inside the texture!
|
||||
// now check if texture is partly off-screen and adjust accordingly
|
||||
|
||||
// left edge
|
||||
if (x1 < 0)
|
||||
x = 0;
|
||||
else
|
||||
x = x1;
|
||||
|
||||
// right edge
|
||||
if (x2 > texture->width)
|
||||
x2 = texture->width;
|
||||
|
||||
@@ -702,7 +721,7 @@ static void R_FinishLoadingTextures(INT32 add)
|
||||
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
HWR_LoadTextures(numtextures);
|
||||
HWR_LoadMapTextures(numtextures);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+18
-2
@@ -642,7 +642,23 @@ typedef struct
|
||||
// Patches are used for sprites and all masked pictures, and we compose
|
||||
// textures from the TEXTURE1 list of patches.
|
||||
//
|
||||
// WARNING: this structure is cloned in GLPatch_t
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT16 width, height;
|
||||
INT16 leftoffset, topoffset;
|
||||
|
||||
INT32 *columnofs; // Column offsets. This is relative to patch->columns
|
||||
UINT8 *columns; // Software column data
|
||||
|
||||
void *hardware; // OpenGL patch, allocated whenever necessary
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
rotsprite_t *rotated; // Rotated patches
|
||||
#endif
|
||||
|
||||
} patch_t;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
@@ -655,7 +671,7 @@ typedef struct
|
||||
INT16 topoffset; // pixels below the origin
|
||||
INT32 columnofs[8]; // only [width] used
|
||||
// the [0] is &columnofs[width]
|
||||
} patch_t;
|
||||
} ATTRPACK softwarepatch_t;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4200)
|
||||
|
||||
+127
-32
@@ -329,6 +329,113 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps)
|
||||
|
||||
static unsigned char imgbuf[1<<26];
|
||||
|
||||
//
|
||||
// Creates a patch.
|
||||
// Assumes a PU_PATCH zone memory tag and no user, but can always be set later
|
||||
//
|
||||
|
||||
patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest)
|
||||
{
|
||||
patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_CACHE, NULL) : (patch_t *)(dest);
|
||||
|
||||
if (source)
|
||||
{
|
||||
INT32 col, colsize;
|
||||
size_t size = sizeof(INT32) * source->width;
|
||||
size_t offs = (sizeof(INT16) * 4) + size;
|
||||
|
||||
patch->width = source->width;
|
||||
patch->height = source->height;
|
||||
patch->leftoffset = source->leftoffset;
|
||||
patch->topoffset = source->topoffset;
|
||||
patch->columnofs = Z_Calloc(size, PU_CACHE, NULL);
|
||||
|
||||
for (col = 0; col < source->width; col++)
|
||||
{
|
||||
// This makes the column offsets relative to the column data itself,
|
||||
// instead of the entire patch data
|
||||
patch->columnofs[col] = LONG(source->columnofs[col]) - offs;
|
||||
}
|
||||
|
||||
if (!srcsize)
|
||||
I_Error("Patch_Create: no source size!");
|
||||
|
||||
colsize = (INT32)(srcsize) - (INT32)offs;
|
||||
if (colsize <= 0)
|
||||
I_Error("Patch_Create: no column data!");
|
||||
|
||||
patch->columns = Z_Calloc(colsize, PU_CACHE, NULL);
|
||||
M_Memcpy(patch->columns, ((UINT8 *)source + LONG(source->columnofs[0])), colsize);
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
//
|
||||
// Frees a patch from memory.
|
||||
//
|
||||
|
||||
void Patch_Free(patch_t *patch)
|
||||
{
|
||||
#ifdef HWRENDER
|
||||
if (patch->hardware)
|
||||
HWR_FreeTexture(patch);
|
||||
#endif
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
if (patch->rotated)
|
||||
{
|
||||
rotsprite_t *rotsprite = patch->rotated;
|
||||
INT32 i = 0;
|
||||
|
||||
for (; i < rotsprite->angles; i++)
|
||||
{
|
||||
if (rotsprite->patches[i])
|
||||
Patch_Free(rotsprite->patches[i]);
|
||||
}
|
||||
|
||||
Z_Free(rotsprite->patches);
|
||||
Z_Free(rotsprite);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (patch->columnofs)
|
||||
Z_Free(patch->columnofs);
|
||||
if (patch->columns)
|
||||
Z_Free(patch->columns);
|
||||
|
||||
Z_Free(patch);
|
||||
}
|
||||
|
||||
#ifdef HWRENDER
|
||||
//
|
||||
// Allocates a hardware patch.
|
||||
//
|
||||
|
||||
void *Patch_AllocateHardwarePatch(patch_t *patch)
|
||||
{
|
||||
if (!patch->hardware)
|
||||
{
|
||||
GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware);
|
||||
grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &grPatch->mipmap);
|
||||
}
|
||||
return (void *)(patch->hardware);
|
||||
}
|
||||
|
||||
//
|
||||
// Creates a hardware patch.
|
||||
//
|
||||
|
||||
void *Patch_CreateGL(patch_t *patch)
|
||||
{
|
||||
GLPatch_t *grPatch = (GLPatch_t *)Patch_AllocateHardwarePatch(patch);
|
||||
if (!grPatch->mipmap->data) // Run HWR_MakePatch in all cases, to recalculate some things
|
||||
HWR_MakePatch(patch, grPatch, grPatch->mipmap, false);
|
||||
return grPatch;
|
||||
}
|
||||
#endif // HWRENDER
|
||||
|
||||
|
||||
//
|
||||
// R_MaskedFlatToPatch
|
||||
//
|
||||
@@ -440,7 +547,14 @@ static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 l
|
||||
|
||||
if (destsize != NULL)
|
||||
*destsize = size;
|
||||
return img;
|
||||
|
||||
patch_t *converted = Patch_Create((softwarepatch_t *)img, size, NULL);
|
||||
#ifdef HWRENDER
|
||||
Patch_CreateGL(converted);
|
||||
#endif
|
||||
Z_Free(img);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
@@ -453,14 +567,14 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
if (patch == NULL)
|
||||
I_Error("GetPatchPixel: patch == NULL");
|
||||
|
||||
width = SHORT(patch->width);
|
||||
width = patch->width;
|
||||
|
||||
if (x >= 0 && x < width)
|
||||
{
|
||||
INT32 colx = flip ? (width-1)-x : x;
|
||||
INT32 topdelta, prevdelta = -1;
|
||||
|
||||
column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[colx]));
|
||||
column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[colx]));
|
||||
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
@@ -486,17 +600,6 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
return 0xFF00;
|
||||
}
|
||||
|
||||
#ifdef HWRENDER
|
||||
static patch_t *R_CreateHardwarePatch(patch_t *patch)
|
||||
{
|
||||
GLPatch_t *glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL);
|
||||
glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL);
|
||||
glPatch->rawpatch = patch;
|
||||
HWR_MakePatch(patch, glPatch, glPatch->mipmap, false);
|
||||
return (patch_t *)glPatch;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
//
|
||||
// R_GetRollAngle
|
||||
@@ -554,7 +657,8 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri
|
||||
if (lump == LUMPERROR)
|
||||
return NULL;
|
||||
|
||||
patch = (patch_t *)W_CacheLumpNum(lump, PU_CACHE); // PU_LEVEL
|
||||
patch = W_CachePatchNum(lump, PU_CACHE); // PU_SPRITE
|
||||
//patch = W_CachePatchNum(lump, PU_SPRITE);
|
||||
|
||||
if (sprinfo->available)
|
||||
{
|
||||
@@ -563,8 +667,8 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri
|
||||
}
|
||||
else
|
||||
{
|
||||
xpivot = SHORT(patch->leftoffset);
|
||||
ypivot = SHORT(patch->height) / 2;
|
||||
xpivot = patch->leftoffset;
|
||||
ypivot = patch->height / 2;
|
||||
}
|
||||
|
||||
RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip);
|
||||
@@ -581,7 +685,6 @@ rotsprite_t *RotatedPatch_Create(INT32 numangles)
|
||||
return rotsprite;
|
||||
}
|
||||
|
||||
|
||||
static void RotatedPatch_CalculateDimensions(
|
||||
INT32 width, INT32 height,
|
||||
fixed_t ca, fixed_t sa,
|
||||
@@ -607,16 +710,15 @@ static void RotatedPatch_CalculateDimensions(
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip)
|
||||
{
|
||||
UINT32 i;
|
||||
|
||||
patch_t *rotated;
|
||||
|
||||
UINT16 *rawdst, *rawconv;
|
||||
size_t size;
|
||||
INT32 bflip = (flip != 0x00);
|
||||
|
||||
INT32 width = SHORT(patch->width);
|
||||
INT32 height = SHORT(patch->height);
|
||||
INT32 leftoffset = SHORT(patch->leftoffset);
|
||||
INT32 width = patch->width;
|
||||
INT32 height = patch->height;
|
||||
INT32 leftoffset = patch->leftoffset;
|
||||
INT32 newwidth, newheight;
|
||||
|
||||
fixed_t ca = rollcosang[angle];
|
||||
@@ -735,18 +837,11 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle
|
||||
// make patch
|
||||
rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size);
|
||||
|
||||
rotated->leftoffset = ox;
|
||||
rotated->topoffset = oy;
|
||||
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
rotated = R_CreateHardwarePatch(rotated);
|
||||
}
|
||||
#endif // HWRENDER
|
||||
|
||||
//Z_ChangeTag(rotated, PU_LEVEL);
|
||||
Z_SetUser(rotated, (void **)(&rotsprite->patches[idx]));
|
||||
Z_Free(rawconv);
|
||||
|
||||
rotated->leftoffset = ox;
|
||||
rotated->topoffset = oy;
|
||||
}
|
||||
#endif
|
||||
@@ -38,6 +38,15 @@ typedef struct
|
||||
boolean available;
|
||||
} spriteinfo_t;
|
||||
|
||||
// Patch functions
|
||||
patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest);
|
||||
void Patch_Free(patch_t *patch);
|
||||
|
||||
#ifdef HWRENDER
|
||||
void *Patch_AllocateHardwarePatch(patch_t *patch);
|
||||
void *Patch_CreateGL(patch_t *patch);
|
||||
#endif
|
||||
|
||||
// Conversions between patches / flats / textures...
|
||||
boolean R_CheckIfPatch(lumpnum_t lump);
|
||||
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ static void R_DrawWallSplats(void)
|
||||
continue;
|
||||
|
||||
// draw the texture
|
||||
col = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn]));
|
||||
col = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn]));
|
||||
R_DrawSplatColumn(col);
|
||||
}
|
||||
} // next splat
|
||||
|
||||
+8
-8
@@ -254,7 +254,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef,
|
||||
UINT8 frame;
|
||||
UINT8 rotation;
|
||||
lumpinfo_t *lumpinfo;
|
||||
patch_t patch;
|
||||
softwarepatch_t patch;
|
||||
UINT8 numadded = 0;
|
||||
|
||||
memset(sprtemp,0xFF, sizeof (sprtemp));
|
||||
@@ -297,10 +297,10 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef,
|
||||
// store sprite info in lookup tables
|
||||
//FIXME : numspritelumps do not duplicate sprite replacements
|
||||
W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0);
|
||||
spritecachedinfo[numspritelumps].width = SHORT(patch.width)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].offset = SHORT(patch.leftoffset)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].topoffset = SHORT(patch.topoffset)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].height = SHORT(patch.height)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].width = (patch.width)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].offset = (patch.leftoffset)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].topoffset = (patch.topoffset)<<FRACBITS;
|
||||
spritecachedinfo[numspritelumps].height = (patch.height)<<FRACBITS;
|
||||
|
||||
//BP: we cannot use special tric in hardware mode because feet in ground caused by z-buffer
|
||||
if (rendermode != render_none) // not for psprite
|
||||
@@ -882,7 +882,7 @@ static void R_DrawVisSprite(vissprite_t *vis)
|
||||
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
|
||||
dc_iscale = (0xffffffffu / (unsigned)spryscale);
|
||||
|
||||
column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn]));
|
||||
column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn]));
|
||||
|
||||
localcolfunc (column);
|
||||
}
|
||||
@@ -893,7 +893,7 @@ static void R_DrawVisSprite(vissprite_t *vis)
|
||||
for (dc_x = vis->x1; dc_x <= vis->x2 && (frac>>FRACBITS) < pwidth; dc_x++, frac += vis->xiscale)
|
||||
{
|
||||
texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1);
|
||||
column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn]));
|
||||
column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn]));
|
||||
|
||||
localcolfunc (column);
|
||||
}
|
||||
@@ -961,7 +961,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis)
|
||||
break;
|
||||
}
|
||||
|
||||
column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn]));
|
||||
column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn]));
|
||||
|
||||
R_DrawMaskedColumn(column);
|
||||
}
|
||||
|
||||
+5
-5
@@ -635,7 +635,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
//if (rendermode != render_soft && !con_startup) // Why?
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
HWR_DrawStretchyFixedPatch((GLPatch_t *)patch, x, y, pscale, vscale, scrn, colormap, bflags);
|
||||
HWR_DrawStretchyFixedPatch(patch, x, y, pscale, vscale, scrn, colormap, bflags);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -761,7 +761,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
// if it's meant to cover the whole screen, black out the rest (ONLY IF TOP LEFT ISN'T TRANSPARENT)
|
||||
if (x == 0 && SHORT(patch->width) == BASEVIDWIDTH && y == 0 && SHORT(patch->height) == BASEVIDHEIGHT)
|
||||
{
|
||||
column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[0]));
|
||||
column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[0]));
|
||||
if (!column->topdelta)
|
||||
{
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
@@ -825,7 +825,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
if (x+offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
break;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[col>>FRACBITS]));
|
||||
column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS]));
|
||||
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
@@ -872,7 +872,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
{
|
||||
HWR_DrawCroppedPatch((GLPatch_t*)patch,x,y,pscale,scrn,sx,sy,w,h);
|
||||
HWR_DrawCroppedPatch(patch, x, y, pscale, scrn, sx, sy, w, h);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -963,7 +963,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_
|
||||
continue;
|
||||
if (x >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
break;
|
||||
column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[col>>FRACBITS]));
|
||||
column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS]));
|
||||
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
|
||||
+80
-38
@@ -824,11 +824,7 @@ UINT16 W_InitFile(const char *filename, boolean local)
|
||||
// set up caching
|
||||
//
|
||||
Z_Calloc(numlumps * sizeof (*wadfile->lumpcache), PU_STATIC, &wadfile->lumpcache);
|
||||
|
||||
#ifdef HWRENDER
|
||||
// allocates GLPatch info structures and store them in a tree
|
||||
wadfile->hwrcache = M_AATreeAlloc(AATREE_ZUSER);
|
||||
#endif
|
||||
Z_Calloc(numlumps * sizeof (*wadfile->patchcache), PU_STATIC, &wadfile->patchcache);
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
// allocates rotsprite structures and store them in a tree
|
||||
@@ -1321,15 +1317,15 @@ UINT8 W_LumpExists(const char *name)
|
||||
return false;
|
||||
}
|
||||
|
||||
UINT8 W_CheckMultipleLumps(const char* lump, ...)
|
||||
UINT8 W_CheckMultipleLumps(const char* lump, ...)
|
||||
{
|
||||
va_list lumps;
|
||||
va_start(lumps, lump);
|
||||
const char* lumpname = lump;
|
||||
|
||||
while (lumpname != NULL)
|
||||
while (lumpname != NULL)
|
||||
{
|
||||
if (!W_LumpExists(lumpname))
|
||||
if (!W_LumpExists(lumpname))
|
||||
{
|
||||
va_end(lumps);
|
||||
return false;
|
||||
@@ -1638,7 +1634,6 @@ void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
|
||||
|
||||
void *W_CacheLumpNum(lumpnum_t lumpnum, INT32 tag)
|
||||
{
|
||||
|
||||
return W_CacheLumpNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag);
|
||||
}
|
||||
|
||||
@@ -1696,6 +1691,39 @@ boolean W_IsLumpCached(lumpnum_t lumpnum, void *ptr)
|
||||
return W_IsLumpCachedPWAD(WADFILENUM(lumpnum),LUMPNUM(lumpnum), ptr);
|
||||
}
|
||||
|
||||
//
|
||||
// W_IsPatchCached
|
||||
//
|
||||
// If a patch is already cached return true, otherwise
|
||||
// return false.
|
||||
//
|
||||
// no outside code uses the PWAD form, for now
|
||||
static inline boolean W_IsPatchCachedPWAD(UINT16 wad, UINT16 lump, void *ptr)
|
||||
{
|
||||
void *lcache;
|
||||
|
||||
if (!TestValidLump(wad, lump))
|
||||
return false;
|
||||
|
||||
lcache = wadfiles[wad]->patchcache[lump];
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr == lcache)
|
||||
return true;
|
||||
}
|
||||
else if (lcache)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean W_IsPatchCached(lumpnum_t lumpnum, void *ptr)
|
||||
{
|
||||
return W_IsPatchCachedPWAD(WADFILENUM(lumpnum),LUMPNUM(lumpnum), ptr);
|
||||
}
|
||||
|
||||
|
||||
// ==========================================================================
|
||||
// W_CacheLumpName
|
||||
// ==========================================================================
|
||||
@@ -1720,40 +1748,59 @@ void *W_CacheLumpName(const char *name, INT32 tag)
|
||||
//
|
||||
|
||||
// Software-only compile cache the data without conversion
|
||||
#ifdef HWRENDER
|
||||
FUNCINLINE static ATTRINLINE void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
|
||||
void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
|
||||
{
|
||||
GLPatch_t *glPatch;
|
||||
|
||||
if (rendermode == render_soft || rendermode == render_none)
|
||||
return W_CacheLumpNumPwad(wad, lump, tag);
|
||||
lumpcache_t *lumpcache = NULL;
|
||||
|
||||
if (!TestValidLump(wad, lump))
|
||||
return NULL;
|
||||
|
||||
glPatch = HWR_GetCachedGLPatchPwad(wad, lump);
|
||||
lumpcache = wadfiles[wad]->patchcache;
|
||||
|
||||
if (glPatch->mipmap->data)
|
||||
if (!lumpcache[lump])
|
||||
{
|
||||
if (tag == PU_CACHE)
|
||||
tag = PU_HWRCACHE;
|
||||
Z_ChangeTag(glPatch->mipmap->data, tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
patch_t *ptr = NULL;
|
||||
size_t len = W_LumpLengthPwad(wad, lump);
|
||||
void *ptr, *dest, *lumpdata = Z_Malloc(len, PU_STATIC, NULL);
|
||||
|
||||
// Only load the patch if we haven't initialised the glPatch yet
|
||||
if (glPatch->mipmap->width == 0)
|
||||
ptr = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC);
|
||||
// read the lump in full
|
||||
W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0);
|
||||
ptr = lumpdata;
|
||||
|
||||
dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]);
|
||||
Patch_Create(ptr, len, dest);
|
||||
|
||||
// Run HWR_MakePatch in all cases, to recalculate some things
|
||||
HWR_MakePatch(ptr, glPatch, glPatch->mipmap, false);
|
||||
Z_Free(ptr);
|
||||
}
|
||||
else
|
||||
Z_ChangeTag(lumpcache[lump], tag);
|
||||
|
||||
// return GLPatch_t, which can be casted to (patch_t) with valid patch header info
|
||||
return (void *)glPatch;
|
||||
return lumpcache[lump];
|
||||
}
|
||||
|
||||
void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag)
|
||||
{
|
||||
return W_CacheSoftwarePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag);
|
||||
}
|
||||
|
||||
void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
|
||||
{
|
||||
patch_t *patch;
|
||||
|
||||
if (!TestValidLump(wad, lump))
|
||||
return NULL;
|
||||
|
||||
patch = W_CacheSoftwarePatchNumPwad(wad, lump, tag);
|
||||
|
||||
#ifdef HWRENDER
|
||||
// Software-only compile cache the data without conversion
|
||||
if (rendermode == render_soft || rendermode == render_none)
|
||||
#endif
|
||||
return (void *)patch;
|
||||
|
||||
#ifdef HWRENDER
|
||||
Patch_CreateGL(patch);
|
||||
return (void *)patch;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag)
|
||||
@@ -1761,8 +1808,6 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag)
|
||||
return W_CachePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag);
|
||||
}
|
||||
|
||||
#endif // HWRENDER
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
// Caches a rotsprite for patch rotation.
|
||||
void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum)
|
||||
@@ -1790,7 +1835,7 @@ void W_UnlockCachedPatch(void *patch)
|
||||
// have different lifetimes from software's.
|
||||
#ifdef HWRENDER
|
||||
if (rendermode == render_opengl)
|
||||
HWR_UnlockCachedPatch((GLPatch_t*)patch);
|
||||
HWR_UnlockCachedPatch((GLPatch_t *)((patch_t *)patch)->hardware);
|
||||
else
|
||||
#endif
|
||||
Z_ChangeTag(patch, PU_LEVEL);
|
||||
@@ -1835,7 +1880,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
|
||||
{
|
||||
INT32 xpivot = 0, ypivot = 0;
|
||||
|
||||
ptr = (patch_t *)(W_CacheLumpNum(num, PU_STATIC));
|
||||
ptr = W_CachePatchNum(num, PU_STATIC); // PU_PATCH
|
||||
|
||||
// >y pivot centered
|
||||
// >x pivot not centered
|
||||
@@ -1844,9 +1889,6 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
|
||||
ypivot = SHORT(ptr->height) / 2;
|
||||
|
||||
RotatedPatch_DoRotation(rspr, ptr, rotationangle, xpivot, ypivot, false);
|
||||
|
||||
// free image data
|
||||
Z_Free(ptr);
|
||||
}
|
||||
|
||||
return rspr->patches[idx];
|
||||
|
||||
+9
-10
@@ -126,9 +126,7 @@ typedef struct wadfile_s
|
||||
restype_t type;
|
||||
lumpinfo_t *lumpinfo;
|
||||
lumpcache_t *lumpcache;
|
||||
#ifdef HWRENDER
|
||||
aatree_t *hwrcache; // patches are cached in renderer's native format
|
||||
#endif
|
||||
lumpcache_t *patchcache;
|
||||
#ifdef ROTSPRITE
|
||||
aatree_t *rotcache; // Cache rotsprites for rotating patches.
|
||||
#endif
|
||||
@@ -209,18 +207,19 @@ void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
||||
void *W_CacheLumpNum(lumpnum_t lump, INT32 tag);
|
||||
void *W_CacheLumpNumForce(lumpnum_t lumpnum, INT32 tag);
|
||||
|
||||
boolean W_IsPatchCached(lumpnum_t lump, void *ptr);
|
||||
boolean W_IsLumpCached(lumpnum_t lump, void *ptr);
|
||||
|
||||
void *W_CacheLumpName(const char *name, INT32 tag);
|
||||
void *W_CachePatchName(const char *name, INT32 tag);
|
||||
|
||||
#ifdef HWRENDER
|
||||
//void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); // return a patch_t
|
||||
void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag); // return a patch_t
|
||||
#else
|
||||
//#define W_CachePatchNumPwad(wad, lump, tag) W_CacheLumpNumPwad(wad, lump, tag)
|
||||
#define W_CachePatchNum(lumpnum, tag) W_CacheLumpNum(lumpnum, tag)
|
||||
#endif
|
||||
// Returns either a Software patch, or an OpenGL patch.
|
||||
void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
||||
void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag);
|
||||
|
||||
// Returns a Software patch.
|
||||
void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
|
||||
void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag);
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum); // Get patch-based rotsprites from the cache.
|
||||
|
||||
+1
-1
@@ -887,7 +887,7 @@ static void Y_FollowIntermission(void)
|
||||
G_AfterIntermission();
|
||||
}
|
||||
|
||||
#define UNLOAD(x) Z_ChangeTag(x, PU_CACHE); x = NULL
|
||||
#define UNLOAD(x) if (x) {Patch_Free(x);} x = NULL;
|
||||
|
||||
//
|
||||
// Y_UnloadData
|
||||
|
||||
Reference in new issue
Block a user