More-efficient OpenGL ES 2.0 font textures
This commit is contained in:
parent
ede541db0a
commit
0423614dca
1 changed files with 1 additions and 31 deletions
|
@ -839,42 +839,19 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
return 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)
|
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);
|
unsigned char *buffer = (unsigned char*)malloc(destination_pitch * height);
|
||||||
|
|
||||||
switch (pixel_mode)
|
switch (pixel_mode)
|
||||||
{
|
{
|
||||||
case FONT_PIXEL_MODE_LCD:
|
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:
|
case FONT_PIXEL_MODE_GRAY:
|
||||||
for (unsigned int y = 0; y < height; ++y)
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
const unsigned char *source_pointer = pixels + y * pitch;
|
const unsigned char *source_pointer = pixels + y * pitch;
|
||||||
unsigned char *destination_pointer = buffer + y * destination_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);
|
memcpy(destination_pointer, source_pointer, width);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -886,13 +863,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width
|
||||||
unsigned char *destination_pointer = buffer + y * destination_pitch;
|
unsigned char *destination_pointer = buffer + y * destination_pitch;
|
||||||
|
|
||||||
for (unsigned int x = 0; x < width; ++x)
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
{
|
|
||||||
*destination_pointer++ = (*source_pointer++ ? 0xFF : 0);
|
*destination_pointer++ = (*source_pointer++ ? 0xFF : 0);
|
||||||
#ifdef USE_OPENGLES2
|
|
||||||
*destination_pointer++ = 0;
|
|
||||||
*destination_pointer++ = 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -907,8 +878,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width
|
||||||
if (pixel_mode == FONT_PIXEL_MODE_LCD)
|
if (pixel_mode == FONT_PIXEL_MODE_LCD)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||||
else
|
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_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
|
||||||
#else
|
#else
|
||||||
if (pixel_mode == FONT_PIXEL_MODE_LCD)
|
if (pixel_mode == FONT_PIXEL_MODE_LCD)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue