forked from floooh/sokol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsokol_gfx_imgui.h
4479 lines (4075 loc) · 173 KB
/
sokol_gfx_imgui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if defined(SOKOL_IMPL) && !defined(SOKOL_GFX_IMGUI_IMPL)
#define SOKOL_GFX_IMGUI_IMPL
#endif
#ifndef SOKOL_GFX_IMGUI_INCLUDED
/*
sokol_gfx_imgui.h -- debug-inspection UI for sokol_gfx.h using Dear ImGui
Project URL: https://github.com/floooh/sokol
Do this:
#define SOKOL_IMPL or
#define SOKOL_GFX_IMGUI_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
NOTE that the implementation can be compiled either as C++ or as C.
When compiled as C++, sokol_gfx_imgui.h will directly call into the
Dear ImGui C++ API. When compiled as C, sokol_gfx_imgui.h will call
cimgui.h functions instead.
Include the following file(s) before including sokol_gfx_imgui.h:
sokol_gfx.h
Additionally, include the following headers before including the
implementation:
If the implementation is compiled as C++:
imgui.h
If the implementation is compiled as C:
cimgui.h
The sokol_gfx.h implementation must be compiled with debug trace hooks
enabled by defining:
SOKOL_TRACE_HOOKS
...before including the sokol_gfx.h implementation.
Before including the sokol_gfx_imgui.h implementation, optionally
override the following macros:
SOKOL_ASSERT(c) -- your own assert macro, default: assert(c)
SOKOL_UNREACHABLE -- your own macro to annotate unreachable code,
default: SOKOL_ASSERT(false)
SOKOL_GFX_IMGUI_API_DECL - public function declaration prefix (default: extern)
SOKOL_API_DECL - same as SOKOL_GFX_IMGUI_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_gfx_imgui.h is compiled as a DLL, define the following before
including the declaration or implementation:
SOKOL_DLL
On Windows, SOKOL_DLL will define SOKOL_GFX_IMGUI_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
STEP BY STEP:
=============
--- create an sg_imgui_t struct (which must be preserved between frames)
and initialize it with:
sg_imgui_init(&sg_imgui, &(sg_imgui_desc_t){ 0 });
Note that from C++ you can't inline the desc structure initialization:
const sg_imgui_desc_t desc = { };
sg_imgui_init(&sg_imgui, &desc);
Provide optional memory allocator override functions (compatible with malloc/free) like this:
sg_imgui_init(&sg_imgui, &(sg_imgui_desc_t){
.allocator = {
.alloc = my_malloc,
.free = my_free,
}
});
--- somewhere in the per-frame code call:
sg_imgui_draw(&sg_imgui)
this won't draw anything yet, since no windows are open.
--- open and close windows directly by setting the following public
booleans in the sg_imgui_t struct:
sg_imgui.buffers.open = true;
sg_imgui.images.open = true;
sg_imgui.samplers.open = true;
sg_imgui.shaders.open = true;
sg_imgui.pipelines.open = true;
sg_imgui.passes.open = true;
sg_imgui.capture.open = true;
...for instance, to control the window visibility through
menu items, the following code can be used:
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("sokol-gfx")) {
ImGui::MenuItem("Buffers", 0, &sg_imgui.buffers.open);
ImGui::MenuItem("Images", 0, &sg_imgui.images.open);
ImGui::MenuItem("Samplers", 0, &sg_imgui.samplers.open);
ImGui::MenuItem("Shaders", 0, &sg_imgui.shaders.open);
ImGui::MenuItem("Pipelines", 0, &sg_imgui.pipelines.open);
ImGui::MenuItem("Passes", 0, &sg_imgui.passes.open);
ImGui::MenuItem("Calls", 0, &sg_imgui.capture.open);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
--- before application shutdown, call:
sg_imgui_discard(&sg_imgui);
...this is not strictly necessary because the application exits
anyway, but not doing this may trigger memory leak detection tools.
--- finally, your application needs an ImGui renderer, you can either
provide your own, or drop in the sokol_imgui.h utility header
ALTERNATIVE DRAWING FUNCTIONS:
==============================
Instead of the convenient, but all-in-one sg_imgui_draw() function,
you can also use the following granular functions which might allow
better integration with your existing UI:
The following functions only render the window *content* (so you
can integrate the UI into you own windows):
void sg_imgui_draw_buffers_content(sg_imgui_t* ctx);
void sg_imgui_draw_images_content(sg_imgui_t* ctx);
void sg_imgui_draw_samplers_content(sg_imgui_t* ctx);
void sg_imgui_draw_shaders_content(sg_imgui_t* ctx);
void sg_imgui_draw_pipelines_content(sg_imgui_t* ctx);
void sg_imgui_draw_passes_content(sg_imgui_t* ctx);
void sg_imgui_draw_capture_content(sg_imgui_t* ctx);
And these are the 'full window' drawing functions:
void sg_imgui_draw_buffers_window(sg_imgui_t* ctx);
void sg_imgui_draw_images_window(sg_imgui_t* ctx);
void sg_imgui_draw_samplers_window(sg_imgui_t* ctx);
void sg_imgui_draw_shaders_window(sg_imgui_t* ctx);
void sg_imgui_draw_pipelines_window(sg_imgui_t* ctx);
void sg_imgui_draw_passes_window(sg_imgui_t* ctx);
void sg_imgui_draw_capture_window(sg_imgui_t* ctx);
Finer-grained drawing functions may be moved to the public API
in the future as needed.
MEMORY ALLOCATION OVERRIDE
==========================
You can override the memory allocation functions at initialization time
like this:
void* my_alloc(size_t size, void* user_data) {
return malloc(size);
}
void my_free(void* ptr, void* user_data) {
free(ptr);
}
...
sg_imgui_init(&(&ctx, &(sg_imgui_desc_t){
// ...
.allocator = {
.alloc = my_alloc,
.free = my_free,
.user_data = ...;
}
});
...
This only affects memory allocation calls done by sokol_gfx_imgui.h
itself though, not any allocations in OS libraries.
LICENSE
=======
zlib/libpng license
Copyright (c) 2018 Andre Weissflog
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the
use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#define SOKOL_GFX_IMGUI_INCLUDED (1)
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h> // size_t
#if !defined(SOKOL_GFX_INCLUDED)
#error "Please include sokol_gfx.h before sokol_gfx_imgui.h"
#endif
#if defined(SOKOL_API_DECL) && !defined(SOKOL_GFX_IMGUI_API_DECL)
#define SOKOL_GFX_IMGUI_API_DECL SOKOL_API_DECL
#endif
#ifndef SOKOL_GFX_IMGUI_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GFX_IMGUI_IMPL)
#define SOKOL_GFX_IMGUI_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
#define SOKOL_GFX_IMGUI_API_DECL __declspec(dllimport)
#else
#define SOKOL_GFX_IMGUI_API_DECL extern
#endif
#endif
#if defined(__cplusplus)
extern "C" {
#endif
#define SG_IMGUI_STRBUF_LEN (96)
/* max number of captured calls per frame */
#define SG_IMGUI_MAX_FRAMECAPTURE_ITEMS (4096)
typedef struct sg_imgui_str_t {
char buf[SG_IMGUI_STRBUF_LEN];
} sg_imgui_str_t;
typedef struct sg_imgui_buffer_t {
sg_buffer res_id;
sg_imgui_str_t label;
sg_buffer_desc desc;
} sg_imgui_buffer_t;
typedef struct sg_imgui_image_t {
sg_image res_id;
float ui_scale;
sg_imgui_str_t label;
sg_image_desc desc;
simgui_image_t simgui_img;
} sg_imgui_image_t;
typedef struct sg_imgui_sampler_t {
sg_sampler res_id;
sg_imgui_str_t label;
sg_sampler_desc desc;
} sg_imgui_sampler_t;
typedef struct sg_imgui_shader_t {
sg_shader res_id;
sg_imgui_str_t label;
sg_imgui_str_t vs_entry;
sg_imgui_str_t vs_d3d11_target;
sg_imgui_str_t vs_image_sampler_name[SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS];
sg_imgui_str_t vs_uniform_name[SG_MAX_SHADERSTAGE_UBS][SG_MAX_UB_MEMBERS];
sg_imgui_str_t fs_entry;
sg_imgui_str_t fs_d3d11_target;
sg_imgui_str_t fs_image_sampler_name[SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS];
sg_imgui_str_t fs_uniform_name[SG_MAX_SHADERSTAGE_UBS][SG_MAX_UB_MEMBERS];
sg_imgui_str_t attr_name[SG_MAX_VERTEX_ATTRIBUTES];
sg_imgui_str_t attr_sem_name[SG_MAX_VERTEX_ATTRIBUTES];
sg_shader_desc desc;
} sg_imgui_shader_t;
typedef struct sg_imgui_pipeline_t {
sg_pipeline res_id;
sg_imgui_str_t label;
sg_pipeline_desc desc;
} sg_imgui_pipeline_t;
typedef struct sg_imgui_pass_t {
sg_pass res_id;
sg_imgui_str_t label;
float color_image_scale[SG_MAX_COLOR_ATTACHMENTS];
float resolve_image_scale[SG_MAX_COLOR_ATTACHMENTS];
float ds_image_scale;
sg_pass_desc desc;
} sg_imgui_pass_t;
typedef struct sg_imgui_buffers_t {
bool open;
int num_slots;
sg_buffer sel_buf;
sg_imgui_buffer_t* slots;
} sg_imgui_buffers_t;
typedef struct sg_imgui_images_t {
bool open;
int num_slots;
sg_image sel_img;
sg_imgui_image_t* slots;
} sg_imgui_images_t;
typedef struct sg_imgui_samplers_t {
bool open;
int num_slots;
sg_sampler sel_smp;
sg_imgui_sampler_t* slots;
} sg_imgui_samplers_t;
typedef struct sg_imgui_shaders_t {
bool open;
int num_slots;
sg_shader sel_shd;
sg_imgui_shader_t* slots;
} sg_imgui_shaders_t;
typedef struct sg_imgui_pipelines_t {
bool open;
int num_slots;
sg_pipeline sel_pip;
sg_imgui_pipeline_t* slots;
} sg_imgui_pipelines_t;
typedef struct sg_imgui_passes_t {
bool open;
int num_slots;
sg_pass sel_pass;
sg_imgui_pass_t* slots;
} sg_imgui_passes_t;
typedef enum sg_imgui_cmd_t {
SG_IMGUI_CMD_INVALID,
SG_IMGUI_CMD_RESET_STATE_CACHE,
SG_IMGUI_CMD_MAKE_BUFFER,
SG_IMGUI_CMD_MAKE_IMAGE,
SG_IMGUI_CMD_MAKE_SAMPLER,
SG_IMGUI_CMD_MAKE_SHADER,
SG_IMGUI_CMD_MAKE_PIPELINE,
SG_IMGUI_CMD_MAKE_PASS,
SG_IMGUI_CMD_DESTROY_BUFFER,
SG_IMGUI_CMD_DESTROY_IMAGE,
SG_IMGUI_CMD_DESTROY_SAMPLER,
SG_IMGUI_CMD_DESTROY_SHADER,
SG_IMGUI_CMD_DESTROY_PIPELINE,
SG_IMGUI_CMD_DESTROY_PASS,
SG_IMGUI_CMD_UPDATE_BUFFER,
SG_IMGUI_CMD_UPDATE_IMAGE,
SG_IMGUI_CMD_APPEND_BUFFER,
SG_IMGUI_CMD_BEGIN_DEFAULT_PASS,
SG_IMGUI_CMD_BEGIN_PASS,
SG_IMGUI_CMD_APPLY_VIEWPORT,
SG_IMGUI_CMD_APPLY_SCISSOR_RECT,
SG_IMGUI_CMD_APPLY_PIPELINE,
SG_IMGUI_CMD_APPLY_BINDINGS,
SG_IMGUI_CMD_APPLY_UNIFORMS,
SG_IMGUI_CMD_DRAW,
SG_IMGUI_CMD_END_PASS,
SG_IMGUI_CMD_COMMIT,
SG_IMGUI_CMD_ALLOC_BUFFER,
SG_IMGUI_CMD_ALLOC_IMAGE,
SG_IMGUI_CMD_ALLOC_SAMPLER,
SG_IMGUI_CMD_ALLOC_SHADER,
SG_IMGUI_CMD_ALLOC_PIPELINE,
SG_IMGUI_CMD_ALLOC_PASS,
SG_IMGUI_CMD_DEALLOC_BUFFER,
SG_IMGUI_CMD_DEALLOC_IMAGE,
SG_IMGUI_CMD_DEALLOC_SAMPLER,
SG_IMGUI_CMD_DEALLOC_SHADER,
SG_IMGUI_CMD_DEALLOC_PIPELINE,
SG_IMGUI_CMD_DEALLOC_PASS,
SG_IMGUI_CMD_INIT_BUFFER,
SG_IMGUI_CMD_INIT_IMAGE,
SG_IMGUI_CMD_INIT_SAMPLER,
SG_IMGUI_CMD_INIT_SHADER,
SG_IMGUI_CMD_INIT_PIPELINE,
SG_IMGUI_CMD_INIT_PASS,
SG_IMGUI_CMD_UNINIT_BUFFER,
SG_IMGUI_CMD_UNINIT_IMAGE,
SG_IMGUI_CMD_UNINIT_SAMPLER,
SG_IMGUI_CMD_UNINIT_SHADER,
SG_IMGUI_CMD_UNINIT_PIPELINE,
SG_IMGUI_CMD_UNINIT_PASS,
SG_IMGUI_CMD_FAIL_BUFFER,
SG_IMGUI_CMD_FAIL_IMAGE,
SG_IMGUI_CMD_FAIL_SAMPLER,
SG_IMGUI_CMD_FAIL_SHADER,
SG_IMGUI_CMD_FAIL_PIPELINE,
SG_IMGUI_CMD_FAIL_PASS,
SG_IMGUI_CMD_PUSH_DEBUG_GROUP,
SG_IMGUI_CMD_POP_DEBUG_GROUP,
} sg_imgui_cmd_t;
typedef struct sg_imgui_args_make_buffer_t {
sg_buffer result;
} sg_imgui_args_make_buffer_t;
typedef struct sg_imgui_args_make_image_t {
sg_image result;
} sg_imgui_args_make_image_t;
typedef struct sg_imgui_args_make_sampler_t {
sg_sampler result;
} sg_imgui_args_make_sampler_t;
typedef struct sg_imgui_args_make_shader_t {
sg_shader result;
} sg_imgui_args_make_shader_t;
typedef struct sg_imgui_args_make_pipeline_t {
sg_pipeline result;
} sg_imgui_args_make_pipeline_t;
typedef struct sg_imgui_args_make_pass_t {
sg_pass result;
} sg_imgui_args_make_pass_t;
typedef struct sg_imgui_args_destroy_buffer_t {
sg_buffer buffer;
} sg_imgui_args_destroy_buffer_t;
typedef struct sg_imgui_args_destroy_image_t {
sg_image image;
} sg_imgui_args_destroy_image_t;
typedef struct sg_imgui_args_destroy_sampler_t {
sg_sampler sampler;
} sg_imgui_args_destroy_sampler_t;
typedef struct sg_imgui_args_destroy_shader_t {
sg_shader shader;
} sg_imgui_args_destroy_shader_t;
typedef struct sg_imgui_args_destroy_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_destroy_pipeline_t;
typedef struct sg_imgui_args_destroy_pass_t {
sg_pass pass;
} sg_imgui_args_destroy_pass_t;
typedef struct sg_imgui_args_update_buffer_t {
sg_buffer buffer;
size_t data_size;
} sg_imgui_args_update_buffer_t;
typedef struct sg_imgui_args_update_image_t {
sg_image image;
} sg_imgui_args_update_image_t;
typedef struct sg_imgui_args_append_buffer_t {
sg_buffer buffer;
size_t data_size;
int result;
} sg_imgui_args_append_buffer_t;
typedef struct sg_imgui_args_begin_default_pass_t {
sg_pass_action action;
int width;
int height;
} sg_imgui_args_begin_default_pass_t;
typedef struct sg_imgui_args_begin_pass_t {
sg_pass pass;
sg_pass_action action;
} sg_imgui_args_begin_pass_t;
typedef struct sg_imgui_args_apply_viewport_t {
int x, y, width, height;
bool origin_top_left;
} sg_imgui_args_apply_viewport_t;
typedef struct sg_imgui_args_apply_scissor_rect_t {
int x, y, width, height;
bool origin_top_left;
} sg_imgui_args_apply_scissor_rect_t;
typedef struct sg_imgui_args_apply_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_apply_pipeline_t;
typedef struct sg_imgui_args_apply_bindings_t {
sg_bindings bindings;
} sg_imgui_args_apply_bindings_t;
typedef struct sg_imgui_args_apply_uniforms_t {
sg_shader_stage stage;
int ub_index;
size_t data_size;
sg_pipeline pipeline; /* the pipeline which was active at this call */
size_t ubuf_pos; /* start of copied data in capture buffer */
} sg_imgui_args_apply_uniforms_t;
typedef struct sg_imgui_args_draw_t {
int base_element;
int num_elements;
int num_instances;
} sg_imgui_args_draw_t;
typedef struct sg_imgui_args_alloc_buffer_t {
sg_buffer result;
} sg_imgui_args_alloc_buffer_t;
typedef struct sg_imgui_args_alloc_image_t {
sg_image result;
} sg_imgui_args_alloc_image_t;
typedef struct sg_imgui_args_alloc_sampler_t {
sg_sampler result;
} sg_imgui_args_alloc_sampler_t;
typedef struct sg_imgui_args_alloc_shader_t {
sg_shader result;
} sg_imgui_args_alloc_shader_t;
typedef struct sg_imgui_args_alloc_pipeline_t {
sg_pipeline result;
} sg_imgui_args_alloc_pipeline_t;
typedef struct sg_imgui_args_alloc_pass_t {
sg_pass result;
} sg_imgui_args_alloc_pass_t;
typedef struct sg_imgui_args_dealloc_buffer_t {
sg_buffer buffer;
} sg_imgui_args_dealloc_buffer_t;
typedef struct sg_imgui_args_dealloc_image_t {
sg_image image;
} sg_imgui_args_dealloc_image_t;
typedef struct sg_imgui_args_dealloc_sampler_t {
sg_sampler sampler;
} sg_imgui_args_dealloc_sampler_t;
typedef struct sg_imgui_args_dealloc_shader_t {
sg_shader shader;
} sg_imgui_args_dealloc_shader_t;
typedef struct sg_imgui_args_dealloc_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_dealloc_pipeline_t;
typedef struct sg_imgui_args_dealloc_pass_t {
sg_pass pass;
} sg_imgui_args_dealloc_pass_t;
typedef struct sg_imgui_args_init_buffer_t {
sg_buffer buffer;
} sg_imgui_args_init_buffer_t;
typedef struct sg_imgui_args_init_image_t {
sg_image image;
} sg_imgui_args_init_image_t;
typedef struct sg_imgui_args_init_sampler_t {
sg_sampler sampler;
} sg_imgui_args_init_sampler_t;
typedef struct sg_imgui_args_init_shader_t {
sg_shader shader;
} sg_imgui_args_init_shader_t;
typedef struct sg_imgui_args_init_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_init_pipeline_t;
typedef struct sg_imgui_args_init_pass_t {
sg_pass pass;
} sg_imgui_args_init_pass_t;
typedef struct sg_imgui_args_uninit_buffer_t {
sg_buffer buffer;
} sg_imgui_args_uninit_buffer_t;
typedef struct sg_imgui_args_uninit_image_t {
sg_image image;
} sg_imgui_args_uninit_image_t;
typedef struct sg_imgui_args_uninit_sampler_t {
sg_sampler sampler;
} sg_imgui_args_uninit_sampler_t;
typedef struct sg_imgui_args_uninit_shader_t {
sg_shader shader;
} sg_imgui_args_uninit_shader_t;
typedef struct sg_imgui_args_uninit_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_uninit_pipeline_t;
typedef struct sg_imgui_args_uninit_pass_t {
sg_pass pass;
} sg_imgui_args_uninit_pass_t;
typedef struct sg_imgui_args_fail_buffer_t {
sg_buffer buffer;
} sg_imgui_args_fail_buffer_t;
typedef struct sg_imgui_args_fail_image_t {
sg_image image;
} sg_imgui_args_fail_image_t;
typedef struct sg_imgui_args_fail_sampler_t {
sg_sampler sampler;
} sg_imgui_args_fail_sampler_t;
typedef struct sg_imgui_args_fail_shader_t {
sg_shader shader;
} sg_imgui_args_fail_shader_t;
typedef struct sg_imgui_args_fail_pipeline_t {
sg_pipeline pipeline;
} sg_imgui_args_fail_pipeline_t;
typedef struct sg_imgui_args_fail_pass_t {
sg_pass pass;
} sg_imgui_args_fail_pass_t;
typedef struct sg_imgui_args_push_debug_group_t {
sg_imgui_str_t name;
} sg_imgui_args_push_debug_group_t;
typedef union sg_imgui_args_t {
sg_imgui_args_make_buffer_t make_buffer;
sg_imgui_args_make_image_t make_image;
sg_imgui_args_make_sampler_t make_sampler;
sg_imgui_args_make_shader_t make_shader;
sg_imgui_args_make_pipeline_t make_pipeline;
sg_imgui_args_make_pass_t make_pass;
sg_imgui_args_destroy_buffer_t destroy_buffer;
sg_imgui_args_destroy_image_t destroy_image;
sg_imgui_args_destroy_sampler_t destroy_sampler;
sg_imgui_args_destroy_shader_t destroy_shader;
sg_imgui_args_destroy_pipeline_t destroy_pipeline;
sg_imgui_args_destroy_pass_t destroy_pass;
sg_imgui_args_update_buffer_t update_buffer;
sg_imgui_args_update_image_t update_image;
sg_imgui_args_append_buffer_t append_buffer;
sg_imgui_args_begin_default_pass_t begin_default_pass;
sg_imgui_args_begin_pass_t begin_pass;
sg_imgui_args_apply_viewport_t apply_viewport;
sg_imgui_args_apply_scissor_rect_t apply_scissor_rect;
sg_imgui_args_apply_pipeline_t apply_pipeline;
sg_imgui_args_apply_bindings_t apply_bindings;
sg_imgui_args_apply_uniforms_t apply_uniforms;
sg_imgui_args_draw_t draw;
sg_imgui_args_alloc_buffer_t alloc_buffer;
sg_imgui_args_alloc_image_t alloc_image;
sg_imgui_args_alloc_sampler_t alloc_sampler;
sg_imgui_args_alloc_shader_t alloc_shader;
sg_imgui_args_alloc_pipeline_t alloc_pipeline;
sg_imgui_args_alloc_pass_t alloc_pass;
sg_imgui_args_dealloc_buffer_t dealloc_buffer;
sg_imgui_args_dealloc_image_t dealloc_image;
sg_imgui_args_dealloc_sampler_t dealloc_sampler;
sg_imgui_args_dealloc_shader_t dealloc_shader;
sg_imgui_args_dealloc_pipeline_t dealloc_pipeline;
sg_imgui_args_dealloc_pass_t dealloc_pass;
sg_imgui_args_init_buffer_t init_buffer;
sg_imgui_args_init_image_t init_image;
sg_imgui_args_init_sampler_t init_sampler;
sg_imgui_args_init_shader_t init_shader;
sg_imgui_args_init_pipeline_t init_pipeline;
sg_imgui_args_init_pass_t init_pass;
sg_imgui_args_uninit_buffer_t uninit_buffer;
sg_imgui_args_uninit_image_t uninit_image;
sg_imgui_args_uninit_sampler_t uninit_sampler;
sg_imgui_args_uninit_shader_t uninit_shader;
sg_imgui_args_uninit_pipeline_t uninit_pipeline;
sg_imgui_args_uninit_pass_t uninit_pass;
sg_imgui_args_fail_buffer_t fail_buffer;
sg_imgui_args_fail_image_t fail_image;
sg_imgui_args_fail_sampler_t fail_sampler;
sg_imgui_args_fail_shader_t fail_shader;
sg_imgui_args_fail_pipeline_t fail_pipeline;
sg_imgui_args_fail_pass_t fail_pass;
sg_imgui_args_push_debug_group_t push_debug_group;
} sg_imgui_args_t;
typedef struct sg_imgui_capture_item_t {
sg_imgui_cmd_t cmd;
uint32_t color;
sg_imgui_args_t args;
} sg_imgui_capture_item_t;
typedef struct sg_imgui_capture_bucket_t {
size_t ubuf_size; /* size of uniform capture buffer in bytes */
size_t ubuf_pos; /* current uniform buffer pos */
uint8_t* ubuf; /* buffer for capturing uniform updates */
int num_items;
sg_imgui_capture_item_t items[SG_IMGUI_MAX_FRAMECAPTURE_ITEMS];
} sg_imgui_capture_bucket_t;
/* double-buffered call-capture buckets, one bucket is currently recorded,
the previous bucket is displayed
*/
typedef struct sg_imgui_capture_t {
bool open;
int bucket_index; /* which bucket to record to, 0 or 1 */
int sel_item; /* currently selected capture item by index */
sg_imgui_capture_bucket_t bucket[2];
} sg_imgui_capture_t;
typedef struct sg_imgui_caps_t {
bool open;
} sg_imgui_caps_t;
/*
sg_imgui_allocator_t
Used in sg_imgui_desc_t to provide custom memory-alloc and -free functions
to sokol_gfx_imgui.h. If memory management should be overridden, both the
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
typedef struct sg_imgui_allocator_t {
void* (*alloc)(size_t size, void* user_data);
void (*free)(void* ptr, void* user_data);
void* user_data;
} sg_imgui_allocator_t;
/*
sg_imgui_desc_t
Initialization options for sg_imgui_init().
*/
typedef struct sg_imgui_desc_t {
sg_imgui_allocator_t allocator; // optional memory allocation overrides (default: malloc/free)
} sg_imgui_desc_t;
typedef struct sg_imgui_t {
uint32_t init_tag;
sg_imgui_desc_t desc;
sg_imgui_buffers_t buffers;
sg_imgui_images_t images;
sg_imgui_samplers_t samplers;
sg_imgui_shaders_t shaders;
sg_imgui_pipelines_t pipelines;
sg_imgui_passes_t passes;
sg_imgui_capture_t capture;
sg_imgui_caps_t caps;
sg_pipeline cur_pipeline;
sg_trace_hooks hooks;
} sg_imgui_t;
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_init(sg_imgui_t* ctx, const sg_imgui_desc_t* desc);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_discard(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_buffers_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_images_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_samplers_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_shaders_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_pipelines_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_passes_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capture_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capabilities_content(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_buffers_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_images_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_samplers_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_shaders_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_pipelines_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_passes_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capture_window(sg_imgui_t* ctx);
SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capabilities_window(sg_imgui_t* ctx);
#if defined(__cplusplus)
} /* extern "C" */
#endif
#endif /* SOKOL_GFX_IMGUI_INCLUDED */
/*=== IMPLEMENTATION =========================================================*/
#ifdef SOKOL_GFX_IMGUI_IMPL
#define SOKOL_GFX_IMGUI_IMPL_INCLUDED (1)
#if defined(SOKOL_MALLOC) || defined(SOKOL_CALLOC) || defined(SOKOL_FREE)
#error "SOKOL_MALLOC/CALLOC/FREE macros are no longer supported, please use sg_imgui_desc_t.allocator to override memory allocation functions"
#endif
#if defined(__cplusplus)
#if !defined(IMGUI_VERSION)
#error "Please include imgui.h before the sokol_imgui.h implementation"
#endif
#else
#if !defined(CIMGUI_INCLUDED)
#error "Please include cimgui.h before the sokol_imgui.h implementation"
#endif
#endif
#ifndef SOKOL_ASSERT
#include <assert.h>
#define SOKOL_ASSERT(c) assert(c)
#endif
#ifndef SOKOL_UNREACHABLE
#define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
#endif
#ifndef _SOKOL_PRIVATE
#if defined(__GNUC__) || defined(__clang__)
#define _SOKOL_PRIVATE __attribute__((unused)) static
#else
#define _SOKOL_PRIVATE static
#endif
#endif
#ifndef _SOKOL_UNUSED
#define _SOKOL_UNUSED(x) (void)(x)
#endif
#ifndef SOKOL_API_IMPL
#define SOKOL_API_IMPL
#endif
#include <string.h>
#include <stdio.h> // snprintf
#include <stdlib.h> // malloc, free
#define _SG_IMGUI_SLOT_MASK (0xFFFF)
#define _SG_IMGUI_LIST_WIDTH (192)
#define _SG_IMGUI_COLOR_OTHER 0xFFCCCCCC
#define _SG_IMGUI_COLOR_RSRC 0xFF00FFFF
#define _SG_IMGUI_COLOR_DRAW 0xFF00FF00
#define _SG_IMGUI_COLOR_ERR 0xFF8888FF
/*--- C => C++ layer ---------------------------------------------------------*/
#if defined(__cplusplus)
#define IMVEC2(x,y) ImVec2(x,y)
#define IMVEC4(x,y,z,w) ImVec4(x,y,z,w)
_SOKOL_PRIVATE void igText(const char* fmt,...) {
va_list args;
va_start(args, fmt);
ImGui::TextV(fmt, args);
va_end(args);
}
_SOKOL_PRIVATE void igSeparator() {
return ImGui::Separator();
}
_SOKOL_PRIVATE void igSameLine(float offset_from_start_x, float spacing) {
return ImGui::SameLine(offset_from_start_x,spacing);
}
_SOKOL_PRIVATE void igPushID_Int(int int_id) {
return ImGui::PushID(int_id);
}
_SOKOL_PRIVATE void igPopID() {
return ImGui::PopID();
}
_SOKOL_PRIVATE bool igSelectable_Bool(const char* label,bool selected,ImGuiSelectableFlags flags,const ImVec2 size) {
return ImGui::Selectable(label,selected,flags,size);
}
_SOKOL_PRIVATE bool igSmallButton(const char* label) {
return ImGui::SmallButton(label);
}
_SOKOL_PRIVATE bool igBeginChild_Str(const char* str_id,const ImVec2 size,bool border,ImGuiWindowFlags flags) {
return ImGui::BeginChild(str_id,size,border,flags);
}
_SOKOL_PRIVATE void igEndChild() {
return ImGui::EndChild();
}
_SOKOL_PRIVATE void igPushStyleColor_U32(ImGuiCol idx, ImU32 col) {
return ImGui::PushStyleColor(idx,col);
}
_SOKOL_PRIVATE void igPopStyleColor(int count) {
return ImGui::PopStyleColor(count);
}
_SOKOL_PRIVATE bool igTreeNode_StrStr(const char* str_id,const char* fmt,...) {
va_list args;
va_start(args, fmt);
bool ret = ImGui::TreeNodeV(str_id,fmt,args);
va_end(args);
return ret;
}
_SOKOL_PRIVATE bool igTreeNode_Str(const char* label) {
return ImGui::TreeNode(label);
}
_SOKOL_PRIVATE void igTreePop() {
return ImGui::TreePop();
}
_SOKOL_PRIVATE bool igIsItemHovered(ImGuiHoveredFlags flags) {
return ImGui::IsItemHovered(flags);
}
_SOKOL_PRIVATE void igSetTooltip(const char* fmt,...) {
va_list args;
va_start(args, fmt);
ImGui::SetTooltipV(fmt,args);
va_end(args);
}
_SOKOL_PRIVATE bool igSliderFloat(const char* label,float* v,float v_min,float v_max,const char* format,ImGuiSliderFlags flags) {
return ImGui::SliderFloat(label,v,v_min,v_max,format,flags);
}
_SOKOL_PRIVATE void igImage(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec4 tint_col,const ImVec4 border_col) {
return ImGui::Image(user_texture_id,size,uv0,uv1,tint_col,border_col);
}
_SOKOL_PRIVATE void igSetNextWindowSize(const ImVec2 size,ImGuiCond cond) {
return ImGui::SetNextWindowSize(size,cond);
}
_SOKOL_PRIVATE bool igBegin(const char* name,bool* p_open,ImGuiWindowFlags flags) {
return ImGui::Begin(name,p_open,flags);
}
_SOKOL_PRIVATE void igEnd() {
return ImGui::End();
}
#else
#define IMVEC2(x,y) (ImVec2){x,y}
#define IMVEC4(x,y,z,w) (ImVec4){x,y,z,w}
#endif
/*--- UTILS ------------------------------------------------------------------*/
_SOKOL_PRIVATE void _sg_imgui_clear(void* ptr, size_t size) {
SOKOL_ASSERT(ptr && (size > 0));
memset(ptr, 0, size);
}
_SOKOL_PRIVATE void* _sg_imgui_malloc(const sg_imgui_allocator_t* allocator, size_t size) {
SOKOL_ASSERT(allocator && (size > 0));
void* ptr;
if (allocator->alloc) {
ptr = allocator->alloc(size, allocator->user_data);
} else {
ptr = malloc(size);
}
SOKOL_ASSERT(ptr);
return ptr;
}
_SOKOL_PRIVATE void* _sg_imgui_malloc_clear(const sg_imgui_allocator_t* allocator, size_t size) {
void* ptr = _sg_imgui_malloc(allocator, size);
_sg_imgui_clear(ptr, size);
return ptr;
}
_SOKOL_PRIVATE void _sg_imgui_free(const sg_imgui_allocator_t* allocator, void* ptr) {
SOKOL_ASSERT(allocator);
if (allocator->free) {
allocator->free(ptr, allocator->user_data);
} else {
free(ptr);
}
}
_SOKOL_PRIVATE void* _sg_imgui_realloc(const sg_imgui_allocator_t* allocator, void* old_ptr, size_t old_size, size_t new_size) {
SOKOL_ASSERT(allocator && (new_size > 0) && (new_size > old_size));
void* new_ptr = _sg_imgui_malloc(allocator, new_size);
if (old_ptr) {
if (old_size > 0) {
memcpy(new_ptr, old_ptr, old_size);
}
_sg_imgui_free(allocator, old_ptr);
}
return new_ptr;
}
_SOKOL_PRIVATE int _sg_imgui_slot_index(uint32_t id) {
int slot_index = (int) (id & _SG_IMGUI_SLOT_MASK);
SOKOL_ASSERT(0 != slot_index);
return slot_index;
}
_SOKOL_PRIVATE uint32_t _sg_imgui_align_u32(uint32_t val, uint32_t align) {
SOKOL_ASSERT((align > 0) && ((align & (align - 1)) == 0));
return (val + (align - 1)) & ~(align - 1);
}
_SOKOL_PRIVATE uint32_t _sg_imgui_std140_uniform_alignment(sg_uniform_type type, int array_count) {
SOKOL_ASSERT(array_count > 0);
if (array_count == 1) {
switch (type) {
case SG_UNIFORMTYPE_FLOAT:
case SG_UNIFORMTYPE_INT:
return 4;
case SG_UNIFORMTYPE_FLOAT2:
case SG_UNIFORMTYPE_INT2:
return 8;
case SG_UNIFORMTYPE_FLOAT3:
case SG_UNIFORMTYPE_FLOAT4:
case SG_UNIFORMTYPE_INT3:
case SG_UNIFORMTYPE_INT4:
return 16;
case SG_UNIFORMTYPE_MAT4:
return 16;
default:
SOKOL_UNREACHABLE;
return 1;
}
} else {
return 16;
}
}
_SOKOL_PRIVATE uint32_t _sg_imgui_std140_uniform_size(sg_uniform_type type, int array_count) {
SOKOL_ASSERT(array_count > 0);
if (array_count == 1) {
switch (type) {
case SG_UNIFORMTYPE_FLOAT:
case SG_UNIFORMTYPE_INT:
return 4;
case SG_UNIFORMTYPE_FLOAT2:
case SG_UNIFORMTYPE_INT2:
return 8;
case SG_UNIFORMTYPE_FLOAT3: