bgfx.c99.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. *
  5. * vim: set tabstop=4 expandtab:
  6. */
  7. #ifndef BGFX_C99_H_HEADER_GUARD
  8. #define BGFX_C99_H_HEADER_GUARD
  9. #include <stdbool.h> // bool
  10. #include <stdint.h> // uint32_t
  11. #include <stdlib.h> // size_t
  12. #include "bgfxdefines.h"
  13. typedef enum bgfx_renderer_type
  14. {
  15. BGFX_RENDERER_TYPE_NULL,
  16. BGFX_RENDERER_TYPE_DIRECT3D9,
  17. BGFX_RENDERER_TYPE_DIRECT3D11,
  18. BGFX_RENDERER_TYPE_DIRECT3D12,
  19. BGFX_RENDERER_TYPE_OPENGLES,
  20. BGFX_RENDERER_TYPE_OPENGL,
  21. BGFX_RENDERER_TYPE_VULKAN,
  22. BGFX_RENDERER_TYPE_COUNT
  23. } bgfx_renderer_type_t;
  24. typedef enum bgfx_access
  25. {
  26. BGFX_ACCESS_READ,
  27. BGFX_ACCESS_WRITE,
  28. BGFX_ACCESS_READWRITE,
  29. BGFX_ACCESS_COUNT
  30. } bgfx_access_t;
  31. typedef enum bgfx_attrib
  32. {
  33. BGFX_ATTRIB_POSITION,
  34. BGFX_ATTRIB_NORMAL,
  35. BGFX_ATTRIB_TANGENT,
  36. BGFX_ATTRIB_BITANGENT,
  37. BGFX_ATTRIB_COLOR0,
  38. BGFX_ATTRIB_COLOR1,
  39. BGFX_ATTRIB_INDICES,
  40. BGFX_ATTRIB_WEIGHT,
  41. BGFX_ATTRIB_TEXCOORD0,
  42. BGFX_ATTRIB_TEXCOORD1,
  43. BGFX_ATTRIB_TEXCOORD2,
  44. BGFX_ATTRIB_TEXCOORD3,
  45. BGFX_ATTRIB_TEXCOORD4,
  46. BGFX_ATTRIB_TEXCOORD5,
  47. BGFX_ATTRIB_TEXCOORD6,
  48. BGFX_ATTRIB_TEXCOORD7,
  49. BGFX_ATTRIB_COUNT
  50. } bgfx_attrib_t;
  51. typedef enum bgfx_attrib_type
  52. {
  53. BGFX_ATTRIB_TYPE_UINT8,
  54. BGFX_ATTRIB_TYPE_INT16,
  55. BGFX_ATTRIB_TYPE_HALF,
  56. BGFX_ATTRIB_TYPE_FLOAT,
  57. BGFX_ATTRIB_TYPE_COUNT
  58. } bgfx_attrib_type_t;
  59. typedef enum bgfx_texture_format
  60. {
  61. BGFX_TEXTURE_FORMAT_BC1,
  62. BGFX_TEXTURE_FORMAT_BC2,
  63. BGFX_TEXTURE_FORMAT_BC3,
  64. BGFX_TEXTURE_FORMAT_BC4,
  65. BGFX_TEXTURE_FORMAT_BC5,
  66. BGFX_TEXTURE_FORMAT_BC6H,
  67. BGFX_TEXTURE_FORMAT_BC7,
  68. BGFX_TEXTURE_FORMAT_ETC1,
  69. BGFX_TEXTURE_FORMAT_ETC2,
  70. BGFX_TEXTURE_FORMAT_ETC2A,
  71. BGFX_TEXTURE_FORMAT_ETC2A1,
  72. BGFX_TEXTURE_FORMAT_PTC12,
  73. BGFX_TEXTURE_FORMAT_PTC14,
  74. BGFX_TEXTURE_FORMAT_PTC12A,
  75. BGFX_TEXTURE_FORMAT_PTC14A,
  76. BGFX_TEXTURE_FORMAT_PTC22,
  77. BGFX_TEXTURE_FORMAT_PTC24,
  78. BGFX_TEXTURE_FORMAT_UNKNOWN,
  79. BGFX_TEXTURE_FORMAT_R1,
  80. BGFX_TEXTURE_FORMAT_R8,
  81. BGFX_TEXTURE_FORMAT_R16,
  82. BGFX_TEXTURE_FORMAT_R16F,
  83. BGFX_TEXTURE_FORMAT_R32,
  84. BGFX_TEXTURE_FORMAT_R32F,
  85. BGFX_TEXTURE_FORMAT_RG8,
  86. BGFX_TEXTURE_FORMAT_RG16,
  87. BGFX_TEXTURE_FORMAT_RG16F,
  88. BGFX_TEXTURE_FORMAT_RG32,
  89. BGFX_TEXTURE_FORMAT_RG32F,
  90. BGFX_TEXTURE_FORMAT_BGRA8,
  91. BGFX_TEXTURE_FORMAT_RGBA8,
  92. BGFX_TEXTURE_FORMAT_RGBA16,
  93. BGFX_TEXTURE_FORMAT_RGBA16F,
  94. BGFX_TEXTURE_FORMAT_RGBA32,
  95. BGFX_TEXTURE_FORMAT_RGBA32F,
  96. BGFX_TEXTURE_FORMAT_R5G6B5,
  97. BGFX_TEXTURE_FORMAT_RGBA4,
  98. BGFX_TEXTURE_FORMAT_RGB5A1,
  99. BGFX_TEXTURE_FORMAT_RGB10A2,
  100. BGFX_TEXTURE_FORMAT_R11G11B10F,
  101. BGFX_TEXTURE_FORMAT_UNKNOWN_DEPTH,
  102. BGFX_TEXTURE_FORMAT_D16,
  103. BGFX_TEXTURE_FORMAT_D24,
  104. BGFX_TEXTURE_FORMAT_D24S8,
  105. BGFX_TEXTURE_FORMAT_D32,
  106. BGFX_TEXTURE_FORMAT_D16F,
  107. BGFX_TEXTURE_FORMAT_D24F,
  108. BGFX_TEXTURE_FORMAT_D32F,
  109. BGFX_TEXTURE_FORMAT_D0S8,
  110. BGFX_TEXTURE_FORMAT_COUNT
  111. } bgfx_texture_format_t;
  112. typedef enum bgfx_uniform_type
  113. {
  114. BGFX_UNIFORM_TYPE_UNIFORM1I,
  115. BGFX_UNIFORM_TYPE_UNIFORM1F,
  116. BGFX_UNIFORM_TYPE_END,
  117. BGFX_UNIFORM_TYPE_UNIFORM1IV,
  118. BGFX_UNIFORM_TYPE_UNIFORM1FV,
  119. BGFX_UNIFORM_TYPE_UNIFORM2FV,
  120. BGFX_UNIFORM_TYPE_UNIFORM3FV,
  121. BGFX_UNIFORM_TYPE_UNIFORM4FV,
  122. BGFX_UNIFORM_TYPE_UNIFORM3X3FV,
  123. BGFX_UNIFORM_TYPE_UNIFORM4X4FV,
  124. BGFX_UNIFORM_TYPE_COUNT
  125. } bgfx_uniform_type_t;
  126. #define BGFX_HANDLE_T(_name) \
  127. typedef struct _name { uint16_t idx; } _name##_t;
  128. BGFX_HANDLE_T(bgfx_dynamic_index_buffer_handle);
  129. BGFX_HANDLE_T(bgfx_dynamic_vertex_buffer_handle);
  130. BGFX_HANDLE_T(bgfx_frame_buffer_handle);
  131. BGFX_HANDLE_T(bgfx_index_buffer_handle);
  132. BGFX_HANDLE_T(bgfx_program_handle);
  133. BGFX_HANDLE_T(bgfx_shader_handle);
  134. BGFX_HANDLE_T(bgfx_texture_handle);
  135. BGFX_HANDLE_T(bgfx_uniform_handle);
  136. BGFX_HANDLE_T(bgfx_vertex_buffer_handle);
  137. BGFX_HANDLE_T(bgfx_vertex_decl_handle);
  138. #undef BGFX_HANDLE_T
  139. /**
  140. *
  141. */
  142. typedef void (*bgfx_release_fn_t)(void* _ptr, void* _userData);
  143. /**
  144. *
  145. */
  146. typedef struct bgfx_memory
  147. {
  148. uint8_t* data;
  149. uint32_t size;
  150. } bgfx_memory_t;
  151. /**
  152. *
  153. */
  154. typedef struct bgfx_transform
  155. {
  156. float* data;
  157. uint16_t num;
  158. } bgfx_transform_t;
  159. /**
  160. * Eye
  161. */
  162. typedef struct bgfx_hmd_eye
  163. {
  164. float rotation[4];
  165. float translation[3];
  166. float fov[4];
  167. float adjust[3];
  168. float pixelsPerTanAngle[2];
  169. } bgfx_hmd_eye_t;
  170. /**
  171. * HMD
  172. */
  173. typedef struct bgfx_hmd
  174. {
  175. bgfx_hmd_eye_t eye[2];
  176. uint16_t width;
  177. uint16_t height;
  178. } bgfx_hmd_t;
  179. /**
  180. * Vertex declaration.
  181. */
  182. typedef struct bgfx_vertex_decl
  183. {
  184. uint32_t hash;
  185. uint16_t stride;
  186. uint16_t offset[BGFX_ATTRIB_COUNT];
  187. uint8_t attributes[BGFX_ATTRIB_COUNT];
  188. } bgfx_vertex_decl_t;
  189. /**
  190. */
  191. typedef struct bgfx_transient_index_buffer
  192. {
  193. uint8_t* data;
  194. uint32_t size;
  195. bgfx_index_buffer_handle_t handle;
  196. uint32_t startIndex;
  197. } bgfx_transient_index_buffer_t;
  198. /**
  199. */
  200. typedef struct bgfx_transient_vertex_buffer
  201. {
  202. uint8_t* data;
  203. uint32_t size;
  204. uint32_t startVertex;
  205. uint16_t stride;
  206. bgfx_vertex_buffer_handle_t handle;
  207. bgfx_vertex_decl_handle_t decl;
  208. } bgfx_transient_vertex_buffer_t;
  209. /**
  210. */
  211. typedef struct bgfx_instance_data_buffer
  212. {
  213. uint8_t* data;
  214. uint32_t size;
  215. uint32_t offset;
  216. uint32_t num;
  217. uint16_t stride;
  218. bgfx_vertex_buffer_handle_t handle;
  219. } bgfx_instance_data_buffer_t;
  220. /**
  221. */
  222. typedef struct bgfx_texture_info
  223. {
  224. bgfx_texture_format_t format;
  225. uint32_t storageSize;
  226. uint16_t width;
  227. uint16_t height;
  228. uint16_t depth;
  229. uint8_t numMips;
  230. uint8_t bitsPerPixel;
  231. bool cubeMap;
  232. } bgfx_texture_info_t;
  233. /**
  234. */
  235. typedef struct bgfx_caps_gpu
  236. {
  237. uint16_t vendorId;
  238. uint16_t deviceId;
  239. } bgfx_caps_gpu_t;
  240. /**
  241. * Renderer capabilities.
  242. */
  243. typedef struct bgfx_caps
  244. {
  245. /**
  246. * Renderer backend type.
  247. */
  248. bgfx_renderer_type_t rendererType;
  249. /**
  250. * Supported functionality, it includes emulated functionality.
  251. * Checking supported and not emulated will give functionality
  252. * natively supported by renderer.
  253. */
  254. uint64_t supported;
  255. uint32_t maxDrawCalls; /* < Maximum draw calls. */
  256. uint16_t maxTextureSize; /* < Maximum texture size. */
  257. uint16_t maxViews; /* < Maximum views. */
  258. uint8_t maxFBAttachments; /* < Maximum frame buffer attachments. */
  259. uint8_t numGPUs; /* < */
  260. uint16_t vendorId; /* < */
  261. uint16_t deviceId; /* < */
  262. bgfx_caps_gpu_t gpu[4]; /* < */
  263. /**
  264. * Supported texture formats.
  265. * `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
  266. * `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
  267. * `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
  268. * `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
  269. */
  270. uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT];
  271. } bgfx_caps_t;
  272. /**
  273. */
  274. typedef enum bgfx_fatal
  275. {
  276. BGFX_FATAL_DEBUG_CHECK,
  277. BGFX_FATAL_MINIMUM_REQUIRED_SPECS,
  278. BGFX_FATAL_INVALID_SHADER,
  279. BGFX_FATAL_UNABLE_TO_INITIALIZE,
  280. BGFX_FATAL_UNABLE_TO_CREATE_TEXTURE,
  281. BGFX_FATAL_DEVICE_LOST,
  282. BGFX_FATAL_COUNT
  283. } bgfx_fatal_t;
  284. #ifndef BGFX_SHARED_LIB_BUILD
  285. # define BGFX_SHARED_LIB_BUILD 0
  286. #endif // BGFX_SHARED_LIB_BUILD
  287. #ifndef BGFX_SHARED_LIB_USE
  288. # define BGFX_SHARED_LIB_USE 0
  289. #endif // BGFX_SHARED_LIB_USE
  290. #if defined(_MSC_VER)
  291. # define BGFX_VTBL_CALL __stdcall
  292. # define BGFX_VTBL_THIS // passed via ecx
  293. # define BGFX_VTBL_THIS_ // passed via ecx
  294. # if BGFX_SHARED_LIB_BUILD
  295. # define BGFX_SHARED_LIB_API __declspec(dllexport)
  296. # elif BGFX_SHARED_LIB_USE
  297. # define BGFX_SHARED_LIB_API __declspec(dllimport)
  298. # else
  299. # define BGFX_SHARED_LIB_API
  300. # endif // BGFX_SHARED_LIB_*
  301. #else
  302. # define BGFX_VTBL_CALL
  303. # define BGFX_VTBL_THIS BGFX_VTBL_INTEFRACE _this
  304. # define BGFX_VTBL_THIS_ BGFX_VTBL_INTEFRACE _this,
  305. # define BGFX_SHARED_LIB_API
  306. #endif // defined(_MSC_VER)
  307. #if defined(__cplusplus)
  308. # define BGFX_C_API extern "C" BGFX_SHARED_LIB_API
  309. #else
  310. # define BGFX_C_API BGFX_SHARED_LIB_API
  311. #endif // defined(__cplusplus)
  312. /**
  313. */
  314. typedef struct bgfx_callback_interface
  315. {
  316. const struct bgfx_callback_vtbl* vtbl;
  317. } bgfx_callback_interface_t;
  318. /**
  319. * Callback interface to implement application specific behavior.
  320. * Cached items are currently used only for OpenGL binary shaders.
  321. *
  322. * NOTE:
  323. * 'fatal' callback can be called from any thread. Other callbacks
  324. * are called from the render thread.
  325. */
  326. typedef struct bgfx_callback_vtbl
  327. {
  328. # define BGFX_VTBL_INTEFRACE bgfx_callback_interface_t
  329. void* ctor;
  330. /**
  331. * If fatal code code is not BGFX_FATAL_DEBUG_CHECK this callback is
  332. * called on unrecoverable error. It's not safe to continue, inform
  333. * user and terminate application from this call.
  334. */
  335. void (BGFX_VTBL_CALL *fatal)(BGFX_VTBL_THIS_ bgfx_fatal_t _code, const char* _str);
  336. /**
  337. * Return size of for cached item. Return 0 if no cached item was
  338. * found.
  339. */
  340. uint32_t (BGFX_VTBL_CALL *cache_read_size)(BGFX_VTBL_THIS_ uint64_t _id);
  341. /**
  342. * Read cached item.
  343. */
  344. bool (BGFX_VTBL_CALL *cache_read)(BGFX_VTBL_THIS_ uint64_t _id, void* _data, uint32_t _size);
  345. /**
  346. * Write cached item.
  347. */
  348. void (BGFX_VTBL_CALL *cache_write)(BGFX_VTBL_THIS_ uint64_t _id, const void* _data, uint32_t _size);
  349. /**
  350. * Screenshot captured. Screenshot format is always 4-byte BGRA.
  351. */
  352. 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);
  353. /**
  354. * Called when capture begins.
  355. */
  356. 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);
  357. /**
  358. * Called when capture ends.
  359. */
  360. void (BGFX_VTBL_CALL *capture_end)(BGFX_VTBL_THIS);
  361. /**
  362. * Captured frame.
  363. */
  364. void (BGFX_VTBL_CALL *capture_frame)(BGFX_VTBL_THIS_ const void* _data, uint32_t _size);
  365. # undef BGFX_VTBL_INTEFRACE
  366. } bgfx_callback_vtbl_t;
  367. /**
  368. */
  369. typedef struct bgfx_reallocator_interface
  370. {
  371. const struct bgfx_reallocator_vtbl* vtbl;
  372. } bgfx_reallocator_interface_t;
  373. /**
  374. */
  375. typedef struct bgfx_reallocator_vtbl
  376. {
  377. # define BGFX_VTBL_INTEFRACE bgfx_reallocator_interface_t
  378. void* ctor;
  379. void* (BGFX_VTBL_CALL *alloc)(BGFX_VTBL_THIS_ size_t _size, size_t _align, const char* _file, uint32_t _line);
  380. void (BGFX_VTBL_CALL *free)(BGFX_VTBL_THIS_ void* _ptr, size_t _align, const char* _file, uint32_t _line);
  381. void* (BGFX_VTBL_CALL *realloc)(BGFX_VTBL_THIS_ void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line);
  382. # undef BGFX_VTBL_INTEFRACE
  383. } bgfx_reallocator_vtbl_t;
  384. /**
  385. * Start vertex declaration.
  386. */
  387. BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer);
  388. /**
  389. * Add attribute to vertex declaration.
  390. *
  391. * @param _attrib Attribute semantics.
  392. * @param _num Number of elements 1, 2, 3 or 4.
  393. * @param _type Element type.
  394. * @param _normalized When using fixed point AttribType (f.e. Uint8)
  395. * value will be normalized for vertex shader usage. When normalized
  396. * is set to true, AttribType::Uint8 value in range 0-255 will be
  397. * in range 0.0-1.0 in vertex shader.
  398. * @param _asInt Packaging rule for vertexPack, vertexUnpack, and
  399. * vertexConvert for AttribType::Uint8 and AttribType::Int16.
  400. * Unpacking code must be implemented inside vertex shader.
  401. *
  402. * NOTE:
  403. * Must be called between begin/end.
  404. */
  405. 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);
  406. /**
  407. * Skip _num bytes in vertex stream.
  408. */
  409. BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _decl, uint8_t _num);
  410. /**
  411. * End vertex declaration.
  412. */
  413. BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _decl);
  414. /**
  415. * Pack vec4 into vertex stream format.
  416. */
  417. 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);
  418. /**
  419. * Unpack vec4 from vertex stream format.
  420. */
  421. 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);
  422. /**
  423. * Converts vertex stream data from one vertex stream format to another.
  424. *
  425. * @param _destDecl Destination vertex stream declaration.
  426. * @param _destData Destination vertex stream.
  427. * @param _srcDecl Source vertex stream declaration.
  428. * @param _srcData Source vertex stream data.
  429. * @param _num Number of vertices to convert from source to destination.
  430. */
  431. 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);
  432. /**
  433. * Weld vertices.
  434. *
  435. * @param _output Welded vertices remapping table. The size of buffer
  436. * must be the same as number of vertices.
  437. * @param _decl Vertex stream declaration.
  438. * @param _data Vertex stream.
  439. * @param _num Number of vertices in vertex stream.
  440. * @param _epsilon Error tolerance for vertex position comparison.
  441. * @returns Number of unique vertices after vertex welding.
  442. */
  443. 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);
  444. /**
  445. * Swizzle RGBA8 image to BGRA8.
  446. *
  447. * @param _width Width of input image (pixels).
  448. * @param _height Height of input image (pixels).
  449. * @param _pitch Pitch of input image (bytes).
  450. * @param _src Source image.
  451. * @param _dst Destination image. Must be the same size as input image.
  452. * _dst might be pointer to the same memory as _src.
  453. */
  454. BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  455. /**
  456. * Downsample RGBA8 image with 2x2 pixel average filter.
  457. *
  458. * @param _width Width of input image (pixels).
  459. * @param _height Height of input image (pixels).
  460. * @param _pitch Pitch of input image (bytes).
  461. * @param _src Source image.
  462. * @param _dst Destination image. Must be at least quarter size of
  463. * input image. _dst might be pointer to the same memory as _src.
  464. */
  465. BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  466. /**
  467. * Returns supported backend API renderers.
  468. */
  469. BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);
  470. /**
  471. * Returns name of renderer.
  472. */
  473. BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type);
  474. /**
  475. * Initialize bgfx library.
  476. *
  477. * @param _type Select rendering backend. When set to RendererType::Count
  478. * default rendering backend will be selected.
  479. *
  480. * @param _callback Provide application specific callback interface.
  481. * See: CallbackI
  482. *
  483. * @param _reallocator Custom allocator. When custom allocator is not
  484. * specified, library uses default CRT allocator. The library assumes
  485. * custom allocator is thread safe.
  486. */
  487. 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);
  488. /**
  489. * Shutdown bgfx library.
  490. */
  491. BGFX_C_API void bgfx_shutdown();
  492. /**
  493. * Reset graphic settings.
  494. */
  495. BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags);
  496. /**
  497. * Advance to next frame. When using multithreaded renderer, this call
  498. * just swaps internal buffers, kicks render thread, and returns. In
  499. * singlethreaded renderer this call does frame rendering.
  500. *
  501. * @returns Current frame number. This might be used in conjunction with
  502. * double/multi buffering data outside the library and passing it to
  503. * library via makeRef calls.
  504. */
  505. BGFX_C_API uint32_t bgfx_frame();
  506. /**
  507. * Returns current renderer backend API type.
  508. *
  509. * NOTE:
  510. * Library must be initialized.
  511. */
  512. BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type();
  513. /**
  514. * Returns renderer capabilities.
  515. *
  516. * NOTE:
  517. * Library must be initialized.
  518. */
  519. BGFX_C_API const bgfx_caps_t* bgfx_get_caps();
  520. /**
  521. * Returns HMD info.
  522. */
  523. BGFX_C_API const bgfx_hmd_t* bgfx_get_hmd();
  524. /**
  525. * Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
  526. */
  527. BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size);
  528. /**
  529. * Allocate buffer and copy data into it. Data will be freed inside bgfx.
  530. */
  531. BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size);
  532. /**
  533. * Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
  534. * doesn't allocate memory for data. It just copies pointer to data.
  535. * You must make sure data is available for at least 2 bgfx::frame calls.
  536. */
  537. BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size);
  538. /**
  539. *
  540. */
  541. BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData);
  542. /**
  543. * Set debug flags.
  544. *
  545. * @param _debug Available flags:
  546. *
  547. * BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
  548. * all rendering calls will be skipped. It's useful when profiling
  549. * to quickly assess bottleneck between CPU and GPU.
  550. *
  551. * BGFX_DEBUG_STATS - Display internal statistics.
  552. *
  553. * BGFX_DEBUG_TEXT - Display debug text.
  554. *
  555. * BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
  556. * primitives will be rendered as lines.
  557. */
  558. BGFX_C_API void bgfx_set_debug(uint32_t _debug);
  559. /**
  560. * Clear internal debug text buffer.
  561. */
  562. BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small);
  563. /**
  564. * Print into internal debug text buffer.
  565. */
  566. BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
  567. /**
  568. * Draw image into internal debug text buffer.
  569. *
  570. * @param _x X position from top-left.
  571. * @param _y Y position from top-left.
  572. * @param _width Image width.
  573. * @param _height Image height.
  574. * @param _data Raw image data (character/attribute raw encoding).
  575. * @param _pitch Image pitch in bytes.
  576. */
  577. 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);
  578. /**
  579. * Create static index buffer.
  580. *
  581. * NOTE:
  582. * Only 16-bit index buffer is supported.
  583. */
  584. BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem);
  585. /**
  586. * Destroy static index buffer.
  587. */
  588. BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle);
  589. /**
  590. * Create static vertex buffer.
  591. *
  592. * @param _mem Vertex buffer data.
  593. * @param _decl Vertex declaration.
  594. * @returns Static vertex buffer handle.
  595. */
  596. 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);
  597. /**
  598. * Destroy static vertex buffer.
  599. *
  600. * @param _handle Static vertex buffer handle.
  601. */
  602. BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle);
  603. /**
  604. * Create empty dynamic index buffer.
  605. *
  606. * @param _num Number of indices.
  607. *
  608. * NOTE:
  609. * Only 16-bit index buffer is supported.
  610. */
  611. BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num);
  612. /**
  613. * Create dynamic index buffer and initialized it.
  614. *
  615. * @param _mem Index buffer data.
  616. *
  617. * NOTE:
  618. * Only 16-bit index buffer is supported.
  619. */
  620. BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem);
  621. /**
  622. * Update dynamic index buffer.
  623. *
  624. * @param _handle Dynamic index buffer handle.
  625. * @param _mem Index buffer data.
  626. */
  627. BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, const bgfx_memory_t* _mem);
  628. /**
  629. * Destroy dynamic index buffer.
  630. *
  631. * @param _handle Dynamic index buffer handle.
  632. */
  633. BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle);
  634. /**
  635. * Create empty dynamic vertex buffer.
  636. *
  637. * @param _num Number of vertices.
  638. * @param _decl Vertex declaration.
  639. */
  640. 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);
  641. /**
  642. * Create dynamic vertex buffer and initialize it.
  643. *
  644. * @param _mem Vertex buffer data.
  645. * @param _decl Vertex declaration.
  646. */
  647. 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);
  648. /**
  649. * Update dynamic vertex buffer.
  650. */
  651. BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, const bgfx_memory_t* _mem);
  652. /**
  653. * Destroy dynamic vertex buffer.
  654. */
  655. BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle);
  656. /**
  657. * Returns true if internal transient index buffer has enough space.
  658. *
  659. * @param _num Number of indices.
  660. */
  661. BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num);
  662. /**
  663. * Returns true if internal transient vertex buffer has enough space.
  664. *
  665. * @param _num Number of vertices.
  666. * @param _decl Vertex declaration.
  667. */
  668. BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl);
  669. /**
  670. * Returns true if internal instance data buffer has enough space.
  671. *
  672. * @param _num Number of instances.
  673. * @param _stride Stride per instance.
  674. */
  675. BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride);
  676. /**
  677. * Returns true if both internal transient index and vertex buffer have
  678. * enough space.
  679. *
  680. * @param _numVertices Number of vertices.
  681. * @param _decl Vertex declaration.
  682. * @param _numIndices Number of indices.
  683. */
  684. BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices);
  685. /**
  686. * Allocate transient index buffer.
  687. *
  688. * @param[out] _tib TransientIndexBuffer structure is filled and is valid
  689. * for the duration of frame, and it can be reused for multiple draw
  690. * calls.
  691. * @param _num Number of indices to allocate.
  692. *
  693. * NOTE:
  694. * 1. You must call setIndexBuffer after alloc in order to avoid memory
  695. * leak.
  696. * 2. Only 16-bit index buffer is supported.
  697. */
  698. BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num);
  699. /**
  700. * Allocate transient vertex buffer.
  701. *
  702. * @param[out] _tvb TransientVertexBuffer structure is filled and is valid
  703. * for the duration of frame, and it can be reused for multiple draw
  704. * calls.
  705. * @param _num Number of vertices to allocate.
  706. * @param _decl Vertex declaration.
  707. *
  708. * NOTE:
  709. * You must call setVertexBuffer after alloc in order to avoid memory
  710. * leak.
  711. */
  712. BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl);
  713. /**
  714. * Check for required space and allocate transient vertex and index
  715. * buffers. If both space requirements are satisfied function returns
  716. * true.
  717. *
  718. * NOTE:
  719. * Only 16-bit index buffer is supported.
  720. */
  721. 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);
  722. /**
  723. * Allocate instance data buffer.
  724. *
  725. * NOTE:
  726. * You must call setInstanceDataBuffer after alloc in order to avoid
  727. * memory leak.
  728. */
  729. BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(uint32_t _num, uint16_t _stride);
  730. /**
  731. * Create shader from memory buffer.
  732. */
  733. BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem);
  734. /**
  735. * Returns num of uniforms, and uniform handles used inside shader.
  736. *
  737. * @param _handle Shader handle.
  738. * @param _uniforms UniformHandle array where data will be stored.
  739. * @param _max Maximum capacity of array.
  740. * @returns Number of uniforms used by shader.
  741. *
  742. * NOTE:
  743. * Only non-predefined uniforms are returned.
  744. */
  745. BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max);
  746. /**
  747. * Destroy shader. Once program is created with shader it is safe to
  748. * destroy shader.
  749. */
  750. BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle);
  751. /**
  752. * Create program with vertex and fragment shaders.
  753. *
  754. * @param _vsh Vertex shader.
  755. * @param _fsh Fragment shader.
  756. * @param _destroyShaders If true, shaders will be destroyed when
  757. * program is destroyed.
  758. * @returns Program handle if vertex shader output and fragment shader
  759. * input are matching, otherwise returns invalid program handle.
  760. */
  761. BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
  762. /**
  763. * Destroy program.
  764. */
  765. BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle);
  766. /**
  767. * Calculate amount of memory required for texture.
  768. */
  769. 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);
  770. /**
  771. * Create texture from memory buffer.
  772. *
  773. * @param _mem DDS, KTX or PVR texture data.
  774. * @param _flags Default texture sampling mode is linear, and wrap mode
  775. * is repeat.
  776. *
  777. * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  778. * mode.
  779. *
  780. * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  781. * sampling.
  782. *
  783. * @param _skip Skip top level mips when parsing texture.
  784. * @param _info Returns parsed texture information.
  785. * @returns Texture handle.
  786. */
  787. 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);
  788. /**
  789. * Create 2D texture.
  790. *
  791. * @param _width
  792. * @param _height
  793. * @param _numMips
  794. * @param _format
  795. * @param _flags
  796. * @param _mem
  797. */
  798. 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);
  799. /**
  800. * Create 3D texture.
  801. *
  802. * @param _width
  803. * @param _height
  804. * @param _depth
  805. * @param _numMips
  806. * @param _format
  807. * @param _flags
  808. * @param _mem
  809. */
  810. 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);
  811. /**
  812. * Create Cube texture.
  813. *
  814. * @param _size
  815. * @param _numMips
  816. * @param _format
  817. * @param _flags
  818. * @param _mem
  819. */
  820. 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);
  821. /**
  822. * Update 2D texture.
  823. *
  824. * @param _handle
  825. * @param _mip
  826. * @param _x
  827. * @param _y
  828. * @param _width
  829. * @param _height
  830. * @param _mem
  831. * @param _pitch Pitch of input image (bytes). When _pitch is set to
  832. * UINT16_MAX, it will be calculated internally based on _width.
  833. */
  834. 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);
  835. /**
  836. * Update 3D texture.
  837. *
  838. * @param _handle
  839. * @param _mip
  840. * @param _x
  841. * @param _y
  842. * @param _z
  843. * @param _width
  844. * @param _height
  845. * @param _depth
  846. * @param _mem
  847. */
  848. 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);
  849. /**
  850. * Update Cube texture.
  851. *
  852. * @param _handle
  853. * @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
  854. * -Y, 4 is +Z, and 5 is -Z.
  855. *
  856. * +----------+
  857. * |-z 2|
  858. * | ^ +y |
  859. * | | |
  860. * | +---->+x |
  861. * +----------+----------+----------+----------+
  862. * |+y 1|+y 4|+y 0|+y 5|
  863. * | ^ -x | ^ +z | ^ +x | ^ -z |
  864. * | | | | | | | | |
  865. * | +---->+z | +---->+x | +---->-z | +---->-x |
  866. * +----------+----------+----------+----------+
  867. * |+z 3|
  868. * | ^ -y |
  869. * | | |
  870. * | +---->+x |
  871. * +----------+
  872. *
  873. * @param _mip
  874. * @param _x
  875. * @param _y
  876. * @param _width
  877. * @param _height
  878. * @param _mem
  879. * @param _pitch Pitch of input image (bytes). When _pitch is set to
  880. * UINT16_MAX, it will be calculated internally based on _width.
  881. */
  882. 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);
  883. /**
  884. * Destroy texture.
  885. */
  886. BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle);
  887. /**
  888. * Create frame buffer (simple).
  889. *
  890. * @param _width Texture width.
  891. * @param _height Texture height.
  892. * @param _format Texture format.
  893. * @param _textureFlags Texture flags.
  894. */
  895. 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);
  896. /**
  897. * Create frame buffer.
  898. *
  899. * @param _num Number of texture attachments.
  900. * @param _handles Texture attachments.
  901. * @param _destroyTextures If true, textures will be destroyed when
  902. * frame buffer is destroyed.
  903. */
  904. BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures);
  905. /**
  906. * Create frame buffer for multiple window rendering.
  907. *
  908. * @param _nwh OS' target native window handle.
  909. * @param _width Window back buffer width.
  910. * @param _height Window back buffer height.
  911. * @param _depthFormat Window back buffer depth format.
  912. *
  913. * NOTE:
  914. * Frame buffer cannnot be used for sampling.
  915. */
  916. 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);
  917. /**
  918. * Destroy frame buffer.
  919. */
  920. BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle);
  921. /**
  922. * Create shader uniform parameter.
  923. *
  924. * @param _name Uniform name in shader.
  925. * @param _type Type of uniform (See: UniformType).
  926. * @param _num Number of elements in array.
  927. *
  928. * Predefined uniforms:
  929. *
  930. * u_viewRect vec4(x, y, width, height) - view rectangle for current
  931. * view.
  932. *
  933. * u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
  934. * width and height
  935. *
  936. * u_view mat4 - view matrix
  937. *
  938. * u_invView mat4 - inverted view matrix
  939. *
  940. * u_proj mat4 - projection matrix
  941. *
  942. * u_invProj mat4 - inverted projection matrix
  943. *
  944. * u_viewProj mat4 - concatenated view projection matrix
  945. *
  946. * u_invViewProj mat4 - concatenated inverted view projection matrix
  947. *
  948. * u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
  949. *
  950. * u_modelView mat4 - concatenated model view matrix, only first
  951. * model matrix from array is used.
  952. *
  953. * u_modelViewProj mat4 - concatenated model view projection matrix.
  954. *
  955. * u_alphaRef float - alpha reference value for alpha test.
  956. */
  957. BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);
  958. /**
  959. * Destroy shader uniform parameter.
  960. */
  961. BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle);
  962. /**
  963. * Set clear color palette value.
  964. *
  965. * @param _index Index into palette.
  966. * @param _rgba RGBA floating point value.
  967. */
  968. BGFX_C_API void bgfx_set_clear_color(uint8_t _index, const float _rgba[4]);
  969. /**
  970. * Set view name.
  971. *
  972. * @param _id View id.
  973. * @param _name View name.
  974. *
  975. * NOTE:
  976. * This is debug only feature.
  977. */
  978. BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name);
  979. /**
  980. * Set view rectangle. Draw primitive outside view will be clipped.
  981. *
  982. * @param _id View id.
  983. * @param _x Position x from the left corner of the window.
  984. * @param _y Position y from the top corner of the window.
  985. * @param _width Width of view port region.
  986. * @param _height Height of view port region.
  987. */
  988. BGFX_C_API void bgfx_set_view_rect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  989. /**
  990. * Set view scissor. Draw primitive outside view will be clipped. When
  991. * _x, _y, _width and _height are set to 0, scissor will be disabled.
  992. *
  993. * @param _x Position x from the left corner of the window.
  994. * @param _y Position y from the top corner of the window.
  995. * @param _width Width of scissor region.
  996. * @param _height Height of scissor region.
  997. */
  998. BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  999. /**
  1000. * Set view clear flags.
  1001. *
  1002. * @param _id View id.
  1003. * @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
  1004. * operation. See: BGFX_CLEAR_*.
  1005. * @param _rgba Color clear value.
  1006. * @param _depth Depth clear value.
  1007. * @param _stencil Stencil clear value.
  1008. */
  1009. BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);
  1010. /**
  1011. * Set view clear flags with different clear color for each
  1012. * frame buffer texture. Must use setClearColor to setup clear color
  1013. * palette.
  1014. * @param _id View id.
  1015. * @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
  1016. * operation. See: BGFX_CLEAR_*.
  1017. * @param _depth Depth clear value.
  1018. * @param _stencil Stencil clear value.
  1019. */
  1020. 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);
  1021. /**
  1022. * Set view into sequential mode. Draw calls will be sorted in the same
  1023. * order in which submit calls were called.
  1024. */
  1025. BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled);
  1026. /**
  1027. * Set view frame buffer.
  1028. *
  1029. * @param _id View id.
  1030. * @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as
  1031. * frame buffer handle will draw primitives from this view into
  1032. * default back buffer.
  1033. */
  1034. BGFX_C_API void bgfx_set_view_frame_buffer(uint8_t _id, bgfx_frame_buffer_handle_t _handle);
  1035. /**
  1036. * Set view view and projection matrices, all draw primitives in this
  1037. * view will use these matrices.
  1038. */
  1039. BGFX_C_API void bgfx_set_view_transform(uint8_t _id, const void* _view, const void* _proj);
  1040. /**
  1041. * Set view view and projection matrices, all draw primitives in this
  1042. * view will use these matrices.
  1043. */
  1044. BGFX_C_API void bgfx_set_view_transform_stereo(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR);
  1045. /**
  1046. * Sets debug marker.
  1047. */
  1048. BGFX_C_API void bgfx_set_marker(const char* _marker);
  1049. /**
  1050. * Set render states for draw primitive.
  1051. *
  1052. * @param _state State flags. Default state for primitive type is
  1053. * triangles. See: BGFX_STATE_DEFAULT.
  1054. *
  1055. * BGFX_STATE_ALPHA_WRITE - Enable alpha write.
  1056. * BGFX_STATE_DEPTH_WRITE - Enable depth write.
  1057. * BGFX_STATE_DEPTH_TEST_* - Depth test function.
  1058. * BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
  1059. * BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
  1060. * BGFX_STATE_CULL_* - Backface culling mode.
  1061. * BGFX_STATE_RGB_WRITE - Enable RGB write.
  1062. * BGFX_STATE_MSAA - Enable MSAA.
  1063. * BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
  1064. *
  1065. * @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
  1066. * BGFX_STATE_BLEND_INV_FACTOR blend modes.
  1067. *
  1068. * NOTE:
  1069. * 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
  1070. * BGFX_STATE_BLEND_FUNC macros to setup more complex states.
  1071. * 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
  1072. * equation is specified.
  1073. */
  1074. BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba);
  1075. /**
  1076. * Set stencil test state.
  1077. *
  1078. * @param _fstencil Front stencil state.
  1079. * @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
  1080. * _fstencil is applied to both front and back facing primitives.
  1081. */
  1082. BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil);
  1083. /**
  1084. * Set scissor for draw primitive. For scissor for all primitives in
  1085. * view see setViewScissor.
  1086. *
  1087. * @param _x Position x from the left corner of the window.
  1088. * @param _y Position y from the top corner of the window.
  1089. * @param _width Width of scissor region.
  1090. * @param _height Height of scissor region.
  1091. * @returns Scissor cache index.
  1092. */
  1093. BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  1094. /**
  1095. * Set scissor from cache for draw primitive.
  1096. *
  1097. * @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
  1098. * scissor and primitive will use view scissor instead.
  1099. */
  1100. BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache);
  1101. /**
  1102. * Set model matrix for draw primitive. If it is not called model will
  1103. * be rendered with identity model matrix.
  1104. *
  1105. * @param _mtx Pointer to first matrix in array.
  1106. * @param _num Number of matrices in array.
  1107. * @returns index into matrix cache in case the same model matrix has
  1108. * to be used for other draw primitive call.
  1109. */
  1110. BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num);
  1111. /**
  1112. * Reserve `_num` matrices in internal matrix cache. Pointer returned
  1113. * can be modifed until `bgfx::frame` is called.
  1114. *
  1115. * @param _transform Pointer to `Transform` structure.
  1116. * @param _num Number of matrices.
  1117. * @returns index into matrix cache.
  1118. */
  1119. BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num);
  1120. /**
  1121. * Set model matrix from matrix cache for draw primitive.
  1122. *
  1123. * @param _cache Index in matrix cache.
  1124. * @param _num Number of matrices from cache.
  1125. */
  1126. BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num);
  1127. /**
  1128. * Set shader uniform parameter for draw primitive.
  1129. */
  1130. BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num);
  1131. /**
  1132. * Set index buffer for draw primitive.
  1133. */
  1134. BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
  1135. /**
  1136. * Set index buffer for draw primitive.
  1137. */
  1138. BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
  1139. /**
  1140. * Set index buffer for draw primitive.
  1141. */
  1142. BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices);
  1143. /**
  1144. * Set vertex buffer for draw primitive.
  1145. */
  1146. BGFX_C_API void bgfx_set_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);
  1147. /**
  1148. * Set vertex buffer for draw primitive.
  1149. */
  1150. BGFX_C_API void bgfx_set_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices);
  1151. /**
  1152. * Set vertex buffer for draw primitive.
  1153. */
  1154. BGFX_C_API void bgfx_set_transient_vertex_buffer(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices);
  1155. /**
  1156. * Set instance data buffer for draw primitive.
  1157. */
  1158. BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _num);
  1159. /**
  1160. * Set program for draw primitive.
  1161. */
  1162. BGFX_C_API void bgfx_set_program(bgfx_program_handle_t _handle);
  1163. /**
  1164. * Set texture stage for draw primitive.
  1165. *
  1166. * @param _stage Texture unit.
  1167. * @param _sampler Program sampler.
  1168. * @param _handle Texture handle.
  1169. * @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1170. * texture sampling settings from the texture.
  1171. *
  1172. * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  1173. * mode.
  1174. *
  1175. * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  1176. * sampling.
  1177. *
  1178. * @param _flags Texture sampler filtering flags. UINT32_MAX use the
  1179. * sampler filtering mode set by texture.
  1180. */
  1181. BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
  1182. /**
  1183. * Set texture stage for draw primitive.
  1184. *
  1185. * @param _stage Texture unit.
  1186. * @param _sampler Program sampler.
  1187. * @param _handle Frame buffer handle.
  1188. * @param _attachment Attachment index.
  1189. * @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1190. * texture sampling settings from the texture.
  1191. *
  1192. * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  1193. * mode.
  1194. *
  1195. * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  1196. * sampling.
  1197. */
  1198. 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);
  1199. /**
  1200. * Submit primitive for rendering into single view.
  1201. *
  1202. * @param _id View id.
  1203. * @param _depth Depth for sorting.
  1204. * @returns Number of draw calls.
  1205. */
  1206. BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth);
  1207. /**
  1208. *
  1209. */
  1210. 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);
  1211. /**
  1212. *
  1213. */
  1214. 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);
  1215. /**
  1216. * Dispatch compute.
  1217. */
  1218. 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);
  1219. /**
  1220. * Discard all previously set state for draw call.
  1221. */
  1222. BGFX_C_API void bgfx_discard();
  1223. /**
  1224. * Request screen shot.
  1225. *
  1226. * @param _filePath Will be passed to CallbackI::screenShot callback.
  1227. *
  1228. * NOTE:
  1229. * CallbackI::screenShot must be implemented.
  1230. */
  1231. BGFX_C_API void bgfx_save_screen_shot(const char* _filePath);
  1232. #endif // BGFX_C99_H_HEADER_GUARD