Some graphic batching:

Speed up for displaying debugtext and envelopepreview
(This reduces the performance hit especially for the 'Show Info' mode in the editor)

Conflicts:

	src/engine/client/client.cpp
	src/game/editor/editor.cpp
	src/game/editor/editor.h
This commit is contained in:
BeaR 2012-10-14 14:04:48 +02:00 committed by oy
parent 0be51ca98a
commit d58afefaae
7 changed files with 124 additions and 88 deletions

View file

@ -137,14 +137,16 @@ void CGraph::Render(IGraphics *pGraphics, int Font, float x, float y, float w, f
pGraphics->LinesEnd(); pGraphics->LinesEnd();
pGraphics->TextureSet(Font); pGraphics->TextureSet(Font);
pGraphics->QuadsText(x+2, y+h-16, 16, 1,1,1,1, pDescription); pGraphics->QuadsBegin();
pGraphics->QuadsText(x+2, y+h-16, 16, pDescription);
char aBuf[32]; char aBuf[32];
str_format(aBuf, sizeof(aBuf), "%.2f", m_Max); str_format(aBuf, sizeof(aBuf), "%.2f", m_Max);
pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, 1,1,1,1, aBuf); pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, aBuf);
str_format(aBuf, sizeof(aBuf), "%.2f", m_Min); str_format(aBuf, sizeof(aBuf), "%.2f", m_Min);
pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, 1,1,1,1, aBuf); pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, aBuf);
pGraphics->QuadsEnd();
} }
@ -678,6 +680,7 @@ void CClient::DebugRender()
//m_pGraphics->BlendNormal(); //m_pGraphics->BlendNormal();
Graphics()->TextureSet(m_DebugFont); Graphics()->TextureSet(m_DebugFont);
Graphics()->MapScreen(0,0,Graphics()->ScreenWidth(),Graphics()->ScreenHeight()); Graphics()->MapScreen(0,0,Graphics()->ScreenWidth(),Graphics()->ScreenHeight());
Graphics()->QuadsBegin();
if(time_get()-LastSnap > time_freq()) if(time_get()-LastSnap > time_freq())
{ {
@ -699,7 +702,7 @@ void CClient::DebugRender()
mem_stats()->total_allocations, mem_stats()->total_allocations,
Graphics()->MemoryUsage()/1024, Graphics()->MemoryUsage()/1024,
(int)(1.0f/FrameTimeAvg + 0.5f)); (int)(1.0f/FrameTimeAvg + 0.5f));
Graphics()->QuadsText(2, 2, 16, 1,1,1,1, aBuffer); Graphics()->QuadsText(2, 2, 16, aBuffer);
{ {
@ -715,7 +718,7 @@ void CClient::DebugRender()
str_format(aBuffer, sizeof(aBuffer), "send: %3d %5d+%4d=%5d (%3d kbps) avg: %5d\nrecv: %3d %5d+%4d=%5d (%3d kbps) avg: %5d", str_format(aBuffer, sizeof(aBuffer), "send: %3d %5d+%4d=%5d (%3d kbps) avg: %5d\nrecv: %3d %5d+%4d=%5d (%3d kbps) avg: %5d",
SendPackets, SendBytes, SendPackets*42, SendTotal, (SendTotal*8)/1024, SendBytes/SendPackets, SendPackets, SendBytes, SendPackets*42, SendTotal, (SendTotal*8)/1024, SendBytes/SendPackets,
RecvPackets, RecvBytes, RecvPackets*42, RecvTotal, (RecvTotal*8)/1024, RecvBytes/RecvPackets); RecvPackets, RecvBytes, RecvPackets*42, RecvTotal, (RecvTotal*8)/1024, RecvBytes/RecvPackets);
Graphics()->QuadsText(2, 14, 16, 1,1,1,1, aBuffer); Graphics()->QuadsText(2, 14, 16, aBuffer);
} }
// render rates // render rates
@ -728,7 +731,7 @@ void CClient::DebugRender()
{ {
str_format(aBuffer, sizeof(aBuffer), "%4d %20s: %8d %8d %8d", i, GameClient()->GetItemName(i), m_SnapshotDelta.GetDataRate(i)/8, m_SnapshotDelta.GetDataUpdates(i), str_format(aBuffer, sizeof(aBuffer), "%4d %20s: %8d %8d %8d", i, GameClient()->GetItemName(i), m_SnapshotDelta.GetDataRate(i)/8, m_SnapshotDelta.GetDataUpdates(i),
(m_SnapshotDelta.GetDataRate(i)/m_SnapshotDelta.GetDataUpdates(i))/8); (m_SnapshotDelta.GetDataRate(i)/m_SnapshotDelta.GetDataUpdates(i))/8);
Graphics()->QuadsText(2, 100+y*12, 16, 1,1,1,1, aBuffer); Graphics()->QuadsText(2, 100+y*12, 16, aBuffer);
y++; y++;
} }
} }
@ -736,7 +739,8 @@ void CClient::DebugRender()
str_format(aBuffer, sizeof(aBuffer), "pred: %d ms", str_format(aBuffer, sizeof(aBuffer), "pred: %d ms",
(int)((m_PredictedTime.Get(Now)-m_GameTime.Get(Now))*1000/(float)time_freq())); (int)((m_PredictedTime.Get(Now)-m_GameTime.Get(Now))*1000/(float)time_freq()));
Graphics()->QuadsText(2, 70, 16, 1,1,1,1, aBuffer); Graphics()->QuadsText(2, 70, 16, aBuffer);
Graphics()->QuadsEnd();
// render graphs // render graphs
if(g_Config.m_DbgGraphs) if(g_Config.m_DbgGraphs)

