bgfx.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  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. #include "bgfxdefines.h"
  10. ///
  11. #define BGFX_HANDLE(_name) \
  12. struct _name { uint16_t idx; }; \
  13. inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; }
  14. #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
  15. namespace bx { struct ReallocatorI; }
  16. /// BGFX
  17. namespace bgfx
  18. {
  19. struct Fatal
  20. {
  21. enum Enum
  22. {
  23. DebugCheck,
  24. MinimumRequiredSpecs,
  25. InvalidShader,
  26. UnableToInitialize,
  27. UnableToCreateTexture,
  28. DeviceLost,
  29. Count
  30. };
  31. };
  32. struct RendererType
  33. {
  34. /// Renderer type enumeration.
  35. enum Enum
  36. {
  37. Null, //!< No rendering.
  38. Direct3D9, //!< Direct3D 9.0
  39. Direct3D11, //!< Direct3D 11.0
  40. OpenGLES = 4, //!< OpenGL ES 2.0+
  41. OpenGL, //!< OpenGL 2.1+
  42. Count
  43. };
  44. };
  45. struct Access
  46. {
  47. enum Enum
  48. {
  49. Read,
  50. Write,
  51. ReadWrite,
  52. Count
  53. };
  54. };
  55. struct Attrib
  56. {
  57. /// Corresponds to vertex shader attribute.
  58. enum Enum
  59. {
  60. Position, //!< a_position
  61. Normal, //!< a_normal
  62. Tangent, //!< a_tangent
  63. Bitangent, //!< a_bitangent
  64. Color0, //!< a_color0
  65. Color1, //!< a_color1
  66. Indices, //!< a_indices
  67. Weight, //!< a_weight
  68. TexCoord0, //!< a_texcoord0
  69. TexCoord1, //!< a_texcoord1
  70. TexCoord2, //!< a_texcoord2
  71. TexCoord3, //!< a_texcoord3
  72. TexCoord4, //!< a_texcoord4
  73. TexCoord5, //!< a_texcoord5
  74. TexCoord6, //!< a_texcoord6
  75. TexCoord7, //!< a_texcoord7
  76. Count
  77. };
  78. };
  79. struct AttribType
  80. {
  81. enum Enum
  82. {
  83. Uint8,
  84. Int16,
  85. Half, // Availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`.
  86. Float,
  87. Count
  88. };
  89. };
  90. struct TextureFormat
  91. {
  92. // Availability depends on Caps (see: formats).
  93. enum Enum
  94. {
  95. BC1, // DXT1
  96. BC2, // DXT3
  97. BC3, // DXT5
  98. BC4, // LATC1/ATI1
  99. BC5, // LATC2/ATI2
  100. BC6H, // BC6H
  101. BC7, // BC7
  102. ETC1, // ETC1 RGB8
  103. ETC2, // ETC2 RGB8
  104. ETC2A, // ETC2 RGBA8
  105. ETC2A1, // ETC2 RGB8A1
  106. PTC12, // PVRTC1 RGB 2BPP
  107. PTC14, // PVRTC1 RGB 4BPP
  108. PTC12A, // PVRTC1 RGBA 2BPP
  109. PTC14A, // PVRTC1 RGBA 4BPP
  110. PTC22, // PVRTC2 RGBA 2BPP
  111. PTC24, // PVRTC2 RGBA 4BPP
  112. Unknown, // compressed formats above
  113. R1,
  114. R8,
  115. R16,
  116. R16F,
  117. R32,
  118. R32F,
  119. RG8,
  120. RG16,
  121. RG16F,
  122. RG32,
  123. RG32F,
  124. BGRA8,
  125. RGBA16,
  126. RGBA16F,
  127. RGBA32,
  128. RGBA32F,
  129. R5G6B5,
  130. RGBA4,
  131. RGB5A1,
  132. RGB10A2,
  133. R11G11B10F,
  134. UnknownDepth, // depth formats below
  135. D16,
  136. D24,
  137. D24S8,
  138. D32,
  139. D16F,
  140. D24F,
  141. D32F,
  142. D0S8,
  143. Count
  144. };
  145. };
  146. struct UniformType
  147. {
  148. enum Enum
  149. {
  150. Uniform1i,
  151. Uniform1f,
  152. End,
  153. Uniform1iv,
  154. Uniform1fv,
  155. Uniform2fv,
  156. Uniform3fv,
  157. Uniform4fv,
  158. Uniform3x3fv,
  159. Uniform4x4fv,
  160. Count
  161. };
  162. };
  163. static const uint16_t invalidHandle = UINT16_MAX;
  164. BGFX_HANDLE(DynamicIndexBufferHandle);
  165. BGFX_HANDLE(DynamicVertexBufferHandle);
  166. BGFX_HANDLE(FrameBufferHandle);
  167. BGFX_HANDLE(IndexBufferHandle);
  168. BGFX_HANDLE(ProgramHandle);
  169. BGFX_HANDLE(ShaderHandle);
  170. BGFX_HANDLE(TextureHandle);
  171. BGFX_HANDLE(UniformHandle);
  172. BGFX_HANDLE(VertexBufferHandle);
  173. BGFX_HANDLE(VertexDeclHandle);
  174. /// Callback interface to implement application specific behavior.
  175. /// Cached items are currently used only for OpenGL binary shaders.
  176. ///
  177. /// @remarks
  178. /// 'fatal' callback can be called from any thread. Other callbacks
  179. /// are called from the render thread.
  180. ///
  181. struct CallbackI
  182. {
  183. virtual ~CallbackI() = 0;
  184. /// If fatal code code is not Fatal::DebugCheck this callback is
  185. /// called on unrecoverable error. It's not safe to continue, inform
  186. /// user and terminate application from this call.
  187. ///
  188. /// @param _code Fatal error code.
  189. /// @param _str More information about error.
  190. ///
  191. virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
  192. /// Return size of for cached item. Return 0 if no cached item was
  193. /// found.
  194. ///
  195. /// @param _id Cache id.
  196. /// @returns Number of bytes to read.
  197. ///
  198. virtual uint32_t cacheReadSize(uint64_t _id) = 0;
  199. /// Read cached item.
  200. ///
  201. /// @param _id Cache id.
  202. /// @param _data Buffer where to read data.
  203. /// @param _size Size of data to read.
  204. ///
  205. /// @returns True if data is read.
  206. ///
  207. virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
  208. /// Write cached item.
  209. ///
  210. /// @param _id Cache id.
  211. /// @param _data Data to write.
  212. /// @param _size Size of data to write.
  213. ///
  214. virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
  215. /// Screenshot captured. Screenshot format is always 4-byte BGRA.
  216. ///
  217. /// @param _filePath File path.
  218. /// @param _width Image width.
  219. /// @param _height Image height.
  220. /// @param _pitch Number of bytes to skip to next line.
  221. /// @param _data Image data.
  222. /// @param _size Image size.
  223. /// @param _yflip If true image origin is bottom left.
  224. ///
  225. virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) = 0;
  226. /// Called when capture begins.
  227. virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, TextureFormat::Enum _format, bool _yflip) = 0;
  228. /// Called when capture ends.
  229. virtual void captureEnd() = 0;
  230. /// Captured frame.
  231. ///
  232. /// @param _data Image data.
  233. /// @param _size Image size.
  234. ///
  235. virtual void captureFrame(const void* _data, uint32_t _size) = 0;
  236. };
  237. inline CallbackI::~CallbackI()
  238. {
  239. }
  240. ///
  241. struct Memory
  242. {
  243. uint8_t* data;
  244. uint32_t size;
  245. };
  246. /// Renderer capabilities.
  247. struct Caps
  248. {
  249. /// Renderer backend type. See: `bgfx::RendererType`
  250. RendererType::Enum rendererType;
  251. /// Supported functionality.
  252. ///
  253. /// - `BGFX_CAPS_TEXTURE_COMPARE_LEQUAL` - Less equal texture
  254. /// compare mode.
  255. /// - `BGFX_CAPS_TEXTURE_COMPARE_ALL` - All texture compare modes.
  256. /// - `BGFX_CAPS_TEXTURE_3D` - 3D textures.
  257. /// - `BGFX_CAPS_VERTEX_ATTRIB_HALF` - AttribType::Half.
  258. /// - `BGFX_CAPS_INSTANCING` - Vertex instancing.
  259. /// - `BGFX_CAPS_RENDERER_MULTITHREADED` - Renderer on separate
  260. /// thread.
  261. /// - `BGFX_CAPS_FRAGMENT_DEPTH` - Fragment shader can modify depth
  262. /// buffer value (gl_FragDepth).
  263. /// - `BGFX_CAPS_BLEND_INDEPENDENT` - Multiple render targets can
  264. /// have different blend mode set individually.
  265. /// - `BGFX_CAPS_COMPUTE` - Renderer has compute shaders.
  266. /// - `BGFX_CAPS_FRAGMENT_ORDERING` - Intel's pixel sync.
  267. /// - `BGFX_CAPS_SWAP_CHAIN` - Multiple windows.
  268. ///
  269. uint64_t supported;
  270. uint16_t maxTextureSize; ///< Maximum texture size.
  271. uint16_t maxDrawCalls; ///< Maximum draw calls.
  272. uint8_t maxFBAttachments; ///< Maximum frame buffer attachments.
  273. /// Supported texture formats.
  274. /// - 0 - not supported
  275. /// - 1 - supported
  276. /// - 2 - emulated
  277. uint8_t formats[TextureFormat::Count];
  278. };
  279. ///
  280. struct TransientIndexBuffer
  281. {
  282. uint8_t* data;
  283. uint32_t size;
  284. IndexBufferHandle handle;
  285. uint32_t startIndex;
  286. };
  287. ///
  288. struct TransientVertexBuffer
  289. {
  290. uint8_t* data;
  291. uint32_t size;
  292. uint32_t startVertex;
  293. uint16_t stride;
  294. VertexBufferHandle handle;
  295. VertexDeclHandle decl;
  296. };
  297. ///
  298. struct InstanceDataBuffer
  299. {
  300. uint8_t* data; //!< Pointer to data.
  301. uint32_t size; //!< Data size.
  302. uint32_t offset; //!< Offset in vertex buffer.
  303. uint32_t num; //!< Number of instances.
  304. uint16_t stride; //!< Vertex buffer stride.
  305. VertexBufferHandle handle; //!< Vertex buffer object handle.
  306. };
  307. ///
  308. struct TextureInfo
  309. {
  310. TextureFormat::Enum format; //!< Texture format.
  311. uint32_t storageSize; //!< Total amount of bytes required to store texture.
  312. uint16_t width; //!< Texture width.
  313. uint16_t height; //!< Texture height.
  314. uint16_t depth; //!< Texture depth.
  315. uint8_t numMips; //!< Number of MIP maps.
  316. uint8_t bitsPerPixel; //!< Format bits per pixel.
  317. };
  318. ///
  319. struct Transform
  320. {
  321. float* data; //!< Pointer to first matrix.
  322. uint16_t num; //!< Number of matrices.
  323. };
  324. /// HMD info.
  325. struct HMD
  326. {
  327. /// Eye
  328. struct Eye
  329. {
  330. float rotation[4]; //!< Eye rotation represented as quaternion.
  331. float translation[3]; //!< Eye translation.
  332. float fov[4]; //!< Field of view (up, down, left, right).
  333. float viewOffset[3]; //!< Eye view matrix translation adjustment.
  334. float pixelsPerTanAngle[2]; //!<
  335. };
  336. Eye eye[2];
  337. uint16_t width; //!< Framebuffer width.
  338. uint16_t height; //!< Framebuffer width.
  339. };
  340. /// Vertex declaration.
  341. struct VertexDecl
  342. {
  343. VertexDecl();
  344. /// Start VertexDecl.
  345. VertexDecl& begin(RendererType::Enum _renderer = RendererType::Null);
  346. /// End VertexDecl.
  347. void end();
  348. /// Add attribute to VertexDecl.
  349. ///
  350. /// @param _attrib Attribute semantics. See: `bgfx::Attrib`
  351. /// @param _num Number of elements 1, 2, 3 or 4.
  352. /// @param _type Element type.
  353. /// @param _normalized When using fixed point AttribType (f.e. Uint8)
  354. /// value will be normalized for vertex shader usage. When normalized
  355. /// is set to true, AttribType::Uint8 value in range 0-255 will be
  356. /// in range 0.0-1.0 in vertex shader.
  357. /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
  358. /// vertexConvert for AttribType::Uint8 and AttribType::Int16.
  359. /// Unpacking code must be implemented inside vertex shader.
  360. ///
  361. /// @remarks
  362. /// Must be called between begin/end.
  363. ///
  364. VertexDecl& add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
  365. /// Skip _num bytes in vertex stream.
  366. VertexDecl& skip(uint8_t _num);
  367. /// Decode attribute.
  368. void decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const;
  369. /// Returns true if VertexDecl contains attribute.
  370. bool has(Attrib::Enum _attrib) const { return 0xff != m_attributes[_attrib]; }
  371. /// Returns relative attribute offset from the vertex.
  372. uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; }
  373. /// Returns vertex stride.
  374. uint16_t getStride() const { return m_stride; }
  375. /// Returns size of vertex buffer for number of vertices.
  376. uint32_t getSize(uint32_t _num) const { return _num*m_stride; }
  377. uint32_t m_hash;
  378. uint16_t m_stride;
  379. uint16_t m_offset[Attrib::Count];
  380. uint8_t m_attributes[Attrib::Count];
  381. };
  382. /// Pack vec4 into vertex stream format.
  383. void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index = 0);
  384. /// Unpack vec4 from vertex stream format.
  385. void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index = 0);
  386. /// Converts vertex stream data from one vertex stream format to another.
  387. ///
  388. /// @param _destDecl Destination vertex stream declaration.
  389. /// @param _destData Destination vertex stream.
  390. /// @param _srcDecl Source vertex stream declaration.
  391. /// @param _srcData Source vertex stream data.
  392. /// @param _num Number of vertices to convert from source to destination.
  393. ///
  394. void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num = 1);
  395. /// Weld vertices.
  396. ///
  397. /// @param _output Welded vertices remapping table. The size of buffer
  398. /// must be the same as number of vertices.
  399. /// @param _decl Vertex stream declaration.
  400. /// @param _data Vertex stream.
  401. /// @param _num Number of vertices in vertex stream.
  402. /// @param _epsilon Error tolerance for vertex position comparison.
  403. /// @returns Number of unique vertices after vertex welding.
  404. ///
  405. uint16_t weldVertices(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon = 0.001f);
  406. /// Swizzle RGBA8 image to BGRA8.
  407. ///
  408. /// @param _width Width of input image (pixels).
  409. /// @param _height Height of input image (pixels).
  410. /// @param _pitch Pitch of input image (bytes).
  411. /// @param _src Source image.
  412. /// @param _dst Destination image. Must be the same size as input image.
  413. /// _dst might be pointer to the same memory as _src.
  414. ///
  415. void imageSwizzleBgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  416. /// Downsample RGBA8 image with 2x2 pixel average filter.
  417. ///
  418. /// @param _width Width of input image (pixels).
  419. /// @param _height Height of input image (pixels).
  420. /// @param _pitch Pitch of input image (bytes).
  421. /// @param _src Source image.
  422. /// @param _dst Destination image. Must be at least quarter size of
  423. /// input image. _dst might be pointer to the same memory as _src.
  424. ///
  425. void imageRgba8Downsample2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
  426. /// Returns supported backend API renderers.
  427. uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]);
  428. /// Returns name of renderer.
  429. const char* getRendererName(RendererType::Enum _type);
  430. /// Initialize bgfx library.
  431. ///
  432. /// @param _type Select rendering backend. When set to RendererType::Count
  433. /// default rendering backend will be selected.
  434. /// See: `bgfx::RendererType`
  435. ///
  436. /// @param _callback Provide application specific callback interface.
  437. /// See: `bgfx::CallbackI`
  438. ///
  439. /// @param _reallocator Custom allocator. When custom allocator is not
  440. /// specified, library uses default CRT allocator. The library assumes
  441. /// icustom allocator is thread safe.
  442. ///
  443. /// @attention C99 equivalent is `bgfx_init`.
  444. ///
  445. void init(RendererType::Enum _type = RendererType::Count, CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
  446. /// Shutdown bgfx library.
  447. ///
  448. /// @attention C99 equivalent is `bgfx_shutdown`.
  449. ///
  450. void shutdown();
  451. /// Reset graphic settings.
  452. ///
  453. /// @param _width Main window width.
  454. /// @param _height Main window height.
  455. /// @param _flags
  456. /// - `BGFX_RESET_NONE` - No reset flags.
  457. /// - `BGFX_RESET_FULLSCREEN` - Not supported yet.
  458. /// - `BGFX_RESET_MSAA_X[2/4/8/16]` - Enable 2, 4, 8 or 16 x MSAA.
  459. /// - `BGFX_RESET_VSYNC` - Enable V-Sync.
  460. /// - `BGFX_RESET_CAPTURE` - Begin screen capture.
  461. ///
  462. /// @attention C99 equivalent is `bgfx_reset`.
  463. ///
  464. void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE);
  465. /// Advance to next frame. When using multithreaded renderer, this call
  466. /// just swaps internal buffers, kicks render thread, and returns. In
  467. /// singlethreaded renderer this call does frame rendering.
  468. ///
  469. /// @returns Current frame number. This might be used in conjunction with
  470. /// double/multi buffering data outside the library and passing it to
  471. /// library via `bgfx::makeRef` calls.
  472. ///
  473. /// @attention C99 equivalent is `bgfx_frame`.
  474. ///
  475. uint32_t frame();
  476. /// Returns current renderer backend API type.
  477. ///
  478. /// @remarks
  479. /// Library must be initialized.
  480. ///
  481. /// @attention C99 equivalent is `bgfx_get_renderer_type`.
  482. ///
  483. RendererType::Enum getRendererType();
  484. /// Returns renderer capabilities.
  485. ///
  486. /// @returns Pointer to static `bgfx::Caps` structure.
  487. ///
  488. /// @remarks
  489. /// Library must be initialized.
  490. ///
  491. /// @attention C99 equivalent is `bgfx_get_caps`.
  492. ///
  493. const Caps* getCaps();
  494. /// Returns HMD info.
  495. const HMD* getHMD();
  496. /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
  497. const Memory* alloc(uint32_t _size);
  498. /// Allocate buffer and copy data into it. Data will be freed inside bgfx.
  499. const Memory* copy(const void* _data, uint32_t _size);
  500. /// Make reference to data to pass to bgfx. Unlike `bgfx::alloc` this call
  501. /// doesn't allocate memory for data. It just copies pointer to data. You
  502. /// must make sure data is available for at least 2 `bgfx::frame` calls.
  503. const Memory* makeRef(const void* _data, uint32_t _size);
  504. /// Set debug flags.
  505. ///
  506. /// @param _debug Available flags:
  507. /// - `BGFX_DEBUG_IFH` - Infinitely fast hardware. When this flag is set
  508. /// all rendering calls will be skipped. It's useful when profiling
  509. /// to quickly assess bottleneck between CPU and GPU.
  510. /// - `BGFX_DEBUG_STATS` - Display internal statistics.
  511. /// - `BGFX_DEBUG_TEXT` - Display debug text.
  512. /// - `BGFX_DEBUG_WIREFRAME` - Wireframe rendering. All rendering
  513. /// primitives will be rendered as lines.
  514. ///
  515. void setDebug(uint32_t _debug);
  516. /// Clear internal debug text buffer.
  517. void dbgTextClear(uint8_t _attr = 0, bool _small = false);
  518. /// Print into internal debug text buffer.
  519. void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
  520. /// Draw image into internal debug text buffer.
  521. ///
  522. /// @param _x X position from top-left.
  523. /// @param _y Y position from top-left.
  524. /// @param _width Image width.
  525. /// @param _height Image height.
  526. /// @param _data Raw image data (character/attribute raw encoding).
  527. /// @param _pitch Image pitch in bytes.
  528. ///
  529. void dbgTextImage(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
  530. /// Create static index buffer.
  531. ///
  532. /// @remarks
  533. /// Only 16-bit index buffer is supported.
  534. ///
  535. IndexBufferHandle createIndexBuffer(const Memory* _mem);
  536. /// Destroy static index buffer.
  537. void destroyIndexBuffer(IndexBufferHandle _handle);
  538. /// Create static vertex buffer.
  539. ///
  540. /// @param _mem Vertex buffer data.
  541. /// @param _decl Vertex declaration.
  542. /// @returns Static vertex buffer handle.
  543. ///
  544. VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags = BGFX_BUFFER_COMPUTE_NONE);
  545. /// Destroy static vertex buffer.
  546. ///
  547. /// @param _handle Static vertex buffer handle.
  548. ///
  549. void destroyVertexBuffer(VertexBufferHandle _handle);
  550. /// Create empty dynamic index buffer.
  551. ///
  552. /// @param _num Number of indices.
  553. ///
  554. /// @remarks
  555. /// Only 16-bit index buffer is supported.
  556. ///
  557. DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num);
  558. /// Create dynamic index buffer and initialized it.
  559. ///
  560. /// @param _mem Index buffer data.
  561. ///
  562. /// @remarks
  563. /// Only 16-bit index buffer is supported.
  564. ///
  565. DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem);
  566. /// Update dynamic index buffer.
  567. ///
  568. /// @param _handle Dynamic index buffer handle.
  569. /// @param _mem Index buffer data.
  570. ///
  571. void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
  572. /// Destroy dynamic index buffer.
  573. ///
  574. /// @param _handle Dynamic index buffer handle.
  575. ///
  576. void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle);
  577. /// Create empty dynamic vertex buffer.
  578. ///
  579. /// @param _num Number of vertices.
  580. /// @param _decl Vertex declaration.
  581. /// @param _compute True if vertex buffer will be used by compute shader.
  582. ///
  583. DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl, uint8_t _flags = BGFX_BUFFER_COMPUTE_NONE);
  584. /// Create dynamic vertex buffer and initialize it.
  585. ///
  586. /// @param _mem Vertex buffer data.
  587. /// @param _decl Vertex declaration.
  588. ///
  589. DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
  590. /// Update dynamic vertex buffer.
  591. void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
  592. /// Destroy dynamic vertex buffer.
  593. void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle);
  594. /// Returns true if internal transient index buffer has enough space.
  595. ///
  596. /// @param _num Number of indices.
  597. ///
  598. bool checkAvailTransientIndexBuffer(uint32_t _num);
  599. /// Returns true if internal transient vertex buffer has enough space.
  600. ///
  601. /// @param _num Number of vertices.
  602. /// @param _decl Vertex declaration.
  603. ///
  604. bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl);
  605. /// Returns true if internal instance data buffer has enough space.
  606. ///
  607. /// @param _num Number of instances.
  608. /// @param _stride Stride per instance.
  609. ///
  610. bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  611. /// Returns true if both internal transient index and vertex buffer have
  612. /// enough space.
  613. ///
  614. /// @param _numVertices Number of vertices.
  615. /// @param _decl Vertex declaration.
  616. /// @param _numIndices Number of indices.
  617. ///
  618. bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices);
  619. /// Allocate transient index buffer.
  620. ///
  621. /// @param[out] _tib TransientIndexBuffer structure is filled and is valid
  622. /// for the duration of frame, and it can be reused for multiple draw
  623. /// calls.
  624. /// @param _num Number of indices to allocate.
  625. ///
  626. /// @remarks
  627. /// 1. You must call setIndexBuffer after alloc in order to avoid memory
  628. /// leak.
  629. /// 2. Only 16-bit index buffer is supported.
  630. ///
  631. void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
  632. /// Allocate transient vertex buffer.
  633. ///
  634. /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid
  635. /// for the duration of frame, and it can be reused for multiple draw
  636. /// calls.
  637. /// @param _num Number of vertices to allocate.
  638. /// @param _decl Vertex declaration.
  639. ///
  640. /// @remarks
  641. /// You must call setVertexBuffer after alloc in order to avoid memory
  642. /// leak.
  643. ///
  644. void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
  645. /// Check for required space and allocate transient vertex and index
  646. /// buffers. If both space requirements are satisfied function returns
  647. /// true.
  648. ///
  649. /// @remarks
  650. /// Only 16-bit index buffer is supported.
  651. ///
  652. bool allocTransientBuffers(TransientVertexBuffer* _tvb, const VertexDecl& _decl, uint16_t _numVertices, TransientIndexBuffer* _tib, uint16_t _numIndices);
  653. /// Allocate instance data buffer.
  654. ///
  655. /// @remarks
  656. /// You must call setInstanceDataBuffer after alloc in order to avoid
  657. /// memory leak.
  658. ///
  659. const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
  660. /// Create shader from memory buffer.
  661. ShaderHandle createShader(const Memory* _mem);
  662. /// Returns num of uniforms, and uniform handles used inside shader.
  663. ///
  664. /// @param _handle Shader handle.
  665. /// @param _uniforms UniformHandle array where data will be stored.
  666. /// @param _max Maximum capacity of array.
  667. /// @returns Number of uniforms used by shader.
  668. ///
  669. /// @remarks
  670. /// Only non-predefined uniforms are returned.
  671. ///
  672. uint16_t getShaderUniforms(ShaderHandle _handle, UniformHandle* _uniforms = NULL, uint16_t _max = 0);
  673. /// Destroy shader. Once program is created with shader it is safe to
  674. /// destroy shader.
  675. void destroyShader(ShaderHandle _handle);
  676. /// Create program with vertex and fragment shaders.
  677. ///
  678. /// @param _vsh Vertex shader.
  679. /// @param _fsh Fragment shader.
  680. /// @param _destroyShaders If true, shaders will be destroyed when
  681. /// program is destroyed.
  682. /// @returns Program handle if vertex shader output and fragment shader
  683. /// input are matching, otherwise returns invalid program handle.
  684. ///
  685. ProgramHandle createProgram(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders = false);
  686. /// Create program with compute shader.
  687. ///
  688. /// @param _csh Compute shader.
  689. /// @param _destroyShader If true, shader will be destroyed when
  690. /// program is destroyed.
  691. /// @returns Program handle.
  692. ///
  693. ProgramHandle createProgram(ShaderHandle _csh, bool _destroyShader = false);
  694. /// Destroy program.
  695. void destroyProgram(ProgramHandle _handle);
  696. /// Calculate amount of memory required for texture.
  697. void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
  698. /// Create texture from memory buffer.
  699. ///
  700. /// @param[in] _mem DDS, KTX or PVR texture data.
  701. /// @param[in] _flags Default texture sampling mode is linear, and wrap mode
  702. /// is repeat.
  703. /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
  704. /// mode.
  705. /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
  706. /// sampling.
  707. ///
  708. /// @param[in] _skip Skip top level mips when parsing texture.
  709. /// @param[out] _info When non-`NULL` is specified it returns parsed texture information.
  710. /// @returns Texture handle.
  711. ///
  712. TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, TextureInfo* _info = NULL);
  713. /// Create 2D texture.
  714. ///
  715. /// @param _width
  716. /// @param _height
  717. /// @param _numMips
  718. /// @param _format
  719. /// @param _flags
  720. /// @param _mem
  721. ///
  722. TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  723. /// Create 3D texture.
  724. ///
  725. /// @param _width
  726. /// @param _height
  727. /// @param _depth
  728. /// @param _numMips
  729. /// @param _format
  730. /// @param _flags
  731. /// @param _mem
  732. ///
  733. 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);
  734. /// Create Cube texture.
  735. ///
  736. /// @param _size
  737. /// @param _numMips
  738. /// @param _format
  739. /// @param _flags
  740. /// @param _mem
  741. ///
  742. TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
  743. /// Update 2D texture.
  744. ///
  745. /// @param _handle
  746. /// @param _mip
  747. /// @param _x
  748. /// @param _y
  749. /// @param _width
  750. /// @param _height
  751. /// @param _mem
  752. /// @param _pitch Pitch of input image (bytes). When _pitch is set to
  753. /// UINT16_MAX, it will be calculated internally based on _width.
  754. ///
  755. 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);
  756. /// Update 3D texture.
  757. ///
  758. /// @param _handle
  759. /// @param _mip
  760. /// @param _x
  761. /// @param _y
  762. /// @param _z
  763. /// @param _width
  764. /// @param _height
  765. /// @param _depth
  766. /// @param _mem
  767. ///
  768. 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);
  769. /// Update Cube texture.
  770. ///
  771. /// @param _handle
  772. /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
  773. /// -Y, 4 is +Z, and 5 is -Z.
  774. ///
  775. /// +----------+
  776. /// |-z 2|
  777. /// | ^ +y |
  778. /// | | |
  779. /// | +---->+x |
  780. /// +----------+----------+----------+----------+
  781. /// |+y 1|+y 4|+y 0|+y 5|
  782. /// | ^ -x | ^ +z | ^ +x | ^ -z |
  783. /// | | | | | | | | |
  784. /// | +---->+z | +---->+x | +---->-z | +---->-x |
  785. /// +----------+----------+----------+----------+
  786. /// |+z 3|
  787. /// | ^ -y |
  788. /// | | |
  789. /// | +---->+x |
  790. /// +----------+
  791. ///
  792. /// @param _mip
  793. /// @param _x
  794. /// @param _y
  795. /// @param _width
  796. /// @param _height
  797. /// @param _mem
  798. /// @param _pitch Pitch of input image (bytes). When _pitch is set to
  799. /// UINT16_MAX, it will be calculated internally based on _width.
  800. ///
  801. 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);
  802. /// Destroy texture.
  803. void destroyTexture(TextureHandle _handle);
  804. /// Create frame buffer (simple).
  805. ///
  806. /// @param _width Texture width.
  807. /// @param _height Texture height.
  808. /// @param _format Texture format.
  809. /// @param _textureFlags Texture flags.
  810. ///
  811. FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
  812. /// Create frame buffer.
  813. ///
  814. /// @param _num Number of texture attachments.
  815. /// @param _handles Texture attachments.
  816. /// @param _destroyTextures If true, textures will be destroyed when
  817. /// frame buffer is destroyed.
  818. ///
  819. FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false);
  820. /// Create frame buffer for multiple window rendering.
  821. ///
  822. /// @param _nwh OS' target native window handle.
  823. /// @param _width Window back buffer width.
  824. /// @param _height Window back buffer height.
  825. /// @param _depthFormat Window back buffer depth format.
  826. ///
  827. /// @returns Handle to frame buffer object.
  828. ///
  829. /// @remarks
  830. /// Frame buffer cannnot be used for sampling.
  831. ///
  832. FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat = TextureFormat::UnknownDepth);
  833. /// Destroy frame buffer.
  834. void destroyFrameBuffer(FrameBufferHandle _handle);
  835. /// Create shader uniform parameter.
  836. ///
  837. /// @param _name Uniform name in shader.
  838. /// @param _type Type of uniform (See: `bgfx::UniformType`).
  839. /// @param _num Number of elements in array.
  840. ///
  841. /// @returns Handle to uniform object.
  842. ///
  843. /// @remarks
  844. /// Predefined uniforms (declared in `bgfx_shader.sh`):
  845. /// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
  846. /// view.
  847. /// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
  848. /// width and height
  849. /// - `u_view mat4` - view matrix
  850. /// - `u_invView mat4` - inverted view matrix
  851. /// - `u_proj mat4` - projection matrix
  852. /// - `u_invProj mat4` - inverted projection matrix
  853. /// - `u_viewProj mat4` - concatenated view projection matrix
  854. /// - `u_invViewProj mat4` - concatenated inverted view projection matrix
  855. /// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
  856. /// - `u_modelView mat4` - concatenated model view matrix, only first
  857. /// model matrix from array is used.
  858. /// - `u_modelViewProj mat4` - concatenated model view projection matrix.
  859. /// - `u_alphaRef float` - alpha reference value for alpha test.
  860. ///
  861. UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);
  862. /// Destroy shader uniform parameter.
  863. ///
  864. /// @param _handle Handle to uniform object.
  865. ///
  866. void destroyUniform(UniformHandle _handle);
  867. /// Set clear color palette value.
  868. ///
  869. /// @param _index Index into palette.
  870. /// @param _rgba Packed 32-bit RGBA value.
  871. ///
  872. void setClearColor(uint8_t _index, uint32_t _rgba);
  873. /// Set clear color palette value.
  874. ///
  875. /// @param _index Index into palette.
  876. /// @param _r, _g, _b, _a RGBA floating point values.
  877. ///
  878. void setClearColor(uint8_t _index, float _r, float _g, float _b, float _a);
  879. /// Set clear color palette value.
  880. ///
  881. /// @param _index Index into palette.
  882. /// @param _rgba RGBA floating point value.
  883. ///
  884. void setClearColor(uint8_t _index, const float _rgba[4]);
  885. /// Set view name.
  886. ///
  887. /// @param _id View id.
  888. /// @param _name View name.
  889. ///
  890. /// @remarks
  891. /// This is debug only feature.
  892. ///
  893. void setViewName(uint8_t _id, const char* _name);
  894. /// Set view rectangle. Draw primitive outside view will be clipped.
  895. ///
  896. /// @param _id View id.
  897. /// @param _x Position x from the left corner of the window.
  898. /// @param _y Position y from the top corner of the window.
  899. /// @param _width Width of view port region.
  900. /// @param _height Height of view port region.
  901. ///
  902. void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  903. /// Set view scissor. Draw primitive outside view will be clipped. When
  904. /// _x, _y, _width and _height are set to 0, scissor will be disabled.
  905. ///
  906. /// @param _x Position x from the left corner of the window.
  907. /// @param _y Position y from the top corner of the window.
  908. /// @param _width Width of scissor region.
  909. /// @param _height Height of scissor region.
  910. ///
  911. void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
  912. /// Set view clear flags.
  913. ///
  914. /// @param _id View id.
  915. /// @param _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear
  916. /// operation. See: `BGFX_CLEAR_*`.
  917. /// @param _rgba Color clear value.
  918. /// @param _depth Depth clear value.
  919. /// @param _stencil Stencil clear value.
  920. ///
  921. void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
  922. /// Set view clear flags with different clear color for each
  923. /// frame buffer texture. Must use setClearColor to setup clear color
  924. /// palette.
  925. ///
  926. /// @param _id View id.
  927. /// @param _flags Clear flags. Use `BGFX_CLEAR_NONE` to remove any clear
  928. /// operation. See: `BGFX_CLEAR_*`.
  929. /// @param _depth Depth clear value.
  930. /// @param _stencil Stencil clear value.
  931. ///
  932. void setViewClear(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0 = UINT8_MAX, uint8_t _1 = UINT8_MAX, uint8_t _2 = UINT8_MAX, uint8_t _3 = UINT8_MAX, uint8_t _4 = UINT8_MAX, uint8_t _5 = UINT8_MAX, uint8_t _6 = UINT8_MAX, uint8_t _7 = UINT8_MAX);
  933. /// Set view into sequential mode. Draw calls will be sorted in the same
  934. /// order in which submit calls were called.
  935. void setViewSeq(uint8_t _id, bool _enabled);
  936. /// Set view frame buffer.
  937. ///
  938. /// @param _id View id.
  939. /// @param _handle Frame buffer handle. Passing `BGFX_INVALID_HANDLE` as
  940. /// frame buffer handle will draw primitives from this view into
  941. /// default back buffer.
  942. ///
  943. /// @remarks
  944. /// Not persistent after `bgfx::reset` call.
  945. ///
  946. void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle);
  947. /// Set view view and projection matrices, all draw primitives in this
  948. /// view will use these matrices.
  949. void setViewTransform(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags = BGFX_VIEW_STEREO, const void* _projR = NULL);
  950. /// Sets debug marker.
  951. void setMarker(const char* _marker);
  952. /// Set render states for draw primitive.
  953. ///
  954. /// @param _state State flags. Default state for primitive type is
  955. /// triangles. See: `BGFX_STATE_DEFAULT`.
  956. /// - `BGFX_STATE_ALPHA_WRITE` - Enable alpha write.
  957. /// - `BGFX_STATE_DEPTH_WRITE` - Enable depth write.
  958. /// - `BGFX_STATE_DEPTH_TEST_*` - Depth test function.
  959. /// - `BGFX_STATE_BLEND_*` - See remark 1 about BGFX_STATE_BLEND_FUNC.
  960. /// - `BGFX_STATE_BLEND_EQUATION_*` - See remark 2.
  961. /// - `BGFX_STATE_CULL_*` - Backface culling mode.
  962. /// - `BGFX_STATE_RGB_WRITE` - Enable RGB write.
  963. /// - `BGFX_STATE_MSAA` - Enable MSAA.
  964. /// - `BGFX_STATE_PT_[TRISTRIP/LINES/POINTS]` - Primitive type.
  965. ///
  966. /// @param _rgba Sets blend factor used by `BGFX_STATE_BLEND_FACTOR` and
  967. /// `BGFX_STATE_BLEND_INV_FACTOR` blend modes.
  968. ///
  969. /// @remarks
  970. /// 1. Use `BGFX_STATE_ALPHA_REF`, `BGFX_STATE_POINT_SIZE` and
  971. /// `BGFX_STATE_BLEND_FUNC` macros to setup more complex states.
  972. /// 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend
  973. /// equation is specified.
  974. ///
  975. void setState(uint64_t _state, uint32_t _rgba = 0);
  976. /// Set stencil test state.
  977. ///
  978. /// @param _fstencil Front stencil state.
  979. /// @param _bstencil Back stencil state. If back is set to `BGFX_STENCIL_NONE`
  980. /// _fstencil is applied to both front and back facing primitives.
  981. ///
  982. void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
  983. /// Set scissor for draw primitive. For scissor for all primitives in
  984. /// view see setViewScissor.
  985. ///
  986. /// @param _x Position x from the left corner of the window.
  987. /// @param _y Position y from the top corner of the window.
  988. /// @param _width Width of scissor region.
  989. /// @param _height Height of scissor region.
  990. /// @returns Scissor cache index.
  991. ///
  992. uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
  993. /// Set scissor from cache for draw primitive.
  994. ///
  995. /// @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
  996. /// scissor and primitive will use view scissor instead.
  997. ///
  998. void setScissor(uint16_t _cache = UINT16_MAX);
  999. /// Set model matrix for draw primitive. If it is not called model will
  1000. /// be rendered with identity model matrix.
  1001. ///
  1002. /// @param _mtx Pointer to first matrix in array.
  1003. /// @param _num Number of matrices in array.
  1004. /// @returns index into matrix cache in case the same model matrix has
  1005. /// to be used for other draw primitive call.
  1006. ///
  1007. uint32_t setTransform(const void* _mtx, uint16_t _num = 1);
  1008. /// Reserve `_num` matrices in internal matrix cache. Pointer returned
  1009. /// can be modifed until `bgfx::frame` is called.
  1010. ///
  1011. /// @param _transform Pointer to `Transform` structure.
  1012. /// @param _num Number of matrices.
  1013. /// @returns index into matrix cache.
  1014. ///
  1015. uint32_t allocTransform(Transform* _transform, uint16_t _num);
  1016. /// Set model matrix from matrix cache for draw primitive.
  1017. ///
  1018. /// @param _cache Index in matrix cache.
  1019. /// @param _num Number of matrices from cache.
  1020. ///
  1021. void setTransform(uint32_t _cache, uint16_t _num = 1);
  1022. /// Set shader uniform parameter for draw primitive.
  1023. void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1);
  1024. /// Set index buffer for draw primitive.
  1025. void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  1026. /// Set index buffer for draw primitive.
  1027. void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
  1028. /// Set index buffer for draw primitive.
  1029. void setIndexBuffer(const TransientIndexBuffer* _tib);
  1030. /// Set index buffer for draw primitive.
  1031. void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices);
  1032. /// Set vertex buffer for draw primitive.
  1033. void setVertexBuffer(VertexBufferHandle _handle);
  1034. /// Set vertex buffer for draw primitive.
  1035. void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices);
  1036. /// Set vertex buffer for draw primitive.
  1037. void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
  1038. /// Set vertex buffer for draw primitive.
  1039. void setVertexBuffer(const TransientVertexBuffer* _tvb);
  1040. /// Set vertex buffer for draw primitive.
  1041. void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices);
  1042. /// Set instance data buffer for draw primitive.
  1043. void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _num = UINT32_MAX);
  1044. /// Set instance data buffer for draw primitive.
  1045. void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _num, uint16_t _stride);
  1046. /// Set instance data buffer for draw primitive.
  1047. void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _offset, uint32_t _num);
  1048. /// Set program for draw primitive.
  1049. void setProgram(ProgramHandle _handle);
  1050. /// Set texture stage for draw primitive.
  1051. ///
  1052. /// @param _stage Texture unit.
  1053. /// @param _sampler Program sampler.
  1054. /// @param _handle Texture handle.
  1055. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1056. /// texture sampling settings from the texture.
  1057. /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
  1058. /// mode.
  1059. /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
  1060. /// sampling.
  1061. ///
  1062. /// @param _flags Texture sampler filtering flags. UINT32_MAX use the
  1063. /// sampler filtering mode set by texture.
  1064. ///
  1065. void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX);
  1066. /// Set texture stage for draw primitive.
  1067. ///
  1068. /// @param _stage Texture unit.
  1069. /// @param _sampler Program sampler.
  1070. /// @param _handle Frame buffer handle.
  1071. /// @param _attachment Attachment index.
  1072. /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
  1073. /// texture sampling settings from the texture.
  1074. /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
  1075. /// mode.
  1076. /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
  1077. /// sampling.
  1078. ///
  1079. void setTexture(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment = 0, uint32_t _flags = UINT32_MAX);
  1080. /// Submit primitive for rendering into single view.
  1081. ///
  1082. /// @param _id View id.
  1083. /// @param _depth Depth for sorting.
  1084. /// @returns Number of draw calls.
  1085. ///
  1086. uint32_t submit(uint8_t _id, int32_t _depth = 0);
  1087. ///
  1088. void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access);
  1089. ///
  1090. void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access);
  1091. ///
  1092. void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access);
  1093. ///
  1094. void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, TextureFormat::Enum _format, Access::Enum _access);
  1095. /// Dispatch compute.
  1096. void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST);
  1097. /// Discard all previously set state for draw or compute call.
  1098. void discard();
  1099. /// Request screen shot.
  1100. ///
  1101. /// @param _filePath Will be passed to `bgfx::CallbackI::screenShot` callback.
  1102. ///
  1103. /// @remarks
  1104. /// `bgfx::CallbackI::screenShot` must be implemented.
  1105. ///
  1106. void saveScreenShot(const char* _filePath);
  1107. } // namespace bgfx
  1108. #endif // BGFX_H_HEADER_GUARD