summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/include/bgfx.c99.h
blob: 59928105623d1a8d2e9af3dd38afd93ba58b3331 (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
/*
 * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
 * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
 *
 * vim: set tabstop=4 expandtab:
 */

#ifndef BGFX_C99_H_HEADER_GUARD
#define BGFX_C99_H_HEADER_GUARD

#include <stdbool.h> // bool
#include <stdint.h>  // uint32_t
#include <stdlib.h>  // size_t

#include "bgfxdefines.h"

typedef enum bgfx_renderer_type
{
    BGFX_RENDERER_TYPE_NULL,
    BGFX_RENDERER_TYPE_DIRECT3D9,
    BGFX_RENDERER_TYPE_DIRECT3D11,
    BGFX_RENDERER_TYPE_DIRECT3D12,
    BGFX_RENDERER_TYPE_OPENGLES,
    BGFX_RENDERER_TYPE_OPENGL,
    BGFX_RENDERER_TYPE_VULKAN,

    BGFX_RENDERER_TYPE_COUNT

} bgfx_renderer_type_t;

typedef enum bgfx_access
{
    BGFX_ACCESS_READ,
    BGFX_ACCESS_WRITE,
    BGFX_ACCESS_READWRITE,

    BGFX_ACCESS_COUNT

} bgfx_access_t;

typedef enum bgfx_attrib
{
    BGFX_ATTRIB_POSITION,
    BGFX_ATTRIB_NORMAL,
    BGFX_ATTRIB_TANGENT,
    BGFX_ATTRIB_BITANGENT,
    BGFX_ATTRIB_COLOR0,
    BGFX_ATTRIB_COLOR1,
    BGFX_ATTRIB_INDICES,
    BGFX_ATTRIB_WEIGHT,
    BGFX_ATTRIB_TEXCOORD0,
    BGFX_ATTRIB_TEXCOORD1,
    BGFX_ATTRIB_TEXCOORD2,
    BGFX_ATTRIB_TEXCOORD3,
    BGFX_ATTRIB_TEXCOORD4,
    BGFX_ATTRIB_TEXCOORD5,
    BGFX_ATTRIB_TEXCOORD6,
    BGFX_ATTRIB_TEXCOORD7,

    BGFX_ATTRIB_COUNT

} bgfx_attrib_t;

typedef enum bgfx_attrib_type
{
    BGFX_ATTRIB_TYPE_UINT8,
    BGFX_ATTRIB_TYPE_INT16,
    BGFX_ATTRIB_TYPE_HALF,
    BGFX_ATTRIB_TYPE_FLOAT,

    BGFX_ATTRIB_TYPE_COUNT

} bgfx_attrib_type_t;

typedef enum bgfx_texture_format
{
    BGFX_TEXTURE_FORMAT_BC1,
    BGFX_TEXTURE_FORMAT_BC2,
    BGFX_TEXTURE_FORMAT_BC3,
    BGFX_TEXTURE_FORMAT_BC4,
    BGFX_TEXTURE_FORMAT_BC5,
    BGFX_TEXTURE_FORMAT_BC6H,
    BGFX_TEXTURE_FORMAT_BC7,
    BGFX_TEXTURE_FORMAT_ETC1,
    BGFX_TEXTURE_FORMAT_ETC2,
    BGFX_TEXTURE_FORMAT_ETC2A,
    BGFX_TEXTURE_FORMAT_ETC2A1,
    BGFX_TEXTURE_FORMAT_PTC12,
    BGFX_TEXTURE_FORMAT_PTC14,
    BGFX_TEXTURE_FORMAT_PTC12A,
    BGFX_TEXTURE_FORMAT_PTC14A,
    BGFX_TEXTURE_FORMAT_PTC22,
    BGFX_TEXTURE_FORMAT_PTC24,

    BGFX_TEXTURE_FORMAT_UNKNOWN,

    BGFX_TEXTURE_FORMAT_R1,
    BGFX_TEXTURE_FORMAT_R8,
    BGFX_TEXTURE_FORMAT_R16,
    BGFX_TEXTURE_FORMAT_R16F,
    BGFX_TEXTURE_FORMAT_R32,
    BGFX_TEXTURE_FORMAT_R32F,
    BGFX_TEXTURE_FORMAT_RG8,
    BGFX_TEXTURE_FORMAT_RG16,
    BGFX_TEXTURE_FORMAT_RG16F,
    BGFX_TEXTURE_FORMAT_RG32,
    BGFX_TEXTURE_FORMAT_RG32F,
    BGFX_TEXTURE_FORMAT_BGRA8,
    BGFX_TEXTURE_FORMAT_RGBA8,
    BGFX_TEXTURE_FORMAT_RGBA16,
    BGFX_TEXTURE_FORMAT_RGBA16F,
    BGFX_TEXTURE_FORMAT_RGBA32,
    BGFX_TEXTURE_FORMAT_RGBA32F,
    BGFX_TEXTURE_FORMAT_R5G6B5,
    BGFX_TEXTURE_FORMAT_RGBA4,
    BGFX_TEXTURE_FORMAT_RGB5A1,
    BGFX_TEXTURE_FORMAT_RGB10A2,
    BGFX_TEXTURE_FORMAT_R11G11B10F,

    BGFX_TEXTURE_FORMAT_UNKNOWN_DEPTH,

    BGFX_TEXTURE_FORMAT_D16,
    BGFX_TEXTURE_FORMAT_D24,
    BGFX_TEXTURE_FORMAT_D24S8,
    BGFX_TEXTURE_FORMAT_D32,
    BGFX_TEXTURE_FORMAT_D16F,
    BGFX_TEXTURE_FORMAT_D24F,
    BGFX_TEXTURE_FORMAT_D32F,
    BGFX_TEXTURE_FORMAT_D0S8,

    BGFX_TEXTURE_FORMAT_COUNT

} bgfx_texture_format_t;

typedef enum bgfx_uniform_type
{
    BGFX_UNIFORM_TYPE_UNIFORM1I,
    BGFX_UNIFORM_TYPE_UNIFORM1F,
    BGFX_UNIFORM_TYPE_END,

    BGFX_UNIFORM_TYPE_UNIFORM1IV,
    BGFX_UNIFORM_TYPE_UNIFORM1FV,
    BGFX_UNIFORM_TYPE_UNIFORM2FV,
    BGFX_UNIFORM_TYPE_UNIFORM3FV,
    BGFX_UNIFORM_TYPE_UNIFORM4FV,
    BGFX_UNIFORM_TYPE_UNIFORM3X3FV,
    BGFX_UNIFORM_TYPE_UNIFORM4X4FV,

    BGFX_UNIFORM_TYPE_COUNT

} bgfx_uniform_type_t;

#define BGFX_HANDLE_T(_name) \
    typedef struct _name { uint16_t idx; } _name##_t;

BGFX_HANDLE_T(bgfx_dynamic_index_buffer_handle);
BGFX_HANDLE_T(bgfx_dynamic_vertex_buffer_handle);
BGFX_HANDLE_T(bgfx_frame_buffer_handle);
BGFX_HANDLE_T(bgfx_index_buffer_handle);
BGFX_HANDLE_T(bgfx_program_handle);
BGFX_HANDLE_T(bgfx_shader_handle);
BGFX_HANDLE_T(bgfx_texture_handle);
BGFX_HANDLE_T(bgfx_uniform_handle);
BGFX_HANDLE_T(bgfx_vertex_buffer_handle);
BGFX_HANDLE_T(bgfx_vertex_decl_handle);

#undef BGFX_HANDLE_T

/**
 *
 */
typedef void (*bgfx_release_fn_t)(void* _ptr, void* _userData);

/**
 *
 */
typedef struct bgfx_memory
{
    uint8_t* data;
    uint32_t size;

} bgfx_memory_t;

/**
 *
 */
typedef struct bgfx_transform
{
    float* data;
    uint16_t num;

} bgfx_transform_t;

/**
 * Eye
 */
typedef struct bgfx_hmd_eye
{
    float rotation[4];
    float translation[3];
    float fov[4];
    float adjust[3];
    float pixelsPerTanAngle[2];

} bgfx_hmd_eye_t;

/**
 * HMD
 */
typedef struct bgfx_hmd
{
    bgfx_hmd_eye_t eye[2];
    uint16_t width;
    uint16_t height;

} bgfx_hmd_t;

/**
 * Vertex declaration.
 */
typedef struct bgfx_vertex_decl
{
    uint32_t hash;
    uint16_t stride;
    uint16_t offset[BGFX_ATTRIB_COUNT];
    uint8_t  attributes[BGFX_ATTRIB_COUNT];

} bgfx_vertex_decl_t;

/**
 */
typedef struct bgfx_transient_index_buffer
{
    uint8_t* data;
    uint32_t size;
    bgfx_index_buffer_handle_t handle;
    uint32_t startIndex;

} bgfx_transient_index_buffer_t;

/**
 */
typedef struct bgfx_transient_vertex_buffer
{
    uint8_t* data;
    uint32_t size;
    uint32_t startVertex;
    uint16_t stride;
    bgfx_vertex_buffer_handle_t handle;
    bgfx_vertex_decl_handle_t decl;

} bgfx_transient_vertex_buffer_t;

/**
 */
typedef struct bgfx_instance_data_buffer
{
    uint8_t* data;
    uint32_t size;
    uint32_t offset;
    uint32_t num;
    uint16_t stride;
    bgfx_vertex_buffer_handle_t handle;

} bgfx_instance_data_buffer_t;

/**
 */
typedef struct bgfx_texture_info
{
    bgfx_texture_format_t format;
    uint32_t storageSize;
    uint16_t width;
    uint16_t height;
    uint16_t depth;
    uint8_t numMips;
    uint8_t bitsPerPixel;
    bool    cubeMap;

} bgfx_texture_info_t;

/**
 */
typedef struct bgfx_caps_gpu
{
    uint16_t vendorId;
    uint16_t deviceId;

} bgfx_caps_gpu_t;

/**
 *  Renderer capabilities.
 */
typedef struct bgfx_caps
{
    /**
     *  Renderer backend type.
     */
    bgfx_renderer_type_t rendererType;

    /**
     *  Supported functionality, it includes emulated functionality.
     *  Checking supported and not emulated will give functionality
     *  natively supported by renderer.
     */
    uint64_t supported;

    uint32_t maxDrawCalls;      /* < Maximum draw calls.               */
    uint16_t maxTextureSize;    /* < Maximum texture size.             */
    uint16_t maxViews;          /* < Maximum views.                    */
    uint8_t  maxFBAttachments;  /* < Maximum frame buffer attachments. */
    uint8_t  numGPUs;           /* <                                   */

    uint16_t vendorId;          /* <                                   */
    uint16_t deviceId;          /* <                                   */
    bgfx_caps_gpu_t gpu[4];     /* <                                   */

    /**
     *  Supported texture formats.
     *   `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
     *   `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
     *   `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
     *   `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
     */
    uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT];

} bgfx_caps_t;

