engine.d.ts 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138
  1. import type { Nullable } from "../types";
  2. import type { Scene } from "../scene";
  3. import { InternalTexture } from "../Materials/Textures/internalTexture";
  4. import type { IOfflineProvider } from "../Offline/IOfflineProvider";
  5. import type { ILoadingScreen } from "../Loading/loadingScreen";
  6. import type { WebGLPipelineContext } from "./WebGL/webGLPipelineContext";
  7. import type { IPipelineContext } from "./IPipelineContext";
  8. import type { ICustomAnimationFrameRequester } from "../Misc/customAnimationFrameRequester";
  9. import type { EngineOptions } from "./thinEngine";
  10. import { ThinEngine } from "./thinEngine";
  11. import type { IViewportLike, IColor4Like } from "../Maths/math.like";
  12. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  13. import { PerformanceMonitor } from "../Misc/performanceMonitor";
  14. import type { DataBuffer } from "../Buffers/dataBuffer";
  15. import type { RenderTargetWrapper } from "./renderTargetWrapper";
  16. import "./Extensions/engine.alpha";
  17. import "./Extensions/engine.readTexture";
  18. import "./Extensions/engine.dynamicBuffer";
  19. import "./AbstractEngine/abstractEngine.loadingScreen";
  20. import "./AbstractEngine/abstractEngine.dom";
  21. import "./AbstractEngine/abstractEngine.states";
  22. import "./AbstractEngine/abstractEngine.renderPass";
  23. import "./AbstractEngine/abstractEngine.texture";
  24. import type { Material } from "../Materials/material";
  25. import type { PostProcess } from "../PostProcesses/postProcess";
  26. import { AbstractEngine } from "./abstractEngine";
  27. import "../Audio/audioEngine";
  28. /**
  29. * The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio
  30. */
  31. export declare class Engine extends ThinEngine {
  32. /** Defines that alpha blending is disabled */
  33. static readonly ALPHA_DISABLE = 0;
  34. /** Defines that alpha blending to SRC ALPHA * SRC + DEST */
  35. static readonly ALPHA_ADD = 1;
  36. /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC ALPHA) * DEST */
  37. static readonly ALPHA_COMBINE = 2;
  38. /** Defines that alpha blending to DEST - SRC * DEST */
  39. static readonly ALPHA_SUBTRACT = 3;
  40. /** Defines that alpha blending to SRC * DEST */
  41. static readonly ALPHA_MULTIPLY = 4;
  42. /** Defines that alpha blending to SRC ALPHA * SRC + (1 - SRC) * DEST */
  43. static readonly ALPHA_MAXIMIZED = 5;
  44. /** Defines that alpha blending to SRC + DEST */
  45. static readonly ALPHA_ONEONE = 6;
  46. /** Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST */
  47. static readonly ALPHA_PREMULTIPLIED = 7;
  48. /**
  49. * Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST
  50. * Alpha will be set to (1 - SRC ALPHA) * DEST ALPHA
  51. */
  52. static readonly ALPHA_PREMULTIPLIED_PORTERDUFF = 8;
  53. /** Defines that alpha blending to CST * SRC + (1 - CST) * DEST */
  54. static readonly ALPHA_INTERPOLATE = 9;
  55. /**
  56. * Defines that alpha blending to SRC + (1 - SRC) * DEST
  57. * Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) * DEST ALPHA
  58. */
  59. static readonly ALPHA_SCREENMODE = 10;
  60. /** Defines that the resource is not delayed*/
  61. static readonly DELAYLOADSTATE_NONE = 0;
  62. /** Defines that the resource was successfully delay loaded */
  63. static readonly DELAYLOADSTATE_LOADED = 1;
  64. /** Defines that the resource is currently delay loading */
  65. static readonly DELAYLOADSTATE_LOADING = 2;
  66. /** Defines that the resource is delayed and has not started loading */
  67. static readonly DELAYLOADSTATE_NOTLOADED = 4;
  68. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn */
  69. static readonly NEVER = 512;
  70. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn */
  71. static readonly ALWAYS = 519;
  72. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value */
  73. static readonly LESS = 513;
  74. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value */
  75. static readonly EQUAL = 514;
  76. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value */
  77. static readonly LEQUAL = 515;
  78. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value */
  79. static readonly GREATER = 516;
  80. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value */
  81. static readonly GEQUAL = 518;
  82. /** Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value */
  83. static readonly NOTEQUAL = 517;
  84. /** Passed to stencilOperation to specify that stencil value must be kept */
  85. static readonly KEEP = 7680;
  86. /** Passed to stencilOperation to specify that stencil value must be replaced */
  87. static readonly REPLACE = 7681;
  88. /** Passed to stencilOperation to specify that stencil value must be incremented */
  89. static readonly INCR = 7682;
  90. /** Passed to stencilOperation to specify that stencil value must be decremented */
  91. static readonly DECR = 7683;
  92. /** Passed to stencilOperation to specify that stencil value must be inverted */
  93. static readonly INVERT = 5386;
  94. /** Passed to stencilOperation to specify that stencil value must be incremented with wrapping */
  95. static readonly INCR_WRAP = 34055;
  96. /** Passed to stencilOperation to specify that stencil value must be decremented with wrapping */
  97. static readonly DECR_WRAP = 34056;
  98. /** Texture is not repeating outside of 0..1 UVs */
  99. static readonly TEXTURE_CLAMP_ADDRESSMODE = 0;
  100. /** Texture is repeating outside of 0..1 UVs */
  101. static readonly TEXTURE_WRAP_ADDRESSMODE = 1;
  102. /** Texture is repeating and mirrored */
  103. static readonly TEXTURE_MIRROR_ADDRESSMODE = 2;
  104. /** ALPHA */
  105. static readonly TEXTUREFORMAT_ALPHA = 0;
  106. /** LUMINANCE */
  107. static readonly TEXTUREFORMAT_LUMINANCE = 1;
  108. /** LUMINANCE_ALPHA */
  109. static readonly TEXTUREFORMAT_LUMINANCE_ALPHA = 2;
  110. /** RGB */
  111. static readonly TEXTUREFORMAT_RGB = 4;
  112. /** RGBA */
  113. static readonly TEXTUREFORMAT_RGBA = 5;
  114. /** RED */
  115. static readonly TEXTUREFORMAT_RED = 6;
  116. /** RED (2nd reference) */
  117. static readonly TEXTUREFORMAT_R = 6;
  118. /** RG */
  119. static readonly TEXTUREFORMAT_RG = 7;
  120. /** RED_INTEGER */
  121. static readonly TEXTUREFORMAT_RED_INTEGER = 8;
  122. /** RED_INTEGER (2nd reference) */
  123. static readonly TEXTUREFORMAT_R_INTEGER = 8;
  124. /** RG_INTEGER */
  125. static readonly TEXTUREFORMAT_RG_INTEGER = 9;
  126. /** RGB_INTEGER */
  127. static readonly TEXTUREFORMAT_RGB_INTEGER = 10;
  128. /** RGBA_INTEGER */
  129. static readonly TEXTUREFORMAT_RGBA_INTEGER = 11;
  130. /** UNSIGNED_BYTE */
  131. static readonly TEXTURETYPE_UNSIGNED_BYTE = 0;
  132. /** UNSIGNED_BYTE (2nd reference) */
  133. static readonly TEXTURETYPE_UNSIGNED_INT = 0;
  134. /** FLOAT */
  135. static readonly TEXTURETYPE_FLOAT = 1;
  136. /** HALF_FLOAT */
  137. static readonly TEXTURETYPE_HALF_FLOAT = 2;
  138. /** BYTE */
  139. static readonly TEXTURETYPE_BYTE = 3;
  140. /** SHORT */
  141. static readonly TEXTURETYPE_SHORT = 4;
  142. /** UNSIGNED_SHORT */
  143. static readonly TEXTURETYPE_UNSIGNED_SHORT = 5;
  144. /** INT */
  145. static readonly TEXTURETYPE_INT = 6;
  146. /** UNSIGNED_INT */
  147. static readonly TEXTURETYPE_UNSIGNED_INTEGER = 7;
  148. /** UNSIGNED_SHORT_4_4_4_4 */
  149. static readonly TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 = 8;
  150. /** UNSIGNED_SHORT_5_5_5_1 */
  151. static readonly TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 = 9;
  152. /** UNSIGNED_SHORT_5_6_5 */
  153. static readonly TEXTURETYPE_UNSIGNED_SHORT_5_6_5 = 10;
  154. /** UNSIGNED_INT_2_10_10_10_REV */
  155. static readonly TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV = 11;
  156. /** UNSIGNED_INT_24_8 */
  157. static readonly TEXTURETYPE_UNSIGNED_INT_24_8 = 12;
  158. /** UNSIGNED_INT_10F_11F_11F_REV */
  159. static readonly TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV = 13;
  160. /** UNSIGNED_INT_5_9_9_9_REV */
  161. static readonly TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV = 14;
  162. /** FLOAT_32_UNSIGNED_INT_24_8_REV */
  163. static readonly TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV = 15;
  164. /** nearest is mag = nearest and min = nearest and mip = none */
  165. static readonly TEXTURE_NEAREST_SAMPLINGMODE = 1;
  166. /** Bilinear is mag = linear and min = linear and mip = nearest */
  167. static readonly TEXTURE_BILINEAR_SAMPLINGMODE = 2;
  168. /** Trilinear is mag = linear and min = linear and mip = linear */
  169. static readonly TEXTURE_TRILINEAR_SAMPLINGMODE = 3;
  170. /** nearest is mag = nearest and min = nearest and mip = linear */
  171. static readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR = 8;
  172. /** Bilinear is mag = linear and min = linear and mip = nearest */
  173. static readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST = 11;
  174. /** Trilinear is mag = linear and min = linear and mip = linear */
  175. static readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR = 3;
  176. /** mag = nearest and min = nearest and mip = nearest */
  177. static readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST = 4;
  178. /** mag = nearest and min = linear and mip = nearest */
  179. static readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST = 5;
  180. /** mag = nearest and min = linear and mip = linear */
  181. static readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR = 6;
  182. /** mag = nearest and min = linear and mip = none */
  183. static readonly TEXTURE_NEAREST_LINEAR = 7;
  184. /** mag = nearest and min = nearest and mip = none */
  185. static readonly TEXTURE_NEAREST_NEAREST = 1;
  186. /** mag = linear and min = nearest and mip = nearest */
  187. static readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST = 9;
  188. /** mag = linear and min = nearest and mip = linear */
  189. static readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR = 10;
  190. /** mag = linear and min = linear and mip = none */
  191. static readonly TEXTURE_LINEAR_LINEAR = 2;
  192. /** mag = linear and min = nearest and mip = none */
  193. static readonly TEXTURE_LINEAR_NEAREST = 12;
  194. /** Explicit coordinates mode */
  195. static readonly TEXTURE_EXPLICIT_MODE = 0;
  196. /** Spherical coordinates mode */
  197. static readonly TEXTURE_SPHERICAL_MODE = 1;
  198. /** Planar coordinates mode */
  199. static readonly TEXTURE_PLANAR_MODE = 2;
  200. /** Cubic coordinates mode */
  201. static readonly TEXTURE_CUBIC_MODE = 3;
  202. /** Projection coordinates mode */
  203. static readonly TEXTURE_PROJECTION_MODE = 4;
  204. /** Skybox coordinates mode */
  205. static readonly TEXTURE_SKYBOX_MODE = 5;
  206. /** Inverse Cubic coordinates mode */
  207. static readonly TEXTURE_INVCUBIC_MODE = 6;
  208. /** Equirectangular coordinates mode */
  209. static readonly TEXTURE_EQUIRECTANGULAR_MODE = 7;
  210. /** Equirectangular Fixed coordinates mode */
  211. static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MODE = 8;
  212. /** Equirectangular Fixed Mirrored coordinates mode */
  213. static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;
  214. /** Defines that texture rescaling will use a floor to find the closer power of 2 size */
  215. static readonly SCALEMODE_FLOOR = 1;
  216. /** Defines that texture rescaling will look for the nearest power of 2 size */
  217. static readonly SCALEMODE_NEAREST = 2;
  218. /** Defines that texture rescaling will use a ceil to find the closer power of 2 size */
  219. static readonly SCALEMODE_CEILING = 3;
  220. /**
  221. * Returns the current npm package of the sdk
  222. */
  223. static get NpmPackage(): string;
  224. /**
  225. * Returns the current version of the framework
  226. */
  227. static get Version(): string;
  228. /** Gets the list of created engines */
  229. static get Instances(): AbstractEngine[];
  230. /**
  231. * Gets the latest created engine
  232. */
  233. static get LastCreatedEngine(): Nullable<AbstractEngine>;
  234. /**
  235. * Gets the latest created scene
  236. */
  237. static get LastCreatedScene(): Nullable<Scene>;
  238. /** @internal */
  239. /**
  240. * Will flag all materials in all scenes in all engines as dirty to trigger new shader compilation
  241. * @param flag defines which part of the materials must be marked as dirty
  242. * @param predicate defines a predicate used to filter which materials should be affected
  243. */
  244. static MarkAllMaterialsAsDirty(flag: number, predicate?: (mat: Material) => boolean): void;
  245. /**
  246. * Method called to create the default loading screen.
  247. * This can be overridden in your own app.
  248. * @param canvas The rendering canvas element
  249. * @returns The loading screen
  250. */
  251. static DefaultLoadingScreenFactory(canvas: HTMLCanvasElement): ILoadingScreen;
  252. /**
  253. * If set, will be used to request the next animation frame for the render loop
  254. */
  255. customAnimationFrameRequester: Nullable<ICustomAnimationFrameRequester>;
  256. private _rescalePostProcess;
  257. protected get _supportsHardwareTextureRescaling(): boolean;
  258. private _measureFps;
  259. private _performanceMonitor;
  260. /**
  261. * Gets the performance monitor attached to this engine
  262. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
  263. */
  264. get performanceMonitor(): PerformanceMonitor;
  265. /**
  266. * Creates a new engine
  267. * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context
  268. * @param antialias defines enable antialiasing (default: false)
  269. * @param options defines further options to be sent to the getContext() function
  270. * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
  271. */
  272. constructor(canvasOrContext: Nullable<HTMLCanvasElement | OffscreenCanvas | WebGLRenderingContext | WebGL2RenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio?: boolean);
  273. protected _initGLContext(): void;
  274. /**
  275. * Shared initialization across engines types.
  276. * @param canvas The canvas associated with this instance of the engine.
  277. */
  278. protected _sharedInit(canvas: HTMLCanvasElement): void;
  279. /**
  280. * Resize an image and returns the image data as an uint8array
  281. * @param image image to resize
  282. * @param bufferWidth destination buffer width
  283. * @param bufferHeight destination buffer height
  284. * @returns an uint8array containing RGBA values of bufferWidth * bufferHeight size
  285. */
  286. resizeImageBitmap(image: HTMLImageElement | ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array;
  287. /**
  288. * Engine abstraction for loading and creating an image bitmap from a given source string.
  289. * @param imageSource source to load the image from.
  290. * @param options An object that sets options for the image's extraction.
  291. * @returns ImageBitmap
  292. */
  293. _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap>;
  294. /**
  295. * Toggle full screen mode
  296. * @param requestPointerLock defines if a pointer lock should be requested from the user
  297. */
  298. switchFullscreen(requestPointerLock: boolean): void;
  299. /**
  300. * Enters full screen mode
  301. * @param requestPointerLock defines if a pointer lock should be requested from the user
  302. */
  303. enterFullscreen(requestPointerLock: boolean): void;
  304. /**
  305. * Exits full screen mode
  306. */
  307. exitFullscreen(): void;
  308. generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
  309. /** States */
  310. /**
  311. * Sets a boolean indicating if the dithering state is enabled or disabled
  312. * @param value defines the dithering state
  313. */
  314. setDitheringState(value: boolean): void;
  315. /**
  316. * Sets a boolean indicating if the rasterizer state is enabled or disabled
  317. * @param value defines the rasterizer state
  318. */
  319. setRasterizerState(value: boolean): void;
  320. /**
  321. * Directly set the WebGL Viewport
  322. * @param x defines the x coordinate of the viewport (in screen space)
  323. * @param y defines the y coordinate of the viewport (in screen space)
  324. * @param width defines the width of the viewport (in screen space)
  325. * @param height defines the height of the viewport (in screen space)
  326. * @returns the current viewport Object (if any) that is being replaced by this call. You can restore this viewport later on to go back to the original state
  327. */
  328. setDirectViewport(x: number, y: number, width: number, height: number): Nullable<IViewportLike>;
  329. /**
  330. * Executes a scissor clear (ie. a clear on a specific portion of the screen)
  331. * @param x defines the x-coordinate of the bottom left corner of the clear rectangle
  332. * @param y defines the y-coordinate of the corner of the clear rectangle
  333. * @param width defines the width of the clear rectangle
  334. * @param height defines the height of the clear rectangle
  335. * @param clearColor defines the clear color
  336. */
  337. scissorClear(x: number, y: number, width: number, height: number, clearColor: IColor4Like): void;
  338. /**
  339. * Enable scissor test on a specific rectangle (ie. render will only be executed on a specific portion of the screen)
  340. * @param x defines the x-coordinate of the bottom left corner of the clear rectangle
  341. * @param y defines the y-coordinate of the corner of the clear rectangle
  342. * @param width defines the width of the clear rectangle
  343. * @param height defines the height of the clear rectangle
  344. */
  345. enableScissor(x: number, y: number, width: number, height: number): void;
  346. /**
  347. * Disable previously set scissor test rectangle
  348. */
  349. disableScissor(): void;
  350. /**
  351. * @internal
  352. */
  353. _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: false): Promise<string>;
  354. _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: true): Promise<ArrayBuffer>;
  355. /**
  356. * Gets the source code of the vertex shader associated with a specific webGL program
  357. * @param program defines the program to use
  358. * @returns a string containing the source code of the vertex shader associated with the program
  359. */
  360. getVertexShaderSource(program: WebGLProgram): Nullable<string>;
  361. /**
  362. * Gets the source code of the fragment shader associated with a specific webGL program
  363. * @param program defines the program to use
  364. * @returns a string containing the source code of the fragment shader associated with the program
  365. */
  366. getFragmentShaderSource(program: WebGLProgram): Nullable<string>;
  367. /**
  368. * Sets a depth stencil texture from a render target to the according uniform.
  369. * @param channel The texture channel
  370. * @param uniform The uniform to set
  371. * @param texture The render target texture containing the depth stencil texture to apply
  372. * @param name The texture name
  373. */
  374. setDepthStencilTexture(channel: number, uniform: Nullable<WebGLUniformLocation>, texture: Nullable<RenderTargetTexture>, name?: string): void;
  375. /**
  376. * Sets a texture to the context from a postprocess
  377. * @param channel defines the channel to use
  378. * @param postProcess defines the source postprocess
  379. * @param name name of the channel
  380. */
  381. setTextureFromPostProcess(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  382. /**
  383. * Binds the output of the passed in post process to the texture channel specified
  384. * @param channel The channel the texture should be bound to
  385. * @param postProcess The post process which's output should be bound
  386. * @param name name of the channel
  387. */
  388. setTextureFromPostProcessOutput(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  389. /**
  390. * sets the object from which width and height will be taken from when getting render width and height
  391. * Will fallback to the gl object
  392. * @param dimensions the framebuffer width and height that will be used.
  393. */
  394. set framebufferDimensionsObject(dimensions: Nullable<{
  395. framebufferWidth: number;
  396. framebufferHeight: number;
  397. }>);
  398. protected _rebuildBuffers(): void;
  399. /**
  400. * Get Font size information
  401. * @param font font name
  402. * @returns an object containing ascent, height and descent
  403. */
  404. getFontOffset(font: string): {
  405. ascent: number;
  406. height: number;
  407. descent: number;
  408. };
  409. /** @internal */
  410. _renderFrame(): void;
  411. protected _cancelFrame(): void;
  412. _renderLoop(): void;
  413. /** @internal */
  414. _renderViews(): boolean;
  415. /**
  416. * Enters Pointerlock mode
  417. */
  418. enterPointerlock(): void;
  419. /**
  420. * Exits Pointerlock mode
  421. */
  422. exitPointerlock(): void;
  423. /**
  424. * Begin a new frame
  425. */
  426. beginFrame(): void;
  427. /**
  428. * Force a specific size of the canvas
  429. * @param width defines the new canvas' width
  430. * @param height defines the new canvas' height
  431. * @param forceSetSize true to force setting the sizes of the underlying canvas
  432. * @returns true if the size was changed
  433. */
  434. setSize(width: number, height: number, forceSetSize?: boolean): boolean;
  435. _deletePipelineContext(pipelineContext: IPipelineContext): void;
  436. createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: Nullable<string>, context?: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram;
  437. protected _createShaderProgram(pipelineContext: WebGLPipelineContext, vertexShader: WebGLShader, fragmentShader: WebGLShader, context: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram;
  438. /**
  439. * @internal
  440. */
  441. _releaseTexture(texture: InternalTexture): void;
  442. /**
  443. * @internal
  444. */
  445. _releaseRenderTargetWrapper(rtWrapper: RenderTargetWrapper): void;
  446. /**
  447. * @internal
  448. * Rescales a texture
  449. * @param source input texture
  450. * @param destination destination texture
  451. * @param scene scene to use to render the resize
  452. * @param internalFormat format to use when resizing
  453. * @param onComplete callback to be called when resize has completed
  454. */
  455. _rescaleTexture(source: InternalTexture, destination: InternalTexture, scene: Nullable<any>, internalFormat: number, onComplete: () => void): void;
  456. /**
  457. * Wraps an external web gl texture in a Babylon texture.
  458. * @param texture defines the external texture
  459. * @param hasMipMaps defines whether the external texture has mip maps (default: false)
  460. * @param samplingMode defines the sampling mode for the external texture (default: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE)
  461. * @param width defines the width for the external texture (default: 0)
  462. * @param height defines the height for the external texture (default: 0)
  463. * @returns the babylon internal texture
  464. */
  465. wrapWebGLTexture(texture: WebGLTexture, hasMipMaps?: boolean, samplingMode?: number, width?: number, height?: number): InternalTexture;
  466. /**
  467. * @internal
  468. */
  469. _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement | ImageBitmap, faceIndex?: number, lod?: number): void;
  470. /**
  471. * Updates a depth texture Comparison Mode and Function.
  472. * If the comparison Function is equal to 0, the mode will be set to none.
  473. * Otherwise, this only works in webgl 2 and requires a shadow sampler in the shader.
  474. * @param texture The texture to set the comparison function for
  475. * @param comparisonFunction The comparison function to set, 0 if no comparison required
  476. */
  477. updateTextureComparisonFunction(texture: InternalTexture, comparisonFunction: number): void;
  478. /**
  479. * Creates a webGL buffer to use with instantiation
  480. * @param capacity defines the size of the buffer
  481. * @returns the webGL buffer
  482. */
  483. createInstancesBuffer(capacity: number): DataBuffer;
  484. /**
  485. * Delete a webGL buffer used with instantiation
  486. * @param buffer defines the webGL buffer to delete
  487. */
  488. deleteInstancesBuffer(buffer: WebGLBuffer): void;
  489. private _clientWaitAsync;
  490. /**
  491. * @internal
  492. */
  493. _readPixelsAsync(x: number, y: number, w: number, h: number, format: number, type: number, outputBuffer: ArrayBufferView): Promise<ArrayBufferView> | null;
  494. dispose(): void;
  495. }
  496. // Mixins
  497. declare global{
  498. /* eslint-disable no-var */
  499. /* eslint-disable @typescript-eslint/naming-convention */
  500. // Mixins
  501. interface Window {
  502. mozIndexedDB: IDBFactory;
  503. webkitIndexedDB: IDBFactory;
  504. msIndexedDB: IDBFactory;
  505. webkitURL: typeof URL;
  506. mozRequestAnimationFrame(callback: FrameRequestCallback): number;
  507. oRequestAnimationFrame(callback: FrameRequestCallback): number;
  508. WebGLRenderingContext: WebGLRenderingContext;
  509. CANNON: any;
  510. AudioContext: AudioContext;
  511. webkitAudioContext: AudioContext;
  512. PointerEvent: any;
  513. Math: Math;
  514. Uint8Array: Uint8ArrayConstructor;
  515. Float32Array: Float32ArrayConstructor;
  516. mozURL: typeof URL;
  517. msURL: typeof URL;
  518. DracoDecoderModule: any;
  519. setImmediate(handler: (...args: any[]) => void): number;
  520. }
  521. interface WorkerGlobalScope {
  522. importScripts: (...args: string[]) => void;
  523. }
  524. type WorkerSelf = WindowOrWorkerGlobalScope & WorkerGlobalScope;
  525. interface HTMLCanvasElement {
  526. requestPointerLock(): void;
  527. msRequestPointerLock?(): void;
  528. mozRequestPointerLock?(): void;
  529. webkitRequestPointerLock?(): void;
  530. /** Track whether a record is in progress */
  531. isRecording: boolean;
  532. /** Capture Stream method defined by some browsers */
  533. captureStream(fps?: number): MediaStream;
  534. }
  535. interface CanvasRenderingContext2D {
  536. msImageSmoothingEnabled: boolean;
  537. }
  538. // Babylon Extension to enable UIEvents to work with our IUIEvents
  539. interface UIEvent {
  540. inputIndex: number;
  541. }
  542. interface MouseEvent {
  543. mozMovementX: number;
  544. mozMovementY: number;
  545. webkitMovementX: number;
  546. webkitMovementY: number;
  547. msMovementX: number;
  548. msMovementY: number;
  549. }
  550. interface Navigator {
  551. mozGetVRDevices: (any: any) => any;
  552. webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: any, errorCallback: any): void;
  553. mozGetUserMedia(constraints: MediaStreamConstraints, successCallback: any, errorCallback: any): void;
  554. msGetUserMedia(constraints: MediaStreamConstraints, successCallback: any, errorCallback: any): void;
  555. webkitGetGamepads(): Gamepad[];
  556. msGetGamepads(): Gamepad[];
  557. webkitGamepads(): Gamepad[];
  558. }
  559. interface HTMLVideoElement {
  560. mozSrcObject: any;
  561. }
  562. interface Math {
  563. fround(x: number): number;
  564. imul(a: number, b: number): number;
  565. log2(x: number): number;
  566. }
  567. interface OffscreenCanvas extends EventTarget {
  568. width: number;
  569. height: number;
  570. }
  571. var OffscreenCanvas: {
  572. prototype: OffscreenCanvas;
  573. new (width: number, height: number): OffscreenCanvas;
  574. };
  575. // Experimental Pressure API https://wicg.github.io/compute-pressure/
  576. type PressureSource = "cpu";
  577. type PressureState = "nominal" | "fair" | "serious" | "critical";
  578. type PressureFactor = "thermal" | "power-supply";
  579. interface PressureRecord {
  580. source: PressureSource;
  581. state: PressureState;
  582. factors: ReadonlyArray<PressureFactor>;
  583. time: number;
  584. }
  585. interface PressureObserver {
  586. observe(source: PressureSource): void;
  587. unobserve(source: PressureSource): void;
  588. disconnect(): void;
  589. takeRecords(): Array<PressureRecord>;
  590. }
  591. interface PressureObserverOptions {
  592. sampleRate?: number;
  593. }
  594. type PressureUpdateCallback = (changes: Array<PressureRecord>, observer: PressureObserver) => void;
  595. const PressureObserver: {
  596. prototype: PressureObserver;
  597. new (callback: PressureUpdateCallback, options?: PressureObserverOptions): PressureObserver;
  598. supportedSources: ReadonlyArray<PressureSource>;
  599. };
  600. /**
  601. * TODO: remove this file when we upgrade to TypeScript 5.0
  602. */
  603. /* eslint-disable no-var */
  604. /* eslint-disable @typescript-eslint/naming-convention */
  605. interface OffscreenCanvasEventMap {
  606. contextlost: Event;
  607. contextrestored: Event;
  608. }
  609. interface OffscreenCanvas extends EventTarget {
  610. /**
  611. * These attributes return the dimensions of the OffscreenCanvas object's bitmap.
  612. *
  613. * They can be set, to replace the bitmap with a new, transparent black bitmap of the specified dimensions (effectively resizing it).
  614. */
  615. height: number;
  616. oncontextlost: ((this: OffscreenCanvas, ev: Event) => any) | null;
  617. oncontextrestored: ((this: OffscreenCanvas, ev: Event) => any) | null;
  618. /**
  619. * These attributes return the dimensions of the OffscreenCanvas object's bitmap.
  620. *
  621. * They can be set, to replace the bitmap with a new, transparent black bitmap of the specified dimensions (effectively resizing it).
  622. */
  623. width: number;
  624. /**
  625. * Returns a promise that will fulfill with a new Blob object representing a file containing the image in the OffscreenCanvas object.
  626. *
  627. * The argument, if provided, is a dictionary that controls the encoding options of the image file to be created. The type field specifies the file format and has a default value of "image/png"; that type is also used if the requested type isn't supported. If the image format supports variable quality (such as "image/jpeg"), then the quality field is a number in the range 0.0 to 1.0 inclusive indicating the desired quality level for the resulting image.
  628. */
  629. convertToBlob(options?: ImageEncodeOptions): Promise<Blob>;
  630. /**
  631. * Returns an object that exposes an API for drawing on the OffscreenCanvas object. contextId specifies the desired API: "2d", "bitmaprenderer", "webgl", or "webgl2". options is handled by that API.
  632. *
  633. * This specification defines the "2d" context below, which is similar but distinct from the "2d" context that is created from a canvas element. The WebGL specifications define the "webgl" and "webgl2" contexts. [WEBGL]
  634. *
  635. * Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context).
  636. */
  637. getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null;
  638. getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null;
  639. getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null;
  640. getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null;
  641. getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null;
  642. /** Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. */
  643. transferToImageBitmap(): ImageBitmap;
  644. addEventListener<K extends keyof OffscreenCanvasEventMap>(
  645. type: K,
  646. listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
  647. options?: boolean | AddEventListenerOptions
  648. ): void;
  649. addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
  650. removeEventListener<K extends keyof OffscreenCanvasEventMap>(
  651. type: K,
  652. listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
  653. options?: boolean | EventListenerOptions
  654. ): void;
  655. removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  656. }
  657. var OffscreenCanvas: {
  658. prototype: OffscreenCanvas;
  659. new (width: number, height: number): OffscreenCanvas;
  660. };
  661. interface OffscreenCanvasRenderingContext2D
  662. extends CanvasCompositing,
  663. CanvasDrawImage,
  664. CanvasDrawPath,
  665. CanvasFillStrokeStyles,
  666. CanvasFilters,
  667. CanvasImageData,
  668. CanvasImageSmoothing,
  669. CanvasPath,
  670. CanvasPathDrawingStyles,
  671. CanvasRect,
  672. CanvasShadowStyles,
  673. CanvasState,
  674. CanvasText,
  675. CanvasTextDrawingStyles,
  676. CanvasTransform {
  677. readonly canvas: OffscreenCanvas;
  678. commit(): void;
  679. }
  680. var OffscreenCanvasRenderingContext2D: {
  681. prototype: OffscreenCanvasRenderingContext2D;
  682. new (): OffscreenCanvasRenderingContext2D;
  683. };
  684. /* eslint-disable no-var */
  685. /* eslint-disable @typescript-eslint/naming-convention */
  686. // Type definitions for WebGL 2 extended with Babylon specific types
  687. interface WebGL2RenderingContext extends WebGL2RenderingContextBase {
  688. HALF_FLOAT_OES: number;
  689. RGBA16F: typeof WebGL2RenderingContext.RGBA16F;
  690. RGBA32F: typeof WebGL2RenderingContext.RGBA32F;
  691. DEPTH24_STENCIL8: typeof WebGL2RenderingContext.DEPTH24_STENCIL8;
  692. COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: number;
  693. COMPRESSED_SRGB_S3TC_DXT1_EXT: number;
  694. COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: number;
  695. COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: number;
  696. COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: number;
  697. COMPRESSED_SRGB8_ETC2: number;
  698. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;
  699. DRAW_FRAMEBUFFER: typeof WebGL2RenderingContext.DRAW_FRAMEBUFFER;
  700. UNSIGNED_INT_24_8: typeof WebGL2RenderingContext.UNSIGNED_INT_24_8;
  701. MIN: typeof WebGL2RenderingContext.MIN;
  702. MAX: typeof WebGL2RenderingContext.MAX;
  703. }
  704. interface EXT_disjoint_timer_query {
  705. QUERY_COUNTER_BITS_EXT: number;
  706. TIME_ELAPSED_EXT: number;
  707. TIMESTAMP_EXT: number;
  708. GPU_DISJOINT_EXT: number;
  709. QUERY_RESULT_EXT: number;
  710. QUERY_RESULT_AVAILABLE_EXT: number;
  711. queryCounterEXT(query: WebGLQuery, target: number): void;
  712. createQueryEXT(): WebGLQuery;
  713. beginQueryEXT(target: number, query: WebGLQuery): void;
  714. endQueryEXT(target: number): void;
  715. getQueryObjectEXT(query: WebGLQuery, target: number): any;
  716. deleteQueryEXT(query: WebGLQuery): void;
  717. }
  718. interface WebGLProgram {
  719. __SPECTOR_rebuildProgram?:
  720. | ((vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (program: WebGLProgram) => void, onError: (message: string) => void) => void)
  721. | null;
  722. }
  723. interface WebGLUniformLocation {
  724. _currentState: any;
  725. }
  726. /* eslint-disable babylonjs/available */
  727. /* eslint-disable @typescript-eslint/naming-convention */
  728. interface GPUObjectBase {
  729. label: string | undefined;
  730. }
  731. interface GPUObjectDescriptorBase {
  732. label?: string;
  733. }
  734. interface GPUSupportedLimits {
  735. [name: string]: number;
  736. readonly maxTextureDimension1D: number;
  737. readonly maxTextureDimension2D: number;
  738. readonly maxTextureDimension3D: number;
  739. readonly maxTextureArrayLayers: number;
  740. readonly maxBindGroups: number;
  741. readonly maxBindGroupsPlusVertexBuffers: number;
  742. readonly maxBindingsPerBindGroup: number;
  743. readonly maxDynamicUniformBuffersPerPipelineLayout: number;
  744. readonly maxDynamicStorageBuffersPerPipelineLayout: number;
  745. readonly maxSampledTexturesPerShaderStage: number;
  746. readonly maxSamplersPerShaderStage: number;
  747. readonly maxStorageBuffersPerShaderStage: number;
  748. readonly maxStorageTexturesPerShaderStage: number;
  749. readonly maxUniformBuffersPerShaderStage: number;
  750. readonly maxUniformBufferBindingSize: number;
  751. readonly maxStorageBufferBindingSize: number;
  752. readonly minUniformBufferOffsetAlignment: number;
  753. readonly minStorageBufferOffsetAlignment: number;
  754. readonly maxVertexBuffers: number;
  755. readonly maxBufferSize: number;
  756. readonly maxVertexAttributes: number;
  757. readonly maxVertexBufferArrayStride: number;
  758. readonly maxInterStageShaderComponents: number;
  759. readonly maxInterStageShaderVariables: number;
  760. readonly maxColorAttachments: number;
  761. readonly maxColorAttachmentBytesPerSample: number;
  762. readonly maxComputeWorkgroupStorageSize: number;
  763. readonly maxComputeInvocationsPerWorkgroup: number;
  764. readonly maxComputeWorkgroupSizeX: number;
  765. readonly maxComputeWorkgroupSizeY: number;
  766. readonly maxComputeWorkgroupSizeZ: number;
  767. readonly maxComputeWorkgroupsPerDimension: number;
  768. }
  769. type GPUSupportedFeatures = ReadonlySet<string>;
  770. type WGSLLanguageFeatures = ReadonlySet<string>;
  771. interface GPUAdapterInfo {
  772. readonly vendor: string;
  773. readonly architecture: string;
  774. readonly device: string;
  775. readonly description: string;
  776. }
  777. interface Navigator {
  778. readonly gpu: GPU | undefined;
  779. }
  780. interface WorkerNavigator {
  781. readonly gpu: GPU | undefined;
  782. }
  783. class GPU {
  784. requestAdapter(options?: GPURequestAdapterOptions): Promise<GPUAdapter | undefined>;
  785. getPreferredCanvasFormat(): GPUTextureFormat;
  786. readonly wgslLanguageFeatures: WGSLLanguageFeatures;
  787. }
  788. interface GPURequestAdapterOptions {
  789. powerPreference?: GPUPowerPreference;
  790. forceFallbackAdapter?: boolean /* default=false */;
  791. }
  792. type GPUPowerPreference = "low-power" | "high-performance";
  793. class GPUAdapter {
  794. // https://michalzalecki.com/nominal-typing-in-typescript/#approach-1-class-with-a-private-property
  795. readonly name: string;
  796. readonly features: GPUSupportedFeatures;
  797. readonly limits: GPUSupportedLimits;
  798. readonly isFallbackAdapter: boolean;
  799. requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
  800. requestAdapterInfo(unmaskHints?: string[]): Promise<GPUAdapterInfo>;
  801. }
  802. interface GPUDeviceDescriptor extends GPUObjectDescriptorBase {
  803. requiredFeatures?: GPUFeatureName[] /* default=[] */;
  804. requiredLimits?: { [name: string]: GPUSize64 } /* default={} */;
  805. defaultQueue?: GPUQueueDescriptor /* default={} */;
  806. }
  807. type GPUFeatureName =
  808. | "depth-clip-control"
  809. | "depth32float-stencil8"
  810. | "texture-compression-bc"
  811. | "texture-compression-etc2"
  812. | "texture-compression-astc"
  813. | "timestamp-query"
  814. | "indirect-first-instance"
  815. | "shader-f16"
  816. | "rg11b10ufloat-renderable"
  817. | "bgra8unorm-storage"
  818. | "float32-filterable";
  819. class GPUDevice extends EventTarget implements GPUObjectBase {
  820. label: string | undefined;
  821. readonly features: GPUSupportedFeatures;
  822. readonly limits: GPUSupportedLimits;
  823. readonly queue: GPUQueue;
  824. destroy(): void;
  825. createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer;
  826. createTexture(descriptor: GPUTextureDescriptor): GPUTexture;
  827. createSampler(descriptor?: GPUSamplerDescriptor): GPUSampler;
  828. importExternalTexture(descriptor: GPUExternalTextureDescriptor): GPUExternalTexture;
  829. createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): GPUBindGroupLayout;
  830. createPipelineLayout(descriptor: GPUPipelineLayoutDescriptor): GPUPipelineLayout;
  831. createBindGroup(descriptor: GPUBindGroupDescriptor): GPUBindGroup;
  832. createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule;
  833. createComputePipeline(descriptor: GPUComputePipelineDescriptor): GPUComputePipeline;
  834. createRenderPipeline(descriptor: GPURenderPipelineDescriptor): GPURenderPipeline;
  835. createComputePipelineAsync(descriptor: GPUComputePipelineDescriptor): Promise<GPUComputePipeline>;
  836. createRenderPipelineAsync(descriptor: GPURenderPipelineDescriptor): Promise<GPURenderPipeline>;
  837. createCommandEncoder(descriptor?: GPUCommandEncoderDescriptor): GPUCommandEncoder;
  838. createRenderBundleEncoder(descriptor: GPURenderBundleEncoderDescriptor): GPURenderBundleEncoder;
  839. createQuerySet(descriptor: GPUQuerySetDescriptor): GPUQuerySet;
  840. readonly lost: Promise<GPUDeviceLostInfo>;
  841. pushErrorScope(filter: GPUErrorFilter): void;
  842. popErrorScope(): Promise<GPUError | undefined>;
  843. onuncapturederror: Event | undefined;
  844. }
  845. class GPUBuffer implements GPUObjectBase {
  846. label: string | undefined;
  847. readonly size: GPUSize64Out;
  848. readonly usage: GPUFlagsConstant;
  849. readonly mapState: GPUBufferMapState;
  850. mapAsync(mode: GPUMapModeFlags, offset?: GPUSize64 /*default=0*/, size?: GPUSize64): Promise<void>;
  851. getMappedRange(offset?: GPUSize64 /*default=0*/, size?: GPUSize64): ArrayBuffer;
  852. unmap(): void;
  853. destroy(): void;
  854. }
  855. type GPUBufferMapState = "unmapped" | "pending" | "mapped";
  856. interface GPUBufferDescriptor extends GPUObjectDescriptorBase {
  857. size: GPUSize64;
  858. usage: GPUBufferUsageFlags;
  859. mappedAtCreation: boolean /* default=false */;
  860. }
  861. type GPUBufferUsageFlags = number;
  862. type GPUMapModeFlags = number;
  863. class GPUTexture implements GPUObjectBase {
  864. label: string | undefined;
  865. createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView;
  866. destroy(): void;
  867. readonly width: GPUIntegerCoordinateOut;
  868. readonly height: GPUIntegerCoordinateOut;
  869. readonly depthOrArrayLayers: GPUIntegerCoordinateOut;
  870. readonly mipLevelCount: GPUIntegerCoordinateOut;
  871. readonly sampleCount: GPUSize32Out;
  872. readonly dimension: GPUTextureDimension;
  873. readonly format: GPUTextureFormat;
  874. readonly usage: GPUFlagsConstant;
  875. }
  876. interface GPUTextureDescriptor extends GPUObjectDescriptorBase {
  877. size: GPUExtent3D;
  878. mipLevelCount?: GPUIntegerCoordinate /* default=1 */;
  879. sampleCount?: GPUSize32 /* default=1 */;
  880. dimension?: GPUTextureDimension /* default="2d" */;
  881. format: GPUTextureFormat;
  882. usage: GPUTextureUsageFlags;
  883. viewFormats?: GPUTextureFormat[] /* default=[] */;
  884. }
  885. type GPUTextureDimension = "1d" | "2d" | "3d";
  886. type GPUTextureUsageFlags = number;
  887. class GPUTextureView implements GPUObjectBase {
  888. label: string | undefined;
  889. }
  890. interface GPUTextureViewDescriptor extends GPUObjectDescriptorBase {
  891. format: GPUTextureFormat;
  892. dimension: GPUTextureViewDimension;
  893. aspect?: GPUTextureAspect /* default="all" */;
  894. baseMipLevel?: GPUIntegerCoordinate /* default=0 */;
  895. mipLevelCount: GPUIntegerCoordinate;
  896. baseArrayLayer?: GPUIntegerCoordinate /* default=0*/;
  897. arrayLayerCount: GPUIntegerCoordinate;
  898. }
  899. type GPUTextureViewDimension = "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d";
  900. type GPUTextureAspect = "all" | "stencil-only" | "depth-only";
  901. type GPUTextureFormat =
  902. // 8-bit formats
  903. | "r8unorm"
  904. | "r8snorm"
  905. | "r8uint"
  906. | "r8sint"
  907. // 16-bit formats
  908. | "r16uint"
  909. | "r16sint"
  910. | "r16float"
  911. | "rg8unorm"
  912. | "rg8snorm"
  913. | "rg8uint"
  914. | "rg8sint"
  915. // 32-bit formats
  916. | "r32uint"
  917. | "r32sint"
  918. | "r32float"
  919. | "rg16uint"
  920. | "rg16sint"
  921. | "rg16float"
  922. | "rgba8unorm"
  923. | "rgba8unorm-srgb"
  924. | "rgba8snorm"
  925. | "rgba8uint"
  926. | "rgba8sint"
  927. | "bgra8unorm"
  928. | "bgra8unorm-srgb"
  929. // Packed 32-bit formats
  930. | "rgb9e5ufloat"
  931. | "rgb10a2uint"
  932. | "rgb10a2unorm"
  933. | "rg11b10ufloat"
  934. // 64-bit formats
  935. | "rg32uint"
  936. | "rg32sint"
  937. | "rg32float"
  938. | "rgba16uint"
  939. | "rgba16sint"
  940. | "rgba16float"
  941. // 128-bit formats
  942. | "rgba32uint"
  943. | "rgba32sint"
  944. | "rgba32float"
  945. // Depth and stencil formats
  946. | "stencil8"
  947. | "depth16unorm"
  948. | "depth24plus"
  949. | "depth24plus-stencil8"
  950. | "depth32float"
  951. // "depth32float-stencil8" feature
  952. | "depth32float-stencil8"
  953. // BC compressed formats usable if "texture-compression-bc" is both
  954. // supported by the device/user agent and enabled in requestDevice.
  955. | "bc1-rgba-unorm"
  956. | "bc1-rgba-unorm-srgb"
  957. | "bc2-rgba-unorm"
  958. | "bc2-rgba-unorm-srgb"
  959. | "bc3-rgba-unorm"
  960. | "bc3-rgba-unorm-srgb"
  961. | "bc4-r-unorm"
  962. | "bc4-r-snorm"
  963. | "bc5-rg-unorm"
  964. | "bc5-rg-snorm"
  965. | "bc6h-rgb-ufloat"
  966. | "bc6h-rgb-float"
  967. | "bc7-rgba-unorm"
  968. | "bc7-rgba-unorm-srgb"
  969. // ETC2 compressed formats usable if "texture-compression-etc2" is both
  970. // supported by the device/user agent and enabled in requestDevice.
  971. | "etc2-rgb8unorm"
  972. | "etc2-rgb8unorm-srgb"
  973. | "etc2-rgb8a1unorm"
  974. | "etc2-rgb8a1unorm-srgb"
  975. | "etc2-rgba8unorm"
  976. | "etc2-rgba8unorm-srgb"
  977. | "eac-r11unorm"
  978. | "eac-r11snorm"
  979. | "eac-rg11unorm"
  980. | "eac-rg11snorm"
  981. // ASTC compressed formats usable if "texture-compression-astc" is both
  982. // supported by the device/user agent and enabled in requestDevice.
  983. | "astc-4x4-unorm"
  984. | "astc-4x4-unorm-srgb"
  985. | "astc-5x4-unorm"
  986. | "astc-5x4-unorm-srgb"
  987. | "astc-5x5-unorm"
  988. | "astc-5x5-unorm-srgb"
  989. | "astc-6x5-unorm"
  990. | "astc-6x5-unorm-srgb"
  991. | "astc-6x6-unorm"
  992. | "astc-6x6-unorm-srgb"
  993. | "astc-8x5-unorm"
  994. | "astc-8x5-unorm-srgb"
  995. | "astc-8x6-unorm"
  996. | "astc-8x6-unorm-srgb"
  997. | "astc-8x8-unorm"
  998. | "astc-8x8-unorm-srgb"
  999. | "astc-10x5-unorm"
  1000. | "astc-10x5-unorm-srgb"
  1001. | "astc-10x6-unorm"
  1002. | "astc-10x6-unorm-srgb"
  1003. | "astc-10x8-unorm"
  1004. | "astc-10x8-unorm-srgb"
  1005. | "astc-10x10-unorm"
  1006. | "astc-10x10-unorm-srgb"
  1007. | "astc-12x10-unorm"
  1008. | "astc-12x10-unorm-srgb"
  1009. | "astc-12x12-unorm"
  1010. | "astc-12x12-unorm-srgb";
  1011. class GPUExternalTexture implements GPUObjectBase {
  1012. label: string | undefined;
  1013. }
  1014. interface GPUExternalTextureDescriptor extends GPUObjectDescriptorBase {
  1015. source: HTMLVideoElement | VideoFrame;
  1016. colorSpace?: PredefinedColorSpace /* default="srgb" */;
  1017. }
  1018. class GPUSampler implements GPUObjectBase {
  1019. label: string | undefined;
  1020. }
  1021. interface GPUSamplerDescriptor extends GPUObjectDescriptorBase {
  1022. addressModeU?: GPUAddressMode /* default="clamp-to-edge" */;
  1023. addressModeV?: GPUAddressMode /* default="clamp-to-edge" */;
  1024. addressModeW?: GPUAddressMode /* default="clamp-to-edge" */;
  1025. magFilter?: GPUFilterMode /* default="nearest" */;
  1026. minFilter?: GPUFilterMode /* default="nearest" */;
  1027. mipmapFilter?: GPUMipmapFilterMode /* default="nearest" */;
  1028. lodMinClamp?: number /* default=0 */;
  1029. lodMaxClamp?: number /* default=32 */;
  1030. compare?: GPUCompareFunction;
  1031. maxAnisotropy?: number /* default=1 */;
  1032. }
  1033. type GPUAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat";
  1034. type GPUFilterMode = "nearest" | "linear";
  1035. type GPUMipmapFilterMode = "nearest" | "linear";
  1036. type GPUCompareFunction = "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always";
  1037. class GPUBindGroupLayout implements GPUObjectBase {
  1038. label: string | undefined;
  1039. }
  1040. interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase {
  1041. entries: GPUBindGroupLayoutEntry[];
  1042. }
  1043. interface GPUBindGroupLayoutEntry {
  1044. binding: GPUIndex32;
  1045. visibility: GPUShaderStageFlags;
  1046. buffer?: GPUBufferBindingLayout;
  1047. sampler?: GPUSamplerBindingLayout;
  1048. texture?: GPUTextureBindingLayout;
  1049. storageTexture?: GPUStorageTextureBindingLayout;
  1050. externalTexture?: GPUExternalTextureBindingLayout;
  1051. }
  1052. type GPUShaderStageFlags = number;
  1053. type GPUBufferBindingType = "uniform" | "storage" | "read-only-storage";
  1054. interface GPUBufferBindingLayout {
  1055. type?: GPUBufferBindingType /* default="uniform" */;
  1056. hasDynamicOffset?: boolean /* default=false */;
  1057. minBindingSize?: GPUSize64 /* default=0 */;
  1058. }
  1059. type GPUSamplerBindingType = "filtering" | "non-filtering" | "comparison";
  1060. interface GPUSamplerBindingLayout {
  1061. type?: GPUSamplerBindingType /* default="filtering" */;
  1062. }
  1063. type GPUTextureSampleType = "float" | "unfilterable-float" | "depth" | "sint" | "uint";
  1064. interface GPUTextureBindingLayout {
  1065. sampleType?: GPUTextureSampleType /* default="float" */;
  1066. viewDimension?: GPUTextureViewDimension /* default="2d" */;
  1067. multisampled?: boolean /* default=false */;
  1068. }
  1069. type GPUStorageTextureAccess = "write-only" | "read-only" | "read-write";
  1070. interface GPUStorageTextureBindingLayout {
  1071. access?: GPUStorageTextureAccess /* default=write-only */;
  1072. format: GPUTextureFormat;
  1073. viewDimension?: GPUTextureViewDimension /* default="2d" */;
  1074. }
  1075. interface GPUExternalTextureBindingLayout {}
  1076. class GPUBindGroup implements GPUObjectBase {
  1077. label: string | undefined;
  1078. }
  1079. interface GPUBindGroupDescriptor extends GPUObjectDescriptorBase {
  1080. layout: GPUBindGroupLayout;
  1081. entries: GPUBindGroupEntry[];
  1082. }
  1083. type GPUBindingResource = GPUSampler | GPUTextureView | GPUBufferBinding | GPUExternalTexture;
  1084. interface GPUBindGroupEntry {
  1085. binding: GPUIndex32;
  1086. resource: GPUBindingResource;
  1087. }
  1088. interface GPUBufferBinding {
  1089. buffer: GPUBuffer;
  1090. offset?: GPUSize64 /* default=0 */;
  1091. size?: GPUSize64 /* default=size_of_buffer - offset */;
  1092. }
  1093. class GPUPipelineLayout implements GPUObjectBase {
  1094. label: string | undefined;
  1095. }
  1096. interface GPUPipelineLayoutDescriptor extends GPUObjectDescriptorBase {
  1097. bindGroupLayouts: GPUBindGroupLayout[];
  1098. }
  1099. class GPUShaderModule implements GPUObjectBase {
  1100. label: string | undefined;
  1101. getCompilationInfo(): Promise<GPUCompilationInfo>;
  1102. }
  1103. interface GPUShaderModuleDescriptor extends GPUObjectDescriptorBase {
  1104. code: string | Uint32Array;
  1105. sourceMap?: object;
  1106. compilationHints?: GPUShaderModuleCompilationHint[] /* default=[] */;
  1107. }
  1108. interface GPUShaderModuleCompilationHint {
  1109. entryPoint: string | Uint32Array;
  1110. layout: GPUPipelineLayout | GPUAutoLayoutMode;
  1111. }
  1112. type GPUCompilationMessageType = "error" | "warning" | "info";
  1113. interface GPUCompilationMessage {
  1114. readonly message: string;
  1115. readonly type: GPUCompilationMessageType;
  1116. readonly lineNum: number;
  1117. readonly linePos: number;
  1118. readonly offset: number;
  1119. readonly length: number;
  1120. }
  1121. interface GPUCompilationInfo {
  1122. readonly messages: readonly GPUCompilationMessage[];
  1123. }
  1124. class GPUPipelineError extends DOMException {
  1125. constructor(message: string | undefined, options: GPUPipelineErrorInit);
  1126. readonly reason: GPUPipelineErrorReason;
  1127. }
  1128. interface GPUPipelineErrorInit {
  1129. reason: GPUPipelineErrorReason;
  1130. }
  1131. type GPUPipelineErrorReason = "validation" | "internal";
  1132. type GPUAutoLayoutMode = "auto";
  1133. interface GPUPipelineDescriptorBase extends GPUObjectDescriptorBase {
  1134. layout: GPUPipelineLayout | GPUAutoLayoutMode;
  1135. }
  1136. interface GPUPipelineBase {
  1137. getBindGroupLayout(index: number): GPUBindGroupLayout;
  1138. }
  1139. interface GPUProgrammableStage {
  1140. module: GPUShaderModule;
  1141. entryPoint: string | Uint32Array;
  1142. constants?: { [name: string]: GPUPipelineConstantValue };
  1143. }
  1144. type GPUPipelineConstantValue = number; // May represent WGSL’s bool, f32, i32, u32, and f16 if enabled.
  1145. class GPUComputePipeline implements GPUObjectBase, GPUPipelineBase {
  1146. label: string | undefined;
  1147. getBindGroupLayout(index: number): GPUBindGroupLayout;
  1148. }
  1149. interface GPUComputePipelineDescriptor extends GPUPipelineDescriptorBase {
  1150. compute: GPUProgrammableStage;
  1151. }
  1152. class GPURenderPipeline implements GPUObjectBase, GPUPipelineBase {
  1153. label: string | undefined;
  1154. getBindGroupLayout(index: number): GPUBindGroupLayout;
  1155. }
  1156. interface GPURenderPipelineDescriptor extends GPUPipelineDescriptorBase {
  1157. vertex: GPUVertexState;
  1158. primitive?: GPUPrimitiveState /* default={} */;
  1159. depthStencil?: GPUDepthStencilState;
  1160. multisample?: GPUMultisampleState /* default={} */;
  1161. fragment?: GPUFragmentState;
  1162. }
  1163. interface GPUPrimitiveState {
  1164. topology?: GPUPrimitiveTopology /* default="triangle-list" */;
  1165. stripIndexFormat?: GPUIndexFormat;
  1166. frontFace?: GPUFrontFace /* default="ccw" */;
  1167. cullMode?: GPUCullMode /* default="none" */;
  1168. // Requires "depth-clip-control" feature.
  1169. unclippedDepth?: boolean /* default=false */;
  1170. }
  1171. type GPUPrimitiveTopology = "point-list" | "line-list" | "line-strip" | "triangle-list" | "triangle-strip";
  1172. type GPUFrontFace = "ccw" | "cw";
  1173. type GPUCullMode = "none" | "front" | "back";
  1174. interface GPUMultisampleState {
  1175. count?: GPUSize32 /* default=1 */;
  1176. mask?: GPUSampleMask /* default=0xFFFFFFFF */;
  1177. alphaToCoverageEnabled?: boolean /* default=false */;
  1178. }
  1179. interface GPUFragmentState extends GPUProgrammableStage {
  1180. targets: (GPUColorTargetState | null)[];
  1181. }
  1182. interface GPUColorTargetState {
  1183. format: GPUTextureFormat;
  1184. blend?: GPUBlendState;
  1185. writeMask?: GPUColorWriteFlags /* default=0xF - GPUColorWrite.ALL */;
  1186. }
  1187. interface GPUBlendState {
  1188. color: GPUBlendComponent;
  1189. alpha: GPUBlendComponent;
  1190. }
  1191. type GPUColorWriteFlags = number;
  1192. interface GPUBlendComponent {
  1193. operation?: GPUBlendOperation /* default="add" */;
  1194. srcFactor?: GPUBlendFactor /* default="one" */;
  1195. dstFactor?: GPUBlendFactor /* default="zero" */;
  1196. }
  1197. type GPUBlendFactor =
  1198. | "zero"
  1199. | "one"
  1200. | "src"
  1201. | "one-minus-src"
  1202. | "src-alpha"
  1203. | "one-minus-src-alpha"
  1204. | "dst"
  1205. | "one-minus-dst"
  1206. | "dst-alpha"
  1207. | "one-minus-dst-alpha"
  1208. | "src-alpha-saturated"
  1209. | "constant"
  1210. | "one-minus-constant";
  1211. type GPUBlendOperation = "add" | "subtract" | "reverse-subtract" | "min" | "max";
  1212. interface GPUDepthStencilState {
  1213. format: GPUTextureFormat;
  1214. depthWriteEnabled?: boolean /* default=false */;
  1215. depthCompare?: GPUCompareFunction /* default="always" */;
  1216. stencilFront?: GPUStencilFaceState /* default={} */;
  1217. stencilBack?: GPUStencilFaceState /* default={} */;
  1218. stencilReadMask?: GPUStencilValue /* default=0xFFFFFFFF */;
  1219. stencilWriteMask?: GPUStencilValue /* default=0xFFFFFFFF */;
  1220. depthBias?: GPUDepthBias /* default=0 */;
  1221. depthBiasSlopeScale?: number /* default= 0 */;
  1222. depthBiasClamp?: number /* default=0 */;
  1223. }
  1224. interface GPUStencilFaceState {
  1225. compare?: GPUCompareFunction /* default="always" */;
  1226. failOp?: GPUStencilOperation /* default="keep" */;
  1227. depthFailOp?: GPUStencilOperation /* default="keep" */;
  1228. passOp?: GPUStencilOperation /* default="keep" */;
  1229. }
  1230. type GPUStencilOperation = "keep" | "zero" | "replace" | "invert" | "increment-clamp" | "decrement-clamp" | "increment-wrap" | "decrement-wrap";
  1231. type GPUIndexFormat = "uint16" | "uint32";
  1232. type GPUVertexFormat =
  1233. | "uint8x2"
  1234. | "uint8x4"
  1235. | "sint8x2"
  1236. | "sint8x4"
  1237. | "unorm8x2"
  1238. | "unorm8x4"
  1239. | "snorm8x2"
  1240. | "snorm8x4"
  1241. | "uint16x2"
  1242. | "uint16x4"
  1243. | "sint16x2"
  1244. | "sint16x4"
  1245. | "unorm16x2"
  1246. | "unorm16x4"
  1247. | "snorm16x2"
  1248. | "snorm16x4"
  1249. | "float16x2"
  1250. | "float16x4"
  1251. | "float32"
  1252. | "float32x2"
  1253. | "float32x3"
  1254. | "float32x4"
  1255. | "uint32"
  1256. | "uint32x2"
  1257. | "uint32x3"
  1258. | "uint32x4"
  1259. | "sint32"
  1260. | "sint32x2"
  1261. | "sint32x3"
  1262. | "sint32x4"
  1263. | "unorm10-10-10-2";
  1264. type GPUVertexStepMode = "vertex" | "instance";
  1265. interface GPUVertexState extends GPUProgrammableStage {
  1266. buffers?: GPUVertexBufferLayout[] /* default=[] */;
  1267. }
  1268. interface GPUVertexBufferLayout {
  1269. arrayStride: GPUSize64;
  1270. stepMode?: GPUVertexStepMode /* default="vertex" */;
  1271. attributes: GPUVertexAttribute[];
  1272. }
  1273. interface GPUVertexAttribute {
  1274. format: GPUVertexFormat;
  1275. offset: GPUSize64;
  1276. shaderLocation: GPUIndex32;
  1277. }
  1278. interface GPUImageDataLayout {
  1279. offset?: GPUSize64 /* default=0 */;
  1280. bytesPerRow: GPUSize32;
  1281. rowsPerImage?: GPUSize32;
  1282. }
  1283. interface GPUImageCopyBuffer extends GPUImageDataLayout {
  1284. buffer: GPUBuffer;
  1285. }
  1286. interface GPUImageCopyTexture {
  1287. texture: GPUTexture;
  1288. mipLevel?: GPUIntegerCoordinate /* default=0 */;
  1289. origin?: GPUOrigin3D /* default={} */;
  1290. aspect?: GPUTextureAspect /* default="all" */;
  1291. }
  1292. interface GPUImageCopyTextureTagged extends GPUImageCopyTexture {
  1293. colorSpace?: PredefinedColorSpace /* default="srgb" */;
  1294. premultipliedAlpha?: boolean /* default=false */;
  1295. }
  1296. type GPUImageCopyExternalImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLVideoElement | VideoFrame | HTMLCanvasElement | OffscreenCanvas;
  1297. interface GPUImageCopyExternalImage {
  1298. source: GPUImageCopyExternalImageSource;
  1299. origin?: GPUOrigin2D /* default={} */;
  1300. flipY?: boolean /* default=false */;
  1301. }
  1302. class GPUCommandBuffer implements GPUObjectBase {
  1303. label: string | undefined;
  1304. }
  1305. interface GPUCommandBufferDescriptor extends GPUObjectDescriptorBase {}
  1306. interface GPUCommandsMixin {}
  1307. class GPUCommandEncoder implements GPUObjectBase, GPUCommandsMixin, GPUDebugCommandsMixin {
  1308. label: string | undefined;
  1309. beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder;
  1310. beginComputePass(descriptor?: GPUComputePassDescriptor): GPUComputePassEncoder;
  1311. copyBufferToBuffer(source: GPUBuffer, sourceOffset: GPUSize64, destination: GPUBuffer, destinationOffset: GPUSize64, size: GPUSize64): void;
  1312. copyBufferToTexture(source: GPUImageCopyBuffer, destination: GPUImageCopyTexture, copySize: GPUExtent3D): void;
  1313. copyTextureToBuffer(source: GPUImageCopyTexture, destination: GPUImageCopyBuffer, copySize: GPUExtent3D): void;
  1314. copyTextureToTexture(source: GPUImageCopyTexture, destination: GPUImageCopyTexture, copySize: GPUExtent3D): void;
  1315. clearBuffer(buffer: GPUBuffer, offset?: GPUSize64 /* default=0 */, size?: GPUSize64): void;
  1316. writeTimestamp?(querySet: GPUQuerySet, queryIndex: GPUSize32): void; // not in the spec anymore, but may come back later, so keep it here for now
  1317. resolveQuerySet(querySet: GPUQuerySet, firstQuery: GPUSize32, queryCount: GPUSize32, destination: GPUBuffer, destinationOffset: GPUSize64): void;
  1318. finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer;
  1319. pushDebugGroup(groupLabel: string): void;
  1320. popDebugGroup(): void;
  1321. insertDebugMarker(markerLabel: string): void;
  1322. }
  1323. interface GPUCommandEncoderDescriptor extends GPUObjectDescriptorBase {}
  1324. interface GPUBindingCommandsMixin {
  1325. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsets?: GPUBufferDynamicOffset[]): void;
  1326. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsetData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): void;
  1327. }
  1328. interface GPUDebugCommandsMixin {
  1329. pushDebugGroup(groupLabel: string): void;
  1330. popDebugGroup(): void;
  1331. insertDebugMarker(markerLabel: string): void;
  1332. }
  1333. class GPUComputePassEncoder implements GPUObjectBase, GPUCommandsMixin, GPUDebugCommandsMixin, GPUBindingCommandsMixin {
  1334. label: string | undefined;
  1335. setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsets?: GPUBufferDynamicOffset[]): void;
  1336. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsetData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): void;
  1337. pushDebugGroup(groupLabel: string): void;
  1338. popDebugGroup(): void;
  1339. insertDebugMarker(markerLabel: string): void;
  1340. setPipeline(pipeline: GPUComputePipeline): void;
  1341. dispatchWorkgroups(workgroupCountX: GPUSize32, workgroupCountY?: GPUSize32 /* default=1 */, workgroupCountZ?: GPUSize32 /* default=1 */): void;
  1342. dispatchWorkgroupsIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1343. end(): void;
  1344. }
  1345. interface GPUComputePassTimestampWrites {
  1346. querySet: GPUQuerySet;
  1347. beginningOfPassWriteIndex: GPUSize32;
  1348. endOfPassWriteIndex: GPUSize32;
  1349. }
  1350. interface GPUComputePassDescriptor extends GPUObjectDescriptorBase {
  1351. timestampWrites?: GPUComputePassTimestampWrites;
  1352. }
  1353. class GPURenderPassEncoder implements GPUObjectBase, GPUCommandsMixin, GPUDebugCommandsMixin, GPUBindingCommandsMixin, GPURenderCommandsMixin {
  1354. label: string | undefined;
  1355. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsets?: GPUBufferDynamicOffset[]): void;
  1356. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsetData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): void;
  1357. pushDebugGroup(groupLabel: string): void;
  1358. popDebugGroup(): void;
  1359. insertDebugMarker(markerLabel: string): void;
  1360. setPipeline(pipeline: GPURenderPipeline): void;
  1361. setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64 /* default=0 */, size?: GPUSize64 /* default=0 */): void;
  1362. setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer, offset?: GPUSize64 /* default=0 */, size?: GPUSize64 /* default=0 */): void;
  1363. draw(vertexCount: GPUSize32, instanceCount?: GPUSize32 /* default=1 */, firstVertex?: GPUSize32 /* default=0 */, firstInstance?: GPUSize32 /* default=0 */): void;
  1364. drawIndexed(
  1365. indexCount: GPUSize32,
  1366. instanceCount?: GPUSize32 /* default=1 */,
  1367. firstIndex?: GPUSize32 /* default=0 */,
  1368. baseVertex?: GPUSignedOffset32 /* default=0 */,
  1369. firstInstance?: GPUSize32 /* default=0 */
  1370. ): void;
  1371. drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1372. drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1373. setViewport(x: number, y: number, width: number, height: number, minDepth: number, maxDepth: number): void;
  1374. setScissorRect(x: GPUIntegerCoordinate, y: GPUIntegerCoordinate, width: GPUIntegerCoordinate, height: GPUIntegerCoordinate): void;
  1375. setBlendConstant(color: GPUColor): void;
  1376. setStencilReference(reference: GPUStencilValue): void;
  1377. beginOcclusionQuery(queryIndex: GPUSize32): void;
  1378. endOcclusionQuery(): void;
  1379. executeBundles(bundles: GPURenderBundle[]): void;
  1380. end(): void;
  1381. }
  1382. interface GPURenderPassTimestampWrites {
  1383. querySet: GPUQuerySet;
  1384. beginningOfPassWriteIndex: GPUSize32;
  1385. endOfPassWriteIndex: GPUSize32;
  1386. }
  1387. interface GPURenderPassDescriptor extends GPUObjectDescriptorBase {
  1388. colorAttachments: (GPURenderPassColorAttachment | null)[];
  1389. depthStencilAttachment?: GPURenderPassDepthStencilAttachment;
  1390. occlusionQuerySet?: GPUQuerySet;
  1391. timestampWrites?: GPURenderPassTimestampWrites;
  1392. maxDrawCount?: GPUSize64 /* default=50000000 */;
  1393. }
  1394. interface GPURenderPassColorAttachment {
  1395. view: GPUTextureView;
  1396. depthSlice?: GPUIntegerCoordinate;
  1397. resolveTarget?: GPUTextureView;
  1398. clearValue?: GPUColor;
  1399. loadOp: GPULoadOp;
  1400. storeOp: GPUStoreOp;
  1401. }
  1402. interface GPURenderPassDepthStencilAttachment {
  1403. view: GPUTextureView;
  1404. depthClearValue?: number /* default=0 */;
  1405. depthLoadOp: GPULoadOp;
  1406. depthStoreOp: GPUStoreOp;
  1407. depthReadOnly?: boolean /* default=false */;
  1408. stencilClearValue?: GPUStencilValue /* default=0 */;
  1409. stencilLoadOp?: GPULoadOp;
  1410. stencilStoreOp?: GPUStoreOp;
  1411. stencilReadOnly?: boolean /* default=false */;
  1412. }
  1413. type GPULoadOp = "load" | "clear";
  1414. type GPUStoreOp = "store" | "discard";
  1415. interface GPURenderPassLayout extends GPUObjectDescriptorBase {
  1416. colorFormats: (GPUTextureFormat | null)[];
  1417. depthStencilFormat?: GPUTextureFormat;
  1418. sampleCount?: GPUSize32 /* default=1 */;
  1419. }
  1420. interface GPURenderCommandsMixin {
  1421. setPipeline(pipeline: GPURenderPipeline): void;
  1422. setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64 /* default=0 */, size?: GPUSize64 /* default=0 */): void;
  1423. setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer, offset?: GPUSize64 /* default=0 */, size?: GPUSize64): void;
  1424. draw(vertexCount: GPUSize32, instanceCount?: GPUSize32 /* default=1 */, firstVertex?: GPUSize32 /* default=0 */, firstInstance?: GPUSize32 /* default=0 */): void;
  1425. drawIndexed(
  1426. indexCount: GPUSize32,
  1427. instanceCount?: GPUSize32 /* default=1 */,
  1428. firstIndex?: GPUSize32 /* default=0 */,
  1429. baseVertex?: GPUSignedOffset32 /* default=0 */,
  1430. firstInstance?: GPUSize32 /* default=0 */
  1431. ): void;
  1432. drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1433. drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1434. }
  1435. class GPURenderBundle implements GPUObjectBase {
  1436. label: string | undefined;
  1437. }
  1438. interface GPURenderBundleDescriptor extends GPUObjectDescriptorBase {}
  1439. class GPURenderBundleEncoder implements GPUObjectBase, GPUCommandsMixin, GPUDebugCommandsMixin, GPUBindingCommandsMixin, GPURenderCommandsMixin {
  1440. label: string | undefined;
  1441. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsets?: GPUBufferDynamicOffset[]): void;
  1442. setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup, dynamicOffsetData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32): void;
  1443. pushDebugGroup(groupLabel: string): void;
  1444. popDebugGroup(): void;
  1445. insertDebugMarker(markerLabel: string): void;
  1446. setPipeline(pipeline: GPURenderPipeline): void;
  1447. setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64 /* default=0 */, size?: GPUSize64 /* default=0 */): void;
  1448. setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer, offset?: GPUSize64 /* default=0 */, size?: GPUSize64 /* default=0 */): void;
  1449. draw(vertexCount: GPUSize32, instanceCount?: GPUSize32 /* default=1 */, firstVertex?: GPUSize32 /* default=0 */, firstInstance?: GPUSize32 /* default=0 */): void;
  1450. drawIndexed(
  1451. indexCount: GPUSize32,
  1452. instanceCount?: GPUSize32 /* default=1 */,
  1453. firstIndex?: GPUSize32 /* default=0 */,
  1454. baseVertex?: GPUSignedOffset32 /* default=0 */,
  1455. firstInstance?: GPUSize32 /* default=0 */
  1456. ): void;
  1457. drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1458. drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
  1459. finish(descriptor?: GPURenderBundleDescriptor): GPURenderBundle;
  1460. }
  1461. interface GPURenderBundleEncoderDescriptor extends GPURenderPassLayout {
  1462. depthReadOnly?: boolean /* default=false */;
  1463. stencilReadOnly?: boolean /* default=false */;
  1464. }
  1465. interface GPUQueueDescriptor extends GPUObjectDescriptorBase {}
  1466. class GPUQueue implements GPUObjectBase {
  1467. label: string | undefined;
  1468. submit(commandBuffers: GPUCommandBuffer[]): void;
  1469. onSubmittedWorkDone(): Promise<void>;
  1470. writeBuffer(buffer: GPUBuffer, bufferOffset: GPUSize64, data: BufferSource, dataOffset?: GPUSize64 /* default=0 */, size?: GPUSize64): void;
  1471. writeTexture(destination: GPUImageCopyTexture, data: BufferSource, dataLayout: GPUImageDataLayout, size: GPUExtent3D): void;
  1472. copyExternalImageToTexture(source: GPUImageCopyExternalImage, destination: GPUImageCopyTextureTagged, copySize: GPUExtent3D): void;
  1473. }
  1474. class GPUQuerySet implements GPUObjectBase {
  1475. label: string | undefined;
  1476. destroy(): void;
  1477. readonly type: GPUQueryType;
  1478. readonly count: GPUSize32Out;
  1479. }
  1480. interface GPUQuerySetDescriptor extends GPUObjectDescriptorBase {
  1481. type: GPUQueryType;
  1482. count: GPUSize32;
  1483. }
  1484. type GPUQueryType = "occlusion" | "timestamp";
  1485. class GPUCanvasContext {
  1486. readonly canvas: HTMLCanvasElement | OffscreenCanvas;
  1487. configure(configuration?: GPUCanvasConfiguration): void;
  1488. unconfigure(): void;
  1489. getCurrentTexture(): GPUTexture;
  1490. }
  1491. type GPUCanvasAlphaMode = "opaque" | "premultiplied";
  1492. interface GPUCanvasConfiguration extends GPUObjectDescriptorBase {
  1493. device: GPUDevice;
  1494. format: GPUTextureFormat;
  1495. usage?: GPUTextureUsageFlags /* default=0x10 - GPUTextureUsage.RENDER_ATTACHMENT */;
  1496. viewFormats?: GPUTextureFormat[] /* default=[] */;
  1497. colorSpace?: PredefinedColorSpace /* default="srgb" */;
  1498. alphaMode?: GPUCanvasAlphaMode /* default="opaque" */;
  1499. }
  1500. type GPUDeviceLostReason = "unknown" | "destroyed";
  1501. class GPUDeviceLostInfo {
  1502. readonly reason?: GPUDeviceLostReason;
  1503. readonly message: string;
  1504. }
  1505. class GPUError {
  1506. readonly message: string;
  1507. }
  1508. class GPUValidationError extends GPUError {
  1509. constructor(message: string);
  1510. readonly message: string;
  1511. }
  1512. class GPUOutOfMemoryError extends GPUError {
  1513. constructor(message: string);
  1514. readonly message: string;
  1515. }
  1516. class GPUInternalError extends GPUError {
  1517. constructor(message: string);
  1518. readonly message: string;
  1519. }
  1520. type GPUErrorFilter = "validation" | "out-of-memory" | "internal";
  1521. class GPUUncapturedErrorEvent extends Event {
  1522. constructor(type: string, gpuUncapturedErrorEventInitDict: GPUUncapturedErrorEventInit);
  1523. readonly error: GPUError;
  1524. }
  1525. interface GPUUncapturedErrorEventInit extends EventInit {
  1526. error: GPUError;
  1527. }
  1528. type GPUBufferDynamicOffset = number; /* unsigned long */
  1529. type GPUStencilValue = number; /* unsigned long */
  1530. type GPUSampleMask = number; /* unsigned long */
  1531. type GPUDepthBias = number; /* long */
  1532. type GPUSize64 = number; /* unsigned long long */
  1533. type GPUIntegerCoordinate = number; /* unsigned long */
  1534. type GPUIndex32 = number; /* unsigned long */
  1535. type GPUSize32 = number; /* unsigned long */
  1536. type GPUSignedOffset32 = number; /* long */
  1537. type GPUSize64Out = number; /* unsigned long long */
  1538. type GPUIntegerCoordinateOut = number; /* unsigned long */
  1539. type GPUSize32Out = number; /* unsigned long */
  1540. type GPUFlagsConstant = number; /* unsigned long */
  1541. interface GPUColorDict {
  1542. r: number;
  1543. g: number;
  1544. b: number;
  1545. a: number;
  1546. }
  1547. type GPUColor = [number, number, number, number] | GPUColorDict;
  1548. interface GPUOrigin2DDict {
  1549. x?: GPUIntegerCoordinate /* default=0 */;
  1550. y?: GPUIntegerCoordinate /* default=0 */;
  1551. }
  1552. type GPUOrigin2D = [GPUIntegerCoordinate, GPUIntegerCoordinate] | GPUOrigin2DDict;
  1553. interface GPUOrigin3DDict {
  1554. x?: GPUIntegerCoordinate /* default=0 */;
  1555. y?: GPUIntegerCoordinate /* default=0 */;
  1556. z?: GPUIntegerCoordinate /* default=0 */;
  1557. }
  1558. type GPUOrigin3D = [GPUIntegerCoordinate, GPUIntegerCoordinate, GPUIntegerCoordinate] | GPUOrigin3DDict;
  1559. interface GPUExtent3DDict {
  1560. width: GPUIntegerCoordinate;
  1561. height?: GPUIntegerCoordinate /* default=1 */;
  1562. depthOrArrayLayers?: GPUIntegerCoordinate /* default=1 */;
  1563. }
  1564. type GPUExtent3D = [GPUIntegerCoordinate, GPUIntegerCoordinate, GPUIntegerCoordinate] | GPUExtent3DDict;
  1565. /* eslint-disable @typescript-eslint/naming-convention */
  1566. // Type definitions for non-npm package webxr 0.5
  1567. // Project: https://www.w3.org/TR/webxr/
  1568. // Definitions by: Rob Rohan <https://github.com/robrohan>
  1569. // Raanan Weber <https://github.com/RaananW>
  1570. // Sean T. McBeth <https://github.com/capnmidnight>
  1571. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  1572. // Minimum TypeScript Version: 3.7
  1573. // Most of this was hand written and... more or less copied from the following
  1574. // sites:
  1575. // https://www.w3.org/TR/webxr/
  1576. // https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API
  1577. // https://www.w3.org/immersive-web/
  1578. // https://github.com/immersive-web
  1579. //
  1580. /**
  1581. * ref: https://immersive-web.github.io/webxr/#navigator-xr-attribute
  1582. */
  1583. interface Navigator {
  1584. /**
  1585. * An XRSystem object is the entry point to the API, used to query for XR features
  1586. * available to the user agent and initiate communication with XR hardware via the
  1587. * creation of XRSessions.
  1588. */
  1589. xr?: XRSystem | undefined;
  1590. }
  1591. /**
  1592. * WebGL Context Compatability
  1593. *
  1594. * ref: https://immersive-web.github.io/webxr/#contextcompatibility
  1595. */
  1596. interface WebGLContextAttributes {
  1597. xrCompatible?: boolean | undefined;
  1598. }
  1599. interface WebGLRenderingContextBase {
  1600. makeXRCompatible(): Promise<void>;
  1601. }
  1602. /**
  1603. * Available session modes
  1604. *
  1605. * ref: https://immersive-web.github.io/webxr/#xrsessionmode-enum
  1606. */
  1607. type XRSessionMode = "inline" | "immersive-vr" | "immersive-ar";
  1608. /**
  1609. * Reference space types
  1610. */
  1611. type XRReferenceSpaceType = "viewer" | "local" | "local-floor" | "bounded-floor" | "unbounded";
  1612. type XREnvironmentBlendMode = "opaque" | "additive" | "alpha-blend";
  1613. /**
  1614. * ref: https://immersive-web.github.io/webxr/#xrsession-interface
  1615. */
  1616. type XRVisibilityState = "visible" | "visible-blurred" | "hidden";
  1617. /**
  1618. * Handedness types
  1619. */
  1620. type XRHandedness = "none" | "left" | "right";
  1621. /**
  1622. * InputSource target ray modes
  1623. */
  1624. type XRTargetRayMode = "gaze" | "tracked-pointer" | "screen" | "transient-pointer";
  1625. /**
  1626. * Eye types
  1627. */
  1628. type XREye = "none" | "left" | "right";
  1629. type XRFrameRequestCallback = (time: DOMHighResTimeStamp, frame: XRFrame) => void;
  1630. interface XRSystemDeviceChangeEvent extends Event {
  1631. type: "devicechange";
  1632. }
  1633. interface XRSystemDeviceChangeEventHandler {
  1634. (event: XRSystemDeviceChangeEvent): any;
  1635. }
  1636. interface XRSystemEventMap {
  1637. devicechange: XRSystemDeviceChangeEvent;
  1638. }
  1639. /**
  1640. * An XRSystem object is the entry point to the API, used to query for XR features available
  1641. * to the user agent and initiate communication with XR hardware via the creation of
  1642. * XRSessions.
  1643. *
  1644. * ref: https://immersive-web.github.io/webxr/#xrsystem-interface
  1645. */
  1646. interface XRSystem extends EventTarget {
  1647. /**
  1648. * Attempts to initialize an XRSession for the given mode if possible, entering immersive
  1649. * mode if necessary.
  1650. * @param mode
  1651. * @param options
  1652. */
  1653. requestSession(mode: XRSessionMode, options?: XRSessionInit): Promise<XRSession>;
  1654. /**
  1655. * Queries if a given mode may be supported by the user agent and device capabilities.
  1656. * @param mode
  1657. */
  1658. isSessionSupported(mode: XRSessionMode): Promise<boolean>;
  1659. ondevicechange: XRSystemDeviceChangeEventHandler | null;
  1660. addEventListener<K extends keyof XRSystemEventMap>(type: K, listener: (this: XRSystem, ev: XRSystemEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
  1661. addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
  1662. removeEventListener<K extends keyof XRSystemEventMap>(type: K, listener: (this: XRSystem, ev: XRSystemEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
  1663. removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  1664. }
  1665. abstract class XRSystem implements XRSystem {}
  1666. /**
  1667. * Describes a viewport, or rectangular region, of a graphics surface.
  1668. *
  1669. * ref: https://immersive-web.github.io/webxr/#xrviewport-interface
  1670. */
  1671. interface XRViewport {
  1672. readonly x: number;
  1673. readonly y: number;
  1674. readonly width: number;
  1675. readonly height: number;
  1676. }
  1677. abstract class XRViewport implements XRViewport {}
  1678. /**
  1679. * Represents a virtual coordinate system with an origin that corresponds to a physical location.
  1680. * Spatial data that is requested from the API or given to the API is always expressed in relation
  1681. * to a specific XRSpace at the time of a specific XRFrame. Numeric values such as pose positions
  1682. * are coordinates in that space relative to its origin. The interface is intentionally opaque.
  1683. *
  1684. * ref: https://immersive-web.github.io/webxr/#xrspace-interface
  1685. */
  1686. // tslint:disable-next-line no-empty-interface
  1687. interface XRSpace extends EventTarget {}
  1688. abstract class XRSpace implements XRSpace {}
  1689. interface XRRenderStateInit {
  1690. baseLayer?: XRWebGLLayer | undefined;
  1691. depthFar?: number | undefined;
  1692. depthNear?: number | undefined;
  1693. inlineVerticalFieldOfView?: number | undefined;
  1694. }
  1695. interface XRRenderState {
  1696. readonly baseLayer?: XRWebGLLayer | undefined;
  1697. readonly depthFar: number;
  1698. readonly depthNear: number;
  1699. readonly inlineVerticalFieldOfView?: number | undefined;
  1700. }
  1701. abstract class XRRenderState implements XRRenderState {}
  1702. interface XRReferenceSpaceEventInit extends EventInit {
  1703. referenceSpace?: XRReferenceSpace | undefined;
  1704. transform?: XRRigidTransform | undefined;
  1705. }
  1706. /**
  1707. * XRReferenceSpaceEvents are fired to indicate changes to the state of an XRReferenceSpace.
  1708. *
  1709. * ref: https://immersive-web.github.io/webxr/#xrreferencespaceevent-interface
  1710. */
  1711. interface XRReferenceSpaceEvent extends Event {
  1712. readonly type: "reset";
  1713. readonly referenceSpace: XRReferenceSpace;
  1714. readonly transform?: XRRigidTransform | undefined;
  1715. }
  1716. // tslint:disable-next-line no-unnecessary-class
  1717. class XRReferenceSpaceEvent implements XRReferenceSpaceEvent {
  1718. constructor(type: "reset", eventInitDict?: XRReferenceSpaceEventInit);
  1719. }
  1720. interface XRReferenceSpaceEventHandler {
  1721. (event: XRReferenceSpaceEvent): any;
  1722. }
  1723. interface XRReferenceSpaceEventMap {
  1724. reset: XRReferenceSpaceEvent;
  1725. }
  1726. /**
  1727. * One of several common XRSpaces that applications can use to establish a spatial relationship
  1728. * with the user's physical environment.
  1729. *
  1730. * ref: https://immersive-web.github.io/webxr/#xrreferencespace-interface
  1731. */
  1732. interface XRReferenceSpace extends XRSpace {
  1733. getOffsetReferenceSpace(originOffset: XRRigidTransform): XRReferenceSpace;
  1734. onreset: XRReferenceSpaceEventHandler;
  1735. addEventListener<K extends keyof XRReferenceSpaceEventMap>(
  1736. type: K,
  1737. listener: (this: XRReferenceSpace, ev: XRReferenceSpaceEventMap[K]) => any,
  1738. options?: boolean | AddEventListenerOptions
  1739. ): void;
  1740. addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
  1741. removeEventListener<K extends keyof XRReferenceSpaceEventMap>(
  1742. type: K,
  1743. listener: (this: XRReferenceSpace, ev: XRReferenceSpaceEventMap[K]) => any,
  1744. options?: boolean | EventListenerOptions
  1745. ): void;
  1746. removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  1747. }
  1748. abstract class XRReferenceSpace implements XRReferenceSpace {}
  1749. /**
  1750. * Extends XRReferenceSpace to include boundsGeometry, indicating the pre-configured boundaries
  1751. * of the user's space.
  1752. *
  1753. * ref: https://immersive-web.github.io/webxr/#xrboundedreferencespace-interface
  1754. */
  1755. interface XRBoundedReferenceSpace extends XRReferenceSpace {
  1756. readonly boundsGeometry: DOMPointReadOnly[];
  1757. }
  1758. abstract class XRBoundedReferenceSpace implements XRBoundedReferenceSpace {}
  1759. /**
  1760. * Represents an XR input source, which is any input mechanism which allows the user to perform
  1761. * targeted actions in the same virtual space as the viewer. Example XR input sources include,
  1762. * but are not limited to, handheld controllers, optically tracked hands, and gaze-based input
  1763. * methods that operate on the viewer's pose. Input mechanisms which are not explicitly associated
  1764. * with the XR device, such as traditional gamepads, mice, or keyboards SHOULD NOT be considered
  1765. * XR input sources.
  1766. * ref: https://immersive-web.github.io/webxr/#xrinputsource-interface
  1767. */
  1768. interface XRInputSource {
  1769. readonly handedness: XRHandedness;
  1770. readonly targetRayMode: XRTargetRayMode;
  1771. readonly targetRaySpace: XRSpace;
  1772. readonly gripSpace?: XRSpace | undefined;
  1773. readonly gamepad?: Gamepad | undefined;
  1774. readonly profiles: string[];
  1775. readonly hand?: XRHand;
  1776. }
  1777. abstract class XRInputSource implements XRInputSource {}
  1778. /**
  1779. * Represents a list of XRInputSources. It is used in favor of a frozen array type when the contents
  1780. * of the list are expected to change over time, such as with the XRSession inputSources attribute.
  1781. * ref: https://immersive-web.github.io/webxr/#xrinputsourcearray-interface
  1782. */
  1783. interface XRInputSourceArray {
  1784. [Symbol.iterator](): IterableIterator<XRInputSource>;
  1785. [n: number]: XRInputSource;
  1786. length: number;
  1787. entries(): IterableIterator<[number, XRInputSource]>;
  1788. keys(): IterableIterator<number>;
  1789. values(): IterableIterator<XRInputSource>;
  1790. forEach(callbackfn: (value: XRInputSource, index: number, array: XRInputSource[]) => void, thisArg?: any): void;
  1791. }
  1792. abstract class XRInputSourceArray implements XRInputSourceArray {}
  1793. /**
  1794. * Describes a position and orientation in space relative to an XRSpace.
  1795. *
  1796. * ref: https://immersive-web.github.io/webxr/#xrpose-interface
  1797. */
  1798. interface XRPose {
  1799. readonly transform: XRRigidTransform;
  1800. readonly emulatedPosition: boolean;
  1801. }
  1802. abstract class XRPose implements XRPose {}
  1803. /**
  1804. * Represents a snapshot of the state of all of the tracked objects for an XRSession. Applications
  1805. * can acquire an XRFrame by calling requestAnimationFrame() on an XRSession with an
  1806. * XRFrameRequestCallback. When the callback is called it will be passed an XRFrame.
  1807. * Events which need to communicate tracking state, such as the select event, will also provide an
  1808. * XRFrame.
  1809. *
  1810. * ref: https://immersive-web.github.io/webxr/#xrframe-interface
  1811. */
  1812. interface XRFrame {
  1813. readonly session: XRSession;
  1814. // BABYLON CHANGE - switched to optional
  1815. readonly predictedDisplayTime?: DOMHighResTimeStamp;
  1816. /**
  1817. * Provides the pose of space relative to baseSpace as an XRPose, at the time represented by
  1818. * the XRFrame.
  1819. *
  1820. * @param space
  1821. * @param baseSpace
  1822. */
  1823. getPose(space: XRSpace, baseSpace: XRSpace): XRPose | undefined;
  1824. /**
  1825. * Provides the pose of the viewer relative to referenceSpace as an XRViewerPose, at the
  1826. * XRFrame's time.
  1827. *
  1828. * @param referenceSpace
  1829. */
  1830. getViewerPose(referenceSpace: XRReferenceSpace): XRViewerPose | undefined;
  1831. }
  1832. abstract class XRFrame implements XRFrame {}
  1833. /**
  1834. * Type of XR events available
  1835. */
  1836. type XRInputSourceEventType = "select" | "selectend" | "selectstart" | "squeeze" | "squeezeend" | "squeezestart";
  1837. interface XRInputSourceEventInit extends EventInit {
  1838. frame?: XRFrame | undefined;
  1839. inputSource?: XRInputSource | undefined;
  1840. }
  1841. /**
  1842. * XRInputSourceEvents are fired to indicate changes to the state of an XRInputSource.
  1843. * ref: https://immersive-web.github.io/webxr/#xrinputsourceevent-interface
  1844. */
  1845. class XRInputSourceEvent extends Event {
  1846. readonly type: XRInputSourceEventType;
  1847. readonly frame: XRFrame;
  1848. readonly inputSource: XRInputSource;
  1849. constructor(type: XRInputSourceEventType, eventInitDict?: XRInputSourceEventInit);
  1850. }
  1851. interface XRInputSourceEventHandler {
  1852. (evt: XRInputSourceEvent): any;
  1853. }
  1854. type XRSessionEventType = "end" | "visibilitychange" | "frameratechange";
  1855. interface XRSessionEventInit extends EventInit {
  1856. session: XRSession;
  1857. }
  1858. /**
  1859. * XRSessionEvents are fired to indicate changes to the state of an XRSession.
  1860. * ref: https://immersive-web.github.io/webxr/#xrsessionevent-interface
  1861. */
  1862. class XRSessionEvent extends Event {
  1863. readonly session: XRSession;
  1864. constructor(type: XRSessionEventType, eventInitDict?: XRSessionEventInit);
  1865. }
  1866. interface XRSessionEventHandler {
  1867. (evt: XRSessionEvent): any;
  1868. }
  1869. /**
  1870. * ref: https://immersive-web.github.io/webxr/#feature-dependencies
  1871. */
  1872. interface XRSessionInit {
  1873. optionalFeatures?: string[] | undefined;
  1874. requiredFeatures?: string[] | undefined;
  1875. }
  1876. interface XRSessionEventMap {
  1877. inputsourceschange: XRInputSourceChangeEvent;
  1878. end: XRSessionEvent;
  1879. visibilitychange: XRSessionEvent;
  1880. frameratechange: XRSessionEvent;
  1881. select: XRInputSourceEvent;
  1882. selectstart: XRInputSourceEvent;
  1883. selectend: XRInputSourceEvent;
  1884. squeeze: XRInputSourceEvent;
  1885. squeezestart: XRInputSourceEvent;
  1886. squeezeend: XRInputSourceEvent;
  1887. eyetrackingstart: XREyeTrackingSourceEvent;
  1888. eyetrackingend: XREyeTrackingSourceEvent;
  1889. }
  1890. /**
  1891. * Any interaction with XR hardware is done via an XRSession object, which can only be
  1892. * retrieved by calling requestSession() on the XRSystem object. Once a session has been
  1893. * successfully acquired, it can be used to poll the viewer pose, query information about
  1894. * the user's environment, and present imagery to the user.
  1895. *
  1896. * ref: https://immersive-web.github.io/webxr/#xrsession-interface
  1897. */
  1898. interface XRSession extends EventTarget {
  1899. /**
  1900. * Returns a list of this session's XRInputSources, each representing an input device
  1901. * used to control the camera and/or scene.
  1902. */
  1903. readonly inputSources: XRInputSourceArray;
  1904. /**
  1905. * object which contains options affecting how the imagery is rendered.
  1906. * This includes things such as the near and far clipping planes
  1907. */
  1908. readonly renderState: XRRenderState;
  1909. readonly environmentBlendMode: XREnvironmentBlendMode;
  1910. readonly visibilityState: XRVisibilityState;
  1911. readonly frameRate?: number | undefined;
  1912. readonly supportedFrameRates?: Float32Array | undefined;
  1913. /**
  1914. * Removes a callback from the animation frame painting callback from
  1915. * XRSession's set of animation frame rendering callbacks, given the
  1916. * identifying handle returned by a previous call to requestAnimationFrame().
  1917. */
  1918. cancelAnimationFrame(id: number): void;
  1919. /**
  1920. * Ends the WebXR session. Returns a promise which resolves when the
  1921. * session has been shut down.
  1922. */
  1923. end(): Promise<void>;
  1924. /**
  1925. * Schedules the specified method to be called the next time the user agent
  1926. * is working on rendering an animation frame for the WebXR device. Returns an
  1927. * integer value which can be used to identify the request for the purposes of
  1928. * canceling the callback using cancelAnimationFrame(). This method is comparable
  1929. * to the Window.requestAnimationFrame() method.
  1930. */
  1931. requestAnimationFrame(callback: XRFrameRequestCallback): number;
  1932. /**
  1933. * Requests that a new XRReferenceSpace of the specified type be created.
  1934. * Returns a promise which resolves with the XRReferenceSpace or
  1935. * XRBoundedReferenceSpace which was requested, or throws a NotSupportedError if
  1936. * the requested space type isn't supported by the device.
  1937. */
  1938. requestReferenceSpace(type: XRReferenceSpaceType): Promise<XRReferenceSpace | XRBoundedReferenceSpace>;
  1939. updateRenderState(renderStateInit?: XRRenderStateInit): Promise<void>;
  1940. updateTargetFrameRate(rate: number): Promise<void>;
  1941. onend: XRSessionEventHandler;
  1942. oninputsourceschange: XRInputSourceChangeEventHandler;
  1943. onselect: XRInputSourceEventHandler;
  1944. onselectstart: XRInputSourceEventHandler;
  1945. onselectend: XRInputSourceEventHandler;
  1946. onsqueeze: XRInputSourceEventHandler;
  1947. onsqueezestart: XRInputSourceEventHandler;
  1948. onsqueezeend: XRInputSourceEventHandler;
  1949. onvisibilitychange: XRSessionEventHandler;
  1950. onframeratechange: XRSessionEventHandler;
  1951. addEventListener<K extends keyof XRSessionEventMap>(type: K, listener: (this: XRSession, ev: XRSessionEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
  1952. addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
  1953. removeEventListener<K extends keyof XRSessionEventMap>(type: K, listener: (this: XRSession, ev: XRSessionEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
  1954. removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  1955. }
  1956. abstract class XRSession implements XRSession {}
  1957. /**
  1958. * An XRPose describing the state of a viewer of the XR scene as tracked by the XR
  1959. * device. A viewer may represent a tracked piece of hardware, the observed position
  1960. * of a user's head relative to the hardware, or some other means of computing a series
  1961. * of viewpoints into the XR scene. XRViewerPoses can only be queried relative to an
  1962. * XRReferenceSpace. It provides, in addition to the XRPose values, an array of views
  1963. * which include rigid transforms to indicate the viewpoint and projection matrices.
  1964. * These values should be used by the application when rendering a frame of an XR scene.
  1965. *
  1966. * ref: https://immersive-web.github.io/webxr/#xrviewerpose-interface
  1967. */
  1968. interface XRViewerPose extends XRPose {
  1969. readonly views: ReadonlyArray<XRView>;
  1970. }
  1971. abstract class XRViewerPose implements XRViewerPose {}
  1972. /**
  1973. * A transform described by a position and orientation. When interpreting an
  1974. * XRRigidTransform the orientation is always applied prior to the position.
  1975. *
  1976. * ref: https://immersive-web.github.io/webxr/#xrrigidtransform-interface
  1977. */
  1978. class XRRigidTransform {
  1979. readonly position: DOMPointReadOnly;
  1980. readonly orientation: DOMPointReadOnly;
  1981. readonly matrix: Float32Array;
  1982. readonly inverse: XRRigidTransform;
  1983. constructor(position?: DOMPointInit, direction?: DOMPointInit);
  1984. }
  1985. /**
  1986. * Describes a single view into an XR scene for a given frame.
  1987. *
  1988. * ref: https://immersive-web.github.io/webxr/#xrview-interface
  1989. */
  1990. interface XRView {
  1991. readonly eye: XREye;
  1992. readonly projectionMatrix: Float32Array;
  1993. readonly transform: XRRigidTransform;
  1994. readonly recommendedViewportScale?: number | undefined;
  1995. requestViewportScale(scale: number): void;
  1996. }
  1997. abstract class XRView implements XRView {}
  1998. /**
  1999. * XRInputSourcesChangeEvents are fired to indicate changes to the XRInputSources that are
  2000. * available to an XRSession.
  2001. * ref: https://immersive-web.github.io/webxr/#xrinputsourceschangeevent-interface
  2002. */
  2003. interface XRInputSourceChangeEvent extends XRSessionEvent {
  2004. readonly removed: ReadonlyArray<XRInputSource>;
  2005. readonly added: ReadonlyArray<XRInputSource>;
  2006. }
  2007. interface XRInputSourceChangeEventHandler {
  2008. (evt: XRInputSourceChangeEvent): any;
  2009. }
  2010. // Experimental/Draft features
  2011. // Anchors
  2012. type XRAnchorSet = Set<XRAnchor>;
  2013. interface XRAnchor {
  2014. anchorSpace: XRSpace;
  2015. delete(): void;
  2016. }
  2017. abstract class XRAnchor implements XRAnchor {}
  2018. interface XRFrame {
  2019. trackedAnchors?: XRAnchorSet | undefined;
  2020. createAnchor?: (pose: XRRigidTransform, space: XRSpace) => Promise<XRAnchor>;
  2021. }
  2022. // AR Hit testing
  2023. class XRRay {
  2024. readonly origin: DOMPointReadOnly;
  2025. readonly direction: DOMPointReadOnly;
  2026. readonly matrix: Float32Array;
  2027. constructor(transformOrOrigin?: XRRigidTransform | DOMPointInit, direction?: DOMPointInit);
  2028. }
  2029. type XRHitTestTrackableType = "point" | "plane" | "mesh";
  2030. interface XRTransientInputHitTestResult {
  2031. readonly inputSource: XRInputSource;
  2032. readonly results: ReadonlyArray<XRHitTestResult>;
  2033. }
  2034. class XRTransientInputHitTestResult {
  2035. prototype: XRTransientInputHitTestResult;
  2036. }
  2037. interface XRHitTestResult {
  2038. getPose(baseSpace: XRSpace): XRPose | undefined;
  2039. // When anchor system is enabled
  2040. createAnchor?: (pose: XRRigidTransform) => Promise<XRAnchor> | undefined;
  2041. }
  2042. abstract class XRHitTestResult implements XRHitTestResult {}
  2043. interface XRHitTestSource {
  2044. cancel(): void;
  2045. }
  2046. abstract class XRHitTestSource implements XRHitTestSource {}
  2047. interface XRTransientInputHitTestSource {
  2048. cancel(): void;
  2049. }
  2050. abstract class XRTransientInputHitTestSource implements XRTransientInputHitTestSource {}
  2051. interface XRHitTestOptionsInit {
  2052. space: XRSpace;
  2053. entityTypes?: XRHitTestTrackableType[] | undefined;
  2054. offsetRay?: XRRay | undefined;
  2055. }
  2056. interface XRTransientInputHitTestOptionsInit {
  2057. profile: string;
  2058. entityTypes?: XRHitTestTrackableType[] | undefined;
  2059. offsetRay?: XRRay | undefined;
  2060. }
  2061. interface XRSession {
  2062. requestHitTestSource?: (options: XRHitTestOptionsInit) => Promise<XRHitTestSource>;
  2063. requestHitTestSourceForTransientInput?: (options: XRTransientInputHitTestOptionsInit) => Promise<XRTransientInputHitTestSource>;
  2064. // Legacy
  2065. requestHitTest?: (ray: XRRay, referenceSpace: XRReferenceSpace) => Promise<XRHitResult[]>;
  2066. }
  2067. interface XRFrame {
  2068. getHitTestResults(hitTestSource: XRHitTestSource): XRHitTestResult[];
  2069. getHitTestResultsForTransientInput(hitTestSource: XRTransientInputHitTestSource): XRTransientInputHitTestResult[];
  2070. }
  2071. // Legacy
  2072. interface XRHitResult {
  2073. hitMatrix: Float32Array;
  2074. }
  2075. // Plane detection
  2076. type XRPlaneSet = Set<XRPlane>;
  2077. type XRPlaneOrientation = "horizontal" | "vertical";
  2078. interface XRPlane {
  2079. orientation: XRPlaneOrientation;
  2080. planeSpace: XRSpace;
  2081. polygon: DOMPointReadOnly[];
  2082. lastChangedTime: number;
  2083. }
  2084. abstract class XRPlane implements XRPlane {}
  2085. interface XRSession {
  2086. // Legacy
  2087. updateWorldTrackingState?: (options: { planeDetectionState?: { enabled: boolean } | undefined }) => void | undefined;
  2088. }
  2089. // interface XRFrame {
  2090. // worldInformation?:
  2091. // | {
  2092. // detectedPlanes?: XRPlaneSet | undefined;
  2093. // }
  2094. // | undefined;
  2095. // }
  2096. // Hand Tracking
  2097. type XRHandJoint =
  2098. | "wrist"
  2099. | "thumb-metacarpal"
  2100. | "thumb-phalanx-proximal"
  2101. | "thumb-phalanx-distal"
  2102. | "thumb-tip"
  2103. | "index-finger-metacarpal"
  2104. | "index-finger-phalanx-proximal"
  2105. | "index-finger-phalanx-intermediate"
  2106. | "index-finger-phalanx-distal"
  2107. | "index-finger-tip"
  2108. | "middle-finger-metacarpal"
  2109. | "middle-finger-phalanx-proximal"
  2110. | "middle-finger-phalanx-intermediate"
  2111. | "middle-finger-phalanx-distal"
  2112. | "middle-finger-tip"
  2113. | "ring-finger-metacarpal"
  2114. | "ring-finger-phalanx-proximal"
  2115. | "ring-finger-phalanx-intermediate"
  2116. | "ring-finger-phalanx-distal"
  2117. | "ring-finger-tip"
  2118. | "pinky-finger-metacarpal"
  2119. | "pinky-finger-phalanx-proximal"
  2120. | "pinky-finger-phalanx-intermediate"
  2121. | "pinky-finger-phalanx-distal"
  2122. | "pinky-finger-tip";
  2123. interface XRJointSpace extends XRSpace {
  2124. readonly jointName: XRHandJoint;
  2125. }
  2126. abstract class XRJointSpace implements XRJointSpace {}
  2127. interface XRJointPose extends XRPose {
  2128. readonly radius: number | undefined;
  2129. }
  2130. abstract class XRJointPose implements XRJointPose {}
  2131. interface XRHand extends Map<XRHandJoint, XRJointSpace> {
  2132. readonly WRIST: number;
  2133. readonly THUMB_METACARPAL: number;
  2134. readonly THUMB_PHALANX_PROXIMAL: number;
  2135. readonly THUMB_PHALANX_DISTAL: number;
  2136. readonly THUMB_PHALANX_TIP: number;
  2137. readonly INDEX_METACARPAL: number;
  2138. readonly INDEX_PHALANX_PROXIMAL: number;
  2139. readonly INDEX_PHALANX_INTERMEDIATE: number;
  2140. readonly INDEX_PHALANX_DISTAL: number;
  2141. readonly INDEX_PHALANX_TIP: number;
  2142. readonly MIDDLE_METACARPAL: number;
  2143. readonly MIDDLE_PHALANX_PROXIMAL: number;
  2144. readonly MIDDLE_PHALANX_INTERMEDIATE: number;
  2145. readonly MIDDLE_PHALANX_DISTAL: number;
  2146. readonly MIDDLE_PHALANX_TIP: number;
  2147. readonly RING_METACARPAL: number;
  2148. readonly RING_PHALANX_PROXIMAL: number;
  2149. readonly RING_PHALANX_INTERMEDIATE: number;
  2150. readonly RING_PHALANX_DISTAL: number;
  2151. readonly RING_PHALANX_TIP: number;
  2152. readonly LITTLE_METACARPAL: number;
  2153. readonly LITTLE_PHALANX_PROXIMAL: number;
  2154. readonly LITTLE_PHALANX_INTERMEDIATE: number;
  2155. readonly LITTLE_PHALANX_DISTAL: number;
  2156. readonly LITTLE_PHALANX_TIP: number;
  2157. }
  2158. abstract class XRHand extends Map<XRHandJoint, XRJointSpace> implements XRHand {}
  2159. // WebXR Layers
  2160. /**
  2161. * The base class for XRWebGLLayer and other layer types introduced by future extensions.
  2162. * ref: https://immersive-web.github.io/webxr/#xrlayer-interface
  2163. */
  2164. // tslint:disable-next-line no-empty-interface
  2165. interface XRLayer extends EventTarget {}
  2166. abstract class XRLayer implements XRLayer {}
  2167. interface XRWebGLLayerInit {
  2168. antialias?: boolean | undefined;
  2169. depth?: boolean | undefined;
  2170. stencil?: boolean | undefined;
  2171. alpha?: boolean | undefined;
  2172. ignoreDepthValues?: boolean | undefined;
  2173. framebufferScaleFactor?: number | undefined;
  2174. }
  2175. /**
  2176. * A layer which provides a WebGL framebuffer to render into, enabling hardware accelerated
  2177. * rendering of 3D graphics to be presented on the XR device. *
  2178. * ref: https://immersive-web.github.io/webxr/#xrwebgllayer-interface
  2179. */
  2180. class XRWebGLLayer extends XRLayer {
  2181. static getNativeFramebufferScaleFactor(session: XRSession): number;
  2182. constructor(session: XRSession, context: WebGLRenderingContext | WebGL2RenderingContext, layerInit?: XRWebGLLayerInit);
  2183. readonly antialias: boolean;
  2184. readonly ignoreDepthValues: boolean;
  2185. fixedFoveation?: number | undefined;
  2186. readonly framebuffer: WebGLFramebuffer;
  2187. readonly framebufferWidth: number;
  2188. readonly framebufferHeight: number;
  2189. getViewport(view: XRView): XRViewport | undefined;
  2190. }
  2191. interface XRRenderStateInit {
  2192. layers?: XRLayer[] | undefined;
  2193. }
  2194. interface XRRenderState {
  2195. readonly layers?: XRLayer[] | undefined;
  2196. }
  2197. type XRLayerEventType = "redraw";
  2198. interface XRLayerEvent extends Event {
  2199. readonly type: XRLayerEventType;
  2200. readonly layer: XRLayer;
  2201. }
  2202. interface XRCompositionLayerEventMap {
  2203. redraw: XRLayerEvent;
  2204. }
  2205. interface XRCompositionLayer extends XRLayer {
  2206. readonly layout: XRLayerLayout;
  2207. blendTextureSourceAlpha: boolean;
  2208. chromaticAberrationCorrection?: boolean | undefined;
  2209. readonly mipLevels: number;
  2210. readonly needsRedraw: boolean;
  2211. destroy(): void;
  2212. space: XRSpace;
  2213. // Events
  2214. onredraw: (evt: XRCompositionLayerEventMap["redraw"]) => any;
  2215. addEventListener<K extends keyof XRCompositionLayerEventMap>(
  2216. this: XRCompositionLayer,
  2217. type: K,
  2218. callback: (evt: XRCompositionLayerEventMap[K]) => any,
  2219. options?: boolean | AddEventListenerOptions
  2220. ): void;
  2221. addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
  2222. removeEventListener<K extends keyof XRCompositionLayerEventMap>(this: XRCompositionLayer, type: K, callback: (evt: XRCompositionLayerEventMap[K]) => any): void;
  2223. removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  2224. }
  2225. abstract class XRCompositionLayer implements XRCompositionLayer {}
  2226. type XRTextureType = "texture" | "texture-array";
  2227. type XRLayerLayout = "default" | "mono" | "stereo" | "stereo-left-right" | "stereo-top-bottom";
  2228. interface XRProjectionLayerInit {
  2229. scaleFactor?: number | undefined;
  2230. textureType?: XRTextureType | undefined;
  2231. colorFormat?: GLenum | undefined;
  2232. depthFormat?: GLenum | undefined;
  2233. clearOnAccess?: boolean | undefined;
  2234. }
  2235. interface XRProjectionLayer extends XRCompositionLayer {
  2236. readonly textureWidth: number;
  2237. readonly textureHeight: number;
  2238. readonly textureArrayLength: number;
  2239. readonly ignoreDepthValues: number;
  2240. fixedFoveation: number;
  2241. }
  2242. abstract class XRProjectionLayer implements XRProjectionLayer {}
  2243. interface XRLayerInit {
  2244. mipLevels?: number | undefined;
  2245. viewPixelWidth: number;
  2246. viewPixelHeight: number;
  2247. isStatic?: boolean | undefined;
  2248. colorFormat?: GLenum | undefined;
  2249. depthFormat?: GLenum | undefined;
  2250. space: XRSpace;
  2251. layout?: XRLayerLayout | undefined;
  2252. clearOnAccess?: boolean | undefined;
  2253. }
  2254. interface XRMediaLayerInit {
  2255. invertStereo?: boolean | undefined;
  2256. space: XRSpace;
  2257. layout?: XRLayerLayout | undefined;
  2258. }
  2259. interface XRCylinderLayerInit extends XRLayerInit {
  2260. textureType?: XRTextureType | undefined;
  2261. transform: XRRigidTransform;
  2262. radius?: number | undefined;
  2263. centralAngle?: number | undefined;
  2264. aspectRatio?: number | undefined;
  2265. }
  2266. interface XRMediaCylinderLayerInit extends XRMediaLayerInit {
  2267. transform?: XRRigidTransform | undefined;
  2268. radius?: number | undefined;
  2269. centralAngle?: number | undefined;
  2270. aspectRatio?: number | undefined;
  2271. }
  2272. interface XRCylinderLayer extends XRCompositionLayer {
  2273. transform: XRRigidTransform;
  2274. radius: number;
  2275. centralAngle: number;
  2276. aspectRatio: number;
  2277. }
  2278. abstract class XRCylinderLayer implements XRCylinderLayer {}
  2279. interface XRQuadLayerInit extends XRLayerInit {
  2280. textureType?: XRTextureType | undefined;
  2281. transform?: XRRigidTransform | undefined;
  2282. width?: number | undefined;
  2283. height?: number | undefined;
  2284. }
  2285. interface XRMediaQuadLayerInit extends XRMediaLayerInit {
  2286. transform?: XRRigidTransform | undefined;
  2287. width?: number | undefined;
  2288. height?: number | undefined;
  2289. }
  2290. interface XRQuadLayer extends XRCompositionLayer {
  2291. transform: XRRigidTransform;
  2292. width: number;
  2293. height: number;
  2294. }
  2295. abstract class XRQuadLayer implements XRQuadLayer {}
  2296. interface XREquirectLayerInit extends XRLayerInit {
  2297. textureType?: XRTextureType | undefined;
  2298. transform?: XRRigidTransform | undefined;
  2299. radius?: number | undefined;
  2300. centralHorizontalAngle?: number | undefined;
  2301. upperVerticalAngle?: number | undefined;
  2302. lowerVerticalAngle?: number | undefined;
  2303. }
  2304. interface XRMediaEquirectLayerInit extends XRMediaLayerInit {
  2305. transform?: XRRigidTransform | undefined;
  2306. radius?: number | undefined;
  2307. centralHorizontalAngle?: number | undefined;
  2308. upperVerticalAngle?: number | undefined;
  2309. lowerVerticalAngle?: number | undefined;
  2310. }
  2311. interface XREquirectLayer extends XRCompositionLayer {
  2312. transform: XRRigidTransform;
  2313. radius: number;
  2314. centralHorizontalAngle: number;
  2315. upperVerticalAngle: number;
  2316. lowerVerticalAngle: number;
  2317. }
  2318. abstract class XREquirectLayer implements XREquirectLayer {}
  2319. interface XRCubeLayerInit extends XRLayerInit {
  2320. orientation?: DOMPointReadOnly | undefined;
  2321. }
  2322. interface XRCubeLayer extends XRCompositionLayer {
  2323. orientation: DOMPointReadOnly;
  2324. }
  2325. abstract class XRCubeLayer implements XRCubeLayer {}
  2326. interface XRSubImage {
  2327. readonly viewport: XRViewport;
  2328. }
  2329. abstract class XRSubImage implements XRSubImage {}
  2330. interface XRWebGLSubImage extends XRSubImage {
  2331. readonly colorTexture: WebGLTexture;
  2332. readonly depthStencilTexture?: WebGLTexture;
  2333. readonly motionVectorTexture?: WebGLTexture;
  2334. readonly imageIndex: number;
  2335. readonly textureWidth: number;
  2336. readonly textureHeight: number;
  2337. readonly colorTextureWidth?: number;
  2338. readonly colorTextureHeight?: number;
  2339. readonly depthStencilTextureWidth?: number;
  2340. readonly depthStencilTextureHeight?: number;
  2341. readonly motionVectorTextureWidth?: number;
  2342. readonly motionVectorTextureHeight?: number;
  2343. }
  2344. abstract class XRWebGLSubImage implements XRWebGLSubImage {}
  2345. class XRWebGLBinding {
  2346. readonly nativeProjectionScaleFactor: number;
  2347. constructor(session: XRSession, context: WebGLRenderingContext);
  2348. createProjectionLayer(init?: XRProjectionLayerInit): XRProjectionLayer;
  2349. createQuadLayer(init?: XRQuadLayerInit): XRQuadLayer;
  2350. createCylinderLayer(init?: XRCylinderLayerInit): XRCylinderLayer;
  2351. createEquirectLayer(init?: XREquirectLayerInit): XREquirectLayer;
  2352. createCubeLayer(init?: XRCubeLayerInit): XRCubeLayer;
  2353. getSubImage(layer: XRCompositionLayer, frame: XRFrame, eye?: XREye): XRWebGLSubImage;
  2354. getViewSubImage(layer: XRProjectionLayer, view: XRView): XRWebGLSubImage;
  2355. // BABYLON addition
  2356. getReflectionCubeMap: (lightProbe: XRLightProbe) => WebGLTexture;
  2357. }
  2358. class XRMediaBinding {
  2359. constructor(sesion: XRSession);
  2360. createQuadLayer(video: HTMLVideoElement, init?: XRMediaQuadLayerInit): XRQuadLayer;
  2361. createCylinderLayer(video: HTMLVideoElement, init?: XRMediaCylinderLayerInit): XRCylinderLayer;
  2362. createEquirectLayer(video: HTMLVideoElement, init?: XRMediaEquirectLayerInit): XREquirectLayer;
  2363. }
  2364. // WebGL extensions
  2365. interface WebGLRenderingContextBase {
  2366. getExtension(extensionName: "OCULUS_multiview"): OCULUS_multiview | null;
  2367. }
  2368. enum XOVR_multiview2 {
  2369. FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR = 0x9630,
  2370. FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR = 0x9632,
  2371. MAX_VIEWS_OVR = 0x9631,
  2372. FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR = 0x9633,
  2373. }
  2374. // Oculus extensions
  2375. interface XRSessionGrant {
  2376. mode: XRSessionMode;
  2377. }
  2378. interface XRSystemSessionGrantedEvent extends Event {
  2379. type: "sessiongranted";
  2380. session: XRSessionGrant;
  2381. }
  2382. interface XRSystemSessionGrantedEventHandler {
  2383. (event: XRSystemSessionGrantedEvent): any;
  2384. }
  2385. interface XRSystemEventMap {
  2386. // Session Grant events are an Meta Oculus Browser extension
  2387. sessiongranted: XRSystemSessionGrantedEvent;
  2388. }
  2389. interface XRSystem {
  2390. onsessiongranted: XRSystemSessionGrantedEventHandler | null;
  2391. }
  2392. interface OCULUS_multiview extends OVR_multiview2 {
  2393. framebufferTextureMultisampleMultiviewOVR(
  2394. target: GLenum,
  2395. attachment: GLenum,
  2396. texture: WebGLTexture | null,
  2397. level: GLint,
  2398. samples: GLsizei,
  2399. baseViewIndex: GLint,
  2400. numViews: GLsizei
  2401. ): void;
  2402. }
  2403. abstract class OCULUS_multiview implements OCULUS_multiview {}
  2404. /**
  2405. * BEGIN: WebXR DOM Overlays Module
  2406. * https://immersive-web.github.io/dom-overlays/
  2407. */
  2408. interface GlobalEventHandlersEventMap {
  2409. beforexrselect: XRSessionEvent;
  2410. }
  2411. interface GlobalEventHandlers {
  2412. /**
  2413. * An XRSessionEvent of type beforexrselect is dispatched on the DOM overlay
  2414. * element before generating a WebXR selectstart input event if the -Z axis
  2415. * of the input source's targetRaySpace intersects the DOM overlay element
  2416. * at the time the input device's primary action is triggered.
  2417. */
  2418. onbeforexrselect: ((this: GlobalEventHandlers, ev: XRSessionEvent) => any) | null;
  2419. }
  2420. interface XRDOMOverlayInit {
  2421. root: Element;
  2422. }
  2423. interface XRSessionInit {
  2424. domOverlay?: XRDOMOverlayInit | undefined;
  2425. }
  2426. type XRDOMOverlayType = "screen" | "floating" | "head-locked";
  2427. interface XRDOMOverlayState {
  2428. type: XRDOMOverlayType;
  2429. }
  2430. interface XRSession {
  2431. readonly domOverlayState?: XRDOMOverlayState | undefined;
  2432. }
  2433. /// BABYLON EDITS
  2434. interface XREyeTrackingSourceEvent extends XRSessionEvent {
  2435. readonly gazeSpace: XRSpace;
  2436. }
  2437. interface XRFrame {
  2438. fillPoses?(spaces: XRSpace[], baseSpace: XRSpace, transforms: Float32Array): boolean;
  2439. // Anchors
  2440. trackedAnchors?: XRAnchorSet;
  2441. // World geometries. DEPRECATED
  2442. worldInformation?: XRWorldInformation | undefined;
  2443. detectedPlanes?: XRPlaneSet | undefined;
  2444. // Hand tracking
  2445. getJointPose?(joint: XRJointSpace, baseSpace: XRSpace): XRJointPose;
  2446. fillJointRadii?(jointSpaces: XRJointSpace[], radii: Float32Array): boolean;
  2447. // Image tracking
  2448. getImageTrackingResults?(): Array<XRImageTrackingResult>;
  2449. getLightEstimate(xrLightProbe: XRLightProbe): XRLightEstimate;
  2450. }
  2451. // Plane detection
  2452. interface XRSession {
  2453. initiateRoomCapture?(): Promise<void>;
  2454. }
  2455. type XREventType = keyof XRSessionEventMap;
  2456. type XRImageTrackingState = "tracked" | "emulated";
  2457. type XRImageTrackingScore = "untrackable" | "trackable";
  2458. interface XRTrackedImageInit {
  2459. image: ImageBitmap;
  2460. widthInMeters: number;
  2461. }
  2462. interface XRImageTrackingResult {
  2463. readonly imageSpace: XRSpace;
  2464. readonly index: number;
  2465. readonly trackingState: XRImageTrackingState;
  2466. readonly measuredWidthInMeters: number;
  2467. }
  2468. interface XRPose {
  2469. readonly linearVelocity?: DOMPointReadOnly;
  2470. readonly angularVelocity?: DOMPointReadOnly;
  2471. }
  2472. type XRLightProbeInit = {
  2473. reflectionFormat: XRReflectionFormat;
  2474. };
  2475. type XRReflectionFormat = "srgba8" | "rgba16f";
  2476. interface XRSession {
  2477. readonly preferredReflectionFormat?: XRReflectionFormat;
  2478. /**
  2479. * The XRSession interface is extended with the ability to create new XRLightProbe instances.
  2480. * XRLightProbe instances have a session object, which is the XRSession that created this XRLightProbe.
  2481. *
  2482. * Can reject with with a "NotSupportedError" DOMException
  2483. */
  2484. requestLightProbe(options?: XRLightProbeInit): Promise<XRLightProbe>;
  2485. getTrackedImageScores?(): Promise<XRImageTrackingScore[]>;
  2486. }
  2487. interface XRWorldInformation {
  2488. detectedPlanes?: XRPlaneSet;
  2489. }
  2490. interface XRSessionInit {
  2491. trackedImages?: XRTrackedImageInit[];
  2492. }
  2493. interface XRLightEstimate {
  2494. readonly sphericalHarmonicsCoefficients: Float32Array;
  2495. readonly primaryLightDirection: DOMPointReadOnly;
  2496. readonly primaryLightIntensity: DOMPointReadOnly;
  2497. }
  2498. interface XREventHandler {
  2499. (evt: Event): any;
  2500. }
  2501. interface XRLightProbe extends EventTarget {
  2502. readonly probeSpace: XRSpace;
  2503. onreflectionchange: XREventHandler;
  2504. }
  2505. /**
  2506. * END: WebXR DOM Overlays Module
  2507. * https://immersive-web.github.io/dom-overlays/
  2508. */
  2509. /**
  2510. * BEGIN: WebXR Depth Sensing Moudle
  2511. * https://www.w3.org/TR/webxr-depth-sensing-1/
  2512. */
  2513. type XRDepthUsage = "cpu-optimized" | "gpu-optimized";
  2514. type XRDepthDataFormat = "luminance-alpha" | "float32";
  2515. type XRDepthStateInit = {
  2516. readonly usagePreference: XRDepthUsage[];
  2517. readonly dataFormatPreference: XRDepthDataFormat[];
  2518. };
  2519. interface XRSessionInit {
  2520. depthSensing?: XRDepthStateInit;
  2521. }
  2522. interface XRSession {
  2523. readonly depthUsage: XRDepthUsage;
  2524. readonly depthDataFormat: XRDepthDataFormat;
  2525. }
  2526. interface XRDepthInformation {
  2527. readonly width: number;
  2528. readonly height: number;
  2529. readonly normDepthBufferFromNormView: XRRigidTransform;
  2530. readonly rawValueToMeters: number;
  2531. }
  2532. interface XRCPUDepthInformation extends XRDepthInformation {
  2533. readonly data: ArrayBuffer;
  2534. getDepthInMeters(x: number, y: number): number;
  2535. }
  2536. interface XRFrame {
  2537. getDepthInformation(view: XRView): XRCPUDepthInformation | undefined;
  2538. }
  2539. interface XRWebGLDepthInformation extends XRDepthInformation {
  2540. readonly texture: WebGLTexture;
  2541. }
  2542. interface XRWebGLBinding {
  2543. getDepthInformation(view: XRView): XRWebGLDepthInformation | undefined;
  2544. }
  2545. // enabledFeatures
  2546. interface XRSession {
  2547. enabledFeatures: string[];
  2548. }
  2549. // Raw camera access
  2550. interface XRView {
  2551. readonly camera: XRCamera | undefined;
  2552. }
  2553. interface XRCamera {
  2554. readonly width: number;
  2555. readonly height: number;
  2556. }
  2557. interface XRWebGLBinding {
  2558. getCameraImage(camera: XRCamera): WebGLTexture | undefined;
  2559. }
  2560. // Mesh Detection
  2561. interface XRMesh {
  2562. meshSpace: XRSpace;
  2563. vertices: Float32Array;
  2564. indices: Uint32Array;
  2565. lastChangedTime: DOMHighResTimeStamp;
  2566. }
  2567. type XRMeshSet = Set<XRMesh>;
  2568. interface XRFrame {
  2569. detectedMeshes?: XRMeshSet;
  2570. }
  2571. // This file contains native only extensions for WebXR. These APIs are not supported in the browser yet.
  2572. // They are intended for use with either Babylon Native https://github.com/BabylonJS/BabylonNative or
  2573. // Babylon React Native: https://github.com/BabylonJS/BabylonReactNative
  2574. type XRSceneObjectType = "unknown" | "background" | "wall" | "floor" | "ceiling" | "platform" | "inferred" | "world";
  2575. interface XRSceneObject {
  2576. type: XRSceneObjectType;
  2577. }
  2578. interface XRFieldOfView {
  2579. angleLeft: number;
  2580. angleRight: number;
  2581. angleUp: number;
  2582. angleDown: number;
  2583. }
  2584. interface XRFrustum {
  2585. position: DOMPointReadOnly;
  2586. orientation: DOMPointReadOnly;
  2587. fieldOfView: XRFieldOfView;
  2588. farDistance: number;
  2589. }
  2590. interface XRPlane {
  2591. parentSceneObject?: XRSceneObject;
  2592. }
  2593. // extending the webxr XRMesh with babylon native properties
  2594. interface XRMesh {
  2595. normals?: Float32Array;
  2596. parentSceneObject?: XRSceneObject;
  2597. positions: Float32Array; // Babylon native!
  2598. }
  2599. interface XRFrustumDetectionBoundary {
  2600. type: "frustum";
  2601. frustum: XRFrustum;
  2602. }
  2603. interface XRSphereDetectionBoundary {
  2604. type: "sphere";
  2605. radius: number;
  2606. }
  2607. interface XRBoxDetectionBoundary {
  2608. type: "box";
  2609. extent: DOMPointReadOnly;
  2610. }
  2611. type XRDetectionBoundary = XRFrustumDetectionBoundary | XRSphereDetectionBoundary | XRBoxDetectionBoundary;
  2612. interface XRGeometryDetectorOptions {
  2613. detectionBoundary?: XRDetectionBoundary;
  2614. updateInterval?: number;
  2615. }
  2616. interface XRSession {
  2617. trySetFeaturePointCloudEnabled(enabled: boolean): boolean;
  2618. trySetPreferredPlaneDetectorOptions(preferredOptions: XRGeometryDetectorOptions): boolean;
  2619. trySetMeshDetectorEnabled(enabled: boolean): boolean;
  2620. trySetPreferredMeshDetectorOptions(preferredOptions: XRGeometryDetectorOptions): boolean;
  2621. }
  2622. interface XRFrame {
  2623. featurePointCloud?: Array<number> | undefined;
  2624. }
  2625. interface XRWorldInformation {
  2626. detectedMeshes?: XRMeshSet;
  2627. }
  2628. }