View file

@ -629,13 +629,10 @@ void CGraphics_Threaded::QuadsDrawFreeform(const CFreeformItem *pArray, int Num)
AddVertices(4*Num); AddVertices(4*Num);
} }
void CGraphics_Threaded::QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pText)
{ {
float StartX = x; float StartX = x;
QuadsBegin();
SetColor(r,g,b,a);
while(*pText) while(*pText)
{ {
char c = *pText; char c = *pText;
@ -659,8 +656,6 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, float r, float
x += Size/2; x += Size/2;
} }
} }
QuadsEnd();
} }
int CGraphics_Threaded::IssueInit() int CGraphics_Threaded::IssueInit()

View file

@ -419,7 +419,7 @@ public:
virtual void QuadsDraw(CQuadItem *pArray, int Num); virtual void QuadsDraw(CQuadItem *pArray, int Num);
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); virtual void QuadsDrawTL(const CQuadItem *pArray, int Num);
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num); virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num);
virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText); virtual void QuadsText(float x, float y, float Size, const char *pText);
virtual void Minimize(); virtual void Minimize();
virtual void Maximize(); virtual void Maximize();

View file

@ -120,7 +120,7 @@ public:
: m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {} : m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {}
}; };
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) = 0; virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
struct CColorVertex struct CColorVertex
{ {

View file

@ -1408,79 +1408,94 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
Graphics()->QuadsDraw(&QuadItem, 1); Graphics()->QuadsDraw(&QuadItem, 1);
} }
void CEditor::DoQuadEnvelopes(CQuad *pQuad, int Index, int TexID) void CEditor::DoQuadEnvelopes(CQuad *pQuad, int Num, int TexID)
{ {
CEnvelope *pEnvelope = 0x0; CEnvelope **apEnvelope = new CEnvelope*[Num]();
if(pQuad->m_PosEnv >= 0 && pQuad->m_PosEnv < m_Map.m_lEnvelopes.size()) for(int i = 0; i < Num; i++)
pEnvelope = m_Map.m_lEnvelopes[pQuad->m_PosEnv]; {
if (!pEnvelope) if((m_ShowEnvelopePreview == 1 && pQuad[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2)
return; if(pQuad[i].m_PosEnv >= 0 && pQuad[i].m_PosEnv < m_Map.m_lEnvelopes.size())
apEnvelope[i] = m_Map.m_lEnvelopes[pQuad[i].m_PosEnv];
//QuadParams }
CPoint *pPoints = pQuad->m_aPoints;
//Draw Lines //Draw Lines
Graphics()->TextureSet(-1); Graphics()->TextureSet(-1);
Graphics()->LinesBegin(); Graphics()->LinesBegin();
Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f); Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f);
for(int i = 0; i < pEnvelope->m_lPoints.size()-1; i++) for(int j = 0; j < Num; j++)
{ {
float OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); if(!apEnvelope[j])
float OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); continue;
//QuadParams
CPoint *pPoints = pQuad[j].m_aPoints;
for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++)
{
float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]);
float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]);
vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY);
OffsetX = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[0]); OffsetX = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[0]);
OffsetY = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[1]); OffsetY = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[1]);
vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY);
IGraphics::CLineItem Line = IGraphics::CLineItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y); IGraphics::CLineItem Line = IGraphics::CLineItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y);
Graphics()->LinesDraw(&Line, 1); Graphics()->LinesDraw(&Line, 1);
} }
}
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Graphics()->LinesEnd(); Graphics()->LinesEnd();
//Draw Quads //Draw Quads
for(int i = 0; i < pEnvelope->m_lPoints.size(); i++) Graphics()->TextureSet(Texture);
{
Graphics()->TextureSet(TexID);
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
for(int j = 0; j < Num; j++)
{
if(!apEnvelope[j])
continue;
//QuadParams
CPoint *pPoints = pQuad[j].m_aPoints;
for(int i = 0; i < apEnvelope[j]->m_lPoints.size(); i++)
{
//Calc Env Position //Calc Env Position
float OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]);
float OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]);
float Rot = fx2f(pEnvelope->m_lPoints[i].m_aValues[2])/360.0f*pi*2; float Rot = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[2])/360.0f*pi*2;
//Set Colours //Set Colours
float Alpha = (m_SelectedQuadEnvelope == pQuad->m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f; float Alpha = (m_SelectedQuadEnvelope == pQuad[j].m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f;
IGraphics::CColorVertex aArray[4] = { IGraphics::CColorVertex aArray[4] = {
IGraphics::CColorVertex(0, pQuad->m_aColors[0].r, pQuad->m_aColors[0].g, pQuad->m_aColors[0].b, Alpha), IGraphics::CColorVertex(0, pQuad[j].m_aColors[0].r, pQuad[j].m_aColors[0].g, pQuad[j].m_aColors[0].b, Alpha),
IGraphics::CColorVertex(1, pQuad->m_aColors[1].r, pQuad->m_aColors[1].g, pQuad->m_aColors[1].b, Alpha), IGraphics::CColorVertex(1, pQuad[j].m_aColors[1].r, pQuad[j].m_aColors[1].g, pQuad[j].m_aColors[1].b, Alpha),
IGraphics::CColorVertex(2, pQuad->m_aColors[2].r, pQuad->m_aColors[2].g, pQuad->m_aColors[2].b, Alpha), IGraphics::CColorVertex(2, pQuad[j].m_aColors[2].r, pQuad[j].m_aColors[2].g, pQuad[j].m_aColors[2].b, Alpha),
IGraphics::CColorVertex(3, pQuad->m_aColors[3].r, pQuad->m_aColors[3].g, pQuad->m_aColors[3].b, Alpha)}; IGraphics::CColorVertex(3, pQuad[j].m_aColors[3].r, pQuad[j].m_aColors[3].g, pQuad[j].m_aColors[3].b, Alpha)};
Graphics()->SetColorVertex(aArray, 4); Graphics()->SetColorVertex(aArray, 4);
//Rotation //Rotation
if(Rot != 0) if(Rot != 0)
{ {
static CPoint aRotated[4]; static CPoint aRotated[4];
aRotated[0] = pQuad->m_aPoints[0]; aRotated[0] = pQuad[j].m_aPoints[0];
aRotated[1] = pQuad->m_aPoints[1]; aRotated[1] = pQuad[j].m_aPoints[1];
aRotated[2] = pQuad->m_aPoints[2]; aRotated[2] = pQuad[j].m_aPoints[2];
aRotated[3] = pQuad->m_aPoints[3]; aRotated[3] = pQuad[j].m_aPoints[3];
pPoints = aRotated; pPoints = aRotated;
Rotate(&pQuad->m_aPoints[4], &aRotated[0], Rot); Rotate(&pQuad[j].m_aPoints[4], &aRotated[0], Rot);
Rotate(&pQuad->m_aPoints[4], &aRotated[1], Rot); Rotate(&pQuad[j].m_aPoints[4], &aRotated[1], Rot);
Rotate(&pQuad->m_aPoints[4], &aRotated[2], Rot); Rotate(&pQuad[j].m_aPoints[4], &aRotated[2], Rot);
Rotate(&pQuad->m_aPoints[4], &aRotated[3], Rot); Rotate(&pQuad[j].m_aPoints[4], &aRotated[3], Rot);
} }
//Set Texture Coords //Set Texture Coords
Graphics()->QuadsSetSubsetFree( Graphics()->QuadsSetSubsetFree(
fx2f(pQuad->m_aTexcoords[0].x), fx2f(pQuad->m_aTexcoords[0].y), fx2f(pQuad[j].m_aTexcoords[0].x), fx2f(pQuad[j].m_aTexcoords[0].y),
fx2f(pQuad->m_aTexcoords[1].x), fx2f(pQuad->m_aTexcoords[1].y), fx2f(pQuad[j].m_aTexcoords[1].x), fx2f(pQuad[j].m_aTexcoords[1].y),
fx2f(pQuad->m_aTexcoords[2].x), fx2f(pQuad->m_aTexcoords[2].y), fx2f(pQuad[j].m_aTexcoords[2].x), fx2f(pQuad[j].m_aTexcoords[2].y),
fx2f(pQuad->m_aTexcoords[3].x), fx2f(pQuad->m_aTexcoords[3].y) fx2f(pQuad[j].m_aTexcoords[3].x), fx2f(pQuad[j].m_aTexcoords[3].y)
); );
//Set Quad Coords & Draw //Set Quad Coords & Draw
@ -1490,14 +1505,34 @@ void CEditor::DoQuadEnvelopes(CQuad *pQuad, int Index, int TexID)
fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY,
fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY);
Graphics()->QuadsDrawFreeform(&Freeform, 1); Graphics()->QuadsDrawFreeform(&Freeform, 1);
Graphics()->QuadsEnd();
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
DoQuadEnvPoint(pQuad, Index, i);
Graphics()->QuadsEnd();
} }
}
Graphics()->QuadsEnd();
Graphics()->TextureClear();
Graphics()->QuadsBegin();
// Draw QuadPoints
for(int j = 0; j < Num; j++)
{
if(!apEnvelope[j])
continue;
//QuadParams
CPoint *pPoints = pQuad[j].m_aPoints;
for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++)
{
float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]);
float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]);
vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY);
OffsetX = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[0]);
OffsetY = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[1]);
vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY);
DoQuadEnvPoint(&pQuad[j], j, i);
}
}
Graphics()->QuadsEnd();
} }
void CEditor::DoQuadEnvPoint(CQuad *pQuad, int QIndex, int PIndex) void CEditor::DoQuadEnvPoint(CQuad *pQuad, int QIndex, int PIndex)
@ -2093,12 +2128,12 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size()) if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size())
TexID = m_Map.m_lImages[pLayer->m_Image]->m_TexID; TexID = m_Map.m_lImages[pLayer->m_Image]->m_TexID;
for(int i = 0; i < pLayer->m_lQuads.size(); i++) /*for(int i = 0; i < pLayer->m_lQuads.size(); i++)
{ {
if((m_ShowEnvelopePreview == 1 && pLayer->m_lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) if((m_ShowEnvelopePreview == 1 && pLayer->m_lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2)
DoQuadEnvelopes(&pLayer->m_lQuads[i], i, TexID); DoQuadEnvelopes(&pLayer->m_lQuads[i], i, TexID);
} }*/
DoQuadEnvelopes(&pLayer->m_lQuads[0], pLayer->m_lQuads.size(), TexID);
m_ShowEnvelopePreview = 0; m_ShowEnvelopePreview = 0;
} }

