Skip to content

Commit

Permalink
Extract CGraphics_Threaded::FreeTextureIndex function
Browse files Browse the repository at this point in the history
To reduce duplicate code.
  • Loading branch information
Robyt3 committed Jul 20, 2023
1 parent 126caa2 commit 51b6514
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/engine/client/graphics_threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ void CGraphics_Threaded::LinesDraw(const CLineItem *pArray, int Num)
AddVertices(2 * Num);
}

void CGraphics_Threaded::FreeTextureIndex(CTextureHandle *pIndex)
{
dbg_assert(pIndex->IsValid(), "Cannot free invalid texture index");
m_vTextureIndices[pIndex->Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = pIndex->Id();
pIndex->Invalidate();
}

int CGraphics_Threaded::UnloadTexture(CTextureHandle *pIndex)
{
if(pIndex->Id() == m_InvalidTexture.Id())
Expand All @@ -275,10 +283,7 @@ int CGraphics_Threaded::UnloadTexture(CTextureHandle *pIndex)
AddCmd(
Cmd, [] { return true; }, "failed to unload texture.");

m_vTextureIndices[pIndex->Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = pIndex->Id();

pIndex->Invalidate();
FreeTextureIndex(pIndex);
return 0;
}

Expand Down Expand Up @@ -589,14 +594,10 @@ bool CGraphics_Threaded::UnloadTextTextures(CTextureHandle &TextTexture, CTextur
AddCmd(
Cmd, [] { return true; }, "failed to unload text textures.");

m_vTextureIndices[TextTexture.Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = TextTexture.Id();

m_vTextureIndices[TextOutlineTexture.Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = TextOutlineTexture.Id();

TextTexture.Invalidate();
TextOutlineTexture.Invalidate();
if(TextTexture.IsValid())
FreeTextureIndex(&TextTexture);
if(TextOutlineTexture.IsValid())
FreeTextureIndex(&TextOutlineTexture);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/engine/client/graphics_threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ class CGraphics_Threaded : public IEngineGraphics
void LinesEnd() override;
void LinesDraw(const CLineItem *pArray, int Num) override;

void FreeTextureIndex(CTextureHandle *pIndex);
int UnloadTexture(IGraphics::CTextureHandle *pIndex) override;
IGraphics::CTextureHandle LoadTextureRaw(size_t Width, size_t Height, int Format, const void *pData, int StoreFormat, int Flags, const char *pTexName = NULL) override;
int LoadTextureRawSub(IGraphics::CTextureHandle TextureID, int x, int y, size_t Width, size_t Height, int Format, const void *pData) override;
Expand Down

0 comments on commit 51b6514

Please sign in to comment.