bgfx.c99.h 41 KB

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