From 51da0964d6a27b2ac9c1c1f5c256292fb4ecc0f1 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 26 Jun 2025 19:05:47 +0100 Subject: [PATCH] some stuff --- vg_build_utils_shader.h | 37 +++++++++++++++++++++++++++---------- vg_db.c | 2 ++ vg_engine.c | 7 +++++++ vg_log.c | 12 ++++++++++-- vg_log.h | 2 ++ 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/vg_build_utils_shader.h b/vg_build_utils_shader.h index 235c67c..8376490 100644 --- a/vg_build_utils_shader.h +++ b/vg_build_utils_shader.h @@ -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 f4e3a76..27e71a7 100644 --- 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 ); diff --git a/vg_engine.c b/vg_engine.c index a95b60c..db310fc 100644 --- a/vg_engine.c +++ b/vg_engine.c @@ -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; } diff --git a/vg_log.c b/vg_log.c index bb81830..914bb94 100644 --- 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