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 )
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 );
(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;
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 );
};
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 )
{
}
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;
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;
}
{
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,