bgfx.h 47 KB

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