bgfx.h 35 KB

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