Allow resizing atlas directly

parent 3f24ebb6
## ExampleLib Example: an example of using Automake to link with a library
AC_INIT([freetype-gl], [1.8], [bernd@net2o.de], [freetype-gl for Linux/Android],
AC_INIT([freetype-gl], [1.9], [bernd@net2o.de], [freetype-gl for Linux/Android],
[https://github.com/forthy42/freetype-gl])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.10 -Wall no-define])
......
......@@ -297,3 +297,36 @@ texture_atlas_clear( texture_atlas_t * self )
vector_push_back( self->nodes, &node );
memset( self->data, 0, self->width*self->height*self->depth );
}
// -------------------------------------------- texture_atlas_enlarge_atlas ---
void texture_atlas_enlarge_texture ( texture_atlas_t* self, size_t width_new, size_t height_new)
{
assert(self);
//ensure size increased
assert(width_new >= self->width);
assert(height_new >= self->height);
assert(width_new + height_new > self->width + self->height);
size_t width_old = self->width;
size_t height_old = self->height;
//allocate new buffer
unsigned char* data_old = self->data;
self->data = calloc(1,width_new*height_new * sizeof(char)*self->depth);
//update atlas size
self->width = width_new;
self->height = height_new;
//add node reflecting the gained space on the right
if(width_new>width_old){
ivec3 node;
node.x = width_old - 1;
node.y = 1;
node.z = width_new - width_old;
vector_push_back(self->nodes, &node);
}
//copy over data from the old buffer, skipping first row and column because of the margin
size_t pixel_size = sizeof(char) * self->depth;
size_t old_row_size = width_old * pixel_size;
texture_atlas_set_region(self, 1, 1, width_old - 2, height_old - 2, data_old + old_row_size + pixel_size, old_row_size);
free(data_old);
}
......@@ -194,6 +194,15 @@ typedef struct texture_atlas_t
void
texture_atlas_clear( texture_atlas_t * self );
/**
* Enlarge a texture atlas
*
* @param self a texture atlas structure
* @param width_new new width
* @param height_new new height
*/
void
texture_atlas_enlarge_texture ( texture_atlas_t* self, size_t width_new, size_t height_new);
/** @} */
......
......@@ -1068,33 +1068,8 @@ texture_font_enlarge_texture( texture_font_t * self, size_t width_new,
size_t height_new)
{
assert(self);
assert(self->atlas);
//ensure size increased
assert(width_new >= self->atlas->width);
assert(height_new >= self->atlas->height);
assert(width_new + height_new > self->atlas->width + self->atlas->height);
texture_atlas_t* ta = self->atlas;
size_t width_old = ta->width;
size_t height_old = ta->height;
//allocate new buffer
unsigned char* data_old = ta->data;
ta->data = calloc(1,width_new*height_new * sizeof(char)*ta->depth);
//update atlas size
ta->width = width_new;
ta->height = height_new;
//add node reflecting the gained space on the right
if(width_new>width_old){
ivec3 node;
node.x = width_old - 1;
node.y = 1;
node.z = width_new - width_old;
vector_push_back(ta->nodes, &node);
}
//copy over data from the old buffer, skipping first row and column because of the margin
size_t pixel_size = sizeof(char) * ta->depth;
size_t old_row_size = width_old * pixel_size;
texture_atlas_set_region(ta, 1, 1, width_old - 2, height_old - 2, data_old + old_row_size + pixel_size, old_row_size);
free(data_old);
texture_atlas_enlarge_texture ( self->atlas, width_new, height_new);
}
// -------------------------------------------- texture_font_enlarge_atlas ---
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment