summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2018-08-17 13:55:46 +0200
committerRay <[email protected]>2018-08-17 13:55:46 +0200
commit506b7b8d7c2e367d61ee92a77b54fb115a566173 (patch)
treec4c4ab160f17ba0589c3309dafbb585861ea260a
parent732b775a1dd5d6829d856eba9d5a374c2dad1cee (diff)
downloadraylib-506b7b8d7c2e367d61ee92a77b54fb115a566173.tar.gz
raylib-506b7b8d7c2e367d61ee92a77b54fb115a566173.zip
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...
-rw-r--r--src/rlgl.h30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/rlgl.h b/src/rlgl.h
index d745b6ae..75246cab 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;