string ops
[vg.git] / vg_lines.h
index 9300445a8b35dc21816a76571ba10256e7d55cdd..5c88d9bc8f40c57f9e7838a3c5b722c0cefa302b 100644 (file)
@@ -19,12 +19,10 @@ typedef v3f line_co;
 #define VG__CYAN  0xffffff00
 #define VG__NONE  0x00000000
 
-static struct vg_shader _shader_lines = 
-{
+static struct vg_shader _shader_lines = {
    .name = "[vg] lines",
    .link = NULL,
-   .vs = 
-   {
+   .vs = {
       .orig_file = NULL,
       .static_src = 
 
@@ -41,8 +39,7 @@ static struct vg_shader _shader_lines =
        "       gl_Position = vert_pos;"
        "}"
    },
-   .fs = 
-   {
+   .fs = {
       .orig_file = NULL,
       .static_src = 
 
@@ -57,14 +54,11 @@ static struct vg_shader _shader_lines =
    }
 };
 
-
-struct
-{
+struct{
    u32 draw,
        allow_input;
        
-   struct vg_lines_vert
-   {
+   struct vg_lines_vert{
       v3f co;
       u32 colour;
    } 
@@ -74,71 +68,63 @@ struct
 }
 static vg_lines;
 
-VG_STATIC void vg_lines_init(void)
+VG_STATIC void async_vg_lines_init( void *payload, u32 payload_size )
 {
-   vg_info( "vg_lines_init\n" );
-
-   vg_var_push( (struct vg_var){
-      .name = "vg_lines",
-      .data = &vg_lines.draw,
-      .data_type = k_var_dtype_i32,
-      .opt_i32 = { .min=0, .max=1, .clamp=1 },
-      .persistent = 1
-   });
+   glGenVertexArrays( 1, &vg_lines.vao );
+   glGenBuffers( 1, &vg_lines.vbo );
+   glBindVertexArray( vg_lines.vao );
+   glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
    
-   vg_shader_register( &_shader_lines );
-
-   vg_acquire_thread_sync();
-   {
-      glGenVertexArrays( 1, &vg_lines.vao );
-      glGenBuffers( 1, &vg_lines.vbo );
-      glBindVertexArray( vg_lines.vao );
-      glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
-      
-      u32 size = 50000 * sizeof( struct vg_lines_vert );
-
-      vg_lines.vertex_buffer = 
-         vg_create_linear_allocator(vg_mem.rtmemory, size, VG_MEMORY_REALTIME);
-      
-      glBufferData( GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW );
-      glBindVertexArray( vg_lines.vao );
-      VG_CHECK_GL_ERR();
-
-      /* Pointers */
-      glVertexAttribPointer( 
-         0, 
-         3,
-         GL_FLOAT, 
-         GL_FALSE, 
-         sizeof( struct vg_lines_vert ), 
-         (void *)0 
-      );
-      glEnableVertexAttribArray( 0 );
-      
-      glVertexAttribPointer( 
-         1, 
-         4, 
-         GL_UNSIGNED_BYTE, 
-         GL_TRUE, 
-         sizeof( struct vg_lines_vert ), 
-         (void*)(offsetof( struct vg_lines_vert, colour ))
-      );
-      glEnableVertexAttribArray( 1 );
-      
-      VG_CHECK_GL_ERR();
-      vg_success( "done\n" );
-   }
+   u32 size = 50000 * sizeof( struct vg_lines_vert );
 
-   vg_release_thread_sync();
+   vg_lines.vertex_buffer = 
+      vg_create_linear_allocator(vg_mem.rtmemory, size, VG_MEMORY_REALTIME);
+   
+   glBufferData( GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW );
+   glBindVertexArray( vg_lines.vao );
+   VG_CHECK_GL_ERR();
+
+   /* Pointers */
+   glVertexAttribPointer( 
+      0, 
+      3,
+      GL_FLOAT, 
+      GL_FALSE, 
+      sizeof( struct vg_lines_vert ), 
+      (void *)0 
+   );
+   glEnableVertexAttribArray( 0 );
+   
+   glVertexAttribPointer( 
+      1, 
+      4, 
+      GL_UNSIGNED_BYTE, 
+      GL_TRUE, 
+      sizeof( struct vg_lines_vert ), 
+      (void*)(offsetof( struct vg_lines_vert, colour ))
+   );
+   glEnableVertexAttribArray( 1 );
+   
+   VG_CHECK_GL_ERR();
    vg_lines.allow_input = 1;
 }
 
-VG_STATIC void vg_lines_drawall( float* projection )
+VG_STATIC void vg_lines_init(void)
+{
+   vg_async_call( async_vg_lines_init, NULL, 0 );
+
+   vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32, 
+                       VG_VAR_CHEAT );
+   vg_shader_register( &_shader_lines );
+
+}
+
+VG_STATIC void vg_lines_drawall( void )
 {
        glUseProgram( _shader_lines.id );
 
-   glUniformMatrix4fv
-   ( glGetUniformLocation( _shader_lines.id, "uPv" ), 1, GL_FALSE, projection );
+   glUniformMatrix4fv( glGetUniformLocation( _shader_lines.id, "uPv" ), 
+     1, GL_FALSE, (float *)vg.pv );
 
        glBindVertexArray( vg_lines.vao );
        glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
@@ -163,6 +149,8 @@ VG_STATIC void vg_line2( line_co from, line_co to, u32 fc, u32 tc )
    if( !vg_lines.allow_input )
       return;
 
+   return;
+
    u32 size = 2 * sizeof(struct vg_lines_vert);
        struct vg_lines_vert *v = vg_linear_alloc( vg_lines.vertex_buffer, size );
 
@@ -181,14 +169,12 @@ VG_STATIC void vg_line( line_co from, line_co to, u32 colour )
 VG_STATIC void line_tangent_basis( v3f n, v3f tx, v3f ty )
 {
    /* Compute tangent basis (box2d) */
-   if( fabsf( n[0] ) >= 0.57735027f )
-   {
+   if( fabsf( n[0] ) >= 0.57735027f ){
       tx[0] =  n[1];
       tx[1] = -n[0];
       tx[2] =  0.0f;
    }
-   else
-   {
+   else{
       tx[0] =  0.0f;
       tx[1] =  n[2];
       tx[2] = -n[1];