/**
 */
typedef enum bgfx_fatal
{
    BGFX_FATAL_DEBUG_CHECK,
    BGFX_FATAL_MINIMUM_REQUIRED_SPECS,
    BGFX_FATAL_INVALID_SHADER,
    BGFX_FATAL_UNABLE_TO_INITIALIZE,
    BGFX_FATAL_UNABLE_TO_CREATE_TEXTURE,
    BGFX_FATAL_DEVICE_LOST,

    BGFX_FATAL_COUNT

} bgfx_fatal_t;

#ifndef BGFX_SHARED_LIB_BUILD
#    define BGFX_SHARED_LIB_BUILD 0
#endif // BGFX_SHARED_LIB_BUILD

#ifndef BGFX_SHARED_LIB_USE
#    define BGFX_SHARED_LIB_USE 0
#endif // BGFX_SHARED_LIB_USE

#if defined(_MSC_VER)
#   define BGFX_VTBL_CALL __stdcall
#   define BGFX_VTBL_THIS  // passed via ecx
#   define BGFX_VTBL_THIS_ // passed via ecx
#   if BGFX_SHARED_LIB_BUILD
#       define BGFX_SHARED_LIB_API __declspec(dllexport)
#   elif BGFX_SHARED_LIB_USE
#       define BGFX_SHARED_LIB_API __declspec(dllimport)
#   else
#       define BGFX_SHARED_LIB_API
#   endif // BGFX_SHARED_LIB_*
#else
#   define BGFX_VTBL_CALL
#   define BGFX_VTBL_THIS  BGFX_VTBL_INTEFRACE _this
#   define BGFX_VTBL_THIS_ BGFX_VTBL_INTEFRACE _this,
#   define BGFX_SHARED_LIB_API
#endif // defined(_MSC_VER)

