From 554f244ef2ceafde17a64170c42623a58a8bb3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 14 May 2024 23:43:38 +0200 Subject: [PATCH] Remove redundant graphics backend functions returning RGBA format The graphics backends only support the RGBA format with the `SCommand_Texture_Create` and `SCommand_Texture_Update` commands, so the `TexFormatToOpenGLFormat`, `TextureFormatToVulkanFormat` and `TexFormatToNewOpenGLFormat` functions and the command member variables for the format are unnecessary. The `TexFormatToNewOpenGLFormat` function was unused. --- src/engine/client/backend/opengl/backend_opengl.cpp | 11 ++--------- src/engine/client/backend/opengl/backend_opengl.h | 1 - src/engine/client/backend/opengl/backend_opengl3.cpp | 11 ++--------- src/engine/client/backend/opengl/backend_opengl3.h | 1 - src/engine/client/backend/vulkan/backend_vulkan.cpp | 11 +---------- src/engine/client/graphics_threaded.cpp | 3 --- src/engine/client/graphics_threaded.h | 5 ++--- 7 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/engine/client/backend/opengl/backend_opengl.cpp b/src/engine/client/backend/opengl/backend_opengl.cpp index e52300a70..2e3223871 100644 --- a/src/engine/client/backend/opengl/backend_opengl.cpp +++ b/src/engine/client/backend/opengl/backend_opengl.cpp @@ -43,13 +43,6 @@ void CCommandProcessorFragment_OpenGL::Cmd_Update_Viewport(const CCommandBuffer: glViewport(pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height); } -int CCommandProcessorFragment_OpenGL::TexFormatToOpenGLFormat(int TexFormat) -{ - if(TexFormat == CCommandBuffer::TEXFORMAT_RGBA) - return GL_RGBA; - return GL_RGBA; -} - size_t CCommandProcessorFragment_OpenGL::GLFormatToPixelSize(int GLFormat) { switch(GLFormat) @@ -665,7 +658,7 @@ void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int 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, TexFormatToOpenGLFormat(pCommand->m_Format), pCommand->m_pData); + 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) @@ -916,7 +909,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) { - TextureCreate(pCommand->m_Slot, pCommand->m_Width, pCommand->m_Height, TexFormatToOpenGLFormat(pCommand->m_Format), TexFormatToOpenGLFormat(pCommand->m_StoreFormat), pCommand->m_Flags, pCommand->m_pData); + TextureCreate(pCommand->m_Slot, pCommand->m_Width, pCommand->m_Height, GL_RGBA, GL_RGBA, pCommand->m_Flags, pCommand->m_pData); } void CCommandProcessorFragment_OpenGL::Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand) diff --git a/src/engine/client/backend/opengl/backend_opengl.h b/src/engine/client/backend/opengl/backend_opengl.h index db8dd5603..c9e1f938d 100644 --- a/src/engine/client/backend/opengl/backend_opengl.h +++ b/src/engine/client/backend/opengl/backend_opengl.h @@ -82,7 +82,6 @@ protected: bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector &vDstData) override; - static int TexFormatToOpenGLFormat(int TexFormat); static size_t GLFormatToPixelSize(int GLFormat); void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData); diff --git a/src/engine/client/backend/opengl/backend_opengl3.cpp b/src/engine/client/backend/opengl/backend_opengl3.cpp index 38ee2c803..3f4fb575a 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.cpp +++ b/src/engine/client/backend/opengl/backend_opengl3.cpp @@ -30,13 +30,6 @@ static constexpr GLenum BUFFER_INIT_VERTEX_TARGET = GL_COPY_WRITE_BUFFER; #endif // ------------ CCommandProcessorFragment_OpenGL3_3 -int CCommandProcessorFragment_OpenGL3_3::TexFormatToNewOpenGLFormat(int TexFormat) -{ - if(TexFormat == CCommandBuffer::TEXFORMAT_RGBA) - return GL_RGBA; - return GL_RGBA; -} - void CCommandProcessorFragment_OpenGL3_3::UseProgram(CGLSLTWProgram *pProgram) { if(m_LastProgramId != pProgram->GetProgramId()) @@ -514,7 +507,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureUpdate(int Slot, int X, int Y, 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, TexFormatToOpenGLFormat(pCommand->m_Format), pCommand->m_pData); + 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) @@ -666,7 +659,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) { - TextureCreate(pCommand->m_Slot, pCommand->m_Width, pCommand->m_Height, TexFormatToOpenGLFormat(pCommand->m_Format), TexFormatToOpenGLFormat(pCommand->m_StoreFormat), pCommand->m_Flags, pCommand->m_pData); + TextureCreate(pCommand->m_Slot, pCommand->m_Width, pCommand->m_Height, GL_RGBA, GL_RGBA, pCommand->m_Flags, pCommand->m_pData); } void CCommandProcessorFragment_OpenGL3_3::Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand) diff --git a/src/engine/client/backend/opengl/backend_opengl3.h b/src/engine/client/backend/opengl/backend_opengl3.h index 6784bb963..05b82a4df 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.h +++ b/src/engine/client/backend/opengl/backend_opengl3.h @@ -71,7 +71,6 @@ protected: void InitPrimExProgram(CGLSLPrimitiveExProgram *pProgram, class CGLSLCompiler *pCompiler, class IStorage *pStorage, bool Textured, bool Rotationless); - static int TexFormatToNewOpenGLFormat(int TexFormat); bool IsNewApi() override { return true; } void UseProgram(CGLSLTWProgram *pProgram); diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index 3fdcd9b95..edc9eda4d 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -2702,13 +2702,6 @@ protected: return true; } - VkFormat TextureFormatToVulkanFormat(int TexFormat) - { - if(TexFormat == CCommandBuffer::TEXFORMAT_RGBA) - return VK_FORMAT_R8G8B8A8_UNORM; - return VK_FORMAT_R8G8B8A8_UNORM; - } - [[nodiscard]] bool BuildMipmaps(VkImage Image, VkFormat ImageFormat, size_t Width, size_t Height, size_t Depth, size_t MipMapLevelCount) { VkCommandBuffer *pMemCommandBuffer; @@ -6657,12 +6650,10 @@ public: int Slot = pCommand->m_Slot; int Width = pCommand->m_Width; int Height = pCommand->m_Height; - int Format = pCommand->m_Format; - int StoreFormat = pCommand->m_StoreFormat; int Flags = pCommand->m_Flags; uint8_t *pData = pCommand->m_pData; - if(!CreateTextureCMD(Slot, Width, Height, TextureFormatToVulkanFormat(Format), TextureFormatToVulkanFormat(StoreFormat), Flags, pData)) + if(!CreateTextureCMD(Slot, Width, Height, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, Flags, pData)) return false; free(pData); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index eced478e8..ec2642fd6 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -347,7 +347,6 @@ int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y Cmd.m_Y = y; Cmd.m_Width = Image.m_Width; Cmd.m_Height = Image.m_Height; - Cmd.m_Format = CCommandBuffer::TEXFORMAT_RGBA; uint8_t *pTmpData = static_cast(malloc(Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); ConvertToRGBA(pTmpData, Image); @@ -433,8 +432,6 @@ static CCommandBuffer::SCommand_Texture_Create LoadTextureCreateCommand(int Text Cmd.m_Slot = TextureId; Cmd.m_Width = Width; Cmd.m_Height = Height; - Cmd.m_Format = CCommandBuffer::TEXFORMAT_RGBA; - Cmd.m_StoreFormat = CCommandBuffer::TEXFORMAT_RGBA; Cmd.m_Flags = 0; if(Flags & IGraphics::TEXLOAD_NOMIPMAPS) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index cd1113759..3255c67aa 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -527,9 +527,8 @@ public: size_t m_Width; size_t m_Height; - int m_Format; - int m_StoreFormat; int m_Flags; + // data must be in RGBA format uint8_t *m_pData; // will be freed by the command processor }; @@ -545,7 +544,7 @@ public: int m_Y; size_t m_Width; size_t m_Height; - int m_Format; + // data must be in RGBA format uint8_t *m_pData; // will be freed by the command processor };