From 493d2dc9d871b918724e5328ac57e8ba9bf593c6 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 28 Oct 2017 00:52:54 +0200 Subject: [PATCH 1/9] add speedups correctly to the border tiles, to allow them beeing displayed on extended range --- src/game/client/components/maplayers.cpp | 30 +++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 3c2f7f374..ac88c4dbc 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -636,14 +636,12 @@ void CMapLayers::OnMapLoad() Visuals.m_TilesOfLayer[y][x].m_IndexBufferByteOffset = (char*)(TilesHandledCount*6*sizeof(unsigned int)); Visuals.m_TilesOfLayer[y][x].m_TilesHandledCount = tmpTiles.size(); - if(IsSpeedupLayer && CurOverlay == 0) - { - if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, true, AngleRotate)) - Visuals.m_TilesOfLayer[y][x].m_Draw = true; - } - else - if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) - Visuals.m_TilesOfLayer[y][x].m_Draw = true; + bool AddAsSpeedup = false; + if (IsSpeedupLayer && CurOverlay == 0) + AddAsSpeedup = true; + + if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + Visuals.m_TilesOfLayer[y][x].m_Draw = true; //do the border tiles if(x == 0) @@ -651,19 +649,19 @@ void CMapLayers::OnMapLoad() if(y == 0) { Visuals.m_BorderTopLeft.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int)); - if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderTopLeft.m_Draw = true; } else if(y == pTMap->m_Height - 1) { Visuals.m_BorderBottomLeft.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int)); - if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderBottomLeft.m_Draw = true; } else { Visuals.m_BorderLeft[y-1].m_IndexBufferByteOffset = (char*)(tmpBorderLeftTiles.size()*6*sizeof(unsigned int)); Visuals.m_BorderLeft[y-1].m_TilesHandledCount = tmpBorderLeftTiles.size(); - if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderLeft[y-1].m_Draw = true; } } else if(x == pTMap->m_Width - 1) @@ -671,20 +669,20 @@ void CMapLayers::OnMapLoad() if(y == 0) { Visuals.m_BorderTopRight.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int)); - if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderTopRight.m_Draw = true; } else if(y == pTMap->m_Height - 1) { Visuals.m_BorderBottomRight.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int)); - if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderBottomRight.m_Draw = true; } else { Visuals.m_BorderRight[y-1].m_IndexBufferByteOffset = (char*)(tmpBorderRightTiles.size()*6*sizeof(unsigned int)); Visuals.m_BorderRight[y-1].m_TilesHandledCount = tmpBorderRightTiles.size(); - if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderRight[y-1].m_Draw = true; } } else if(y == 0) @@ -693,7 +691,7 @@ void CMapLayers::OnMapLoad() { Visuals.m_BorderTop[x-1].m_IndexBufferByteOffset = (char*)(tmpBorderTopTiles.size()*6*sizeof(unsigned int)); Visuals.m_BorderTop[x-1].m_TilesHandledCount = tmpBorderTopTiles.size(); - if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderTop[x-1].m_Draw = true; } } else if(y == pTMap->m_Height - 1) @@ -702,7 +700,7 @@ void CMapLayers::OnMapLoad() { Visuals.m_BorderBottom[x-1].m_IndexBufferByteOffset = (char*)(tmpBorderBottomTiles.size()*6*sizeof(unsigned int)); Visuals.m_BorderBottom[x-1].m_TilesHandledCount = tmpBorderBottomTiles.size(); - if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords)) + if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_BorderBottom[x-1].m_Draw = true; } } From f15f41e6547a929df95754224c0f347161891a9c Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 28 Oct 2017 02:04:53 +0200 Subject: [PATCH 2/9] remove extension limit for tile layers --- src/game/client/components/maplayers.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index ac88c4dbc..43ed6ebe1 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -884,11 +884,6 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem { STileLayerVisuals& Visuals = *m_TileLayerVisuals[LayerIndex]; - if(BorderX0 < -300 + pGroup->m_OffsetX/32) BorderX0 = -300 + pGroup->m_OffsetX/32; - if(BorderY0 < -300 + pGroup->m_OffsetY/32) BorderY0 = -300 + pGroup->m_OffsetY/32; - if(BorderX1 >= pTileLayer->m_Width + 300 + pGroup->m_OffsetX/32) BorderX1 = pTileLayer->m_Width + 299 + pGroup->m_OffsetX/32; - if(BorderY1 >= pTileLayer->m_Height + 300 + pGroup->m_OffsetY/32) BorderY1 = pTileLayer->m_Height + 299 + pGroup->m_OffsetY/32; - int Y0 = BorderY0; int X0 = BorderX0; int Y1 = BorderY1; From c22af4bb4da9a2b6377c661528c1d070ff77d8a2 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Fri, 3 Nov 2017 19:33:23 +0100 Subject: [PATCH 3/9] fix index buffer bindig for normal quads(fixes startup crashes) and initialize non mipmap textures as linear(texture completness) --- src/engine/client/backend_sdl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 9734445c6..b0cfe4bae 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -763,7 +763,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand glGenBuffers(1, &m_QuadDrawIndexBufferID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadDrawIndexBufferID); - m_LastIndexBufferBound = m_QuadDrawIndexBufferID; + m_LastIndexBufferBound = 0; unsigned int Indices[CCommandBuffer::MAX_VERTICES/4 * 6]; int Primq = 0; @@ -927,6 +927,8 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); From d367f94d7c6e5aa592260eea733b0ff72393dfc4 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Fri, 3 Nov 2017 19:48:17 +0100 Subject: [PATCH 4/9] invalidate all index buffer bindigs, when index buffer is resized --- src/engine/client/backend_sdl.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index b0cfe4bae..cbfe56f84 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -760,7 +760,8 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand { m_TextureSlotBoundToUnit[i].m_TextureSlot = -1; } - + + glBindVertexArray(0); glGenBuffers(1, &m_QuadDrawIndexBufferID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadDrawIndexBufferID); m_LastIndexBufferBound = 0; @@ -1158,6 +1159,11 @@ void CCommandProcessorFragment_OpenGL3_3::AppendIndices(unsigned int NewIndicesC glDeleteBuffers(1, &m_QuadDrawIndexBufferID); m_QuadDrawIndexBufferID = NewIndexBufferID; + + m_LastIndexBufferBound = 0; + for (size_t i = 0; i < m_VisualObjects.size(); ++i) { + m_VisualObjects[i].m_LastIndexBufferBound = 0; + } m_CurrentIndicesInBuffer = NewIndicesCount; delete[] Indices; From 78a9fbb9b56bb2f94063d689724af9b68eeafd33 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 4 Nov 2017 04:57:58 +0100 Subject: [PATCH 5/9] use the write buffer slot, instead of elementarray slot to create the index buffer --- src/engine/client/backend_sdl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index cbfe56f84..f2a8ad5ef 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -763,7 +763,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand glBindVertexArray(0); glGenBuffers(1, &m_QuadDrawIndexBufferID); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadDrawIndexBufferID); + glBindBuffer(GL_COPY_WRITE_BUFFER, m_QuadDrawIndexBufferID); m_LastIndexBufferBound = 0; unsigned int Indices[CCommandBuffer::MAX_VERTICES/4 * 6]; @@ -778,7 +778,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand Indices[i+5] = Primq + 3; Primq+=4; } - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * CCommandBuffer::MAX_VERTICES/4 * 6, Indices, GL_STATIC_DRAW); + glBufferData(GL_COPY_WRITE_BUFFER, sizeof(unsigned int) * CCommandBuffer::MAX_VERTICES/4 * 6, Indices, GL_STATIC_DRAW); m_CurrentIndicesInBuffer = CCommandBuffer::MAX_VERTICES/4 * 6; From 78c06e180fcbaec3d257ad27d57f5e0f5832cfac Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sat, 4 Nov 2017 05:38:48 +0100 Subject: [PATCH 6/9] remove dublicated GL queries --- src/engine/client/backend_sdl.cpp | 23 +++++++++++++---------- src/engine/client/backend_sdl.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index f2a8ad5ef..09fcd9a62 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -263,8 +263,9 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: // resample if needed if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) { - int MaxTexSize; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); + static int MaxTexSize = -1; + if(MaxTexSize == -1) + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); if(Width > MaxTexSize || Height > MaxTexSize) { do @@ -752,7 +753,10 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand if(m_UsePreinitializedVertexBuffer) glBufferData(GL_ARRAY_BUFFER, sizeof(CCommandBuffer::SVertex) * CCommandBuffer::MAX_VERTICES, NULL, GL_STREAM_DRAW); - + + //query the image max size only once + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_MaxTexSize); + //query maximum of allowed textures glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_MaxTextureUnits); m_TextureSlotBoundToUnit.resize(m_MaxTextureUnits); @@ -785,6 +789,9 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand mem_zero(m_aTextures, sizeof(m_aTextures)); m_ClearColor.r = m_ClearColor.g = m_ClearColor.b = -1.f; + + //fix the alignment to allow even 1byte changes, e.g. for alpha components + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown *pCommand) @@ -827,9 +834,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Update(const CCommandBuffe glActiveTexture(GL_TEXTURE0 + Slot); glBindSampler(Slot, m_aTextures[pCommand->m_Slot].m_Sampler); } - - //fix the alignment to allow even 1byte changes, e.g. for alpha components - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); glTexSubImage2D(GL_TEXTURE_2D, 0, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, TexFormatToOpenGLFormat(pCommand->m_Format), GL_UNSIGNED_BYTE, pCommand->m_pData); @@ -860,16 +865,14 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe // resample if needed if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) { - int MaxTexSize; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); - if(Width > MaxTexSize || Height > MaxTexSize) + if(Width > m_MaxTexSize || Height > m_MaxTexSize) { do { Width>>=1; Height>>=1; } - while(Width > MaxTexSize || Height > MaxTexSize); + while(Width > m_MaxTexSize || Height > m_MaxTexSize); void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); mem_free(pTexData); diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 7efbda756..802d12056 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -156,6 +156,7 @@ class CCommandProcessorFragment_OpenGL3_3 unsigned int m_CurrentIndicesInBuffer; GLint m_MaxTextureUnits; + GLint m_MaxTexSize; int m_LastBlendMode; //avoid all possible opengl state changes bool m_LastClipEnable; From 14297ae45c4f3627b8bae99b5bb775e128cbca41 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 26 Nov 2017 13:28:41 +0100 Subject: [PATCH 7/9] code pattern --- src/engine/client/backend_sdl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 09fcd9a62..30bd3834c 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -263,7 +263,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: // resample if needed if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) { - static int MaxTexSize = -1; + static int s_MaxTexSize = -1; if(MaxTexSize == -1) glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); if(Width > MaxTexSize || Height > MaxTexSize) @@ -1164,7 +1164,8 @@ void CCommandProcessorFragment_OpenGL3_3::AppendIndices(unsigned int NewIndicesC m_QuadDrawIndexBufferID = NewIndexBufferID; m_LastIndexBufferBound = 0; - for (size_t i = 0; i < m_VisualObjects.size(); ++i) { + for (size_t i = 0; i < m_VisualObjects.size(); ++i) + { m_VisualObjects[i].m_LastIndexBufferBound = 0; } From bff1186d3b87deb33e509ff896b42a98907968c3 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 26 Nov 2017 14:08:00 +0100 Subject: [PATCH 8/9] is now s_ --- src/engine/client/backend_sdl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 30bd3834c..f1765f21f 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -264,9 +264,9 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) { static int s_MaxTexSize = -1; - if(MaxTexSize == -1) - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); - if(Width > MaxTexSize || Height > MaxTexSize) + if(s_MaxTexSize == -1) + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s_MaxTexSize); + if(Width > s_MaxTexSize || Height > s_MaxTexSize) { do { From b1d99de87a2dca98563f36bb7d61328aeee883c6 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 26 Nov 2017 14:10:47 +0100 Subject: [PATCH 9/9] s_ --- src/engine/client/backend_sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index f1765f21f..fcedebc16 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -273,7 +273,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: Width>>=1; Height>>=1; } - while(Width > MaxTexSize || Height > MaxTexSize); + while(Width > s_MaxTexSize || Height > s_MaxTexSize); void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); mem_free(pTexData);