shithub: cstory

Download patch

ref: 4afe7f4b119ae70ed902e0bad830ce7be91d275e
parent: 5712c4ad6360c363c83bbf2f3cbc01890e2368dc
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Aug 9 12:25:36 EDT 2019

Use orphaning to slightly speed up rendering GPU-side

For some reason CPU usage is still double that of the SDLTexture
backend (SDL2 uses OpenGL 2.1, with glEnable/glDisable-style
immediate mode).

If I downgrade to OpenGL 2.1, and use VBO-less glDrawArrays, I get
great performance. I just wish I knew what the AMD driver is doing
that's so much faster.

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -255,7 +255,6 @@
 	// Set up Vertex Buffer Object
 	glGenBuffers(1, &vertex_buffer_id);
 	glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id);
-	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), NULL, GL_STREAM_DRAW);
 
 	// Set up the vertex attributes
 	glEnableVertexAttribArray(1);
@@ -348,7 +347,7 @@
 	vertex_buffer.vertexes[3].x = -1.0f;
 	vertex_buffer.vertexes[3].y = 1.0f;
 
-	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 	SDL_GL_SwapWindow(window);
@@ -462,7 +461,7 @@
 	vertex_buffer.vertexes[3].x = vertex_left;
 	vertex_buffer.vertexes[3].y = vertex_bottom;
 
-	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 }
 
@@ -511,7 +510,7 @@
 	vertex_buffer.vertexes[3].x = vertex_left;
 	vertex_buffer.vertexes[3].y = vertex_bottom;
 
-	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer.vertexes), &vertex_buffer);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 }
 
@@ -641,7 +640,7 @@
 	vertex_buffer.vertexes[3].x = vertex_left;
 	vertex_buffer.vertexes[3].y = vertex_bottom;
 
-	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_buffer), &vertex_buffer);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
 
 	if (glyph->pixel_mode == FONT_PIXEL_MODE_LCD)
 	{