cogl-atlas: Use _cogl_texture_driver_size_supported

Previously when creating a new rectangle map it would try increasingly
larger texture sizes until GL_MAX_TEXTURE_SIZE is reached. This is bad
because it queries state which should really be owned by the texture
driver. Also GL_MAX_TEXTURE_SIZE is often a conservative estimate so
larger texture sizes can be used if the proxy texture is queried
instead.
This commit is contained in:
Neil Roberts 2010-08-12 09:08:30 +01:00
parent 72029e14db
commit b9f9ea3a9c

View File

@ -34,6 +34,7 @@
#include "cogl-context.h" #include "cogl-context.h"
#include "cogl-texture-private.h" #include "cogl-texture-private.h"
#include "cogl-texture-2d-private.h" #include "cogl-texture-2d-private.h"
#include "cogl-texture-driver.h"
#include "cogl-material-opengl-private.h" #include "cogl-material-opengl-private.h"
#include "cogl-debug.h" #include "cogl-debug.h"
@ -315,23 +316,26 @@ _cogl_atlas_get_next_size (unsigned int *map_width,
} }
static CoglRectangleMap * static CoglRectangleMap *
_cogl_atlas_create_map (unsigned int map_width, _cogl_atlas_create_map (CoglPixelFormat format,
unsigned int map_width,
unsigned int map_height, unsigned int map_height,
unsigned int n_textures, unsigned int n_textures,
CoglAtlasRepositionData *textures) CoglAtlasRepositionData *textures)
{ {
GLint max_texture_size = 1024; GLenum gl_intformat;
GLenum gl_type;
GE( glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size) ); _cogl_pixel_format_to_gl (format,
&gl_intformat,
/* Sanity check that we're not going to get stuck in an infinite NULL, /* gl_format */
loop if the maximum texture size has the high bit set */ &gl_type);
if ((max_texture_size & (1 << (sizeof (GLint) * 8 - 2))))
max_texture_size >>= 1;
/* Keep trying increasingly larger atlases until we can fit all of /* Keep trying increasingly larger atlases until we can fit all of
the textures */ the textures */
while (map_width < max_texture_size && map_height < max_texture_size) while (_cogl_texture_driver_size_supported (GL_TEXTURE_2D,
gl_intformat,
gl_type,
map_width, map_height))
{ {
CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width, CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width,
map_height, map_height,
@ -524,7 +528,8 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas,
} }
} }
new_map = _cogl_atlas_create_map (map_width, map_height, new_map = _cogl_atlas_create_map (atlas->texture_format,
map_width, map_height,
data.n_textures, data.textures); data.n_textures, data.textures);
/* If we can't create a map with the texture then give up */ /* If we can't create a map with the texture then give up */