bgfx.c99.h 41 KB

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