REVIEWED: RLGL.State.vertexCounter (See detailed comment)

`RLGL.State.vertexCounter` is a generic counter and it's reused for all `rlRenderBatch`, actually, once render batch is filled, required vertex count is provided through the draw calls, so, the total accumulated count of vertices is not directly registered inside the rlRenderBatch.

`RLGL.State.vertexCounter` keeps that count but one possible improvement(?) could be moving the `vertexCounter` inside `rlRenderBatch` to always keep a register of the total accumulated vertices in that batch (despite that info is provided by the accumulated `draws[i].vertexCount`.

Simplifying, `RLGL.State.vertexCounter = SUM(draws[i].vertexCount)`

The decision to move the counter out of `rlVertexBuffer` is to keep only the data that I think should belong to `rlVertexBuffer` and make it more generic, aligned with raylib `Mesh` structure.

The decision to not add it to `rlRenderBatch` is because it could contain multiple `rlVertexBuffer` and it would be confusing (because it would only register the count of the last filled one).
This commit is contained in:
raysan5 2021-10-06 11:44:57 +02:00
parent 8d7f97ee04
commit 8722ff7043

View file

@ -847,10 +847,10 @@ typedef struct rlglData {
rlRenderBatch defaultBatch; // Default internal render batch
struct {
int vertexCounter; // Vertex counter to process (and draw) from full buffer
float texcoordx, texcoordy; // Current active texture coordinate
float normalx, normaly, normalz; // Current active normal
unsigned char colorr, colorg, colorb, colora; // Current active color
int vertexCounter; // Current active render batch vertex counter (generic, used for all batches)
float texcoordx, texcoordy; // Current active texture coordinate (added on glVertex*())
float normalx, normaly, normalz; // Current active normal (added on glVertex*())
unsigned char colorr, colorg, colorb, colora; // Current active color (added on glVertex*())
int currentMatrixMode; // Current matrix mode
Matrix *currentMatrix; // Current matrix pointer
@ -2468,7 +2468,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
// Reset batch buffers
//------------------------------------------------------------------------------------------------------------
// Reset vertex counters for next frame
// Reset vertex counter for next frame
RLGL.State.vertexCounter = 0;
// Reset depth for next draw
@ -2534,7 +2534,7 @@ bool rlCheckRenderBatchLimit(int vCount)
overflow = true;
rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside
// restore state of last batch so we can continue adding vertices
// Restore state of last batch so we can continue adding vertices
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = currentMode;
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = currentTexture;
}