shithub: cstory

Download patch

ref: 0423614dcac843da6a9b5bbfb12de1ad53474e2b
parent: ede541db0a71d4a58b95c0af514304e36bd7e4c3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Jan 20 08:23:51 EST 2020

More-efficient OpenGL ES 2.0 font textures

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -839,11 +839,7 @@
 	if (glyph == NULL)
 		return NULL;
 
-#ifdef USE_OPENGLES2
-	const unsigned int destination_pitch = ((width * 3) + 3) & ~3;	// Round up to the nearest 4 (OpenGL needs this)
-#else
 	const unsigned int destination_pitch = (width + 3) & ~3;	// Round up to the nearest 4 (OpenGL needs this)
-#endif
 
 	unsigned char *buffer = (unsigned char*)malloc(destination_pitch * height);
 
@@ -850,31 +846,12 @@
 	switch (pixel_mode)
 	{
 		case FONT_PIXEL_MODE_LCD:
-			for (unsigned int y = 0; y < height; ++y)
-			{
-				const unsigned char *source_pointer = pixels + y * pitch;
-				unsigned char *destination_pointer = buffer + y * destination_pitch;
-				memcpy(destination_pointer, source_pointer, width);
-			}
-
-			break;
-
 		case FONT_PIXEL_MODE_GRAY:
 			for (unsigned int y = 0; y < height; ++y)
 			{
 				const unsigned char *source_pointer = pixels + y * pitch;
 				unsigned char *destination_pointer = buffer + y * destination_pitch;
-
-			#ifdef USE_OPENGLES2
-				for (unsigned int x = 0; x < width; ++x)
-				{
-					*destination_pointer++ = *source_pointer++;
-					*destination_pointer++ = 0;
-					*destination_pointer++ = 0;
-				}
-			#else
 				memcpy(destination_pointer, source_pointer, width);
-			#endif
 			}
 
 			break;
@@ -886,13 +863,7 @@
 				unsigned char *destination_pointer = buffer + y * destination_pitch;
 
 				for (unsigned int x = 0; x < width; ++x)
-				{
 					*destination_pointer++ = (*source_pointer++ ? 0xFF : 0);
-				#ifdef USE_OPENGLES2
-					*destination_pointer++ = 0;
-					*destination_pointer++ = 0;
-				#endif
-				}
 			}
 
 			break;
@@ -907,8 +878,7 @@
 	if (pixel_mode == FONT_PIXEL_MODE_LCD)
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
 	else
-		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);	// OpenGL ES 2.0 doesn't support GL_RED
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);
 #else
 	if (pixel_mode == FONT_PIXEL_MODE_LCD)
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
--