shithub: cstory

Download patch

ref: 23156d38de052b1480bed45468ec019e6b5bbea8
parent: b080954a716f1f04dc98787d9e3164acf039b992
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Sep 7 21:55:57 EDT 2020

Optimise OpenGL renderer a little

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -84,7 +84,6 @@
 
 static RenderBackend_Surface framebuffer;
 
-static unsigned char glyph_colour_channels[3];
 static RenderBackend_Surface *glyph_destination_surface;
 
 static int actual_screen_width;
@@ -920,25 +919,17 @@
 {
 	(void)atlas;
 
-	if (destination_surface == NULL)
-		return;
-
-	glyph_destination_surface = destination_surface;
-
-	memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels));
-}
-
-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)
-{
 	static unsigned char last_red;
 	static unsigned char last_green;
 	static unsigned char last_blue;
 
-	if (glyph_destination_surface == NULL)
+	if (destination_surface == NULL)
 		return;
 
+	glyph_destination_surface = destination_surface;
+
 	// Flush vertex data if a context-change is needed
-	if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != glyph_destination_surface->texture_id || last_source_texture != atlas->texture_id || last_red != glyph_colour_channels[0] || last_green != glyph_colour_channels[1] || last_blue != glyph_colour_channels[2])
+	if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != glyph_destination_surface->texture_id || last_source_texture != atlas->texture_id || last_red != colour_channels[0] || last_green != colour_channels[1] || last_blue != colour_channels[2])
 	{
 		FlushVertexBuffer();
 
@@ -945,12 +936,12 @@
 		last_render_mode = MODE_DRAW_GLYPH;
 		last_destination_texture = glyph_destination_surface->texture_id;
 		last_source_texture = atlas->texture_id;
-		last_red = glyph_colour_channels[0];
-		last_green = glyph_colour_channels[1];
-		last_blue = glyph_colour_channels[2];
+		last_red = colour_channels[0];
+		last_green = colour_channels[1];
+		last_blue = colour_channels[2];
 
 		glUseProgram(program_glyph);
-		glUniform4f(program_glyph_uniform_colour, glyph_colour_channels[0] / 255.0f, glyph_colour_channels[1] / 255.0f, glyph_colour_channels[2] / 255.0f, 1.0f);
+		glUniform4f(program_glyph_uniform_colour, colour_channels[0] / 255.0f, colour_channels[1] / 255.0f, colour_channels[2] / 255.0f, 1.0f);
 
 		// Point our framebuffer to the destination texture
 		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glyph_destination_surface->texture_id, 0);
@@ -963,6 +954,12 @@
 
 		glBindTexture(GL_TEXTURE_2D, atlas->texture_id);
 	}
+}
+
+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)
+{
+	if (glyph_destination_surface == NULL)
+		return;
 
 	// Add data to the vertex queue
 	VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);