bgfx.h 42 KB

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