#if defined(__cplusplus)
#   define BGFX_C_API extern "C" BGFX_SHARED_LIB_API
#else
#   define BGFX_C_API BGFX_SHARED_LIB_API
#endif // defined(__cplusplus)

/**
 */
typedef struct bgfx_callback_interface
{
    const struct bgfx_callback_vtbl* vtbl;

} bgfx_callback_interface_t;

/**
 *  Callback interface to implement application specific behavior.
 *  Cached items are currently used only for OpenGL binary shaders.
 *
 *  NOTE:
 *    'fatal' callback can be called from any thread. Other callbacks
 *    are called from the render thread.
 */
typedef struct bgfx_callback_vtbl
{
#   define BGFX_VTBL_INTEFRACE bgfx_callback_interface_t

    void* ctor;

    /**
     *  If fatal code code is not BGFX_FATAL_DEBUG_CHECK this callback is
     *  called on unrecoverable error. It's not safe to continue, inform
     *  user and terminate application from this call.
     */
    void (BGFX_VTBL_CALL *fatal)(BGFX_VTBL_THIS_ bgfx_fatal_t _code, const char* _str);

    /**
     *  Return size of for cached item. Return 0 if no cached item was
     *  found.
     */
    uint32_t (BGFX_VTBL_CALL *cache_read_size)(BGFX_VTBL_THIS_ uint64_t _id);

    /**
     *  Read cached item.
     */
    bool (BGFX_VTBL_CALL *cache_read)(BGFX_VTBL_THIS_ uint64_t _id, void* _data, uint32_t _size);

    /**
     *  Write cached item.
     */
    void (BGFX_VTBL_CALL *cache_write)(BGFX_VTBL_THIS_ uint64_t _id, const void* _data, uint32_t _size);

    /**
     *  Screenshot captured. Screenshot format is always 4-byte BGRA.
     */
    void (BGFX_VTBL_CALL *screen_shot)(BGFX_VTBL_THIS_ const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip);

    /**
     *  Called when capture begins.
     */
    void (BGFX_VTBL_CALL *capture_begin)(BGFX_VTBL_THIS_ uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, bool _yflip);

    /**
     *  Called when capture ends.
     */
    void (BGFX_VTBL_CALL *capture_end)(BGFX_VTBL_THIS);

    /**
     *  Captured frame.
     */
    void (BGFX_VTBL_CALL *capture_frame)(BGFX_VTBL_THIS_ const void* _data, uint32_t _size);

#   undef BGFX_VTBL_INTEFRACE

} bgfx_callback_vtbl_t;

