window_should_close;
int display_refresh_rate,
- fps_limit; /* 0: use vsync, >0: cap fps to this, no vsync */
+ fps_limit,
+ vsync;
enum vsync_feature{
k_vsync_feature_disabled=0,
vg_profile_end( &vg_prof_render );
}
-static int vg_framefilter( double dt )
-{
- if( (vg.fps_limit <= 0) && (vg.vsync_feature != k_vsync_feature_error) ){
+static void vg_changevsync(void){
+ if( vg.vsync && (vg.vsync_feature != k_vsync_feature_error) ){
/* turn on vsync if not enabled */
enum vsync_feature requested = k_vsync_feature_enabled;
- if( vg.fps_limit < 0 ) requested = k_vsync_feature_enabled_adaptive;
+ if( vg.vsync < 0 ) requested = k_vsync_feature_enabled_adaptive;
if( vg.vsync_feature != requested ){
vg_info( "Setting swap interval\n" );
int swap_interval = 1;
- if( requested == k_vsync_feature_enabled_adaptive ) swap_interval = -1;
+ if( requested == k_vsync_feature_enabled_adaptive )
+ swap_interval = -1;
if( SDL_GL_SetSwapInterval( swap_interval ) == -1 ){
if( requested == k_vsync_feature_enabled ){
}
vg.vsync_feature = k_vsync_feature_error;
- vg.fps_limit = vg.display_refresh_rate;
-
+ vg.vsync = 0;
/* TODO: Make popup to notify user that this happened */
- return 1;
}
else{
vg_success( "Vsync enabled (%d)\n", requested );
vg.vsync_feature = requested;
}
}
-
- return 0;
}
-
- if( vg.vsync_feature != k_vsync_feature_disabled ){
- SDL_GL_SetSwapInterval( 0 );
- vg.vsync_feature = k_vsync_feature_disabled;
+ else {
+ if( vg.vsync_feature != k_vsync_feature_disabled ){
+ SDL_GL_SetSwapInterval( 0 );
+ vg.vsync_feature = k_vsync_feature_disabled;
+ }
}
-
+}
+
+static int vg_framefilter( double dt ){
if( vg.fps_limit < 25 ) vg.fps_limit = 25;
if( vg.fps_limit > 300 ) vg.fps_limit = 300;
u32 ms = (u32)floor( sleep_ms );
if( ms ){
- SDL_Delay( ms );
+ if( !vg_loader_availible() )
+ SDL_Delay(1);
+ else
+ SDL_Delay(ms);
}
else{
vg.time_spinning ++;
int post_start = 0;
while(1){
-
vg.time_hp = SDL_GetPerformanceCounter();
u64 udt = vg.time_hp - vg.time_hp_last;
vg.time_hp_last = vg.time_hp;
if( vg_framefilter( dt ) )
continue;
+ vg_changevsync();
+
vg_profile_begin( &vg_prof_swap );
SDL_GL_SwapWindow( vg.window );
vg_profile_end( &vg_prof_swap );
}
vg_info( "Display refresh rate: %d\n", dispmode.refresh_rate );
+ vg.fps_limit = vg.display_refresh_rate;
#if defined(_WIN32) || defined(VG_DEVWINDOW)
- vg.fps_limit = vg.display_refresh_rate;
#else
- vg.fps_limit = 0;
+ //vg.vsync = 1;
#endif
}
_vg_console_init();
vg_console_reg_var( "fps_limit", &vg.fps_limit, k_var_dtype_i32, 0 );
+ vg_console_reg_var( "vsync", &vg.vsync, k_var_dtype_i32, VG_VAR_PERSISTENT );
_vg_init_window( window_name );
vg_async_init();
#endif
}
-static void _vg_loader_render_ring( float opacity )
-{
+static void _vg_loader_render_ring( f32 opacity ){
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
+ opacity *= opacity;
+
glUseProgram( _shader_loader.id );
glUniform1f( glGetUniformLocation( _shader_loader.id, "uTime" ), vg.time );
- float ratio = (float)vg.window_x / (float)vg.window_y;
+ f32 ratio = (f32)vg.window_x / (f32)vg.window_y;
glUniform1f( glGetUniformLocation( _shader_loader.id, "uRatio"), ratio );
glUniform1f( glGetUniformLocation( _shader_loader.id, "uOpacity"), opacity );
glBindVertexArray( vg_loader.vao );