2
0

bgfx.h 37 KB

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