| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295 |
- /*
- * Copyright 2011-2014 Branimir Karadzic. All rights reserved.
- * License: http://www.opensource.org/licenses/BSD-2-Clause
- */
- #ifndef BGFX_H_HEADER_GUARD
- #define BGFX_H_HEADER_GUARD
- #include <stdint.h> // uint32_t
- #include <stdlib.h> // size_t
- ///
- #define BGFX_STATE_DEPTH_WRITE UINT64_C(0x0000000000000001)
- #define BGFX_STATE_ALPHA_WRITE UINT64_C(0x0000000000000008)
- #define BGFX_STATE_ALPHA_MASK UINT64_C(0x000000000000000c)
- #define BGFX_STATE_DEPTH_TEST_LESS UINT64_C(0x0000000000000010)
- #define BGFX_STATE_DEPTH_TEST_LEQUAL UINT64_C(0x0000000000000020)
- #define BGFX_STATE_DEPTH_TEST_EQUAL UINT64_C(0x0000000000000030)
- #define BGFX_STATE_DEPTH_TEST_GEQUAL UINT64_C(0x0000000000000040)
- #define BGFX_STATE_DEPTH_TEST_GREATER UINT64_C(0x0000000000000050)
- #define BGFX_STATE_DEPTH_TEST_NOTEQUAL UINT64_C(0x0000000000000060)
- #define BGFX_STATE_DEPTH_TEST_NEVER UINT64_C(0x0000000000000070)
- #define BGFX_STATE_DEPTH_TEST_ALWAYS UINT64_C(0x0000000000000080)
- #define BGFX_STATE_DEPTH_TEST_SHIFT 4
- #define BGFX_STATE_DEPTH_TEST_MASK UINT64_C(0x00000000000000f0)
- #define BGFX_STATE_BLEND_ZERO UINT64_C(0x0000000000001000)
- #define BGFX_STATE_BLEND_ONE UINT64_C(0x0000000000002000)
- #define BGFX_STATE_BLEND_SRC_COLOR UINT64_C(0x0000000000003000)
- #define BGFX_STATE_BLEND_INV_SRC_COLOR UINT64_C(0x0000000000004000)
- #define BGFX_STATE_BLEND_SRC_ALPHA UINT64_C(0x0000000000005000)
- #define BGFX_STATE_BLEND_INV_SRC_ALPHA UINT64_C(0x0000000000006000)
- #define BGFX_STATE_BLEND_DST_ALPHA UINT64_C(0x0000000000007000)
- #define BGFX_STATE_BLEND_INV_DST_ALPHA UINT64_C(0x0000000000008000)
- #define BGFX_STATE_BLEND_DST_COLOR UINT64_C(0x0000000000009000)
- #define BGFX_STATE_BLEND_INV_DST_COLOR UINT64_C(0x000000000000a000)
- #define BGFX_STATE_BLEND_SRC_ALPHA_SAT UINT64_C(0x000000000000b000)
- #define BGFX_STATE_BLEND_FACTOR UINT64_C(0x000000000000c000)
- #define BGFX_STATE_BLEND_INV_FACTOR UINT64_C(0x000000000000d000)
- #define BGFX_STATE_BLEND_SHIFT 12
- #define BGFX_STATE_BLEND_MASK UINT64_C(0x00000000000ff000)
- #define BGFX_STATE_BLEND_EQUATION_SUB UINT64_C(0x0000000000100000)
- #define BGFX_STATE_BLEND_EQUATION_REVSUB UINT64_C(0x0000000000200000)
- #define BGFX_STATE_BLEND_EQUATION_MIN UINT64_C(0x0000000000300000)
- #define BGFX_STATE_BLEND_EQUATION_MAX UINT64_C(0x0000000000400000)
- #define BGFX_STATE_BLEND_EQUATION_SHIFT 20
- #define BGFX_STATE_BLEND_EQUATION_MASK UINT64_C(0x0000000000700000)
- #define BGFX_STATE_CULL_CW UINT64_C(0x0000000010000000)
- #define BGFX_STATE_CULL_CCW UINT64_C(0x0000000020000000)
- #define BGFX_STATE_CULL_SHIFT 28
- #define BGFX_STATE_CULL_MASK UINT64_C(0x0000000030000000)
- #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000040000000)
- #define BGFX_STATE_ALPHA_REF_SHIFT 32
- #define BGFX_STATE_ALPHA_REF_MASK UINT64_C(0x000000ff00000000)
- #define BGFX_STATE_PT_LINES UINT64_C(0x0000010000000000)
- #define BGFX_STATE_PT_POINTS UINT64_C(0x0000020000000000)
- #define BGFX_STATE_PT_SHIFT 40
- #define BGFX_STATE_PT_MASK UINT64_C(0x0000030000000000)
- #define BGFX_STATE_POINT_SIZE_SHIFT 44
- #define BGFX_STATE_POINT_SIZE_MASK UINT64_C(0x000ff00000000000)
- #define BGFX_STATE_MSAA UINT64_C(0x0020000000000000)
- #define BGFX_STATE_RESERVED_MASK UINT64_C(0xff00000000000000)
- #define BGFX_STATE_NONE UINT64_C(0x0000000000000000)
- #define BGFX_STATE_MASK UINT64_C(0xffffffffffffffff)
- #define BGFX_STATE_DEFAULT (0 \
- | BGFX_STATE_RGB_WRITE \
- | BGFX_STATE_ALPHA_WRITE \
- | BGFX_STATE_DEPTH_TEST_LESS \
- | BGFX_STATE_DEPTH_WRITE \
- | BGFX_STATE_CULL_CW \
- | BGFX_STATE_MSAA \
- )
- #define BGFX_STATE_ALPHA_REF(_ref) ( (uint64_t(_ref)<<BGFX_STATE_ALPHA_REF_SHIFT)&BGFX_STATE_ALPHA_REF_MASK)
- #define BGFX_STATE_POINT_SIZE(_size) ( (uint64_t(_size)<<BGFX_STATE_POINT_SIZE_SHIFT)&BGFX_STATE_POINT_SIZE_MASK)
- #define BGFX_STATE_BLEND_FUNC(_src, _dst) ( uint64_t(_src)|( uint64_t(_dst)<<4) )
- #define BGFX_STATE_BLEND_ADD (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) )
- #define BGFX_STATE_BLEND_ALPHA (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_COLOR) )
- #define BGFX_STATE_BLEND_DARKEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) | BGFX_STATE_BLEND_EQUATION_MIN)
- #define BGFX_STATE_BLEND_LIGHTEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE ) | BGFX_STATE_BLEND_EQUATION_MAX)
- #define BGFX_STATE_BLEND_MULTIPLY (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO ) )
- #define BGFX_STATE_BLEND_NORMAL (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA) )
- #define BGFX_STATE_BLEND_SCREEN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR) )
- #define BGFX_STATE_BLEND_LINEAR_BURN (BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_DST_COLOR) | BGFX_STATE_BLEND_EQUATION_SUB)
- ///
- #define BGFX_STENCIL_FUNC_REF_SHIFT 0
- #define BGFX_STENCIL_FUNC_REF_MASK UINT32_C(0x000000ff)
- #define BGFX_STENCIL_FUNC_RMASK_SHIFT 8
- #define BGFX_STENCIL_FUNC_RMASK_MASK UINT32_C(0x0000ff00)
- #define BGFX_STENCIL_TEST_LESS UINT32_C(0x00010000)
- #define BGFX_STENCIL_TEST_LEQUAL UINT32_C(0x00020000)
- #define BGFX_STENCIL_TEST_EQUAL UINT32_C(0x00030000)
- #define BGFX_STENCIL_TEST_GEQUAL UINT32_C(0x00040000)
- #define BGFX_STENCIL_TEST_GREATER UINT32_C(0x00050000)
- #define BGFX_STENCIL_TEST_NOTEQUAL UINT32_C(0x00060000)
- #define BGFX_STENCIL_TEST_NEVER UINT32_C(0x00070000)
- #define BGFX_STENCIL_TEST_ALWAYS UINT32_C(0x00080000)
- #define BGFX_STENCIL_TEST_SHIFT 16
- #define BGFX_STENCIL_TEST_MASK UINT32_C(0x000f0000)
- #define BGFX_STENCIL_OP_FAIL_S_ZERO UINT32_C(0x00000000)
- #define BGFX_STENCIL_OP_FAIL_S_KEEP UINT32_C(0x00100000)
- #define BGFX_STENCIL_OP_FAIL_S_REPLACE UINT32_C(0x00200000)
- #define BGFX_STENCIL_OP_FAIL_S_INCR UINT32_C(0x00300000)
- #define BGFX_STENCIL_OP_FAIL_S_INCRSAT UINT32_C(0x00400000)
- #define BGFX_STENCIL_OP_FAIL_S_DECR UINT32_C(0x00500000)
- #define BGFX_STENCIL_OP_FAIL_S_DECRSAT UINT32_C(0x00600000)
- #define BGFX_STENCIL_OP_FAIL_S_INVERT UINT32_C(0x00700000)
- #define BGFX_STENCIL_OP_FAIL_S_SHIFT 20
- #define BGFX_STENCIL_OP_FAIL_S_MASK UINT32_C(0x00f00000)
- #define BGFX_STENCIL_OP_FAIL_Z_ZERO UINT32_C(0x00000000)
- #define BGFX_STENCIL_OP_FAIL_Z_KEEP UINT32_C(0x01000000)
- #define BGFX_STENCIL_OP_FAIL_Z_REPLACE UINT32_C(0x02000000)
- #define BGFX_STENCIL_OP_FAIL_Z_INCR UINT32_C(0x03000000)
- #define BGFX_STENCIL_OP_FAIL_Z_INCRSAT UINT32_C(0x04000000)
- #define BGFX_STENCIL_OP_FAIL_Z_DECR UINT32_C(0x05000000)
- #define BGFX_STENCIL_OP_FAIL_Z_DECRSAT UINT32_C(0x06000000)
- #define BGFX_STENCIL_OP_FAIL_Z_INVERT UINT32_C(0x07000000)
- #define BGFX_STENCIL_OP_FAIL_Z_SHIFT 24
- #define BGFX_STENCIL_OP_FAIL_Z_MASK UINT32_C(0x0f000000)
- #define BGFX_STENCIL_OP_PASS_Z_ZERO UINT32_C(0x00000000)
- #define BGFX_STENCIL_OP_PASS_Z_KEEP UINT32_C(0x10000000)
- #define BGFX_STENCIL_OP_PASS_Z_REPLACE UINT32_C(0x20000000)
- #define BGFX_STENCIL_OP_PASS_Z_INCR UINT32_C(0x30000000)
- #define BGFX_STENCIL_OP_PASS_Z_INCRSAT UINT32_C(0x40000000)
- #define BGFX_STENCIL_OP_PASS_Z_DECR UINT32_C(0x50000000)
- #define BGFX_STENCIL_OP_PASS_Z_DECRSAT UINT32_C(0x60000000)
- #define BGFX_STENCIL_OP_PASS_Z_INVERT UINT32_C(0x70000000)
- #define BGFX_STENCIL_OP_PASS_Z_SHIFT 28
- #define BGFX_STENCIL_OP_PASS_Z_MASK UINT32_C(0xf0000000)
- #define BGFX_STENCIL_NONE UINT32_C(0x00000000)
- #define BGFX_STENCIL_MASK UINT32_C(0xffffffff)
- #define BGFX_STENCIL_DEFAULT UINT32_C(0x00000000)
- #define BGFX_STENCIL_FUNC_REF(_ref) ( (uint32_t(_ref)<<BGFX_STENCIL_FUNC_REF_SHIFT)&BGFX_STENCIL_FUNC_REF_MASK)
- #define BGFX_STENCIL_FUNC_RMASK(_mask) ( (uint32_t(_mask)<<BGFX_STENCIL_FUNC_RMASK_SHIFT)&BGFX_STENCIL_FUNC_RMASK_MASK)
- ///
- #define BGFX_CLEAR_NONE UINT8_C(0x00)
- #define BGFX_CLEAR_COLOR_BIT UINT8_C(0x01)
- #define BGFX_CLEAR_DEPTH_BIT UINT8_C(0x02)
- #define BGFX_CLEAR_STENCIL_BIT UINT8_C(0x04)
- ///
- #define BGFX_DEBUG_NONE UINT32_C(0x00000000)
- #define BGFX_DEBUG_WIREFRAME UINT32_C(0x00000001)
- #define BGFX_DEBUG_IFH UINT32_C(0x00000002)
- #define BGFX_DEBUG_STATS UINT32_C(0x00000004)
- #define BGFX_DEBUG_TEXT UINT32_C(0x00000008)
- ///
- #define BGFX_TEXTURE_NONE UINT32_C(0x00000000)
- #define BGFX_TEXTURE_U_MIRROR UINT32_C(0x00000001)
- #define BGFX_TEXTURE_U_CLAMP UINT32_C(0x00000002)
- #define BGFX_TEXTURE_U_SHIFT 0
- #define BGFX_TEXTURE_U_MASK UINT32_C(0x00000003)
- #define BGFX_TEXTURE_V_MIRROR UINT32_C(0x00000004)
- #define BGFX_TEXTURE_V_CLAMP UINT32_C(0x00000008)
- #define BGFX_TEXTURE_V_SHIFT 2
- #define BGFX_TEXTURE_V_MASK UINT32_C(0x0000000c)
- #define BGFX_TEXTURE_W_MIRROR UINT32_C(0x00000010)
- #define BGFX_TEXTURE_W_CLAMP UINT32_C(0x00000020)
- #define BGFX_TEXTURE_W_SHIFT 4
- #define BGFX_TEXTURE_W_MASK UINT32_C(0x00000030)
- #define BGFX_TEXTURE_MIN_POINT UINT32_C(0x00000040)
- #define BGFX_TEXTURE_MIN_ANISOTROPIC UINT32_C(0x00000080)
- #define BGFX_TEXTURE_MIN_SHIFT 6
- #define BGFX_TEXTURE_MIN_MASK UINT32_C(0x000000c0)
- #define BGFX_TEXTURE_MAG_POINT UINT32_C(0x00000100)
- #define BGFX_TEXTURE_MAG_ANISOTROPIC UINT32_C(0x00000200)
- #define BGFX_TEXTURE_MAG_SHIFT 8
- #define BGFX_TEXTURE_MAG_MASK UINT32_C(0x00000300)
- #define BGFX_TEXTURE_MIP_POINT UINT32_C(0x00000400)
- #define BGFX_TEXTURE_MIP_SHIFT 10
- #define BGFX_TEXTURE_MIP_MASK UINT32_C(0x00000400)
- #define BGFX_TEXTURE_RT UINT32_C(0x00001000)
- #define BGFX_TEXTURE_RT_MSAA_X2 UINT32_C(0x00002000)
- #define BGFX_TEXTURE_RT_MSAA_X4 UINT32_C(0x00003000)
- #define BGFX_TEXTURE_RT_MSAA_X8 UINT32_C(0x00004000)
- #define BGFX_TEXTURE_RT_MSAA_X16 UINT32_C(0x00005000)
- #define BGFX_TEXTURE_RT_MSAA_SHIFT 12
- #define BGFX_TEXTURE_RT_MSAA_MASK UINT32_C(0x00007000)
- #define BGFX_TEXTURE_RT_BUFFER_ONLY UINT32_C(0x00008000)
- #define BGFX_TEXTURE_RT_MASK UINT32_C(0x0000f000)
- #define BGFX_TEXTURE_COMPARE_LESS UINT32_C(0x00010000)
- #define BGFX_TEXTURE_COMPARE_LEQUAL UINT32_C(0x00020000)
- #define BGFX_TEXTURE_COMPARE_EQUAL UINT32_C(0x00030000)
- #define BGFX_TEXTURE_COMPARE_GEQUAL UINT32_C(0x00040000)
- #define BGFX_TEXTURE_COMPARE_GREATER UINT32_C(0x00050000)
- #define BGFX_TEXTURE_COMPARE_NOTEQUAL UINT32_C(0x00060000)
- #define BGFX_TEXTURE_COMPARE_NEVER UINT32_C(0x00070000)
- #define BGFX_TEXTURE_COMPARE_ALWAYS UINT32_C(0x00080000)
- #define BGFX_TEXTURE_COMPARE_SHIFT 16
- #define BGFX_TEXTURE_COMPARE_MASK UINT32_C(0x000f0000)
- #define BGFX_TEXTURE_RESERVED_SHIFT 24
- #define BGFX_TEXTURE_RESERVED_MASK UINT32_C(0xff000000)
- ///
- #define BGFX_RESET_NONE UINT32_C(0x00000000)
- #define BGFX_RESET_FULLSCREEN UINT32_C(0x00000001)
- #define BGFX_RESET_FULLSCREEN_SHIFT 0
- #define BGFX_RESET_FULLSCREEN_MASK UINT32_C(0x00000001)
- #define BGFX_RESET_MSAA_X2 UINT32_C(0x00000010)
- #define BGFX_RESET_MSAA_X4 UINT32_C(0x00000020)
- #define BGFX_RESET_MSAA_X8 UINT32_C(0x00000030)
- #define BGFX_RESET_MSAA_X16 UINT32_C(0x00000040)
- #define BGFX_RESET_MSAA_SHIFT 4
- #define BGFX_RESET_MSAA_MASK UINT32_C(0x00000070)
- #define BGFX_RESET_VSYNC UINT32_C(0x00000080)
- #define BGFX_RESET_CAPTURE UINT32_C(0x00000100)
- ///
- #define BGFX_CAPS_TEXTURE_FORMAT_BC1 UINT64_C(0x0000000000000001)
- #define BGFX_CAPS_TEXTURE_FORMAT_BC2 UINT64_C(0x0000000000000002)
- #define BGFX_CAPS_TEXTURE_FORMAT_BC3 UINT64_C(0x0000000000000004)
- #define BGFX_CAPS_TEXTURE_FORMAT_BC4 UINT64_C(0x0000000000000008)
- #define BGFX_CAPS_TEXTURE_FORMAT_BC5 UINT64_C(0x0000000000000010)
- #define BGFX_CAPS_TEXTURE_FORMAT_ETC1 UINT64_C(0x0000000000000020)
- #define BGFX_CAPS_TEXTURE_FORMAT_ETC2 UINT64_C(0x0000000000000040)
- #define BGFX_CAPS_TEXTURE_FORMAT_ETC2A UINT64_C(0x0000000000000080)
- #define BGFX_CAPS_TEXTURE_FORMAT_ETC2A1 UINT64_C(0x0000000000000100)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC12 UINT64_C(0x0000000000000200)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC14 UINT64_C(0x0000000000000400)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC14A UINT64_C(0x0000000000000800)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC12A UINT64_C(0x0000000000001000)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC22 UINT64_C(0x0000000000002000)
- #define BGFX_CAPS_TEXTURE_FORMAT_PTC24 UINT64_C(0x0000000000004000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D16 UINT64_C(0x0000000000008000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D24 UINT64_C(0x0000000000010000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D24S8 UINT64_C(0x0000000000020000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D32 UINT64_C(0x0000000000040000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D16F UINT64_C(0x0000000000080000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D24F UINT64_C(0x0000000000100000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D32F UINT64_C(0x0000000000200000)
- #define BGFX_CAPS_TEXTURE_FORMAT_D0S8 UINT64_C(0x0000000000400000)
- #define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000001000000)
- #define BGFX_CAPS_TEXTURE_COMPARE_ALL UINT64_C(0x0000000003000000)
- #define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000004000000)
- #define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000008000000)
- #define BGFX_CAPS_INSTANCING UINT64_C(0x0000000010000000)
- #define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000020000000)
- #define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000040000000)
- #define BGFX_CAPS_TEXTURE_DEPTH_MASK (0 \
- | BGFX_CAPS_TEXTURE_FORMAT_D16 \
- | BGFX_CAPS_TEXTURE_FORMAT_D24 \
- | BGFX_CAPS_TEXTURE_FORMAT_D24S8 \
- | BGFX_CAPS_TEXTURE_FORMAT_D32 \
- | BGFX_CAPS_TEXTURE_FORMAT_D16F \
- | BGFX_CAPS_TEXTURE_FORMAT_D24F \
- | BGFX_CAPS_TEXTURE_FORMAT_D32F \
- | BGFX_CAPS_TEXTURE_FORMAT_D0S8 \
- )
- ///
- #define BGFX_HANDLE(_name) \
- struct _name { uint16_t idx; }; \
- inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; }
- #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
- namespace bx { struct ReallocatorI; }
- /// BGFX
- namespace bgfx
- {
- struct Fatal
- {
- enum Enum
- {
- DebugCheck,
- MinimumRequiredSpecs,
- InvalidShader,
- UnableToInitialize,
- UnableToCreateTexture,
- };
- };
- struct RendererType
- {
- enum Enum
- {
- Null,
- Direct3D9,
- Direct3D11,
- OpenGLES2,
- OpenGLES3,
- OpenGL,
- Count
- };
- };
- struct Attrib
- {
- enum Enum // corresponds to vertex shader attribute:
- {
- Position, // a_position
- Normal, // a_normal
- Tangent, // a_tangent
- Color0, // a_color0
- Color1, // a_color1
- Indices, // a_indices
- Weight, // a_weight
- TexCoord0, // a_texcoord0
- TexCoord1, // a_texcoord1
- TexCoord2, // a_texcoord2
- TexCoord3, // a_texcoord3
- TexCoord4, // a_texcoord4
- TexCoord5, // a_texcoord5
- TexCoord6, // a_texcoord6
- TexCoord7, // a_texcoord7
- Count
- };
- };
- struct AttribType
- {
- enum Enum
- {
- Uint8,
- Int16,
- Half, // Availability depends on: BGFX_CAPS_VERTEX_ATTRIB_HALF.
- Float,
- Count
- };
- };
- struct TextureFormat
- {
- // Availability depends on BGFX_CAPS_TEXTURE_FORMAT_*.
- enum Enum
- {
- BC1, // DXT1
- BC2, // DXT3
- BC3, // DXT5
- BC4, // LATC1/ATI1
- BC5, // LATC2/ATI2
- ETC1, // ETC1 RGB8
- ETC2, // ETC2 RGB8
- ETC2A, // ETC2 RGBA8
- ETC2A1, // ETC2 RGB8A1
- PTC12, // PVRTC1 RGB 2BPP
- PTC14, // PVRTC1 RGB 4BPP
- PTC12A, // PVRTC1 RGBA 2BPP
- PTC14A, // PVRTC1 RGBA 4BPP
- PTC22, // PVRTC2 RGBA 2BPP
- PTC24, // PVRTC2 RGBA 4BPP
- Unknown, // compressed formats above
- L8,
- BGRA8,
- RGBA16,
- RGBA16F,
- R5G6B5,
- RGBA4,
- RGB5A1,
- RGB10A2,
- UnknownDepth, // depth formats below
- D16,
- D24,
- D24S8,
- D32,
- D16F,
- D24F,
- D32F,
- D0S8,
-
- Count
- };
- };
- struct UniformType
- {
- enum Enum
- {
- Uniform1i,
- Uniform1f,
- End,
- Uniform1iv,
- Uniform1fv,
- Uniform2fv,
- Uniform3fv,
- Uniform4fv,
- Uniform3x3fv,
- Uniform4x4fv,
- Count
- };
- };
- static const uint16_t invalidHandle = UINT16_MAX;
- BGFX_HANDLE(DynamicIndexBufferHandle);
- BGFX_HANDLE(DynamicVertexBufferHandle);
- BGFX_HANDLE(FragmentShaderHandle);
- BGFX_HANDLE(IndexBufferHandle);
- BGFX_HANDLE(ProgramHandle);
- BGFX_HANDLE(FrameBufferHandle);
- BGFX_HANDLE(TextureHandle);
- BGFX_HANDLE(UniformHandle);
- BGFX_HANDLE(VertexBufferHandle);
- BGFX_HANDLE(VertexDeclHandle);
- BGFX_HANDLE(VertexShaderHandle);
- /// Callback interface to implement application specific behavior.
- /// Cached items are currently used only for OpenGL binary shaders.
- ///
- /// NOTE:
- /// 'fatal' callback can be called from any thread. Other callbacks
- /// are called from the render thread.
- ///
- struct CallbackI
- {
- virtual ~CallbackI() = 0;
- /// If fatal code code is not Fatal::DebugCheck this callback is
- /// called on unrecoverable error. It's not safe to continue, inform
- /// user and terminate application from this call.
- virtual void fatal(Fatal::Enum _code, const char* _str) = 0;
- /// Return size of for cached item. Return 0 if no cached item was
- /// found.
- virtual uint32_t cacheReadSize(uint64_t _id) = 0;
- /// Read cached item.
- virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) = 0;
- /// Write cached item.
- virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) = 0;
- /// Screenshot captured. Screenshot format is always 4-byte BGRA.
- virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) = 0;
- /// Called when capture begins.
- virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx::TextureFormat::Enum _format, bool _yflip) = 0;
- /// Called when capture ends.
- virtual void captureEnd() = 0;
- /// Captured frame.
- virtual void captureFrame(const void* _data, uint32_t _size) = 0;
- };
- inline CallbackI::~CallbackI()
- {
- }
- struct Memory
- {
- uint8_t* data;
- uint32_t size;
- };
- /// Renderer capabilities.
- struct Caps
- {
- /// Renderer backend type.
- RendererType::Enum rendererType;
- /// Supported functionality, it includes emulated functionality.
- /// Checking supported and not emulated will give functionality
- /// natively supported by renderer.
- uint64_t supported;
- /// Emulated functionality. For example some texture compression
- /// modes are not natively supported by all renderers. The library
- /// internally decompresses texture into supported format.
- uint64_t emulated;
- uint16_t maxTextureSize; ///< Maximum texture size.
- uint16_t maxDrawCalls; ///< Maximum draw calls.
- uint8_t maxFBAttachments; ///< Maximum frame buffer attachments.
- };
- struct TransientIndexBuffer
- {
- uint8_t* data;
- uint32_t size;
- IndexBufferHandle handle;
- uint32_t startIndex;
- };
- struct TransientVertexBuffer
- {
- uint8_t* data;
- uint32_t size;
- uint32_t startVertex;
- uint16_t stride;
- VertexBufferHandle handle;
- VertexDeclHandle decl;
- };
- struct InstanceDataBuffer
- {
- uint8_t* data;
- uint32_t size;
- uint32_t offset;
- uint16_t stride;
- uint16_t num;
- VertexBufferHandle handle;
- };
- struct TextureInfo
- {
- TextureFormat::Enum format;
- uint32_t storageSize;
- uint16_t width;
- uint16_t height;
- uint16_t depth;
- uint8_t numMips;
- uint8_t bitsPerPixel;
- };
- /// Vertex declaration.
- struct VertexDecl
- {
- /// Start VertexDecl.
- void begin(RendererType::Enum _renderer = RendererType::Null);
- /// End VertexDecl.
- void end();
- /// Add attribute to VertexDecl.
- ///
- /// @param _attrib Attribute semantics.
- /// @param _num Number of elements 1, 2, 3 or 4.
- /// @param _type Element type.
- /// @param _normalized When using fixed point AttribType (f.e. Uint8)
- /// value will be normalized for vertex shader usage. When normalized
- /// is set to true, AttribType::Uint8 value in range 0-255 will be
- /// in range 0.0-1.0 in vertex shader.
- /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
- /// vertexConvert for AttribType::Uint8 and AttribType::Int16.
- /// Unpacking code must be implemented inside vertex shader.
- ///
- /// NOTE:
- /// Must be called between begin/end.
- ///
- void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
- /// Skip _num bytes in vertex stream.
- void skip(uint8_t _num);
- /// Decode attribute.
- void decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const;
- /// Returns true if VertexDecl contains attribute.
- bool has(Attrib::Enum _attrib) const { return 0xff != m_attributes[_attrib]; }
- /// Returns relative attribute offset from the vertex.
- uint16_t getOffset(Attrib::Enum _attrib) const { return m_offset[_attrib]; }
- /// Returns vertex stride.
- uint16_t getStride() const { return m_stride; }
- /// Returns size of vertex buffer for number of vertices.
- uint32_t getSize(uint32_t _num) const { return _num*m_stride; }
- uint32_t m_hash;
- uint16_t m_stride;
- uint16_t m_offset[Attrib::Count];
- uint8_t m_attributes[Attrib::Count];
- };
- /// Pack vec4 into vertex stream format.
- void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index = 0);
- /// Unpack vec4 from vertex stream format.
- void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index = 0);
- /// Converts vertex stream data from one vertex stream format to another.
- ///
- /// @param _destDecl Destination vertex stream declaration.
- /// @param _destData Destination vertex stream.
- /// @param _srcDecl Source vertex stream declaration.
- /// @param _srcData Source vertex stream data.
- /// @param _num Number of vertices to convert from source to destination.
- ///
- void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num = 1);
- /// Weld vertices.
- ///
- /// @param _output Welded vertices remapping table. The size of buffer
- /// must be the same as number of vertices.
- /// @param _decl Vertex stream declaration.
- /// @param _data Vertex stream.
- /// @param _num Number of vertices in vertex stream.
- /// @param _epsilon Error tolerance for vertex position comparison.
- /// @returns Number of unique vertices after vertex welding.
- ///
- uint16_t weldVertices(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon = 0.001f);
- /// Swizzle RGBA8 image to BGRA8.
- ///
- /// @param _width Width of input image (pixels).
- /// @param _height Height of input image (pixels).
- /// @param _pitch Pitch of input image (bytes).
- /// @param _src Source image.
- /// @param _dst Destination image. Must be the same size as input image.
- /// _dst might be pointer to the same memory as _src.
- ///
- void imageSwizzleBgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
- /// Downsample RGBA8 image with 2x2 pixel average filter.
- ///
- /// @param _width Width of input image (pixels).
- /// @param _height Height of input image (pixels).
- /// @param _pitch Pitch of input image (bytes).
- /// @param _src Source image.
- /// @param _dst Destination image. Must be at least quarter size of
- /// input image. _dst might be pointer to the same memory as _src.
- ///
- void imageRgba8Downsample2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
- /// Returns renderer backend API type.
- RendererType::Enum getRendererType();
- /// Initialize bgfx library.
- ///
- /// @param _callback Provide application specific callback interface.
- /// See: CallbackI
- ///
- /// @param _reallocator Custom allocator. When custom allocator is not
- /// specified, library uses default CRT allocator. The library assumes
- /// custom allocator is thread safe.
- ///
- void init(CallbackI* _callback = NULL, bx::ReallocatorI* _reallocator = NULL);
- /// Shutdown bgfx library.
- void shutdown();
- /// Reset graphic settings.
- void reset(uint32_t _width, uint32_t _height, uint32_t _flags = BGFX_RESET_NONE);
- /// Advance to next frame. When using multithreaded renderer, this call
- /// just swaps internal buffers, kicks render thread, and returns. In
- /// singlethreaded renderer this call does frame rendering.
- ///
- /// @returns Current frame number. This might be used in conjunction with
- /// double/multi buffering data outside the library and passing it to
- /// library via makeRef calls.
- ///
- uint32_t frame();
- /// Returns renderer capabilities.
- const Caps* getCaps();
- /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx.
- const Memory* alloc(uint32_t _size);
- /// Make reference to data to pass to bgfx. Unlike bgfx::alloc this call
- /// doesn't allocate memory for data. It just copies pointer to data.
- /// You must make sure data is available for at least 2 bgfx::frame calls.
- const Memory* makeRef(const void* _data, uint32_t _size);
- /// Set debug flags.
- ///
- /// @param _debug Available flags:
- ///
- /// BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set
- /// all rendering calls will be skipped. It's useful when profiling
- /// to quickly assess bottleneck between CPU and GPU.
- ///
- /// BGFX_DEBUG_STATS - Display internal statistics.
- ///
- /// BGFX_DEBUG_TEXT - Display debug text.
- ///
- /// BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering
- /// primitives will be rendered as lines.
- ///
- void setDebug(uint32_t _debug);
- /// Clear internal debug text buffer.
- void dbgTextClear(uint8_t _attr = 0, bool _small = false);
- /// Print into internal debug text buffer.
- void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
- /// Create static index buffer.
- IndexBufferHandle createIndexBuffer(const Memory* _mem);
- /// Destroy static index buffer.
- void destroyIndexBuffer(IndexBufferHandle _handle);
- /// Create static vertex buffer.
- ///
- /// @param _mem Vertex buffer data.
- /// @param _decl Vertex declaration.
- /// @returns Static vertex buffer handle.
- ///
- VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
- /// Destroy static vertex buffer.
- ///
- /// @param _handle Static vertex buffer handle.
- ///
- void destroyVertexBuffer(VertexBufferHandle _handle);
- /// Create empty dynamic index buffer.
- ///
- /// @param _num Number of indices.
- ///
- DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num);
- /// Create dynamic index buffer and initialized it.
- ///
- /// @param _mem Index buffer data.
- ///
- DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem);
- /// Update dynamic index buffer.
- ///
- /// @param _handle Dynamic index buffer handle.
- /// @param _mem Index buffer data.
- ///
- void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
- /// Destroy dynamic index buffer.
- ///
- /// @param _handle Dynamic index buffer handle.
- ///
- void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle);
- /// Create empty dynamic vertex buffer.
- ///
- /// @param _num Number of vertices.
- /// @param _decl Vertex declaration.
- ///
- DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl);
- /// Create dynamic vertex buffer and initialize it.
- ///
- /// @param _mem Vertex buffer data.
- /// @param _decl Vertex declaration.
- ///
- DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl);
- /// Update dynamic vertex buffer.
- void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
- /// Destroy dynamic vertex buffer.
- void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle);
- /// Returns true if internal transient index buffer has enough space.
- ///
- /// @param _num Number of indices.
- ///
- bool checkAvailTransientIndexBuffer(uint32_t _num);
- /// Returns true if internal transient vertex buffer has enough space.
- ///
- /// @param _num Number of vertices.
- /// @param _decl Vertex declaration.
- ///
- bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl);
- /// Returns true if internal instance data buffer has enough space.
- ///
- /// @param _num Number of instances.
- /// @param _stride Stride per instance.
- ///
- bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride);
- /// Returns true if both internal transient index and vertex buffer have
- /// enough space.
- ///
- /// @param _numVertices Number of vertices.
- /// @param _decl Vertex declaration.
- /// @param _numIndices Number of indices.
- ///
- bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices);
- /// Allocate transient index buffer.
- ///
- /// @param[out] _tib TransientIndexBuffer structure is filled and is valid
- /// for the duration of frame, and it can be reused for multiple draw
- /// calls.
- /// @param _num Number of indices to allocate.
- ///
- /// NOTE:
- /// You must call setIndexBuffer after alloc in order to avoid memory
- /// leak.
- ///
- void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num);
- /// Allocate transient vertex buffer.
- ///
- /// @param[out] _tvb TransientVertexBuffer structure is filled and is valid
- /// for the duration of frame, and it can be reused for multiple draw
- /// calls.
- /// @param _num Number of vertices to allocate.
- /// @param _decl Vertex declaration.
- ///
- /// NOTE:
- /// You must call setVertexBuffer after alloc in order to avoid memory
- /// leak.
- ///
- void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl);
- /// Allocate instance data buffer.
- ///
- /// NOTE:
- /// You must call setInstanceDataBuffer after alloc in order to avoid
- /// memory leak.
- ///
- const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride);
- /// Create vertex shader from memory buffer.
- VertexShaderHandle createVertexShader(const Memory* _mem);
- /// Destroy vertex shader. Once program is created with vertex shader
- /// it is safe to destroy vertex shader.
- void destroyVertexShader(VertexShaderHandle _handle);
- /// Create fragment shader from memory buffer.
- FragmentShaderHandle createFragmentShader(const Memory* _mem);
- /// Destroy fragment shader. Once program is created with fragment shader
- /// it is safe to destroy fragment shader.
- void destroyFragmentShader(FragmentShaderHandle _handle);
- /// Create program with vertex and fragment shaders.
- ///
- /// @param _vsh Vertex shader.
- /// @param _fsh Fragment shader.
- /// @param _destroyShaders If true, shaders will be destroyed when
- /// program is destroyed.
- /// @returns Program handle if vertex shader output and fragment shader
- /// input are matching, otherwise returns invalid program handle.
- ///
- ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh, bool _destroyShaders = false);
- /// Destroy program.
- void destroyProgram(ProgramHandle _handle);
- /// Calculate amount of memory required for texture.
- void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
- /// Create texture from memory buffer.
- ///
- /// @param _mem DDS, KTX or PVR texture data.
- /// @param _flags Default texture sampling mode is linear, and wrap mode
- /// is repeat.
- ///
- /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
- /// mode.
- ///
- /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
- /// sampling.
- ///
- /// @param _skip Skip top level mips when parsing texture.
- /// @param _info Returns parsed DDS texture information.
- /// @returns Texture handle.
- ///
- TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, TextureInfo* _info = NULL);
- /// Create 2D texture.
- ///
- /// @param _width
- /// @param _height
- /// @param _numMips
- /// @param _format
- /// @param _flags
- /// @param _mem
- ///
- TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
- /// Create 3D texture.
- ///
- /// @param _width
- /// @param _height
- /// @param _depth
- /// @param _numMips
- /// @param _format
- /// @param _flags
- /// @param _mem
- ///
- 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);
- /// Create Cube texture.
- ///
- /// @param _size
- /// @param _numMips
- /// @param _format
- /// @param _flags
- /// @param _mem
- ///
- TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL);
- /// Update 2D texture.
- ///
- /// @param _handle
- /// @param _mip
- /// @param _x
- /// @param _y
- /// @param _width
- /// @param _height
- /// @param _mem
- /// @param _pitch Pitch of input image (bytes). When _pitch is set to
- /// UINT16_MAX, it will be calculated internally based on _width.
- ///
- 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);
- /// Update 3D texture.
- ///
- /// @param _handle
- /// @param _mip
- /// @param _x
- /// @param _y
- /// @param _z
- /// @param _width
- /// @param _height
- /// @param _depth
- /// @param _mem
- ///
- 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);
- /// Update Cube texture.
- ///
- /// @param _handle
- /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
- /// -Y, 4 is +Z, and 5 is -Z.
- ///
- /// +----------+
- /// |-z 2|
- /// | ^ +y |
- /// | | |
- /// | +---->+x |
- /// +----------+----------+----------+----------+
- /// |+y 1|+y 4|+y 0|+y 5|
- /// | ^ -x | ^ +z | ^ +x | ^ -z |
- /// | | | | | | | | |
- /// | +---->+z | +---->+x | +---->-z | +---->-x |
- /// +----------+----------+----------+----------+
- /// |+z 3|
- /// | ^ -y |
- /// | | |
- /// | +---->+x |
- /// +----------+
- ///
- /// @param _mip
- /// @param _x
- /// @param _y
- /// @param _width
- /// @param _height
- /// @param _mem
- /// @param _pitch Pitch of input image (bytes). When _pitch is set to
- /// UINT16_MAX, it will be calculated internally based on _width.
- ///
- 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);
- /// Destroy texture.
- void destroyTexture(TextureHandle _handle);
- /// Create frame buffer (simple).
- ///
- /// @param _width Texture width.
- /// @param _height Texture height.
- /// @param _format Texture format.
- /// @param _textureFlags Texture flags.
- ///
- FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
- /// Create frame buffer.
- ///
- /// @param _num Number of texture attachments.
- /// @param _handles Texture attachments.
- /// @param _destroyTextures If true, textures will be destroyed when
- /// frame buffer is destroyed.
- ///
- FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false);
- /// Destroy frame buffer.
- void destroyFrameBuffer(FrameBufferHandle _handle);
- /// Create shader uniform parameter.
- ///
- /// @param _name Uniform name in shader.
- /// @param _type Type of uniform (See: UniformType).
- /// @param _num Number of elements in array.
- ///
- /// Predefined uniforms:
- ///
- /// u_viewRect vec4(x, y, width, height) - view rectangle for current
- /// view.
- ///
- /// u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
- /// width and height
- ///
- /// u_view mat4 - view matrix
- ///
- /// u_viewProj mat4 - concatenated view projection matrix
- ///
- /// u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
- ///
- /// u_modelView mat4 - concatenated model view matrix, only first
- /// model matrix from array is used.
- ///
- /// u_modelViewProj mat4 - concatenated model view projection matrix.
- ///
- /// u_alphaRef float - alpha reference value for alpha test.
- ///
- UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);
- /// Destroy shader uniform parameter.
- void destroyUniform(UniformHandle _handle);
- /// Set view name.
- ///
- /// @param _id View id.
- /// @param _name View name.
- ///
- /// NOTE:
- /// This is debug only feature.
- ///
- void setViewName(uint8_t _id, const char* _name);
- /// Set view rectangle. Draw primitive outside view will be clipped.
- ///
- /// @param _id View id.
- /// @param _x Position x from the left corner of the window.
- /// @param _y Position y from the top corner of the window.
- /// @param _width Width of view port region.
- /// @param _height Height of view port region.
- ///
- void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
- /// Set view rectangle for multiple views.
- ///
- /// @param _viewMask Bit mask representing affected views.
- /// @param _x Position x from the left corner of the window.
- /// @param _y Position y from the top corner of the window.
- /// @param _width Width of view port region.
- /// @param _height Height of view port region.
- ///
- void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
- /// Set view scissor. Draw primitive outside view will be clipped. When
- /// _x, _y, _width and _height are set to 0, scissor will be disabled.
- ///
- /// @param _x Position x from the left corner of the window.
- /// @param _y Position y from the top corner of the window.
- /// @param _width Width of scissor region.
- /// @param _height Height of scissor region.
- ///
- void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
- /// Set view scissor for multiple views. When _x, _y, _width and _height
- /// are set to 0, scissor will be disabled.
- ///
- /// @param _id View id.
- /// @param _viewMask Bit mask representing affected views.
- /// @param _x Position x from the left corner of the window.
- /// @param _y Position y from the top corner of the window.
- /// @param _width Width of scissor region.
- /// @param _height Height of scissor region.
- ///
- void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0);
- /// Set view clear flags.
- ///
- /// @param _id View id.
- /// @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear
- /// operation. See: BGFX_CLEAR_*.
- /// @param _rgba Color clear value.
- /// @param _depth Depth clear value.
- /// @param _stencil Stencil clear value.
- ///
- void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
- /// Set view clear flags for multiple views.
- void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0);
- /// Set view into sequential mode. Draw calls will be sorted in the same
- /// order in which submit calls were called.
- void setViewSeq(uint8_t _id, bool _enabled);
- /// Set multiple views into sequential mode.
- void setViewSeqMask(uint32_t _viewMask, bool _enabled);
- /// Set view frame buffer.
- ///
- /// @param _id View id.
- /// @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as
- /// frame buffer handle will draw primitives from this view into
- /// default back buffer.
- ///
- void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle);
- /// Set view frame buffer for multiple views.
- ///
- /// @param _viewMask View mask.
- /// @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as
- /// frame buffer handle will draw primitives from this view into
- /// default back buffer.
- ///
- void setViewFrameBufferMask(uint32_t _viewMask, FrameBufferHandle _handle);
- /// Set view view and projection matrices, all draw primitives in this
- /// view will use these matrices.
- void setViewTransform(uint8_t _id, const void* _view, const void* _proj, uint8_t _other = 0xff);
- /// Set view view and projection matrices for multiple views.
- void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj, uint8_t _other = 0xff);
- /// Sets debug marker.
- void setMarker(const char* _marker);
- /// Set render states for draw primitive.
- ///
- /// @param _state State flags. Default state for primitive type is
- /// triangles. See: BGFX_STATE_DEFAULT.
- ///
- /// BGFX_STATE_ALPHA_WRITE - Enable alpha write.
- /// BGFX_STATE_DEPTH_WRITE - Enable depth write.
- /// BGFX_STATE_DEPTH_TEST_* - Depth test function.
- /// BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC.
- /// BGFX_STATE_BLEND_EQUATION_* - See NOTE 2.
- /// BGFX_STATE_CULL_* - Backface culling mode.
- /// BGFX_STATE_RGB_WRITE - Enable RGB write.
- /// BGFX_STATE_MSAA - Enable MSAA.
- /// BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
- ///
- /// @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
- /// BGFX_STATE_BLEND_INV_FACTOR blend modes.
- ///
- /// NOTE:
- /// 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and
- /// BGFX_STATE_BLEND_FUNC macros to setup more complex states.
- /// 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend
- /// equation is specified.
- ///
- void setState(uint64_t _state, uint32_t _rgba = UINT32_MAX);
- /// Set stencil test state.
- ///
- /// @param _fstencil Front stencil state.
- /// @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE
- /// _fstencil is applied to both front and back facing primitives.
- ///
- void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE);
- /// Set scissor for draw primitive. For scissor for all primitives in
- /// view see setViewScissor.
- ///
- /// @param _x Position x from the left corner of the window.
- /// @param _y Position y from the top corner of the window.
- /// @param _width Width of scissor region.
- /// @param _height Height of scissor region.
- /// @returns Scissor cache index.
- ///
- uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
- /// Set scissor from cache for draw primitive.
- ///
- /// @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive
- /// scissor and primitive will use view scissor instead.
- ///
- void setScissor(uint16_t _cache = UINT16_MAX);
- /// Set model matrix for draw primitive. If it is not called model will
- /// be rendered with identity model matrix.
- ///
- /// @param _mtx Pointer to first matrix in array.
- /// @param _num Number of matrices in array.
- /// @returns index into matrix cache in case the same model matrix has
- /// to be used for other draw primitive call.
- ///
- uint32_t setTransform(const void* _mtx, uint16_t _num = 1);
- /// Set model matrix from matrix cache for draw primitive.
- ///
- /// @param _cache Index in matrix cache.
- /// @param _num Number of matrices from cache.
- ///
- void setTransform(uint32_t _cache, uint16_t _num = 1);
- /// Set shader uniform parameter for draw primitive.
- void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1);
- /// Set index buffer for draw primitive.
- void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
- /// Set index buffer for draw primitive.
- void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX);
- /// Set index buffer for draw primitive.
- void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _numIndices = UINT32_MAX);
- /// Set vertex buffer for draw primitive.
- void setVertexBuffer(VertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
- /// Set vertex buffer for draw primitive.
- void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX);
- /// Set vertex buffer for draw primitive.
- void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _numVertices = UINT32_MAX);
- /// Set instance data buffer for draw primitive.
- void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint16_t _num = UINT16_MAX);
- /// Set program for draw primitive.
- void setProgram(ProgramHandle _handle);
- /// Set texture stage for draw primitive.
- ///
- /// @param _stage Texture unit.
- /// @param _sampler Program sampler.
- /// @param _handle Texture handle.
- /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
- /// texture sampling settings from the texture.
- ///
- /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
- /// mode.
- ///
- /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
- /// sampling.
- ///
- /// @param _flags Texture sampler filtering flags. UINT32_MAX use the
- /// sampler filtering mode set by texture.
- ///
- void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX);
- /// Set texture stage for draw primitive.
- ///
- /// @param _stage Texture unit.
- /// @param _sampler Program sampler.
- /// @param _handle Frame buffer handle.
- /// @param _attachment Attachment index.
- /// @param _flags Texture sampling mode. Default value UINT32_MAX uses
- /// texture sampling settings from the texture.
- ///
- /// BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap
- /// mode.
- ///
- /// BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic
- /// sampling.
- ///
- void setTexture(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment = 0, uint32_t _flags = UINT32_MAX);
- /// Submit primitive for rendering into single view.
- ///
- /// @param _id View id.
- /// @param _depth Depth for sorting.
- /// @returns Number of draw calls.
- ///
- uint32_t submit(uint8_t _id, int32_t _depth = 0);
- /// Submit primitive for rendering into multiple views.
- ///
- /// @param _viewMask Mask to which views to submit draw primitive calls.
- /// @param _depth Depth for sorting.
- /// @returns Number of draw calls.
- ///
- uint32_t submitMask(uint32_t _viewMask, int32_t _depth = 0);
- /// Discard all previously set state for draw call.
- void discard();
- /// Request screen shot.
- ///
- /// @param _filePath Will be passed to CallbackI::screenShot callback.
- ///
- /// NOTE:
- /// CallbackI::screenShot must be implemented.
- ///
- void saveScreenShot(const char* _filePath);
- } // namespace bgfx
- #endif // BGFX_H_HEADER_GUARD
|