View file

@ -761,7 +761,7 @@ public:
vec4 ButtonColorMul(const void *pID); vec4 ButtonColorMul(const void *pID);
void DoQuadEnvelopes(CQuad *pQuad, int Index, int TexID = -1); void DoQuadEnvelopes(CQuad *pQuad, int Num, int TexID = -1);
void DoQuadEnvPoint(CQuad *pQuad, int QIndex, int pIndex); void DoQuadEnvPoint(CQuad *pQuad, int QIndex, int pIndex);
void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v); void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v);

View file

@ -338,6 +338,7 @@ void CLayerTiles::ShowInfo()
float ScreenX0, ScreenY0, ScreenX1, ScreenY1; float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
Graphics()->TextureSet(m_pEditor->Client()->GetDebugFont()); Graphics()->TextureSet(m_pEditor->Client()->GetDebugFont());
Graphics()->QuadsBegin();
int StartY = max(0, (int)(ScreenY0/32.0f)-1); int StartY = max(0, (int)(ScreenY0/32.0f)-1);
int StartX = max(0, (int)(ScreenX0/32.0f)-1); int StartX = max(0, (int)(ScreenX0/32.0f)-1);
@ -352,17 +353,18 @@ void CLayerTiles::ShowInfo()
{ {
char aBuf[64]; char aBuf[64];
str_format(aBuf, sizeof(aBuf), "%i", m_pTiles[c].m_Index); str_format(aBuf, sizeof(aBuf), "%i", m_pTiles[c].m_Index);
m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, 1,1,1,1, aBuf); m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, aBuf);
char aFlags[4] = { m_pTiles[c].m_Flags&TILEFLAG_VFLIP ? 'V' : ' ', char aFlags[4] = { m_pTiles[c].m_Flags&TILEFLAG_VFLIP ? 'V' : ' ',
m_pTiles[c].m_Flags&TILEFLAG_HFLIP ? 'H' : ' ', m_pTiles[c].m_Flags&TILEFLAG_HFLIP ? 'H' : ' ',
m_pTiles[c].m_Flags&TILEFLAG_ROTATE? 'R' : ' ', m_pTiles[c].m_Flags&TILEFLAG_ROTATE? 'R' : ' ',
0}; 0};
m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, 1,1,1,1, aFlags); m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, aFlags);
} }
x += m_pTiles[c].m_Skip; x += m_pTiles[c].m_Skip;
} }
Graphics()->QuadsEnd();
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
} }