bgfx.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  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_HEADER_GUARD
  6. #define BGFX_H_HEADER_GUARD
  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_SHIFT 24
  167. #define BGFX_TEXTURE_RESERVED_MASK UINT32_C(0xff000000)
  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_D16 UINT32_C(0x00000100)
  179. #define BGFX_RENDER_TARGET_DEPTH_D24 UINT32_C(0x00000200)
  180. #define BGFX_RENDER_TARGET_DEPTH_D24S8 UINT32_C(0x00000300)
  181. #define BGFX_RENDER_TARGET_DEPTH_D32 UINT32_C(0x00000400)
  182. #define BGFX_RENDER_TARGET_DEPTH_D16F UINT32_C(0x00000500)
  183. #define BGFX_RENDER_TARGET_DEPTH_D24F UINT32_C(0x00000600)
  184. #define BGFX_RENDER_TARGET_DEPTH_D32F UINT32_C(0x00000700)
  185. #define BGFX_RENDER_TARGET_DEPTH_D0S8 UINT32_C(0x00000800)
  186. #define BGFX_RENDER_TARGET_DEPTH_SHIFT 8
  187. #define BGFX_RENDER_TARGET_DEPTH_MASK UINT32_C(0x0000ff00)
  188. #define BGFX_RENDER_TARGET_MSAA_X2 UINT32_C(0x00010000)
  189. #define BGFX_RENDER_TARGET_MSAA_X4 UINT32_C(0x00020000)
  190. #define BGFX_RENDER_TARGET_MSAA_X8 UINT32_C(0x00030000)
  191. #define BGFX_RENDER_TARGET_MSAA_X16 UINT32_C(0x00040000)
  192. #define BGFX_RENDER_TARGET_MSAA_SHIFT 16
  193. #define BGFX_RENDER_TARGET_MSAA_MASK UINT32_C(0x00070000)
  194. ///
  195. #define BGFX_RESET_NONE UINT32_C(0x00000000)
  196. #define BGFX_RESET_FULLSCREEN UINT32_C(0x00000001)
  197. #define BGFX_RESET_FULLSCREEN_SHIFT 0
  198. #define BGFX_RESET_FULLSCREEN_MASK UINT32_C(0x00000001)
  199. #define BGFX_RESET_MSAA_X2 UINT32_C(0x00000010)
  200. #define BGFX_RESET_MSAA_X4 UINT32_C(0x00000020)
  201. #define BGFX_RESET_MSAA_X8 UINT32_C(0x00000030)
  202. #define BGFX_RESET_MSAA_X16 UINT32_C(0x00000040)
  203. #define BGFX_RESET_MSAA_SHIFT 4
  204. #define BGFX_RESET_MSAA_MASK UINT32_C(0x00000070)
  205. #define BGFX_RESET_VSYNC UINT32_C(0x00000080)
  206. #define BGFX_RESET_CAPTURE UINT32_C(0x00000100)
  207. ///
  208. #define BGFX_CAPS_TEXTURE_FORMAT_BC1 UINT64_C(0x0000000000000001)
  209. #define BGFX_CAPS_TEXTURE_FORMAT_BC2 UINT64_C(0x0000000000000002)
  210. #define BGFX_CAPS_TEXTURE_FORMAT_BC3 UINT64_C(0x0000000000000004)
  211. #define BGFX_CAPS_TEXTURE_FORMAT_BC4 UINT64_C(0x0000000000000008)
  212. #define BGFX_CAPS_TEXTURE_FORMAT_BC5 UINT64_C(0x0000000000000010)
  213. #define BGFX_CAPS_TEXTURE_FORMAT_ETC1 UINT64_C(0x0000000000000020)
  214. #define BGFX_CAPS_TEXTURE_FORMAT_ETC2 UINT64_C(0x0000000000000040)
  215. #define BGFX_CAPS_TEXTURE_FORMAT_ETC2A UINT64_C(0x0000000000000080)
  216. #define BGFX_CAPS_TEXTURE_FORMAT_ETC2A1 UINT64_C(0x0000000000000100)
  217. #define BGFX_CAPS_TEXTURE_FORMAT_PTC12 UINT64_C(0x0000000000000200)
  218. #define BGFX_CAPS_TEXTURE_FORMAT_PTC14 UINT64_C(0x0000000000000400)
  219. #define BGFX_CAPS_TEXTURE_FORMAT_PTC14A UINT64_C(0x0000000000000800)
  220. #define BGFX_CAPS_TEXTURE_FORMAT_PTC12A UINT64_C(0x0000000000001000)
  221. #define BGFX_CAPS_TEXTURE_FORMAT_PTC22 UINT64_C(0x0000000000002000)
  222. #define BGFX_CAPS_TEXTURE_FORMAT_PTC24 UINT64_C(0x0000000000004000)
  223. #define BGFX_CAPS_TEXTURE_FORMAT_D16 UINT64_C(0x0000000000008000)
  224. #define BGFX_CAPS_TEXTURE_FORMAT_D24 UINT64_C(0x0000000000010000)
  225. #define BGFX_CAPS_TEXTURE_FORMAT_D24S8 UINT64_C(0x0000000000020000)
  226. #define BGFX_CAPS_TEXTURE_FORMAT_D32 UINT64_C(0x0000000000040000)
  227. #define BGFX_CAPS_TEXTURE_FORMAT_D16F UINT64_C(0x0000000000080000)
  228. #define BGFX_CAPS_TEXTURE_FORMAT_D24F UINT64_C(0x0000000000100000)
  229. #define BGFX_CAPS_TEXTURE_FORMAT_D32F UINT64_C(0x0000000000200000)
  230. #define BGFX_CAPS_TEXTURE_FORMAT_D0S8 UINT64_C(0x0000000000400000)
  231. #define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000001000000)
  232. #define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000004000000)
  233. #define BGFX_CAPS_INSTANCING UINT64_C(0x0000000008000000)
  234. #define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000010000000)
  235. #define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000020000000)
  236. #define BGFX_CAPS_TEXTURE_DEPTH_MASK (0 \
  237. | BGFX_CAPS_TEXTURE_FORMAT_D16 \
  238. | BGFX_CAPS_TEXTURE_FORMAT_D24 \
  239. | BGFX_CAPS_TEXTURE_FORMAT_D24S8 \
  240. | BGFX_CAPS_TEXTURE_FORMAT_D32 \
  241. | BGFX_CAPS_TEXTURE_FORMAT_D16F \
  242. | BGFX_CAPS_TEXTURE_FORMAT_D24F \
  243. | BGFX_CAPS_TEXTURE_FORMAT_D32F \
  244. | BGFX_CAPS_TEXTURE_FORMAT_D0S8 \
  245. )
  246. ///
  247. #define BGFX_HANDLE(_name) \
  248. struct _name { uint16_t idx; }; \
  249. inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; }
  250. #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
  251. namespace bx { struct ReallocatorI; }
  252. /// BGFX
  253. namespace bgfx
  254. {
  255. struct Fatal
  256. {
  257. enum Enum
  258. {
  259. DebugCheck,
  260. MinimumRequiredSpecs,
  261. InvalidShader,
  262. UnableToInitialize,
  263. UnableToCreateRenderTarget,
  264. UnableToCreateTexture,
  265. };
  266. };
  267. struct RendererType
  268. {
  269. enum Enum
  270. {
  271. Null,
  272. Direct3D9,
  273. Direct3D11,
  274. OpenGLES2,
  275. OpenGLES3,
  276. OpenGL,
  277. Count
  278. };
  279. };
  280. struct Attrib
  281. {
  282. enum Enum // corresponds to vertex shader attribute:
  283. {
  284. Position, // a_position
  285. Normal, // a_normal
  286. Tangent, // a_tangent
  287. Color0, // a_color0
  288. Color1, // a_color1
  289. Indices, // a_indices
  290. Weight, // a_weight
  291. TexCoord0, // a_texcoord0
  292. TexCoord1, // a_texcoord1
  293. TexCoord2, // a_texcoord2
  294. TexCoord3, // a_texcoord3
  295. TexCoord4, // a_texcoord4
  296. TexCoord5, // a_texcoord5
  297. TexCoord6, // a_texcoord6
  298. TexCoord7, // a_texcoord7
  299. Count
  300. };
  301. };
  302. struct AttribType
  303. {
  304. enum Enum
  305. {
  306. Uint8,
  307. Int16,
  308. Half, // Availability depends on: BGFX_CAPS_VERTEX_ATTRIB_HALF.
  309. Float,
  310. Count
  311. };
  312. };
  313. struct TextureFormat
  314. {
  315. // Availability depends on BGFX_CAPS_TEXTURE_FORMAT_*.
  316. enum Enum
  317. {
  318. BC1, // DXT1
  319. BC2, // DXT3
  320. BC3, // DXT5
  321. BC4, // LATC1/ATI1
  322. BC5, // LATC2/ATI2
  323. ETC1, // ETC1 RGB8
  324. ETC2, // ETC2 RGB8
  325. ETC2A, // ETC2 RGBA8
  326. ETC2A1, // ETC2 RGB8A1
  327. PTC12, // PVRTC1 RGB 2BPP
  328. PTC14, // PVRTC1 RGB 4BPP
  329. PTC14A, // PVRTC1 RGBA 4BPP
  330. PTC12A, // PVRTC1 RGBA 2BPP
  331. PTC22, // PVRTC2 RGBA 2BPP
  332. PTC24, // PVRTC2 RGBA 4BPP
  333. Unknown, // compressed formats above
  334. L8,
  335. BGRA8,
  336. RGBA16,
  337. RGBA16F,
  338. R5G6B5,
  339. RGBA4,
  340. RGB5A1,
  341. RGB10A2,
  342. UnknownDepth, // depth formats below
  343. D16,
  344. D24,
  345. D24S8,
  346. D32,
  347. D16F,
  348. D24F,
  349. D32F,
  350. D0S8,
  351. Count
  352. };
  353. };
  354. struct UniformType
  355. {
  356. enum Enum
  357. {
  358. Uniform1i,
  359. Uniform1f,
  360. End,
  361. Uniform1iv,
  362. Uniform1fv,
  363. Uniform2fv,
  364. Uniform3fv,
  365. Uniform4fv,
  366. Uniform3x3fv,
  367. Uniform4x4fv,
  368. Count
  369. };
  370. };
  371. static const uint16_t invalidHandle = UINT16_MAX;
  372. BGFX_HANDLE(DynamicIndexBufferHandle);
  373. BGFX_HANDLE(DynamicVertexBufferHandle);
  374. BGFX_HANDLE(FragmentShaderHandle);
  375. BGFX_HANDLE(IndexBufferHandle);
  376. BGFX_HANDLE(ProgramHandle);
  377. BGFX_HANDLE(RenderTargetHandle);
  378. BGFX_HANDLE(TextureHandle);
  379. BGFX_HANDLE(UniformHandle);
  380. BGFX_HANDLE(VertexBufferHandle);
  381. BGFX_HANDLE(VertexDeclHandle);
  382. BGFX_HANDLE(VertexShaderHandle);
  383. /// Callback interface to implement application specific behavior.
  384. /// Cached items are currently used only for OpenGL binary shaders.
  385. ///
  386. /// NOTE:
  387. /// 'fatal' callback can be called from any thread. Other callbacks
  388. /// are called from the render thread.
  389. ///
  390. struct CallbackI
  391. {
  392. virtual ~CallbackI() = 0;
  393. /// If fatal code code is not Fatal::DebugCheck this callback is
  394. /// called on unrecoverable error. It's not safe to continue, inform
  395. /// user and terminate application from this call.
  396. virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
  397. /// Return size of for cached item. Return 0 if no cached item was
  398. /// found.
  399. virtual uint32_t cacheReadSize(uint64_t _id) = 0;
  400. /// Read cached item.
  401. virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
  402. /// Write cached item.
  403. virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
  404. /// Screenshot captured. Screenshot format is always 4-byte BGRA.
  405. virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) = 0;
  406. /// Called when capture begins.
  407. virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx::TextureFormat::Enum _format, bool _yflip) = 0;
  408. /// Called when capture ends.
  409. virtual void captureEnd() = 0;
  410. /// Captured frame.
  411. virtual void captureFrame(const void* _data, uint32_t _size) = 0;
  412. };
  413. inline CallbackI::~CallbackI()
  414. {
  415. }
  416. struct Memory
  417. {
  418. uint8_t* data;
  419. uint32_t size;
  420. };
  421. /// Renderer capabilities.
  422. struct Caps
  423. {
  424. /// Renderer backend type.
  425. RendererType::Enum rendererType;
  426. /// Supported functionality, it includes emulated functionality.
  427. /// Checking supported and not emulated will give functionality
  428. /// natively supported by renderer.
  429. uint64_t supported;
  430. /// Emulated functionality. For example some texture compression
  431. /// modes are not natively supported by all renderers. The library
  432. /// internally decompresses texture into supported format.
  433. uint64_t emulated;
  434. uint16_t maxTextureSize; ///< Maximum texture size.
  435. uint16_t maxDrawCalls; ///< Maximum draw calls.
  436. };
  437. struct TransientIndexBuffer
  438. {
  439. uint8_t* data;
  440. uint32_t size;
  441. IndexBufferHandle handle;
  442. uint32_t startIndex;
  443. };
  444. struct TransientVertexBuffer
  445. {
  446. uint8_t* data;
  447. uint32_t size;
  448. uint32_t startVertex;
  449. uint16_t stride;
  450. VertexBufferHandle handle;
  451. VertexDeclHandle decl;
  452. };
  453. struct InstanceDataBuffer
  454. {
  455. uint8_t* data;
  456. uint32_t size;
  457. uint32_t offset;
  458. uint16_t stride;
  459. uint16_t num;
  460. VertexBufferHandle handle;
  461. };
  462. struct TextureInfo
  463. {
  464. TextureFormat::Enum format;
  465. uint32_t storageSize;
  466. uint16_t width;
  467. uint16_t height;
  468. uint16_t depth;
  469. uint8_t numMips;
  470. uint8_t bitsPerPixel;
  471. };
  472. /// Vertex declaration.
  473. struct VertexDecl
  474. {
  475. /// Start VertexDecl.
  476. void begin(RendererType::Enum _renderer = RendererType::Null);
  477. /// End VertexDecl.
  478. void end();
  479. /// Add attribute to VertexDecl.
  480. ///
  481. /// @param _attrib Attribute semantics.
  482. /// @param _num Number of elements 1, 2, 3 or 4.
  483. /// @param _type Element type.
  484. /// @param _normalized When using fixed point AttribType (f.e. Uint8)
  485. /// value will be normalized for vertex shader usage. When normalized
  486. /// is set to true, AttribType::Uint8 value in range 0-255 will be
  487. /// in range 0.0-1.0 in vertex shader.
  488. /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
  489. /// vertexConvert for AttribType::Uint8 and AttribType::Int16.
  490. /// Unpacking code must be implemented inside vertex shader.
  491. ///
  492. /// NOTE:
  493. /// Must be called between begin/end.
  494. ///
  495. void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
  496. /// Skip _num bytes in vertex stream.
  497. void skip(uint8_t _num);
  498. /// Decode attribute.
  499. void decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const;
  500. /// Returns true if VertexDecl contains attribute.
  501. bool has(Attrib::Enum _attrib) const { return 0xff != m_attributes[_attrib]; }
  502. /// Returns relative attribute offset from the vertex.
  503. uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; }
  504. /// Returns vertex stride.
  505. uint16_t getStride() const { return m_stride; }
  506. /// Returns size of vertex buffer for number of vertices.
  507. uint32_t getSize(uint32_t _num) const { return _num*m_stride; }
  508. uint32_t m_hash;
  509. uint16_t m_stride;
  510. uint16_t m_offset[Attrib::Count];
  511. uint8_t m_attributes[Attrib::Count];
  512. };
  513. /// Pack vec4 into vertex stream format.
  514. void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index = 0);
  515. /// Unpack vec4 from vertex stream format.
  516. void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index = 0);
  517. /// Converts vertex stream data from one vertex stream format to another.
  518. ///
  519. /// @param _destDecl Destination vertex stream declaration.
  520. /// @param _destData Destination vertex stream.
  521. /// @param _srcDecl Source vertex stream declaration.
  522. /// @param _srcData Source vertex stream data.
  523. /// @param _num Number of vertices to convert from source to destination.
  524. ///
  525. void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num = 1);
  526. /// Weld vertices.
  527. ///
  528. /// @param _output Welded vertices remapping table. The size of buffer
  529. /// must be the same as number of vertices.
  530. /// @param _decl Vertex stream declaration.
  531. /// @param _data Vertex stream.
  532. /// @param _num Number of vertices in vertex stream.
  533. /// @param _epsilon Error tolerance for vertex position comparison.
  534. /// @returns Number of unique vertices after vertex welding.
  535. ///
  536. uint16_t weldVertices(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon = 0.001f);
  537. /// Swizzle RGBA8 image to BGRA8.
  538. ///
  539. /// @param _width Width of input image (pixels).
  540. /// @param _height Height of input image (pixels).
  541. /// @param _pitch Pitch of input image (bytes).
  542. /// @param _src Source image.
  543. /// @param _dst Destination image. Must be the same size as input image.
  544. /// _dst might be pointer to the same memory as _src.
  545. ///
  546. void imageSwizzleBgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  547. /// Downsample RGBA8 image with 2x2 pixel average filter.
  548. ///
  549. /// @param _width Width of input image (pixels).
  550. /// @param _height Height of input image (pixels).
  551. /// @param _pitch Pitch of input image (bytes).
  552. /// @param _src Source image.
  553. /// @param _dst Destination image. Must be at least quarter size of
  554. /// input image. _dst might be pointer to the same memory as _src.
  555. ///
  556. void imageRgba8Downsample2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  557. /// Returns renderer backend API type.
  558. RendererType::Enum getRendererType();
  559. /// Initialize bgfx library.
  560. ///
  561. /// @param _callback Provide application specific callback interface.
  562. /// See: CallbackI
  563. ///
  564. /// @param _reallocator Custom allocator. When custom allocator is not
  565. /// specified, library uses default CRT allocator. The library assumes
  566. /// custom allocator is thread safe.
  567. ///
  568. void init(CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
  569. /// Shutdown bgfx library.
  570. void shutdown();
  571. /// Reset graphic settings.
  572. void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE);
  573. /// Advance to next frame. When using multithreaded renderer, this call
  574. /// just swaps internal buffers, kicks render thread, and returns. In
  575. /// singlethreaded renderer this call does frame rendering.
  576. ///
  577. /// @returns Current frame number. This might be used in conjunction with
  578. /// double/multi buffering data outside the library and passing it to
  579. /// library via makeRef calls.
  580. ///
  581. uint32_t frame();
  582. /// Returns renderer capabilities.
  583. const Caps* getCaps();
  584. /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
  585. const Memory* alloc(uint32_t _size);
  586. /// Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
  587. /// doesn't allocate memory for data. It just copies pointer to data.
  588. /// You must make sure data is available for at least 2 bgfx::frame calls.
  589. const Memory* makeRef(const void* _data, uint32_t _size);
  590. /// Set debug flags.
  591. ///
  592. /// @param _debug Available flags:
  593. ///
  594. /// BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
  595. /// all rendering calls will be skipped. It's useful when profiling
  596. /// to quickly assess bottleneck between CPU and GPU.
  597. ///
  598. /// BGFX_DEBUG_STATS - Display internal statistics.
  599. ///
  600. /// BGFX_DEBUG_TEXT - Display debug text.
  601. ///
  602. /// BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
  603. /// primitives will be rendered as lines.
  604. ///
  605. void setDebug(uint32_t _debug);
  606. /// Clear internal debug text buffer.
  607. void dbgTextClear(uint8_t _attr = 0, bool _small = false);
  608. /// Print into internal debug text buffer.
  609. void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
  610. /// Create static index buffer.
  611. IndexBufferHandle createIndexBuffer(const Memory* _mem);
  612. /// Destroy static index buffer.
  613. void destroyIndexBuffer(IndexBufferHandle _handle);
  614. /// Create static vertex buffer.
  615. ///
  616. /// @param _mem Vertex buffer data.
  617. /// @param _decl Vertex declaration.
  618. /// @returns Static vertex buffer handle.
  619. ///
  620. VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  621. /// Destroy static vertex buffer.
  622. ///
  623. /// @param _handle Static vertex buffer handle.
  624. ///
  625. void destroyVertexBuffer(VertexBufferHandle _handle);
  626. /// Create empty dynamic index buffer.
  627. ///
  628. /// @param _num Number of indices.
  629. ///
  630. DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num);
  631. /// Create dynamic index buffer and initialized it.
  632. ///
  633. /// @param _mem Index buffer data.
  634. ///
  635. DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem);
  636. /// Update dynamic index buffer.
  637. ///
  638. /// @param _handle Dynamic index buffer handle.
  639. /// @param _mem Index buffer data.
  640. ///
  641. void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
  642. /// Destroy dynamic index buffer.
  643. ///
  644. /// @param _handle Dynamic index buffer handle.
  645. ///
  646. void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle);
  647. /// Create empty dynamic vertex buffer.
  648. ///
  649. /// @param _num Number of vertices.
  650. /// @param _decl Vertex declaration.
  651. ///
  652. DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl);
  653. /// Create dynamic vertex buffer and initialize it.
  654. ///
  655. /// @param _mem Vertex buffer data.
  656. /// @param _decl Vertex declaration.
  657. ///
  658. DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  659. /// Update dynamic vertex buffer.
  660. void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
  661. /// Destroy dynamic vertex buffer.
  662. void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle);
  663. /// Returns true if internal transient index buffer has enough space.
  664. ///
  665. /// @param _num Number of indices.
  666. ///
  667. bool checkAvailTransientIndexBuffer(uint32_t _num);
  668. /// Returns true if internal transient vertex buffer has enough space.
  669. ///
  670. /// @param _num Number of vertices.
  671. /// @param _decl Vertex declaration.
  672. ///
  673. bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl);
  674. /// Returns true if internal instance data buffer has enough space.
  675. ///
  676. /// @param _num Number of instances.
  677. /// @param _stride Stride per instance.
  678. ///
  679. bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  680. /// Returns true if both internal transient index and vertex buffer have
  681. /// enough space.
  682. ///
  683. /// @param _numVertices Number of vertices.
  684. /// @param _decl Vertex declaration.
  685. /// @param _numIndices Number of indices.
  686. ///
  687. bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices);
  688. /// Allocate transient index buffer.
  689. ///
  690. /// @param[out] _tib TransientIndexBuffer structure is filled and is valid
  691. /// for the duration of frame, and it can be reused for multiple draw
  692. /// calls.
  693. /// @param _num Number of indices to allocate.
  694. ///
  695. /// NOTE:
  696. /// You must call setIndexBuffer after alloc in order to avoid memory
  697. /// leak.
  698. ///
  699. void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
  700. /// Allocate transient vertex buffer.
  701. ///
  702. /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid
  703. /// for the duration of frame, and it can be reused for multiple draw
  704. /// calls.
  705. /// @param _num Number of vertices to allocate.
  706. /// @param _decl Vertex declaration.
  707. ///
  708. /// NOTE:
  709. /// You must call setVertexBuffer after alloc in order to avoid memory
  710. /// leak.
  711. ///
  712. void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
  713. /// Allocate instance data buffer.
  714. ///
  715. /// NOTE:
  716. /// You must call setInstanceDataBuffer after alloc in order to avoid
  717. /// memory leak.
  718. ///
  719. const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  720. /// Create vertex shader from memory buffer.
  721. VertexShaderHandle createVertexShader(const Memory* _mem);
  722. /// Destroy vertex shader. Once program is created with vertex shader
  723. /// it is safe to destroy vertex shader.
  724. void destroyVertexShader(VertexShaderHandle _handle);
  725. /// Create fragment shader from memory buffer.
  726. FragmentShaderHandle createFragmentShader(const Memory* _mem);
  727. /// Destroy fragment shader. Once program is created with fragment shader
  728. /// it is safe to destroy fragment shader.
  729. void destroyFragmentShader(FragmentShaderHandle _handle);
  730. /// Create program with vertex and fragment shaders.
  731. ///
  732. /// @param _vsh Vertex shader.
  733. /// @param _fsh Fragment shader.
  734. /// @returns Program handle if vertex shader output and fragment shader
  735. /// input are matching, otherwise returns invalid program handle.
  736. ///
  737. ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh);
  738. /// Destroy program.
  739. void destroyProgram(ProgramHandle _handle);
  740. /// Calculate amount of memory required for texture.
  741. void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
  742. /// Create texture from memory buffer.
  743. ///
  744. /// @param _mem DDS, KTX or PVR texture data.
  745. /// @param _flags Default texture sampling mode is linear, and wrap mode
  746. /// is repeat.
  747. ///
  748. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  749. /// mode.
  750. ///
  751. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  752. /// sampling.
  753. ///
  754. /// @param _info Returns parsed DDS texture information.
  755. /// @returns Texture handle.
  756. ///
  757. TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, TextureInfo* _info = NULL);
  758. /// Create 2D texture.
  759. ///
  760. /// @param _width
  761. /// @param _height
  762. /// @param _numMips
  763. /// @param _format
  764. /// @param _flags
  765. /// @param _mem
  766. ///
  767. TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  768. /// Create 3D texture.
  769. ///
  770. /// @param _width
  771. /// @param _height
  772. /// @param _depth
  773. /// @param _numMips
  774. /// @param _format
  775. /// @param _flags
  776. /// @param _mem
  777. ///
  778. 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);
  779. /// Create Cube texture.
  780. ///
  781. /// @param _size
  782. /// @param _numMips
  783. /// @param _format
  784. /// @param _flags
  785. /// @param _mem
  786. ///
  787. TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  788. /// Update 2D texture.
  789. ///
  790. /// @param _handle
  791. /// @param _mip
  792. /// @param _x
  793. /// @param _y
  794. /// @param _width
  795. /// @param _height
  796. /// @param _mem
  797. /// @param _pitch Pitch of input image (bytes). When _pitch is set to
  798. /// UINT16_MAX, it will be calculated internally based on _width.
  799. ///
  800. void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch = UINT16_MAX);
  801. /// Update 3D texture.
  802. ///
  803. /// @param _handle
  804. /// @param _mip
  805. /// @param _x
  806. /// @param _y
  807. /// @param _z
  808. /// @param _width
  809. /// @param _height
  810. /// @param _depth
  811. /// @param _mem
  812. ///
  813. 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);
  814. /// Update Cube texture.
  815. ///
  816. /// @param _handle
  817. /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
  818. /// -Y, 4 is +Z, and 5 is -Z.
  819. ///
  820. /// +----------+
  821. /// |-z 2|
  822. /// | ^ +y |
  823. /// | | |
  824. /// | +---->+x |
  825. /// +----------+----------+----------+----------+
  826. /// |+y 1|+y 4|+y 0|+y 5|
  827. /// | ^ -x | ^ +z | ^ +x | ^ -z |
  828. /// | | | | | | | | |
  829. /// | +---->+z | +---->+x | +---->-z | +---->-x |
  830. /// +----------+----------+----------+----------+
  831. /// |+z 3|
  832. /// | ^ -y |
  833. /// | | |
  834. /// | +---->+x |
  835. /// +----------+
  836. ///
  837. /// @param _mip
  838. /// @param _x
  839. /// @param _y
  840. /// @param _width
  841. /// @param _height
  842. /// @param _mem
  843. /// @param _pitch Pitch of input image (bytes). When _pitch is set to
  844. /// UINT16_MAX, it will be calculated internally based on _width.
  845. ///
  846. 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, uint16_t _pitch = UINT16_MAX);
  847. /// Destroy texture.
  848. void destroyTexture(TextureHandle _handle);
  849. /// Create render target.
  850. 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);
  851. /// Destroy render target.
  852. void destroyRenderTarget(RenderTargetHandle _handle);
  853. /// Create shader uniform parameter.
  854. ///
  855. /// @param _name Uniform name in shader.
  856. /// @param _type Type of uniform (See: UniformType).
  857. /// @param _num Number of elements in array.
  858. ///
  859. /// Predefined uniforms:
  860. ///
  861. /// u_viewRect vec4(x, y, width, height) - view rectangle for current
  862. /// view.
  863. ///
  864. /// u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
  865. /// width and height
  866. ///
  867. /// u_view mat4 - view matrix
  868. ///
  869. /// u_viewProj mat4 - concatenated view projection matrix
  870. ///
  871. /// u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
  872. ///
  873. /// u_modelView mat4 - concatenated model view matrix, only first
  874. /// model matrix from array is used.
  875. ///
  876. /// u_modelViewProj mat4 - concatenated model view projection matrix.
  877. ///
  878. /// u_alphaRef float - alpha reference value for alpha test.
  879. ///
  880. UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);
  881. /// Destroy shader uniform parameter.
  882. void destroyUniform(UniformHandle _handle);
  883. /// Set view name.
  884. ///
  885. /// @param _id View id.
  886. /// @param _name View name.
  887. ///
  888. /// NOTE:
  889. /// This is debug only feature.
  890. ///
  891. void setViewName(uint8_t _id, const char* _name);
  892. /// Set view rectangle. Draw primitive outside view will be clipped.
  893. ///
  894. /// @param _id View id.
  895. /// @param _x Position x from the left corner of the window.
  896. /// @param _y Position y from the top corner of the window.
  897. /// @param _width Width of view port region.
  898. /// @param _height Height of view port region.
  899. ///
  900. void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  901. /// Set view rectangle for multiple views.
  902. ///
  903. /// @param _viewMask Bit mask representing affected views.
  904. /// @param _x Position x from the left corner of the window.
  905. /// @param _y Position y from the top corner of the window.
  906. /// @param _width Width of view port region.
  907. /// @param _height Height of view port region.
  908. ///
  909. void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  910. /// Set view scissor. Draw primitive outside view will be clipped. When
  911. /// _x, _y, _width and _height are set to 0, scissor will be disabled.
  912. ///
  913. /// @param _x Position x from the left corner of the window.
  914. /// @param _y Position y from the top corner of the window.
  915. /// @param _width Width of scissor region.
  916. /// @param _height Height of scissor region.
  917. ///
  918. void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  919. /// Set view scissor for multiple views. When _x, _y, _width and _height
  920. /// are set to 0, scissor will be disabled.
  921. ///
  922. /// @param _id View id.
  923. /// @param _viewMask Bit mask representing affected views.
  924. /// @param _x Position x from the left corner of the window.
  925. /// @param _y Position y from the top corner of the window.
  926. /// @param _width Width of scissor region.
  927. /// @param _height Height of scissor region.
  928. ///
  929. void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  930. /// Set view clear flags.
  931. ///
  932. /// @param _id View id.
  933. /// @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
  934. /// operation. See: BGFX_CLEAR_*.
  935. /// @param _rgba Color clear value.
  936. /// @param _depth Depth clear value.
  937. /// @param _stencil Stencil clear value.
  938. ///
  939. void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  940. /// Set view clear flags for multiple views.
  941. void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  942. /// Set view into sequential mode. Draw calls will be sorted in the same
  943. /// order in which submit calls were called.
  944. void setViewSeq(uint8_t _id, bool _enabled);
  945. /// Set multiple views into sequential mode.
  946. void setViewSeqMask(uint32_t _viewMask, bool _enabled);
  947. /// Set view render target.
  948. ///
  949. /// @param _id View id.
  950. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  951. /// render target handle will draw primitives from this view into
  952. /// default backbuffer.
  953. ///
  954. void setViewRenderTarget(uint8_t _id, RenderTargetHandle _handle);
  955. /// Set view render target for multiple views.
  956. ///
  957. /// @param _viewMask View mask.
  958. /// @param _handle Render target handle. Passing BGFX_INVALID_HANDLE as
  959. /// render target handle will draw primitives from this view into
  960. /// default backbuffer.
  961. ///
  962. void setViewRenderTargetMask(uint32_t _viewMask, RenderTargetHandle _handle);
  963. /// Set view view and projection matrices, all draw primitives in this
  964. /// view will use these matrices.
  965. void setViewTransform(uint8_t _id, const void* _view, const void* _proj, uint8_t _other = 0xff);
  966. /// Set view view and projection matrices for multiple views.
  967. void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj, uint8_t _other = 0xff);
  968. /// Sets debug marker.
  969. void setMarker(const char* _marker);
  970. /// Set render states for draw primitive.
  971. ///
  972. /// @param _state State flags. Default state for primitive type is
  973. /// triangles. See: BGFX_STATE_DEFAULT.
  974. ///
  975. /// BGFX_STATE_ALPHA_WRITE - Enable alpha write.
  976. /// BGFX_STATE_DEPTH_WRITE - Enable depth write.
  977. /// BGFX_STATE_DEPTH_TEST_* - Depth test function.
  978. /// BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
  979. /// BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
  980. /// BGFX_STATE_CULL_* - Backface culling mode.
  981. /// BGFX_STATE_RGB_WRITE - Enable RGB write.
  982. /// BGFX_STATE_MSAA - Enable MSAA.
  983. /// BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
  984. ///
  985. /// @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
  986. /// BGFX_STATE_BLEND_INV_FACTOR blend modes.
  987. ///
  988. /// NOTE:
  989. /// 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
  990. /// BGFX_STATE_BLEND_FUNC macros to setup more complex states.
  991. /// 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
  992. /// equation is specified.
  993. ///
  994. void setState(uint64_t _state, uint32_t _rgba = UINT32_MAX);
  995. /// Set stencil test state.
  996. ///
  997. /// @param _fstencil Front stencil state.
  998. /// @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
  999. /// _fstencil is applied to both front and back facing primitives.
  1000. ///
  1001. void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
  1002. /// Set scissor for draw primitive. For scissor for all primitives in
  1003. /// view see setViewScissor.
  1004. ///
  1005. /// @param _x Position x from the left corner of the window.
  1006. /// @param _y Position y from the top corner of the window.
  1007. /// @param _width Width of scissor region.
  1008. /// @param _height Height of scissor region.
  1009. /// @returns Scissor cache index.
  1010. ///
  1011. uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  1012. /// Set scissor from cache for draw primitive.
  1013. ///
  1014. /// @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
  1015. /// scissor and primitive will use view scissor instead.
  1016. ///
  1017. void setScissor(uint16_t _cache = UINT16_MAX);
  1018. /// Set model matrix for draw primitive. If it is not called model will
  1019. /// be rendered with identity model matrix.
  1020. ///
  1021. /// @param _mtx Pointer to first matrix in array.
  1022. /// @param _num Number of matrices in array.
  1023. /// @returns index into matrix cache in case the same model matrix has
  1024. /// to be used for other draw primitive call.
  1025. ///
  1026. uint32_t setTransform(const void* _mtx, uint16_t _num = 1);
  1027. /// Set model matrix from matrix cache for draw primitive.
  1028. ///
  1029. /// @param _cache Index in matrix cache.
  1030. /// @param _num Number of matrices from cache.
  1031. ///
  1032. void setTransform(uint32_t _cache, uint16_t _num = 1);
  1033. /// Set shader uniform parameter for draw primitive.
  1034. void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1);
  1035. /// Set index buffer for draw primitive.
  1036. void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  1037. /// Set index buffer for draw primitive.
  1038. void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  1039. /// Set index buffer for draw primitive.
  1040. void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _numIndices = UINT32_MAX);
  1041. /// Set vertex buffer for draw primitive.
  1042. void setVertexBuffer(VertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  1043. /// Set vertex buffer for draw primitive.
  1044. void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  1045. /// Set vertex buffer for draw primitive.
  1046. void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _numVertices = UINT32_MAX);
  1047. /// Set instance data buffer for draw primitive.
  1048. void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint16_t _num = UINT16_MAX);
  1049. /// Set program for draw primitive.
  1050. void setProgram(ProgramHandle _handle);
  1051. /// Set texture stage for draw primitive.
  1052. ///
  1053. /// @param _stage Texture unit.
  1054. /// @param _sampler Program sampler.
  1055. /// @param _handle Texture handle.
  1056. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1057. /// texture sampling settings from the texture.
  1058. ///
  1059. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  1060. /// mode.
  1061. ///
  1062. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  1063. /// sampling.
  1064. ///
  1065. /// @param _flags Texture sampler filtering flags. UINT32_MAX use the
  1066. /// sampler filtering mode set by texture.
  1067. ///
  1068. void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX);
  1069. /// Set texture stage for draw primitive.
  1070. ///
  1071. /// @param _stage Texture unit.
  1072. /// @param _sampler Program sampler.
  1073. /// @param _handle Render target handle.
  1074. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1075. /// texture sampling settings from the texture.
  1076. ///
  1077. /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
  1078. /// mode.
  1079. ///
  1080. /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
  1081. /// sampling.
  1082. ///
  1083. void setTexture(uint8_t _stage, UniformHandle _sampler, RenderTargetHandle _handle, bool _depth = false, uint32_t _flags = UINT32_MAX);
  1084. /// Submit primitive for rendering into single view.
  1085. ///
  1086. /// @param _id View id.
  1087. /// @param _depth Depth for sorting.
  1088. /// @returns Number of draw calls.
  1089. ///
  1090. uint32_t submit(uint8_t _id, int32_t _depth = 0);
  1091. /// Submit primitive for rendering into multiple views.
  1092. ///
  1093. /// @param _viewMask Mask to which views to submit draw primitive calls.
  1094. /// @param _depth Depth for sorting.
  1095. /// @returns Number of draw calls.
  1096. ///
  1097. uint32_t submitMask(uint32_t _viewMask, int32_t _depth = 0);
  1098. /// Discard all previously set state for draw call.
  1099. void discard();
  1100. /// Request screen shot.
  1101. ///
  1102. /// @param _filePath Will be passed to CallbackI::screenShot callback.
  1103. ///
  1104. /// NOTE:
  1105. /// CallbackI::screenShot must be implemented.
  1106. ///
  1107. void saveScreenShot(const char* _filePath);
  1108. } // namespace bgfx
  1109. #endif // BGFX_H_HEADER_GUARD