/
bgfx.h
3976 lines (3683 loc) · 121 KB
/
bgfx.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
/*
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#ifndef BGFX_H_HEADER_GUARD
#define BGFX_H_HEADER_GUARD
#include <stdarg.h> // va_list
#include <stdint.h> // uint32_t
#include <stdlib.h> // NULL
#include "defines.h"
///
#define BGFX_HANDLE(_name) \
struct _name { uint16_t idx; }; \
inline bool isValid(_name _handle) { return bgfx::kInvalidHandle != _handle.idx; }
#define BGFX_INVALID_HANDLE { bgfx::kInvalidHandle }
namespace bx { struct AllocatorI; }
/// BGFX
namespace bgfx
{
/// Fatal error enum.
///
/// @attention C99 equivalent is `bgfx_fatal_t`.
///
struct Fatal
{
enum Enum
{
DebugCheck,
InvalidShader,
UnableToInitialize,
UnableToCreateTexture,
DeviceLost,
Count
};
};
/// Renderer backend type enum.
///
/// @attention C99 equivalent is `bgfx_renderer_type_t`.
///
struct RendererType
{
/// Renderer types:
enum Enum
{
Noop, //!< No rendering.
Direct3D9, //!< Direct3D 9.0
Direct3D11, //!< Direct3D 11.0
Direct3D12, //!< Direct3D 12.0
Gnm, //!< GNM
Metal, //!< Metal
OpenGLES, //!< OpenGL ES 2.0+
OpenGL, //!< OpenGL 2.1+
Vulkan, //!< Vulkan
Count
};
};
/// Access mode enum.
///
/// @attention C99 equivalent is `bgfx_access_t`.
///
struct Access
{
/// Access:
enum Enum
{
Read, //!< Read
Write, //!< Write
ReadWrite, //!< Read and write
Count
};
};
/// Vertex attribute enum.
///
/// @attention C99 equivalent is `bgfx_attrib_t`.
///
struct Attrib
{
/// Corresponds to vertex shader attribute.
enum Enum
{
Position, //!< a_position
Normal, //!< a_normal
Tangent, //!< a_tangent
Bitangent, //!< a_bitangent
Color0, //!< a_color0
Color1, //!< a_color1
Color2, //!< a_color2
Color3, //!< a_color3
Indices, //!< a_indices
Weight, //!< a_weight
TexCoord0, //!< a_texcoord0
TexCoord1, //!< a_texcoord1
TexCoord2, //!< a_texcoord2
TexCoord3, //!< a_texcoord3
TexCoord4, //!< a_texcoord4
TexCoord5, //!< a_texcoord5
TexCoord6, //!< a_texcoord6
TexCoord7, //!< a_texcoord7
Count
};
};
/// Vertex attribute type enum.
///
/// @attention C99 equivalent is `bgfx_attrib_type_t`.
///
struct AttribType
{
/// Attribute types:
enum Enum
{
Uint8, //!< Uint8
Uint10, //!< Uint10, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_UINT10`.
Int16, //!< Int16
Half, //!< Half, availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`.
Float, //!< Float
Count
};
};
/// Texture format enum.
///
/// Notation:
///
/// RGBA16S
/// ^ ^ ^
/// | | +-- [ ]Unorm
/// | | [F]loat
/// | | [S]norm
/// | | [I]nt
/// | | [U]int
/// | +---- Number of bits per component
/// +-------- Components
///
/// @attention Availability depends on Caps (see: formats).
///
/// @attention C99 equivalent is `bgfx_texture_format_t`.
///
struct TextureFormat
{
/// Texture formats:
enum Enum
{
BC1, //!< DXT1
BC2, //!< DXT3
BC3, //!< DXT5
BC4, //!< LATC1/ATI1
BC5, //!< LATC2/ATI2
BC6H, //!< BC6H
BC7, //!< BC7
ETC1, //!< ETC1 RGB8
ETC2, //!< ETC2 RGB8
ETC2A, //!< ETC2 RGBA8
ETC2A1, //!< ETC2 RGB8A1
PTC12, //!< PVRTC1 RGB 2BPP
PTC14, //!< PVRTC1 RGB 4BPP
PTC12A, //!< PVRTC1 RGBA 2BPP
PTC14A, //!< PVRTC1 RGBA 4BPP
PTC22, //!< PVRTC2 RGBA 2BPP
PTC24, //!< PVRTC2 RGBA 4BPP
ATC, //!< ATC RGB 4BPP
ATCE, //!< ATCE RGBA 8 BPP explicit alpha
ATCI, //!< ATCI RGBA 8 BPP interpolated alpha
ASTC4x4, //!< ASTC 4x4 8.0 BPP
ASTC5x5, //!< ASTC 5x5 5.12 BPP
ASTC6x6, //!< ASTC 6x6 3.56 BPP
ASTC8x5, //!< ASTC 8x5 3.20 BPP
ASTC8x6, //!< ASTC 8x6 2.67 BPP
ASTC10x5, //!< ASTC 10x5 2.56 BPP
Unknown, // Compressed formats above.
R1,
A8,
R8,
R8I,
R8U,
R8S,
R16,
R16I,
R16U,
R16F,
R16S,
R32I,
R32U,
R32F,
RG8,
RG8I,
RG8U,
RG8S,
RG16,
RG16I,
RG16U,
RG16F,
RG16S,
RG32I,
RG32U,
RG32F,
RGB8,
RGB8I,
RGB8U,
RGB8S,
RGB9E5F,
BGRA8,
RGBA8,
RGBA8I,
RGBA8U,
RGBA8S,
RGBA16,
RGBA16I,
RGBA16U,
RGBA16F,
RGBA16S,
RGBA32I,
RGBA32U,
RGBA32F,
R5G6B5,
RGBA4,
RGB5A1,
RGB10A2,
RG11B10F,
UnknownDepth, // Depth formats below.
D16,
D24,
D24S8,
D32,
D16F,
D24F,
D32F,
D0S8,
Count
};
};
/// Uniform type enum.
///
/// @attention C99 equivalent is `bgfx_uniform_type_t`.
///
struct UniformType
{
/// Uniform types:
enum Enum
{
Int1, //!< Int, used for samplers only.
End, //!< Reserved, do not use.
Vec4, //!< 4 floats vector.
Mat3, //!< 3x3 matrix.
Mat4, //!< 4x4 matrix.
Count
};
};
/// Backbuffer ratio enum.
///
/// @attention C99 equivalent is `bgfx_backbuffer_ratio_t`.
///
struct BackbufferRatio
{
/// Backbuffer ratios:
enum Enum
{
Equal, //!< Equal to backbuffer.
Half, //!< One half size of backbuffer.
Quarter, //!< One quarter size of backbuffer.
Eighth, //!< One eighth size of backbuffer.
Sixteenth, //!< One sixteenth size of backbuffer.
Double, //!< Double size of backbuffer.
Count
};
};
/// Occlusion query result.
///
/// @attention C99 equivalent is `bgfx_occlusion_query_result_t`.
///
struct OcclusionQueryResult
{
/// Occlusion query results:
enum Enum
{
Invisible, //!< Query failed test.
Visible, //!< Query passed test.
NoResult, //!< Query result is not available yet.
Count
};
};
/// Primitive topology.
///
/// @attention C99 equivalent is `bgfx_topology_t`.
///
struct Topology
{
/// Primitive topology:
enum Enum
{
TriList, //!< Triangle list.
TriStrip, //!< Triangle strip.
LineList, //!< Line list.
LineStrip, //!< Line strip.
PointList, //!< Point list.
Count
};
};
/// Topology conversion function.
///
/// @attention C99 equivalent is `bgfx_topology_convert_t`.
///
struct TopologyConvert
{
/// Topology conversion functions:
enum Enum
{
TriListFlipWinding, //!< Flip winding order of triangle list.
TriStripFlipWinding, //!< Flip winding order of trinagle strip.
TriListToLineList, //!< Convert triangle list to line list.
TriStripToTriList, //!< Convert triangle strip to triangle list.
LineStripToLineList, //!< Convert line strip to line list.
Count
};
};
/// Topology sort order.
///
/// @attention C99 equivalent is `bgfx_topology_sort_t`.
///
struct TopologySort
{
/// Topology sort order:
enum Enum
{
DirectionFrontToBackMin, //!<
DirectionFrontToBackAvg, //!<
DirectionFrontToBackMax, //!<
DirectionBackToFrontMin, //!<
DirectionBackToFrontAvg, //!<
DirectionBackToFrontMax, //!<
DistanceFrontToBackMin, //!<
DistanceFrontToBackAvg, //!<
DistanceFrontToBackMax, //!<
DistanceBackToFrontMin, //!<
DistanceBackToFrontAvg, //!<
DistanceBackToFrontMax, //!<
Count
};
};
/// View mode sets draw call sort order.
///
/// @attention C99 equivalent is `bgfx_view_mode_t`.
///
struct ViewMode
{
/// View modes:
enum Enum
{
Default, //!< Default sort order.
Sequential, //!< Sort in the same order in which submit calls were called.
DepthAscending, //!< Sort draw call depth in ascending order.
DepthDescending, //!< Sort draw call depth in descending order.
Count
};
};
static const uint16_t kInvalidHandle = UINT16_MAX;
BGFX_HANDLE(DynamicIndexBufferHandle)
BGFX_HANDLE(DynamicVertexBufferHandle)
BGFX_HANDLE(FrameBufferHandle)
BGFX_HANDLE(IndexBufferHandle)
BGFX_HANDLE(IndirectBufferHandle)
BGFX_HANDLE(OcclusionQueryHandle)
BGFX_HANDLE(ProgramHandle)
BGFX_HANDLE(ShaderHandle)
BGFX_HANDLE(TextureHandle)
BGFX_HANDLE(UniformHandle)
BGFX_HANDLE(VertexBufferHandle)
BGFX_HANDLE(VertexDeclHandle)
/// Callback interface to implement application specific behavior.
/// Cached items are currently used for OpenGL and Direct3D 12 binary
/// shaders.
///
/// @remarks
/// 'fatal' and 'trace' callbacks can be called from any thread. Other
/// callbacks are called from the render thread.
///
/// @attention C99 equivalent is `bgfx_callback_interface_t`.
///
struct CallbackI
{
virtual ~CallbackI() = 0;
/// This callback is called on unrecoverable errors.
/// It's not safe to continue (Exluding _code `Fatal::DebugCheck`),
/// inform the user and terminate the application.
///
/// @param[in] _code Fatal error code.
/// @param[in] _str More information about error.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.fatal`.
///
virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
/// Print debug message.
///
/// @param[in] _filePath File path where debug message was generated.
/// @param[in] _line Line where debug message was generated.
/// @param[in] _format `printf` style format.
/// @param[in] _argList Variable arguments list initialized with
/// `va_start`.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.trace_vargs`.
///
virtual void traceVargs(
const char* _filePath
, uint16_t _line
, const char* _format
, va_list _argList
) = 0;
/// Profiler region begin.
///
/// @param[in] _name Region name, contains dynamic string.
/// @param[in] _abgr Color of profiler region.
/// @param[in] _filePath File path where `profilerBegin` was called.
/// @param[in] _line Line where `profilerBegin` was called.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.profiler_begin`.
///
virtual void profilerBegin(
const char* _name
, uint32_t _abgr
, const char* _filePath
, uint16_t _line
) = 0;
/// Profiler region begin with string literal name.
///
/// @param[in] _name Region name, contains string literal.
/// @param[in] _abgr Color of profiler region.
/// @param[in] _filePath File path where `profilerBeginLiteral` was called.
/// @param[in] _line Line where `profilerBeginLiteral` was called.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.profiler_begin_literal`.
///
virtual void profilerBeginLiteral(
const char* _name
, uint32_t _abgr
, const char* _filePath
, uint16_t _line
) = 0;
/// Profiler region end.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.profiler_end`.
///
virtual void profilerEnd() = 0;
/// Returns the size of a cached item. Returns 0 if no cached item was
/// found.
///
/// @param[in] _id Cache id.
/// @returns Number of bytes to read.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.cache_read_size`.
///
virtual uint32_t cacheReadSize(uint64_t _id) = 0;
/// Read cached item.
///
/// @param[in] _id Cache id.
/// @param[in] _data Buffer where to read data.
/// @param[in] _size Size of data to read.
///
/// @returns True if data is read.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.cache_read`.
///
virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
/// Write cached item.
///
/// @param[in] _id Cache id.
/// @param[in] _data Data to write.
/// @param[in] _size Size of data to write.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.cache_write`.
///
virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
/// Screenshot captured. Screenshot format is always 4-byte BGRA.
///
/// @param[in] _filePath File path.
/// @param[in] _width Image width.
/// @param[in] _height Image height.
/// @param[in] _pitch Number of bytes to skip between the start of
/// each horizontal line of the image.
/// @param[in] _data Image data.
/// @param[in] _size Image size.
/// @param[in] _yflip If true, image origin is bottom left.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.screen_shot`.
///
virtual void screenShot(
const char* _filePath
, uint32_t _width
, uint32_t _height
, uint32_t _pitch
, const void* _data
, uint32_t _size
, bool _yflip
) = 0;
/// Called when a video capture begins.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.capture_begin`.
///
virtual void captureBegin(
uint32_t _width
, uint32_t _height
, uint32_t _pitch
, TextureFormat::Enum _format
, bool _yflip
) = 0;
/// Called when a video capture ends.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.capture_end`.
///
virtual void captureEnd() = 0;
/// Captured frame.
///
/// @param[in] _data Image data.
/// @param[in] _size Image size.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.capture_frame`.
///
virtual void captureFrame(const void* _data, uint32_t _size) = 0;
};
inline CallbackI::~CallbackI()
{
}
/// Backbuffer resolution and reset parameters.
///
/// @attention C99 equivalent is `bgfx_resolution_t`.
///
struct Resolution
{
Resolution();
uint32_t width; //!< Backbuffer width.
uint32_t height; //!< Backbuffer height.
uint32_t reset; //!< Reset parameters.
};
/// Initialization parameters used by `bgfx::init`.
///
/// @attention C99 equivalent is `bgfx_init_t`.
///
struct Init
{
Init();
/// Select rendering backend. When set to RendererType::Count
/// a default rendering backend will be selected appropriate to the platform.
/// See: `bgfx::RendererType`
RendererType::Enum type;
/// Vendor PCI id. If set to `BGFX_PCI_ID_NONE` it will select the first
/// device.
/// - `BGFX_PCI_ID_NONE` - Autoselect adapter.
/// - `BGFX_PCI_ID_SOFTWARE_RASTERIZER` - Software rasterizer.
/// - `BGFX_PCI_ID_AMD` - AMD adapter.
/// - `BGFX_PCI_ID_INTEL` - Intel adapter.
/// - `BGFX_PCI_ID_NVIDIA` - nVidia adapter.
uint16_t vendorId;
/// Device id. If set to 0 it will select first device, or device with
/// matching id.
uint16_t deviceId;
bool debug; //!< Enable device for debuging.
bool profile; //!< Enable device for profiling.
Resolution resolution; //!< Backbuffer resolution and reset parameters.
struct Limits
{
uint16_t maxEncoders; //!< Maximum number of encoder threads.
uint32_t transientVbSize; //!< Maximum transient vertex buffer size.
uint32_t transientIbSize; //!< Maximum transient index buffer size.
};
Limits limits;
/// Provide application specific callback interface.
/// See: `bgfx::CallbackI`
CallbackI* callback;
/// Custom allocator. When a custom allocator is not
/// specified, bgfx uses the CRT allocator. Bgfx assumes
/// custom allocator is thread safe.
bx::AllocatorI* allocator;
};
/// Memory release callback.
///
/// param[in] _ptr Pointer to allocated data.
/// param[in] _userData User defined data if needed.
///
/// @attention C99 equivalent is `bgfx_release_fn_t`.
///
typedef void (*ReleaseFn)(void* _ptr, void* _userData);
/// Memory obtained by calling `bgfx::alloc`, `bgfx::copy`, or `bgfx::makeRef`.
///
/// @attention C99 equivalent is `bgfx_memory_t`.
///
struct Memory
{
uint8_t* data; //!< Pointer to data.
uint32_t size; //!< Data size.
};
/// Renderer capabilities.
///
/// @attention C99 equivalent is `bgfx_caps_t`.
///
struct Caps
{
/// Renderer backend type. See: `bgfx::RendererType`
RendererType::Enum rendererType;
/// Supported functionality.
///
/// @attention See BGFX_CAPS_* flags at https://bkaradzic.github.io/bgfx/bgfx.html#available-caps
///
uint64_t supported;
uint16_t vendorId; //!< Selected GPU vendor PCI id.
uint16_t deviceId; //!< Selected GPU device id.
bool homogeneousDepth; //!< True when NDC depth is in [-1, 1] range, otherwise its [0, 1].
bool originBottomLeft; //!< True when NDC origin is at bottom left.
uint8_t numGPUs; //!< Number of enumerated GPUs.
/// GPU info.
///
/// @attention C99 equivalent is `bgfx_caps_gpu_t`.
///
struct GPU
{
uint16_t vendorId; //!< Vendor PCI id. See `BGFX_PCI_ID_*`.
uint16_t deviceId; //!< Device id.
};
GPU gpu[4]; //!< Enumerated GPUs.
struct Limits
{
uint32_t maxDrawCalls; //!< Maximum number of draw calls.
uint32_t maxBlits; //!< Maximum number of blit calls.
uint32_t maxTextureSize; //!< Maximum texture size.
uint32_t maxTextureLayers; //!< Maximum texture layers.
uint32_t maxViews; //!< Maximum number of views.
uint32_t maxFrameBuffers; //!< Maximum number of frame buffer handles.
uint32_t maxFBAttachments; //!< Maximum number of frame buffer attachments.
uint32_t maxPrograms; //!< Maximum number of program handles.
uint32_t maxShaders; //!< Maximum number of shader handles.
uint32_t maxTextures; //!< Maximum number of texture handles.
uint32_t maxTextureSamplers; //!< Maximum number of texture samplers.
uint32_t maxVertexDecls; //!< Maximum number of vertex format declarations.
uint32_t maxVertexStreams; //!< Maximum number of vertex streams.
uint32_t maxIndexBuffers; //!< Maximum number of index buffer handles.
uint32_t maxVertexBuffers; //!< Maximum number of vertex buffer handles.
uint32_t maxDynamicIndexBuffers; //!< Maximum number of dynamic index buffer handles.
uint32_t maxDynamicVertexBuffers; //!< Maximum number of dynamic vertex buffer handles.
uint32_t maxUniforms; //!< Maximum number of uniform handles.
uint32_t maxOcclusionQueries; //!< Maximum number of occlusion query handles.
uint32_t maxEncoders; //!< Maximum number of encoder threads.
uint32_t transientVbSize; //!< Maximum transient vertex buffer size.
uint32_t transientIbSize; //!< Maximum transient index buffer size.
};
Limits limits;
/// Supported texture format capabilities flags:
/// - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - Texture format is not supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_2D` - Texture format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB` - Texture as sRGB format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED` - Texture format is emulated.
/// - `BGFX_CAPS_FORMAT_TEXTURE_3D` - Texture format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB` - Texture as sRGB format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED` - Texture format is emulated.
/// - `BGFX_CAPS_FORMAT_TEXTURE_CUBE` - Texture format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB` - Texture as sRGB format is supported.
/// - `BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED` - Texture format is emulated.
/// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - Texture format can be used from vertex shader.
/// - `BGFX_CAPS_FORMAT_TEXTURE_IMAGE` - Texture format can be used as image from compute
/// shader.
/// - `BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER` - Texture format can be used as frame
/// buffer.
/// - `BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA` - Texture format can be used as MSAA
/// frame buffer.
/// - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
/// - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
/// mips.
uint16_t formats[TextureFormat::Count];
};
/// Transient index buffer.
///
/// @attention C99 equivalent is `bgfx_transient_index_buffer_t`.
///
struct TransientIndexBuffer
{
uint8_t* data; //!< Pointer to data.
uint32_t size; //!< Data size.
uint32_t startIndex; //!< First index.
IndexBufferHandle handle; //!< Index buffer handle.
};
/// Transient vertex buffer.
///
/// @attention C99 equivalent is `bgfx_transient_vertex_buffer_t`.
///
struct TransientVertexBuffer
{
uint8_t* data; //!< Pointer to data.
uint32_t size; //!< Data size.
uint32_t startVertex; //!< First vertex.
uint16_t stride; //!< Vertex stride.
VertexBufferHandle handle; //!< Vertex buffer handle.
VertexDeclHandle decl; //!< Vertex declaration handle.
};
/// Instance data buffer info.
///
/// @attention C99 equivalent is `bgfx_texture_info_t`.
///
struct InstanceDataBuffer
{
uint8_t* data; //!< Pointer to data.
uint32_t size; //!< Data size.
uint32_t offset; //!< Offset in vertex buffer.
uint32_t num; //!< Number of instances.
uint16_t stride; //!< Vertex buffer stride.
VertexBufferHandle handle; //!< Vertex buffer object handle.
};
/// Texture info.
///
/// @attention C99 equivalent is `bgfx_texture_info_t`.
///
struct TextureInfo
{
TextureFormat::Enum format; //!< Texture format.
uint32_t storageSize; //!< Total amount of bytes required to store texture.
uint16_t width; //!< Texture width.
uint16_t height; //!< Texture height.
uint16_t depth; //!< Texture depth.
uint16_t numLayers; //!< Number of layers in texture array.
uint8_t numMips; //!< Number of MIP maps.
uint8_t bitsPerPixel; //!< Format bits per pixel.
bool cubeMap; //!< Texture is cubemap.
};
/// Uniform info.
///
/// @attention C99 equivalent is `bgfx_uniform_info_t`.
///
struct UniformInfo
{
char name[256]; //!< Uniform name.
UniformType::Enum type; //!< Uniform type.
uint16_t num; //!< Number of elements in array.
};
/// Frame buffer texture attachment info.
///
/// @attention C99 equivalent is `bgfx_attachment_t`.
///
struct Attachment
{
TextureHandle handle; //!< Texture handle.
uint16_t mip; //!< Mip level.
uint16_t layer; //!< Cubemap side or depth layer/slice.
};
/// Transform data.
///
/// @attention C99 equivalent is `bgfx_transform_t`.
///
struct Transform
{
float* data; //!< Pointer to first 4x4 matrix.
uint16_t num; //!< Number of matrices.
};
/// HMD info.
///
/// @attention C99 equivalent is `bgfx_hmd_t`.
///
struct HMD
{
/// Eye
///
/// @attention C99 equivalent is `bgfx_hmd_eye_t`.
///
struct Eye
{
float rotation[4]; //!< Eye rotation represented as quaternion.
float translation[3]; //!< Eye translation.
float fov[4]; //!< Field of view (up, down, left, right).
float viewOffset[3]; //!< Eye view matrix translation adjustment.
float projection[16]; //!< Eye projection matrix.
float pixelsPerTanAngle[2]; //!< Number of pixels that fit in tan(angle) = 1.
};
Eye eye[2];
uint16_t width; //!< Frame buffer width.
uint16_t height; //!< Frame buffer height.
uint32_t deviceWidth; //!< Device resolution width.
uint32_t deviceHeight; //!< Device resolution height.
uint8_t flags; //!< Status flags.
};
///
typedef uint16_t ViewId;
/// View stats.
///
/// @attention C99 equivalent is `bgfx_view_stats_t`.
///
struct ViewStats
{
char name[256]; //!< View name.
ViewId view; //!< View id.
int64_t cpuTimeElapsed; //!< CPU (submit) time elapsed.
int64_t gpuTimeElapsed; //!< GPU time elapsed.
};
/// Encoder stats.
///
/// @attention C99 equivalent is `bgfx_encoder_stats_t`.
///
struct EncoderStats
{
int64_t cpuTimeBegin; //!< Encoder thread CPU submit begin time.
int64_t cpuTimeEnd; //!< Encoder thread CPU submit end time.
};
/// Renderer statistics data.
///
/// @attention C99 equivalent is `bgfx_stats_t`.
///
/// @remarks All time values are high-resolution timestamps, while
/// time frequencies define timestamps-per-second for that hardware.
struct Stats
{
int64_t cpuTimeFrame; //!< CPU time between two `bgfx::frame` calls.
int64_t cpuTimeBegin; //!< Render thread CPU submit begin time.
int64_t cpuTimeEnd; //!< Render thread CPU submit end time.
int64_t cpuTimerFreq; //!< CPU timer frequency. Timestamps-per-second
int64_t gpuTimeBegin; //!< GPU frame begin time.
int64_t gpuTimeEnd; //!< GPU frame end time.
int64_t gpuTimerFreq; //!< GPU timer frequency.
int64_t waitRender; //!< Time spent waiting for render backend thread to finish issuing
//! draw commands to underlying graphics API.
int64_t waitSubmit; //!< Time spent waiting for submit thread to advance to next frame.
uint32_t numDraw; //!< Number of draw calls submitted.
uint32_t numCompute; //!< Number of compute calls submitted.
uint32_t maxGpuLatency; //!< GPU driver latency.
uint16_t numDynamicIndexBuffers; //!< Number of used dynamic index buffers.
uint16_t numDynamicVertexBuffers; //!< Number of used dynamic vertex buffers.
uint16_t numFrameBuffers; //!< Number of used frame buffers.
uint16_t numIndexBuffers; //!< Number of used index buffers.
uint16_t numOcclusionQueries; //!< Number of used occlusion queries.
uint16_t numPrograms; //!< Number of used programs.
uint16_t numShaders; //!< Number of used shaders.
uint16_t numTextures; //!< Number of used textures.
uint16_t numUniforms; //!< Number of used uniforms.
uint16_t numVertexBuffers; //!< Number of used vertex buffers.
uint16_t numVertexDecls; //!< Number of used vertex declarations.
int64_t textureMemoryUsed; //!< Estimate of texture memory used.
int64_t rtMemoryUsed; //!< Estimate of render target memory used.
int32_t transientVbUsed; //!< Amount of transient vertex buffer used.
int32_t transientIbUsed; //!< Amount of transient index buffer used.
uint32_t numPrims[Topology::Count]; //!< Number of primitives rendered.
int64_t gpuMemoryMax; //!< Maximum available GPU memory for application.
int64_t gpuMemoryUsed; //!< Amount of GPU memory used by the application.
uint16_t width; //!< Backbuffer width in pixels.
uint16_t height; //!< Backbuffer height in pixels.
uint16_t textWidth; //!< Debug text width in characters.
uint16_t textHeight; //!< Debug text height in characters.
uint16_t numViews; //!< Number of view stats.
ViewStats* viewStats; //!< Array of View stats.
uint8_t numEncoders; //!< Number of encoders used during frame.
EncoderStats* encoderStats; //!< Array of encoder stats.
};
/// Encoders are used for submitting draw calls from multiple threads. Only one encoder
/// per thread should be used. Use `bgfx::begin()` to obtain an encoder for a thread.
///
/// @attention C99 equivalent is `bgfx_encoder`.
///
struct Encoder
{
/// Sets a debug marker. This allows you to group
/// graphics calls together for easy browsing in
/// graphics debugging tools.
///
/// @attention C99 equivalent is `bgfx_set_marker`.
///
void setMarker(const char* _marker);
/// Set render states for draw primitive.
///
/// @param[in] _state State flags. Default state for primitive type is
/// triangles. See: `BGFX_STATE_DEFAULT`.
/// - `BGFX_STATE_DEPTH_TEST_*` - Depth test function.
/// - `BGFX_STATE_BLEND_*` - See remark 1 about BGFX_STATE_BLEND_FUNC.
/// - `BGFX_STATE_BLEND_EQUATION_*` - See remark 2.
/// - `BGFX_STATE_CULL_*` - Backface culling mode.
/// - `BGFX_STATE_WRITE_*` - Enable R, G, B, A or Z write.
/// - `BGFX_STATE_MSAA` - Enable hardware multisample antialiasing.
/// - `BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]` - Primitive type.
///
/// @param[in] _rgba Sets blend factor used by `BGFX_STATE_BLEND_FACTOR` and
/// `BGFX_STATE_BLEND_INV_FACTOR` blend modes.
///
/// @remarks
/// 1. To setup more complex states use:
/// `BGFX_STATE_ALPHA_REF(_ref)`,
/// `BGFX_STATE_POINT_SIZE(_size)`,
/// `BGFX_STATE_BLEND_FUNC(_src, _dst)`,
/// `BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)`,
/// `BGFX_STATE_BLEND_EQUATION(_equation)`,
/// `BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)`
/// 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend
/// equation is specified.
///
/// @attention C99 equivalent is `bgfx_set_state`.
///
void setState(