bgfx.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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) \
  201. struct _name { uint16_t idx; }; \
  202. inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; }
  203. #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
  204. namespace bx { struct ReallocatorI; }
  205. /// BGFX
  206. namespace bgfx
  207. {
  208. struct Fatal
  209. {
  210. enum Enum
  211. {
  212. DebugCheck,
  213. MinimumRequiredSpecs,
  214. InvalidShader,
  215. UnableToInitialize,
  216. UnableToCreateRenderTarget,
  217. UnableToCreateTexture,
  218. };
  219. };
  220. struct RendererType
  221. {
  222. enum Enum
  223. {
  224. Null,
  225. Direct3D9,
  226. Direct3D11,
  227. OpenGLES2,
  228. OpenGLES3,
  229. OpenGL,
  230. Count
  231. };
  232. };
  233. struct Attrib
  234. {
  235. enum Enum // corresponds to vertex shader attribute:
  236. {
  237. Position, // a_position
  238. Normal, // a_normal
  239. Tangent, // a_tangent
  240. Color0, // a_color0
  241. Color1, // a_color1
  242. Indices, // a_indices
  243. Weight, // a_weight
  244. TexCoord0, // a_texcoord0
  245. TexCoord1, // a_texcoord1
  246. TexCoord2, // a_texcoord2
  247. TexCoord3, // a_texcoord3
  248. TexCoord4, // a_texcoord4
  249. TexCoord5, // a_texcoord5
  250. TexCoord6, // a_texcoord6
  251. TexCoord7, // a_texcoord7
  252. Count
  253. };
  254. };
  255. struct AttribType
  256. {
  257. enum Enum
  258. {
  259. Uint8,
  260. Int16,
  261. Half,
  262. Float,
  263. Count
  264. };
  265. };
  266. struct TextureFormat
  267. {
  268. enum Enum
  269. {
  270. BC1, // DXT1
  271. BC2, // DXT3
  272. BC3, // DXT5
  273. BC4, // LATC1/ATI1
  274. BC5, // LATC2/ATI2
  275. ETC1, // ETC1 RGB8
  276. ETC2, // ETC2 RGB8
  277. ETC2A, // ETC2 RGBA8
  278. ETC2A1, // ETC2 RGB8A1
  279. PTC12, // PVRTC1 RGB 2BPP
  280. PTC14, // PVRTC1 RGB 4BPP
  281. PTC14A, // PVRTC1 RGBA 4BPP
  282. PTC12A, // PVRTC1 RGBA 2BPP
  283. PTC22, // PVRTC2 RGBA 2BPP
  284. PTC24, // PVRTC2 RGBA 4BPP
  285. Unknown,
  286. L8,
  287. BGRA8,
  288. RGBA16,
  289. RGBA16F,
  290. R5G6B5,
  291. RGBA4,
  292. RGB5A1,
  293. RGB10A2,
  294. Count
  295. };
  296. };
  297. struct UniformType
  298. {
  299. enum Enum
  300. {
  301. Uniform1i,
  302. Uniform1f,
  303. End,
  304. Uniform1iv,
  305. Uniform1fv,
  306. Uniform2fv,
  307. Uniform3fv,
  308. Uniform4fv,
  309. Uniform3x3fv,
  310. Uniform4x4fv,
  311. Count
  312. };
  313. };
  314. static const uint16_t invalidHandle = UINT16_MAX;
  315. BGFX_HANDLE(DynamicIndexBufferHandle);
  316. BGFX_HANDLE(DynamicVertexBufferHandle);
  317. BGFX_HANDLE(FragmentShaderHandle);
  318. BGFX_HANDLE(IndexBufferHandle);
  319. BGFX_HANDLE(ProgramHandle);
  320. BGFX_HANDLE(RenderTargetHandle);
  321. BGFX_HANDLE(TextureHandle);
  322. BGFX_HANDLE(UniformHandle);
  323. BGFX_HANDLE(VertexBufferHandle);
  324. BGFX_HANDLE(VertexDeclHandle);
  325. BGFX_HANDLE(VertexShaderHandle);
  326. /// Callback interface to implement application specific behavior.
  327. /// Cached items are currently used only for OpenGL binary shaders.
  328. ///
  329. /// NOTE:
  330. /// 'fatal' callback can be called from any thread. Other callbacks
  331. /// are called from the render thread.
  332. ///
  333. struct CallbackI
  334. {
  335. virtual ~CallbackI() = 0;
  336. /// If fatal code code is not Fatal::DebugCheck this callback is
  337. /// called on unrecoverable error. It's not safe to continue, inform
  338. /// user and terminate application from this call.
  339. virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
  340. /// Return size of for cached item. Return 0 if no cached item was
  341. /// found.
  342. virtual uint32_t cacheReadSize(uint64_t _id) = 0;
  343. /// Read cached item.
  344. virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
  345. /// Write cached item.
  346. virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
  347. /// Screenshot captured. Screenshot format is always 4-byte BGRA.
  348. virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) = 0;
  349. /// Called when capture begins.
  350. virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx::TextureFormat::Enum _format, bool _yflip) = 0;
  351. /// Called when capture ends.
  352. virtual void captureEnd() = 0;
  353. /// Captured frame.
  354. virtual void captureFrame(const void* _data, uint32_t _size) = 0;
  355. };
  356. inline CallbackI::~CallbackI()
  357. {
  358. }
  359. struct Memory
  360. {
  361. uint8_t* data;
  362. uint32_t size;
  363. };
  364. struct TransientIndexBuffer
  365. {
  366. uint8_t* data;
  367. uint32_t size;
  368. IndexBufferHandle handle;
  369. uint32_t startIndex;
  370. };
  371. struct TransientVertexBuffer
  372. {
  373. uint8_t* data;
  374. uint32_t size;
  375. uint32_t startVertex;
  376. uint16_t stride;
  377. VertexBufferHandle handle;
  378. VertexDeclHandle decl;
  379. };
  380. struct InstanceDataBuffer
  381. {
  382. uint8_t* data;
  383. uint32_t size;
  384. uint32_t offset;
  385. uint16_t stride;
  386. uint16_t num;
  387. VertexBufferHandle handle;
  388. };
  389. struct TextureInfo
  390. {
  391. TextureFormat::Enum format;
  392. uint32_t storageSize;
  393. uint16_t width;
  394. uint16_t height;
  395. uint16_t depth;
  396. uint8_t numMips;
  397. uint8_t bitsPerPixel;
  398. };
  399. /// Vertex declaration.
  400. struct VertexDecl
  401. {
  402. /// Start VertexDecl.
  403. void begin(RendererType::Enum _renderer = RendererType::Null);
  404. /// End VertexDecl.
  405. void end();
  406. /// Add attribute to VertexDecl.
  407. ///
  408. /// @param _attrib Attribute semantics.
  409. /// @param _num Number of elements 1, 2, 3 or 4.
  410. /// @param _type Element type.
  411. /// @param _normalized When using fixed point AttribType (f.e. Uint8)
  412. /// value will be normalized for vertex shader usage. When normalized
  413. /// is set to true, AttribType::Uint8 value in range 0-255 will be
  414. /// in range 0.0-1.0 in vertex shader.
  415. /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
  416. /// vertexConvert for AttribType::Uint8 and AttribType::Int16.
  417. /// Unpacking code must be implemented inside vertex shader.
  418. ///
  419. /// NOTE:
  420. /// Must be called between begin/end.
  421. ///
  422. void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
  423. /// Decode attribute.
  424. void decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const;
  425. /// Returns true if VertexDecl contains attribute.
  426. bool has(Attrib::Enum _attrib) const { return 0xff != m_attributes[_attrib]; }
  427. /// Returns relative attribute offset from the vertex.
  428. uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; }
  429. /// Returns vertex stride.
  430. uint16_t getStride() const { return m_stride; }
  431. /// Returns size of vertex buffer for number of vertices.
  432. uint32_t getSize(uint32_t _num) const { return _num*m_stride; }
  433. uint32_t m_hash;
  434. uint16_t m_stride;
  435. uint16_t m_offset[Attrib::Count];
  436. uint8_t m_attributes[Attrib::Count];
  437. };
  438. /// Pack vec4 into vertex stream format.
  439. void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index = 0);
  440. /// Unpack vec4 from vertex stream format.
  441. void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index = 0);
  442. /// Converts vertex stream data from one vertex stream format to another.
  443. ///
  444. /// @param _destDecl Destination vertex stream declaration.
  445. /// @param _destData Destination vertex stream.
  446. /// @param _srcDecl Source vertex stream declaration.
  447. /// @param _srcData Source vertex stream data.
  448. /// @param _num Number of vertices to convert from source to destination.
  449. ///
  450. void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num = 1);
  451. /// Swizzle RGBA8 image to BGRA8.
  452. ///
  453. /// @param _width Width of input image (pixels).
  454. /// @param _height Height of input image (pixels).
  455. /// @param _src Source image.
  456. /// @param _dst Destination image. Must be the same size as input image.
  457. /// _dst might be pointer to the same memory as _src.
  458. ///
  459. void imageSwizzleBgra8(uint32_t _width, uint32_t _height, const void* _src, void* _dst);
  460. /// Downsample RGBA8 image with 2x2 pixel average filter.
  461. ///
  462. /// @param _width Width of input image (pixels).
  463. /// @param _height Height of input image (pixels).
  464. /// @param _pitch Pitch of input image (bytes).
  465. /// @param _src Source image.
  466. /// @param _dst Destination image. Must be at least quarter size of
  467. /// input image. _dst might be pointer to the same memory as _src.
  468. ///
  469. void imageRgba8Downsample2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  470. /// Returns renderer backend API type.
  471. RendererType::Enum getRendererType();
  472. /// Initialize bgfx library.
  473. ///
  474. /// @param _callback Provide application specific callback interface.
  475. /// See: CallbackI
  476. ///
  477. /// @param _reallocator Custom allocator. When custom allocator is not
  478. /// specified, library uses default CRT allocator. The library assumes
  479. /// custom allocator is thread safe.
  480. ///
  481. void init(CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
  482. /// Shutdown bgfx library.
  483. void shutdown();
  484. /// Reset graphic settings.
  485. void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE);
  486. /// Advance to next frame. When using multithreaded renderer, this call
  487. /// just swaps internal buffers, kicks render thread, and returns. In
  488. /// singlethreaded renderer this call does frame rendering.
  489. void frame();
  490. /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
  491. const Memory* alloc(uint32_t _size);
  492. /// Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
  493. /// doesn't allocate memory for data. It just copies pointer to data.
  494. /// You must make sure data is available for at least 2 bgfx::frame calls.
  495. const Memory* makeRef(const void* _data, uint32_t _size);
  496. /// Set debug flags.
  497. ///
  498. /// @param _debug Available flags:
  499. ///
  500. /// BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
  501. /// all rendering calls will be skipped. It's useful when profiling
  502. /// to quickly assess bottleneck between CPU and GPU.
  503. ///
  504. /// BGFX_DEBUG_STATS - Display internal statistics.
  505. ///
  506. /// BGFX_DEBUG_TEXT - Display debug text.
  507. ///
  508. /// BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
  509. /// primitives will be rendered as lines.
  510. ///
  511. void setDebug(uint32_t _debug);
  512. /// Clear internal debug text buffer.
  513. void dbgTextClear(uint8_t _attr = 0, bool _small = false);
  514. /// Print into internal debug text buffer.
  515. void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
  516. /// Create static index buffer.
  517. IndexBufferHandle createIndexBuffer(const Memory* _mem);
  518. /// Destroy static index buffer.
  519. void destroyIndexBuffer(IndexBufferHandle _handle);
  520. /// Create static vertex buffer.
  521. VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  522. /// Destroy static vertex buffer.
  523. void destroyVertexBuffer(VertexBufferHandle _handle);
  524. /// Create empty dynamic index buffer.
  525. DynamicIndexBufferHandle createDynamicIndexBuffer(uint16_t _num);
  526. /// Create dynamic index buffer and initialized it.
  527. DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem);
  528. /// Update dynamic index buffer.
  529. void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
  530. /// Destroy dynamic index buffer.
  531. void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle);
  532. /// Create empty dynamic vertex buffer.
  533. DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl);
  534. /// Create dynamic vertex buffer and initialize it.
  535. DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  536. /// Update dynamic vertex buffer.
  537. void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
  538. /// Destroy dynamic vertex buffer.
  539. void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle);
  540. /// Returns true if internal transient index buffer has enough space.
  541. ///
  542. /// @param _num Number of indices.
  543. ///
  544. bool checkAvailTransientIndexBuffer(uint32_t _num);
  545. /// Returns true if internal transient vertex buffer has enough space.
  546. ///
  547. /// @param _num Number of vertices.
  548. /// @param _decl Vertex declaration.
  549. ///
  550. bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl);
  551. /// Returns true if internal instance data buffer has enough space.
  552. ///
  553. /// @param _num Number of instances.
  554. /// @param _stride Stride per instance.
  555. ///
  556. bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  557. /// Returns true if both internal transient index and vertex buffer have
  558. /// enough space.
  559. ///
  560. /// @param _numVertices Number of vertices.
  561. /// @param _decl Vertex declaration.
  562. /// @param _numIndices Number of indices.
  563. ///
  564. bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices);
  565. /// Allocate transient index buffer.
  566. ///
  567. /// @param[out] _tib TransientIndexBuffer structure is filled and is valid
  568. /// for the duration of frame, and it can be reused for multiple draw
  569. /// calls.
  570. /// @param _num Number of indices to allocate.
  571. ///
  572. /// NOTE:
  573. /// You must call setIndexBuffer after alloc in order to avoid memory
  574. /// leak.
  575. ///
  576. void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
  577. /// Allocate transient vertex buffer.
  578. ///
  579. /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid
  580. /// for the duration of frame, and it can be reused for multiple draw
  581. /// calls.
  582. /// @param _num Number of vertices to allocate.
  583. /// @param _decl Vertex declaration.
  584. ///
  585. /// NOTE:
  586. /// You must call setVertexBuffer after alloc in order to avoid memory
  587. /// leak.
  588. ///
  589. void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
  590. /// Allocate instance data buffer.
  591. ///
  592. /// NOTE:
  593. /// You must call setInstanceDataBuffer after alloc in order to avoid
  594. /// memory leak.
  595. ///
  596. const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  597. /// Create vertex shader from memory buffer.
  598. VertexShaderHandle createVertexShader(const Memory* _mem);
  599. /// Destroy vertex shader. Once program is created with vertex shader
  600. /// it is safe to destroy vertex shader.
  601. void destroyVertexShader(VertexShaderHandle _handle);
  602. /// Create fragment shader from memory buffer.
  603. FragmentShaderHandle createFragmentShader(const Memory* _mem);
  604. /// Destroy fragment shader. Once program is created with fragment shader
  605. /// it is safe to destroy fragment shader.
  606. void destroyFragmentShader(FragmentShaderHandle _handle);
  607. /// Create program with vertex and fragment shaders.
  608. ///
  609. /// @param _vsh Vertex shader.
  610. /// @param _fsh Fragment shader.
  611. /// @returns Program handle if vertex shader output and fragment shader
  612. /// input are matching, otherwise returns invalid program handle.
  613. ///
  614. ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh);
  615. /// Destroy program.
  616. void destroyProgram(ProgramHandle _handle);
  617. /// Calculate amount of memory required for texture.
  618. void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
  619. /// Create texture from memory buffer.
  620. ///
  621. /// @param _mem DDS texture data.
  622. /// @param _flags Default texture sampling mode is linear, and wrap mode
  623. /// is repeat.
  624. ///
  625. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  626. /// mode.
  627. ///
  628. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  629. /// sampling.
  630. ///
  631. /// @param _info Returns parsed DDS texture information.
  632. /// @returns Texture handle.
  633. ///
  634. TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, TextureInfo* _info = NULL);
  635. /// Create 2D texture.
  636. ///
  637. /// @param _width
  638. /// @param _height
  639. /// @param _numMips
  640. /// @param _format
  641. /// @param _flags
  642. /// @param _mem
  643. ///
  644. TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  645. /// Create 3D texture.
  646. ///
  647. /// @param _width
  648. /// @param _height
  649. /// @param _depth
  650. /// @param _numMips
  651. /// @param _format
  652. /// @param _flags
  653. /// @param _mem
  654. ///
  655. 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);
  656. /// Create Cube texture.
  657. ///
  658. /// @param _sides
  659. /// @param _width
  660. /// @param _numMips
  661. /// @param _format
  662. /// @param _flags
  663. /// @param _mem
  664. ///
  665. TextureHandle createTextureCube(uint16_t _sides, uint16_t _width, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  666. /// Update 2D texture.
  667. void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem);
  668. /// Update 3D texture.
  669. 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);
  670. /// Update Cube texture.
  671. ///
  672. /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
  673. /// -Y, 4 is +Z, and 5 is -Z.
  674. ///
  675. /// +----------+
  676. /// |-z 2|
  677. /// | ^ +y |
  678. /// | | |
  679. /// | +---->+x |
  680. /// +----------+----------+----------+----------+
  681. /// |+y 1|+y 4|+y 0|+y 5|
  682. /// | ^ -x | ^ +z | ^ +x | ^ -z |
  683. /// | | | | | | | | |
  684. /// | +---->+z | +---->+x | +---->-z | +---->-x |
  685. /// +----------+----------+----------+----------+
  686. /// |+z 3|
  687. /// | ^ -y |
  688. /// | | |
  689. /// | +---->+x |
  690. /// +----------+
  691. ///
  692. 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);
  693. /// Destroy texture.
  694. void destroyTexture(TextureHandle _handle);
  695. /// Create render target.
  696. 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);
  697. /// Destroy render target.
  698. void destroyRenderTarget(RenderTargetHandle _handle);
  699. /// Create shader uniform parameter.
  700. ///
  701. /// @param _name Uniform name in shader.
  702. /// @param _type Type of uniform (See: UniformType).
  703. /// @param _num Number of elements in array.
  704. ///
  705. /// Predefined uniforms:
  706. ///
  707. /// u_viewRect vec4(x, y, width, height) - view rectangle for current
  708. /// view.
  709. ///
  710. /// u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
  711. /// width and height
  712. ///
  713. /// u_view mat4 - view matrix
  714. ///
  715. /// u_viewProj mat4 - concatenated view projection matrix
  716. ///
  717. /// u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
  718. ///
  719. /// u_modelView mat4 - concatenated model view matrix, only first
  720. /// model matrix from array is used.
  721. ///
  722. /// u_modelViewProj mat4 - concatenated model view projection matrix.
  723. ///
  724. /// u_alphaRef float - alpha reference value for alpha test.
  725. ///
  726. UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);
  727. /// Destroy shader uniform parameter.
  728. void destroyUniform(UniformHandle _handle);
  729. /// Set view name.
  730. ///
  731. /// @param _id View id.
  732. /// @param _name View name.
  733. ///
  734. /// NOTE:
  735. /// This is debug only feature.
  736. ///
  737. void setViewName(uint8_t _id, const char* _name);
  738. /// Set view rectangle. Draw primitive outside view will be clipped.
  739. void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  740. /// Set view rectangle for multiple views.
  741. void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  742. /// Set view scissor. Draw primitive outside view will be clipped. When
  743. /// _x, _y, _width and _height are set to 0, scissor will be disabled.
  744. void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  745. /// Set view scissor for multiple views. When _x, _y, _width and _height
  746. /// are set to 0, scissor will be disabled.
  747. void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  748. /// Set view clear flags.
  749. ///
  750. /// @param _id View id.
  751. /// @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
  752. /// operation. See: BGFX_CLEAR_*.
  753. /// @param _rgba Color clear value.
  754. /// @param _depth Depth clear value.
  755. /// @param _stencil Stencil clear value.
  756. ///
  757. void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  758. /// Set view clear flags for multiple views.
  759. void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  760. /// Set view into sequential mode. Draw calls will be sorted in the same
  761. /// order in which submit calls were called.
  762. void setViewSeq(uint8_t _id, bool _enabled);
  763. /// Set mulitple views into sequential mode.
  764. void setViewSeqMask(uint32_t _viewMask, bool _enabled);
  765. /// Set view render target.
  766. ///
  767. /// @param _id View id.
  768. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  769. /// render target handle will draw primitives from this view into
  770. /// default backbuffer.
  771. ///
  772. void setViewRenderTarget(uint8_t _id, RenderTargetHandle _handle);
  773. /// Set view render target for multiple views.
  774. ///
  775. /// @param _viewMask View mask.
  776. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  777. /// render target handle will draw primitives from this view into
  778. /// default backbuffer.
  779. ///
  780. void setViewRenderTargetMask(uint32_t _viewMask, RenderTargetHandle _handle);
  781. /// Set view view and projection matrices, all draw primitives in this
  782. /// view will use these matrices.
  783. void setViewTransform(uint8_t _id, const void* _view, const void* _proj, uint8_t _other = 0xff);
  784. /// Set view view and projection matrices for multiple views.
  785. void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj, uint8_t _other = 0xff);
  786. /// Sets debug marker.
  787. void setMarker(const char* _marker);
  788. /// Set render states for draw primitive.
  789. ///
  790. /// @param _state State flags. Default state for primitive type is
  791. /// triangles. See: BGFX_STATE_DEFAULT.
  792. ///
  793. /// BGFX_STATE_ALPHA_WRITE - Enable alpha write.
  794. /// BGFX_STATE_DEPTH_WRITE - Enable depth write.
  795. /// BGFX_STATE_DEPTH_TEST_* - Depth test function.
  796. /// BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
  797. /// BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
  798. /// BGFX_STATE_CULL_* - Backface culling mode.
  799. /// BGFX_STATE_RGB_WRITE - Enable RGB write.
  800. /// BGFX_STATE_MSAA - Enable MSAA.
  801. /// BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
  802. ///
  803. /// @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
  804. /// BGFX_STATE_BLEND_INV_FACTOR blend modes.
  805. ///
  806. /// NOTE:
  807. /// 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
  808. /// BGFX_STATE_BLEND_FUNC macros to setup more complex states.
  809. /// 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
  810. /// equation is specified.
  811. ///
  812. void setState(uint64_t _state, uint32_t _rgba = UINT32_MAX);
  813. /// Set stencil test state.
  814. ///
  815. /// @param _fstencil Front stencil state.
  816. /// @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
  817. /// _fstencil is applied to both front and back facing primitives.
  818. ///
  819. void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
  820. /// Set scissor for draw primitive.
  821. uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  822. /// Set scissor from cache for draw primitive.
  823. ///
  824. /// @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
  825. /// scissor and primitive will use view scissor instead.
  826. ///
  827. void setScissor(uint16_t _cache = UINT16_MAX);
  828. /// Set model matrix for draw primitive. If it is not called model will
  829. /// be rendered with identity model matrix.
  830. ///
  831. /// @param _mtx Pointer to first matrix in array.
  832. /// @param _num Number of matrices in array.
  833. /// @returns index into matrix cache in case the same model matrix has
  834. /// to be used for other draw primitive call.
  835. ///
  836. uint32_t setTransform(const void* _mtx, uint16_t _num = 1);
  837. /// Set model matrix from matrix cache for draw primitive.
  838. ///
  839. /// @param _cache Index in matrix cache.
  840. /// @param _num Number of matrices from cache.
  841. ///
  842. void setTransform(uint32_t _cache, uint16_t _num = 1);
  843. /// Set shader uniform parameter for draw primitive.
  844. void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1);
  845. /// Set index buffer for draw primitive.
  846. void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  847. /// Set index buffer for draw primitive.
  848. void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  849. /// Set index buffer for draw primitive.
  850. void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _numIndices = UINT32_MAX);
  851. /// Set vertex buffer for draw primitive.
  852. void setVertexBuffer(VertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  853. /// Set vertex buffer for draw primitive.
  854. void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  855. /// Set vertex buffer for draw primitive.
  856. void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _numVertices = UINT32_MAX);
  857. /// Set instance data buffer for draw primitive.
  858. void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint16_t _num = UINT16_MAX);
  859. /// Set program for draw primitive.
  860. void setProgram(ProgramHandle _handle);
  861. /// Set texture stage for draw primitive.
  862. ///
  863. /// @param _stage Texture unit.
  864. /// @param _sampler Program sampler.
  865. /// @param _handle Texture handle.
  866. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  867. /// texture sampling settings from the texture.
  868. ///
  869. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  870. /// mode.
  871. ///
  872. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  873. /// sampling.
  874. ///
  875. /// @param _flags Texture sampler filtering flags. UINT32_MAX use the
  876. /// sampler filtering mode set by texture.
  877. ///
  878. void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX);
  879. /// Set texture stage for draw primitive.
  880. ///
  881. /// @param _stage Texture unit.
  882. /// @param _sampler Program sampler.
  883. /// @param _handle Render target handle.
  884. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  885. /// texture sampling settings from the texture.
  886. ///
  887. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  888. /// mode.
  889. ///
  890. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  891. /// sampling.
  892. ///
  893. void setTexture(uint8_t _stage, UniformHandle _sampler, RenderTargetHandle _handle, bool _depth = false, uint32_t _flags = UINT32_MAX);
  894. /// Submit primitive for rendering into single view.
  895. ///
  896. /// @param _id View id.
  897. /// @param _depth Depth for sorting.
  898. ///
  899. void submit(uint8_t _id, int32_t _depth = 0);
  900. /// Submit primitive for rendering into multiple views.
  901. ///
  902. /// @param _viewMask Mask to which views to submit draw primitive calls.
  903. /// @param _depth Depth for sorting.
  904. ///
  905. void submitMask(uint32_t _viewMask, int32_t _depth = 0);
  906. /// Discard all previously set state for draw call.
  907. void discard();
  908. /// Request screen shot.
  909. ///
  910. /// @param _filePath Will be passed to CallbackI::screenShot callback.
  911. ///
  912. /// NOTE:
  913. /// CallbackI::screenShot must be implemented.
  914. ///
  915. void saveScreenShot(const char* _filePath);
  916. } // namespace bgfx
  917. #endif // __BGFX_H__