/**
 */
typedef struct bgfx_reallocator_interface
{
    const struct bgfx_reallocator_vtbl* vtbl;

} bgfx_reallocator_interface_t;

/**
 */
typedef struct bgfx_reallocator_vtbl
{
#   define BGFX_VTBL_INTEFRACE bgfx_reallocator_interface_t

    void* ctor;
    void* (BGFX_VTBL_CALL *alloc)(BGFX_VTBL_THIS_ size_t _size, size_t _align, const char* _file, uint32_t _line);
    void  (BGFX_VTBL_CALL *free)(BGFX_VTBL_THIS_ void* _ptr, size_t _align, const char* _file, uint32_t _line);
    void* (BGFX_VTBL_CALL *realloc)(BGFX_VTBL_THIS_ void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line);

#   undef BGFX_VTBL_INTEFRACE

} bgfx_reallocator_vtbl_t;

/**
 *  Start vertex declaration.
 */
BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer);

/**
 *  Add attribute to vertex declaration.
 *
 *  @param _attrib Attribute semantics.
 *  @param _num Number of elements 1, 2, 3 or 4.
 *  @param _type Element type.
 *  @param _normalized When using fixed point AttribType (f.e. Uint8)
 *    value will be normalized for vertex shader usage. When normalized
 *    is set to true, AttribType::Uint8 value in range 0-255 will be
 *    in range 0.0-1.0 in vertex shader.
 *  @param _asInt Packaging rule for vertexPack, vertexUnpack, and
 *    vertexConvert for AttribType::Uint8 and AttribType::Int16.
 *    Unpacking code must be implemented inside vertex shader.
 *
 *  NOTE:
 *    Must be called between begin/end.
 */
BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt);

/**
 *  Skip _num bytes in vertex stream.
 */
BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _decl, uint8_t _num);

/**
 *  End vertex declaration.
 */
BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _decl);

/**
 *  Pack vec4 into vertex stream format.
 */
BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index);

/**
 *  Unpack vec4 from vertex stream format.
 */
BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index);

/**
 *  Converts vertex stream data from one vertex stream format to another.
 *
 *  @param _destDecl Destination vertex stream declaration.
 *  @param _destData Destination vertex stream.
 *  @param _srcDecl Source vertex stream declaration.
 *  @param _srcData Source vertex stream data.
 *  @param _num Number of vertices to convert from source to destination.
 */
BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num);

/**
 *  Weld vertices.
 *
 *  @param _output Welded vertices remapping table. The size of buffer
 *    must be the same as number of vertices.
 *  @param _decl Vertex stream declaration.
 *  @param _data Vertex stream.
 *  @param _num Number of vertices in vertex stream.
 *  @param _epsilon Error tolerance for vertex position comparison.
 *  @returns Number of unique vertices after vertex welding.
 */
BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon);

/**
 *  Swizzle RGBA8 image to BGRA8.
 *
 *  @param _width Width of input image (pixels).
 *  @param _height Height of input image (pixels).
 *  @param _pitch Pitch of input image (bytes).
 *  @param _src Source image.
 *  @param _dst Destination image. Must be the same size as input image.
 *    _dst might be pointer to the same memory as _src.
 */
BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);

/**
 *  Downsample RGBA8 image with 2x2 pixel average filter.
 *
 *  @param _width Width of input image (pixels).
 *  @param _height Height of input image (pixels).
 *  @param _pitch Pitch of input image (bytes).
 *  @param _src Source image.
 *  @param _dst Destination image. Must be at least quarter size of
 *    input image. _dst might be pointer to the same memory as _src.
 */
BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);

/**
 *  Returns supported backend API renderers.
 */
BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);

/**
 *  Returns name of renderer.
 */
BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type);

/**
 *  Initialize bgfx library.
 *
 *  @param _type Select rendering backend. When set to RendererType::Count
 *    default rendering backend will be selected.
 *
 *  @param _callback Provide application specific callback interface.
 *    See: CallbackI
 *
 *  @param _reallocator Custom allocator. When custom allocator is not
 *    specified, library uses default CRT allocator. The library assumes
 *    custom allocator is thread safe.
 */
