some stuff vg3
authorhgn <hgodden00@gmail.com>
Thu, 26 Jun 2025 18:05:47 +0000 (19:05 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 26 Jun 2025 18:05:47 +0000 (19:05 +0100)
vg_build_utils_shader.h
vg_db.c
vg_engine.c
vg_log.c
vg_log.h

index 235c67c04f6f156b8a9d3f87800a184c35692642..8376490bc4a96d338d12be3cf2216ba60979e93d 100644 (file)
@@ -24,6 +24,7 @@ struct
           code_function_body;
 
    bool init;
+   const char *preprocessed_dir;
 }
 static vg_shaderbuild;
 
@@ -72,12 +73,10 @@ static void parse_uniform_name( char *start, struct uniform *uf )
       }
    }
 
-   snprintf( uf->uniform_code_id, 64, "_uniform_%s_%s",
-             vg_shaderbuild.current_shader_name,
-             uf->name );
+   snprintf( uf->uniform_code_id, 64, "_uniform_%s_%s", vg_shaderbuild.current_shader_name, uf->name );
 }
 
-static int compile_subshader( vg_str *str, char *name )
+static int compile_subshader( vg_str *str, char *name, const char *path_write_full )
 {
    char error[256];
    char *full = stb_include_file( name, "", vg_shaderbuild.shader_dir, error );
@@ -89,6 +88,20 @@ static int compile_subshader( vg_str *str, char *name )
    }
    else
    {
+      if( path_write_full )
+      {
+         FILE *fp = fopen( path_write_full, "w" );
+         if( !fp )
+         {
+            free( full );
+            fprintf( stderr, "Cant open %s\n", path_write_full );
+            return 0;
+         }
+         fputs( "#version 330 core\n", fp );
+         fputs( full, fp );
+         fclose( fp );
+      }
+
       vg_strcatf( str, "{\n"
                        ".orig_file = \"%s\",\n" 
                        ".static_src = \n",
@@ -107,10 +120,7 @@ static int compile_subshader( vg_str *str, char *name )
             if( !strncmp(start,"uniform",7) )
             {
                start += 8;
-               struct uniform *uf = 
-                  &vg_shaderbuild.uniform_buffer[ 
-                        vg_shaderbuild.uniform_count ++ ];
-
+               struct uniform *uf = &vg_shaderbuild.uniform_buffer[ vg_shaderbuild.uniform_count ++ ];
                parse_uniform_name( start, uf );
             }
 
@@ -197,15 +207,22 @@ int vg_build_shader( char *src_vert, /* path/to/vert.vs    */
                        "   .name = \"%s\",\n"
                        "   .vs = \n", name, name, name );
 
+   char pcpath[ 260 ];
+   if( vg_shaderbuild.preprocessed_dir )
+      snprintf( pcpath, sizeof(pcpath), "%s/%s.vert", vg_shaderbuild.preprocessed_dir, name );
+
    vg_shaderbuild.uniform_count = 0;
-   if( !compile_subshader( c_body, src_vert ) )
+   if( !compile_subshader( c_body, src_vert, vg_shaderbuild.preprocessed_dir? pcpath: NULL ) )
    {
       fclose( header );
       vg_fatal_error( "Failed to assemble vertex source code" );
    }
 
+   if( vg_shaderbuild.preprocessed_dir )
+      snprintf( pcpath, sizeof(pcpath), "%s/%s.frag", vg_shaderbuild.preprocessed_dir, name );
+
    vg_strcatf( c_body, "\n   .fs = \n" );
-   if( !compile_subshader( c_body, src_frag ) )
+   if( !compile_subshader( c_body, src_frag, vg_shaderbuild.preprocessed_dir? pcpath: NULL ) )
    {
       fclose( header );
       vg_fatal_error( "Failed to assemble fragment source code" );
diff --git a/vg_db.c b/vg_db.c
index f4e3a764d6b0ab66dbee08dd247f79d995848a02..27e71a7f19588ed71f07fd129dd96f85aef0d412 100644 (file)
--- a/vg_db.c
+++ b/vg_db.c
@@ -130,6 +130,7 @@ static void vg_db_commit( vg_db *db, FILE *fwal )
    if( last_good_log != last_good_checkpoint )
       vg_info( "Rewinding took %u writes back..\n", writes_away );
 
+   fflush( db->fp );
    free( temp_page );
 }
 
@@ -396,6 +397,7 @@ void vg_db_checkpoint( vg_db *db )
 
    if( db->wal_writes > 1000 )
    {
+      fflush( db->fp_wal );
       vg_db_commit( db, db->fp_wal );
       fclose( db->fp_wal );
       remove( db->wal_path );
index a95b60ccf120564f089b4f9c597c88ea5851b643..db310fcdb1db385a9311c49084bba814ca589506 100644 (file)
@@ -724,6 +724,13 @@ void vg_init( int argc, const char *argv[], const char *window_name )
    if( (arg = vg_long_opt_arg( "load-step-delay", "Loader step delay (ms)" )) )
       vg.load_step_delay = atoi(arg);
 
+   if( (arg = vg_long_opt_arg( "log", "Log output to text file (without console colours)" )) )
+   {
+      vg_log.plain_output_file = fopen( arg, "w" );
+      if( !vg_log.plain_output_file )
+         vg_error( "Could not open '%s' for logging.\n", arg );
+   }
+
    vg.window_name = window_name;
 }
 
index bb8183046bc163b229341737de17038681181d04..914bb94637e2261ceb41388640ea2764a5f92f1a 100644 (file)
--- a/vg_log.c
+++ b/vg_log.c
@@ -64,8 +64,17 @@ void _vg_logx_va( FILE *file, const char *location, const char *prefix,
 #endif
 
        char buffer[4096], line[96];
-
    vsnprintf( buffer, VG_ARRAY_LEN(buffer), fmt, args );
+
+#ifdef VG_ENGINE
+   if( vg_log.plain_output_file )
+   {
+      fputs( prefix, vg_log.plain_output_file );
+      fputs( " | ",  vg_log.plain_output_file );
+      fputs( buffer, vg_log.plain_output_file );
+   }
+#endif
+
    int line_length = snprintf( line, 90, "%s%7s" KNRM "|%s ", colour, prefix, colour );
 
    for( u32 i=0; i<VG_ARRAY_LEN(buffer); i ++ )
@@ -130,7 +139,6 @@ void vg_logx( FILE *file,
              const char *colour,
              const char *fmt, ... )
 {
-
    va_list args;
    va_start( args, fmt );
    _vg_logx_va( file, 
index a3a80f3e16eda2814da850bf724d4f74c507df82..f0582fe3829a69aec4a43f319ab89f06ce1437c2 100644 (file)
--- a/vg_log.h
+++ b/vg_log.h
@@ -55,6 +55,8 @@ struct vg_log
    char log[64][96];
    u32  log_line_count, log_line_current;
 
+   FILE *plain_output_file;
+
    bool initialized;
 #ifdef VG_MULTITHREAD
  #ifdef VG_ENGINE