From: hgn Date: Sat, 25 Oct 2025 01:08:06 +0000 (+0100) Subject: smol skinning changes and cvars X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=29a606f75aeb6c87214b404f7e19d94e1a6a7b3e;p=vg.git smol skinning changes and cvars --- diff --git a/source/console/console_system.c b/source/console/console_system.c index c30470f..7545f76 100644 --- a/source/console/console_system.c +++ b/source/console/console_system.c @@ -1,10 +1,23 @@ #include "foundation.h" #include "console_system.h" -struct console_command +struct console_item { const c8 *alias; - i32 (*fn)( struct console_arguments *args ); + enum console_item_type + { + k_console_item_ccmd, + k_console_item_cvar_i32, + k_console_item_cvar_f32 + } + type; + + union + { + i32 (*fn)( struct console_arguments *args ); + i32 *_i32; + f32 *_f32; + }; }; #include "generated/console.c" @@ -63,7 +76,7 @@ void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed ) args.count = 0; u32 temp_frame = _start_temporary_frame(); - struct console_command *target_command = NULL; + struct console_item *target_command = NULL; // TODO: warning if we put to many or to few arguments & required ones. for( u32 i=0; ialias, 0, command+start, length ) ) { target_command = cmd; @@ -104,7 +117,45 @@ void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed ) } if( target_command ) - target_command->fn( &args ); + { + if( target_command->type == k_console_item_ccmd ) + target_command->fn( &args ); + else + { + const c8 *set_to = console_get_argument( &args, 0 ); + if( set_to ) + { + struct stream string; + stream_open_buffer_read( &string, set_to, buffer_last_index( set_to, 0, 0 ), 0 ); + + if( target_command->type == k_console_item_cvar_f32 ) + { + f64 f; + if( string_parse_f64( &string, &f ) == k_string_parse_ok ) + *target_command->_f32 = f; + } + if( target_command->type == k_console_item_cvar_i32 ) + { + i64 i; + if( string_parse_i64( &string, &i ) == k_string_parse_ok ) + *target_command->_i32 = i; + } + + $log( $info, {"Value set"} ); + } + else + { + if( target_command->type == k_console_item_cvar_f32 ) + { + $log( $info, {"The value of "}, {target_command->alias}, {"(f32) is: "}, $float( *target_command->_f32 ) ); + } + else if( target_command->type == k_console_item_cvar_i32 ) + { + $log( $info, {"The value of "}, {target_command->alias}, {"(i32) is: "}, $signed( *target_command->_i32 ) ); + } + } + } + } _end_temporary_frame( temp_frame ); } diff --git a/source/engine/engine.kv b/source/engine/engine.kv index c29fc62..93bebf3 100644 --- a/source/engine/engine.kv +++ b/source/engine/engine.kv @@ -296,14 +296,26 @@ shader } } } - -cvar +shader { - name test - type u32 - default 5 - cheat 1 - description "This is just a test variable!" + name blit_colour + subshader + { + type vertex + add shaders/blit_colour.vs + } + + subshader + { + type fragment + add shaders/blit_colour.fs + + uniform + { + type vec4 + alias uColour + } + } } hook @@ -311,7 +323,6 @@ hook event START function "_shaders_compile" } -} @@ -337,8 +348,8 @@ hook } cvar { - name debug_lines - type u32 + name vg_lines_enable + type i32 default 0 cheat 1 description "Show line debuggers" diff --git a/source/engine/metascene.h b/source/engine/metascene.h index a82063d..505d353 100644 --- a/source/engine/metascene.h +++ b/source/engine/metascene.h @@ -171,8 +171,7 @@ enum anim_apply k_anim_apply_defer_ik, k_anim_apply_deffered_only, k_anim_apply_absolute -} -anim_apply; +}; void skeleton_apply_pose( struct ms_skeleton *skele, struct ms_keyframe *pose, enum anim_apply passtype, f32 final_mtx[][4][3] ); void skeleton_decompose_mtx_absolute( struct ms_skeleton *skele, struct ms_keyframe *anim, f32 final_mtx[][4][3] ); diff --git a/source/engine/model.c b/source/engine/model.c index 5e34c1c..f0ac2bb 100644 --- a/source/engine/model.c +++ b/source/engine/model.c @@ -547,3 +547,14 @@ i32 vg_model_get_submesh_index( struct vg_model *model, const c8 *mesh_name ) return -1; return mesh->submesh_start; } + +void vg_model_bind_texture( struct vg_model *model, GLuint target, u32 tex_id, u32 slot ) +{ + if( tex_id ) + { + union mdl_texture *mdl_tex = &model->textures[ tex_id -1 ]; + vg_tex_bind( target, &mdl_tex->tex, slot ); + } + else + vg_tex_bind( target, NULL, slot ); +} diff --git a/source/engine/model.h b/source/engine/model.h index fe90a95..b8dfe43 100644 --- a/source/engine/model.h +++ b/source/engine/model.h @@ -267,6 +267,7 @@ struct stream *vg_model_stream_pack_stream( struct vg_model_stream_context *ctx, /* Rendering operations * ----------------------------------------------------------------------------------------------------------------- */ void vg_model_bind_mesh( struct vg_model *model ); +void vg_model_bind_texture( struct vg_model *model, GLuint target, u32 tex_id, u32 slot ); void vg_model_draw_elements( u32 start, u32 count ); void vg_model_draw_submesh( struct mdl_submesh *sm ); i32 vg_model_get_mesh_index( struct vg_model *model, const c8 *name ); diff --git a/source/engine/shaders/blit_colour.fs b/source/engine/shaders/blit_colour.fs new file mode 100644 index 0000000..070cb51 --- /dev/null +++ b/source/engine/shaders/blit_colour.fs @@ -0,0 +1,6 @@ +out vec4 FragColor; + +void main() +{ + FragColor = uColour; +} diff --git a/source/engine/shaders/blit_colour.vs b/source/engine/shaders/blit_colour.vs new file mode 100644 index 0000000..beb5f34 --- /dev/null +++ b/source/engine/shaders/blit_colour.vs @@ -0,0 +1,6 @@ +layout (location=0) in vec2 a_co; + +void main() +{ + gl_Position = vec4(a_co*2.0-1.0,0.0,1.0); +} diff --git a/source/engine/vg_engine.c b/source/engine/vg_engine.c index 493f911..1c3db8b 100644 --- a/source/engine/vg_engine.c +++ b/source/engine/vg_engine.c @@ -258,7 +258,7 @@ L_new_frame:; } _engine.time = actual_time; _engine.time_delta = actual_delta; - _engine.time_fixed_extrapolate = fixed_accumulator / (1.0/60.0); + _engine.time_fixed_extrapolate = fixed_accumulator;// / (1.0/60.0); i32 pw = _engine.w, ph = _engine.h; //glfwGetFramebufferSize( _engine.window_handle, &_engine.w, &_engine.h ); diff --git a/source/engine/vg_lines.c b/source/engine/vg_lines.c index ec9d611..311d6e4 100644 --- a/source/engine/vg_lines.c +++ b/source/engine/vg_lines.c @@ -3,6 +3,7 @@ #include "common_maths.h" #include "vg_async.h" #include "vg_shader.h" +#include "console_system.h" #include struct vg_lines @@ -58,6 +59,9 @@ void _vg_lines_init(void) void vg_lines_draw( f32 pv[4][4] ) { + if( _cvar_vg_lines_enable == 0 ) + return; + _shader_bind( k_shader_debug_lines ); _shader_debug_lines_uPv( pv ); diff --git a/source/tools/metacompiler.c b/source/tools/metacompiler.c index e925b44..9646057 100644 --- a/source/tools/metacompiler.c +++ b/source/tools/metacompiler.c @@ -345,6 +345,7 @@ void _codegen_shaders(void) const c8 *type; const c8 *alias; const c8 *shader_name; + const c8 *count; }; struct stretchy_allocator uniforms; stretchy_init( &uniforms, sizeof(struct uniform_info) ); @@ -364,7 +365,7 @@ void _codegen_shaders(void) { "mat3", "f32 m[3][3]", "glUniformMatrix3fv", "1,GL_FALSE,(f32*)m" }, { "mat4", "f32 m[4][4]", "glUniformMatrix4fv", "1,GL_FALSE,(f32*)m" }, { "float", "f32 f", "glUniform1f", "f" }, - { "mat4x3", "f32 m[4][3]", "glUniformMatrix4x3fv", "1,GL_FALSE,(f32*)m" }, + { "mat4x3", "f32 (*m)[4][3], u32 c","glUniformMatrix4x3fv", "c,GL_FALSE,(f32*)m" }, { "sampler2D", "i32 i", "glUniform1i", "i" }, { "usampler3D", "i32 i", "glUniform1i", "i" }, { "samplerCube", "i32 i", "glUniform1i", "i" }, @@ -452,6 +453,7 @@ void _codegen_shaders(void) uniform->glsl_index = -1; uniform->type = keyvalues_read_string( &_assembly, uniform_it, "type", NULL ); uniform->alias = keyvalues_read_string( &_assembly, uniform_it, "alias", NULL ); + uniform->count = keyvalues_read_string( &_assembly, uniform_it, "count", NULL ); uniform->shader_name = shader_name; ASSERT_CRITICAL( uniform->type && uniform->alias ); @@ -466,7 +468,14 @@ void _codegen_shaders(void) ASSERT_CRITICAL( uniform->glsl_index != -1 ); uniform_count ++; - $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} ); + if( uniform->count ) + { + $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {"["},{uniform->count},{"];\\n"} ); + } + else + { + $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} ); + } } $v_string( &C, {"\",\n"}, {" },\n"} ); subshader_count ++; @@ -558,7 +567,7 @@ void _codegen_console(void) stream_open_file( &H, "generated/console.h", k_stream_write ); stream_open_file( &C, "generated/console.c", k_stream_write ); - $v_string( &C, {"static struct console_command _console_commands[] = \n{\n"} ); + $v_string( &C, {"static struct console_item _console_items[] = \n{\n"} ); u32 ccmd_it = 0; while( keyvalues_foreach( &_assembly, &ccmd_it, 0, "ccmd" ) ) @@ -568,10 +577,34 @@ void _codegen_console(void) ASSERT_CRITICAL( name && function ); $v_string( &H, {"i32 "}, {function}, {"( struct console_arguments *args );\n"} ); - $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .fn = "}, {function}, {"\n },\n"} ); + $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .type = k_console_item_ccmd,\n .fn = "}, {function}, {"\n },\n"} ); + } + + u32 cvar_it = 0; + while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) ) + { + const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL ); + const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL ); + const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL ); + const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL ); + ASSERT_CRITICAL( name && type && value ); + $v_string( &H, {"extern "}, {type}, {" _cvar_"}, {name}, {";\n"} ); + $v_string( &C, {" {\n .alias = \""}, {name}, {"\",\n .type = k_console_item_cvar_"},{type}, + {",\n ._"},{type},{" = &_cvar_"}, {name}, {"\n },\n"} ); } $v_string( &C, {"};\n\n"} ); + cvar_it = 0; + while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) ) + { + const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL ); + const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL ); + const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL ); + const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL ); + ASSERT_CRITICAL( name && type && value ); + $v_string( &C, {type}, {" _cvar_"}, {name}, {" = "}, {value}, {";\n"} ); + } + stream_close( &H ); stream_close( &C ); }