bgfx.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef __BGFX_H__
  6. #define __BGFX_H__
  7. #include <stdint.h> // uint32_t
  8. #include <stdlib.h> // size_t
  9. ///
  10. #define BGFX_STATE_DEPTH_WRITE UINT64_C(0x0000000000000001)
  11. #define BGFX_STATE_ALPHA_WRITE UINT64_C(0x0000000000000008)
  12. #define BGFX_STATE_ALPHA_MASK UINT64_C(0x000000000000000c)
  13. #define BGFX_STATE_DEPTH_TEST_LESS UINT64_C(0x0000000000000010)
  14. #define BGFX_STATE_DEPTH_TEST_LEQUAL UINT64_C(0x0000000000000020)
  15. #define BGFX_STATE_DEPTH_TEST_EQUAL UINT64_C(0x0000000000000030)
  16. #define BGFX_STATE_DEPTH_TEST_GEQUAL UINT64_C(0x0000000000000040)
  17. #define BGFX_STATE_DEPTH_TEST_GREATER UINT64_C(0x0000000000000050)
  18. #define BGFX_STATE_DEPTH_TEST_NOTEQUAL UINT64_C(0x0000000000000060)
  19. #define BGFX_STATE_DEPTH_TEST_NEVER UINT64_C(0x0000000000000070)
  20. #define BGFX_STATE_DEPTH_TEST_ALWAYS UINT64_C(0x0000000000000080)
  21. #define BGFX_STATE_DEPTH_TEST_SHIFT 4
  22. #define BGFX_STATE_DEPTH_TEST_MASK UINT64_C(0x00000000000000f0)
  23. #define BGFX_STATE_BLEND_ZERO UINT64_C(0x0000000000001000)
  24. #define BGFX_STATE_BLEND_ONE UINT64_C(0x0000000000002000)
  25. #define BGFX_STATE_BLEND_SRC_COLOR UINT64_C(0x0000000000003000)
  26. #define BGFX_STATE_BLEND_INV_SRC_COLOR UINT64_C(0x0000000000004000)
  27. #define BGFX_STATE_BLEND_SRC_ALPHA UINT64_C(0x0000000000005000)
  28. #define BGFX_STATE_BLEND_INV_SRC_ALPHA UINT64_C(0x0000000000006000)
  29. #define BGFX_STATE_BLEND_DST_ALPHA UINT64_C(0x0000000000007000)
  30. #define BGFX_STATE_BLEND_INV_DST_ALPHA UINT64_C(0x0000000000008000)
  31. #define BGFX_STATE_BLEND_DST_COLOR UINT64_C(0x0000000000009000)
  32. #define BGFX_STATE_BLEND_INV_DST_COLOR UINT64_C(0x000000000000a000)
  33. #define BGFX_STATE_BLEND_SRC_ALPHA_SAT UINT64_C(0x000000000000b000)
  34. #define BGFX_STATE_BLEND_FACTOR UINT64_C(0x000000000000c000)
  35. #define BGFX_STATE_BLEND_INV_FACTOR UINT64_C(0x000000000000d000)
  36. #define BGFX_STATE_BLEND_SHIFT 12
  37. #define BGFX_STATE_BLEND_MASK UINT64_C(0x00000000000ff000)
  38. #define BGFX_STATE_BLEND_EQUATION_SUB UINT64_C(0x0000000000100000)
  39. #define BGFX_STATE_BLEND_EQUATION_REVSUB UINT64_C(0x0000000000200000)
  40. #define BGFX_STATE_BLEND_EQUATION_MIN UINT64_C(0x0000000000300000)
  41. #define BGFX_STATE_BLEND_EQUATION_MAX UINT64_C(0x0000000000400000)
  42. #define BGFX_STATE_BLEND_EQUATION_SHIFT 20
  43. #define BGFX_STATE_BLEND_EQUATION_MASK UINT64_C(0x0000000000700000)
  44. #define BGFX_STATE_CULL_CW UINT64_C(0x0000000010000000)
  45. #define BGFX_STATE_CULL_CCW UINT64_C(0x0000000020000000)
  46. #define BGFX_STATE_CULL_SHIFT 28
  47. #define BGFX_STATE_CULL_MASK UINT64_C(0x0000000030000000)
  48. #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000040000000)
  49. #define BGFX_STATE_ALPHA_REF_SHIFT 32
  50. #define BGFX_STATE_ALPHA_REF_MASK UINT64_C(0x000000ff00000000)
  51. #define BGFX_STATE_PT_LINES UINT64_C(0x0000010000000000)
  52. #define BGFX_STATE_PT_POINTS UINT64_C(0x0000020000000000)
  53. #define BGFX_STATE_PT_SHIFT 40
  54. #define BGFX_STATE_PT_MASK UINT64_C(0x0000030000000000)
  55. #define BGFX_STATE_POINT_SIZE_SHIFT 44
  56. #define BGFX_STATE_POINT_SIZE_MASK UINT64_C(0x000ff00000000000)
  57. #define BGFX_STATE_SRGBWRITE UINT64_C(0x0010000000000000)
  58. #define BGFX_STATE_MSAA UINT64_C(0x0020000000000000)
  59. #define BGFX_STATE_RESERVED_MASK UINT64_C(0xff00000000000000)
  60. #define BGFX_STATE_NONE UINT64_C(0x0000000000000000)
  61. #define BGFX_STATE_MASK UINT64_C(0xffffffffffffffff)
  62. #define BGFX_STATE_DEFAULT (0 \
  63. | BGFX_STATE_RGB_WRITE \
  64. | BGFX_STATE_ALPHA_WRITE \
  65. | BGFX_STATE_DEPTH_TEST_LESS \
  66. | BGFX_STATE_DEPTH_WRITE \
  67. | BGFX_STATE_CULL_CW \
  68. | BGFX_STATE_MSAA \
  69. )
  70. #define BGFX_STATE_ALPHA_REF(_ref) ( (uint64_t(_ref)<<BGFX_STATE_ALPHA_REF_SHIFT)&BGFX_STATE_ALPHA_REF_MASK)
  71. #define BGFX_STATE_POINT_SIZE(_size) ( (uint64_t(_size)<<BGFX_STATE_POINT_SIZE_SHIFT)&BGFX_STATE_POINT_SIZE_MASK)
  72. #define BGFX_STATE_BLEND_FUNC(_src, _dst) ( uint64_t(_src)|( uint64_t(_dst)<<4) )
  73. #define BGFX_STATE_BLEND_ADD (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) )
  74. #define BGFX_STATE_BLEND_ALPHA (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_COLOR) )
  75. #define BGFX_STATE_BLEND_DARKEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) | BGFX_STATE_BLEND_EQUATION_MIN)
  76. #define BGFX_STATE_BLEND_LIGHTEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) | BGFX_STATE_BLEND_EQUATION_MAX)
  77. #define BGFX_STATE_BLEND_MULTIPLY (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO ) )
  78. #define BGFX_STATE_BLEND_NORMAL (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA) )
  79. #define BGFX_STATE_BLEND_SCREEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR) )
  80. #define BGFX_STATE_BLEND_LINEAR_BURN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_DST_COLOR) | BGFX_STATE_BLEND_EQUATION_SUB)
  81. ///
  82. #define BGFX_STENCIL_FUNC_REF_SHIFT 0
  83. #define BGFX_STENCIL_FUNC_REF_MASK UINT32_C(0x000000ff)
  84. #define BGFX_STENCIL_FUNC_RMASK_SHIFT 8
  85. #define BGFX_STENCIL_FUNC_RMASK_MASK UINT32_C(0x0000ff00)
  86. #define BGFX_STENCIL_TEST_LESS UINT32_C(0x00010000)
  87. #define BGFX_STENCIL_TEST_LEQUAL UINT32_C(0x00020000)
  88. #define BGFX_STENCIL_TEST_EQUAL UINT32_C(0x00030000)
  89. #define BGFX_STENCIL_TEST_GEQUAL UINT32_C(0x00040000)
  90. #define BGFX_STENCIL_TEST_GREATER UINT32_C(0x00050000)
  91. #define BGFX_STENCIL_TEST_NOTEQUAL UINT32_C(0x00060000)
  92. #define BGFX_STENCIL_TEST_NEVER UINT32_C(0x00070000)
  93. #define BGFX_STENCIL_TEST_ALWAYS UINT32_C(0x00080000)
  94. #define BGFX_STENCIL_TEST_SHIFT 16
  95. #define BGFX_STENCIL_TEST_MASK UINT32_C(0x000f0000)
  96. #define BGFX_STENCIL_OP_FAIL_S_ZERO UINT32_C(0x00000000)
  97. #define BGFX_STENCIL_OP_FAIL_S_KEEP UINT32_C(0x00100000)
  98. #define BGFX_STENCIL_OP_FAIL_S_REPLACE UINT32_C(0x00200000)
  99. #define BGFX_STENCIL_OP_FAIL_S_INCR UINT32_C(0x00300000)
  100. #define BGFX_STENCIL_OP_FAIL_S_INCRSAT UINT32_C(0x00400000)
  101. #define BGFX_STENCIL_OP_FAIL_S_DECR UINT32_C(0x00500000)
  102. #define BGFX_STENCIL_OP_FAIL_S_DECRSAT UINT32_C(0x00600000)
  103. #define BGFX_STENCIL_OP_FAIL_S_INVERT UINT32_C(0x00700000)
  104. #define BGFX_STENCIL_OP_FAIL_S_SHIFT 20
  105. #define BGFX_STENCIL_OP_FAIL_S_MASK UINT32_C(0x00f00000)
  106. #define BGFX_STENCIL_OP_FAIL_Z_ZERO UINT32_C(0x00000000)
  107. #define BGFX_STENCIL_OP_FAIL_Z_KEEP UINT32_C(0x01000000)
  108. #define BGFX_STENCIL_OP_FAIL_Z_REPLACE UINT32_C(0x02000000)
  109. #define BGFX_STENCIL_OP_FAIL_Z_INCR UINT32_C(0x03000000)
  110. #define BGFX_STENCIL_OP_FAIL_Z_INCRSAT UINT32_C(0x04000000)
  111. #define BGFX_STENCIL_OP_FAIL_Z_DECR UINT32_C(0x05000000)
  112. #define BGFX_STENCIL_OP_FAIL_Z_DECRSAT UINT32_C(0x06000000)
  113. #define BGFX_STENCIL_OP_FAIL_Z_INVERT UINT32_C(0x07000000)
  114. #define BGFX_STENCIL_OP_FAIL_Z_SHIFT 24
  115. #define BGFX_STENCIL_OP_FAIL_Z_MASK UINT32_C(0x0f000000)
  116. #define BGFX_STENCIL_OP_PASS_Z_ZERO UINT32_C(0x00000000)
  117. #define BGFX_STENCIL_OP_PASS_Z_KEEP UINT32_C(0x10000000)
  118. #define BGFX_STENCIL_OP_PASS_Z_REPLACE UINT32_C(0x20000000)
  119. #define BGFX_STENCIL_OP_PASS_Z_INCR UINT32_C(0x30000000)
  120. #define BGFX_STENCIL_OP_PASS_Z_INCRSAT UINT32_C(0x40000000)
  121. #define BGFX_STENCIL_OP_PASS_Z_DECR UINT32_C(0x50000000)
  122. #define BGFX_STENCIL_OP_PASS_Z_DECRSAT UINT32_C(0x60000000)
  123. #define BGFX_STENCIL_OP_PASS_Z_INVERT UINT32_C(0x70000000)
  124. #define BGFX_STENCIL_OP_PASS_Z_SHIFT 28
  125. #define BGFX_STENCIL_OP_PASS_Z_MASK UINT32_C(0xf0000000)
  126. #define BGFX_STENCIL_NONE UINT32_C(0x00000000)
  127. #define BGFX_STENCIL_MASK UINT32_C(0xffffffff)
  128. #define BGFX_STENCIL_DEFAULT UINT32_C(0x00000000)
  129. #define BGFX_STENCIL_FUNC_REF(_ref) ( (uint32_t(_ref)<<BGFX_STENCIL_FUNC_REF_SHIFT)&BGFX_STENCIL_FUNC_REF_MASK)
  130. #define BGFX_STENCIL_FUNC_RMASK(_mask) ( (uint32_t(_mask)<<BGFX_STENCIL_FUNC_RMASK_SHIFT)&BGFX_STENCIL_FUNC_RMASK_MASK)
  131. ///
  132. #define BGFX_CLEAR_NONE UINT8_C(0x00)
  133. #define BGFX_CLEAR_COLOR_BIT UINT8_C(0x01)
  134. #define BGFX_CLEAR_DEPTH_BIT UINT8_C(0x02)
  135. #define BGFX_CLEAR_STENCIL_BIT UINT8_C(0x04)
  136. ///
  137. #define BGFX_DEBUG_NONE UINT32_C(0x00000000)
  138. #define BGFX_DEBUG_WIREFRAME UINT32_C(0x00000001)
  139. #define BGFX_DEBUG_IFH UINT32_C(0x00000002)
  140. #define BGFX_DEBUG_STATS UINT32_C(0x00000004)
  141. #define BGFX_DEBUG_TEXT UINT32_C(0x00000008)
  142. ///
  143. #define BGFX_TEXTURE_NONE UINT32_C(0x00000000)
  144. #define BGFX_TEXTURE_U_MIRROR UINT32_C(0x00000001)
  145. #define BGFX_TEXTURE_U_CLAMP UINT32_C(0x00000002)
  146. #define BGFX_TEXTURE_U_SHIFT 0
  147. #define BGFX_TEXTURE_U_MASK UINT32_C(0x00000003)
  148. #define BGFX_TEXTURE_V_MIRROR UINT32_C(0x00000010)
  149. #define BGFX_TEXTURE_V_CLAMP UINT32_C(0x00000020)
  150. #define BGFX_TEXTURE_V_SHIFT 4
  151. #define BGFX_TEXTURE_V_MASK UINT32_C(0x00000030)
  152. #define BGFX_TEXTURE_W_MIRROR UINT32_C(0x00000100)
  153. #define BGFX_TEXTURE_W_CLAMP UINT32_C(0x00000200)
  154. #define BGFX_TEXTURE_W_SHIFT 8
  155. #define BGFX_TEXTURE_W_MASK UINT32_C(0x00000300)
  156. #define BGFX_TEXTURE_MIN_POINT UINT32_C(0x00001000)
  157. #define BGFX_TEXTURE_MIN_ANISOTROPIC UINT32_C(0x00002000)
  158. #define BGFX_TEXTURE_MIN_SHIFT 12
  159. #define BGFX_TEXTURE_MIN_MASK UINT32_C(0x00003000)
  160. #define BGFX_TEXTURE_MAG_POINT UINT32_C(0x00010000)
  161. #define BGFX_TEXTURE_MAG_ANISOTROPIC UINT32_C(0x00020000)
  162. #define BGFX_TEXTURE_MAG_SHIFT 16
  163. #define BGFX_TEXTURE_MAG_MASK UINT32_C(0x00030000)
  164. #define BGFX_TEXTURE_MIP_POINT UINT32_C(0x00100000)
  165. #define BGFX_TEXTURE_MIP_SHIFT 20
  166. #define BGFX_TEXTURE_MIP_MASK UINT32_C(0x00100000)
  167. #define BGFX_TEXTURE_SRGB UINT32_C(0x00200000)
  168. ///
  169. #define BGFX_RENDER_TARGET_NONE UINT32_C(0x00000000)
  170. #define BGFX_RENDER_TARGET_COLOR_RGBA8 UINT32_C(0x00000001)
  171. #define BGFX_RENDER_TARGET_COLOR_RGB10A2 UINT32_C(0x00000002)
  172. #define BGFX_RENDER_TARGET_COLOR_RGBA16 UINT32_C(0x00000003)
  173. #define BGFX_RENDER_TARGET_COLOR_RGBA16F UINT32_C(0x00000004)
  174. #define BGFX_RENDER_TARGET_COLOR_R16F UINT32_C(0x00000005)
  175. #define BGFX_RENDER_TARGET_COLOR_R32F UINT32_C(0x00000006)
  176. #define BGFX_RENDER_TARGET_COLOR_SHIFT 0
  177. #define BGFX_RENDER_TARGET_COLOR_MASK UINT32_C(0x000000ff)
  178. #define BGFX_RENDER_TARGET_DEPTH UINT32_C(0x00000100)
  179. #define BGFX_RENDER_TARGET_DEPTH_SHIFT 8
  180. #define BGFX_RENDER_TARGET_DEPTH_MASK UINT32_C(0x0000ff00)
  181. #define BGFX_RENDER_TARGET_MSAA_X2 UINT32_C(0x00010000)
  182. #define BGFX_RENDER_TARGET_MSAA_X4 UINT32_C(0x00020000)
  183. #define BGFX_RENDER_TARGET_MSAA_X8 UINT32_C(0x00030000)
  184. #define BGFX_RENDER_TARGET_MSAA_X16 UINT32_C(0x00040000)
  185. #define BGFX_RENDER_TARGET_MSAA_SHIFT 16
  186. #define BGFX_RENDER_TARGET_MSAA_MASK UINT32_C(0x00070000)
  187. #define BGFX_RENDER_TARGET_SRGBWRITE UINT32_C(0x00080000)
  188. ///
  189. #define BGFX_RESET_NONE UINT32_C(0x00000000)
  190. #define BGFX_RESET_FULLSCREEN UINT32_C(0x00000001)
  191. #define BGFX_RESET_FULLSCREEN_SHIFT 0
  192. #define BGFX_RESET_FULLSCREEN_MASK UINT32_C(0x00000001)
  193. #define BGFX_RESET_MSAA_X2 UINT32_C(0x00000010)
  194. #define BGFX_RESET_MSAA_X4 UINT32_C(0x00000020)
  195. #define BGFX_RESET_MSAA_X8 UINT32_C(0x00000030)
  196. #define BGFX_RESET_MSAA_X16 UINT32_C(0x00000040)
  197. #define BGFX_RESET_MSAA_SHIFT 4
  198. #define BGFX_RESET_MSAA_MASK UINT32_C(0x00000070)
  199. #define BGFX_RESET_VSYNC UINT32_C(0x00000080)
  200. #define BGFX_RESET_CAPTURE UINT32_C(0x00000100)
  201. ///
  202. #define BGFX_HANDLE(_name) struct _name { uint16_t idx; }
  203. #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
  204. /// BGFX
  205. namespace bgfx
  206. {
  207. struct Fatal
  208. {
  209. enum Enum
  210. {
  211. DebugCheck,
  212. MinimumRequiredSpecs,
  213. InvalidShader,
  214. UnableToInitialize,
  215. UnableToCreateRenderTarget,
  216. UnableToCreateTexture,
  217. };
  218. };
  219. struct RendererType
  220. {
  221. enum Enum
  222. {
  223. Null,
  224. Direct3D9,
  225. Direct3D11,
  226. OpenGLES2,
  227. OpenGLES3,
  228. OpenGL,
  229. Count
  230. };
  231. };
  232. struct Attrib
  233. {
  234. enum Enum // corresponds to vertex shader attribute:
  235. {
  236. Position, // a_position
  237. Normal, // a_normal
  238. Tangent, // a_tangent
  239. Color0, // a_color0
  240. Color1, // a_color1
  241. Indices, // a_indices
  242. Weight, // a_weight
  243. TexCoord0, // a_texcoord0
  244. TexCoord1, // a_texcoord1
  245. TexCoord2, // a_texcoord2
  246. TexCoord3, // a_texcoord3
  247. TexCoord4, // a_texcoord4
  248. TexCoord5, // a_texcoord5
  249. TexCoord6, // a_texcoord6
  250. TexCoord7, // a_texcoord7
  251. Count
  252. };
  253. };
  254. struct AttribType
  255. {
  256. enum Enum
  257. {
  258. Uint8,
  259. Int16,
  260. Half,
  261. Float,
  262. Count
  263. };
  264. };
  265. struct TextureFormat
  266. {
  267. enum Enum
  268. {
  269. BC1, // DXT1
  270. BC2, // DXT3
  271. BC3, // DXT5
  272. BC4, // LATC1/ATI1
  273. BC5, // LATC2/ATI2
  274. Unknown,
  275. L8,
  276. BGRX8,
  277. BGRA8,
  278. RGBA16,
  279. RGBA16F,
  280. R5G6B5,
  281. RGBA4,
  282. RGB5A1,
  283. RGB10A2,
  284. Count
  285. };
  286. };
  287. struct UniformType
  288. {
  289. enum Enum
  290. {
  291. Uniform1i,
  292. Uniform1f,
  293. End,
  294. Uniform1iv,
  295. Uniform1fv,
  296. Uniform2fv,
  297. Uniform3fv,
  298. Uniform4fv,
  299. Uniform3x3fv,
  300. Uniform4x4fv,
  301. Count
  302. };
  303. };
  304. static const uint16_t invalidHandle = UINT16_MAX;
  305. BGFX_HANDLE(DynamicIndexBufferHandle);
  306. BGFX_HANDLE(DynamicVertexBufferHandle);
  307. BGFX_HANDLE(FragmentShaderHandle);
  308. BGFX_HANDLE(IndexBufferHandle);
  309. BGFX_HANDLE(ProgramHandle);
  310. BGFX_HANDLE(RenderTargetHandle);
  311. BGFX_HANDLE(TextureHandle);
  312. BGFX_HANDLE(UniformHandle);
  313. BGFX_HANDLE(VertexBufferHandle);
  314. BGFX_HANDLE(VertexDeclHandle);
  315. BGFX_HANDLE(VertexShaderHandle);
  316. typedef void* (*ReallocFn)(void* _ptr, size_t _size);
  317. typedef void (*FreeFn)(void* _ptr);
  318. /// Callback interface to implement application specific behavior.
  319. /// Cached items are currently used only for OpenGL binary shaders.
  320. ///
  321. /// NOTE:
  322. /// 'fatal' callback can be called from any thread. Other callbacks
  323. /// are called from the render thread.
  324. ///
  325. struct CallbackI
  326. {
  327. virtual ~CallbackI() = 0;
  328. /// If fatal code code is not Fatal::DebugCheck this callback is
  329. /// called on unrecoverable error. It's not safe to continue, inform
  330. /// user and terminate application from this call.
  331. virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
  332. /// Return size of for cached item. Return 0 if no cached item was
  333. /// found.
  334. virtual uint32_t cacheReadSize(uint64_t _id) = 0;
  335. /// Read cached item.
  336. virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
  337. /// Write cached item.
  338. virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
  339. /// Screenshot captured. Screenshot format is always 4-byte BGRA.
  340. virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) = 0;
  341. /// Called when capture begins.
  342. virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx::TextureFormat::Enum _format, bool _yflip) = 0;
  343. /// Called when capture ends.
  344. virtual void captureEnd() = 0;
  345. /// Captured frame.
  346. virtual void captureFrame(const void* _data, uint32_t _size) = 0;
  347. };
  348. inline CallbackI::~CallbackI()
  349. {
  350. }
  351. struct Memory
  352. {
  353. uint8_t* data;
  354. uint32_t size;
  355. };
  356. struct TransientIndexBuffer
  357. {
  358. uint8_t* data;
  359. uint32_t size;
  360. IndexBufferHandle handle;
  361. uint32_t startIndex;
  362. };
  363. struct TransientVertexBuffer
  364. {
  365. uint8_t* data;
  366. uint32_t size;
  367. uint32_t startVertex;
  368. uint16_t stride;
  369. VertexBufferHandle handle;
  370. VertexDeclHandle decl;
  371. };
  372. struct InstanceDataBuffer
  373. {
  374. uint8_t* data;
  375. uint32_t size;
  376. uint32_t offset;
  377. uint16_t stride;
  378. uint16_t num;
  379. VertexBufferHandle handle;
  380. };
  381. struct TextureInfo
  382. {
  383. TextureFormat::Enum format;
  384. uint32_t storageSize;
  385. uint16_t width;
  386. uint16_t height;
  387. uint16_t depth;
  388. uint8_t numMips;
  389. uint8_t bitsPerPixel;
  390. };
  391. /// Vertex declaration.
  392. struct VertexDecl
  393. {
  394. /// Start VertexDecl.
  395. void begin(RendererType::Enum _renderer = RendererType::Null);
  396. /// End VertexDecl.
  397. void end();
  398. /// Add attribute to VertexDecl.
  399. ///
  400. /// @param _attrib Attribute semantics.
  401. /// @param _num Number of elements 1, 2, 3 or 4.
  402. /// @param _type Element type.
  403. /// @param _normalized When using fixed point AttribType (f.e. Uint8)
  404. /// value will be normalized for vertex shader usage. When normalized
  405. /// is set to true, AttribType::Uint8 value in range 0-255 will be
  406. /// in range 0.0-1.0 in vertex shader.
  407. /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
  408. /// vertexConvert for AttribType::Uint8 and AttribType::Int16.
  409. /// Unpacking code must be implemented inside vertex shader.
  410. ///
  411. /// NOTE:
  412. /// Must be called between begin/end.
  413. ///
  414. void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
  415. /// Decode attribute.
  416. void decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const;
  417. /// Returns true if VertexDecl contains attribute.
  418. bool has(Attrib::Enum _attrib) const { return 0xff != m_attributes[_attrib]; }
  419. /// Returns relative attribute offset from the vertex.
  420. uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; }
  421. /// Returns vertex stride.
  422. uint16_t getStride() const { return m_stride; }
  423. /// Returns size of vertex buffer for number of vertices.
  424. uint32_t getSize(uint32_t _num) const { return _num*m_stride; }
  425. uint32_t m_hash;
  426. uint16_t m_stride;
  427. uint16_t m_offset[Attrib::Count];
  428. uint8_t m_attributes[Attrib::Count];
  429. };
  430. /// Pack vec4 into vertex stream format.
  431. void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index = 0);
  432. /// Unpack vec4 from vertex stream format.
  433. void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index = 0);
  434. /// Converts vertex stream data from one vertex stream format to another.
  435. ///
  436. /// @param _destDecl Destination vertex stream declaration.
  437. /// @param _destData Destination vertex stream.
  438. /// @param _srcDecl Source vertex stream declaration.
  439. /// @param _srcData Source vertex stream data.
  440. /// @param _num Number of vertices to convert from source to destination.
  441. ///
  442. void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num = 1);
  443. /// Returns renderer backend API type.
  444. RendererType::Enum getRendererType();
  445. /// Initialize bgfx library.
  446. ///
  447. /// @param _callback Provide application specific callback interface.
  448. /// See: CallbackI
  449. ///
  450. /// @param _realloc Custom realloc function.
  451. /// @param _free Custom free function.
  452. ///
  453. /// NOTE: In order to properly set custom allocator realloc and free,
  454. /// both functions must be provided. When custom allocator is not
  455. /// specified, library uses default CRT allocator. The library assumes
  456. /// custom allocator is thread safe.
  457. ///
  458. void init(CallbackI* _callback = NULL, ReallocFn _realloc = NULL, FreeFn _free = NULL);
  459. /// Shutdown bgfx library.
  460. void shutdown();
  461. /// Reset graphic settings.
  462. void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE);
  463. /// Advance to next frame. When using multithreaded renderer, this call
  464. /// just swaps internal buffers, kicks render thread, and returns. In
  465. /// singlethreaded renderer this call does frame rendering.
  466. void frame();
  467. /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
  468. const Memory* alloc(uint32_t _size);
  469. /// Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
  470. /// doesn't allocate memory for data. It just copies pointer to data.
  471. /// You must make sure data is available for at least 2 bgfx::frame calls.
  472. const Memory* makeRef(const void* _data, uint32_t _size);
  473. /// Set debug flags.
  474. ///
  475. /// @param _debug Available flags:
  476. ///
  477. /// BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
  478. /// all rendering calls will be skipped. It's useful when profiling
  479. /// to quickly assess bottleneck between CPU and GPU.
  480. ///
  481. /// BGFX_DEBUG_STATS - Display internal statistics.
  482. ///
  483. /// BGFX_DEBUG_TEXT - Display debug text.
  484. ///
  485. /// BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
  486. /// primitives will be rendered as lines.
  487. ///
  488. void setDebug(uint32_t _debug);
  489. /// Clear internal debug text buffer.
  490. void dbgTextClear(uint8_t _attr = 0, bool _small = false);
  491. /// Print into internal debug text buffer.
  492. void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
  493. /// Create static index buffer.
  494. IndexBufferHandle createIndexBuffer(const Memory* _mem);
  495. /// Destroy static index buffer.
  496. void destroyIndexBuffer(IndexBufferHandle _handle);
  497. /// Create static vertex buffer.
  498. VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  499. /// Destroy static vertex buffer.
  500. void destroyVertexBuffer(VertexBufferHandle _handle);
  501. /// Create empty dynamic index buffer.
  502. DynamicIndexBufferHandle createDynamicIndexBuffer(uint16_t _num);
  503. /// Create dynamic index buffer and initialized it.
  504. DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem);
  505. /// Update dynamic index buffer.
  506. void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
  507. /// Destroy dynamic index buffer.
  508. void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle);
  509. /// Create empty dynamic vertex buffer.
  510. DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl);
  511. /// Create dynamic vertex buffer and initialize it.
  512. DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  513. /// Update dynamic vertex buffer.
  514. void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
  515. /// Destroy dynamic vertex buffer.
  516. void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle);
  517. /// Returns true if internal transient index buffer has enough space.
  518. ///
  519. /// @param _num Number of indices.
  520. ///
  521. bool checkAvailTransientIndexBuffer(uint32_t _num);
  522. /// Returns true if internal transient vertex buffer has enough space.
  523. ///
  524. /// @param _num Number of vertices.
  525. /// @param _decl Vertex declaration.
  526. ///
  527. bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl);
  528. /// Returns true if internal instance data buffer has enough space.
  529. ///
  530. /// @param _num Number of instances.
  531. /// @param _stride Stride per instance.
  532. ///
  533. bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  534. /// Returns true if both internal transient index and vertex buffer have
  535. /// enough space.
  536. ///
  537. /// @param _numVertices Number of vertices.
  538. /// @param _decl Vertex declaration.
  539. /// @param _numIndices Number of indices.
  540. ///
  541. bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices);
  542. /// Allocate transient index buffer.
  543. ///
  544. /// @param[out] _tib TransientIndexBuffer structure is filled and is valid
  545. /// for the duration of frame, and it can be reused for multiple draw
  546. /// calls.
  547. /// @param _num Number of indices to allocate.
  548. ///
  549. void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
  550. /// Allocate transient vertex buffer.
  551. ///
  552. /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid
  553. /// for the duration of frame, and it can be reused for multiple draw
  554. /// calls.
  555. /// @param _num Number of vertices to allocate.
  556. /// @param _decl Vertex declaration.
  557. ///
  558. void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
  559. /// Allocate instance data buffer.
  560. const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  561. /// Create vertex shader from memory buffer.
  562. VertexShaderHandle createVertexShader(const Memory* _mem);
  563. /// Destroy vertex shader. Once program is created with vertex shader
  564. /// it is safe to destroy vertex shader.
  565. void destroyVertexShader(VertexShaderHandle _handle);
  566. /// Create fragment shader from memory buffer.
  567. FragmentShaderHandle createFragmentShader(const Memory* _mem);
  568. /// Destroy fragment shader. Once program is created with fragment shader
  569. /// it is safe to destroy fragment shader.
  570. void destroyFragmentShader(FragmentShaderHandle _handle);
  571. /// Create program with vertex and fragment shaders.
  572. ///
  573. /// @param _vsh Vertex shader.
  574. /// @param _fsh Fragment shader.
  575. /// @returns Program handle if vertex shader output and fragment shader
  576. /// input are matching, otherwise returns invalid program handle.
  577. ///
  578. ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh);
  579. /// Destroy program.
  580. void destroyProgram(ProgramHandle _handle);
  581. /// Calculate amount of memory required for texture.
  582. void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
  583. /// Create texture from memory buffer.
  584. ///
  585. /// @param _mem DDS texture data.
  586. /// @param _flags Default texture sampling mode is linear, and wrap mode
  587. /// is repeat.
  588. ///
  589. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  590. /// mode.
  591. ///
  592. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  593. /// sampling.
  594. ///
  595. /// BGFX_TEXTURE_SRGB - Sample as sRGB texture.
  596. ///
  597. /// @param _info Returns parsed DDS texture information.
  598. /// @returns Texture handle.
  599. ///
  600. TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, TextureInfo* _info = NULL);
  601. /// Create 2D texture.
  602. TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  603. /// Create 3D texture.
  604. TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  605. /// Create Cube texture.
  606. TextureHandle createTextureCube(uint16_t _sides, uint16_t _width, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  607. /// Update 2D texture.
  608. void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem);
  609. /// Update 3D texture.
  610. void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem);
  611. /// Update Cube texture.
  612. ///
  613. /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
  614. /// -Y, 4 is +Z, and 5 is -Z.
  615. ///
  616. void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem);
  617. /// Destroy texture.
  618. void destroyTexture(TextureHandle _handle);
  619. /// Create render target.
  620. RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags = BGFX_RENDER_TARGET_COLOR_RGBA8, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
  621. /// Destroy render target.
  622. void destroyRenderTarget(RenderTargetHandle _handle);
  623. /// Create shader uniform parameter.
  624. UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);
  625. /// Destroy shader uniform parameter.
  626. void destroyUniform(UniformHandle _handle);
  627. /// Set view name.
  628. ///
  629. /// @param _id View id.
  630. /// @param _name View name.
  631. ///
  632. /// NOTE:
  633. /// This is debug only feature.
  634. ///
  635. void setViewName(uint8_t _id, const char* _name);
  636. /// Set view rectangle. Draw primitive outside view will be clipped.
  637. void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  638. /// Set view rectangle for multiple views.
  639. void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  640. /// Set view scissor. Draw primitive outside view will be clipped. When
  641. /// _x, _y, _width and _height are set to 0, scissor will be disabled.
  642. void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  643. /// Set view scissor for multiple views. When _x, _y, _width and _height
  644. /// are set to 0, scissor will be disabled.
  645. void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  646. /// Set view clear flags.
  647. ///
  648. /// @param _id View id.
  649. /// @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
  650. /// operation. See: BGFX_CLEAR_*.
  651. /// @param _rgba Color clear value.
  652. /// @param _depth Depth clear value.
  653. /// @param _stencil Stencil clear value.
  654. ///
  655. void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  656. /// Set view clear flags for multiple views.
  657. void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  658. /// Set view into sequential mode. Draw calls will be sorted in the same
  659. /// order in which submit calls were called.
  660. void setViewSeq(uint8_t _id, bool _enabled);
  661. /// Set mulitple views into sequential mode.
  662. void setViewSeqMask(uint32_t _viewMask, bool _enabled);
  663. /// Set view render target.
  664. ///
  665. /// @param _id View id.
  666. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  667. /// render target handle will draw primitives from this view into
  668. /// default backbuffer.
  669. ///
  670. void setViewRenderTarget(uint8_t _id, RenderTargetHandle _handle);
  671. /// Set view render target for multiple views.
  672. ///
  673. /// @param _viewMask View mask.
  674. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  675. /// render target handle will draw primitives from this view into
  676. /// default backbuffer.
  677. ///
  678. void setViewRenderTargetMask(uint32_t _viewMask, RenderTargetHandle _handle);
  679. /// Set view view and projection matrices, all draw primitives in this
  680. /// view will use these matrices.
  681. void setViewTransform(uint8_t _id, const void* _view, const void* _proj, uint8_t _other = 0xff);
  682. /// Set view view and projection matrices for multiple views.
  683. void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj, uint8_t _other = 0xff);
  684. /// Sets debug marker.
  685. void setMarker(const char* _marker);
  686. /// Set render states for draw primitive.
  687. ///
  688. /// @param _state State flags. Default state for primitive type is
  689. /// triangles. See: BGFX_STATE_DEFAULT.
  690. ///
  691. /// BGFX_STATE_ALPHA_WRITE - Enable alpha write.
  692. /// BGFX_STATE_DEPTH_WRITE - Enable depth write.
  693. /// BGFX_STATE_DEPTH_TEST_* - Depth test function.
  694. /// BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
  695. /// BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
  696. /// BGFX_STATE_CULL_* - Backface culling mode.
  697. /// BGFX_STATE_RGB_WRITE - Enable RGB write.
  698. /// BGFX_STATE_SRGBWRITE - Enable sRGB write.
  699. /// BGFX_STATE_MSAA - Enable MSAA.
  700. /// BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
  701. ///
  702. /// @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
  703. /// BGFX_STATE_BLEND_INV_FACTOR blend modes.
  704. ///
  705. /// NOTE:
  706. /// 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
  707. /// BGFX_STATE_BLEND_FUNC macros to setup more complex states.
  708. /// 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
  709. /// equation is specified.
  710. ///
  711. void setState(uint64_t _state, uint32_t _rgba = UINT32_MAX);
  712. /// Set stencil test state.
  713. ///
  714. /// @param _fstencil Front stencil state.
  715. /// @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
  716. /// _fstencil is applied to both front and back facing primitives.
  717. ///
  718. void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
  719. /// Set scissor for draw primitive.
  720. uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  721. /// Set scissor from cache for draw primitive.
  722. ///
  723. /// @param _cache Index in scissor cache.
  724. ///
  725. void setScissor(uint16_t _cache);
  726. /// Set model matrix for draw primitive. If it is not called model will
  727. /// be rendered with identity model matrix.
  728. ///
  729. /// @param _mtx Pointer to first matrix in array.
  730. /// @param _num Number of matrices in array.
  731. /// @returns index into matrix cache in case the same model matrix has
  732. /// to be used for other draw primitive call.
  733. ///
  734. uint32_t setTransform(const void* _mtx, uint16_t _num = 1);
  735. /// Set model matrix from matrix cache for draw primitive.
  736. ///
  737. /// @param _cache Index in matrix cache.
  738. /// @param _num Number of matrices from cache.
  739. ///
  740. void setTransform(uint32_t _cache, uint16_t _num = 1);
  741. /// Set shader uniform parameter for draw primitive.
  742. void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1);
  743. /// Set index buffer for draw primitive.
  744. void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  745. /// Set index buffer for draw primitive.
  746. void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  747. /// Set index buffer for draw primitive.
  748. void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _numIndices = UINT32_MAX);
  749. /// Set vertex buffer for draw primitive.
  750. void setVertexBuffer(VertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  751. /// Set vertex buffer for draw primitive.
  752. void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  753. /// Set vertex buffer for draw primitive.
  754. void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _numVertices = UINT32_MAX);
  755. /// Set instance data buffer for draw primitive.
  756. void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint16_t _num = UINT16_MAX);
  757. /// Set program for draw primitive.
  758. void setProgram(ProgramHandle _handle);
  759. /// Set texture stage for draw primitive.
  760. void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle);
  761. /// Set texture stage for draw primitive.
  762. void setTexture(uint8_t _stage, UniformHandle _sampler, RenderTargetHandle _handle, bool _depth = false);
  763. /// Submit primitive for rendering into single view.
  764. ///
  765. /// @param _id View id.
  766. /// @param _depth Depth for sorting.
  767. ///
  768. void submit(uint8_t _id, int32_t _depth = 0);
  769. /// Submit primitive for rendering into multiple views.
  770. ///
  771. /// @param _viewMask Mask to which views to submit draw primitive calls.
  772. /// @param _depth Depth for sorting.
  773. ///
  774. void submitMask(uint32_t _viewMask, int32_t _depth = 0);
  775. /// Request screen shot.
  776. void saveScreenShot(const char* _filePath);
  777. } // namespace bgfx
  778. #endif // __BGFX_H__