Commits

Alex Szpakowski committed 69b0b4e

Reduced the RAM and VRAM space taken up by TrueType font glyphs by 1/2.

Comments (0)

Files changed (5)

src/modules/font/GlyphData.cpp

 	{
 		switch (f)
 		{
-		case GlyphData::FORMAT_LUMINANCE_ALPHA:
-			data = new unsigned char[metrics.width * metrics.height * 2];
+		case GlyphData::FORMAT_ALPHA:
+			data = new unsigned char[metrics.width * metrics.height];
 			break;
 		case GlyphData::FORMAT_RGBA:
 		default:
 {
 	switch (format)
 	{
-	case GlyphData::FORMAT_LUMINANCE_ALPHA:
-		return getWidth() * getHeight() * 2;
+	case GlyphData::FORMAT_ALPHA:
+		return getWidth() * getHeight();
 		break;
 	case GlyphData::FORMAT_RGBA:
 	default:
 
 StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
 {
-	{"luminance alpha", GlyphData::FORMAT_LUMINANCE_ALPHA},
+	{"alpha", GlyphData::FORMAT_ALPHA},
 	{"rgba", GlyphData::FORMAT_RGBA},
 };
 

src/modules/font/GlyphData.h

 
 	enum Format
 	{
-		FORMAT_LUMINANCE_ALPHA,
+		FORMAT_ALPHA,
 		FORMAT_RGBA,
 		FORMAT_MAX_ENUM
 	};

src/modules/font/freetype/TrueTypeRasterizer.cpp

 	glyphMetrics.width = bitmap.width;
 	glyphMetrics.advance = face->glyph->metrics.horiAdvance >> 6;
 
-	GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_LUMINANCE_ALPHA);
+	GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_ALPHA);
 
 	int size = bitmap.rows * bitmap.width;
-	unsigned char *dst = (unsigned char *) glyphData->getData();
 
-	// Note that bitmap.buffer contains only luminosity. We copy that single 
-	// value to our luminosity-alpha format.
-	for (int i = 0; i < size; i++)
-	{
-		dst[2*i] = 255;
-		dst[2*i+1] = bitmap.buffer[i];
-	}
+	// We treat the luminance of the FreeType bitmap as alpha in the GlyphData.
+	memcpy(glyphData->getData(), bitmap.buffer, size);
 
 	// Having copied the data over, we can destroy the glyph
 	FT_Done_Glyph(ftglyph);

src/modules/graphics/opengl/Font.cpp

 	try
 	{
 		gd = r->getGlyphData(32);
-		type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
+		type = (gd->getFormat() == love::font::GlyphData::FORMAT_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
 
 		loadVolatile();
 	}
 
 bool Font::initializeTexture(GLenum format)
 {
-	GLint internalformat = (format == GL_LUMINANCE_ALPHA) ? GL_LUMINANCE8_ALPHA8 : GL_RGBA8;
+	GLint internalformat = (format == GL_ALPHA) ? GL_ALPHA8 : GL_RGBA8;
 
 	// clear errors before initializing
 	while (glGetError() != GL_NO_ERROR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-	GLenum format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
+	GLenum format = (type == FONT_TRUETYPE ? GL_ALPHA : GL_RGBA);
 
 	// Initialize the texture, attempting smaller sizes if initialization fails.
 	bool initialized = false;
 	}
 	
 	// Fill the texture with transparent black.
-	std::vector<GLubyte> emptyData(textureWidth * textureHeight * (type == FONT_TRUETYPE ? 2 : 4), 0);
+	std::vector<GLubyte> emptyData(textureWidth * textureHeight * (type == FONT_TRUETYPE ? 1 : 4), 0);
 	glTexSubImage2D(GL_TEXTURE_2D,
 					0,
 					0, 0,
 						textureX,
 						textureY,
 						w, h,
-						(type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA),
+						(type == FONT_TRUETYPE ? GL_ALPHA : GL_RGBA),
 						GL_UNSIGNED_BYTE,
 						gd->getData());
 

src/modules/graphics/opengl/Graphics.cpp

 	glLoadIdentity();
 
 	// Set pixel row alignment
-	glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
 	// Reload all volatile objects.
 	if (!Volatile::loadAll())