1111#include "sokol_imgui.h"
1212#define SOKOL_GFX_IMGUI_IMPL
1313#include "sokol_gfx_imgui.h"
14+ #define SOKOL_APP_IMGUI_IMPL
15+ #include "sokol_app_imgui.h"
1416#define VECMATH_GENERICS
1517#include "vecmath/vecmath.h"
1618#include "drawcallperf-sapp.glsl.h"
@@ -41,6 +43,8 @@ static struct {
4143
4244static vs_per_instance_t positions [MAX_INSTANCES ];
4345
46+ static void drawui (void );
47+
4448static inline uint32_t xorshift32 (void ) {
4549 static uint32_t x = 0x12345678 ;
4650 x ^= x <<13 ;
@@ -63,10 +67,11 @@ static void init(void) {
6367 .logger .func = slog_func ,
6468 .uniform_buffer_size = MAX_INSTANCES * 256 + 1024 ,
6569 });
70+ sgimgui_setup (& (sgimgui_desc_t ){0 });
71+ sappimgui_setup ();
6672 simgui_setup (& (simgui_desc_t ){
6773 .logger .func = slog_func ,
6874 });
69- sgimgui_setup (& (sgimgui_desc_t ){0 });
7075 state .pass_action = (sg_pass_action ) {
7176 .colors [0 ] = { .load_action = SG_LOADACTION_CLEAR , .clear_value = { 0.0f , 0.5f , 0.75f , 1.0f } },
7277 };
@@ -199,37 +204,7 @@ static mat44_t compute_viewproj(void) {
199204}
200205
201206static void frame (void ) {
202- double frame_measured_time = stm_sec (stm_laptime (& state .last_time ));
203-
204- simgui_new_frame (& (simgui_frame_desc_t ){
205- .width = sapp_width (),
206- .height = sapp_height (),
207- .delta_time = sapp_frame_duration (),
208- .dpi_scale = sapp_dpi_scale (),
209- });
210-
211- // sokol-gfx debug ui
212- if (igBeginMainMenuBar ()) {
213- sgimgui_draw_menu ("sokol-gfx" );
214- sgimgui_draw ();
215- igEndMainMenuBar ();
216- }
217-
218- // control ui
219- igSetNextWindowPos ((ImVec2 ){20 ,20 }, ImGuiCond_Once );
220- igSetNextWindowSize ((ImVec2 ){600 ,200 }, ImGuiCond_Once );
221- if (igBegin ("Controls" , 0 , ImGuiWindowFlags_NoResize )) {
222- igText ("Each cube/instance is 1 16-byte uniform update and 1 draw call\n" );
223- igText ("DC/texture is the number of adjacent draw calls with the same texture binding\n" );
224- igSliderIntEx ("Num Instances" , & state .num_instances , 100 , MAX_INSTANCES , "%d" , ImGuiSliderFlags_Logarithmic );
225- igSliderIntEx ("DC/texture" , & state .bind_frequency , 1 , MAX_BIND_FREQUENCY , "%d" , ImGuiSliderFlags_Logarithmic );
226- igText ("Backend: %s" , state .backend );
227- igText ("Frame duration: %.4fms" , frame_measured_time * 1000.0 );
228- igText ("sg_apply_bindings(): %d\n" , state .stats .num_binding_updates );
229- igText ("sg_apply_uniforms(): %d\n" , state .stats .num_uniform_updates );
230- igText ("sg_draw(): %d\n" , state .stats .num_draw_calls );
231- }
232- igEnd ();
207+ drawui ();
233208
234209 if (state .num_instances < 1 ) {
235210 state .num_instances = 1 ;
@@ -277,15 +252,53 @@ static void frame(void) {
277252}
278253
279254static void input (const sapp_event * ev ) {
255+ sappimgui_track_event (ev );
280256 simgui_handle_event (ev );
281257}
282258
283259static void cleanup (void ) {
260+ sappimgui_shutdown ();
284261 sgimgui_shutdown ();
285262 simgui_shutdown ();
286263 sg_shutdown ();
287264}
288265
266+ static void drawui (void ) {
267+ double frame_measured_time = stm_sec (stm_laptime (& state .last_time ));
268+ sappimgui_track_frame ();
269+ simgui_new_frame (& (simgui_frame_desc_t ){
270+ .width = sapp_width (),
271+ .height = sapp_height (),
272+ .delta_time = sapp_frame_duration (),
273+ .dpi_scale = sapp_dpi_scale (),
274+ });
275+
276+ // sokol-gfx debug ui
277+ if (igBeginMainMenuBar ()) {
278+ sgimgui_draw_menu ("sokol-gfx" );
279+ sappimgui_draw_menu ("sokol-app" );
280+ igEndMainMenuBar ();
281+ }
282+
283+ // control ui
284+ igSetNextWindowPos ((ImVec2 ){20 ,20 }, ImGuiCond_Once );
285+ igSetNextWindowSize ((ImVec2 ){600 ,200 }, ImGuiCond_Once );
286+ if (igBegin ("Controls" , 0 , ImGuiWindowFlags_NoResize )) {
287+ igText ("Each cube/instance is 1 16-byte uniform update and 1 draw call\n" );
288+ igText ("DC/texture is the number of adjacent draw calls with the same texture binding\n" );
289+ igSliderIntEx ("Num Instances" , & state .num_instances , 100 , MAX_INSTANCES , "%d" , ImGuiSliderFlags_Logarithmic );
290+ igSliderIntEx ("DC/texture" , & state .bind_frequency , 1 , MAX_BIND_FREQUENCY , "%d" , ImGuiSliderFlags_Logarithmic );
291+ igText ("Backend: %s" , state .backend );
292+ igText ("Frame duration: %.4fms" , frame_measured_time * 1000.0 );
293+ igText ("sg_apply_bindings(): %d\n" , state .stats .num_binding_updates );
294+ igText ("sg_apply_uniforms(): %d\n" , state .stats .num_uniform_updates );
295+ igText ("sg_draw(): %d\n" , state .stats .num_draw_calls );
296+ }
297+ igEnd ();
298+ sgimgui_draw ();
299+ sappimgui_draw ();
300+ }
301+
289302sapp_desc sokol_main (int argc , char * argv []) {
290303 (void )argc ; (void )argv ;
291304 return (sapp_desc ){
0 commit comments