From 9110d393ddd3b2db93fc0185e0dc689ee8ce1d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 1 Aug 2024 22:25:31 +0200 Subject: [PATCH 1/4] Remove unused `IGraphics::NullTexture` function It should not be necessary to access the null-texture directly. The `CTextureHandle::IsNullTexture` function can be used to check if a texture handle is the null-texture. --- src/engine/client/graphics_threaded.cpp | 5 ----- src/engine/client/graphics_threaded.h | 1 - src/engine/graphics.h | 1 - 3 files changed, 7 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index c4fe1bf8a..88027a0aa 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -514,11 +514,6 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename, return m_NullTexture; } -IGraphics::CTextureHandle CGraphics_Threaded::NullTexture() const -{ - return m_NullTexture; -} - bool CGraphics_Threaded::LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) { if(Width == 0 || Height == 0) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 156e9d6d5..17321917b 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -967,7 +967,6 @@ public: IGraphics::CTextureHandle LoadTextureRaw(const CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; IGraphics::CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; int LoadTextureRawSub(IGraphics::CTextureHandle TextureId, int x, int y, const CImageInfo &Image) override; - IGraphics::CTextureHandle NullTexture() const override; bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) override; bool UnloadTextTextures(CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture) override; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index da9206349..2bb017641 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -345,7 +345,6 @@ public: virtual CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) = 0; virtual int LoadTextureRawSub(CTextureHandle TextureId, int x, int y, const CImageInfo &Image) = 0; virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) = 0; - virtual CTextureHandle NullTexture() const = 0; virtual void TextureSet(CTextureHandle Texture) = 0; void TextureClear() { TextureSet(CTextureHandle()); } From da8ec6bed9e371234be48cd3177867b53d905f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 1 Aug 2024 22:37:02 +0200 Subject: [PATCH 2/4] Remove unused `LoadTextureRawSub` and `CMD_TEXTURE_UPDATE` The `IGraphics::LoadTextureRawSub` function and the respective `CMD_TEXTURE_UPDATE` command are unused. Only text textures are updated after having been uploaded, but there is a separate `CMD_TEXT_TEXTURE_UPDATE` for that. --- .../client/backend/opengl/backend_opengl.cpp | 8 -------- .../client/backend/opengl/backend_opengl.h | 1 - .../client/backend/opengl/backend_opengl3.cpp | 5 ----- .../client/backend/opengl/backend_opengl3.h | 1 - .../client/backend/vulkan/backend_vulkan.cpp | 14 -------------- src/engine/client/graphics_threaded.cpp | 19 ------------------- src/engine/client/graphics_threaded.h | 18 ------------------ src/engine/graphics.h | 1 - 8 files changed, 67 deletions(-) diff --git a/src/engine/client/backend/opengl/backend_opengl.cpp b/src/engine/client/backend/opengl/backend_opengl.cpp index 2e3223871..3ca11ff59 100644 --- a/src/engine/client/backend/opengl/backend_opengl.cpp +++ b/src/engine/client/backend/opengl/backend_opengl.cpp @@ -656,11 +656,6 @@ void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int free(pTexData); } -void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) -{ - TextureUpdate(pCommand->m_Slot, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, GL_RGBA, pCommand->m_pData); -} - void CCommandProcessorFragment_OpenGL::DestroyTexture(int Slot) { m_pTextureMemoryUsage->store(m_pTextureMemoryUsage->load(std::memory_order_relaxed) - m_vTextures[Slot].m_MemSize, std::memory_order_relaxed); @@ -1057,9 +1052,6 @@ ERunCommandReturnTypes CCommandProcessorFragment_OpenGL::RunCommand(const CComma case CCommandBuffer::CMD_TEXTURE_DESTROY: Cmd_Texture_Destroy(static_cast(pBaseCommand)); break; - case CCommandBuffer::CMD_TEXTURE_UPDATE: - Cmd_Texture_Update(static_cast(pBaseCommand)); - break; case CCommandBuffer::CMD_TEXT_TEXTURES_CREATE: Cmd_TextTextures_Create(static_cast(pBaseCommand)); break; diff --git a/src/engine/client/backend/opengl/backend_opengl.h b/src/engine/client/backend/opengl/backend_opengl.h index c9e1f938d..f0d833cc4 100644 --- a/src/engine/client/backend/opengl/backend_opengl.h +++ b/src/engine/client/backend/opengl/backend_opengl.h @@ -89,7 +89,6 @@ protected: virtual bool Cmd_Init(const SCommand_Init *pCommand); virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {} - virtual void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand); virtual void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand); virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand); virtual void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand); diff --git a/src/engine/client/backend/opengl/backend_opengl3.cpp b/src/engine/client/backend/opengl/backend_opengl3.cpp index 3f4fb575a..95dbf3d36 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.cpp +++ b/src/engine/client/backend/opengl/backend_opengl3.cpp @@ -505,11 +505,6 @@ void CCommandProcessorFragment_OpenGL3_3::TextureUpdate(int Slot, int X, int Y, free(pTexData); } -void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) -{ - TextureUpdate(pCommand->m_Slot, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, GL_RGBA, pCommand->m_pData); -} - void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) { int Slot = 0; diff --git a/src/engine/client/backend/opengl/backend_opengl3.h b/src/engine/client/backend/opengl/backend_opengl3.h index 05b82a4df..7b68d813d 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.h +++ b/src/engine/client/backend/opengl/backend_opengl3.h @@ -82,7 +82,6 @@ protected: bool Cmd_Init(const SCommand_Init *pCommand) override; void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override; - void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) override; void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) override; void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) override; void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand) override; diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index 4efcc5bd8..8c36efa4a 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -1263,7 +1263,6 @@ protected: { m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXTURE_CREATE)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_Texture_Create(static_cast(pBaseCommand)); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXTURE_DESTROY)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_Texture_Destroy(static_cast(pBaseCommand)); }}; - m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXTURE_UPDATE)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_Texture_Update(static_cast(pBaseCommand)); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXT_TEXTURES_CREATE)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_TextTextures_Create(static_cast(pBaseCommand)); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXT_TEXTURES_DESTROY)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_TextTextures_Destroy(static_cast(pBaseCommand)); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_TEXT_TEXTURE_UPDATE)] = {false, [](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) {}, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_TextTexture_Update(static_cast(pBaseCommand)); }}; @@ -6631,19 +6630,6 @@ public: return true; } - [[nodiscard]] bool Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) - { - size_t IndexTex = pCommand->m_Slot; - uint8_t *pData = pCommand->m_pData; - - if(!UpdateTexture(IndexTex, VK_FORMAT_B8G8R8A8_UNORM, pData, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height)) - return false; - - free(pData); - - return true; - } - [[nodiscard]] bool Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) { size_t ImageIndex = (size_t)pCommand->m_Slot; diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 88027a0aa..b3d4a6f28 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -337,25 +337,6 @@ static bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage) } } -int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y, const CImageInfo &Image) -{ - dbg_assert(TextureId.IsValid(), "Invalid texture handle used with LoadTextureRawSub."); - - CCommandBuffer::SCommand_Texture_Update Cmd; - Cmd.m_Slot = TextureId.Id(); - Cmd.m_X = x; - Cmd.m_Y = y; - Cmd.m_Width = Image.m_Width; - Cmd.m_Height = Image.m_Height; - - uint8_t *pTmpData = static_cast(malloc(Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); - ConvertToRGBA(pTmpData, Image); - Cmd.m_pData = pTmpData; - AddCmd(Cmd); - - return 0; -} - IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTextureImpl(const CImageInfo &FromImageInfo, int x, int y, size_t w, size_t h, const char *pName) { m_vSpriteHelper.resize(w * h * FromImageInfo.PixelSize()); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 17321917b..3b852b50f 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -93,7 +93,6 @@ public: // texture commands CMD_TEXTURE_CREATE, CMD_TEXTURE_DESTROY, - CMD_TEXTURE_UPDATE, CMD_TEXT_TEXTURES_CREATE, CMD_TEXT_TEXTURES_DESTROY, CMD_TEXT_TEXTURE_UPDATE, @@ -532,22 +531,6 @@ public: uint8_t *m_pData; // will be freed by the command processor }; - struct SCommand_Texture_Update : public SCommand - { - SCommand_Texture_Update() : - SCommand(CMD_TEXTURE_UPDATE) {} - - // texture information - int m_Slot; - - int m_X; - int m_Y; - size_t m_Width; - size_t m_Height; - // data must be in RGBA format - uint8_t *m_pData; // will be freed by the command processor - }; - struct SCommand_Texture_Destroy : public SCommand { SCommand_Texture_Destroy() : @@ -966,7 +949,6 @@ public: int UnloadTexture(IGraphics::CTextureHandle *pIndex) override; IGraphics::CTextureHandle LoadTextureRaw(const CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; IGraphics::CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; - int LoadTextureRawSub(IGraphics::CTextureHandle TextureId, int x, int y, const CImageInfo &Image) override; bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) override; bool UnloadTextTextures(CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture) override; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 2bb017641..2c7c4dbfc 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -343,7 +343,6 @@ public: virtual int UnloadTexture(CTextureHandle *pIndex) = 0; virtual CTextureHandle LoadTextureRaw(const CImageInfo &Image, int Flags, const char *pTexName = nullptr) = 0; virtual CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) = 0; - virtual int LoadTextureRawSub(CTextureHandle TextureId, int x, int y, const CImageInfo &Image) = 0; virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) = 0; virtual void TextureSet(CTextureHandle Texture) = 0; void TextureClear() { TextureSet(CTextureHandle()); } From 273f3e5bfa72dd3cf2143c9e9cb025d7d4b4643b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 1 Aug 2024 22:38:48 +0200 Subject: [PATCH 3/4] Remove unused return value of `IGraphics::UnloadTexture` function --- src/engine/client/graphics_threaded.cpp | 5 ++--- src/engine/client/graphics_threaded.h | 2 +- src/engine/graphics.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index b3d4a6f28..282dda34a 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -288,17 +288,16 @@ void CGraphics_Threaded::FreeTextureIndex(CTextureHandle *pIndex) pIndex->Invalidate(); } -int CGraphics_Threaded::UnloadTexture(CTextureHandle *pIndex) +void CGraphics_Threaded::UnloadTexture(CTextureHandle *pIndex) { if(pIndex->IsNullTexture() || !pIndex->IsValid()) - return 0; + return; CCommandBuffer::SCommand_Texture_Destroy Cmd; Cmd.m_Slot = pIndex->Id(); AddCmd(Cmd); FreeTextureIndex(pIndex); - return 0; } static bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 3b852b50f..dd1d4ce65 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -946,7 +946,7 @@ public: IGraphics::CTextureHandle FindFreeTextureIndex(); void FreeTextureIndex(CTextureHandle *pIndex); - int UnloadTexture(IGraphics::CTextureHandle *pIndex) override; + void UnloadTexture(IGraphics::CTextureHandle *pIndex) override; IGraphics::CTextureHandle LoadTextureRaw(const CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; IGraphics::CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) override; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 2c7c4dbfc..418bf7b58 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -340,7 +340,7 @@ public: // destination width must be equal to the subwidth of the source virtual void CopyTextureFromTextureBufferSub(uint8_t *pDestBuffer, size_t DestWidth, size_t DestHeight, const CImageInfo &SourceImage, size_t SrcSubOffsetX, size_t SrcSubOffsetY, size_t SrcSubCopyWidth, size_t SrcSubCopyHeight) = 0; - virtual int UnloadTexture(CTextureHandle *pIndex) = 0; + virtual void UnloadTexture(CTextureHandle *pIndex) = 0; virtual CTextureHandle LoadTextureRaw(const CImageInfo &Image, int Flags, const char *pTexName = nullptr) = 0; virtual CTextureHandle LoadTextureRawMove(CImageInfo &Image, int Flags, const char *pTexName = nullptr) = 0; virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) = 0; From 924f8f582b6e18cdd14bb05ef2eed406c294dd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 1 Aug 2024 22:41:11 +0200 Subject: [PATCH 4/4] Remove unused `TEXLOAD_NOMIPMAPS` and `TEXLOAD_NO_COMPRESSION` The flag `TEXLOAD_NO_COMPRESSION` is entirely unused. The flag `TEXLOAD_NOMIPMAPS` is unused and only the respective `CCommandBuffer::TEXFLAG_NOMIPMAPS` is used internally, so the former flag does not need to be exposed to users of `IGraphics`. --- src/engine/client/graphics_threaded.cpp | 2 -- src/engine/graphics.h | 8 +++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 282dda34a..5122ba1db 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -414,8 +414,6 @@ static CCommandBuffer::SCommand_Texture_Create LoadTextureCreateCommand(int Text Cmd.m_Height = Height; Cmd.m_Flags = 0; - if(Flags & IGraphics::TEXLOAD_NOMIPMAPS) - Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NOMIPMAPS; if((Flags & IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE) != 0) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE; if((Flags & IGraphics::TEXLOAD_TO_3D_TEXTURE) != 0) diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 418bf7b58..184e907e8 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -250,11 +250,9 @@ protected: public: enum { - TEXLOAD_NOMIPMAPS = 1 << 1, - TEXLOAD_NO_COMPRESSION = 1 << 2, - TEXLOAD_TO_3D_TEXTURE = (1 << 3), - TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4), - TEXLOAD_NO_2D_TEXTURE = (1 << 5), + TEXLOAD_TO_3D_TEXTURE = 1 << 0, + TEXLOAD_TO_2D_ARRAY_TEXTURE = 1 << 1, + TEXLOAD_NO_2D_TEXTURE = 1 << 2, }; class CTextureHandle