bgfx.c99.h 40 KB

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