Revert "Linked list for textures"

This reverts commit 7eec58a834.
This commit is contained in:
Alug committed 2024-02-19 12:15:12 +01:00
1 parent 194ae46ce8
commit fe0dabb177
7 files changed
+30 -100

No files matched your search

+3 -7
View File
@@ -502,16 +502,12 @@ 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.
if (next->data)
Z_Free(next->data);
next->data = NULL;
HWD.pfnDeleteTexture(next);
// Free the old colormap mipmap from memory.
free(next);
@@ -578,6 +574,7 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore)
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!grtex->mipmap.downloaded)
HWD.pfnSetTexture(&grtex->mipmap);
HWR_SetCurrentTexture(&grtex->mipmap);
// The system-memory data can be purged now.
@@ -646,9 +643,6 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum)
void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
{
GLMipmap_t *grmip;
if (flatlumpnum == LUMPERROR)
return;
grmip = HWR_GetCachedGLPatch(flatlumpnum)->mipmap;
@@ -665,6 +659,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!grmip->downloaded)
HWD.pfnSetTexture(grmip);
HWR_SetCurrentTexture(grmip);
// The system-memory data can be purged now.
@@ -780,6 +775,7 @@ void HWR_UnlockCachedPatch(GLPatch_t *gpatch)
return;
Z_ChangeTag(gpatch->mipmap->data, PU_HWRCACHE_UNLOCKED);
Z_ChangeTag(gpatch, PU_HWRPATCHINFO_UNLOCKED);
}
GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
+1 -11
View File
@@ -255,17 +255,7 @@ enum ETextureFlags
TF_TRANSPARENT = 0x00000040, // texture with some alpha == 0
};
struct FTextureInfo
{
UINT32 width, height;
UINT32 downloaded;
UINT32 format;
struct GLMipmap_s *texture;
struct FTextureInfo *prev, *next;
};
typedef struct FTextureInfo FTextureInfo;
typedef struct GLMipmap_s FTextureInfo;
struct FLightInfo
{
+2 -4
View File
@@ -36,9 +36,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI
EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray);
EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags);
EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor);
EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo);
EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo);
EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *TexInfo);
EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo);
EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *TexInfo);
EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data);
EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip);
EXPORT void HWRAPI(ClearMipMapCache) (void);
@@ -100,7 +99,6 @@ struct hwdriver_s
ClearBuffer pfnClearBuffer;
SetTexture pfnSetTexture;
UpdateTexture pfnUpdateTexture;
DeleteTexture pfnDeleteTexture;
ReadScreenTexture pfnReadScreenTexture;
GClipRect pfnGClipRect;
ClearMipMapCache pfnClearMipMapCache;
+23 -76
View File
@@ -78,9 +78,8 @@ static GLuint lt_downloaded = 0; // currently bound lighttable texture
static GLfloat fov = 90.0f;
static FBITFIELD CurrentPolyFlags;
// Linked list of all textures.
static FTextureInfo *TexCacheTail = NULL;
static FTextureInfo *TexCacheHead = NULL;
static FTextureInfo *gr_cachetail = NULL;
static FTextureInfo *gr_cachehead = NULL;
static RGBA_t *textureBuffer = NULL;
static size_t textureBufferSize = 0;
@@ -1164,70 +1163,27 @@ void GLFramebuffer_Disable(void)
pglBindRenderbuffer(GL_RENDERBUFFER, 0);
}
// -----------------+
// DeleteTexture : Deletes a texture from the GPU and frees its data
// -----------------+
EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo)
{
FTextureInfo *head = TexCacheHead;
if (!pTexInfo)
return;
else if (pTexInfo->downloaded)
pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded);
while (head)
{
if (head->downloaded == pTexInfo->downloaded)
{
if (head->next)
head->next->prev = head->prev;
else // no next -> tail is being deleted -> update TexCacheTail
TexCacheTail = head->prev;
if (head->prev)
head->prev->next = head->next;
else // no prev -> head is being deleted -> update TexCacheHead
TexCacheHead = head->next;
free(head);
break;
}
head = head->next;
}
pTexInfo->downloaded = 0;
}
// -----------------+
// Flush : flush OpenGL textures
// : Clear list of downloaded mipmaps
// -----------------+
void Flush(void)
{
//GL_DBG_Printf ("HWR_Flush()\n");
//GL_DBG_Printf("HWR_Flush()\n");
while (TexCacheHead)
while (gr_cachehead)
{
FTextureInfo *pTexInfo = TexCacheHead;
GLMipmap_t *texture = pTexInfo->texture;
if (pTexInfo->downloaded)
{
pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded);
pTexInfo->downloaded = 0;
}
if (texture)
texture->downloaded = 0;
TexCacheHead = pTexInfo->next;
free(pTexInfo);
// this is not necessary at all, because you have loaded them normally,
// and so they already are in your list!
if (gr_cachehead->downloaded)
pglDeleteTextures(1, (GLuint *)&gr_cachehead->downloaded);
gr_cachehead->downloaded = 0;
gr_cachehead = gr_cachehead->nextmipmap;
}
gr_cachetail = gr_cachehead = NULL; //Hurdler: well, gr_cachehead is already NULL
TexCacheTail = TexCacheHead = NULL; //Hurdler: well, TexCacheHead is already NULL
tex_downloaded = 0;
free(textureBuffer);
textureBuffer = NULL;
textureBufferSize = 0;
@@ -1586,7 +1542,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo)
// -----------------+
// UpdateTexture : Updates texture data.
// -----------------+
EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
{
// Upload a texture
GLuint num = pTexInfo->downloaded;
@@ -1643,6 +1599,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
tex[w*j+i].s.alpha = *pImgData;
pImgData++;
}
}
}
}
@@ -1792,7 +1749,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
// -----------------+
// SetTexture : The mipmap becomes the current texture source
// -----------------+
EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo)
EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
{
if (!pTexInfo)
{
@@ -1809,25 +1766,15 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo)
}
else
{
FTextureInfo *newTex = calloc(1, sizeof (*newTex));
UpdateTexture(pTexInfo);
newTex->texture = pTexInfo;
newTex->downloaded = (UINT32)pTexInfo->downloaded;
newTex->width = (UINT32)pTexInfo->width;
newTex->height = (UINT32)pTexInfo->height;
newTex->format = (UINT32)pTexInfo->format;
// insertion at the tail
if (TexCacheTail)
{
newTex->prev = TexCacheTail;
TexCacheTail->next = newTex;
TexCacheTail = newTex;
pTexInfo->nextmipmap = NULL;
if (gr_cachetail)
{ // insertion at the tail
gr_cachetail->nextmipmap = pTexInfo;
gr_cachetail = pTexInfo;
}
else // initialization of the linked list
TexCacheTail = TexCacheHead = newTex;
gr_cachetail = gr_cachehead = pTexInfo;
}
}
@@ -3026,7 +2973,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform)
EXPORT INT32 HWRAPI(GetTextureUsed) (void)
{
FTextureInfo *tmp = TexCacheHead;
FTextureInfo *tmp = gr_cachehead;
INT32 res = 0;
while (tmp)
@@ -3043,7 +2990,7 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void)
// Add it up!
res += tmp->height*tmp->width*bpp;
tmp = tmp->next;
tmp = tmp->nextmipmap;
}
return res;
-1
View File
@@ -86,7 +86,6 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(ClearBuffer);
GETFUNC(SetTexture);
GETFUNC(UpdateTexture);
GETFUNC(DeleteTexture);
GETFUNC(ReadScreenTexture);
GETFUNC(GClipRect);
GETFUNC(ClearMipMapCache);
-1
View File
@@ -2278,7 +2278,6 @@ void I_StartupGraphics(void)
HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL);
HWD.pfnSetTexture = hwSym("SetTexture",NULL);
HWD.pfnUpdateTexture = hwSym("UpdateTexture",NULL);
HWD.pfnDeleteTexture = hwSym("DeleteTexture",NULL);
HWD.pfnReadScreenTexture= hwSym("ReadScreenTexture",NULL);
HWD.pfnGClipRect = hwSym("GClipRect",NULL);
HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL);
+1
View File
@@ -64,6 +64,7 @@ enum
PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory:
// 'second-level' cache for graphics
// stored in hardware format and downloaded as needed
PU_HWRPATCHINFO_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory
PU_HWRMODELTEXTURE_UNLOCKED = 104, // 'unlocked' PU_HWRMODELTEXTURE memory
};