BGFX_C_API void bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_reallocator_interface_t* _allocator);

/**
 *  Shutdown bgfx library.
 */
BGFX_C_API void bgfx_shutdown();

/**
 *  Reset graphic settings.
 */
BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags);

/**
 *  Advance to next frame. When using multithreaded renderer, this call
 *  just swaps internal buffers, kicks render thread, and returns. In
 *  singlethreaded renderer this call does frame rendering.
 *
 *  @returns Current frame number. This might be used in conjunction with
 *    double/multi buffering data outside the library and passing it to
 *    library via makeRef calls.
 */
BGFX_C_API uint32_t bgfx_frame();

/**
 *  Returns current renderer backend API type.
 *
 *  NOTE:
 *    Library must be initialized.
 */
BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type();

/**
 *  Returns renderer capabilities.
 *
 *  NOTE:
 *    Library must be initialized.
 */
BGFX_C_API const bgfx_caps_t* bgfx_get_caps();

/**
 * Returns HMD info.
 */
BGFX_C_API const bgfx_hmd_t* bgfx_get_hmd();

/**
 *  Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
 */
BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size);

/**
 *  Allocate buffer and copy data into it. Data will be freed inside bgfx.
 */
BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size);

/**
 *  Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
 *  doesn't allocate memory for data. It just copies pointer to data.
 *  You must make sure data is available for at least 2 bgfx::frame calls.
 */
BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size);

/**
 *
 */
BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData);

/**
 *  Set debug flags.
 *
 *  @param _debug Available flags:
 *
 *    BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
 *      all rendering calls will be skipped. It's useful when profiling
 *      to quickly assess bottleneck between CPU and GPU.
 *
 *    BGFX_DEBUG_STATS - Display internal statistics.
 *
 *    BGFX_DEBUG_TEXT - Display debug text.
 *
 *    BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
 *      primitives will be rendered as lines.
 */
BGFX_C_API void bgfx_set_debug(uint32_t _debug);

/**
 *  Clear internal debug text buffer.
 */
BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small);

/**
 *  Print into internal debug text buffer.
 */
BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);

/**
 *  Draw image into internal debug text buffer.
 *
 *  @param _x      X position from top-left.
 *  @param _y      Y position from top-left.
 *  @param _width  Image width.
 *  @param _height Image height.
 *  @param _data   Raw image data (character/attribute raw encoding).
 *  @param _pitch  Image pitch in bytes.
 */
BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);

/**
 *  Create static index buffer.
 *
 *  NOTE:
 *    Only 16-bit index buffer is supported.
 */
BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem);

/**
 *  Destroy static index buffer.
 */
BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle);

/**
 *  Create static vertex buffer.
 *
 *  @param _mem Vertex buffer data.
 *  @param _decl Vertex declaration.
 *  @returns Static vertex buffer handle.
 */
BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags);

/**
 *  Destroy static vertex buffer.
 *
 *  @param _handle Static vertex buffer handle.
 */
BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle);

/**
 *  Create empty dynamic index buffer.
 *
 *  @param _num Number of indices.
 *
 *  NOTE:
 *    Only 16-bit index buffer is supported.
 */
BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num);

/**
 *  Create dynamic index buffer and initialized it.
 *
 *  @param _mem Index buffer data.
 *
 *  NOTE:
 *    Only 16-bit index buffer is supported.
 */
BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem);

/**
 *  Update dynamic index buffer.
 *
 *  @param _handle Dynamic index buffer handle.
 *  @param _mem Index buffer data.
 */
BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, const bgfx_memory_t* _mem);

/**
 *  Destroy dynamic index buffer.
 *
 *  @param _handle Dynamic index buffer handle.
 */
BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle);

/**
 *  Create empty dynamic vertex buffer.
 *
 *  @param _num Number of vertices.
 *  @param _decl Vertex declaration.
 */
BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint8_t _flags);

/**
 *  Create dynamic vertex buffer and initialize it.
 *
 *  @param _mem Vertex buffer data.
 *  @param _decl Vertex declaration.
 */
BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl);

/**
 *  Update dynamic vertex buffer.
 */
BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, const bgfx_memory_t* _mem);

/**
 *  Destroy dynamic vertex buffer.
 */
BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle);

/**
 *  Returns true if internal transient index buffer has enough space.
 *
 *  @param _num Number of indices.
 */
BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num);

/**
 *  Returns true if internal transient vertex buffer has enough space.
 *
 *  @param _num Number of vertices.
 *  @param _decl Vertex declaration.
 */
BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl);

/**
 *  Returns true if internal instance data buffer has enough space.
 *
 *  @param _num Number of instances.
 *  @param _stride Stride per instance.
 */
BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride);

/**
 *  Returns true if both internal transient index and vertex buffer have
 *  enough space.
 *
 *  @param _numVertices Number of vertices.
 *  @param _decl Vertex declaration.
 *  @param _numIndices Number of indices.
 */
BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices);

/**
 *  Allocate transient index buffer.
 *
 *  @param[out] _tib TransientIndexBuffer structure is filled and is valid
 *    for the duration of frame, and it can be reused for multiple draw
 *    calls.
 *  @param _num Number of indices to allocate.
 *
 *  NOTE:
 *    1. You must call setIndexBuffer after alloc in order to avoid memory
 *       leak.
 *    2. Only 16-bit index buffer is supported.
 */
BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num);

/**
 *  Allocate transient vertex buffer.
 *
 *  @param[out] _tvb TransientVertexBuffer structure is filled and is valid
 *    for the duration of frame, and it can be reused for multiple draw
 *    calls.
 *  @param _num Number of vertices to allocate.
 *  @param _decl Vertex declaration.
 *
 *  NOTE:
 *    You must call setVertexBuffer after alloc in order to avoid memory
 *    leak.
 */
BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl);

/**
 *  Check for required space and allocate transient vertex and index
 *  buffers. If both space requirements are satisfied function returns
 *  true.
 *
 *  NOTE:
 *    Only 16-bit index buffer is supported.
 */
BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices);

/**
 *  Allocate instance data buffer.
 *
 *  NOTE:
 *    You must call setInstanceDataBuffer after alloc in order to avoid
 *    memory leak.
 */
BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(uint32_t _num, uint16_t _stride);

/**
 *  Create shader from memory buffer.
 */
BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem);

/**
 *  Returns num of uniforms, and uniform handles used inside shader.
 *
 *  @param _handle Shader handle.
 *  @param _uniforms UniformHandle array where data will be stored.
 *  @param _max Maximum capacity of array.
 *  @returns Number of uniforms used by shader.
 *
 *  NOTE:
 *    Only non-predefined uniforms are returned.
 */
BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max);

/**
 *  Destroy shader. Once program is created with shader it is safe to
 *  destroy shader.
 */
BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle);

/**
 *  Create program with vertex and fragment shaders.
 *
 *  @param _vsh Vertex shader.
 *  @param _fsh Fragment shader.
 *  @param _destroyShaders If true, shaders will be destroyed when
 *    program is destroyed.
 *  @returns Program handle if vertex shader output and fragment shader
 *    input are matching, otherwise returns invalid program handle.
 */
BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);

/**
 *  Destroy program.
 */
BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle);

/**
 *  Calculate amount of memory required for texture.
 */
BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format);

/**
 *  Create texture from memory buffer.
 *
 *  @param _mem DDS, KTX or PVR texture data.
 *  @param _flags Default texture sampling mode is linear, and wrap mode
 *    is repeat.
 *
 *    BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
 *      mode.
 *
 *    BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
 *      sampling.
 *
 *  @param _skip Skip top level mips when parsing texture.
 *  @param _info Returns parsed texture information.
 *  @returns Texture handle.
 */
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);

/**
 *  Create 2D texture.
 *
 *  @param _width
 *  @param _height
 *  @param _numMips
 *  @param _format
 *  @param _flags
 *  @param _mem
 */
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);

/**
 *  Create 3D texture.
 *
 *  @param _width
 *  @param _height
 *  @param _depth
 *  @param _numMips
 *  @param _format
 *  @param _flags
 *  @param _mem
 */
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);

/**
 *  Create Cube texture.
 *
 *  @param _size
 *  @param _numMips
 *  @param _format
 *  @param _flags
 *  @param _mem
 */
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);

/**
 *  Update 2D texture.
 *
 *  @param _handle
 *  @param _mip
 *  @param _x
 *  @param _y
 *  @param _width
 *  @param _height
 *  @param _mem
 *  @param _pitch Pitch of input image (bytes). When _pitch is set to
 *    UINT16_MAX, it will be calculated internally based on _width.
 */
BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);

/**
 *  Update 3D texture.
 *
 *  @param _handle
 *  @param _mip
 *  @param _x
 *  @param _y
 *  @param _z
 *  @param _width
 *  @param _height
 *  @param _depth
 *  @param _mem
 */
BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);

/**
 *  Update Cube texture.
 *
 *  @param _handle
 *  @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
 *    -Y, 4 is +Z, and 5 is -Z.
 *
 *               +----------+
 *               |-z       2|
 *               | ^  +y    |
 *               | |        |
 *               | +---->+x |
 *    +----------+----------+----------+----------+
 *    |+y       1|+y       4|+y       0|+y       5|
 *    | ^  -x    | ^  +z    | ^  +x    | ^  -z    |
 *    | |        | |        | |        | |        |
 *    | +---->+z | +---->+x | +---->-z | +---->-x |
 *    +----------+----------+----------+----------+
 *               |+z       3|
 *               | ^  -y    |
 *               | |        |
 *               | +---->+x |
 *               +----------+
 *
 *  @param _mip
 *  @param _x
 *  @param _y
 *  @param _width
 *  @param _height
 *  @param _mem
 *  @param _pitch Pitch of input image (bytes). When _pitch is set to
 *    UINT16_MAX, it will be calculated internally based on _width.
 */
BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);

/**
 *  Destroy texture.
 */
BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle);

/**
 *  Create frame buffer (simple).
 *
 *  @param _width Texture width.
 *  @param _height Texture height.
 *  @param _format Texture format.
 *  @param _textureFlags Texture flags.
 */
BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);

/**
 *  Create frame buffer.
 *
 *  @param _num Number of texture attachments.
 *  @param _handles Texture attachments.
 *  @param _destroyTextures If true, textures will be destroyed when
 *    frame buffer is destroyed.
 */
BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures);

/**
 *  Create frame buffer for multiple window rendering.
 *
 *  @param _nwh OS' target native window handle.
 *  @param _width Window back buffer width.
 *  @param _height Window back buffer height.
 *  @param _depthFormat Window back buffer depth format.
 *
 *  NOTE:
 *    Frame buffer cannnot be used for sampling.
 */
BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat);

/**
 *  Destroy frame buffer.
 */
BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle);

/**
 *  Create shader uniform parameter.
 *
 *  @param _name Uniform name in shader.
 *  @param _type Type of uniform (See: UniformType).
 *  @param _num Number of elements in array.
 *
 *  Predefined uniforms:
 *
 *    u_viewRect vec4(x, y, width, height) - view rectangle for current
 *      view.
 *
 *    u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
 *      width and height
 *
 *    u_view mat4 - view matrix
 *
 *    u_invView mat4 - inverted view matrix
 *
 *    u_proj mat4 - projection matrix
 *
 *    u_invProj mat4 - inverted projection matrix
 *
 *    u_viewProj mat4 - concatenated view projection matrix
 *
 *    u_invViewProj mat4 - concatenated inverted view projection matrix
 *
 *    u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
 *
 *    u_modelView mat4 - concatenated model view matrix, only first
 *      model matrix from array is used.
 *
 *    u_modelViewProj mat4 - concatenated model view projection matrix.
 *
 *    u_alphaRef float - alpha reference value for alpha test.
 */
BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);

/**
 *  Destroy shader uniform parameter.
 */
BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle);

/**
 *  Set clear color palette value.
 *
 *  @param _index Index into palette.
 *  @param _rgba RGBA floating point value.
 */
BGFX_C_API void bgfx_set_clear_color(uint8_t _index, const float _rgba[4]);

/**
 *  Set view name.
 *
 *  @param _id View id.
 *  @param _name View name.
 *
 *  NOTE:
 *    This is debug only feature.
 */
BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name);

/**
 *  Set view rectangle. Draw primitive outside view will be clipped.
 *
 *  @param _id View id.
 *  @param _x Position x from the left corner of the window.
 *  @param _y Position y from the top corner of the window.
 *  @param _width Width of view port region.
 *  @param _height Height of view port region.
 */
BGFX_C_API void bgfx_set_view_rect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);

/**
 *  Set view scissor. Draw primitive outside view will be clipped. When
 *  _x, _y, _width and _height are set to 0, scissor will be disabled.
 *
 *  @param _x Position x from the left corner of the window.
 *  @param _y Position y from the top corner of the window.
 *  @param _width Width of scissor region.
 *  @param _height Height of scissor region.
 */
BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);

/**
 *  Set view clear flags.
 *
 *  @param _id View id.
 *  @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
 *    operation. See: BGFX_CLEAR_*.
 *  @param _rgba Color clear value.
 *  @param _depth Depth clear value.
 *  @param _stencil Stencil clear value.
 */
BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);

/**
 *  Set view clear flags with different clear color for each
 *  frame buffer texture. Must use setClearColor to setup clear color
 *  palette.

 *  @param _id View id.
 *  @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
 *  operation. See: BGFX_CLEAR_*.
 *  @param _depth Depth clear value.
 *  @param _stencil Stencil clear value.
 */
BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);

/**
 *  Set view into sequential mode. Draw calls will be sorted in the same
 *  order in which submit calls were called.
 */
BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled);

/**
 *  Set view frame buffer.
 *
 *  @param _id View id.
 *  @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as
 *    frame buffer handle will draw primitives from this view into
 *    default back buffer.
 */
BGFX_C_API void bgfx_set_view_frame_buffer(uint8_t _id, bgfx_frame_buffer_handle_t _handle);

/**
 *  Set view view and projection matrices, all draw primitives in this
 *  view will use these matrices.
 */
BGFX_C_API void bgfx_set_view_transform(uint8_t _id, const void* _view, const void* _proj);

/**
 *  Set view view and projection matrices, all draw primitives in this
 *  view will use these matrices.
 */
BGFX_C_API void bgfx_set_view_transform_stereo(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR);

