Fix major overstep with last commit
[vg.git] / src / vg / vg_ui.h
index 844194e73867e9e468c70d9b9fcb732d983e9e2d..4e09338dc2985149ea84f711e596433754ba37f4 100644 (file)
@@ -175,14 +175,14 @@ static ui_colourset ui_default_colours = {
 
 static ui_ctx ui_global_ctx;
 
-static void ui_context_free( ui_ctx *ctx )
+static void ui_context_vg_free( ui_ctx *ctx )
 {
        glDeleteVertexArrays( 1, &ctx->vao );
        glDeleteBuffers( 1, &ctx->vbo );
        glDeleteBuffers( 1, &ctx->ebo );
        
-       free( ctx->verts );
-       free( ctx->indices );
+       vg_free( ctx->verts );
+       vg_free( ctx->indices );
 }
 
 static int ui_init_context( ui_ctx *ctx, int index_buffer_size )
@@ -206,8 +206,7 @@ static int ui_init_context( ui_ctx *ctx, int index_buffer_size )
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, 
          index_buffer_size * sizeof( u16 ), NULL, GL_DYNAMIC_DRAW );
 
-   if( VG_CHECK_GL_ERR() )
-      goto il_fail_alloc_gpu;
+   VG_CHECK_GL_ERR();
 
    /* Set pointers */
    u32 const stride = sizeof( struct ui_vert );
@@ -232,17 +231,15 @@ static int ui_init_context( ui_ctx *ctx, int index_buffer_size )
          (void *)offsetof( struct ui_vert, clip ) );
    glEnableVertexAttribArray( 3 );
    
-   if( VG_CHECK_GL_ERR() )
-      goto il_fail_attributes;
-       
+   VG_CHECK_GL_ERR();
 
        /* Alloc RAM default context */
-   ctx->verts = (struct ui_vert *)malloc( 
+   ctx->verts = (struct ui_vert *)vg_alloc( 
          vertex_buffer_size * sizeof(struct ui_vert) );
    if( !ctx->verts )
       goto il_fail_alloc_verts;
 
-   ctx->indices = (u16*)malloc( index_buffer_size * sizeof(u16) );
+   ctx->indices = (u16*)vg_alloc( index_buffer_size * sizeof(u16) );
    if( !ctx->indices )
       goto il_fail_alloc_indices;
 
@@ -251,14 +248,12 @@ static int ui_init_context( ui_ctx *ctx, int index_buffer_size )
 
    return 1;
 
-                           free( ctx->indices );
+                           vg_free( ctx->indices );
                            ctx->indices = NULL;
 il_fail_alloc_indices:
-                           free( ctx->verts );
+                           vg_free( ctx->verts );
                            ctx->verts = NULL;
 il_fail_alloc_verts:
-il_fail_attributes:
-il_fail_alloc_gpu:
                            glDeleteBuffers( 1, &ctx->ebo );
                            glDeleteBuffers( 1, &ctx->vbo );
                            glDeleteVertexArrays( 1, &ctx->vao );
@@ -274,8 +269,7 @@ static int ui_default_init(void)
    };
 
    u32 pixels = 0, total = 256*256, data = 0;
-   u8 *image = malloc( total );
-   if( !image ) goto il_fail_alloc_image;
+   u8 *image = vg_alloc( total );
    
    while( pixels < total )
    {
@@ -293,18 +287,16 @@ static int ui_default_init(void)
    }
    
    glGenTextures( 1, &ui_glyph_texture );
-   if( !ui_glyph_texture ) goto il_fail_gen_texture;
-
    glBindTexture( GL_TEXTURE_2D, ui_glyph_texture );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, 256, 256, 0, 
          GL_RED, GL_UNSIGNED_BYTE, image );
+   
+   vg_free( image );
 
-   if( VG_CHECK_GL_ERR() ) goto il_fail_alloc_gpu;
+   VG_CHECK_GL_ERR();
    
    vg_tex2d_clamp();
    vg_tex2d_nearest();
-   
-   free( image );
        
        if( !ui_init_context( &ui_global_ctx, 20000 ) ) goto il_generic_fail;
    if( !vg_shader_compile( &_shader_ui ) ) goto il_shader_fail;
@@ -312,14 +304,9 @@ static int ui_default_init(void)
    return 1;
 
 il_shader_fail:
-il_fail_alloc_gpu:
 il_generic_fail:
    glDeleteTextures( 1, &ui_glyph_texture );
-
-il_fail_gen_texture:
-   free( image );
-
-il_fail_alloc_image:
+   vg_free( image );
    return 0;
 }
 
@@ -327,7 +314,7 @@ static void ui_default_free(void)
 {
    vg_free_shader( &_shader_ui );
    glDeleteTextures( 1, &ui_glyph_texture );
-       ui_context_free( &ui_global_ctx );
+       ui_context_vg_free( &ui_global_ctx );
 }
 
 static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect,