From fd8875baf8264b20731fb1bffaba4e1393beb189 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 20 Jan 2023 03:15:04 +0000 Subject: [PATCH 1/1] latest --- vg_audio.h | 2 +- vg_console.h | 32 +++++++++++++++++++++++++++++++- vg_graph.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ vg_profiler.h | 18 ++++++++++++------ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 vg_graph.h diff --git a/vg_audio.h b/vg_audio.h index 07c4be0..edbe8a2 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -639,7 +639,7 @@ VG_STATIC void audio_entity_get_samples( aatree_ptr id, u32 count, float *buf ) if( source_mode == k_audio_source_mono ) { i16 *src_buffer = ent->info.source->data, - *src = &src_buffer[cursor]; + *src = &src_buffer[cursor]; audio_decode_uncompressed_mono( src, samples_this_run, dst ); } diff --git a/vg_console.h b/vg_console.h index dbf57f7..5a137e3 100644 --- a/vg_console.h +++ b/vg_console.h @@ -10,6 +10,36 @@ #include "vg/vg_ui.h" #include "vg/vg_log.h" +#define VG_VAR_F32_PERSISTENT( NAME ) \ + vg_var_push( (struct vg_var){ \ + .name = #NAME, \ + .data = &NAME, \ + .data_type = k_var_dtype_f32, \ + .persistent = 1 \ + }); + +#define VG_VAR_F32( NAME ) \ + vg_var_push( (struct vg_var){ \ + .name = #NAME, \ + .data = &NAME, \ + .data_type = k_var_dtype_f32, \ + }); + +#define VG_VAR_I32_PERSISTENT( NAME ) \ + vg_var_push( (struct vg_var){ \ + .name = #NAME, \ + .data = &NAME, \ + .data_type = k_var_dtype_i32, \ + .persistent = 1 \ + }); + +#define VG_VAR_I32( NAME ) \ + vg_var_push( (struct vg_var){ \ + .name = #NAME, \ + .data = &NAME, \ + .data_type = k_var_dtype_i32, \ + }); + typedef struct vg_var vg_var; typedef struct vg_cmd vg_cmd; @@ -46,7 +76,7 @@ struct vg_console int persistent; /* Should this var be stored to cfg/auto.conf? */ } - vars[ 32 ]; + vars[ 64 ]; struct vg_cmd { diff --git a/vg_graph.h b/vg_graph.h new file mode 100644 index 0000000..fac1984 --- /dev/null +++ b/vg_graph.h @@ -0,0 +1,48 @@ +#ifndef VG_GRAPH_H +#define VG_GRAPH_H + +#define VG_GAME +#include "vg/vg.h" + +enum { k_vg_graph_max_samples = 1024 }; +enum { k_vg_graph_max_vertices = k_vg_graph_max_samples * 2 }; +enum { k_vg_graph_max_indices = (k_vg_graph_max_samples-1) * 6 }; + +struct vg_graph +{ + GLuint vao, vbo, ebo; +}; + +VG_STATIC void vg_graph_init( struct vg_graph *graph ) +{ + vg_acquire_thread_sync(); + { + glGenVertexArrays( 1, &graph->vao ); + glGenBuffers( 1, &graph->vbo ); + glGenBuffers( 1, &graph->ebo ); + glBindVertexArray( graph->vao ); + + size_t stride = sizeof(v2f); + + glBindBuffer( GL_ARRAY_BUFFER, graph->vbo ); + glBufferData( GL_ARRAY_BUFFER, k_vg_graph_max_vertices*stride, + NULL, GL_DYNAMIC_DRAW ); + + glBindVertexArray( graph->vao ); + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, graph->ebo ); + glBufferData( GL_ELEMENT_ARRAY_BUFFER, + k_vg_graph_max_indices*sizeof(u16), NULL, + GL_DYNAMIC_DRAW ); + + glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, stride, (void *)0 ); + glEnableVertexAttribArray( 0 ); + VG_CHECK_GL_ERR(); + } +} + +VG_STATIC void vg_graph_add_sample( struct vg_graph *graph ) +{ + +} + +#endif /* VG_GRAPH_H */ diff --git a/vg_profiler.h b/vg_profiler.h index 944a5bb..c8db76d 100644 --- a/vg_profiler.h +++ b/vg_profiler.h @@ -13,8 +13,8 @@ struct vg_profile { const char *name; - u64 samples[ VG_PROFILE_SAMPLE_COUNT ]; - u32 buffer_count, buffer_current; + float samples[ VG_PROFILE_SAMPLE_COUNT ]; + u32 buffer_count, buffer_current; enum profile_mode { @@ -41,7 +41,7 @@ VG_STATIC void vg_profile_increment( struct vg_profile *profile ) if( profile->buffer_current >= VG_PROFILE_SAMPLE_COUNT ) profile->buffer_current = 0; - profile->samples[ profile->buffer_current ] = 0; + profile->samples[ profile->buffer_current ] = 0.0f; } VG_STATIC void vg_profile_end( struct vg_profile *profile ) @@ -51,7 +51,7 @@ VG_STATIC void vg_profile_end( struct vg_profile *profile ) if( profile->mode == k_profile_mode_frame ) { - profile->samples[ profile->buffer_current ] = delta; + profile->samples[ profile->buffer_current ] = (float)delta; vg_profile_increment( profile ); } else @@ -60,6 +60,12 @@ VG_STATIC void vg_profile_end( struct vg_profile *profile ) } } +VG_STATIC void vg_profile_graph_sample( struct vg_profile *profile, float s ) +{ + profile->samples[ profile->buffer_current ] = s; + vg_profile_increment( profile ); +} + VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, float budget, ui_rect panel, u32 colour_offset ) { @@ -90,7 +96,7 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, u32 colours[] = { 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00 }; - double rate_mul = 1000.0 / (double)SDL_GetPerformanceFrequency(); + float rate_mul = 1000.0f / (float)SDL_GetPerformanceFrequency(); for( int i=0; isamples[ptrs[j]] * rate_mul, + float sample = profiles[j]->samples[ptrs[j]] * rate_mul, px = (total / (budget)) * sw, wx = (sample / (budget)) * sw; -- 2.25.1