diff --git a/source/client/renderer/GameRenderer.cpp b/source/client/renderer/GameRenderer.cpp index 42fa5a8..5ca1ae2 100644 --- a/source/client/renderer/GameRenderer.cpp +++ b/source/client/renderer/GameRenderer.cpp @@ -13,6 +13,12 @@ #include "Frustum.hpp" #include "renderer/GL/GL.hpp" +// #define SHOW_VERTEX_COUNTER_GRAPHIC + +#if defined SHOW_VERTEX_COUNTER_GRAPHIC && !defined _DEBUG +#undef SHOW_VERTEX_COUNTER_GRAPHIC +#endif + static int t_keepHitResult; // that is its address in v0.1.1j int t_keepPic; @@ -686,8 +692,60 @@ void GameRenderer::render(float f) debugText << "\nentities: " << m_pMinecraft->m_pLevel->m_entities.size(); debugText << "\n" << m_pMinecraft->m_pLevelRenderer->gatherStats1(); } +#ifdef SHOW_VERTEX_COUNTER_GRAPHIC + extern int g_nVertices; // Tesselator.cpp + debugText << "\nverts: " << g_nVertices; + + static int vertGraph[200]; + memcpy(vertGraph, vertGraph + 1, sizeof(vertGraph) - sizeof(int)); + vertGraph [ (sizeof(vertGraph) / sizeof(vertGraph[0])) - 1 ] = g_nVertices; + + g_nVertices = 0; + + Tesselator& t = Tesselator::instance; + + int max = 0; + for (int i = 0; i < 200; i++) + max = std::max(max, vertGraph[i]); + + int maxht = 100; + int h = int(Minecraft::height * Gui::InvGuiScale); + + glDisable(GL_DEPTH_TEST); + glClear(GL_DEPTH_BUFFER_BIT); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + t.begin(); + t.color(1.0f, 1.0f, 1.0f, 0.15f); + t.vertex(000, h-maxht, 0); + t.vertex(000, h, 0); + t.vertex(200, h, 0); + t.vertex(200, h-maxht, 0); + t.draw(); + + t.begin(); + t.color(0.0f, 1.0f, 0.0f, 1.0f); + + for (int i = 0; i < 200 && max != 0; i++) + { + t.vertex(i + 0, h - (vertGraph[i] * maxht / max), 0); + t.vertex(i + 0, h - 0, 0); + t.vertex(i + 1, h - 0, 0); + t.vertex(i + 1, h - (vertGraph[i] * maxht / max), 0); + } + + t.draw(); + glEnable(GL_DEPTH_TEST); + + + m_pMinecraft->m_pFont->drawShadow(std::to_string(max), 200, h - maxht, 0xFFFFFF); +#endif m_pMinecraft->m_pFont->drawShadow(debugText.str(), 2, 2, 0xFFFFFF); + +#ifdef SHOW_VERTEX_COUNTER_GRAPHIC + g_nVertices = 0; +#endif } int timeMs = getTimeMs(); diff --git a/source/client/renderer/Tesselator.cpp b/source/client/renderer/Tesselator.cpp index 53f186b..210fbb5 100644 --- a/source/client/renderer/Tesselator.cpp +++ b/source/client/renderer/Tesselator.cpp @@ -14,6 +14,8 @@ int dword_2514A4 = 0; +int g_nVertices = 0, g_nTriangles = 0; + Tesselator Tesselator::instance; Tesselator::Tesselator(int allotedSize) @@ -33,7 +35,7 @@ Tesselator::Tesselator(int allotedSize) field_26 = false; m_bBlockColor = false; field_28 = false; - field_2C = 0; + m_nVertices = 0; field_30 = 0; field_34 = false; @@ -73,7 +75,7 @@ void Tesselator::clear() m_accessMode = 2; field_4 = 0; field_30 = 0; - field_2C = 0; + m_nVertices = 0; field_28 = 0; } @@ -158,7 +160,7 @@ void Tesselator::draw() field_3C = 0; xglBindBuffer(GL_ARRAY_BUFFER, m_pVBOs[field_3C]); - xglBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * field_2C, m_pVertices, m_accessMode == 1 ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); + xglBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * m_nVertices, m_pVertices, m_accessMode == 1 ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); if (m_bHaveTex) { @@ -211,9 +213,9 @@ RenderChunk Tesselator::end(int vboIdx) vboIdx = m_pVBOs[field_3C]; xglBindBuffer(GL_ARRAY_BUFFER, vboIdx); - xglBufferData(GL_ARRAY_BUFFER, sizeof (Vertex) * field_2C, m_pVertices, m_accessMode == 1 ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); + xglBufferData(GL_ARRAY_BUFFER, sizeof (Vertex) * m_nVertices, m_pVertices, m_accessMode == 1 ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); - field_48 += sizeof (Vertex) * field_2C; + field_48 += sizeof (Vertex) * m_nVertices; } clear(); @@ -273,13 +275,18 @@ void Tesselator::vertexUV(float x, float y, float z, float u, float v) void Tesselator::vertex(float x, float y, float z) { + if (m_nVertices >= m_maxVertices) { + LOG_W("Overwriting the vertex buffer! This chunk/entity won't show up"); + clear(); + } + field_30++; - if (m_drawArraysMode == GL_QUADS && !(field_30 << 30)) + if (m_drawArraysMode == GL_QUADS && (field_30 & 3) == 0) { - for (int v18 = 3; v18 != 1; v18--) + for (int idx = 3; idx != 1; idx--) { - // why the hell is it doing this - Vertex *pVert1 = &m_pVertices[field_2C - v18], *pVert2 = &m_pVertices[field_2C]; + // duplicate the last 2 added vertices in quad mode + Vertex *pVert1 = &m_pVertices[m_nVertices - idx], *pVert2 = &m_pVertices[m_nVertices]; if (m_bHaveTex) { pVert2->m_u = pVert1->m_u; @@ -296,11 +303,18 @@ void Tesselator::vertex(float x, float y, float z) pVert2->m_z = pVert1->m_z; field_4++; - field_2C++; + m_nVertices++; + +#ifdef _DEBUG + g_nVertices++; +#endif + + if (m_nVertices >= m_maxVertices) + return; } } - Vertex* pVert = &m_pVertices[field_2C]; + Vertex* pVert = &m_pVertices[m_nVertices]; if (m_bHaveTex) { pVert->m_u = m_nextVtxU; @@ -317,15 +331,7 @@ void Tesselator::vertex(float x, float y, float z) pVert->m_z = m_offsetZ + z; field_4++; - field_2C++; - - if (!(field_4 & 3) && field_2C >= m_maxVertices - 1) - { - for (int i = 0; i < 3; i++) - LOG_W("Overwriting the vertex buffer! This chunk/entity won't show up"); - - clear(); - } + m_nVertices++; } void Tesselator::voidBeginAndEndCalls(bool b) diff --git a/source/client/renderer/Tesselator.hpp b/source/client/renderer/Tesselator.hpp index 92fcb47..210888c 100644 --- a/source/client/renderer/Tesselator.hpp +++ b/source/client/renderer/Tesselator.hpp @@ -82,7 +82,7 @@ public: bool field_26; bool m_bBlockColor; bool field_28; - int field_2C; + int m_nVertices; int field_30; bool field_34;