mirror of
https://github.com/brl/mutter.git
synced 2024-11-10 07:56:14 -05:00
cogl-atlas: Verify that the chosen initial size is supported
CoglAtlas chooses a fairly large default initial size of either 512x512 or 1024x1024 depending on the texture format. There is a chance that this size will not be supported on some platforms which would be catastrophic for the glyph cache because it would mean that it would always fail to put any glyphs in the cache so text wouldn't work. To fix this the atlas code now checks whether the chosen initial size is supported by the texture driver and if not it will get halved until it is supported.
This commit is contained in:
parent
b9f9ea3a9c
commit
db0c15aee8
@ -315,6 +315,43 @@ _cogl_atlas_get_next_size (unsigned int *map_width,
|
||||
*map_height <<= 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_get_initial_size (CoglPixelFormat format,
|
||||
unsigned int *map_width,
|
||||
unsigned int *map_height)
|
||||
{
|
||||
unsigned int size;
|
||||
GLenum gl_intformat;
|
||||
GLenum gl_type;
|
||||
|
||||
_cogl_pixel_format_to_gl (format,
|
||||
&gl_intformat,
|
||||
NULL, /* gl_format */
|
||||
&gl_type);
|
||||
|
||||
/* At least on Intel hardware, the texture size will be rounded up
|
||||
to at least 1MB so we might as well try to aim for that as an
|
||||
initial minimum size. If the format is only 1 byte per pixel we
|
||||
can use 1024x1024, otherwise we'll assume it will take 4 bytes
|
||||
per pixel and use 512x512. */
|
||||
if (_cogl_get_format_bpp (format) == 1)
|
||||
size = 1024;
|
||||
else
|
||||
size = 512;
|
||||
|
||||
/* Some platforms might not support this large size so we'll
|
||||
decrease the size until it can */
|
||||
while (size > 1 &&
|
||||
!_cogl_texture_driver_size_supported (GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
size, size))
|
||||
size >>= 1;
|
||||
|
||||
*map_width = size;
|
||||
*map_height = size;
|
||||
}
|
||||
|
||||
static CoglRectangleMap *
|
||||
_cogl_atlas_create_map (CoglPixelFormat format,
|
||||
unsigned int map_width,
|
||||
@ -510,23 +547,8 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas,
|
||||
_cogl_atlas_get_next_size (&map_width, &map_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* At least on Intel hardware, the texture size will be rounded
|
||||
up to at least 1MB so we might as well try to aim for that as
|
||||
an initial minimum size. If the format is only 1 byte per
|
||||
pixel we can use 1024x1024, otherwise we'll assume it will
|
||||
take 4 bytes per pixel and use 512x512. */
|
||||
if (_cogl_get_format_bpp (atlas->texture_format) == 1)
|
||||
{
|
||||
map_width = 1024;
|
||||
map_height = 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
map_width = 512;
|
||||
map_height = 512;
|
||||
}
|
||||
}
|
||||
_cogl_atlas_get_initial_size (atlas->texture_format,
|
||||
&map_width, &map_height);
|
||||
|
||||
new_map = _cogl_atlas_create_map (atlas->texture_format,
|
||||
map_width, map_height,
|
||||
|
Loading…
Reference in New Issue
Block a user