mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #2718
2718: Fix texture destroy r=heinrich5991 a=Jupeyy Might already help with #2717 Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
f48ba92161
|
@ -530,11 +530,41 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::
|
|||
free(pTexData);
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL::DestroyTexture(int Slot)
|
||||
{
|
||||
m_pTextureMemoryUsage->store(m_pTextureMemoryUsage->load(std::memory_order_relaxed) - m_aTextures[Slot].m_MemSize, std::memory_order_relaxed);
|
||||
|
||||
if(m_aTextures[Slot].m_Tex != 0)
|
||||
{
|
||||
glDeleteTextures(1, &m_aTextures[Slot].m_Tex);
|
||||
}
|
||||
|
||||
if(m_aTextures[Slot].m_Tex2DArray != 0)
|
||||
{
|
||||
glDeleteTextures(1, &m_aTextures[Slot].m_Tex2DArray);
|
||||
}
|
||||
|
||||
if(IsNewApi())
|
||||
{
|
||||
if(m_aTextures[Slot].m_Sampler != 0)
|
||||
{
|
||||
glDeleteSamplers(1, &m_aTextures[Slot].m_Sampler);
|
||||
}
|
||||
if(m_aTextures[Slot].m_Sampler2DArray != 0)
|
||||
{
|
||||
glDeleteSamplers(1, &m_aTextures[Slot].m_Sampler2DArray);
|
||||
}
|
||||
}
|
||||
|
||||
m_aTextures[Slot].m_Tex = 0;
|
||||
m_aTextures[Slot].m_Sampler = 0;
|
||||
m_aTextures[Slot].m_Tex2DArray = 0;
|
||||
m_aTextures[Slot].m_Sampler2DArray = 0;
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand)
|
||||
{
|
||||
glDeleteTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex);
|
||||
m_aTextures[pCommand->m_Slot].m_Tex = 0;
|
||||
m_pTextureMemoryUsage->store(m_pTextureMemoryUsage->load(std::memory_order_relaxed) - m_aTextures[pCommand->m_Slot].m_MemSize, std::memory_order_relaxed);
|
||||
DestroyTexture(pCommand->m_Slot);
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand)
|
||||
|
@ -2341,15 +2371,34 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand
|
|||
|
||||
void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown *pCommand)
|
||||
{
|
||||
glUseProgram(0);
|
||||
|
||||
m_pPrimitiveProgram->DeleteProgram();
|
||||
m_pBorderTileProgram->DeleteProgram();
|
||||
m_pBorderTileProgramTextured->DeleteProgram();
|
||||
m_pBorderTileLineProgram->DeleteProgram();
|
||||
m_pBorderTileLineProgramTextured->DeleteProgram();
|
||||
m_pQuadProgram->DeleteProgram();
|
||||
m_pQuadProgramTextured->DeleteProgram();
|
||||
m_pTileProgram->DeleteProgram();
|
||||
m_pTileProgramTextured->DeleteProgram();
|
||||
m_pTextProgram->DeleteProgram();
|
||||
m_pSpriteProgram->DeleteProgram();
|
||||
m_pSpriteProgramMultiple->DeleteProgram();
|
||||
|
||||
//clean up everything
|
||||
delete m_pPrimitiveProgram;
|
||||
//delete m_QuadProgram;
|
||||
delete m_pTileProgram;
|
||||
delete m_pTileProgramTextured;
|
||||
delete m_pBorderTileProgram;
|
||||
delete m_pBorderTileProgramTextured;
|
||||
delete m_pBorderTileLineProgram;
|
||||
delete m_pBorderTileLineProgramTextured;
|
||||
delete m_pQuadProgram;
|
||||
delete m_pQuadProgramTextured;
|
||||
delete m_pTileProgram;
|
||||
delete m_pTileProgramTextured;
|
||||
delete m_pTextProgram;
|
||||
delete m_pSpriteProgram;
|
||||
delete m_pSpriteProgramMultiple;
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteBuffers(MAX_STREAM_BUFFER_COUNT, m_PrimitiveDrawBufferID);
|
||||
|
@ -2719,28 +2768,6 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Screenshot(const CCommandBuffer::S
|
|||
pCommand->m_pImage->m_pData = pPixelData;
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL3_3::DestroyTexture(int Slot)
|
||||
{
|
||||
glDeleteTextures(1, &m_aTextures[Slot].m_Tex);
|
||||
glDeleteSamplers(1, &m_aTextures[Slot].m_Sampler);
|
||||
m_pTextureMemoryUsage->store(m_pTextureMemoryUsage->load(std::memory_order_relaxed) - m_aTextures[Slot].m_MemSize, std::memory_order_relaxed);
|
||||
|
||||
if(m_aTextures[Slot].m_Tex2DArray != 0)
|
||||
{
|
||||
glDeleteTextures(1, &m_aTextures[Slot].m_Tex2DArray);
|
||||
}
|
||||
|
||||
if(m_aTextures[Slot].m_Sampler2DArray != 0)
|
||||
{
|
||||
glDeleteSamplers(1, &m_aTextures[Slot].m_Sampler2DArray);
|
||||
}
|
||||
|
||||
m_aTextures[Slot].m_Tex = 0;
|
||||
m_aTextures[Slot].m_Sampler = 0;
|
||||
m_aTextures[Slot].m_Tex2DArray = 0;
|
||||
m_aTextures[Slot].m_Sampler2DArray = 0;
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL3_3::DestroyBufferContainer(int Index, bool DeleteBOs)
|
||||
{
|
||||
SBufferContainer& BufferContainer = m_BufferContainers[Index];
|
||||
|
@ -4268,6 +4295,12 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
|
|||
|
||||
if(InitError == -2)
|
||||
{
|
||||
CCommandProcessorFragment_OpenGL::SCommand_Shutdown CmdGL;
|
||||
CmdBuffer.AddCommand(CmdGL);
|
||||
RunBuffer(&CmdBuffer);
|
||||
WaitForIdle();
|
||||
CmdBuffer.Reset();
|
||||
|
||||
g_Config.m_GfxOpenGLMajor = 1;
|
||||
g_Config.m_GfxOpenGLMinor = 5;
|
||||
g_Config.m_GfxOpenGLPatch = 0;
|
||||
|
@ -4340,6 +4373,12 @@ int CGraphicsBackend_SDL_OpenGL::Shutdown()
|
|||
{
|
||||
// issue a shutdown command
|
||||
CCommandBuffer CmdBuffer(1024, 512);
|
||||
CCommandProcessorFragment_OpenGL::SCommand_Shutdown CmdGL;
|
||||
CmdBuffer.AddCommand(CmdGL);
|
||||
RunBuffer(&CmdBuffer);
|
||||
WaitForIdle();
|
||||
CmdBuffer.Reset();
|
||||
|
||||
CCommandProcessorFragment_SDL::SCommand_Shutdown Cmd;
|
||||
CmdBuffer.AddCommand(Cmd);
|
||||
RunBuffer(&CmdBuffer);
|
||||
|
|
|
@ -110,7 +110,7 @@ class CCommandProcessorFragment_OpenGL
|
|||
protected:
|
||||
struct CTexture
|
||||
{
|
||||
CTexture() : m_Tex2DArray(0), m_Sampler2DArray(0) {}
|
||||
CTexture() : m_Tex(0), m_Tex2DArray(0), m_Sampler(0), m_Sampler2DArray(0) {}
|
||||
GLuint m_Tex;
|
||||
GLuint m_Tex2DArray; //or 3D texture as fallback
|
||||
GLuint m_Sampler;
|
||||
|
@ -164,6 +164,7 @@ public:
|
|||
protected:
|
||||
void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture = false);
|
||||
virtual bool IsNewApi() { return false; }
|
||||
void DestroyTexture(int Slot);
|
||||
|
||||
static int TexFormatToOpenGLFormat(int TexFormat);
|
||||
static int TexFormatToImageColorChannelCount(int TexFormat);
|
||||
|
@ -313,7 +314,6 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope
|
|||
GLuint m_QuadDrawIndexBufferID;
|
||||
unsigned int m_CurrentIndicesInBuffer;
|
||||
|
||||
void DestroyTexture(int Slot);
|
||||
void DestroyBufferContainer(int Index, bool DeleteBOs = true);
|
||||
|
||||
void AppendIndices(unsigned int NewIndicesCount);
|
||||
|
|
Loading…
Reference in a new issue