Don't render fully transparent quads

This commit is contained in:
Jupeyy 2020-12-29 14:31:42 +01:00
parent 505656313c
commit 288a18fa95
6 changed files with 31 additions and 11 deletions

View file

@ -3329,6 +3329,8 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderQuadLayer(const CCommandBuff
int QuadsLeft = pCommand->m_QuadNum; int QuadsLeft = pCommand->m_QuadNum;
size_t QuadOffset = 0; 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]; vec4 aColors[m_MaxQuadsPossible];
vec2 aOffsets[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->SetUniformVec4(pProgram->m_LocColors, ActualQuadCount, (float *)aColors);
pProgram->SetUniformVec2(pProgram->m_LocOffsets, ActualQuadCount, (float *)aOffsets); pProgram->SetUniformVec2(pProgram->m_LocOffsets, ActualQuadCount, (float *)aOffsets);
pProgram->SetUniform(pProgram->m_LocRotations, ActualQuadCount, (float *)aRotations); pProgram->SetUniform(pProgram->m_LocRotations, ActualQuadCount, (float *)aRotations);
pProgram->SetUniform(pProgram->m_LocQuadOffset, (int)QuadOffset); pProgram->SetUniform(pProgram->m_LocQuadOffset, (int)(QuadOffset + QuadOffsetExtra));
glDrawElements(GL_TRIANGLES, ActualQuadCount * 6, GL_UNSIGNED_INT, (void *)(QuadOffset * 6 * sizeof(unsigned int))); glDrawElements(GL_TRIANGLES, ActualQuadCount * 6, GL_UNSIGNED_INT, (void *)((QuadOffset + QuadOffsetExtra) * 6 * sizeof(unsigned int)));
QuadsLeft -= ActualQuadCount; QuadsLeft -= ActualQuadCount;
QuadOffset += (size_t)ActualQuadCount; QuadOffset += (size_t)ActualQuadCount;

View file

@ -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) if(QuadNum == 0)
return; return;
@ -1229,6 +1229,7 @@ void CGraphics_Threaded::RenderQuadLayer(int BufferContainerIndex, SQuadRenderIn
CCommandBuffer::SCommand_RenderQuadLayer Cmd; CCommandBuffer::SCommand_RenderQuadLayer Cmd;
Cmd.m_State = m_State; Cmd.m_State = m_State;
Cmd.m_QuadNum = QuadNum; Cmd.m_QuadNum = QuadNum;
Cmd.m_QuadOffset = QuadOffset;
Cmd.m_BufferContainerIndex = BufferContainerIndex; Cmd.m_BufferContainerIndex = BufferContainerIndex;
Cmd.m_pQuadInfo = (SQuadRenderInfo *)AllocCommandBufferData(QuadNum * sizeof(SQuadRenderInfo)); Cmd.m_pQuadInfo = (SQuadRenderInfo *)AllocCommandBufferData(QuadNum * sizeof(SQuadRenderInfo));

View file

@ -398,6 +398,7 @@ public:
int m_BufferContainerIndex; int m_BufferContainerIndex;
SQuadRenderInfo *m_pQuadInfo; SQuadRenderInfo *m_pQuadInfo;
int m_QuadNum; int m_QuadNum;
int m_QuadOffset;
}; };
struct SCommand_RenderText : public SCommand 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 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 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 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; void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, float *pTextColor, float *pTextoutlineColor) override;
// opengl 3.3 functions // opengl 3.3 functions

View file

@ -253,7 +253,7 @@ public:
virtual void RenderTileLayer(int BufferContainerIndex, float *pColor, char **pOffsets, unsigned int *IndicedVertexDrawNum, size_t NumIndicesOffet) = 0; 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 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 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; virtual void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, float *pTextColor, float *pTextoutlineColor) = 0;
// opengl 3.3 functions // opengl 3.3 functions

View file

@ -1388,6 +1388,8 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer,
static std::vector<SQuadRenderInfo> s_QuadRenderInfo; static std::vector<SQuadRenderInfo> s_QuadRenderInfo;
s_QuadRenderInfo.resize(pQuadLayer->m_NumQuads); s_QuadRenderInfo.resize(pQuadLayer->m_NumQuads);
size_t QuadsRenderCount = 0;
size_t CurQuadOffset = 0;
for(int i = 0; i < pQuadLayer->m_NumQuads; ++i) for(int i = 0; i < pQuadLayer->m_NumQuads; ++i)
{ {
CQuad *q = &pQuads[i]; CQuad *q = &pQuads[i];
@ -1412,13 +1414,24 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer,
Rot = aChannels[2] / 180.0f * pi; Rot = aChannels[2] / 180.0f * pi;
} }
SQuadRenderInfo &QInfo = s_QuadRenderInfo[i]; if(aColor[3] > 0)
mem_copy(QInfo.m_aColor, aColor, sizeof(aColor)); {
QInfo.m_aOffsets[0] = OffsetX; SQuadRenderInfo &QInfo = s_QuadRenderInfo[QuadsRenderCount++];
QInfo.m_aOffsets[1] = OffsetY; mem_copy(QInfo.m_aColor, aColor, sizeof(aColor));
QInfo.m_Rotation = Rot; 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) void CMapLayers::LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer)

View file

@ -115,6 +115,9 @@ void CRenderTools::ForceRenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags
a = aChannels[3]; a = aChannels[3];
} }
if(a <= 0)
continue;
bool Opaque = false; bool Opaque = false;
/* TODO: Analyze quadtexture /* 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)) 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))