From 288a18fa95177916a27b59972cea116274165b6d Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 29 Dec 2020 14:31:42 +0100 Subject: [PATCH] Don't render fully transparent quads --- src/engine/client/backend_sdl.cpp | 6 ++++-- src/engine/client/graphics_threaded.cpp | 3 ++- src/engine/client/graphics_threaded.h | 3 ++- src/engine/graphics.h | 2 +- src/game/client/components/maplayers.cpp | 25 ++++++++++++++++++------ src/game/client/render_map.cpp | 3 +++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 8ddff6f87..cfe85156e 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -3329,6 +3329,8 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderQuadLayer(const CCommandBuff int QuadsLeft = pCommand->m_QuadNum; size_t QuadOffset = 0; + // the extra offset is not related to the information from the command, but an actual offset in the buffer + size_t QuadOffsetExtra = pCommand->m_QuadOffset; vec4 aColors[m_MaxQuadsPossible]; vec2 aOffsets[m_MaxQuadsPossible]; @@ -3348,8 +3350,8 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderQuadLayer(const CCommandBuff pProgram->SetUniformVec4(pProgram->m_LocColors, ActualQuadCount, (float *)aColors); pProgram->SetUniformVec2(pProgram->m_LocOffsets, ActualQuadCount, (float *)aOffsets); pProgram->SetUniform(pProgram->m_LocRotations, ActualQuadCount, (float *)aRotations); - pProgram->SetUniform(pProgram->m_LocQuadOffset, (int)QuadOffset); - glDrawElements(GL_TRIANGLES, ActualQuadCount * 6, GL_UNSIGNED_INT, (void *)(QuadOffset * 6 * sizeof(unsigned int))); + pProgram->SetUniform(pProgram->m_LocQuadOffset, (int)(QuadOffset + QuadOffsetExtra)); + glDrawElements(GL_TRIANGLES, ActualQuadCount * 6, GL_UNSIGNED_INT, (void *)((QuadOffset + QuadOffsetExtra) * 6 * sizeof(unsigned int))); QuadsLeft -= ActualQuadCount; QuadOffset += (size_t)ActualQuadCount; diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index ea3e68a8b..fd1f0b511 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1220,7 +1220,7 @@ void CGraphics_Threaded::RenderBorderTileLines(int BufferContainerIndex, float * } } -void CGraphics_Threaded::RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum) +void CGraphics_Threaded::RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum, int QuadOffset) { if(QuadNum == 0) return; @@ -1229,6 +1229,7 @@ void CGraphics_Threaded::RenderQuadLayer(int BufferContainerIndex, SQuadRenderIn CCommandBuffer::SCommand_RenderQuadLayer Cmd; Cmd.m_State = m_State; Cmd.m_QuadNum = QuadNum; + Cmd.m_QuadOffset = QuadOffset; Cmd.m_BufferContainerIndex = BufferContainerIndex; Cmd.m_pQuadInfo = (SQuadRenderInfo *)AllocCommandBufferData(QuadNum * sizeof(SQuadRenderInfo)); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 78a0ce9e9..4676d3560 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -398,6 +398,7 @@ public: int m_BufferContainerIndex; SQuadRenderInfo *m_pQuadInfo; int m_QuadNum; + int m_QuadOffset; }; struct SCommand_RenderText : public SCommand @@ -1092,7 +1093,7 @@ public: void RenderTileLayer(int BufferContainerIndex, float *pColor, char **pOffsets, unsigned int *IndicedVertexDrawNum, size_t NumIndicesOffet) override; void RenderBorderTiles(int BufferContainerIndex, float *pColor, char *pIndexBufferOffset, float *pOffset, float *pDir, int JumpIndex, unsigned int DrawNum) override; void RenderBorderTileLines(int BufferContainerIndex, float *pColor, char *pIndexBufferOffset, float *pOffset, float *pDir, unsigned int IndexDrawNum, unsigned int RedrawNum) override; - void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum) override; + void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum, int QuadOffset) override; void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, float *pTextColor, float *pTextoutlineColor) override; // opengl 3.3 functions diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 493c671aa..bd175cbb4 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -253,7 +253,7 @@ public: virtual void RenderTileLayer(int BufferContainerIndex, float *pColor, char **pOffsets, unsigned int *IndicedVertexDrawNum, size_t NumIndicesOffet) = 0; virtual void RenderBorderTiles(int BufferContainerIndex, float *pColor, char *pIndexBufferOffset, float *pOffset, float *pDir, int JumpIndex, unsigned int DrawNum) = 0; virtual void RenderBorderTileLines(int BufferContainerIndex, float *pColor, char *pIndexBufferOffset, float *pOffset, float *pDir, unsigned int IndexDrawNum, unsigned int RedrawNum) = 0; - virtual void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum) = 0; + virtual void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, int QuadNum, int QuadOffset) = 0; virtual void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, float *pTextColor, float *pTextoutlineColor) = 0; // opengl 3.3 functions diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 8717718f5..4fffb5601 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -1388,6 +1388,8 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, static std::vector s_QuadRenderInfo; s_QuadRenderInfo.resize(pQuadLayer->m_NumQuads); + size_t QuadsRenderCount = 0; + size_t CurQuadOffset = 0; for(int i = 0; i < pQuadLayer->m_NumQuads; ++i) { CQuad *q = &pQuads[i]; @@ -1412,13 +1414,24 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, Rot = aChannels[2] / 180.0f * pi; } - SQuadRenderInfo &QInfo = s_QuadRenderInfo[i]; - mem_copy(QInfo.m_aColor, aColor, sizeof(aColor)); - QInfo.m_aOffsets[0] = OffsetX; - QInfo.m_aOffsets[1] = OffsetY; - QInfo.m_Rotation = Rot; + if(aColor[3] > 0) + { + SQuadRenderInfo &QInfo = s_QuadRenderInfo[QuadsRenderCount++]; + mem_copy(QInfo.m_aColor, aColor, sizeof(aColor)); + QInfo.m_aOffsets[0] = OffsetX; + QInfo.m_aOffsets[1] = OffsetY; + QInfo.m_Rotation = Rot; + } + else + { + // render quads of the current offset directly(cancel batching) + Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, &s_QuadRenderInfo[0], QuadsRenderCount, CurQuadOffset); + QuadsRenderCount = 0; + // since this quad is ignored, the offset is the next quad + CurQuadOffset = i + 1; + } } - Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, &s_QuadRenderInfo[0], pQuadLayer->m_NumQuads); + Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, &s_QuadRenderInfo[0], QuadsRenderCount, CurQuadOffset); } void CMapLayers::LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer) diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index e95292923..6812116df 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -115,6 +115,9 @@ void CRenderTools::ForceRenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags a = aChannels[3]; } + if(a <= 0) + continue; + bool Opaque = false; /* TODO: Analyze quadtexture if(a < 0.01f || (q->m_aColors[0].a < 0.01f && q->m_aColors[1].a < 0.01f && q->m_aColors[2].a < 0.01f && q->m_aColors[3].a < 0.01f))