now thats a lot of damage!
[vg.git] / src / vg / vg_loader.h
index c7522b0addb811e3695be881d955149587bcfdb2..23d35b9a455fec7a4806c29e7ca043ffb3fc74a7 100644 (file)
@@ -58,14 +58,14 @@ static struct vg_loader
       void (*fn_free)(void *);
       void *data;
    }
-   *step_buffer;
-   u32 step_count, step_cap, step_action;
+   step_buffer[16];
+   u32 step_count, step_action;
 
    GLuint vao, vbo;
 }
 vg_loader;
 
-static int vg_loader_init(void)
+VG_STATIC void vg_loader_init(void)
 {
    float quad[] = { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                     0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
@@ -76,23 +76,16 @@ static int vg_loader_init(void)
    glBindBuffer( GL_ARRAY_BUFFER, vg_loader.vbo );
    glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW );
    glBindVertexArray( vg_loader.vao );
-   glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 
-         sizeof(float)*2, (void*)0 );
+   glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, sizeof(float)*2, (void*)0 );
    glEnableVertexAttribArray( 0 );
 
    VG_CHECK_GL_ERR();
 
    if( !vg_shader_compile( &_shader_loader ) )
-   {
-      glDeleteVertexArrays( 1, &vg_loader.vao );
-      glDeleteBuffers( 1, &vg_loader.vbo );
-      return 0;
-   }
-
-   return 1;
+      vg_fatal_exit_loop( "failed to compile shader" );
 }
 
-static void vg_loader_free(void)
+VG_STATIC void vg_loader_free(void)
 {
    vg_info( "vg_loader_free\n" );
    glDeleteVertexArrays( 1, &vg_loader.vao );
@@ -107,11 +100,10 @@ static void vg_loader_free(void)
       step->fn_free( step->data );
    }
 
-   vg_free( vg_loader.step_buffer );
    vg_info( "done\n" );
 }
 
-static float hue_to_rgb( float p, float q, float t )
+VG_STATIC float hue_to_rgb( float p, float q, float t )
 {
    if(t < 0.0f) t += 1.0f;
    if(t > 1.0f) t -= 1.0f;
@@ -121,9 +113,9 @@ static float hue_to_rgb( float p, float q, float t )
    return p;
 }
 
-static void vg_render_log(void)
+VG_STATIC void vg_render_log(void)
 {
-   ui_begin( &ui_global_ctx, vg.window_x, vg.window_y );
+   ui_begin( vg.window_x, vg.window_y );
 
    int const fh = 14;
    int lines_screen_max = ((vg.window_y/fh)-2),
@@ -132,10 +124,10 @@ static void vg_render_log(void)
 
        int ptr = vg_log.buffer_line_current;
        
-       ui_global_ctx.cursor[0] = 0;
-       ui_global_ctx.cursor[1] = lines_to_draw*fh;
-   ui_global_ctx.cursor[3] = fh;
-       ui_fill_x( &ui_global_ctx );
+       vg_uictx.cursor[0] = 0;
+       vg_uictx.cursor[1] = lines_to_draw*fh;
+   vg_uictx.cursor[3] = fh;
+       ui_fill_x();
 
    for( int i=0; i<lines_to_draw; i ++ )
    {
@@ -144,17 +136,15 @@ static void vg_render_log(void)
       if( ptr < 0 )
          ptr = vg_list_size( vg_log.buffer )-1;
       
-      ui_text( &ui_global_ctx, ui_global_ctx.cursor, 
-            vg_log.buffer[ptr], vg_console.scale, 0 );
-
-      ui_global_ctx.cursor[1] -= fh*vg_console.scale;
+      ui_text( vg_uictx.cursor, vg_log.buffer[ptr], 1, 0 );
+      vg_uictx.cursor[1] -= fh;
    }
 
-   ui_resolve( &ui_global_ctx );
-   ui_draw( &ui_global_ctx, NULL );
+   ui_resolve();
+   ui_draw( NULL );
 }
 
-static void vg_loader_render(void)
+VG_STATIC void vg_loader_render(void)
 {
    glViewport( 0,0, vg.window_x, vg.window_y );
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
@@ -171,9 +161,9 @@ static void vg_loader_render(void)
 }
 
 
-static void vg_load_full(void);
+VG_STATIC void vg_load_full(void);
 
-static void vg_loader_thread(void * nothing)
+VG_STATIC void vg_loader_thread(void * nothing)
 {
    vg_thread_info.gl_context_level = 0;
    vg_thread_info.purpose = k_thread_purpose_loader;
@@ -184,31 +174,30 @@ static void vg_loader_thread(void * nothing)
    vg_semaphore_post( &vg.sem_loader );
 }
 
-static void vg_loader_start(void)
+VG_STATIC void vg_loader_start(void)
 {
    vg_semaphore_wait( &vg.sem_loader );
    vg_thread_run( vg_loader_thread, NULL );
 }
 
-static void vg_free_libc_malloced( void *data )
+/* this is maybe probably unused now */
+VG_STATIC void vg_free_libc_malloced( void *data )
 {
-   vg_free( data );
+   free( data );
 }
 
-static void vg_loader_push_free_step( struct loader_free_step step )
+VG_STATIC void vg_loader_push_free_step( struct loader_free_step step )
 {
-   vg_loader.step_buffer = 
-      buffer_reserve( vg_loader.step_buffer, vg_loader.step_count, 
-                              &vg_loader.step_cap, 1, 
-                              sizeof( struct loader_free_step ) );
+   if( vg_loader.step_count == vg_list_size(vg_loader.step_buffer) )
+      vg_fatal_exit_loop( "Too many free steps" );
 
    vg_loader.step_buffer[ vg_loader.step_count ++ ] = step;
 }
 
 /*
- * Schedule something to be ran now, freed later
+ * Schedule something to be ran now, freed later. Checks in with engine status
  */
-static void vg_loader_highwater( void( *fn_load )(void), 
+VG_STATIC void vg_loader_highwater( void( *fn_load )(void), 
                                  void( *fn_free )(void *), void *data )
 {
    if( fn_load )