From 506b7b8d7c2e367d61ee92a77b54fb115a566173 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 17 Aug 2018 13:55:46 +0200 Subject: [PATCH] Corrected issue with batch overflows When a batch reach its vertex limit, a draw call is issued and batch restarted for refilling but if the draw call was issued for vertex data accumulated inside rlPushMatrix/rlPopMatrix, draw call was issued before the rlPopMatrix, consequently modelview matrix was not properly recovered before the draw call... obviously, it only happened the following draw calls, not the first one... Now it works ok but this system needs to reviewed, noticed and important frames drop when processing around 20 dynamic batch draw calls, it means filling MAX_QUADS_BATCH (8192) quads of data 20 times per frame, including data updating and sending for draw processing. Doing some maths, it means: Vertex data (float) -----> 8192 quads * 4 vertex * 3 comp * 4 byte = 393216 bytes Texcoords data (float) -> 8192 quads * 4 vertex * 2 comp * 4 byte = 262144 bytes Color data (uchar) -----> 8192 quads * 4 vertex * 4 comp * 1 byte = 131072 bytes Thats a total of 786432 bytes (0.75MB) sent to GPU 20 times per frame for processing... I'm testing in an Intel HD Graphics integrated, I imagine is too much data to be sent and and it causes stalls, so the frames drop... --- src/rlgl.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index d745b6ae6..75246cabf 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1213,21 +1213,30 @@ void rlEnd(void) // NOTE: This check is combined with usage of rlCheckBufferLimit() if ((lines.vCounter/2 >= (MAX_LINES_BATCH - 2)) || (triangles.vCounter/3 >= (MAX_TRIANGLES_BATCH - 3)) || - (quads.vCounter/4 >= (MAX_QUADS_BATCH - 4))) rlglDraw(); + (quads.vCounter/4 >= (MAX_QUADS_BATCH - 4))) + { + // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlglDraw(), + // we need to call rlPopMatrix() before to recover *currentMatrix (modelview) for the next forced draw call! + // Also noted that if we had multiple matrix pushed, it will require "stackCounter" pops before launching the draw + + // TODO: Undoubtely, current rlPushMatrix/rlPopMatrix should be redesigned... or removed... it's not working properly + + rlPopMatrix(); + rlglDraw(); + } } // Define one vertex (position) void rlVertex3f(float x, float y, float z) { - if (useTempBuffer) + // NOTE: Temp buffer is processed and resetted at rlEnd() + // Between rlBegin() and rlEnd() can not be more than TEMP_VERTEX_BUFFER_SIZE rlVertex3f() calls + if (useTempBuffer && (tempBufferCount < TEMP_VERTEX_BUFFER_SIZE)) { - if (tempBufferCount < TEMP_VERTEX_BUFFER_SIZE) - { - tempBuffer[tempBufferCount].x = x; - tempBuffer[tempBufferCount].y = y; - tempBuffer[tempBufferCount].z = z; - tempBufferCount++; - } + tempBuffer[tempBufferCount].x = x; + tempBuffer[tempBufferCount].y = y; + tempBuffer[tempBufferCount].z = z; + tempBufferCount++; } else { @@ -4321,9 +4330,6 @@ static void DrawBuffersDefault(void) quads.tcCounter = 0; quads.cCounter = 0; - tempBufferCount = 0; - useTempBuffer = false; - // Reset depth for next draw currentDepth = -1.0f;