/**
 *  Sets debug marker.
 */
BGFX_C_API void bgfx_set_marker(const char* _marker);

/**
 *  Set render states for draw primitive.
 *
 *  @param _state State flags. Default state for primitive type is
 *    triangles. See: BGFX_STATE_DEFAULT.
 *
 *    BGFX_STATE_ALPHA_WRITE - Enable alpha write.
 *    BGFX_STATE_DEPTH_WRITE - Enable depth write.
 *    BGFX_STATE_DEPTH_TEST_* - Depth test function.
 *    BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
 *    BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
 *    BGFX_STATE_CULL_* - Backface culling mode.
 *    BGFX_STATE_RGB_WRITE - Enable RGB write.
 *    BGFX_STATE_MSAA - Enable MSAA.
 *    BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
 *
 *  @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
 *    BGFX_STATE_BLEND_INV_FACTOR blend modes.
 *
 *  NOTE:
 *    1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
 *       BGFX_STATE_BLEND_FUNC macros to setup more complex states.
 *    2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
 *       equation is specified.
 */
BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba);

/**
 *  Set stencil test state.
 *
 *  @param _fstencil Front stencil state.
 *  @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
 *    _fstencil is applied to both front and back facing primitives.
 */
BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil);

/**
 *  Set scissor for draw primitive. For scissor for all primitives in
 *  view see setViewScissor.
 *
 *  @param _x Position x from the left corner of the window.
 *  @param _y Position y from the top corner of the window.
 *  @param _width Width of scissor region.
 *  @param _height Height of scissor region.
 *  @returns Scissor cache index.
 */
BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);

/**
 *  Set scissor from cache for draw primitive.
 *
 *  @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
 *    scissor and primitive will use view scissor instead.
 */
BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache);

/**
 *  Set model matrix for draw primitive. If it is not called model will
 *  be rendered with identity model matrix.
 *
 *  @param _mtx Pointer to first matrix in array.
 *  @param _num Number of matrices in array.
 *  @returns index into matrix cache in case the same model matrix has
 *    to be used for other draw primitive call.
 */
BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num);

/**
 *  Reserve `_num` matrices in internal matrix cache. Pointer returned
 *  can be modifed until `bgfx::frame` is called.
 *
 *  @param _transform Pointer to `Transform` structure.
 *  @param _num Number of matrices.
 *  @returns index into matrix cache.
 */
BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num);

/**
 *  Set model matrix from matrix cache for draw primitive.
 *
 *  @param _cache Index in matrix cache.
 *  @param _num Number of matrices from cache.
 */
BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num);

/**
 *  Set shader uniform parameter for draw primitive.
 */
BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num);

/**
 *  Set index buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);

/**
 *  Set index buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);

/**
 *  Set index buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices);

/**
 *  Set vertex buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);

/**
 *  Set vertex buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices);

/**
 *  Set vertex buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_transient_vertex_buffer(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices);

/**
 *  Set instance data buffer for draw primitive.
 */
BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _num);

/**
 *  Set program for draw primitive.
 */
BGFX_C_API void bgfx_set_program(bgfx_program_handle_t _handle);

/**
 *  Set texture stage for draw primitive.
 *
 *  @param _stage Texture unit.
 *  @param _sampler Program sampler.
 *  @param _handle Texture handle.
 *  @param _flags Texture sampling mode. Default value UINT32_MAX uses
 *    texture sampling settings from the texture.
 *
 *    BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
 *      mode.
 *
 *    BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
 *      sampling.
 *
 *  @param _flags Texture sampler filtering flags. UINT32_MAX use the
 *    sampler filtering mode set by texture.
 */
BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);

/**
 *  Set texture stage for draw primitive.
 *
 *  @param _stage Texture unit.
 *  @param _sampler Program sampler.
 *  @param _handle Frame buffer handle.
 *  @param _attachment Attachment index.
 *  @param _flags Texture sampling mode. Default value UINT32_MAX uses
 *    texture sampling settings from the texture.
 *
 *    BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
 *      mode.
 *
 *    BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
 *      sampling.
 */
BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags);

/**
 *  Submit primitive for rendering into single view.
 *
 *  @param _id View id.
 *  @param _depth Depth for sorting.
 *  @returns Number of draw calls.
 */
BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth);

/**
 *
 */
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);

/**
 *
 */
BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format);

/**
 * Dispatch compute.
 */
BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags);

/**
 *  Discard all previously set state for draw call.
 */
BGFX_C_API void bgfx_discard();

/**
 *  Request screen shot.
 *
 *  @param _filePath Will be passed to CallbackI::screenShot callback.
 *
 *  NOTE:
 *    CallbackI::screenShot must be implemented.
 */
BGFX_C_API void bgfx_save_screen_shot(const char* _filePath);

#endif // BGFX_C99_H_HEADER_GUARD