shithub: cstory

Download patch

ref: 392d5898a3cd3d6ff8f25117402f1843dd3e4d6f
parent: e2b64df84a2abe8a838499918b5c5d44002883b7
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Sep 15 12:28:35 EDT 2020

Make GetVertexBufferSlot consistent

It would be nice keep this batching stuff in a common file
somewhere...

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -347,21 +347,23 @@
 // Vertex buffer management //
 //////////////////////////////
 
-static VertexBufferSlot* GetVertexBufferSlot(unsigned int slots_needed)
+static VertexBufferSlot* GetVertexBufferSlot(void)
 {
+	++current_vertex_buffer_slot;
+
 	// Check if buffer needs expanding
-	if (current_vertex_buffer_slot + slots_needed > local_vertex_buffer_size)
+	if (current_vertex_buffer_slot > local_vertex_buffer_size)
 	{
 		local_vertex_buffer_size = 1;
 
-		while (current_vertex_buffer_slot + slots_needed > local_vertex_buffer_size)
+		while (current_vertex_buffer_slot > local_vertex_buffer_size)
 			local_vertex_buffer_size <<= 1;
 
-		VertexBufferSlot *realloc_result = (VertexBufferSlot*)realloc(local_vertex_buffer, local_vertex_buffer_size * sizeof(VertexBufferSlot));
+		VertexBufferSlot *new_vertex_buffer = (VertexBufferSlot*)realloc(local_vertex_buffer, local_vertex_buffer_size * sizeof(VertexBufferSlot));
 
-		if (realloc_result != NULL)
+		if (new_vertex_buffer != NULL)
 		{
-			local_vertex_buffer = realloc_result;
+			local_vertex_buffer = new_vertex_buffer;
 		}
 		else
 		{
@@ -370,9 +372,7 @@
 		}
 	}
 
-	current_vertex_buffer_slot += slots_needed;
-
-	return &local_vertex_buffer[current_vertex_buffer_slot - slots_needed];
+	return &local_vertex_buffer[current_vertex_buffer_slot - 1];
 }
 
 static void FlushVertexBuffer(void)
@@ -646,7 +646,7 @@
 	// Draw framebuffer to screen
 	glBindTexture(GL_TEXTURE_2D, framebuffer.texture_id);
 
-	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
 
 	if (vertex_buffer_slot != NULL)
 	{
@@ -812,7 +812,7 @@
 	}
 
 	// Add data to the vertex queue
-	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
 
 	if (vertex_buffer_slot != NULL)
 	{
@@ -897,7 +897,7 @@
 	}
 
 	// Add data to the vertex queue
-	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
 
 	if (vertex_buffer_slot != NULL)
 	{
@@ -1027,7 +1027,7 @@
 void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
 {
 	// Add data to the vertex queue
-	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
 
 	if (vertex_buffer_slot != NULL)
 	{
--- a/src/Backends/Rendering/WiiU.cpp
+++ b/src/Backends/Rendering/WiiU.cpp
@@ -111,11 +111,11 @@
 		while (current_vertex_buffer_slot > local_vertex_buffer_size)
 			local_vertex_buffer_size <<= 1;
 
-		VertexBufferSlot *realloc_result = (VertexBufferSlot*)realloc(local_vertex_buffer, local_vertex_buffer_size * sizeof(VertexBufferSlot));
+		VertexBufferSlot *new_vertex_buffer = (VertexBufferSlot*)realloc(local_vertex_buffer, local_vertex_buffer_size * sizeof(VertexBufferSlot));
 
-		if (realloc_result != NULL)
+		if (new_vertex_buffer != NULL)
 		{
-			local_vertex_buffer = realloc_result;
+			local_vertex_buffer = new_vertex_buffer;
 		}
 		else
 		{