1 /* Copyright (C) 2021-2023 Harry Godden (hgn) - All Rights Reserved */
7 | | .---------------------------------------------------------.
8 |API| | vg_enter( int argc, char *argv[], const char *window_name |
9 | | '---------------------------------------------------------'
12 |IMP| vg_launch_opt(void) <--.
14 | | |'---------------'
16 | | |'-----------------------------------| 1 |------.
19 | | | |IMP| vg_preload(void)
22 | | | | |IMP| vg_load(void)
24 |IMP| | vg_framebuffer_resize(void) |
26 |IMP| | |.------------- vg_start(void) ---------------'
29 |IMP| | vg_update(void)
34 |IMP| | '- vg_update_fixed(void)
39 |IMP| | vg_update_post(void)
42 |IMP| | vg_render(void)
52 | | .-------------------------------------.
53 |API| | vg_fatal_exit_loop( const char *err ) |
54 | | '-------------------------------------'
59 |IMP| '- vg_framebuffer_resize(void)
67 #include "vg_platform.h"
74 VG_STATIC
void vg_print_backtrace(void)
82 size
= backtrace( array
, 20 );
83 strings
= backtrace_symbols( array
, size
);
85 if( strings
!= NULL
){
86 vg_error( "---------------- gnu backtrace -------------\n" );
88 for( int i
=0; i
<size
; i
++ )
89 vg_info( "%s\n", strings
[i
] );
91 vg_error( "---------------- gnu backtrace -------------\n" );
100 #include "dep/glad/glad.h"
101 #include "submodules/SDL/include/SDL.h"
102 #include "vg_stdint.h"
104 void vg_register_exit( void( *funcptr
)(void), const char *name
);
109 #include "vg_steam.h"
111 //#define VG_SYNC_DEBUG
113 #define VG_SYNC_LOG(STR,...) \
114 vg_info(STR,SDL_GetThreadID(NULL),##__VA_ARGS__)
116 #define VG_SYNC_LOG(...)
120 VG_STATIC
void vg_enter( int argc
, char *argv
[], const char *window_name
);
123 VG_STATIC
void vg_preload(void);
124 VG_STATIC
void vg_load(void);
127 VG_STATIC
void vg_launch_opt(void);
128 VG_STATIC
void vg_start(void);
130 VG_STATIC
void vg_framebuffer_resize(int w
, int h
);
131 VG_STATIC
void vg_update(void);
132 VG_STATIC
void vg_update_fixed(void);
133 VG_STATIC
void vg_update_post(void);
135 VG_STATIC
void vg_render(void);
136 VG_STATIC
void vg_ui(void);
142 SDL_GLContext gl_context
;
144 SDL_SpinLock sl_context
;
145 SDL_sem
*sem_allow_exec
,
149 SDL_threadID thread_id_main
,
151 thread_id_with_opengl_context
;
152 int context_ownership_depth
;
158 k_engine_status_none
,
159 k_engine_status_running
,
160 k_engine_status_crashed
163 const char *str_const_engine_err
;
166 /* Window information */
172 int display_refresh_rate
,
173 fps_limit
; /* 0: use vsync, >0: cap fps to this, no vsync */
177 k_vsync_feature_disabled
=0,
178 k_vsync_feature_enabled
=1,
179 k_vsync_feature_enabled_adaptive
=2,
180 k_vsync_feature_error
=3
193 time_fixed_accumulator
,
194 time_fixed_extrapolate
,
197 u64 time_hp
, time_hp_last
, time_spinning
;
199 int fixed_iterations
;
204 k_engine_stage_update
,
205 k_engine_stage_update_fixed
,
206 k_engine_stage_rendering
,
215 k_quality_profile_high
= 0,
216 k_quality_profile_low
= 1,
220 VG_STATIC vg
= { .time_rate
= 1.0 };
222 enum vg_thread_purpose
224 k_thread_purpose_nothing
,
225 k_thread_purpose_main
,
226 k_thread_purpose_loader
229 VG_STATIC
void vg_fatal_exit_loop( const char *error
);
232 * Checks if the engine is running
234 VG_STATIC
void _vg_ensure_engine_running(void)
236 /* Check if the engine is no longer running */
237 SDL_AtomicLock( &vg
.sl_context
);
238 enum engine_status status
= vg
.engine_status
;
239 SDL_AtomicUnlock( &vg
.sl_context
);
241 if( status
!= k_engine_status_running
){
243 VG_SYNC_LOG( "[%d] No longer running...\n");
249 VG_STATIC
enum vg_thread_purpose
vg_thread_purpose(void)
251 SDL_AtomicLock( &vg
.sl_context
);
253 if( vg
.thread_id_main
== SDL_GetThreadID(NULL
) ){
254 SDL_AtomicUnlock( &vg
.sl_context
);
255 return k_thread_purpose_main
;
258 SDL_AtomicUnlock( &vg
.sl_context
);
259 return k_thread_purpose_loader
;
264 * Sync execution so that the OpenGL context is switched onto this thread.
265 * Anything after this call will be in a valid context.
267 VG_STATIC
void vg_acquire_thread_sync(void)
269 /* We dont want to do anything if this is the main thread */
271 if( vg_thread_purpose() == k_thread_purpose_loader
){
272 VG_SYNC_LOG( "[%d] vg_acquire_thread_sync()\n" );
273 _vg_ensure_engine_running();
275 SDL_AtomicLock( &vg
.sl_context
);
276 if( vg
.context_ownership_depth
== 0 ){
277 vg
.context_ownership_depth
++;
279 SDL_AtomicUnlock( &vg
.sl_context
);
281 /* wait until told we can go */
282 VG_SYNC_LOG( "[%d] Waiting to acuire sync.\n" );
283 SDL_SemWait( vg
.sem_allow_exec
);
285 _vg_ensure_engine_running();
287 SDL_GL_MakeCurrent( vg
.window
, vg
.gl_context
);
288 VG_SYNC_LOG( "[%d] granted\n" );
291 vg
.context_ownership_depth
++;
292 VG_SYNC_LOG( "[%d] granted\n" );
293 SDL_AtomicUnlock( &vg
.sl_context
);
299 * Signify that we are done with the OpenGL context in this thread.
300 * Anything after this call will be in an undefined context.
302 VG_STATIC
void vg_release_thread_sync(void)
304 if( vg_thread_purpose() == k_thread_purpose_loader
){
305 VG_SYNC_LOG( "[%d] vg_release_thread_sync()\n" );
307 SDL_AtomicLock( &vg
.sl_context
);
308 vg
.context_ownership_depth
--;
310 if( vg
.context_ownership_depth
== 0 ){
311 SDL_AtomicUnlock( &vg
.sl_context
);
312 VG_SYNC_LOG( "[%d] Releasing context.\n" );
313 SDL_GL_MakeCurrent( NULL
, NULL
);
314 SDL_SemPost( vg
.sem_exec_finished
);
317 SDL_AtomicUnlock( &vg
.sl_context
);
321 VG_STATIC
void _vg_run_synced(void)
323 SDL_AtomicLock( &vg
.sl_context
);
325 if( vg
.exec_context
!= 0 ){
326 VG_SYNC_LOG( "[%d] _vg_run_synced() (%d).\n", vg
.exec_context
);
328 SDL_AtomicUnlock( &vg
.sl_context
);
330 /* allow operations to go */
331 SDL_GL_MakeCurrent( NULL
, NULL
);
332 SDL_SemPost( vg
.sem_allow_exec
);
334 /* wait for operations to complete */
335 VG_SYNC_LOG( "[%d] Waiting for content.\n" );
336 SDL_SemWait( vg
.sem_exec_finished
);
338 /* check if we killed the engine */
339 _vg_ensure_engine_running();
341 /* re-engage main thread */
342 VG_SYNC_LOG( "[%d] Re-engaging.\n" );
343 SDL_GL_MakeCurrent( vg
.window
, vg
.gl_context
);
346 VG_SYNC_LOG( "[%d] Nothing to do.\n" );
347 SDL_AtomicUnlock( &vg
.sl_context
);
351 VG_STATIC
void _vg_opengl_sync_init(void)
353 vg
.sem_allow_exec
= SDL_CreateSemaphore(0);
354 vg
.sem_exec_finished
= SDL_CreateSemaphore(0);
355 vg
.sem_loader
= SDL_CreateSemaphore(1);
358 VG_STATIC
void vg_checkgl( const char *src_info
);
359 #define VG_STRINGIT( X ) #X
360 #define VG_CHECK_GL_ERR() vg_checkgl( __FILE__ ":L" VG_STRINGIT(__LINE__) )
362 #include "vg_console.h"
363 #include "vg_profiler.h"
364 #include "vg_audio.h"
365 #include "vg_shader.h"
367 #include "vg_input.h"
369 #include "vg_lines.h"
370 #include "vg_loader.h"
374 VG_STATIC
struct vg_profile vg_prof_update
= {.name
="update()"},
375 vg_prof_render
= {.name
="render()"},
376 vg_prof_swap
= {.name
="swap"};
378 VG_STATIC
void vg_checkgl( const char *src_info
)
383 while( (err
= glGetError()) != GL_NO_ERROR
){
384 vg_error( "(%s) OpenGL Error: #%d\n", src_info
, err
);
389 vg_fatal_exit_loop( "OpenGL Error" );
392 VG_STATIC
void vg_bake_shaders(void)
394 vg_acquire_thread_sync();
395 vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile
, NULL
);
397 vg_shaders_compile();
398 vg_release_thread_sync();
401 VG_STATIC
void _vg_load_full(void)
406 vg_loader_step( vg_input_init
, vg_input_free
);
407 vg_loader_step( vg_lines_init
, NULL
);
408 vg_loader_step( vg_audio_init
, vg_audio_free
);
409 vg_loader_step( vg_profiler_init
, NULL
);
415 VG_STATIC
void _vg_process_events(void)
418 v2_zero( vg
.mouse_wheel
);
419 v2_zero( vg
.mouse_delta
);
423 while( SDL_PollEvent( &event
) ){
424 if( event
.type
== SDL_KEYDOWN
){
425 console_proc_key( event
.key
.keysym
);
427 else if( event
.type
== SDL_MOUSEWHEEL
){
428 vg
.mouse_wheel
[0] += event
.wheel
.preciseX
;
429 vg
.mouse_wheel
[1] += event
.wheel
.preciseY
;
431 else if( event
.type
== SDL_CONTROLLERAXISMOTION
||
432 event
.type
== SDL_CONTROLLERBUTTONDOWN
||
433 event
.type
== SDL_CONTROLLERBUTTONUP
||
434 event
.type
== SDL_CONTROLLERDEVICEADDED
||
435 event
.type
== SDL_CONTROLLERDEVICEREMOVED
438 vg_input_controller_event( &event
);
440 else if( event
.type
== SDL_MOUSEMOTION
){
441 vg
.mouse_delta
[0] += event
.motion
.xrel
;
442 vg
.mouse_delta
[1] += event
.motion
.yrel
;
444 else if( event
.type
== SDL_WINDOWEVENT
){
445 if( event
.window
.event
== SDL_WINDOWEVENT_SIZE_CHANGED
){
447 SDL_GL_GetDrawableSize( vg
.window
, &w
, &h
);
450 vg_warn( "Got a invalid framebuffer size: "
451 "%dx%d... ignoring\n", w
, h
);
457 vg_framebuffer_resize(w
,h
);
460 else if( event
.window
.event
== SDL_WINDOWEVENT_CLOSE
){
461 vg
.window_should_close
= 1;
464 else if( event
.type
== SDL_TEXTINPUT
){
465 console_proc_utf8( event
.text
.text
);
469 vg
.mouse_pos
[0] += vg
.mouse_delta
[0];
470 vg
.mouse_pos
[1] += vg
.mouse_delta
[1];
476 VG_STATIC
void _vg_gameloop_update(void)
478 vg_profile_begin( &vg_prof_update
);
480 vg
.engine_stage
= k_engine_stage_update
;
483 /* Fixed update loop */
484 vg
.engine_stage
= k_engine_stage_update_fixed
;
486 vg
.fixed_iterations
= 0;
487 vg_lines
.allow_input
= 1;
488 vg
.time_fixed_accumulator
+= vg
.time_delta
;
490 while( vg
.time_fixed_accumulator
>= VG_TIMESTEP_FIXED
){
492 vg_lines
.allow_input
= 0;
494 vg
.time_fixed_accumulator
-= VG_TIMESTEP_FIXED
;
495 //vg.accumulator = VG_MAX( 0.0, vg.accumulator );
497 vg
.fixed_iterations
++;
498 if( vg
.fixed_iterations
== 8 ){
502 vg_lines
.allow_input
= 1;
503 vg
.time_fixed_extrapolate
= vg
.time_fixed_accumulator
/ VG_TIMESTEP_FIXED
;
505 vg
.engine_stage
= k_engine_stage_update
;
507 vg_profile_end( &vg_prof_update
);
510 VG_STATIC
void _vg_gameloop_render(void)
512 vg_profile_begin( &vg_prof_render
);
516 vg
.engine_stage
= k_engine_stage_rendering
;
520 vg
.engine_stage
= k_engine_stage_ui
;
522 ui_begin( vg
.window_x
, vg
.window_y
);
525 ui_set_mouse( vg
.mouse_pos
[0], vg
.mouse_pos
[1], 0 );
527 int frame_target
= vg
.display_refresh_rate
;
529 if( vg
.fps_limit
> 0 ){
530 frame_target
= vg
.fps_limit
;
534 (struct vg_profile
*[]){
535 &vg_prof_update
,&vg_prof_render
,&vg_prof_swap
}, 3,
536 (1.0f
/(float)frame_target
)*1000.0f
,
537 (ui_rect
){ 4, 4, 250, 0 }, 0
545 "refresh: %d (%.1fms)\n"
547 "iterations: %d (acc: %.3fms%%)\n"
548 "time: real(%.2f) delta(%.2f) rate(%.2f)\n"
550 " extrap(%.2f) frame(%.2f) spin( %llu )\n",
552 " extrap(%.2f) frame(%.2f) spin( %lu )\n",
554 vg
.window_x
, vg
.window_y
,
555 frame_target
, (1.0f
/(float)frame_target
)*1000.0f
,
558 (vg
.time_fixed_accumulator
/VG_TIMESTEP_FIXED
)*100.0f
,
559 vg
.time
, vg
.time_delta
, vg
.time_rate
,
560 vg
.time_fixed_extrapolate
, vg
.time_frame_delta
,
563 ui_text( (ui_rect
){258, 4+24+12+12,0,0},perf
, 1,0);
567 audio_debug_ui( vg
.pv
);
576 vg_profile_end( &vg_prof_render
);
579 VG_STATIC
int vg_framefilter( double dt
)
581 if( (vg
.fps_limit
<= 0) && (vg
.vsync_feature
!= k_vsync_feature_error
) ){
582 /* turn on vsync if not enabled */
584 enum vsync_feature requested
= k_vsync_feature_enabled
;
585 if( vg
.fps_limit
< 0 ) requested
= k_vsync_feature_enabled_adaptive
;
587 if( vg
.vsync_feature
!= requested
){
588 vg_info( "Setting swap interval\n" );
590 int swap_interval
= 1;
591 if( requested
== k_vsync_feature_enabled_adaptive
) swap_interval
= -1;
593 if( SDL_GL_SetSwapInterval( swap_interval
) == -1 ){
594 if( requested
== k_vsync_feature_enabled
){
595 vg_error( "Vsync is not supported by your system\n" );
596 vg_warn( "You may be overriding it in your"
597 " graphics control panel.\n" );
600 vg_error( "Adaptive Vsync is not supported by your system\n" );
603 vg
.vsync_feature
= k_vsync_feature_error
;
604 vg
.fps_limit
= vg
.display_refresh_rate
;
606 /* TODO: Make popup to notify user that this happened */
610 vg_success( "Vsync enabled (%d)\n", requested
);
611 vg
.vsync_feature
= requested
;
618 if( vg
.vsync_feature
!= k_vsync_feature_disabled
){
619 SDL_GL_SetSwapInterval( 0 );
620 vg
.vsync_feature
= k_vsync_feature_disabled
;
623 if( vg
.fps_limit
< 25 ) vg
.fps_limit
= 25;
624 if( vg
.fps_limit
> 300 ) vg
.fps_limit
= 300;
626 double min_frametime
= 1.0/(double)vg
.fps_limit
;
627 if( vg
.time_frame_delta
< min_frametime
){
628 /* TODO: we can use high res nanosleep on Linux here */
629 double sleep_ms
= (min_frametime
-vg
.time_frame_delta
) * 1000.0;
630 u32 ms
= (u32
)floor( sleep_ms
);
645 VG_STATIC
void _vg_gameloop(void)
647 //vg.time_fixed_accumulator = 0.75f * (1.0f/60.0f);
649 vg
.time_hp
= SDL_GetPerformanceCounter();
650 vg
.time_hp_last
= vg
.time_hp
;
655 vg
.time_hp
= SDL_GetPerformanceCounter();
656 u64 udt
= vg
.time_hp
- vg
.time_hp_last
;
657 vg
.time_hp_last
= vg
.time_hp
;
659 double dt
= (double)udt
/ (double)SDL_GetPerformanceFrequency();
661 vg
.time_frame_delta
+= dt
;
663 if( vg_framefilter( dt
) )
666 vg_profile_begin( &vg_prof_swap
);
667 SDL_GL_SwapWindow( vg
.window
);
669 vg_profile_end( &vg_prof_swap
);
671 vg
.time_delta
= vg
.time_frame_delta
* vg
.time_rate
;
672 vg
.time
+= vg
.time_delta
;
674 _vg_process_events();
676 if( vg
.window_should_close
)
689 _vg_gameloop_update();
690 _vg_gameloop_render();
692 vg
.time_frame_delta
= 0.0;
693 vg
.time_spinning
= 0;
697 VG_STATIC
void _vg_process_launch_opts_internal( int argc
, char *argv
[] )
700 while( vg_argp( argc
, argv
) ){
701 if( (arg
= vg_opt_arg( 'w' )) ){
702 vg
.window_x
= atoi( arg
);
705 if( (arg
= vg_opt_arg( 'h' )) ){
706 vg
.window_y
= atoi( arg
);
709 if( (arg
= vg_long_opt_arg( "samples" )) ){
710 vg
.samples
= VG_MAX( 0, VG_MIN( 8, atoi( arg
) ) );
713 if( vg_long_opt( "use-libc-malloc" ) ){
714 vg_mem
.use_libc_malloc
= 1;
717 if( vg_long_opt( "high-performance" ) ){
718 vg
.quality_profile
= k_quality_profile_low
;
725 VG_STATIC
void _vg_init_window( const char *window_name
)
727 vg_info( "SDL_INIT\n" );
729 if( SDL_Init( SDL_INIT_VIDEO
) != 0 ){
730 vg_error( "SDL_Init failed: %s\n", SDL_GetError() );
734 SDL_InitSubSystem( SDL_INIT_AUDIO
);
735 SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER
);
737 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER
, 1 );
738 SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION
, 3 );
739 SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION
, 3 );
740 SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK
,
741 SDL_GL_CONTEXT_PROFILE_CORE
);
743 SDL_GL_SetAttribute( SDL_GL_CONTEXT_RELEASE_BEHAVIOR
,
744 SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH
);
746 SDL_GL_SetAttribute( SDL_GL_RED_SIZE
, 8 );
747 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE
, 8 );
748 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE
, 8 );
749 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE
, 8 );
750 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE
, 0 );
753 * Get monitor information
755 vg_info( "Getting display count\n" );
756 int display_count
= 0,
765 SDL_DisplayMode video_mode
;
766 if( SDL_GetDesktopDisplayMode( display_index
, &video_mode
) ){
767 vg_error( "SDL_GetDesktopDisplayMode failed: %s\n", SDL_GetError() );
772 vg
.display_refresh_rate
= video_mode
.refresh_rate
;
773 vg
.window_x
= video_mode
.w
;
774 vg
.window_y
= video_mode
.h
;
778 SDL_SetHint( "SDL_VIDEO_X11_XINERAMA", "1" );
779 SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "0" );
780 SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "0" );
783 vg_info( "CreateWindow( %d %d @%dhz )\n", vg
.window_x
, vg
.window_y
,
784 vg
.display_refresh_rate
);
786 /* TODO: Allow selecting closest video mode from launch opts */
787 if((vg
.window
= SDL_CreateWindow( window_name
,
790 0, 0, vg
.window_x
, vg
.window_y
,
791 SDL_WINDOW_BORDERLESS
|SDL_WINDOW_OPENGL
|SDL_WINDOW_INPUT_GRABBED
795 vg
.window_x
, vg
.window_y
,
797 SDL_WINDOW_FULLSCREEN_DESKTOP
|
799 SDL_WINDOW_INPUT_GRABBED
802 if( SDL_SetWindowDisplayMode( vg
.window
, &video_mode
) ){
803 vg_error( "SDL_SetWindowDisplayMode failed: %s", SDL_GetError() );
810 vg_error( "SDL_CreateWindow failed: %s", SDL_GetError() );
814 SDL_RaiseWindow( vg
.window
);
816 vg_info( "CreateContext\n" );
821 if( (vg
.gl_context
= SDL_GL_CreateContext(vg
.window
) )){
822 SDL_GL_GetDrawableSize( vg
.window
, &vg
.window_x
, &vg
.window_y
);
823 vg_success( "Window created (%dx%d)\n", vg
.window_x
, vg
.window_y
);
826 vg_error( "SDL_GL_CreateContext failed: %s\n", SDL_GetError() );
831 if( !gladLoadGLLoader((GLADloadproc
)SDL_GL_GetProcAddress
) ) {
832 vg_error( "Glad Failed to initialize\n" );
833 SDL_GL_DeleteContext( vg
.gl_context
);
838 const unsigned char* glver
= glGetString( GL_VERSION
);
839 vg_success( "Load setup complete, OpenGL version: %s\n", glver
);
841 SDL_GL_SetSwapInterval(0); /* disable vsync while loading */
843 SDL_DisplayMode dispmode
;
844 if( !SDL_GetWindowDisplayMode( vg
.window
, &dispmode
) ){
845 if( dispmode
.refresh_rate
){
846 vg
.display_refresh_rate
= dispmode
.refresh_rate
;
850 if( vg
.display_refresh_rate
< 25 || vg
.display_refresh_rate
> 300 ){
851 vg
.display_refresh_rate
= 60;
854 vg_info( "Display refresh rate: %d\n", dispmode
.refresh_rate
);
857 vg
.fps_limit
= vg
.display_refresh_rate
;
859 /* request vsync by default on linux to avoid screen tearing.
860 * this does have its own issues with compositing on X11. */
865 VG_STATIC
void vg_enter( int argc
, char *argv
[], const char *window_name
)
867 _vg_process_launch_opts_internal( argc
, argv
);
874 vg_console_reg_var( "fps_limit", &vg
.fps_limit
, k_var_dtype_i32
, 0 );
876 _vg_init_window( window_name
);
878 SDL_SetRelativeMouseMode(1);
879 vg
.thread_id_main
= SDL_GetThreadID(NULL
);
881 /* Opengl-required systems */
885 vg
.engine_status
= k_engine_status_running
;
887 _vg_opengl_sync_init();
888 vg_loader_start( _vg_load_full
);
892 _vg_console_write_persistent();
894 SDL_AtomicLock( &vg
.sl_context
);
895 vg
.engine_status
= k_engine_status_none
;
896 SDL_AtomicUnlock( &vg
.sl_context
);
900 vg_success( "If you see this it means everything went.. \"well\".....\n" );
902 SDL_GL_DeleteContext( vg
.gl_context
);
907 * Immediately transfer away from calling thread into a safe loop, signal for
908 * others to shutdown, then free everything once the user closes the window.
910 * FIXME(bug): glfwWindowShouldClose() never returns 1 in windows via wine, ONLY
911 * when calling the program from outside its normal directory.
913 VG_STATIC
void vg_fatal_exit_loop( const char *error
)
916 * https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
919 * TODO: this on windows?
922 vg_print_backtrace();
923 vg_error( "Fatal error: %s\n", error
);
925 SDL_AtomicLock( &vg
.sl_context
);
926 if( vg
.engine_status
== k_engine_status_none
){
927 SDL_AtomicUnlock( &vg
.sl_context
);
929 /* TODO: Correct shutdown before other systems */
933 SDL_AtomicUnlock( &vg
.sl_context
);
935 vg_acquire_thread_sync();
937 SDL_AtomicLock( &vg
.sl_context
);
938 vg
.engine_status
= k_engine_status_crashed
;
939 vg
.str_const_engine_err
= error
;
940 SDL_AtomicUnlock( &vg
.sl_context
);
942 /* Notify other thread for curtosey */
943 if( vg_thread_purpose() == k_thread_purpose_main
){
944 SDL_AtomicLock( &vg
.sl_context
);
946 if( vg
.exec_context
!= 0 )
947 SDL_SemPost( vg
.sem_allow_exec
);
949 SDL_AtomicUnlock( &vg
.sl_context
);
955 _vg_process_events();
956 if( vg
.window_should_close
)
959 if( vg_getkey( SDLK_ESCAPE
) )
962 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
964 glDisable(GL_DEPTH_TEST
);
965 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
966 glBlendEquation(GL_FUNC_ADD
);
968 glClearColor( 0.15f
+ sinf(vg
.time
)*0.1f
, 0.0f
, 0.0f
,1.0f
);
969 glClear( GL_COLOR_BUFFER_BIT
);
970 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
973 SDL_GL_SwapWindow( vg
.window
);
976 /* Can now shutdown and EXIT */
978 SDL_GL_DeleteContext( vg
.gl_context
);
986 VG_STATIC
void vg_fatal_exit_loop( const char *error
)
988 vg_error( "Fatal error: %s\n", error
);
995 * Graphic cards will check these to force it to use the GPU
997 u32 NvOptimusEnablement
= 0x00000001;
998 int AmdPowerXpressRequestHighPerformance
= 1;
1000 #endif /* VG_HEADER_H */