index.d.ts 200 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465
  1. /// <reference path="./global.d.ts" />
  2. import { ALPHA_MODES } from '@pixi/constants';
  3. import type { ArrayFixed } from '@pixi/utils';
  4. import type { BaseTexture as BaseTexture_2 } from '@pixi/core';
  5. import { BLEND_MODES } from '@pixi/constants';
  6. import { BUFFER_BITS } from '@pixi/constants';
  7. import { BUFFER_TYPE } from '@pixi/constants';
  8. import { CLEAR_MODES } from '@pixi/constants';
  9. import type { COLOR_MASK_BITS } from '@pixi/constants';
  10. import type { Dict } from '@pixi/utils';
  11. import { DRAW_MODES } from '@pixi/constants';
  12. import { EventEmitter } from '@pixi/utils';
  13. import { FORMATS } from '@pixi/constants';
  14. import { GC_MODES } from '@pixi/constants';
  15. import type { IPointData } from '@pixi/math';
  16. import type { ISize } from '@pixi/math';
  17. import type { ISpriteMaskFilter as ISpriteMaskFilter_2 } from '@pixi/core';
  18. import { MASK_TYPES } from '@pixi/constants';
  19. import { Matrix } from '@pixi/math';
  20. import type { MIPMAP_MODES } from '@pixi/constants';
  21. import { MSAA_QUALITY } from '@pixi/constants';
  22. import { Point } from '@pixi/math';
  23. import { Rectangle } from '@pixi/math';
  24. import { RENDERER_TYPE } from '@pixi/constants';
  25. import { Runner } from '@pixi/runner';
  26. import { SCALE_MODES } from '@pixi/constants';
  27. import { TARGETS } from '@pixi/constants';
  28. import { TYPES } from '@pixi/constants';
  29. import type { WRAP_MODES } from '@pixi/constants';
  30. /**
  31. * Renderer dedicated to drawing and batching sprites.
  32. *
  33. * This is the default batch renderer. It buffers objects
  34. * with texture-based geometries and renders them in
  35. * batches. It uploads multiple textures to the GPU to
  36. * reduce to the number of draw calls.
  37. * @memberof PIXI
  38. */
  39. export declare class AbstractBatchRenderer extends ObjectRenderer {
  40. /** The WebGL state in which this renderer will work. */
  41. readonly state: State;
  42. /**
  43. * The number of bufferable objects before a flush
  44. * occurs automatically.
  45. * @default settings.SPRITE_BATCH_SIZE * 4
  46. */
  47. size: number;
  48. /**
  49. * Maximum number of textures that can be uploaded to
  50. * the GPU under the current context. It is initialized
  51. * properly in `this.contextChange`.
  52. * @see PIXI.AbstractBatchRenderer#contextChange
  53. * @readonly
  54. */
  55. MAX_TEXTURES: number;
  56. /**
  57. * This is used to generate a shader that can
  58. * color each vertex based on a `aTextureId`
  59. * attribute that points to an texture in `uSampler`.
  60. *
  61. * This enables the objects with different textures
  62. * to be drawn in the same draw call.
  63. *
  64. * You can customize your shader by creating your
  65. * custom shader generator.
  66. */
  67. protected shaderGenerator: BatchShaderGenerator;
  68. /**
  69. * The class that represents the geometry of objects
  70. * that are going to be batched with this.
  71. * @member {object}
  72. * @default PIXI.BatchGeometry
  73. */
  74. protected geometryClass: typeof BatchGeometry;
  75. /**
  76. * Size of data being buffered per vertex in the
  77. * attribute buffers (in floats). By default, the
  78. * batch-renderer plugin uses 6:
  79. *
  80. * | aVertexPosition | 2 |
  81. * |-----------------|---|
  82. * | aTextureCoords | 2 |
  83. * | aColor | 1 |
  84. * | aTextureId | 1 |
  85. * @readonly
  86. */
  87. protected vertexSize: number;
  88. /** Total count of all vertices used by the currently buffered objects. */
  89. protected _vertexCount: number;
  90. /** Total count of all indices used by the currently buffered objects. */
  91. protected _indexCount: number;
  92. /**
  93. * Buffer of objects that are yet to be rendered.
  94. * @member {PIXI.DisplayObject[]}
  95. */
  96. protected _bufferedElements: Array<IBatchableElement>;
  97. /**
  98. * Data for texture batch builder, helps to save a bit of CPU on a pass.
  99. * @member {PIXI.BaseTexture[]}
  100. */
  101. protected _bufferedTextures: Array<BaseTexture>;
  102. /** Number of elements that are buffered and are waiting to be flushed. */
  103. protected _bufferSize: number;
  104. /**
  105. * This shader is generated by `this.shaderGenerator`.
  106. *
  107. * It is generated specifically to handle the required
  108. * number of textures being batched together.
  109. */
  110. protected _shader: Shader;
  111. /**
  112. * A flush may occur multiple times in a single
  113. * frame. On iOS devices or when
  114. * `settings.CAN_UPLOAD_SAME_BUFFER` is false, the
  115. * batch renderer does not upload data to the same
  116. * `WebGLBuffer` for performance reasons.
  117. *
  118. * This is the index into `packedGeometries` that points to
  119. * geometry holding the most recent buffers.
  120. */
  121. protected _flushId: number;
  122. /**
  123. * Pool of `ViewableBuffer` objects that are sorted in
  124. * order of increasing size. The flush method uses
  125. * the buffer with the least size above the amount
  126. * it requires. These are used for passing attributes.
  127. *
  128. * The first buffer has a size of 8; each subsequent
  129. * buffer has double capacity of its previous.
  130. * @member {PIXI.ViewableBuffer[]}
  131. * @see PIXI.AbstractBatchRenderer#getAttributeBuffer
  132. */
  133. protected _aBuffers: Array<ViewableBuffer>;
  134. /**
  135. * Pool of `Uint16Array` objects that are sorted in
  136. * order of increasing size. The flush method uses
  137. * the buffer with the least size above the amount
  138. * it requires. These are used for passing indices.
  139. *
  140. * The first buffer has a size of 12; each subsequent
  141. * buffer has double capacity of its previous.
  142. * @member {Uint16Array[]}
  143. * @see PIXI.AbstractBatchRenderer#getIndexBuffer
  144. */
  145. protected _iBuffers: Array<Uint16Array>;
  146. protected _dcIndex: number;
  147. protected _aIndex: number;
  148. protected _iIndex: number;
  149. protected _attributeBuffer: ViewableBuffer;
  150. protected _indexBuffer: Uint16Array;
  151. protected _tempBoundTextures: BaseTexture[];
  152. /**
  153. * Pool of `this.geometryClass` geometry objects
  154. * that store buffers. They are used to pass data
  155. * to the shader on each draw call.
  156. *
  157. * These are never re-allocated again, unless a
  158. * context change occurs; however, the pool may
  159. * be expanded if required.
  160. * @member {PIXI.Geometry[]}
  161. * @see PIXI.AbstractBatchRenderer.contextChange
  162. */
  163. private _packedGeometries;
  164. /**
  165. * Size of `this._packedGeometries`. It can be expanded
  166. * if more than `this._packedGeometryPoolSize` flushes
  167. * occur in a single frame.
  168. */
  169. private _packedGeometryPoolSize;
  170. /**
  171. * This will hook onto the renderer's `contextChange`
  172. * and `prerender` signals.
  173. * @param {PIXI.Renderer} renderer - The renderer this works for.
  174. */
  175. constructor(renderer: Renderer);
  176. /**
  177. * Handles the `contextChange` signal.
  178. *
  179. * It calculates `this.MAX_TEXTURES` and allocating the packed-geometry object pool.
  180. */
  181. contextChange(): void;
  182. /** Makes sure that static and dynamic flush pooled objects have correct dimensions. */
  183. initFlushBuffers(): void;
  184. /** Handles the `prerender` signal. It ensures that flushes start from the first geometry object again. */
  185. onPrerender(): void;
  186. /**
  187. * Buffers the "batchable" object. It need not be rendered immediately.
  188. * @param {PIXI.DisplayObject} element - the element to render when
  189. * using this renderer
  190. */
  191. render(element: IBatchableElement): void;
  192. buildTexturesAndDrawCalls(): void;
  193. /**
  194. * Populating drawcalls for rendering
  195. * @param texArray
  196. * @param start
  197. * @param finish
  198. */
  199. buildDrawCalls(texArray: BatchTextureArray, start: number, finish: number): void;
  200. /**
  201. * Bind textures for current rendering
  202. * @param texArray
  203. */
  204. bindAndClearTexArray(texArray: BatchTextureArray): void;
  205. updateGeometry(): void;
  206. drawBatches(): void;
  207. /** Renders the content _now_ and empties the current batch. */
  208. flush(): void;
  209. /** Starts a new sprite batch. */
  210. start(): void;
  211. /** Stops and flushes the current batch. */
  212. stop(): void;
  213. /** Destroys this `AbstractBatchRenderer`. It cannot be used again. */
  214. destroy(): void;
  215. /**
  216. * Fetches an attribute buffer from `this._aBuffers` that can hold atleast `size` floats.
  217. * @param size - minimum capacity required
  218. * @returns - buffer than can hold atleast `size` floats
  219. */
  220. getAttributeBuffer(size: number): ViewableBuffer;
  221. /**
  222. * Fetches an index buffer from `this._iBuffers` that can
  223. * have at least `size` capacity.
  224. * @param size - minimum required capacity
  225. * @returns - buffer that can fit `size` indices.
  226. */
  227. getIndexBuffer(size: number): Uint16Array;
  228. /**
  229. * Takes the four batching parameters of `element`, interleaves
  230. * and pushes them into the batching attribute/index buffers given.
  231. *
  232. * It uses these properties: `vertexData` `uvs`, `textureId` and
  233. * `indicies`. It also uses the "tint" of the base-texture, if
  234. * present.
  235. * @param {PIXI.DisplayObject} element - element being rendered
  236. * @param attributeBuffer - attribute buffer.
  237. * @param indexBuffer - index buffer
  238. * @param aIndex - number of floats already in the attribute buffer
  239. * @param iIndex - number of indices already in `indexBuffer`
  240. */
  241. packInterleavedGeometry(element: IBatchableElement, attributeBuffer: ViewableBuffer, indexBuffer: Uint16Array, aIndex: number, iIndex: number): void;
  242. /**
  243. * Pool of `BatchDrawCall` objects that `flush` used
  244. * to create "batches" of the objects being rendered.
  245. *
  246. * These are never re-allocated again.
  247. * Shared between all batch renderers because it can be only one "flush" working at the moment.
  248. * @member {PIXI.BatchDrawCall[]}
  249. */
  250. static _drawCallPool: Array<BatchDrawCall>;
  251. /**
  252. * Pool of `BatchDrawCall` objects that `flush` used
  253. * to create "batches" of the objects being rendered.
  254. *
  255. * These are never re-allocated again.
  256. * Shared between all batch renderers because it can be only one "flush" working at the moment.
  257. * @member {PIXI.BatchTextureArray[]}
  258. */
  259. static _textureArrayPool: Array<BatchTextureArray>;
  260. }
  261. /**
  262. * System plugin to the renderer to manage specific types of masking operations.
  263. * @memberof PIXI
  264. */
  265. declare class AbstractMaskSystem implements ISystem {
  266. /**
  267. * The mask stack
  268. * @member {PIXI.MaskData[]}
  269. */
  270. protected maskStack: Array<MaskData>;
  271. /**
  272. * Constant for gl.enable
  273. * @private
  274. */
  275. protected glConst: number;
  276. protected renderer: Renderer;
  277. /**
  278. * @param renderer - The renderer this System works for.
  279. */
  280. constructor(renderer: Renderer);
  281. /** Gets count of masks of certain type. */
  282. getStackLength(): number;
  283. /**
  284. * Changes the mask stack that is used by this System.
  285. * @param {PIXI.MaskData[]} maskStack - The mask stack
  286. */
  287. setMaskStack(maskStack: Array<MaskData>): void;
  288. /**
  289. * Setup renderer to use the current mask data.
  290. * @private
  291. */
  292. protected _useCurrent(): void;
  293. /** Destroys the mask stack. */
  294. destroy(): void;
  295. }
  296. /**
  297. * Resource that can manage several resource (items) inside.
  298. * All resources need to have the same pixel size.
  299. * Parent class for CubeResource and ArrayResource
  300. * @memberof PIXI
  301. */
  302. export declare abstract class AbstractMultiResource extends Resource {
  303. /** Number of elements in array. */
  304. readonly length: number;
  305. /**
  306. * Collection of partial baseTextures that correspond to resources.
  307. * @readonly
  308. */
  309. items: Array<BaseTexture>;
  310. /**
  311. * Dirty IDs for each part.
  312. * @readonly
  313. */
  314. itemDirtyIds: Array<number>;
  315. /**
  316. * Promise when loading.
  317. * @default null
  318. */
  319. private _load;
  320. /** Bound baseTexture, there can only be one. */
  321. baseTexture: BaseTexture;
  322. /**
  323. * @param length
  324. * @param options - Options to for Resource constructor
  325. * @param {number} [options.width] - Width of the resource
  326. * @param {number} [options.height] - Height of the resource
  327. */
  328. constructor(length: number, options?: ISize);
  329. /**
  330. * Used from ArrayResource and CubeResource constructors.
  331. * @param resources - Can be resources, image elements, canvas, etc. ,
  332. * length should be same as constructor length
  333. * @param options - Detect options for resources
  334. */
  335. protected initFromArray(resources: Array<any>, options?: IAutoDetectOptions): void;
  336. /** Destroy this BaseImageResource. */
  337. dispose(): void;
  338. /**
  339. * Set a baseTexture by ID
  340. * @param baseTexture
  341. * @param index - Zero-based index of resource to set
  342. * @returns - Instance for chaining
  343. */
  344. abstract addBaseTextureAt(baseTexture: BaseTexture, index: number): this;
  345. /**
  346. * Set a resource by ID
  347. * @param resource
  348. * @param index - Zero-based index of resource to set
  349. * @returns - Instance for chaining
  350. */
  351. addResourceAt(resource: Resource, index: number): this;
  352. /**
  353. * Set the parent base texture.
  354. * @param baseTexture
  355. */
  356. bind(baseTexture: BaseTexture): void;
  357. /**
  358. * Unset the parent base texture.
  359. * @param baseTexture
  360. */
  361. unbind(baseTexture: BaseTexture): void;
  362. /**
  363. * Load all the resources simultaneously
  364. * @returns - When load is resolved
  365. */
  366. load(): Promise<this>;
  367. }
  368. /**
  369. * The AbstractRenderer is the base for a PixiJS Renderer. It is extended by the {@link PIXI.CanvasRenderer}
  370. * and {@link PIXI.Renderer} which can be used for rendering a PixiJS scene.
  371. * @abstract
  372. * @class
  373. * @extends PIXI.utils.EventEmitter
  374. * @memberof PIXI
  375. */
  376. export declare abstract class AbstractRenderer extends EventEmitter {
  377. resolution: number;
  378. clearBeforeRender?: boolean;
  379. readonly options: IRendererOptions;
  380. readonly type: RENDERER_TYPE;
  381. readonly screen: Rectangle;
  382. readonly view: HTMLCanvasElement;
  383. readonly plugins: IRendererPlugins;
  384. readonly useContextAlpha: boolean | 'notMultiplied';
  385. readonly autoDensity: boolean;
  386. readonly preserveDrawingBuffer: boolean;
  387. protected _backgroundColor: number;
  388. protected _backgroundColorString: string;
  389. _backgroundColorRgba: number[];
  390. _lastObjectRendered: IRenderableObject;
  391. /**
  392. * @param type - The renderer type.
  393. * @param {PIXI.IRendererOptions} [options] - The optional renderer parameters.
  394. * @param {boolean} [options.antialias=false] -
  395. * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
  396. * @param {boolean} [options.autoDensity=false] -
  397. * Whether the CSS dimensions of the renderer's view should be resized automatically.
  398. * @param {number} [options.backgroundAlpha=1] -
  399. * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
  400. * @param {number} [options.backgroundColor=0x000000] -
  401. * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
  402. * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.
  403. * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.
  404. * @param {number} [options.height=600] - The height of the renderer's view.
  405. * @param {string} [options.powerPreference] -
  406. * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
  407. * can be `'default'`, `'high-performance'` or `'low-power'`.
  408. * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
  409. * while setting to `'low-power'` will prioritize power saving over rendering performance.
  410. * @param {boolean} [options.premultipliedAlpha=true] -
  411. * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
  412. * @param {boolean} [options.preserveDrawingBuffer=false] -
  413. * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
  414. * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
  415. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -
  416. * The resolution / device pixel ratio of the renderer.
  417. * @param {boolean} [options.transparent] -
  418. * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \
  419. * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.
  420. * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -
  421. * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
  422. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  423. * If you want to set transparency, please use `backgroundAlpha`. \
  424. * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
  425. * set to `true` and `premultipliedAlpha` will be to `false`.
  426. * @param {HTMLCanvasElement} [options.view=null] -
  427. * The canvas to use as the view. If omitted, a new canvas will be created.
  428. * @param {number} [options.width=800] - The width of the renderer's view.
  429. */
  430. constructor(type?: RENDERER_TYPE, options?: IRendererOptions);
  431. /**
  432. * Initialize the plugins.
  433. * @protected
  434. * @param {object} staticMap - The dictionary of statically saved plugins.
  435. */
  436. initPlugins(staticMap: IRendererPlugins): void;
  437. /**
  438. * Same as view.width, actual number of pixels in the canvas by horizontal.
  439. * @member {number}
  440. * @readonly
  441. * @default 800
  442. */
  443. get width(): number;
  444. /**
  445. * Same as view.height, actual number of pixels in the canvas by vertical.
  446. * @member {number}
  447. * @readonly
  448. * @default 600
  449. */
  450. get height(): number;
  451. /**
  452. * Resizes the screen and canvas as close as possible to the specified width and height.
  453. * Canvas dimensions are multiplied by resolution and rounded to the nearest integers.
  454. * The new canvas dimensions divided by the resolution become the new screen dimensions.
  455. * @param desiredScreenWidth - The desired width of the screen.
  456. * @param desiredScreenHeight - The desired height of the screen.
  457. */
  458. resize(desiredScreenWidth: number, desiredScreenHeight: number): void;
  459. /**
  460. * Useful function that returns a texture of the display object that can then be used to create sprites
  461. * This can be quite useful if your displayObject is complicated and needs to be reused multiple times.
  462. * @method PIXI.AbstractRenderer#generateTexture
  463. * @param displayObject - The displayObject the object will be generated from.
  464. * @param {object} options - Generate texture options.
  465. * @param {PIXI.SCALE_MODES} options.scaleMode - The scale mode of the texture.
  466. * @param {number} options.resolution - The resolution / device pixel ratio of the texture being generated.
  467. * @param {PIXI.Rectangle} options.region - The region of the displayObject, that shall be rendered,
  468. * if no region is specified, defaults to the local bounds of the displayObject.
  469. * @param {PIXI.MSAA_QUALITY} options.multisample - The number of samples of the frame buffer.
  470. * @returns A texture of the graphics object.
  471. */
  472. generateTexture(displayObject: IRenderableObject, options?: IGenerateTextureOptions): RenderTexture;
  473. /**
  474. * Please use the options argument instead.
  475. * @method PIXI.AbstractRenderer#generateTexture
  476. * @deprecated Since 6.1.0
  477. * @param displayObject - The displayObject the object will be generated from.
  478. * @param scaleMode - The scale mode of the texture.
  479. * @param resolution - The resolution / device pixel ratio of the texture being generated.
  480. * @param region - The region of the displayObject, that shall be rendered,
  481. * if no region is specified, defaults to the local bounds of the displayObject.
  482. * @returns A texture of the graphics object.
  483. */
  484. generateTexture(displayObject: IRenderableObject, scaleMode?: SCALE_MODES, resolution?: number, region?: Rectangle): RenderTexture;
  485. /**
  486. * Adds a new system to the renderer.
  487. * @param ClassRef - Class reference
  488. * @param name - Property name for system
  489. * @returns Return instance of renderer
  490. */
  491. abstract addSystem(ClassRef: ISystemConstructor, name: string): this;
  492. abstract render(displayObject: IRenderableObject, options?: IRendererRenderOptions): void;
  493. /**
  494. * Removes everything from the renderer and optionally removes the Canvas DOM element.
  495. * @param [removeView=false] - Removes the Canvas element from the DOM.
  496. */
  497. destroy(removeView?: boolean): void;
  498. /**
  499. * The background color to fill if not transparent
  500. * @member {number}
  501. */
  502. get backgroundColor(): number;
  503. set backgroundColor(value: number);
  504. /**
  505. * The background color alpha. Setting this to 0 will make the canvas transparent.
  506. * @member {number}
  507. */
  508. get backgroundAlpha(): number;
  509. set backgroundAlpha(value: number);
  510. }
  511. /**
  512. * A resource that contains a number of sources.
  513. * @memberof PIXI
  514. */
  515. export declare class ArrayResource extends AbstractMultiResource {
  516. /**
  517. * @param source - Number of items in array or the collection
  518. * of image URLs to use. Can also be resources, image elements, canvas, etc.
  519. * @param options - Options to apply to {@link PIXI.autoDetectResource}
  520. * @param {number} [options.width] - Width of the resource
  521. * @param {number} [options.height] - Height of the resource
  522. */
  523. constructor(source: number | Array<any>, options?: ISize);
  524. /**
  525. * Set a baseTexture by ID,
  526. * ArrayResource just takes resource from it, nothing more
  527. * @param baseTexture
  528. * @param index - Zero-based index of resource to set
  529. * @returns - Instance for chaining
  530. */
  531. addBaseTextureAt(baseTexture: BaseTexture, index: number): this;
  532. /**
  533. * Add binding
  534. * @param baseTexture
  535. */
  536. bind(baseTexture: BaseTexture): void;
  537. /**
  538. * Upload the resources to the GPU.
  539. * @param renderer
  540. * @param texture
  541. * @param glTexture
  542. * @returns - whether texture was uploaded
  543. */
  544. upload(renderer: Renderer, texture: BaseTexture, glTexture: GLTexture): boolean;
  545. }
  546. /**
  547. * Holds the information for a single attribute structure required to render geometry.
  548. *
  549. * This does not contain the actual data, but instead has a buffer id that maps to a {@link PIXI.Buffer}
  550. * This can include anything from positions, uvs, normals, colors etc.
  551. * @memberof PIXI
  552. */
  553. export declare class Attribute {
  554. buffer: number;
  555. size: number;
  556. normalized: boolean;
  557. type: TYPES;
  558. stride: number;
  559. start: number;
  560. instance: boolean;
  561. /**
  562. * @param buffer - the id of the buffer that this attribute will look for
  563. * @param size - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2.
  564. * @param normalized - should the data be normalized.
  565. * @param {PIXI.TYPES} [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {@link PIXI.TYPES} to see the ones available
  566. * @param [stride=0] - How far apart, in bytes, the start of each value is. (used for interleaving data)
  567. * @param [start=0] - How far into the array to start reading values (used for interleaving data)
  568. * @param [instance=false] - Whether the geometry is instanced.
  569. */
  570. constructor(buffer: number, size?: number, normalized?: boolean, type?: TYPES, stride?: number, start?: number, instance?: boolean);
  571. /** Destroys the Attribute. */
  572. destroy(): void;
  573. /**
  574. * Helper function that creates an Attribute based on the information provided
  575. * @param buffer - the id of the buffer that this attribute will look for
  576. * @param [size=0] - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2
  577. * @param [normalized=false] - should the data be normalized.
  578. * @param [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {@link PIXI.TYPES} to see the ones available
  579. * @param [stride=0] - How far apart, in bytes, the start of each value is. (used for interleaving data)
  580. * @returns - A new {@link PIXI.Attribute} based on the information provided
  581. */
  582. static from(buffer: number, size?: number, normalized?: boolean, type?: TYPES, stride?: number): Attribute;
  583. }
  584. /**
  585. * This helper function will automatically detect which renderer you should be using.
  586. * WebGL is the preferred renderer as it is a lot faster. If WebGL is not supported by
  587. * the browser then this function will return a canvas renderer.
  588. * @memberof PIXI
  589. * @function autoDetectRenderer
  590. * @param {PIXI.IRendererOptionsAuto} [options] - The optional renderer parameters.
  591. * @param {boolean} [options.antialias=false] -
  592. * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
  593. * @param {boolean} [options.autoDensity=false] -
  594. * Whether the CSS dimensions of the renderer's view should be resized automatically.
  595. * @param {number} [options.backgroundAlpha=1] -
  596. * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
  597. * @param {number} [options.backgroundColor=0x000000] -
  598. * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
  599. * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.
  600. * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.
  601. * @param {boolean} [options.forceCanvas=false] -
  602. * Force using {@link PIXI.CanvasRenderer}, even if WebGL is available. This option only is available when
  603. * using **pixi.js-legacy** or **@pixi/canvas-renderer** packages, otherwise it is ignored.
  604. * @param {number} [options.height=600] - The height of the renderer's view.
  605. * @param {string} [options.powerPreference] -
  606. * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
  607. * can be `'default'`, `'high-performance'` or `'low-power'`.
  608. * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
  609. * while setting to `'low-power'` will prioritize power saving over rendering performance.
  610. * @param {boolean} [options.premultipliedAlpha=true] -
  611. * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
  612. * @param {boolean} [options.preserveDrawingBuffer=false] -
  613. * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
  614. * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
  615. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -
  616. * The resolution / device pixel ratio of the renderer.
  617. * @param {boolean} [options.transparent] -
  618. * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \
  619. * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.
  620. * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -
  621. * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
  622. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  623. * If you want to set transparency, please use `backgroundAlpha`. \
  624. * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
  625. * set to `true` and `premultipliedAlpha` will be to `false`.
  626. * @param {HTMLCanvasElement} [options.view=null] -
  627. * The canvas to use as the view. If omitted, a new canvas will be created.
  628. * @param {number} [options.width=800] - The width of the renderer's view.
  629. * @returns {PIXI.Renderer|PIXI.CanvasRenderer}
  630. * Returns {@link PIXI.Renderer} if WebGL is available, otherwise {@link PIXI.CanvasRenderer}.
  631. */
  632. export declare function autoDetectRenderer(options?: IRendererOptionsAuto): AbstractRenderer;
  633. /**
  634. * Create a resource element from a single source element. This
  635. * auto-detects which type of resource to create. All resources that
  636. * are auto-detectable must have a static `test` method and a constructor
  637. * with the arguments `(source, options?)`. Currently, the supported
  638. * resources for auto-detection include:
  639. * - {@link PIXI.ImageResource}
  640. * - {@link PIXI.CanvasResource}
  641. * - {@link PIXI.VideoResource}
  642. * - {@link PIXI.SVGResource}
  643. * - {@link PIXI.BufferResource}
  644. * @static
  645. * @memberof PIXI
  646. * @function autoDetectResource
  647. * @param {string|*} source - Resource source, this can be the URL to the resource,
  648. * a typed-array (for BufferResource), HTMLVideoElement, SVG data-uri
  649. * or any other resource that can be auto-detected. If not resource is
  650. * detected, it's assumed to be an ImageResource.
  651. * @param {object} [options] - Pass-through options to use for Resource
  652. * @param {number} [options.width] - Width of BufferResource or SVG rasterization
  653. * @param {number} [options.height] - Height of BufferResource or SVG rasterization
  654. * @param {boolean} [options.autoLoad=true] - Image, SVG and Video flag to start loading
  655. * @param {number} [options.scale=1] - SVG source scale. Overridden by width, height
  656. * @param {boolean} [options.createBitmap=PIXI.settings.CREATE_IMAGE_BITMAP] - Image option to create Bitmap object
  657. * @param {boolean} [options.crossorigin=true] - Image and Video option to set crossOrigin
  658. * @param {boolean} [options.autoPlay=true] - Video option to start playing video immediately
  659. * @param {number} [options.updateFPS=0] - Video option to update how many times a second the
  660. * texture should be updated from the video. Leave at 0 to update at every render
  661. * @returns {PIXI.Resource} The created resource.
  662. */
  663. export declare function autoDetectResource<R extends Resource, RO>(source: unknown, options?: RO): R;
  664. /**
  665. * Base for all the image/canvas resources.
  666. * @memberof PIXI
  667. */
  668. export declare class BaseImageResource extends Resource {
  669. /**
  670. * The source element.
  671. * @member {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement}
  672. * @readonly
  673. */
  674. source: ImageSource;
  675. /**
  676. * If set to `true`, will force `texImage2D` over `texSubImage2D` for uploading.
  677. * Certain types of media (e.g. video) using `texImage2D` is more performant.
  678. * @default false
  679. * @private
  680. */
  681. noSubImage: boolean;
  682. /**
  683. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement} source
  684. */
  685. constructor(source: ImageSource);
  686. /**
  687. * Set cross origin based detecting the url and the crossorigin
  688. * @param element - Element to apply crossOrigin
  689. * @param url - URL to check
  690. * @param crossorigin - Cross origin value to use
  691. */
  692. static crossOrigin(element: HTMLImageElement | HTMLVideoElement, url: string, crossorigin?: boolean | string): void;
  693. /**
  694. * Upload the texture to the GPU.
  695. * @param renderer - Upload to the renderer
  696. * @param baseTexture - Reference to parent texture
  697. * @param glTexture
  698. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement} [source] - (optional)
  699. * @returns - true is success
  700. */
  701. upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture, source?: ImageSource): boolean;
  702. /**
  703. * Checks if source width/height was changed, resize can cause extra baseTexture update.
  704. * Triggers one update in any case.
  705. */
  706. update(): void;
  707. /** Destroy this {@link BaseImageResource} */
  708. dispose(): void;
  709. }
  710. export declare interface BaseRenderTexture extends GlobalMixins.BaseRenderTexture, BaseTexture {
  711. }
  712. /**
  713. * A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  714. *
  715. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded
  716. * otherwise black rectangles will be drawn instead.
  717. *
  718. * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position
  719. * and rotation of the given Display Objects is ignored. For example:
  720. *
  721. * ```js
  722. * let renderer = PIXI.autoDetectRenderer();
  723. * let baseRenderTexture = new PIXI.BaseRenderTexture({ width: 800, height: 600 });
  724. * let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
  725. * let sprite = PIXI.Sprite.from("spinObj_01.png");
  726. *
  727. * sprite.position.x = 800/2;
  728. * sprite.position.y = 600/2;
  729. * sprite.anchor.x = 0.5;
  730. * sprite.anchor.y = 0.5;
  731. *
  732. * renderer.render(sprite, {renderTexture});
  733. * ```
  734. *
  735. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  736. * you can clear the transform
  737. *
  738. * ```js
  739. *
  740. * sprite.setTransform()
  741. *
  742. * let baseRenderTexture = new PIXI.BaseRenderTexture({ width: 100, height: 100 });
  743. * let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
  744. *
  745. * renderer.render(sprite, {renderTexture}); // Renders to center of RenderTexture
  746. * ```
  747. * @memberof PIXI
  748. */
  749. export declare class BaseRenderTexture extends BaseTexture {
  750. clearColor: number[];
  751. framebuffer: Framebuffer;
  752. /** The data structure for the stencil masks. */
  753. maskStack: Array<MaskData>;
  754. /** The data structure for the filters. */
  755. filterStack: Array<any>;
  756. /**
  757. * @param options
  758. * @param {number} [options.width=100] - The width of the base render texture.
  759. * @param {number} [options.height=100] - The height of the base render texture.
  760. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES}
  761. * for possible values.
  762. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio
  763. * of the texture being generated.
  764. * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer.
  765. */
  766. constructor(options?: IBaseTextureOptions);
  767. /**
  768. * Resizes the BaseRenderTexture.
  769. * @param desiredWidth - The desired width to resize to.
  770. * @param desiredHeight - The desired height to resize to.
  771. */
  772. resize(desiredWidth: number, desiredHeight: number): void;
  773. /**
  774. * Frees the texture and framebuffer from WebGL memory without destroying this texture object.
  775. * This means you can still use the texture later which will upload it to GPU
  776. * memory again.
  777. * @fires PIXI.BaseTexture#dispose
  778. */
  779. dispose(): void;
  780. /** Destroys this texture. */
  781. destroy(): void;
  782. }
  783. export declare interface BaseTexture extends GlobalMixins.BaseTexture, EventEmitter {
  784. }
  785. /**
  786. * A Texture stores the information that represents an image.
  787. * All textures have a base texture, which contains information about the source.
  788. * Therefore you can have many textures all using a single BaseTexture
  789. * @memberof PIXI
  790. * @typeParam R - The BaseTexture's Resource type.
  791. * @typeParam RO - The options for constructing resource.
  792. */
  793. export declare class BaseTexture<R extends Resource = Resource, RO = IAutoDetectOptions> extends EventEmitter {
  794. /**
  795. * The width of the base texture set when the image has loaded
  796. * @readonly
  797. */
  798. width: number;
  799. /**
  800. * The height of the base texture set when the image has loaded
  801. * @readonly
  802. */
  803. height: number;
  804. /**
  805. * The resolution / device pixel ratio of the texture
  806. * @readonly
  807. * @default PIXI.settings.RESOLUTION
  808. */
  809. resolution: number;
  810. /**
  811. * How to treat premultiplied alpha, see {@link PIXI.ALPHA_MODES}.
  812. * @member {PIXI.ALPHA_MODES}
  813. * @default PIXI.ALPHA_MODES.UNPACK
  814. */
  815. alphaMode?: ALPHA_MODES;
  816. /**
  817. * Anisotropic filtering level of texture
  818. * @member {number}
  819. * @default PIXI.settings.ANISOTROPIC_LEVEL
  820. */
  821. anisotropicLevel?: number;
  822. /**
  823. * The pixel format of the texture
  824. * @default PIXI.FORMATS.RGBA
  825. */
  826. format?: FORMATS;
  827. /**
  828. * The type of resource data
  829. * @default PIXI.TYPES.UNSIGNED_BYTE
  830. */
  831. type?: TYPES;
  832. /**
  833. * The target type
  834. * @default PIXI.TARGETS.TEXTURE_2D
  835. */
  836. target?: TARGETS;
  837. /**
  838. * Global unique identifier for this BaseTexture
  839. * @protected
  840. */
  841. readonly uid: number;
  842. /**
  843. * Used by automatic texture Garbage Collection, stores last GC tick when it was bound
  844. * @protected
  845. */
  846. touched: number;
  847. /**
  848. * Whether or not the texture is a power of two, try to use power of two textures as much
  849. * as you can
  850. * @readonly
  851. * @default false
  852. */
  853. isPowerOfTwo: boolean;
  854. /**
  855. * The map of render context textures where this is bound
  856. * @private
  857. */
  858. _glTextures: {
  859. [key: number]: GLTexture;
  860. };
  861. /**
  862. * Used by TextureSystem to only update texture to the GPU when needed.
  863. * Please call `update()` to increment it.
  864. * @readonly
  865. */
  866. dirtyId: number;
  867. /**
  868. * Used by TextureSystem to only update texture style when needed.
  869. * @protected
  870. */
  871. dirtyStyleId: number;
  872. /**
  873. * Currently default cache ID.
  874. * @member {string}
  875. */
  876. cacheId: string;
  877. /**
  878. * Generally speaking means when resource is loaded.
  879. * @readonly
  880. * @member {boolean}
  881. */
  882. valid: boolean;
  883. /**
  884. * The collection of alternative cache ids, since some BaseTextures
  885. * can have more than one ID, short name and longer full URL
  886. * @member {Array<string>}
  887. * @readonly
  888. */
  889. textureCacheIds: Array<string>;
  890. /**
  891. * Flag if BaseTexture has been destroyed.
  892. * @member {boolean}
  893. * @readonly
  894. */
  895. destroyed: boolean;
  896. /**
  897. * The resource used by this BaseTexture, there can only
  898. * be one resource per BaseTexture, but textures can share
  899. * resources.
  900. * @member {PIXI.Resource}
  901. * @readonly
  902. */
  903. resource: R;
  904. /**
  905. * Number of the texture batch, used by multi-texture renderers
  906. * @member {number}
  907. */
  908. _batchEnabled: number;
  909. /**
  910. * Location inside texture batch, used by multi-texture renderers
  911. * @member {number}
  912. */
  913. _batchLocation: number;
  914. /**
  915. * Whether its a part of another texture, handled by ArrayResource or CubeResource
  916. * @member {PIXI.BaseTexture}
  917. */
  918. parentTextureArray: BaseTexture;
  919. private _mipmap?;
  920. private _scaleMode?;
  921. private _wrapMode?;
  922. /**
  923. * @param {PIXI.Resource|string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} [resource=null] -
  924. * The current resource to use, for things that aren't Resource objects, will be converted
  925. * into a Resource.
  926. * @param options - Collection of options
  927. * @param {PIXI.MIPMAP_MODES} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture
  928. * @param {number} [options.anisotropicLevel=PIXI.settings.ANISOTROPIC_LEVEL] - Anisotropic filtering level of texture
  929. * @param {PIXI.WRAP_MODES} [options.wrapMode=PIXI.settings.WRAP_MODE] - Wrap mode for textures
  930. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - Default scale mode, linear, nearest
  931. * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type
  932. * @param {PIXI.TYPES} [options.type=PIXI.TYPES.UNSIGNED_BYTE] - GL data type
  933. * @param {PIXI.TARGETS} [options.target=PIXI.TARGETS.TEXTURE_2D] - GL texture target
  934. * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.UNPACK] - Pre multiply the image alpha
  935. * @param {number} [options.width=0] - Width of the texture
  936. * @param {number} [options.height=0] - Height of the texture
  937. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - Resolution of the base texture
  938. * @param {object} [options.resourceOptions] - Optional resource options,
  939. * see {@link PIXI.autoDetectResource autoDetectResource}
  940. */
  941. constructor(resource?: R | ImageSource | string | any, options?: IBaseTextureOptions<RO>);
  942. /**
  943. * Pixel width of the source of this texture
  944. * @readonly
  945. */
  946. get realWidth(): number;
  947. /**
  948. * Pixel height of the source of this texture
  949. * @readonly
  950. */
  951. get realHeight(): number;
  952. /**
  953. * Mipmap mode of the texture, affects downscaled images
  954. * @default PIXI.settings.MIPMAP_TEXTURES
  955. */
  956. get mipmap(): MIPMAP_MODES;
  957. set mipmap(value: MIPMAP_MODES);
  958. /**
  959. * The scale mode to apply when scaling this texture
  960. * @default PIXI.settings.SCALE_MODE
  961. */
  962. get scaleMode(): SCALE_MODES;
  963. set scaleMode(value: SCALE_MODES);
  964. /**
  965. * How the texture wraps
  966. * @default PIXI.settings.WRAP_MODE
  967. */
  968. get wrapMode(): WRAP_MODES;
  969. set wrapMode(value: WRAP_MODES);
  970. /**
  971. * Changes style options of BaseTexture
  972. * @param scaleMode - Pixi scalemode
  973. * @param mipmap - enable mipmaps
  974. * @returns - this
  975. */
  976. setStyle(scaleMode?: SCALE_MODES, mipmap?: MIPMAP_MODES): this;
  977. /**
  978. * Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.
  979. * @param desiredWidth - Desired visual width
  980. * @param desiredHeight - Desired visual height
  981. * @param resolution - Optionally set resolution
  982. * @returns - this
  983. */
  984. setSize(desiredWidth: number, desiredHeight: number, resolution?: number): this;
  985. /**
  986. * Sets real size of baseTexture, preserves current resolution.
  987. * @param realWidth - Full rendered width
  988. * @param realHeight - Full rendered height
  989. * @param resolution - Optionally set resolution
  990. * @returns - this
  991. */
  992. setRealSize(realWidth: number, realHeight: number, resolution?: number): this;
  993. /**
  994. * Refresh check for isPowerOfTwo texture based on size
  995. * @private
  996. */
  997. protected _refreshPOT(): void;
  998. /**
  999. * Changes resolution
  1000. * @param resolution - res
  1001. * @returns - this
  1002. */
  1003. setResolution(resolution: number): this;
  1004. /**
  1005. * Sets the resource if it wasn't set. Throws error if resource already present
  1006. * @param resource - that is managing this BaseTexture
  1007. * @returns - this
  1008. */
  1009. setResource(resource: R): this;
  1010. /** Invalidates the object. Texture becomes valid if width and height are greater than zero. */
  1011. update(): void;
  1012. /**
  1013. * Handle errors with resources.
  1014. * @private
  1015. * @param event - Error event emitted.
  1016. */
  1017. onError(event: ErrorEvent): void;
  1018. /**
  1019. * Destroys this base texture.
  1020. * The method stops if resource doesn't want this texture to be destroyed.
  1021. * Removes texture from all caches.
  1022. */
  1023. destroy(): void;
  1024. /**
  1025. * Frees the texture from WebGL memory without destroying this texture object.
  1026. * This means you can still use the texture later which will upload it to GPU
  1027. * memory again.
  1028. * @fires PIXI.BaseTexture#dispose
  1029. */
  1030. dispose(): void;
  1031. /** Utility function for BaseTexture|Texture cast. */
  1032. castToBaseTexture(): BaseTexture;
  1033. /**
  1034. * Helper function that creates a base texture based on the source you provide.
  1035. * The source can be - image url, image element, canvas element. If the
  1036. * source is an image url or an image element and not in the base texture
  1037. * cache, it will be created and loaded.
  1038. * @static
  1039. * @param {string|string[]|HTMLImageElement|HTMLCanvasElement|SVGElement|HTMLVideoElement} source - The
  1040. * source to create base texture from.
  1041. * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
  1042. * @param {string} [options.pixiIdPrefix=pixiid] - If a source has no id, this is the prefix of the generated id
  1043. * @param {boolean} [strict] - Enforce strict-mode, see {@link PIXI.settings.STRICT_TEXTURE_CACHE}.
  1044. * @returns {PIXI.BaseTexture} The new base texture.
  1045. */
  1046. static from<R extends Resource = Resource, RO = IAutoDetectOptions>(source: ImageSource | string | string[], options?: IBaseTextureOptions<RO>, strict?: boolean): BaseTexture<R>;
  1047. /**
  1048. * Create a new BaseTexture with a BufferResource from a Float32Array.
  1049. * RGBA values are floats from 0 to 1.
  1050. * @param {Float32Array|Uint8Array} buffer - The optional array to use, if no data
  1051. * is provided, a new Float32Array is created.
  1052. * @param width - Width of the resource
  1053. * @param height - Height of the resource
  1054. * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
  1055. * Default properties are different from the constructor's defaults.
  1056. * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type
  1057. * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.NPM] - Image alpha, not premultiplied by default
  1058. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.SCALE_MODES.NEAREST] - Scale mode, pixelating by default
  1059. * @returns - The resulting new BaseTexture
  1060. */
  1061. static fromBuffer(buffer: Float32Array | Uint8Array, width: number, height: number, options?: IBaseTextureOptions): BaseTexture<BufferResource>;
  1062. /**
  1063. * Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.
  1064. * @param {PIXI.BaseTexture} baseTexture - The BaseTexture to add to the cache.
  1065. * @param {string} id - The id that the BaseTexture will be stored against.
  1066. */
  1067. static addToCache(baseTexture: BaseTexture, id: string): void;
  1068. /**
  1069. * Remove a BaseTexture from the global BaseTextureCache.
  1070. * @param {string|PIXI.BaseTexture} baseTexture - id of a BaseTexture to be removed, or a BaseTexture instance itself.
  1071. * @returns {PIXI.BaseTexture|null} The BaseTexture that was removed.
  1072. */
  1073. static removeFromCache(baseTexture: string | BaseTexture): BaseTexture | null;
  1074. /** Global number of the texture batch, used by multi-texture renderers. */
  1075. static _globalBatch: number;
  1076. }
  1077. /**
  1078. * Used by the batcher to draw batches.
  1079. * Each one of these contains all information required to draw a bound geometry.
  1080. * @memberof PIXI
  1081. */
  1082. export declare class BatchDrawCall {
  1083. texArray: BatchTextureArray;
  1084. type: DRAW_MODES;
  1085. blend: BLEND_MODES;
  1086. start: number;
  1087. size: number;
  1088. /** Data for uniforms or custom webgl state. */
  1089. data: any;
  1090. constructor();
  1091. }
  1092. /**
  1093. * Geometry used to batch standard PIXI content (e.g. Mesh, Sprite, Graphics objects).
  1094. * @memberof PIXI
  1095. */
  1096. export declare class BatchGeometry extends Geometry {
  1097. /**
  1098. * Buffer used for position, color, texture IDs
  1099. * @protected
  1100. */
  1101. _buffer: Buffer_2;
  1102. /**
  1103. * Index buffer data
  1104. * @protected
  1105. */
  1106. _indexBuffer: Buffer_2;
  1107. /**
  1108. * @param {boolean} [_static=false] - Optimization flag, where `false`
  1109. * is updated every frame, `true` doesn't change frame-to-frame.
  1110. */
  1111. constructor(_static?: boolean);
  1112. }
  1113. /** @memberof PIXI */
  1114. export declare class BatchPluginFactory {
  1115. /**
  1116. * Create a new BatchRenderer plugin for Renderer. this convenience can provide an easy way
  1117. * to extend BatchRenderer with all the necessary pieces.
  1118. * @example
  1119. * const fragment = `
  1120. * varying vec2 vTextureCoord;
  1121. * varying vec4 vColor;
  1122. * varying float vTextureId;
  1123. * uniform sampler2D uSamplers[%count%];
  1124. *
  1125. * void main(void){
  1126. * vec4 color;
  1127. * %forloop%
  1128. * gl_FragColor = vColor * vec4(color.a - color.rgb, color.a);
  1129. * }
  1130. * `;
  1131. * const InvertBatchRenderer = PIXI.BatchPluginFactory.create({ fragment });
  1132. * PIXI.extensions.add({
  1133. * name: 'invert',
  1134. * ref: InvertBatchRenderer,
  1135. * type: PIXI.ExtensionType.RendererPlugin,
  1136. * });
  1137. * const sprite = new PIXI.Sprite();
  1138. * sprite.pluginName = 'invert';
  1139. * @param {object} [options]
  1140. * @param {string} [options.vertex=PIXI.BatchPluginFactory.defaultVertexSrc] - Vertex shader source
  1141. * @param {string} [options.fragment=PIXI.BatchPluginFactory.defaultFragmentTemplate] - Fragment shader template
  1142. * @param {number} [options.vertexSize=6] - Vertex size
  1143. * @param {object} [options.geometryClass=PIXI.BatchGeometry]
  1144. * @returns {*} New batch renderer plugin
  1145. */
  1146. static create(options?: IBatchFactoryOptions): typeof AbstractBatchRenderer;
  1147. /**
  1148. * The default vertex shader source
  1149. * @readonly
  1150. */
  1151. static get defaultVertexSrc(): string;
  1152. /**
  1153. * The default fragment shader source
  1154. * @readonly
  1155. */
  1156. static get defaultFragmentTemplate(): string;
  1157. }
  1158. export declare const BatchRenderer: typeof AbstractBatchRenderer;
  1159. /**
  1160. * Helper that generates batching multi-texture shader. Use it with your new BatchRenderer
  1161. * @memberof PIXI
  1162. */
  1163. export declare class BatchShaderGenerator {
  1164. /** Reference to the vertex shader source. */
  1165. vertexSrc: string;
  1166. /** Reference to the fragment shader template. Must contain "%count%" and "%forloop%". */
  1167. fragTemplate: string;
  1168. programCache: {
  1169. [key: number]: Program;
  1170. };
  1171. defaultGroupCache: {
  1172. [key: number]: UniformGroup;
  1173. };
  1174. /**
  1175. * @param vertexSrc - Vertex shader
  1176. * @param fragTemplate - Fragment shader template
  1177. */
  1178. constructor(vertexSrc: string, fragTemplate: string);
  1179. generateShader(maxTextures: number): Shader;
  1180. generateSampleSrc(maxTextures: number): string;
  1181. }
  1182. /**
  1183. * System plugin to the renderer to manage batching.
  1184. * @memberof PIXI
  1185. */
  1186. export declare class BatchSystem implements ISystem {
  1187. /** An empty renderer. */
  1188. readonly emptyRenderer: ObjectRenderer;
  1189. /** The currently active ObjectRenderer. */
  1190. currentRenderer: ObjectRenderer;
  1191. private renderer;
  1192. /**
  1193. * @param renderer - The renderer this System works for.
  1194. */
  1195. constructor(renderer: Renderer);
  1196. /**
  1197. * Changes the current renderer to the one given in parameter
  1198. * @param objectRenderer - The object renderer to use.
  1199. */
  1200. setObjectRenderer(objectRenderer: ObjectRenderer): void;
  1201. /**
  1202. * This should be called if you wish to do some custom rendering
  1203. * It will basically render anything that may be batched up such as sprites
  1204. */
  1205. flush(): void;
  1206. /** Reset the system to an empty renderer */
  1207. reset(): void;
  1208. /**
  1209. * Handy function for batch renderers: copies bound textures in first maxTextures locations to array
  1210. * sets actual _batchLocation for them
  1211. * @param arr - arr copy destination
  1212. * @param maxTextures - number of copied elements
  1213. */
  1214. copyBoundTextures(arr: BaseTexture[], maxTextures: number): void;
  1215. /**
  1216. * Assigns batch locations to textures in array based on boundTextures state.
  1217. * All textures in texArray should have `_batchEnabled = _batchId`,
  1218. * and their count should be less than `maxTextures`.
  1219. * @param texArray - textures to bound
  1220. * @param boundTextures - current state of bound textures
  1221. * @param batchId - marker for _batchEnabled param of textures in texArray
  1222. * @param maxTextures - number of texture locations to manipulate
  1223. */
  1224. boundArray(texArray: BatchTextureArray, boundTextures: Array<BaseTexture>, batchId: number, maxTextures: number): void;
  1225. /**
  1226. * @ignore
  1227. */
  1228. destroy(): void;
  1229. }
  1230. /**
  1231. * Used by the batcher to build texture batches.
  1232. * Holds list of textures and their respective locations.
  1233. * @memberof PIXI
  1234. */
  1235. export declare class BatchTextureArray {
  1236. /** Inside textures array. */
  1237. elements: BaseTexture_2[];
  1238. /** Respective locations for textures. */
  1239. ids: number[];
  1240. /** Number of filled elements. */
  1241. count: number;
  1242. constructor();
  1243. clear(): void;
  1244. }
  1245. /**
  1246. * A wrapper for data so that it can be used and uploaded by WebGL
  1247. * @memberof PIXI
  1248. */
  1249. declare class Buffer_2 {
  1250. /**
  1251. * The data in the buffer, as a typed array
  1252. * @type {PIXI.IArrayBuffer}
  1253. */
  1254. data: ITypedArray;
  1255. /**
  1256. * The type of buffer this is, one of:
  1257. * + ELEMENT_ARRAY_BUFFER - used as an index buffer
  1258. * + ARRAY_BUFFER - used as an attribute buffer
  1259. * + UNIFORM_BUFFER - used as a uniform buffer (if available)
  1260. */
  1261. type: BUFFER_TYPE;
  1262. static: boolean;
  1263. id: number;
  1264. disposeRunner: Runner;
  1265. /**
  1266. * A map of renderer IDs to webgl buffer
  1267. * @private
  1268. * @type {Object<number, GLBuffer>}
  1269. */
  1270. _glBuffers: {
  1271. [key: number]: GLBuffer;
  1272. };
  1273. _updateID: number;
  1274. /**
  1275. * @param {PIXI.IArrayBuffer} data - the data to store in the buffer.
  1276. * @param _static - `true` for static buffer
  1277. * @param index - `true` for index buffer
  1278. */
  1279. constructor(data?: IArrayBuffer, _static?: boolean, index?: boolean);
  1280. /**
  1281. * Flags this buffer as requiring an upload to the GPU.
  1282. * @param {PIXI.IArrayBuffer|number[]} [data] - the data to update in the buffer.
  1283. */
  1284. update(data?: IArrayBuffer | Array<number>): void;
  1285. /** Disposes WebGL resources that are connected to this geometry. */
  1286. dispose(): void;
  1287. /** Destroys the buffer. */
  1288. destroy(): void;
  1289. /**
  1290. * Flags whether this is an index buffer.
  1291. *
  1292. * Index buffers are of type `ELEMENT_ARRAY_BUFFER`. Note that setting this property to false will make
  1293. * the buffer of type `ARRAY_BUFFER`.
  1294. *
  1295. * For backwards compatibility.
  1296. */
  1297. set index(value: boolean);
  1298. get index(): boolean;
  1299. /**
  1300. * Helper function that creates a buffer based on an array or TypedArray
  1301. * @param {ArrayBufferView | number[]} data - the TypedArray that the buffer will store. If this is a regular Array it will be converted to a Float32Array.
  1302. * @returns - A new Buffer based on the data provided.
  1303. */
  1304. static from(data: IArrayBuffer | number[]): Buffer_2;
  1305. }
  1306. export { Buffer_2 as Buffer }
  1307. /**
  1308. * @interface SharedArrayBuffer
  1309. */
  1310. /**
  1311. * Buffer resource with data of typed array.
  1312. * @memberof PIXI
  1313. */
  1314. export declare class BufferResource extends Resource {
  1315. /** Source array Cannot be {@code ClampedUint8Array} because it cant be uploaded to WebGL */
  1316. data: Float32Array | Uint8Array | Uint16Array | Int32Array | Uint32Array;
  1317. /**
  1318. * @param source - Source buffer
  1319. * @param options - Options
  1320. * @param {number} options.width - Width of the texture
  1321. * @param {number} options.height - Height of the texture
  1322. */
  1323. constructor(source: Float32Array | Uint8Array | Uint16Array | Int32Array | Uint32Array, options: ISize);
  1324. /**
  1325. * Upload the texture to the GPU.
  1326. * @param renderer - Upload to the renderer
  1327. * @param baseTexture - Reference to parent texture
  1328. * @param glTexture - glTexture
  1329. * @returns - true is success
  1330. */
  1331. upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean;
  1332. /** Destroy and don't use after this. */
  1333. dispose(): void;
  1334. /**
  1335. * Used to auto-detect the type of resource.
  1336. * @param {*} source - The source object
  1337. * @returns {boolean} `true` if <canvas>
  1338. */
  1339. static test(source: unknown): source is Float32Array | Uint8Array | Uint32Array;
  1340. }
  1341. /**
  1342. * System plugin to the renderer to manage buffers.
  1343. *
  1344. * WebGL uses Buffers as a way to store objects to the GPU.
  1345. * This system makes working with them a lot easier.
  1346. *
  1347. * Buffers are used in three main places in WebGL
  1348. * - geometry information
  1349. * - Uniform information (via uniform buffer objects - a WebGL 2 only feature)
  1350. * - Transform feedback information. (WebGL 2 only feature)
  1351. *
  1352. * This system will handle the binding of buffers to the GPU as well as uploading
  1353. * them. With this system, you never need to work directly with GPU buffers, but instead work with
  1354. * the PIXI.Buffer class.
  1355. * @class
  1356. * @memberof PIXI
  1357. */
  1358. declare class BufferSystem implements ISystem {
  1359. CONTEXT_UID: number;
  1360. gl: IRenderingContext;
  1361. /** Cache for all buffers by id, used in case renderer gets destroyed or for profiling */
  1362. readonly managedBuffers: {
  1363. [key: number]: Buffer_2;
  1364. };
  1365. /** Cache keeping track of the base bound buffer bases */
  1366. readonly boundBufferBases: {
  1367. [key: number]: Buffer_2;
  1368. };
  1369. private renderer;
  1370. /**
  1371. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  1372. */
  1373. constructor(renderer: Renderer);
  1374. /**
  1375. * @ignore
  1376. */
  1377. destroy(): void;
  1378. /** Sets up the renderer context and necessary buffers. */
  1379. protected contextChange(): void;
  1380. /**
  1381. * This binds specified buffer. On first run, it will create the webGL buffers for the context too
  1382. * @param buffer - the buffer to bind to the renderer
  1383. */
  1384. bind(buffer: Buffer_2): void;
  1385. /**
  1386. * Binds an uniform buffer to at the given index.
  1387. *
  1388. * A cache is used so a buffer will not be bound again if already bound.
  1389. * @param buffer - the buffer to bind
  1390. * @param index - the base index to bind it to.
  1391. */
  1392. bindBufferBase(buffer: Buffer_2, index: number): void;
  1393. /**
  1394. * Binds a buffer whilst also binding its range.
  1395. * This will make the buffer start from the offset supplied rather than 0 when it is read.
  1396. * @param buffer - the buffer to bind
  1397. * @param index - the base index to bind at, defaults to 0
  1398. * @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
  1399. */
  1400. bindBufferRange(buffer: Buffer_2, index?: number, offset?: number): void;
  1401. /**
  1402. * Will ensure the data in the buffer is uploaded to the GPU.
  1403. * @param {PIXI.Buffer} buffer - the buffer to update
  1404. */
  1405. update(buffer: Buffer_2): void;
  1406. /**
  1407. * Disposes buffer
  1408. * @param {PIXI.Buffer} buffer - buffer with data
  1409. * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
  1410. */
  1411. dispose(buffer: Buffer_2, contextLost?: boolean): void;
  1412. /**
  1413. * dispose all WebGL resources of all managed buffers
  1414. * @param {boolean} [contextLost=false] - If context was lost, we suppress `gl.delete` calls
  1415. */
  1416. disposeAll(contextLost?: boolean): void;
  1417. /**
  1418. * creates and attaches a GLBuffer object tied to the current context.
  1419. * @param buffer
  1420. * @protected
  1421. */
  1422. protected createGLBuffer(buffer: Buffer_2): GLBuffer;
  1423. }
  1424. /**
  1425. * @interface OffscreenCanvas
  1426. */
  1427. /**
  1428. * Resource type for HTMLCanvasElement.
  1429. * @memberof PIXI
  1430. */
  1431. export declare class CanvasResource extends BaseImageResource {
  1432. /**
  1433. * @param source - Canvas element to use
  1434. */
  1435. constructor(source: HTMLCanvasElement);
  1436. /**
  1437. * Used to auto-detect the type of resource.
  1438. * @param {*} source - The source object
  1439. * @returns {boolean} `true` if source is HTMLCanvasElement or OffscreenCanvas
  1440. */
  1441. static test(source: unknown): source is OffscreenCanvas | HTMLCanvasElement;
  1442. }
  1443. export declare function checkMaxIfStatementsInShader(maxIfs: number, gl: IRenderingContext): number;
  1444. /**
  1445. * System plugin to the renderer to manage the context.
  1446. * @memberof PIXI
  1447. */
  1448. export declare class ContextSystem implements ISystem {
  1449. /**
  1450. * Either 1 or 2 to reflect the WebGL version being used.
  1451. * @readonly
  1452. */
  1453. webGLVersion: number;
  1454. /**
  1455. * Features supported by current context.
  1456. * @type {object}
  1457. * @readonly
  1458. * @property {boolean} uint32Indices - Support for 32-bit indices buffer.
  1459. */
  1460. readonly supports: ISupportDict;
  1461. protected CONTEXT_UID: number;
  1462. protected gl: IRenderingContext;
  1463. /**
  1464. * Extensions available.
  1465. * @type {object}
  1466. * @readonly
  1467. * @property {WEBGL_draw_buffers} drawBuffers - WebGL v1 extension
  1468. * @property {WEBGL_depth_texture} depthTexture - WebGL v1 extension
  1469. * @property {OES_texture_float} floatTexture - WebGL v1 extension
  1470. * @property {WEBGL_lose_context} loseContext - WebGL v1 extension
  1471. * @property {OES_vertex_array_object} vertexArrayObject - WebGL v1 extension
  1472. * @property {EXT_texture_filter_anisotropic} anisotropicFiltering - WebGL v1 and v2 extension
  1473. */
  1474. extensions: WebGLExtensions;
  1475. private renderer;
  1476. /** @param renderer - The renderer this System works for. */
  1477. constructor(renderer: Renderer);
  1478. /**
  1479. * `true` if the context is lost
  1480. * @readonly
  1481. */
  1482. get isLost(): boolean;
  1483. /**
  1484. * Handles the context change event.
  1485. * @param {WebGLRenderingContext} gl - New WebGL context.
  1486. */
  1487. protected contextChange(gl: IRenderingContext): void;
  1488. /**
  1489. * Initializes the context.
  1490. * @protected
  1491. * @param {WebGLRenderingContext} gl - WebGL context
  1492. */
  1493. initFromContext(gl: IRenderingContext): void;
  1494. /**
  1495. * Initialize from context options
  1496. * @protected
  1497. * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
  1498. * @param {object} options - context attributes
  1499. */
  1500. initFromOptions(options: WebGLContextAttributes): void;
  1501. /**
  1502. * Helper class to create a WebGL Context
  1503. * @param canvas - the canvas element that we will get the context from
  1504. * @param options - An options object that gets passed in to the canvas element containing the
  1505. * context attributes
  1506. * @see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext
  1507. * @returns {WebGLRenderingContext} the WebGL context
  1508. */
  1509. createContext(canvas: HTMLCanvasElement, options: WebGLContextAttributes): IRenderingContext;
  1510. /** Auto-populate the {@link PIXI.ContextSystem.extensions extensions}. */
  1511. protected getExtensions(): void;
  1512. /**
  1513. * Handles a lost webgl context
  1514. * @param {WebGLContextEvent} event - The context lost event.
  1515. */
  1516. protected handleContextLost(event: WebGLContextEvent): void;
  1517. /** Handles a restored webgl context. */
  1518. protected handleContextRestored(): void;
  1519. destroy(): void;
  1520. /** Handle the post-render runner event. */
  1521. protected postrender(): void;
  1522. /**
  1523. * Validate context.
  1524. * @param {WebGLRenderingContext} gl - Render context.
  1525. */
  1526. protected validateContext(gl: IRenderingContext): void;
  1527. }
  1528. /**
  1529. * logic originally from here: https://github.com/sketchpunk/FunWithWebGL2/blob/master/lesson_022/Shaders.js
  1530. * rewrote it, but this was a great starting point to get a solid understanding of whats going on :)
  1531. * @ignore
  1532. * @param uniformData
  1533. */
  1534. export declare function createUBOElements(uniformData: IUniformData[]): {
  1535. uboElements: UBOElement[];
  1536. size: number;
  1537. };
  1538. /**
  1539. * Resource for a CubeTexture which contains six resources.
  1540. * @memberof PIXI
  1541. */
  1542. export declare class CubeResource extends AbstractMultiResource {
  1543. items: ArrayFixed<BaseTexture, 6>;
  1544. /**
  1545. * In case BaseTextures are supplied, whether to use same resource or bind baseTexture itself.
  1546. * @protected
  1547. */
  1548. linkBaseTexture: boolean;
  1549. /**
  1550. * @param {Array<string|PIXI.Resource>} [source] - Collection of URLs or resources
  1551. * to use as the sides of the cube.
  1552. * @param options - ImageResource options
  1553. * @param {number} [options.width] - Width of resource
  1554. * @param {number} [options.height] - Height of resource
  1555. * @param {number} [options.autoLoad=true] - Whether to auto-load resources
  1556. * @param {number} [options.linkBaseTexture=true] - In case BaseTextures are supplied,
  1557. * whether to copy them or use
  1558. */
  1559. constructor(source?: ArrayFixed<string | Resource, 6>, options?: ICubeResourceOptions);
  1560. /**
  1561. * Add binding.
  1562. * @param baseTexture - parent base texture
  1563. */
  1564. bind(baseTexture: BaseTexture): void;
  1565. addBaseTextureAt(baseTexture: BaseTexture, index: number, linkBaseTexture?: boolean): this;
  1566. /**
  1567. * Upload the resource
  1568. * @param renderer
  1569. * @param _baseTexture
  1570. * @param glTexture
  1571. * @returns {boolean} true is success
  1572. */
  1573. upload(renderer: Renderer, _baseTexture: BaseTexture, glTexture: GLTexture): boolean;
  1574. /** Number of texture sides to store for CubeResources. */
  1575. static SIDES: number;
  1576. /**
  1577. * Used to auto-detect the type of resource.
  1578. * @param {*} source - The source object
  1579. * @returns {boolean} `true` if source is an array of 6 elements
  1580. */
  1581. static test(source: unknown): source is ArrayFixed<string | Resource, 6>;
  1582. }
  1583. export declare const defaultFilterVertex: string;
  1584. /**
  1585. * Default filter vertex shader
  1586. * @memberof PIXI
  1587. * @member {string} defaultFilterVertex
  1588. */
  1589. export declare const defaultVertex: string;
  1590. /**
  1591. * A filter is a special shader that applies post-processing effects to an input texture and writes into an output
  1592. * render-target.
  1593. *
  1594. * {@link http://pixijs.io/examples/#/filters/blur-filter.js Example} of the
  1595. * {@link PIXI.filters.BlurFilter BlurFilter}.
  1596. *
  1597. * ### Usage
  1598. * Filters can be applied to any DisplayObject or Container.
  1599. * PixiJS' `FilterSystem` renders the container into temporary Framebuffer,
  1600. * then filter renders it to the screen.
  1601. * Multiple filters can be added to the `filters` array property and stacked on each other.
  1602. *
  1603. * ```
  1604. * const filter = new PIXI.Filter(myShaderVert, myShaderFrag, { myUniform: 0.5 });
  1605. * const container = new PIXI.Container();
  1606. * container.filters = [filter];
  1607. * ```
  1608. *
  1609. * ### Previous Version Differences
  1610. *
  1611. * In PixiJS **v3**, a filter was always applied to _whole screen_.
  1612. *
  1613. * In PixiJS **v4**, a filter can be applied _only part of the screen_.
  1614. * Developers had to create a set of uniforms to deal with coordinates.
  1615. *
  1616. * In PixiJS **v5** combines _both approaches_.
  1617. * Developers can use normal coordinates of v3 and then allow filter to use partial Framebuffers,
  1618. * bringing those extra uniforms into account.
  1619. *
  1620. * Also be aware that we have changed default vertex shader, please consult
  1621. * {@link https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters Wiki}.
  1622. *
  1623. * ### Frames
  1624. *
  1625. * The following table summarizes the coordinate spaces used in the filtering pipeline:
  1626. *
  1627. * <table>
  1628. * <thead>
  1629. * <tr>
  1630. * <th>Coordinate Space</th>
  1631. * <th>Description</th>
  1632. * </tr>
  1633. * </thead>
  1634. * <tbody>
  1635. * <tr>
  1636. * <td>Texture Coordinates</td>
  1637. * <td>
  1638. * The texture (or UV) coordinates in the input base-texture's space. These are normalized into the (0,1) range along
  1639. * both axes.
  1640. * </td>
  1641. * </tr>
  1642. * <tr>
  1643. * <td>World Space</td>
  1644. * <td>
  1645. * A point in the same space as the world bounds of any display-object (i.e. in the scene graph's space).
  1646. * </td>
  1647. * </tr>
  1648. * <tr>
  1649. * <td>Physical Pixels</td>
  1650. * <td>
  1651. * This is base-texture's space with the origin on the top-left. You can calculate these by multiplying the texture
  1652. * coordinates by the dimensions of the texture.
  1653. * </td>
  1654. * </tr>
  1655. * </tbody>
  1656. * </table>
  1657. *
  1658. * ### Built-in Uniforms
  1659. *
  1660. * PixiJS viewport uses screen (CSS) coordinates, `(0, 0, renderer.screen.width, renderer.screen.height)`,
  1661. * and `projectionMatrix` uniform maps it to the gl viewport.
  1662. *
  1663. * **uSampler**
  1664. *
  1665. * The most important uniform is the input texture that container was rendered into.
  1666. * _Important note: as with all Framebuffers in PixiJS, both input and output are
  1667. * premultiplied by alpha._
  1668. *
  1669. * By default, input normalized coordinates are passed to fragment shader with `vTextureCoord`.
  1670. * Use it to sample the input.
  1671. *
  1672. * ```
  1673. * const fragment = `
  1674. * varying vec2 vTextureCoord;
  1675. * uniform sampler2D uSampler;
  1676. * void main(void)
  1677. * {
  1678. * gl_FragColor = texture2D(uSampler, vTextureCoord);
  1679. * }
  1680. * `;
  1681. *
  1682. * const myFilter = new PIXI.Filter(null, fragment);
  1683. * ```
  1684. *
  1685. * This filter is just one uniform less than {@link PIXI.filters.AlphaFilter AlphaFilter}.
  1686. *
  1687. * **outputFrame**
  1688. *
  1689. * The `outputFrame` holds the rectangle where filter is applied in screen (CSS) coordinates.
  1690. * It's the same as `renderer.screen` for a fullscreen filter.
  1691. * Only a part of `outputFrame.zw` size of temporary Framebuffer is used,
  1692. * `(0, 0, outputFrame.width, outputFrame.height)`,
  1693. *
  1694. * Filters uses this quad to normalized (0-1) space, its passed into `aVertexPosition` attribute.
  1695. * To calculate vertex position in screen space using normalized (0-1) space:
  1696. *
  1697. * ```
  1698. * vec4 filterVertexPosition( void )
  1699. * {
  1700. * vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;
  1701. * return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
  1702. * }
  1703. * ```
  1704. *
  1705. * **inputSize**
  1706. *
  1707. * Temporary framebuffer is different, it can be either the size of screen, either power-of-two.
  1708. * The `inputSize.xy` are size of temporary framebuffer that holds input.
  1709. * The `inputSize.zw` is inverted, it's a shortcut to evade division inside the shader.
  1710. *
  1711. * Set `inputSize.xy = outputFrame.zw` for a fullscreen filter.
  1712. *
  1713. * To calculate input normalized coordinate, you have to map it to filter normalized space.
  1714. * Multiply by `outputFrame.zw` to get input coordinate.
  1715. * Divide by `inputSize.xy` to get input normalized coordinate.
  1716. *
  1717. * ```
  1718. * vec2 filterTextureCoord( void )
  1719. * {
  1720. * return aVertexPosition * (outputFrame.zw * inputSize.zw); // same as /inputSize.xy
  1721. * }
  1722. * ```
  1723. * **resolution**
  1724. *
  1725. * The `resolution` is the ratio of screen (CSS) pixels to real pixels.
  1726. *
  1727. * **inputPixel**
  1728. *
  1729. * `inputPixel.xy` is the size of framebuffer in real pixels, same as `inputSize.xy * resolution`
  1730. * `inputPixel.zw` is inverted `inputPixel.xy`.
  1731. *
  1732. * It's handy for filters that use neighbour pixels, like {@link PIXI.filters.FXAAFilter FXAAFilter}.
  1733. *
  1734. * **inputClamp**
  1735. *
  1736. * If you try to get info from outside of used part of Framebuffer - you'll get undefined behaviour.
  1737. * For displacements, coordinates has to be clamped.
  1738. *
  1739. * The `inputClamp.xy` is left-top pixel center, you may ignore it, because we use left-top part of Framebuffer
  1740. * `inputClamp.zw` is bottom-right pixel center.
  1741. *
  1742. * ```
  1743. * vec4 color = texture2D(uSampler, clamp(modifiedTextureCoord, inputClamp.xy, inputClamp.zw))
  1744. * ```
  1745. * OR
  1746. * ```
  1747. * vec4 color = texture2D(uSampler, min(modifigedTextureCoord, inputClamp.zw))
  1748. * ```
  1749. *
  1750. * ### Additional Information
  1751. *
  1752. * Complete documentation on Filter usage is located in the
  1753. * {@link https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters Wiki}.
  1754. *
  1755. * Since PixiJS only had a handful of built-in filters, additional filters can be downloaded
  1756. * {@link https://github.com/pixijs/pixi-filters here} from the PixiJS Filters repository.
  1757. * @memberof PIXI
  1758. */
  1759. export declare class Filter extends Shader {
  1760. /**
  1761. * The padding of the filter. Some filters require extra space to breath such as a blur.
  1762. * Increasing this will add extra width and height to the bounds of the object that the
  1763. * filter is applied to.
  1764. */
  1765. padding: number;
  1766. /** The samples of the filter. */
  1767. multisample: MSAA_QUALITY;
  1768. /** If enabled is true the filter is applied, if false it will not. */
  1769. enabled: boolean;
  1770. /**
  1771. * If enabled, PixiJS will fit the filter area into boundaries for better performance.
  1772. * Switch it off if it does not work for specific shader.
  1773. * @default true
  1774. */
  1775. autoFit: boolean;
  1776. /**
  1777. * Legacy filters use position and uvs from attributes (set by filter system)
  1778. * @readonly
  1779. */
  1780. legacy: boolean;
  1781. /** The WebGL state the filter requires to render. */
  1782. state: State;
  1783. protected _resolution: number;
  1784. /**
  1785. * @param vertexSrc - The source of the vertex shader.
  1786. * @param fragmentSrc - The source of the fragment shader.
  1787. * @param uniforms - Custom uniforms to use to augment the built-in ones.
  1788. */
  1789. constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: Dict<any>);
  1790. /**
  1791. * Applies the filter
  1792. * @param {PIXI.FilterSystem} filterManager - The renderer to retrieve the filter from
  1793. * @param {PIXI.RenderTexture} input - The input render target.
  1794. * @param {PIXI.RenderTexture} output - The target to output to.
  1795. * @param {PIXI.CLEAR_MODES} [clearMode] - Should the output be cleared before rendering to it.
  1796. * @param {object} [_currentState] - It's current state of filter.
  1797. * There are some useful properties in the currentState :
  1798. * target, filters, sourceFrame, destinationFrame, renderTarget, resolution
  1799. */
  1800. apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clearMode?: CLEAR_MODES, _currentState?: FilterState): void;
  1801. /**
  1802. * Sets the blend mode of the filter.
  1803. * @default PIXI.BLEND_MODES.NORMAL
  1804. */
  1805. get blendMode(): BLEND_MODES;
  1806. set blendMode(value: BLEND_MODES);
  1807. /**
  1808. * The resolution of the filter. Setting this to be lower will lower the quality but
  1809. * increase the performance of the filter.
  1810. */
  1811. get resolution(): number;
  1812. set resolution(value: number);
  1813. /**
  1814. * The default vertex shader source
  1815. * @constant
  1816. */
  1817. static get defaultVertexSrc(): string;
  1818. /**
  1819. * The default fragment shader source
  1820. * @constant
  1821. */
  1822. static get defaultFragmentSrc(): string;
  1823. /** Used for caching shader IDs. */
  1824. static SOURCE_KEY_MAP: Dict<string>;
  1825. }
  1826. /**
  1827. * System plugin to the renderer to manage filter states.
  1828. * @ignore
  1829. */
  1830. export declare class FilterState {
  1831. renderTexture: RenderTexture;
  1832. /**
  1833. * Target of the filters
  1834. * We store for case when custom filter wants to know the element it was applied on
  1835. * @member {PIXI.DisplayObject}
  1836. */
  1837. target: IFilterTarget;
  1838. /**
  1839. * Compatibility with PixiJS v4 filters
  1840. * @default false
  1841. */
  1842. legacy: boolean;
  1843. /**
  1844. * Resolution of filters
  1845. * @default 1
  1846. */
  1847. resolution: number;
  1848. /**
  1849. * Number of samples
  1850. * @default MSAA_QUALITY.NONE
  1851. */
  1852. multisample: MSAA_QUALITY;
  1853. /** Source frame. */
  1854. sourceFrame: Rectangle;
  1855. /** Destination frame. */
  1856. destinationFrame: Rectangle;
  1857. /** Original render-target source frame. */
  1858. bindingSourceFrame: Rectangle;
  1859. /** Original render-target destination frame. */
  1860. bindingDestinationFrame: Rectangle;
  1861. /** Collection of filters. */
  1862. filters: Array<Filter>;
  1863. /** Projection system transform saved by link. */
  1864. transform: Matrix;
  1865. constructor();
  1866. /** Clears the state */
  1867. clear(): void;
  1868. }
  1869. /**
  1870. * System plugin to the renderer to manage filters.
  1871. *
  1872. * ## Pipeline
  1873. *
  1874. * The FilterSystem executes the filtering pipeline by rendering the display-object into a texture, applying its
  1875. * [filters]{@link PIXI.Filter} in series, and the last filter outputs into the final render-target.
  1876. *
  1877. * The filter-frame is the rectangle in world space being filtered, and those contents are mapped into
  1878. * `(0, 0, filterFrame.width, filterFrame.height)` into the filter render-texture. The filter-frame is also called
  1879. * the source-frame, as it is used to bind the filter render-textures. The last filter outputs to the `filterFrame`
  1880. * in the final render-target.
  1881. *
  1882. * ## Usage
  1883. *
  1884. * {@link PIXI.Container#renderAdvanced} is an example of how to use the filter system. It is a 3 step process:
  1885. *
  1886. * **push**: Use {@link PIXI.FilterSystem#push} to push the set of filters to be applied on a filter-target.
  1887. * **render**: Render the contents to be filtered using the renderer. The filter-system will only capture the contents
  1888. * inside the bounds of the filter-target. NOTE: Using {@link PIXI.Renderer#render} is
  1889. * illegal during an existing render cycle, and it may reset the filter system.
  1890. * **pop**: Use {@link PIXI.FilterSystem#pop} to pop & execute the filters you initially pushed. It will apply them
  1891. * serially and output to the bounds of the filter-target.
  1892. * @memberof PIXI
  1893. */
  1894. export declare class FilterSystem implements ISystem {
  1895. /**
  1896. * List of filters for the FilterSystem
  1897. * @member {object[]}
  1898. */
  1899. readonly defaultFilterStack: Array<FilterState>;
  1900. /** A pool for storing filter states, save us creating new ones each tick. */
  1901. statePool: Array<FilterState>;
  1902. /** Stores a bunch of POT textures used for filtering. */
  1903. texturePool: RenderTexturePool;
  1904. /** Whether to clear output renderTexture in AUTO/BLIT mode. See {@link PIXI.CLEAR_MODES}. */
  1905. forceClear: boolean;
  1906. /**
  1907. * Old padding behavior is to use the max amount instead of sum padding.
  1908. * Use this flag if you need the old behavior.
  1909. * @default false
  1910. */
  1911. useMaxPadding: boolean;
  1912. /** A very simple geometry used when drawing a filter effect to the screen. */
  1913. protected quad: Quad;
  1914. /** Quad UVs */
  1915. protected quadUv: QuadUv;
  1916. /**
  1917. * Active state
  1918. * @member {object}
  1919. */
  1920. protected activeState: FilterState;
  1921. /**
  1922. * This uniform group is attached to filter uniforms when used.
  1923. * @property {PIXI.Rectangle} outputFrame -
  1924. * @property {Float32Array} inputSize -
  1925. * @property {Float32Array} inputPixel -
  1926. * @property {Float32Array} inputClamp -
  1927. * @property {number} resolution -
  1928. * @property {Float32Array} filterArea -
  1929. * @property {Float32Array} filterClamp -
  1930. */
  1931. protected globalUniforms: UniformGroup;
  1932. /** Temporary rect for math. */
  1933. private tempRect;
  1934. renderer: Renderer;
  1935. /**
  1936. * @param renderer - The renderer this System works for.
  1937. */
  1938. constructor(renderer: Renderer);
  1939. /**
  1940. * Pushes a set of filters to be applied later to the system. This will redirect further rendering into an
  1941. * input render-texture for the rest of the filtering pipeline.
  1942. * @param {PIXI.DisplayObject} target - The target of the filter to render.
  1943. * @param filters - The filters to apply.
  1944. */
  1945. push(target: IFilterTarget, filters: Array<Filter>): void;
  1946. /** Pops off the filter and applies it. */
  1947. pop(): void;
  1948. /**
  1949. * Binds a renderTexture with corresponding `filterFrame`, clears it if mode corresponds.
  1950. * @param filterTexture - renderTexture to bind, should belong to filter pool or filter stack
  1951. * @param clearMode - clearMode, by default its CLEAR/YES. See {@link PIXI.CLEAR_MODES}
  1952. */
  1953. bindAndClear(filterTexture: RenderTexture, clearMode?: CLEAR_MODES): void;
  1954. /**
  1955. * Draws a filter using the default rendering process.
  1956. *
  1957. * This should be called only by {@link Filter#apply}.
  1958. * @param filter - The filter to draw.
  1959. * @param input - The input render target.
  1960. * @param output - The target to output to.
  1961. * @param clearMode - Should the output be cleared before rendering to it
  1962. */
  1963. applyFilter(filter: Filter, input: RenderTexture, output: RenderTexture, clearMode?: CLEAR_MODES): void;
  1964. /**
  1965. * Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
  1966. *
  1967. * Use `outputMatrix * vTextureCoord` in the shader.
  1968. * @param outputMatrix - The matrix to output to.
  1969. * @param {PIXI.Sprite} sprite - The sprite to map to.
  1970. * @returns The mapped matrix.
  1971. */
  1972. calculateSpriteMatrix(outputMatrix: Matrix, sprite: ISpriteMaskTarget): Matrix;
  1973. /** Destroys this Filter System. */
  1974. destroy(): void;
  1975. /**
  1976. * Gets a Power-of-Two render texture or fullScreen texture
  1977. * @param minWidth - The minimum width of the render texture in real pixels.
  1978. * @param minHeight - The minimum height of the render texture in real pixels.
  1979. * @param resolution - The resolution of the render texture.
  1980. * @param multisample - Number of samples of the render texture.
  1981. * @returns - The new render texture.
  1982. */
  1983. protected getOptimalFilterTexture(minWidth: number, minHeight: number, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
  1984. /**
  1985. * Gets extra render texture to use inside current filter
  1986. * To be compliant with older filters, you can use params in any order
  1987. * @param input - renderTexture from which size and resolution will be copied
  1988. * @param resolution - override resolution of the renderTexture
  1989. * @param multisample - number of samples of the renderTexture
  1990. */
  1991. getFilterTexture(input?: RenderTexture, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
  1992. /**
  1993. * Frees a render texture back into the pool.
  1994. * @param renderTexture - The renderTarget to free
  1995. */
  1996. returnFilterTexture(renderTexture: RenderTexture): void;
  1997. /** Empties the texture pool. */
  1998. emptyPool(): void;
  1999. /** Calls `texturePool.resize()`, affects fullScreen renderTextures. */
  2000. resize(): void;
  2001. /**
  2002. * @param matrix - first param
  2003. * @param rect - second param
  2004. */
  2005. private transformAABB;
  2006. private roundFrame;
  2007. }
  2008. /**
  2009. * A framebuffer can be used to render contents off of the screen. {@link PIXI.BaseRenderTexture} uses
  2010. * one internally to render into itself. You can attach a depth or stencil buffer to a framebuffer.
  2011. *
  2012. * On WebGL 2 machines, shaders can output to multiple textures simultaneously with GLSL 300 ES.
  2013. * @memberof PIXI
  2014. */
  2015. export declare class Framebuffer {
  2016. /** Width of framebuffer in pixels. */
  2017. width: number;
  2018. /** Height of framebuffer in pixels. */
  2019. height: number;
  2020. /**
  2021. * Desired number of samples for antialiasing. 0 means AA should not be used.
  2022. *
  2023. * Experimental WebGL2 feature, allows to use antialiasing in individual renderTextures.
  2024. * Antialiasing is the same as for main buffer with renderer `antialias:true` options.
  2025. * Seriously affects GPU memory consumption and GPU performance.
  2026. *
  2027. *```js
  2028. * renderTexture.framebuffer.multisample = PIXI.MSAA_QUALITY.HIGH;
  2029. * //...
  2030. * renderer.render(myContainer, {renderTexture});
  2031. * renderer.framebuffer.blit(); // copies data from MSAA framebuffer to texture
  2032. * ```
  2033. * @default PIXI.MSAA_QUALITY.NONE
  2034. */
  2035. multisample: MSAA_QUALITY;
  2036. stencil: boolean;
  2037. depth: boolean;
  2038. dirtyId: number;
  2039. dirtyFormat: number;
  2040. dirtySize: number;
  2041. depthTexture: BaseTexture;
  2042. colorTextures: Array<BaseTexture>;
  2043. glFramebuffers: {
  2044. [key: string]: GLFramebuffer;
  2045. };
  2046. disposeRunner: Runner;
  2047. /**
  2048. * @param width - Width of the frame buffer
  2049. * @param height - Height of the frame buffer
  2050. */
  2051. constructor(width: number, height: number);
  2052. /**
  2053. * Reference to the colorTexture.
  2054. * @readonly
  2055. */
  2056. get colorTexture(): BaseTexture;
  2057. /**
  2058. * Add texture to the colorTexture array.
  2059. * @param index - Index of the array to add the texture to
  2060. * @param texture - Texture to add to the array
  2061. */
  2062. addColorTexture(index?: number, texture?: BaseTexture): this;
  2063. /**
  2064. * Add a depth texture to the frame buffer.
  2065. * @param texture - Texture to add.
  2066. */
  2067. addDepthTexture(texture?: BaseTexture): this;
  2068. /** Enable depth on the frame buffer. */
  2069. enableDepth(): this;
  2070. /** Enable stencil on the frame buffer. */
  2071. enableStencil(): this;
  2072. /**
  2073. * Resize the frame buffer
  2074. * @param width - Width of the frame buffer to resize to
  2075. * @param height - Height of the frame buffer to resize to
  2076. */
  2077. resize(width: number, height: number): void;
  2078. /** Disposes WebGL resources that are connected to this geometry. */
  2079. dispose(): void;
  2080. /** Destroys and removes the depth texture added to this framebuffer. */
  2081. destroyDepthTexture(): void;
  2082. }
  2083. /**
  2084. * System plugin to the renderer to manage framebuffers.
  2085. * @memberof PIXI
  2086. */
  2087. export declare class FramebufferSystem implements ISystem {
  2088. /** A list of managed framebuffers. */
  2089. readonly managedFramebuffers: Array<Framebuffer>;
  2090. current: Framebuffer;
  2091. viewport: Rectangle;
  2092. hasMRT: boolean;
  2093. writeDepthTexture: boolean;
  2094. protected CONTEXT_UID: number;
  2095. protected gl: IRenderingContext;
  2096. /** Framebuffer value that shows that we don't know what is bound. */
  2097. protected unknownFramebuffer: Framebuffer;
  2098. protected msaaSamples: Array<number>;
  2099. renderer: Renderer;
  2100. /**
  2101. * @param renderer - The renderer this System works for.
  2102. */
  2103. constructor(renderer: Renderer);
  2104. /** Sets up the renderer context and necessary buffers. */
  2105. protected contextChange(): void;
  2106. /**
  2107. * Bind a framebuffer.
  2108. * @param framebuffer
  2109. * @param frame - frame, default is framebuffer size
  2110. * @param mipLevel - optional mip level to set on the framebuffer - defaults to 0
  2111. */
  2112. bind(framebuffer?: Framebuffer, frame?: Rectangle, mipLevel?: number): void;
  2113. /**
  2114. * Set the WebGLRenderingContext's viewport.
  2115. * @param x - X position of viewport
  2116. * @param y - Y position of viewport
  2117. * @param width - Width of viewport
  2118. * @param height - Height of viewport
  2119. */
  2120. setViewport(x: number, y: number, width: number, height: number): void;
  2121. /**
  2122. * Get the size of the current width and height. Returns object with `width` and `height` values.
  2123. * @readonly
  2124. */
  2125. get size(): {
  2126. x: number;
  2127. y: number;
  2128. width: number;
  2129. height: number;
  2130. };
  2131. /**
  2132. * Clear the color of the context
  2133. * @param r - Red value from 0 to 1
  2134. * @param g - Green value from 0 to 1
  2135. * @param b - Blue value from 0 to 1
  2136. * @param a - Alpha value from 0 to 1
  2137. * @param {PIXI.BUFFER_BITS} [mask=BUFFER_BITS.COLOR | BUFFER_BITS.DEPTH] - Bitwise OR of masks
  2138. * that indicate the buffers to be cleared, by default COLOR and DEPTH buffers.
  2139. */
  2140. clear(r: number, g: number, b: number, a: number, mask?: BUFFER_BITS): void;
  2141. /**
  2142. * Initialize framebuffer for this context
  2143. * @protected
  2144. * @param framebuffer
  2145. * @returns - created GLFramebuffer
  2146. */
  2147. initFramebuffer(framebuffer: Framebuffer): GLFramebuffer;
  2148. /**
  2149. * Resize the framebuffer
  2150. * @param framebuffer
  2151. * @protected
  2152. */
  2153. resizeFramebuffer(framebuffer: Framebuffer): void;
  2154. /**
  2155. * Update the framebuffer
  2156. * @param framebuffer
  2157. * @param mipLevel
  2158. * @protected
  2159. */
  2160. updateFramebuffer(framebuffer: Framebuffer, mipLevel: number): void;
  2161. /**
  2162. * Returns true if the frame buffer can be multisampled.
  2163. * @param framebuffer
  2164. */
  2165. protected canMultisampleFramebuffer(framebuffer: Framebuffer): boolean;
  2166. /**
  2167. * Detects number of samples that is not more than a param but as close to it as possible
  2168. * @param samples - number of samples
  2169. * @returns - recommended number of samples
  2170. */
  2171. protected detectSamples(samples: MSAA_QUALITY): MSAA_QUALITY;
  2172. /**
  2173. * Only works with WebGL2
  2174. *
  2175. * blits framebuffer to another of the same or bigger size
  2176. * after that target framebuffer is bound
  2177. *
  2178. * Fails with WebGL warning if blits multisample framebuffer to different size
  2179. * @param framebuffer - by default it blits "into itself", from renderBuffer to texture.
  2180. * @param sourcePixels - source rectangle in pixels
  2181. * @param destPixels - dest rectangle in pixels, assumed to be the same as sourcePixels
  2182. */
  2183. blit(framebuffer?: Framebuffer, sourcePixels?: Rectangle, destPixels?: Rectangle): void;
  2184. /**
  2185. * Disposes framebuffer.
  2186. * @param framebuffer - framebuffer that has to be disposed of
  2187. * @param contextLost - If context was lost, we suppress all delete function calls
  2188. */
  2189. disposeFramebuffer(framebuffer: Framebuffer, contextLost?: boolean): void;
  2190. /**
  2191. * Disposes all framebuffers, but not textures bound to them.
  2192. * @param [contextLost=false] - If context was lost, we suppress all delete function calls
  2193. */
  2194. disposeAll(contextLost?: boolean): void;
  2195. /**
  2196. * Forcing creation of stencil buffer for current framebuffer, if it wasn't done before.
  2197. * Used by MaskSystem, when its time to use stencil mask for Graphics element.
  2198. *
  2199. * Its an alternative for public lazy `framebuffer.enableStencil`, in case we need stencil without rebind.
  2200. * @private
  2201. */
  2202. forceStencil(): void;
  2203. /** Resets framebuffer stored state, binds screen framebuffer. Should be called before renderTexture reset(). */
  2204. reset(): void;
  2205. destroy(): void;
  2206. }
  2207. /**
  2208. * generates a WebGL Program object from a high level Pixi Program.
  2209. * @param gl - a rendering context on which to generate the program
  2210. * @param program - the high level Pixi Program.
  2211. */
  2212. export declare function generateProgram(gl: IRenderingContext, program: Program): GLProgram;
  2213. export declare function generateUniformBufferSync(group: UniformGroup, uniformData: Dict<any>): {
  2214. size: number;
  2215. syncFunc: UniformsSyncCallback;
  2216. };
  2217. /**
  2218. * The Geometry represents a model. It consists of two components:
  2219. * - GeometryStyle - The structure of the model such as the attributes layout
  2220. * - GeometryData - the data of the model - this consists of buffers.
  2221. * This can include anything from positions, uvs, normals, colors etc.
  2222. *
  2223. * Geometry can be defined without passing in a style or data if required (thats how I prefer!)
  2224. *
  2225. * ```js
  2226. * let geometry = new PIXI.Geometry();
  2227. *
  2228. * geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
  2229. * geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1],2)
  2230. * geometry.addIndex([0,1,2,1,3,2])
  2231. * ```
  2232. * @memberof PIXI
  2233. */
  2234. export declare class Geometry {
  2235. buffers: Array<Buffer_2>;
  2236. indexBuffer: Buffer_2;
  2237. attributes: {
  2238. [key: string]: Attribute;
  2239. };
  2240. id: number;
  2241. /** Whether the geometry is instanced. */
  2242. instanced: boolean;
  2243. /**
  2244. * Number of instances in this geometry, pass it to `GeometrySystem.draw()`.
  2245. * @default 1
  2246. */
  2247. instanceCount: number;
  2248. /**
  2249. * A map of renderer IDs to webgl VAOs
  2250. * @type {object}
  2251. */
  2252. glVertexArrayObjects: {
  2253. [key: number]: {
  2254. [key: string]: WebGLVertexArrayObject;
  2255. };
  2256. };
  2257. disposeRunner: Runner;
  2258. /** Count of existing (not destroyed) meshes that reference this geometry. */
  2259. refCount: number;
  2260. /**
  2261. * @param buffers - An array of buffers. optional.
  2262. * @param attributes - Of the geometry, optional structure of the attributes layout
  2263. */
  2264. constructor(buffers?: Array<Buffer_2>, attributes?: {
  2265. [key: string]: Attribute;
  2266. });
  2267. /**
  2268. *
  2269. * Adds an attribute to the geometry
  2270. * Note: `stride` and `start` should be `undefined` if you dont know them, not 0!
  2271. * @param id - the name of the attribute (matching up to a shader)
  2272. * @param {PIXI.Buffer|number[]} buffer - the buffer that holds the data of the attribute . You can also provide an Array and a buffer will be created from it.
  2273. * @param size - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2
  2274. * @param normalized - should the data be normalized.
  2275. * @param [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {PIXI.TYPES} to see the ones available
  2276. * @param [stride=0] - How far apart, in bytes, the start of each value is. (used for interleaving data)
  2277. * @param [start=0] - How far into the array to start reading values (used for interleaving data)
  2278. * @param instance - Instancing flag
  2279. * @returns - Returns self, useful for chaining.
  2280. */
  2281. addAttribute(id: string, buffer: Buffer_2 | Float32Array | Uint32Array | Array<number>, size?: number, normalized?: boolean, type?: TYPES, stride?: number, start?: number, instance?: boolean): this;
  2282. /**
  2283. * Returns the requested attribute.
  2284. * @param id - The name of the attribute required
  2285. * @returns - The attribute requested.
  2286. */
  2287. getAttribute(id: string): Attribute;
  2288. /**
  2289. * Returns the requested buffer.
  2290. * @param id - The name of the buffer required.
  2291. * @returns - The buffer requested.
  2292. */
  2293. getBuffer(id: string): Buffer_2;
  2294. /**
  2295. *
  2296. * Adds an index buffer to the geometry
  2297. * The index buffer contains integers, three for each triangle in the geometry, which reference the various attribute buffers (position, colour, UV coordinates, other UV coordinates, normal, …). There is only ONE index buffer.
  2298. * @param {PIXI.Buffer|number[]} [buffer] - The buffer that holds the data of the index buffer. You can also provide an Array and a buffer will be created from it.
  2299. * @returns - Returns self, useful for chaining.
  2300. */
  2301. addIndex(buffer?: Buffer_2 | IArrayBuffer | number[]): Geometry;
  2302. /**
  2303. * Returns the index buffer
  2304. * @returns - The index buffer.
  2305. */
  2306. getIndex(): Buffer_2;
  2307. /**
  2308. * This function modifies the structure so that all current attributes become interleaved into a single buffer
  2309. * This can be useful if your model remains static as it offers a little performance boost
  2310. * @returns - Returns self, useful for chaining.
  2311. */
  2312. interleave(): Geometry;
  2313. /** Get the size of the geometries, in vertices. */
  2314. getSize(): number;
  2315. /** Disposes WebGL resources that are connected to this geometry. */
  2316. dispose(): void;
  2317. /** Destroys the geometry. */
  2318. destroy(): void;
  2319. /**
  2320. * Returns a clone of the geometry.
  2321. * @returns - A new clone of this geometry.
  2322. */
  2323. clone(): Geometry;
  2324. /**
  2325. * Merges an array of geometries into a new single one.
  2326. *
  2327. * Geometry attribute styles must match for this operation to work.
  2328. * @param geometries - array of geometries to merge
  2329. * @returns - Shiny new geometry!
  2330. */
  2331. static merge(geometries: Array<Geometry>): Geometry;
  2332. }
  2333. /**
  2334. * System plugin to the renderer to manage geometry.
  2335. * @memberof PIXI
  2336. */
  2337. export declare class GeometrySystem implements ISystem {
  2338. /**
  2339. * `true` if we has `*_vertex_array_object` extension.
  2340. * @readonly
  2341. */
  2342. hasVao: boolean;
  2343. /**
  2344. * `true` if has `ANGLE_instanced_arrays` extension.
  2345. * @readonly
  2346. */
  2347. hasInstance: boolean;
  2348. /**
  2349. * `true` if support `gl.UNSIGNED_INT` in `gl.drawElements` or `gl.drawElementsInstanced`.
  2350. * @readonly
  2351. */
  2352. canUseUInt32ElementIndex: boolean;
  2353. protected CONTEXT_UID: number;
  2354. protected gl: IRenderingContext;
  2355. protected _activeGeometry: Geometry;
  2356. protected _activeVao: WebGLVertexArrayObject;
  2357. protected _boundBuffer: GLBuffer;
  2358. /** Cache for all geometries by id, used in case renderer gets destroyed or for profiling. */
  2359. readonly managedGeometries: {
  2360. [key: number]: Geometry;
  2361. };
  2362. /** Renderer that owns this {@link GeometrySystem}. */
  2363. private renderer;
  2364. /** @param renderer - The renderer this System works for. */
  2365. constructor(renderer: Renderer);
  2366. /** Sets up the renderer context and necessary buffers. */
  2367. protected contextChange(): void;
  2368. /**
  2369. * Binds geometry so that is can be drawn. Creating a Vao if required
  2370. * @param geometry - Instance of geometry to bind.
  2371. * @param shader - Instance of shader to use vao for.
  2372. */
  2373. bind(geometry?: Geometry, shader?: Shader): void;
  2374. /** Reset and unbind any active VAO and geometry. */
  2375. reset(): void;
  2376. /** Update buffers of the currently bound geometry. */
  2377. updateBuffers(): void;
  2378. /**
  2379. * Check compatibility between a geometry and a program
  2380. * @param geometry - Geometry instance.
  2381. * @param program - Program instance.
  2382. */
  2383. protected checkCompatibility(geometry: Geometry, program: Program): void;
  2384. /**
  2385. * Takes a geometry and program and generates a unique signature for them.
  2386. * @param geometry - To get signature from.
  2387. * @param program - To test geometry against.
  2388. * @returns - Unique signature of the geometry and program
  2389. */
  2390. protected getSignature(geometry: Geometry, program: Program): string;
  2391. /**
  2392. * Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
  2393. * If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
  2394. * attribute locations.
  2395. * @param geometry - Instance of geometry to to generate Vao for.
  2396. * @param shader - Instance of the shader.
  2397. * @param incRefCount - Increment refCount of all geometry buffers.
  2398. */
  2399. protected initGeometryVao(geometry: Geometry, shader: Shader, incRefCount?: boolean): WebGLVertexArrayObject;
  2400. /**
  2401. * Disposes geometry.
  2402. * @param geometry - Geometry with buffers. Only VAO will be disposed
  2403. * @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
  2404. */
  2405. disposeGeometry(geometry: Geometry, contextLost?: boolean): void;
  2406. /**
  2407. * Dispose all WebGL resources of all managed geometries.
  2408. * @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
  2409. */
  2410. disposeAll(contextLost?: boolean): void;
  2411. /**
  2412. * Activate vertex array object.
  2413. * @param geometry - Geometry instance.
  2414. * @param program - Shader program instance.
  2415. */
  2416. protected activateVao(geometry: Geometry, program: Program): void;
  2417. /**
  2418. * Draws the currently bound geometry.
  2419. * @param type - The type primitive to render.
  2420. * @param size - The number of elements to be rendered. If not specified, all vertices after the
  2421. * starting vertex will be drawn.
  2422. * @param start - The starting vertex in the geometry to start drawing from. If not specified,
  2423. * drawing will start from the first vertex.
  2424. * @param instanceCount - The number of instances of the set of elements to execute. If not specified,
  2425. * all instances will be drawn.
  2426. */
  2427. draw(type: DRAW_MODES, size?: number, start?: number, instanceCount?: number): this;
  2428. /** Unbind/reset everything. */
  2429. protected unbind(): void;
  2430. destroy(): void;
  2431. }
  2432. /**
  2433. * returns a little WebGL context to use for program inspection.
  2434. * @static
  2435. * @private
  2436. * @returns {WebGLRenderingContext} a gl context to test with
  2437. */
  2438. export declare function getTestContext(): WebGLRenderingContext | WebGL2RenderingContext;
  2439. export declare function getUBOData(uniforms: Dict<any>, uniformData: Dict<any>): any[];
  2440. declare class GLBuffer {
  2441. buffer: WebGLBuffer;
  2442. updateID: number;
  2443. byteLength: number;
  2444. refCount: number;
  2445. constructor(buffer?: WebGLBuffer);
  2446. }
  2447. /**
  2448. * Internal framebuffer for WebGL context.
  2449. * @memberof PIXI
  2450. */
  2451. export declare class GLFramebuffer {
  2452. /** The WebGL framebuffer. */
  2453. framebuffer: WebGLFramebuffer;
  2454. /** Stencil+depth , usually costs 32bits per pixel. */
  2455. stencil: WebGLRenderbuffer;
  2456. /** Detected AA samples number. */
  2457. multisample: MSAA_QUALITY;
  2458. /** In case MSAA, we use this Renderbuffer instead of colorTextures[0] when we write info. */
  2459. msaaBuffer: WebGLRenderbuffer;
  2460. /**
  2461. * In case we use MSAA, this is actual framebuffer that has colorTextures[0]
  2462. * The contents of that framebuffer are read when we use that renderTexture in sprites
  2463. */
  2464. blitFramebuffer: Framebuffer;
  2465. /** Latest known version of framebuffer. */
  2466. dirtyId: number;
  2467. /** Latest known version of framebuffer format. */
  2468. dirtyFormat: number;
  2469. /** Latest known version of framebuffer size. */
  2470. dirtySize: number;
  2471. /** Store the current mipmap of the textures the framebuffer will write too. */
  2472. mipLevel: number;
  2473. constructor(framebuffer: WebGLTexture);
  2474. }
  2475. /**
  2476. * Helper class to create a WebGL Program
  2477. * @memberof PIXI
  2478. */
  2479. export declare class GLProgram {
  2480. /** The shader program. */
  2481. program: WebGLProgram;
  2482. /**
  2483. * Holds the uniform data which contains uniform locations
  2484. * and current uniform values used for caching and preventing unneeded GPU commands.
  2485. */
  2486. uniformData: Dict<any>;
  2487. /**
  2488. * UniformGroups holds the various upload functions for the shader. Each uniform group
  2489. * and program have a unique upload function generated.
  2490. */
  2491. uniformGroups: Dict<any>;
  2492. /** A hash that stores where UBOs are bound to on the program. */
  2493. uniformBufferBindings: Dict<any>;
  2494. /** A hash for lazily-generated uniform uploading functions. */
  2495. uniformSync: Dict<any>;
  2496. /**
  2497. * A place where dirty ticks are stored for groups
  2498. * If a tick here does not match with the Higher level Programs tick, it means
  2499. * we should re upload the data.
  2500. */
  2501. uniformDirtyGroups: Dict<any>;
  2502. /**
  2503. * Makes a new Pixi program.
  2504. * @param program - webgl program
  2505. * @param uniformData - uniforms
  2506. */
  2507. constructor(program: WebGLProgram, uniformData: {
  2508. [key: string]: IGLUniformData;
  2509. });
  2510. /** Destroys this program. */
  2511. destroy(): void;
  2512. }
  2513. /**
  2514. * Internal texture for WebGL context.
  2515. * @memberof PIXI
  2516. */
  2517. export declare class GLTexture {
  2518. /** The WebGL texture. */
  2519. texture: WebGLTexture;
  2520. /** Width of texture that was used in texImage2D. */
  2521. width: number;
  2522. /** Height of texture that was used in texImage2D. */
  2523. height: number;
  2524. /** Whether mip levels has to be generated. */
  2525. mipmap: boolean;
  2526. /** WrapMode copied from baseTexture. */
  2527. wrapMode: number;
  2528. /** Type copied from baseTexture. */
  2529. type: number;
  2530. /** Type copied from baseTexture. */
  2531. internalFormat: number;
  2532. /** Type of sampler corresponding to this texture. See {@link PIXI.SAMPLER_TYPES} */
  2533. samplerType: number;
  2534. /** Texture contents dirty flag. */
  2535. dirtyId: number;
  2536. /** Texture style dirty flag. */
  2537. dirtyStyleId: number;
  2538. constructor(texture: WebGLTexture);
  2539. }
  2540. /**
  2541. * Marks places in PixiJS where you can pass Float32Array, UInt32Array, any typed arrays, and ArrayBuffer
  2542. *
  2543. * Same as ArrayBuffer in typescript lib, defined here just for documentation
  2544. */
  2545. export declare interface IArrayBuffer extends ArrayBuffer {
  2546. }
  2547. export declare interface IAttributeData {
  2548. type: string;
  2549. size: number;
  2550. location: number;
  2551. name: string;
  2552. }
  2553. export declare type IAutoDetectOptions = ISize | ICubeResourceOptions | IImageResourceOptions | ISVGResourceOptions | IVideoResourceOptions | IResourcePluginOptions;
  2554. export declare interface IBaseTextureOptions<RO = any> {
  2555. alphaMode?: ALPHA_MODES;
  2556. mipmap?: MIPMAP_MODES;
  2557. anisotropicLevel?: number;
  2558. scaleMode?: SCALE_MODES;
  2559. width?: number;
  2560. height?: number;
  2561. wrapMode?: WRAP_MODES;
  2562. format?: FORMATS;
  2563. type?: TYPES;
  2564. target?: TARGETS;
  2565. resolution?: number;
  2566. multisample?: MSAA_QUALITY;
  2567. resourceOptions?: RO;
  2568. pixiIdPrefix?: string;
  2569. }
  2570. /**
  2571. * Interface for elements like Sprite, Mesh etc. for batching.
  2572. * @memberof PIXI
  2573. */
  2574. export declare interface IBatchableElement {
  2575. _texture: Texture;
  2576. vertexData: Float32Array;
  2577. indices: Uint16Array | Uint32Array | Array<number>;
  2578. uvs: Float32Array;
  2579. worldAlpha: number;
  2580. _tintRGB: number;
  2581. blendMode: BLEND_MODES;
  2582. }
  2583. export declare interface IBatchFactoryOptions {
  2584. vertex?: string;
  2585. fragment?: string;
  2586. geometryClass?: typeof BatchGeometry;
  2587. vertexSize?: number;
  2588. }
  2589. /** Constructor options for CubeResource */
  2590. export declare interface ICubeResourceOptions extends ISize {
  2591. /** Whether to auto-load resources */
  2592. autoLoad?: boolean;
  2593. /** In case BaseTextures are supplied, whether to copy them or use. */
  2594. linkBaseTexture?: boolean;
  2595. }
  2596. export declare interface IFilterTarget {
  2597. filterArea: Rectangle;
  2598. getBounds(skipUpdate?: boolean): Rectangle;
  2599. }
  2600. export declare interface IGenerateTextureOptions {
  2601. scaleMode?: SCALE_MODES;
  2602. resolution?: number;
  2603. region?: Rectangle;
  2604. multisample?: MSAA_QUALITY;
  2605. }
  2606. /**
  2607. * @private
  2608. */
  2609. export declare class IGLUniformData {
  2610. location: WebGLUniformLocation;
  2611. value: number | boolean | Float32Array | Int32Array | Uint32Array | boolean[];
  2612. }
  2613. export declare interface IImageResourceOptions {
  2614. /** Start loading process */
  2615. autoLoad?: boolean;
  2616. /** Whether its required to create a bitmap before upload. */
  2617. createBitmap?: boolean;
  2618. /** Load image using cross origin. */
  2619. crossorigin?: boolean | string;
  2620. /** Premultiply image alpha in bitmap. */
  2621. alphaMode?: ALPHA_MODES;
  2622. }
  2623. /**
  2624. * Resource type for ImageBitmap.
  2625. * @memberof PIXI
  2626. */
  2627. export declare class ImageBitmapResource extends BaseImageResource {
  2628. /**
  2629. * @param source - Image element to use
  2630. */
  2631. constructor(source: ImageBitmap);
  2632. /**
  2633. * Used to auto-detect the type of resource.
  2634. * @param {*} source - The source object
  2635. * @returns {boolean} `true` if source is an ImageBitmap
  2636. */
  2637. static test(source: unknown): source is ImageBitmap;
  2638. }
  2639. /**
  2640. * Resource type for HTMLImageElement.
  2641. * @memberof PIXI
  2642. */
  2643. export declare class ImageResource extends BaseImageResource {
  2644. /** URL of the image source */
  2645. url: string;
  2646. /**
  2647. * If the image should be disposed after upload
  2648. * @default false
  2649. */
  2650. preserveBitmap: boolean;
  2651. /**
  2652. * If capable, convert the image using createImageBitmap API.
  2653. * @default PIXI.settings.CREATE_IMAGE_BITMAP
  2654. */
  2655. createBitmap: boolean;
  2656. /**
  2657. * Controls texture alphaMode field
  2658. * Copies from options
  2659. * Default is `null`, copies option from baseTexture
  2660. * @readonly
  2661. */
  2662. alphaMode: ALPHA_MODES;
  2663. /**
  2664. * The ImageBitmap element created for a {@code HTMLImageElement}.
  2665. * @default null
  2666. */
  2667. bitmap: ImageBitmap;
  2668. /**
  2669. * Promise when loading.
  2670. * @default null
  2671. */
  2672. private _load;
  2673. /** When process is completed */
  2674. private _process;
  2675. /**
  2676. * @param source - image source or URL
  2677. * @param options
  2678. * @param {boolean} [options.autoLoad=true] - start loading process
  2679. * @param {boolean} [options.createBitmap=PIXI.settings.CREATE_IMAGE_BITMAP] - whether its required to create
  2680. * a bitmap before upload
  2681. * @param {boolean} [options.crossorigin=true] - Load image using cross origin
  2682. * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.UNPACK] - Premultiply image alpha in bitmap
  2683. */
  2684. constructor(source: HTMLImageElement | string, options?: IImageResourceOptions);
  2685. /**
  2686. * Returns a promise when image will be loaded and processed.
  2687. * @param createBitmap - whether process image into bitmap
  2688. */
  2689. load(createBitmap?: boolean): Promise<ImageResource>;
  2690. /**
  2691. * Called when we need to convert image into BitmapImage.
  2692. * Can be called multiple times, real promise is cached inside.
  2693. * @returns - Cached promise to fill that bitmap
  2694. */
  2695. process(): Promise<ImageResource>;
  2696. /**
  2697. * Upload the image resource to GPU.
  2698. * @param renderer - Renderer to upload to
  2699. * @param baseTexture - BaseTexture for this resource
  2700. * @param glTexture - GLTexture to use
  2701. * @returns {boolean} true is success
  2702. */
  2703. upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean;
  2704. /** Destroys this resource. */
  2705. dispose(): void;
  2706. /**
  2707. * Used to auto-detect the type of resource.
  2708. * @param {*} source - The source object
  2709. * @returns {boolean} `true` if source is string or HTMLImageElement
  2710. */
  2711. static test(source: unknown): source is string | HTMLImageElement;
  2712. }
  2713. export declare type ImageSource = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap;
  2714. export declare interface IMaskTarget extends IFilterTarget {
  2715. renderable: boolean;
  2716. isSprite?: boolean;
  2717. worldTransform: Matrix;
  2718. isFastRect?(): boolean;
  2719. getBounds(skipUpdate?: boolean, rect?: Rectangle): Rectangle;
  2720. render(renderer: Renderer): void;
  2721. }
  2722. /**
  2723. * Collection of installed resource types, class must extend {@link PIXI.Resource}.
  2724. * @example
  2725. * class CustomResource extends PIXI.Resource {
  2726. * // MUST have source, options constructor signature
  2727. * // for auto-detected resources to be created.
  2728. * constructor(source, options) {
  2729. * super();
  2730. * }
  2731. * upload(renderer, baseTexture, glTexture) {
  2732. * // upload with GL
  2733. * return true;
  2734. * }
  2735. * // used to auto-detect resource
  2736. * static test(source, extension) {
  2737. * return extension === 'xyz'|| source instanceof SomeClass;
  2738. * }
  2739. * }
  2740. * // Install the new resource type
  2741. * PIXI.INSTALLED.push(CustomResource);
  2742. * @memberof PIXI
  2743. * @type {Array<PIXI.IResourcePlugin>}
  2744. * @static
  2745. * @readonly
  2746. */
  2747. export declare const INSTALLED: Array<IResourcePlugin<any, any>>;
  2748. /**
  2749. * Interface for Container to interface with Renderer.
  2750. * @memberof PIXI
  2751. */
  2752. export declare interface IRenderableContainer extends IRenderableObject {
  2753. /** Get Local bounds for container */
  2754. getLocalBounds(rect?: Rectangle, skipChildrenUpdate?: boolean): Rectangle;
  2755. }
  2756. /**
  2757. * Interface for DisplayObject to interface with Renderer.
  2758. * The minimum APIs needed to implement a renderable object.
  2759. * @memberof PIXI
  2760. */
  2761. export declare interface IRenderableObject {
  2762. /** Object must have a parent container */
  2763. parent: IRenderableContainer;
  2764. /** Before method for transform updates */
  2765. enableTempParent(): IRenderableContainer;
  2766. /** Update the transforms */
  2767. updateTransform(): void;
  2768. /** After method for transform updates */
  2769. disableTempParent(parent: IRenderableContainer): void;
  2770. /** Render object directly */
  2771. render(renderer: Renderer): void;
  2772. }
  2773. /**
  2774. * Renderer options supplied to constructor.
  2775. * @memberof PIXI
  2776. * @see PIXI.settings.RENDER_OPTIONS
  2777. */
  2778. export declare interface IRendererOptions extends GlobalMixins.IRendererOptions {
  2779. /** The canvas to use as the view. If omitted, a new canvas will be created. */
  2780. view?: HTMLCanvasElement;
  2781. /**
  2782. * The width of the renderer's view.
  2783. * @default 800
  2784. */
  2785. width?: number;
  2786. /**
  2787. * The height of the renderer's view.
  2788. * @default 600
  2789. */
  2790. height?: number;
  2791. /**
  2792. * The resolution / device pixel ratio of the renderer.
  2793. * @default PIXI.settings.RESOLUTION
  2794. */
  2795. resolution?: number;
  2796. /**
  2797. * Whether the CSS dimensions of the renderer's view should be resized automatically.
  2798. * @default false
  2799. */
  2800. autoDensity?: boolean;
  2801. /**
  2802. * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
  2803. * @default 0x000000
  2804. */
  2805. backgroundColor?: number;
  2806. /**
  2807. * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
  2808. * @default 1
  2809. */
  2810. backgroundAlpha?: number;
  2811. /**
  2812. * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
  2813. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  2814. * If you want to set transparency, please use `backgroundAlpha`.
  2815. *
  2816. * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
  2817. * set to `true` and `premultipliedAlpha` will be to `false`.
  2818. * @default true
  2819. */
  2820. useContextAlpha?: boolean | 'notMultiplied';
  2821. /**
  2822. * Use `backgroundAlpha` instead.
  2823. * @deprecated since 6.0.0
  2824. */
  2825. transparent?: boolean;
  2826. /**
  2827. * Whether to clear the canvas before new render passes.
  2828. * @default true
  2829. */
  2830. clearBeforeRender?: boolean;
  2831. /** **WebGL Only.** User-provided WebGL rendering context object. */
  2832. context?: IRenderingContext;
  2833. /**
  2834. * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
  2835. * @default false
  2836. */
  2837. antialias?: boolean;
  2838. /**
  2839. * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
  2840. * can be `'default'`, `'high-performance'` or `'low-power'`.
  2841. * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
  2842. * while setting to `'low-power'` will prioritize power saving over rendering performance.
  2843. */
  2844. powerPreference?: WebGLPowerPreference;
  2845. /**
  2846. * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
  2847. * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
  2848. * @default false
  2849. */
  2850. preserveDrawingBuffer?: boolean;
  2851. }
  2852. /**
  2853. * Renderer options supplied to `autoDetectRenderer`.
  2854. * @memberof PIXI
  2855. */
  2856. export declare interface IRendererOptionsAuto extends IRendererOptions {
  2857. forceCanvas?: boolean;
  2858. }
  2859. export declare interface IRendererPlugin {
  2860. destroy(): void;
  2861. }
  2862. export declare interface IRendererPluginConstructor {
  2863. new (renderer: Renderer, options?: any): IRendererPlugin;
  2864. }
  2865. export declare interface IRendererPlugins {
  2866. [key: string]: any;
  2867. }
  2868. export declare interface IRendererRenderOptions {
  2869. renderTexture?: RenderTexture;
  2870. clear?: boolean;
  2871. transform?: Matrix;
  2872. skipUpdateTransform?: boolean;
  2873. }
  2874. /** Mixed WebGL1/WebGL2 Rendering Context. Either its WebGL2, either its WebGL1 with PixiJS polyfills on it */
  2875. export declare interface IRenderingContext extends WebGL2RenderingContext {
  2876. }
  2877. /**
  2878. * Shape of supported resource plugins
  2879. * @memberof PIXI
  2880. */
  2881. export declare interface IResourcePlugin<R, RO> {
  2882. test(source: unknown, extension: string): boolean;
  2883. new (source: any, options?: RO): R;
  2884. }
  2885. export declare type IResourcePluginOptions = {
  2886. [key: string]: any;
  2887. };
  2888. export declare interface ISpriteMaskFilter extends Filter {
  2889. maskSprite: IMaskTarget;
  2890. }
  2891. export declare interface ISpriteMaskTarget extends IMaskTarget {
  2892. _texture: Texture;
  2893. worldAlpha: number;
  2894. anchor: Point;
  2895. }
  2896. export declare interface ISupportDict {
  2897. uint32Indices: boolean;
  2898. }
  2899. export declare interface ISVGResourceOptions {
  2900. source?: string;
  2901. scale?: number;
  2902. width?: number;
  2903. height?: number;
  2904. autoLoad?: boolean;
  2905. crossorigin?: boolean | string;
  2906. }
  2907. /**
  2908. * Interface for systems used by the {@link PIXI.Renderer}.
  2909. * @memberof PIXI
  2910. */
  2911. export declare interface ISystem {
  2912. /** Generic destroy methods to be overridden by the subclass */
  2913. destroy(): void;
  2914. }
  2915. /**
  2916. * Types for system and pipe classes.
  2917. * @ignore
  2918. */
  2919. export declare interface ISystemConstructor<R = Renderer> {
  2920. new (renderer: R): ISystem;
  2921. }
  2922. /**
  2923. * PixiJS classes use this type instead of ArrayBuffer and typed arrays
  2924. * to support expressions like `geometry.buffers[0].data[0] = position.x`.
  2925. *
  2926. * Gives access to indexing and `length` field
  2927. * * @popelyshev: If data is actually ArrayBuffer and throws Exception on indexing - its user problem :)
  2928. */
  2929. export declare interface ITypedArray extends IArrayBuffer {
  2930. readonly length: number;
  2931. [index: number]: number;
  2932. readonly BYTES_PER_ELEMENT: number;
  2933. }
  2934. export declare interface IUniformData {
  2935. index: number;
  2936. type: string;
  2937. size: number;
  2938. isArray: boolean;
  2939. value: any;
  2940. name: string;
  2941. }
  2942. export declare interface IUniformParser {
  2943. test(data: unknown, uniform: any): boolean;
  2944. code(name: string, uniform: any): string;
  2945. codeUbo?(name: string, uniform: any): string;
  2946. }
  2947. export declare interface IUnloadableTexture {
  2948. _texture: Texture | RenderTexture;
  2949. children: IUnloadableTexture[];
  2950. }
  2951. export declare interface IVideoResourceOptions {
  2952. autoLoad?: boolean;
  2953. autoPlay?: boolean;
  2954. updateFPS?: number;
  2955. crossorigin?: boolean | string;
  2956. }
  2957. export declare interface IVideoResourceOptionsElement {
  2958. src: string;
  2959. mime: string;
  2960. }
  2961. /**
  2962. * Component for masked elements.
  2963. *
  2964. * Holds mask mode and temporary data about current mask.
  2965. * @memberof PIXI
  2966. */
  2967. export declare class MaskData {
  2968. /** Mask type */
  2969. type: MASK_TYPES;
  2970. /**
  2971. * Whether we know the mask type beforehand
  2972. * @default true
  2973. */
  2974. autoDetect: boolean;
  2975. /**
  2976. * Which element we use to mask
  2977. * @member {PIXI.DisplayObject}
  2978. */
  2979. maskObject: IMaskTarget;
  2980. /** Whether it belongs to MaskSystem pool */
  2981. pooled: boolean;
  2982. /** Indicator of the type (always true for {@link MaskData} objects) */
  2983. isMaskData: boolean;
  2984. /**
  2985. * Resolution of the sprite mask filter.
  2986. * If set to `null` or `0`, the resolution of the current render target is used.
  2987. * @default null
  2988. */
  2989. resolution: number;
  2990. /**
  2991. * Number of samples of the sprite mask filter.
  2992. * If set to `null`, the sample count of the current render target is used.
  2993. * @default PIXI.settings.FILTER_MULTISAMPLE
  2994. */
  2995. multisample: MSAA_QUALITY;
  2996. /** If enabled is true the mask is applied, if false it will not. */
  2997. enabled: boolean;
  2998. /** Color mask. */
  2999. colorMask: COLOR_MASK_BITS;
  3000. /**
  3001. * The sprite mask filter wrapped in an array.
  3002. * @private
  3003. */
  3004. _filters: ISpriteMaskFilter_2[];
  3005. /**
  3006. * Stencil counter above the mask in stack
  3007. * @private
  3008. */
  3009. _stencilCounter: number;
  3010. /**
  3011. * Scissor counter above the mask in stack
  3012. * @private
  3013. */
  3014. _scissorCounter: number;
  3015. /**
  3016. * Scissor operation above the mask in stack.
  3017. * Null if _scissorCounter is zero, rectangle instance if positive.
  3018. * @private
  3019. */
  3020. _scissorRect: Rectangle;
  3021. /**
  3022. * pre-computed scissor rect
  3023. * does become _scissorRect when mask is actually pushed
  3024. * @private
  3025. */
  3026. _scissorRectLocal: Rectangle;
  3027. /**
  3028. * pre-computed color mask
  3029. * @private
  3030. */
  3031. _colorMask: number;
  3032. /**
  3033. * Targeted element. Temporary variable set by MaskSystem
  3034. * @member {PIXI.DisplayObject}
  3035. * @private
  3036. */
  3037. _target: IMaskTarget;
  3038. /**
  3039. * Create MaskData
  3040. * @param {PIXI.DisplayObject} [maskObject=null] - object that describes the mask
  3041. */
  3042. constructor(maskObject?: IMaskTarget);
  3043. /**
  3044. * The sprite mask filter.
  3045. * If set to `null`, the default sprite mask filter is used.
  3046. * @default null
  3047. */
  3048. get filter(): ISpriteMaskFilter_2;
  3049. set filter(value: ISpriteMaskFilter_2);
  3050. /** Resets the mask data after popMask(). */
  3051. reset(): void;
  3052. /**
  3053. * Copies counters from maskData above, called from pushMask().
  3054. * @param maskAbove
  3055. */
  3056. copyCountersOrReset(maskAbove?: MaskData): void;
  3057. }
  3058. /**
  3059. * System plugin to the renderer to manage masks.
  3060. *
  3061. * There are three built-in types of masking:
  3062. * **Scissor Masking**: Scissor masking discards pixels that are outside of a rectangle called the scissor box. It is
  3063. * the most performant as the scissor test is inexpensive. However, it can only be used when the mask is rectangular.
  3064. * **Stencil Masking**: Stencil masking discards pixels that don't overlap with the pixels rendered into the stencil
  3065. * buffer. It is the next fastest option as it does not require rendering into a separate framebuffer. However, it does
  3066. * cause the mask to be rendered **twice** for each masking operation; hence, minimize the rendering cost of your masks.
  3067. * **Sprite Mask Filtering**: Sprite mask filtering discards pixels based on the red channel of the sprite-mask's
  3068. * texture. (Generally, the masking texture is grayscale). Using advanced techniques, you might be able to embed this
  3069. * type of masking in a custom shader - and hence, bypassing the masking system fully for performance wins.
  3070. *
  3071. * The best type of masking is auto-detected when you `push` one. To use scissor masking, you must pass in a `Graphics`
  3072. * object with just a rectangle drawn.
  3073. *
  3074. * ## Mask Stacks
  3075. *
  3076. * In the scene graph, masks can be applied recursively, i.e. a mask can be applied during a masking operation. The mask
  3077. * stack stores the currently applied masks in order. Each {@link PIXI.BaseRenderTexture} holds its own mask stack, i.e.
  3078. * when you switch render-textures, the old masks only applied when you switch back to rendering to the old render-target.
  3079. * @memberof PIXI
  3080. */
  3081. export declare class MaskSystem implements ISystem {
  3082. /**
  3083. * Flag to enable scissor masking.
  3084. * @default true
  3085. */
  3086. enableScissor: boolean;
  3087. /** Pool of used sprite mask filters. */
  3088. protected readonly alphaMaskPool: Array<SpriteMaskFilter[]>;
  3089. /**
  3090. * Current index of alpha mask pool.
  3091. * @default 0
  3092. * @readonly
  3093. */
  3094. protected alphaMaskIndex: number;
  3095. /** Pool of mask data. */
  3096. private readonly maskDataPool;
  3097. private maskStack;
  3098. private renderer;
  3099. /**
  3100. * @param renderer - The renderer this System works for.
  3101. */
  3102. constructor(renderer: Renderer);
  3103. /**
  3104. * Changes the mask stack that is used by this System.
  3105. * @param maskStack - The mask stack
  3106. */
  3107. setMaskStack(maskStack: Array<MaskData>): void;
  3108. /**
  3109. * Enables the mask and appends it to the current mask stack.
  3110. *
  3111. * NOTE: The batch renderer should be flushed beforehand to prevent pending renders from being masked.
  3112. * @param {PIXI.DisplayObject} target - Display Object to push the mask to
  3113. * @param {PIXI.MaskData|PIXI.Sprite|PIXI.Graphics|PIXI.DisplayObject} maskDataOrTarget - The masking data.
  3114. */
  3115. push(target: IMaskTarget, maskDataOrTarget: MaskData | IMaskTarget): void;
  3116. /**
  3117. * Removes the last mask from the mask stack and doesn't return it.
  3118. *
  3119. * NOTE: The batch renderer should be flushed beforehand to render the masked contents before the mask is removed.
  3120. * @param {PIXI.IMaskTarget} target - Display Object to pop the mask from
  3121. */
  3122. pop(target: IMaskTarget): void;
  3123. /**
  3124. * Sets type of MaskData based on its maskObject.
  3125. * @param maskData
  3126. */
  3127. detect(maskData: MaskData): void;
  3128. /**
  3129. * Applies the Mask and adds it to the current filter stack.
  3130. * @param maskData - Sprite to be used as the mask.
  3131. */
  3132. pushSpriteMask(maskData: MaskData): void;
  3133. /**
  3134. * Removes the last filter from the filter stack and doesn't return it.
  3135. * @param maskData - Sprite to be used as the mask.
  3136. */
  3137. popSpriteMask(maskData: MaskData): void;
  3138. /**
  3139. * Pushes the color mask.
  3140. * @param maskData - The mask data
  3141. */
  3142. pushColorMask(maskData: MaskData): void;
  3143. /**
  3144. * Pops the color mask.
  3145. * @param maskData - The mask data
  3146. */
  3147. popColorMask(maskData: MaskData): void;
  3148. destroy(): void;
  3149. }
  3150. /**
  3151. * Base for a common object renderer that can be used as a
  3152. * system renderer plugin.
  3153. * @memberof PIXI
  3154. */
  3155. export declare class ObjectRenderer implements ISystem {
  3156. /** The renderer this manager works for. */
  3157. protected renderer: Renderer;
  3158. /**
  3159. * @param renderer - The renderer this manager works for.
  3160. */
  3161. constructor(renderer: Renderer);
  3162. /** Stub method that should be used to empty the current batch by rendering objects now. */
  3163. flush(): void;
  3164. /** Generic destruction method that frees all resources. This should be called by subclasses. */
  3165. destroy(): void;
  3166. /**
  3167. * Stub method that initializes any state required before
  3168. * rendering starts. It is different from the `prerender`
  3169. * signal, which occurs every frame, in that it is called
  3170. * whenever an object requests _this_ renderer specifically.
  3171. */
  3172. start(): void;
  3173. /** Stops the renderer. It should free up any state and become dormant. */
  3174. stop(): void;
  3175. /**
  3176. * Keeps the object to render. It doesn't have to be
  3177. * rendered immediately.
  3178. * @param {PIXI.DisplayObject} _object - The object to render.
  3179. */
  3180. render(_object: any): void;
  3181. }
  3182. /**
  3183. * Helper class to create a shader program.
  3184. * @memberof PIXI
  3185. */
  3186. export declare class Program {
  3187. id: number;
  3188. /** Source code for the vertex shader. */
  3189. vertexSrc: string;
  3190. /** Source code for the fragment shader. */
  3191. fragmentSrc: string;
  3192. nameCache: any;
  3193. glPrograms: {
  3194. [key: number]: GLProgram;
  3195. };
  3196. syncUniforms: any;
  3197. /** Assigned when a program is first bound to the shader system. */
  3198. attributeData: {
  3199. [key: string]: IAttributeData;
  3200. };
  3201. /** Assigned when a program is first bound to the shader system. */
  3202. uniformData: {
  3203. [key: string]: IUniformData;
  3204. };
  3205. /**
  3206. * @param vertexSrc - The source of the vertex shader.
  3207. * @param fragmentSrc - The source of the fragment shader.
  3208. * @param name - Name for shader
  3209. */
  3210. constructor(vertexSrc?: string, fragmentSrc?: string, name?: string);
  3211. /**
  3212. * The default vertex shader source.
  3213. * @constant
  3214. */
  3215. static get defaultVertexSrc(): string;
  3216. /**
  3217. * The default fragment shader source.
  3218. * @constant
  3219. */
  3220. static get defaultFragmentSrc(): string;
  3221. /**
  3222. * A short hand function to create a program based of a vertex and fragment shader.
  3223. *
  3224. * This method will also check to see if there is a cached program.
  3225. * @param vertexSrc - The source of the vertex shader.
  3226. * @param fragmentSrc - The source of the fragment shader.
  3227. * @param name - Name for shader
  3228. * @returns A shiny new PixiJS shader program!
  3229. */
  3230. static from(vertexSrc?: string, fragmentSrc?: string, name?: string): Program;
  3231. }
  3232. /**
  3233. * System plugin to the renderer to manage the projection matrix.
  3234. *
  3235. * The `projectionMatrix` is a global uniform provided to all shaders. It is used to transform points in world space to
  3236. * normalized device coordinates.
  3237. * @memberof PIXI
  3238. */
  3239. export declare class ProjectionSystem implements ISystem {
  3240. /**
  3241. * The destination frame used to calculate the current projection matrix.
  3242. *
  3243. * The destination frame is the rectangle in the render-target into which contents are rendered. If rendering
  3244. * to the screen, the origin is on the top-left. If rendering to a framebuffer, the origin is on the
  3245. * bottom-left. This "flipping" phenomenon is because of WebGL convention for (shader) texture coordinates, where
  3246. * the bottom-left corner is (0,0). It allows display-objects to map their (0,0) position in local-space (top-left)
  3247. * to (0,0) in texture space (bottom-left). In other words, a sprite's top-left corner actually renders the
  3248. * texture's bottom-left corner. You will also notice this when using a tool like SpectorJS to view your textures
  3249. * at runtime.
  3250. *
  3251. * The destination frame's dimensions (width,height) should be equal to the source frame. This is because,
  3252. * otherwise, the contents will be scaled to fill the destination frame. Similarly, the destination frame's (x,y)
  3253. * coordinates are (0,0) unless you know what you're doing.
  3254. * @readonly
  3255. */
  3256. destinationFrame: Rectangle;
  3257. /**
  3258. * The source frame used to calculate the current projection matrix.
  3259. *
  3260. * The source frame is the rectangle in world space containing the contents to be rendered.
  3261. * @readonly
  3262. */
  3263. sourceFrame: Rectangle;
  3264. /**
  3265. * Default destination frame
  3266. *
  3267. * This is not used internally. It is not advised to use this feature specifically unless you know what
  3268. * you're doing. The `update` method will default to this frame if you do not pass the destination frame.
  3269. * @readonly
  3270. */
  3271. defaultFrame: Rectangle;
  3272. /**
  3273. * Projection matrix
  3274. *
  3275. * This matrix can be used to transform points from world space to normalized device coordinates, and is calculated
  3276. * from the sourceFrame → destinationFrame mapping provided.
  3277. *
  3278. * The renderer's `globalUniforms` keeps a reference to this, and so it is available for all shaders to use as a
  3279. * uniform.
  3280. * @readonly
  3281. */
  3282. projectionMatrix: Matrix;
  3283. /**
  3284. * A transform to be appended to the projection matrix.
  3285. *
  3286. * This can be used to transform points in world-space one last time before they are outputted by the shader. You can
  3287. * use to rotate the whole scene, for example. Remember to clear it once you've rendered everything.
  3288. * @member {PIXI.Matrix}
  3289. */
  3290. transform: Matrix;
  3291. private renderer;
  3292. /** @param renderer - The renderer this System works for. */
  3293. constructor(renderer: Renderer);
  3294. /**
  3295. * Updates the projection-matrix based on the sourceFrame → destinationFrame mapping provided.
  3296. *
  3297. * NOTE: It is expected you call `renderer.framebuffer.setViewport(destinationFrame)` after this. This is because
  3298. * the framebuffer viewport converts shader vertex output in normalized device coordinates to window coordinates.
  3299. *
  3300. * NOTE-2: {@link RenderTextureSystem#bind} updates the projection-matrix when you bind a render-texture. It is expected
  3301. * that you dirty the current bindings when calling this manually.
  3302. * @param destinationFrame - The rectangle in the render-target to render the contents into. If rendering to the canvas,
  3303. * the origin is on the top-left; if rendering to a render-texture, the origin is on the bottom-left.
  3304. * @param sourceFrame - The rectangle in world space that contains the contents being rendered.
  3305. * @param resolution - The resolution of the render-target, which is the ratio of
  3306. * world-space (or CSS) pixels to physical pixels.
  3307. * @param root - Whether the render-target is the screen. This is required because rendering to textures
  3308. * is y-flipped (i.e. upside down relative to the screen).
  3309. */
  3310. update(destinationFrame: Rectangle, sourceFrame: Rectangle, resolution: number, root: boolean): void;
  3311. /**
  3312. * Calculates the `projectionMatrix` to map points inside `sourceFrame` to inside `destinationFrame`.
  3313. * @param _destinationFrame - The destination frame in the render-target.
  3314. * @param sourceFrame - The source frame in world space.
  3315. * @param _resolution - The render-target's resolution, i.e. ratio of CSS to physical pixels.
  3316. * @param root - Whether rendering into the screen. Otherwise, if rendering to a framebuffer, the projection
  3317. * is y-flipped.
  3318. */
  3319. calculateProjection(_destinationFrame: Rectangle, sourceFrame: Rectangle, _resolution: number, root: boolean): void;
  3320. /**
  3321. * Sets the transform of the active render target to the given matrix.
  3322. * @param _matrix - The transformation matrix
  3323. */
  3324. setTransform(_matrix: Matrix): void;
  3325. destroy(): void;
  3326. }
  3327. /**
  3328. * Helper class to create a quad
  3329. * @memberof PIXI
  3330. */
  3331. export declare class Quad extends Geometry {
  3332. constructor();
  3333. }
  3334. /**
  3335. * Helper class to create a quad with uvs like in v4
  3336. * @memberof PIXI
  3337. */
  3338. export declare class QuadUv extends Geometry {
  3339. vertexBuffer: Buffer_2;
  3340. uvBuffer: Buffer_2;
  3341. /** An array of vertices. */
  3342. vertices: Float32Array;
  3343. /** The Uvs of the quad. */
  3344. uvs: Float32Array;
  3345. constructor();
  3346. /**
  3347. * Maps two Rectangle to the quad.
  3348. * @param targetTextureFrame - The first rectangle
  3349. * @param destinationFrame - The second rectangle
  3350. * @returns - Returns itself.
  3351. */
  3352. map(targetTextureFrame: Rectangle, destinationFrame: Rectangle): this;
  3353. /**
  3354. * Legacy upload method, just marks buffers dirty.
  3355. * @returns - Returns itself.
  3356. */
  3357. invalidate(): this;
  3358. }
  3359. /**
  3360. * The Renderer draws the scene and all its content onto a WebGL enabled canvas.
  3361. *
  3362. * This renderer should be used for browsers that support WebGL.
  3363. *
  3364. * This renderer works by automatically managing WebGLBatchesm, so no need for Sprite Batches or Sprite Clouds.
  3365. * Don't forget to add the view to your DOM or you will not see anything!
  3366. *
  3367. * Renderer is composed of systems that manage specific tasks. The following systems are added by default
  3368. * whenever you create a renderer:
  3369. *
  3370. * | System | Description |
  3371. * | ------------------------------------ | ----------------------------------------------------------------------------- |
  3372. * | {@link PIXI.BatchSystem} | This manages object renderers that defer rendering until a flush. |
  3373. * | {@link PIXI.ContextSystem} | This manages the WebGL context and extensions. |
  3374. * | {@link PIXI.EventSystem} | This manages UI events. |
  3375. * | {@link PIXI.FilterSystem} | This manages the filtering pipeline for post-processing effects. |
  3376. * | {@link PIXI.FramebufferSystem} | This manages framebuffers, which are used for offscreen rendering. |
  3377. * | {@link PIXI.GeometrySystem} | This manages geometries & buffers, which are used to draw object meshes. |
  3378. * | {@link PIXI.MaskSystem} | This manages masking operations. |
  3379. * | {@link PIXI.ProjectionSystem} | This manages the `projectionMatrix`, used by shaders to get NDC coordinates. |
  3380. * | {@link PIXI.RenderTextureSystem} | This manages render-textures, which are an abstraction over framebuffers. |
  3381. * | {@link PIXI.ScissorSystem} | This handles scissor masking, and is used internally by {@link MaskSystem} |
  3382. * | {@link PIXI.ShaderSystem} | This manages shaders, programs that run on the GPU to calculate 'em pixels. |
  3383. * | {@link PIXI.StateSystem} | This manages the WebGL state variables like blend mode, depth testing, etc. |
  3384. * | {@link PIXI.StencilSystem} | This handles stencil masking, and is used internally by {@link MaskSystem} |
  3385. * | {@link PIXI.TextureSystem} | This manages textures and their resources on the GPU. |
  3386. * | {@link PIXI.TextureGCSystem} | This will automatically remove textures from the GPU if they are not used. |
  3387. *
  3388. * The breadth of the API surface provided by the renderer is contained within these systems.
  3389. * @memberof PIXI
  3390. */
  3391. export declare class Renderer extends AbstractRenderer {
  3392. /**
  3393. * WebGL context, set by {@link PIXI.ContextSystem this.context}.
  3394. * @readonly
  3395. * @member {WebGLRenderingContext}
  3396. */
  3397. gl: IRenderingContext;
  3398. /** Global uniforms */
  3399. globalUniforms: UniformGroup;
  3400. /** Unique UID assigned to the renderer's WebGL context. */
  3401. CONTEXT_UID: number;
  3402. /**
  3403. * Flag if we are rendering to the screen vs renderTexture
  3404. * @readonly
  3405. * @default true
  3406. */
  3407. renderingToScreen: boolean;
  3408. /**
  3409. * The number of msaa samples of the canvas.
  3410. * @readonly
  3411. */
  3412. multisample: MSAA_QUALITY;
  3413. /**
  3414. * Mask system instance
  3415. * @readonly
  3416. */
  3417. mask: MaskSystem;
  3418. /**
  3419. * Context system instance
  3420. * @readonly
  3421. */
  3422. context: ContextSystem;
  3423. /**
  3424. * State system instance
  3425. * @readonly
  3426. */
  3427. state: StateSystem;
  3428. /**
  3429. * Shader system instance
  3430. * @readonly
  3431. */
  3432. shader: ShaderSystem;
  3433. /**
  3434. * Texture system instance
  3435. * @readonly
  3436. */
  3437. texture: TextureSystem;
  3438. /**
  3439. * Buffer system instance
  3440. * @readonly
  3441. */
  3442. buffer: BufferSystem;
  3443. /**
  3444. * Geometry system instance
  3445. * @readonly
  3446. */
  3447. geometry: GeometrySystem;
  3448. /**
  3449. * Framebuffer system instance
  3450. * @readonly
  3451. */
  3452. framebuffer: FramebufferSystem;
  3453. /**
  3454. * Scissor system instance
  3455. * @readonly
  3456. */
  3457. scissor: ScissorSystem;
  3458. /**
  3459. * Stencil system instance
  3460. * @readonly
  3461. */
  3462. stencil: StencilSystem;
  3463. /**
  3464. * Projection system instance
  3465. * @readonly
  3466. */
  3467. projection: ProjectionSystem;
  3468. /**
  3469. * Texture garbage collector system instance
  3470. * @readonly
  3471. */
  3472. textureGC: TextureGCSystem;
  3473. /**
  3474. * Filter system instance
  3475. * @readonly
  3476. */
  3477. filter: FilterSystem;
  3478. /**
  3479. * RenderTexture system instance
  3480. * @readonly
  3481. */
  3482. renderTexture: RenderTextureSystem;
  3483. /**
  3484. * Batch system instance
  3485. * @readonly
  3486. */
  3487. batch: BatchSystem;
  3488. /**
  3489. * Internal signal instances of **runner**, these
  3490. * are assigned to each system created.
  3491. * @see PIXI.Runner
  3492. * @name runners
  3493. * @private
  3494. * @type {object}
  3495. * @readonly
  3496. * @property {PIXI.Runner} destroy - Destroy runner
  3497. * @property {PIXI.Runner} contextChange - Context change runner
  3498. * @property {PIXI.Runner} reset - Reset runner
  3499. * @property {PIXI.Runner} update - Update runner
  3500. * @property {PIXI.Runner} postrender - Post-render runner
  3501. * @property {PIXI.Runner} prerender - Pre-render runner
  3502. * @property {PIXI.Runner} resize - Resize runner
  3503. */
  3504. runners: {
  3505. [key: string]: Runner;
  3506. };
  3507. /**
  3508. * Create renderer if WebGL is available. Overrideable
  3509. * by the **@pixi/canvas-renderer** package to allow fallback.
  3510. * throws error if WebGL is not available.
  3511. * @param options
  3512. * @private
  3513. */
  3514. static create(options?: IRendererOptions): AbstractRenderer;
  3515. /**
  3516. * @param {PIXI.IRendererOptions} [options] - The optional renderer parameters.
  3517. * @param {boolean} [options.antialias=false] -
  3518. * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
  3519. * @param {boolean} [options.autoDensity=false] -
  3520. * Whether the CSS dimensions of the renderer's view should be resized automatically.
  3521. * @param {number} [options.backgroundAlpha=1] -
  3522. * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
  3523. * @param {number} [options.backgroundColor=0x000000] -
  3524. * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
  3525. * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.
  3526. * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.
  3527. * @param {number} [options.height=600] - The height of the renderer's view.
  3528. * @param {string} [options.powerPreference] -
  3529. * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
  3530. * can be `'default'`, `'high-performance'` or `'low-power'`.
  3531. * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
  3532. * while setting to `'low-power'` will prioritize power saving over rendering performance.
  3533. * @param {boolean} [options.premultipliedAlpha=true] -
  3534. * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
  3535. * @param {boolean} [options.preserveDrawingBuffer=false] -
  3536. * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
  3537. * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
  3538. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -
  3539. * The resolution / device pixel ratio of the renderer.
  3540. * @param {boolean} [options.transparent] -
  3541. * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \
  3542. * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.
  3543. * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -
  3544. * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
  3545. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  3546. * If you want to set transparency, please use `backgroundAlpha`. \
  3547. * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
  3548. * set to `true` and `premultipliedAlpha` will be to `false`.
  3549. * @param {HTMLCanvasElement} [options.view=null] -
  3550. * The canvas to use as the view. If omitted, a new canvas will be created.
  3551. * @param {number} [options.width=800] - The width of the renderer's view.
  3552. */
  3553. constructor(options?: IRendererOptions);
  3554. protected contextChange(): void;
  3555. /**
  3556. * Add a new system to the renderer.
  3557. * @param ClassRef - Class reference
  3558. * @param name - Property name for system, if not specified
  3559. * will use a static `name` property on the class itself. This
  3560. * name will be assigned as s property on the Renderer so make
  3561. * sure it doesn't collide with properties on Renderer.
  3562. * @returns Return instance of renderer
  3563. */
  3564. addSystem(ClassRef: ISystemConstructor, name: string): this;
  3565. /**
  3566. * Renders the object to its WebGL view.
  3567. * @param displayObject - The object to be rendered.
  3568. * @param {object} [options] - Object to use for render options.
  3569. * @param {PIXI.RenderTexture} [options.renderTexture] - The render texture to render to.
  3570. * @param {boolean} [options.clear=true] - Should the canvas be cleared before the new render.
  3571. * @param {PIXI.Matrix} [options.transform] - A transform to apply to the render texture before rendering.
  3572. * @param {boolean} [options.skipUpdateTransform=false] - Should we skip the update transform pass?
  3573. */
  3574. render(displayObject: IRenderableObject, options?: IRendererRenderOptions): void;
  3575. /**
  3576. * Please use the `option` render arguments instead.
  3577. * @deprecated Since 6.0.0
  3578. * @param displayObject
  3579. * @param renderTexture
  3580. * @param clear
  3581. * @param transform
  3582. * @param skipUpdateTransform
  3583. */
  3584. render(displayObject: IRenderableObject, renderTexture?: RenderTexture, clear?: boolean, transform?: Matrix, skipUpdateTransform?: boolean): void;
  3585. /**
  3586. * @override
  3587. * @ignore
  3588. */
  3589. generateTexture(displayObject: IRenderableObject, options?: IGenerateTextureOptions | SCALE_MODES, resolution?: number, region?: Rectangle): RenderTexture;
  3590. /**
  3591. * Resizes the WebGL view to the specified width and height.
  3592. * @param desiredScreenWidth - The desired width of the screen.
  3593. * @param desiredScreenHeight - The desired height of the screen.
  3594. */
  3595. resize(desiredScreenWidth: number, desiredScreenHeight: number): void;
  3596. /**
  3597. * Resets the WebGL state so you can render things however you fancy!
  3598. * @returns Returns itself.
  3599. */
  3600. reset(): this;
  3601. /** Clear the frame buffer. */
  3602. clear(): void;
  3603. /**
  3604. * Removes everything from the renderer (event listeners, spritebatch, etc...)
  3605. * @param [removeView=false] - Removes the Canvas element from the DOM.
  3606. * See: https://github.com/pixijs/pixi.js/issues/2233
  3607. */
  3608. destroy(removeView?: boolean): void;
  3609. /**
  3610. * Please use `plugins.extract` instead.
  3611. * @member {PIXI.Extract} extract
  3612. * @deprecated since 6.0.0
  3613. * @readonly
  3614. */
  3615. get extract(): any;
  3616. /**
  3617. * Collection of installed plugins. These are included by default in PIXI, but can be excluded
  3618. * by creating a custom build. Consult the README for more information about creating custom
  3619. * builds and excluding plugins.
  3620. * @readonly
  3621. * @property {PIXI.AccessibilityManager} accessibility Support tabbing interactive elements.
  3622. * @property {PIXI.Extract} extract Extract image data from renderer.
  3623. * @property {PIXI.InteractionManager} interaction Handles mouse, touch and pointer events.
  3624. * @property {PIXI.ParticleRenderer} particle Renderer for ParticleContainer objects.
  3625. * @property {PIXI.Prepare} prepare Pre-render display objects.
  3626. * @property {PIXI.BatchRenderer} batch Batching of Sprite, Graphics and Mesh objects.
  3627. * @property {PIXI.TilingSpriteRenderer} tilingSprite Renderer for TilingSprite objects.
  3628. */
  3629. static __plugins: IRendererPlugins;
  3630. /**
  3631. * Use the {@link PIXI.extensions.add} API to register plugins.
  3632. * @deprecated since 6.5.0
  3633. * @param pluginName - The name of the plugin.
  3634. * @param ctor - The constructor function or class for the plugin.
  3635. */
  3636. static registerPlugin(pluginName: string, ctor: IRendererPluginConstructor): void;
  3637. }
  3638. /**
  3639. * A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  3640. *
  3641. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded
  3642. * otherwise black rectangles will be drawn instead.
  3643. *
  3644. * __Hint-2__: The actual memory allocation will happen on first render.
  3645. * You shouldn't create renderTextures each frame just to delete them after, try to reuse them.
  3646. *
  3647. * A RenderTexture takes a snapshot of any Display Object given to its render method. For example:
  3648. *
  3649. * ```js
  3650. * let renderer = PIXI.autoDetectRenderer();
  3651. * let renderTexture = PIXI.RenderTexture.create({ width: 800, height: 600 });
  3652. * let sprite = PIXI.Sprite.from("spinObj_01.png");
  3653. *
  3654. * sprite.position.x = 800/2;
  3655. * sprite.position.y = 600/2;
  3656. * sprite.anchor.x = 0.5;
  3657. * sprite.anchor.y = 0.5;
  3658. *
  3659. * renderer.render(sprite, {renderTexture});
  3660. * ```
  3661. * Note that you should not create a new renderer, but reuse the same one as the rest of the application.
  3662. *
  3663. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  3664. * you can clear the transform
  3665. *
  3666. * ```js
  3667. *
  3668. * sprite.setTransform()
  3669. *
  3670. * let renderTexture = new PIXI.RenderTexture.create({ width: 100, height: 100 });
  3671. *
  3672. * renderer.render(sprite, {renderTexture}); // Renders to center of RenderTexture
  3673. * ```
  3674. * @memberof PIXI
  3675. */
  3676. export declare class RenderTexture extends Texture {
  3677. baseTexture: BaseRenderTexture;
  3678. /**
  3679. * Stores `sourceFrame` when this texture is inside current filter stack.
  3680. *
  3681. * You can read it inside filters.
  3682. * @readonly
  3683. */
  3684. filterFrame: Rectangle | null;
  3685. /**
  3686. * The key for pooled texture of FilterSystem.
  3687. * @see PIXI.RenderTexturePool
  3688. */
  3689. filterPoolKey: string | number | null;
  3690. /**
  3691. * @param baseRenderTexture - The base texture object that this texture uses.
  3692. * @param frame - The rectangle frame of the texture to show.
  3693. */
  3694. constructor(baseRenderTexture: BaseRenderTexture, frame?: Rectangle);
  3695. /**
  3696. * Shortcut to `this.baseTexture.framebuffer`, saves baseTexture cast.
  3697. * @readonly
  3698. */
  3699. get framebuffer(): Framebuffer;
  3700. /**
  3701. * Shortcut to `this.framebuffer.multisample`.
  3702. * @default PIXI.MSAA_QUALITY.NONE
  3703. */
  3704. get multisample(): MSAA_QUALITY;
  3705. set multisample(value: MSAA_QUALITY);
  3706. /**
  3707. * Resizes the RenderTexture.
  3708. * @param desiredWidth - The desired width to resize to.
  3709. * @param desiredHeight - The desired height to resize to.
  3710. * @param resizeBaseTexture - Should the baseTexture.width and height values be resized as well?
  3711. */
  3712. resize(desiredWidth: number, desiredHeight: number, resizeBaseTexture?: boolean): void;
  3713. /**
  3714. * Changes the resolution of baseTexture, but does not change framebuffer size.
  3715. * @param resolution - The new resolution to apply to RenderTexture
  3716. */
  3717. setResolution(resolution: number): void;
  3718. /**
  3719. * Use the object-based construction instead.
  3720. * @deprecated since 6.0.0
  3721. * @param {number} [width]
  3722. * @param {number} [height]
  3723. * @param {PIXI.SCALE_MODES} [scaleMode=PIXI.settings.SCALE_MODE]
  3724. * @param {number} [resolution=PIXI.settings.FILTER_RESOLUTION]
  3725. */
  3726. static create(width: number, height: number, scaleMode?: SCALE_MODES, resolution?: number): RenderTexture;
  3727. /**
  3728. * A short hand way of creating a render texture.
  3729. * @param options - Options
  3730. * @param {number} [options.width=100] - The width of the render texture
  3731. * @param {number} [options.height=100] - The height of the render texture
  3732. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES}
  3733. * for possible values
  3734. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the texture
  3735. * being generated
  3736. * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer
  3737. * @returns The new render texture
  3738. */
  3739. static create(options?: IBaseTextureOptions): RenderTexture;
  3740. }
  3741. /**
  3742. * Texture pool, used by FilterSystem and plugins.
  3743. *
  3744. * Stores collection of temporary pow2 or screen-sized renderTextures
  3745. *
  3746. * If you use custom RenderTexturePool for your filters, you can use methods
  3747. * `getFilterTexture` and `returnFilterTexture` same as in
  3748. * @memberof PIXI
  3749. */
  3750. export declare class RenderTexturePool {
  3751. textureOptions: IBaseTextureOptions;
  3752. /**
  3753. * Allow renderTextures of the same size as screen, not just pow2
  3754. *
  3755. * Automatically sets to true after `setScreenSize`
  3756. * @default false
  3757. */
  3758. enableFullScreen: boolean;
  3759. texturePool: {
  3760. [x in string | number]: RenderTexture[];
  3761. };
  3762. private _pixelsWidth;
  3763. private _pixelsHeight;
  3764. /**
  3765. * @param textureOptions - options that will be passed to BaseRenderTexture constructor
  3766. * @param {PIXI.SCALE_MODES} [textureOptions.scaleMode] - See {@link PIXI.SCALE_MODES} for possible values.
  3767. */
  3768. constructor(textureOptions?: IBaseTextureOptions);
  3769. /**
  3770. * Creates texture with params that were specified in pool constructor.
  3771. * @param realWidth - Width of texture in pixels.
  3772. * @param realHeight - Height of texture in pixels.
  3773. * @param multisample - Number of samples of the framebuffer.
  3774. */
  3775. createTexture(realWidth: number, realHeight: number, multisample?: MSAA_QUALITY): RenderTexture;
  3776. /**
  3777. * Gets a Power-of-Two render texture or fullScreen texture
  3778. * @param minWidth - The minimum width of the render texture.
  3779. * @param minHeight - The minimum height of the render texture.
  3780. * @param resolution - The resolution of the render texture.
  3781. * @param multisample - Number of samples of the render texture.
  3782. * @returns The new render texture.
  3783. */
  3784. getOptimalTexture(minWidth: number, minHeight: number, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
  3785. /**
  3786. * Gets extra texture of the same size as input renderTexture
  3787. *
  3788. * `getFilterTexture(input, 0.5)` or `getFilterTexture(0.5, input)`
  3789. * @param input - renderTexture from which size and resolution will be copied
  3790. * @param resolution - override resolution of the renderTexture
  3791. * It overrides, it does not multiply
  3792. * @param multisample - number of samples of the renderTexture
  3793. */
  3794. getFilterTexture(input: RenderTexture, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
  3795. /**
  3796. * Place a render texture back into the pool.
  3797. * @param renderTexture - The renderTexture to free
  3798. */
  3799. returnTexture(renderTexture: RenderTexture): void;
  3800. /**
  3801. * Alias for returnTexture, to be compliant with FilterSystem interface.
  3802. * @param renderTexture - The renderTexture to free
  3803. */
  3804. returnFilterTexture(renderTexture: RenderTexture): void;
  3805. /**
  3806. * Clears the pool.
  3807. * @param destroyTextures - Destroy all stored textures.
  3808. */
  3809. clear(destroyTextures?: boolean): void;
  3810. /**
  3811. * If screen size was changed, drops all screen-sized textures,
  3812. * sets new screen size, sets `enableFullScreen` to true
  3813. *
  3814. * Size is measured in pixels, `renderer.view` can be passed here, not `renderer.screen`
  3815. * @param size - Initial size of screen.
  3816. */
  3817. setScreenSize(size: ISize): void;
  3818. /**
  3819. * Key that is used to store fullscreen renderTextures in a pool
  3820. * @constant
  3821. */
  3822. static SCREEN_KEY: number;
  3823. }
  3824. /**
  3825. * System plugin to the renderer to manage render textures.
  3826. *
  3827. * Should be added after FramebufferSystem
  3828. *
  3829. * ### Frames
  3830. *
  3831. * The `RenderTextureSystem` holds a sourceFrame → destinationFrame projection. The following table explains the different
  3832. * coordinate spaces used:
  3833. *
  3834. * | Frame | Description | Coordinate System |
  3835. * | ---------------------- | ---------------------------------------------------------------- | ------------------------------------------------------- |
  3836. * | sourceFrame | The rectangle inside of which display-objects are being rendered | **World Space**: The origin on the top-left |
  3837. * | destinationFrame | The rectangle in the render-target (canvas or texture) into which contents should be rendered | If rendering to the canvas, this is in screen space and the origin is on the top-left. If rendering to a render-texture, this is in its base-texture's space with the origin on the bottom-left. |
  3838. * | viewportFrame | The framebuffer viewport corresponding to the destination-frame | **Window Coordinates**: The origin is always on the bottom-left. |
  3839. * @memberof PIXI
  3840. */
  3841. export declare class RenderTextureSystem implements ISystem {
  3842. /** The clear background color as RGBA. */
  3843. clearColor: number[];
  3844. /**
  3845. * List of masks for the {@link PIXI.StencilSystem}.
  3846. * @readonly
  3847. */
  3848. defaultMaskStack: Array<MaskData>;
  3849. /**
  3850. * Render texture currently bound. {@code null} if rendering to the canvas.
  3851. * @readonly
  3852. */
  3853. current: RenderTexture | null;
  3854. /**
  3855. * The source frame for the render-target's projection mapping.
  3856. *
  3857. * See {@link PIXI.ProjectionSystem#sourceFrame} for more details
  3858. */
  3859. readonly sourceFrame: Rectangle;
  3860. /**
  3861. * The destination frame for the render-target's projection mapping.
  3862. *
  3863. * See {@link PIXI.Projection#destinationFrame} for more details.
  3864. */
  3865. readonly destinationFrame: Rectangle;
  3866. /**
  3867. * The viewport frame for the render-target's viewport binding. This is equal to the destination-frame
  3868. * for render-textures, while it is y-flipped when rendering to the screen (i.e. its origin is always on
  3869. * the bottom-left).
  3870. */
  3871. readonly viewportFrame: Rectangle;
  3872. private renderer;
  3873. /**
  3874. * @param renderer - The renderer this System works for.
  3875. */
  3876. constructor(renderer: Renderer);
  3877. /**
  3878. * Bind the current render texture.
  3879. * @param renderTexture - RenderTexture to bind, by default its `null` - the screen.
  3880. * @param sourceFrame - Part of world that is mapped to the renderTexture.
  3881. * @param destinationFrame - Part of renderTexture, by default it has the same size as sourceFrame.
  3882. */
  3883. bind(renderTexture?: RenderTexture, sourceFrame?: Rectangle, destinationFrame?: Rectangle): void;
  3884. /**
  3885. * Erases the render texture and fills the drawing area with a colour.
  3886. * @param clearColor - The color as rgba, default to use the renderer backgroundColor
  3887. * @param [mask=BUFFER_BITS.COLOR | BUFFER_BITS.DEPTH] - Bitwise OR of masks
  3888. * that indicate the buffers to be cleared, by default COLOR and DEPTH buffers.
  3889. */
  3890. clear(clearColor?: number[], mask?: BUFFER_BITS): void;
  3891. resize(): void;
  3892. /** Resets render-texture state. */
  3893. reset(): void;
  3894. destroy(): void;
  3895. }
  3896. /**
  3897. * Base resource class for textures that manages validation and uploading, depending on its type.
  3898. *
  3899. * Uploading of a base texture to the GPU is required.
  3900. * @memberof PIXI
  3901. */
  3902. export declare abstract class Resource {
  3903. /** The url of the resource */
  3904. src: string;
  3905. /**
  3906. * If resource has been destroyed.
  3907. * @readonly
  3908. * @default false
  3909. */
  3910. destroyed: boolean;
  3911. /**
  3912. * `true` if resource is created by BaseTexture
  3913. * useful for doing cleanup with BaseTexture destroy
  3914. * and not cleaning up resources that were created
  3915. * externally.
  3916. */
  3917. internal: boolean;
  3918. /** Internal width of the resource. */
  3919. protected _width: number;
  3920. /** Internal height of the resource. */
  3921. protected _height: number;
  3922. /**
  3923. * Mini-runner for handling resize events
  3924. * accepts 2 parameters: width, height
  3925. * @member {Runner}
  3926. * @private
  3927. */
  3928. protected onResize: Runner;
  3929. /**
  3930. * Mini-runner for handling update events
  3931. * @member {Runner}
  3932. * @private
  3933. */
  3934. protected onUpdate: Runner;
  3935. /**
  3936. * Handle internal errors, such as loading errors
  3937. * accepts 1 param: error
  3938. * @member {Runner}
  3939. * @private
  3940. */
  3941. protected onError: Runner;
  3942. /**
  3943. * @param width - Width of the resource
  3944. * @param height - Height of the resource
  3945. */
  3946. constructor(width?: number, height?: number);
  3947. /**
  3948. * Bind to a parent BaseTexture
  3949. * @param baseTexture - Parent texture
  3950. */
  3951. bind(baseTexture: BaseTexture): void;
  3952. /**
  3953. * Unbind to a parent BaseTexture
  3954. * @param baseTexture - Parent texture
  3955. */
  3956. unbind(baseTexture: BaseTexture): void;
  3957. /**
  3958. * Trigger a resize event
  3959. * @param width - X dimension
  3960. * @param height - Y dimension
  3961. */
  3962. resize(width: number, height: number): void;
  3963. /**
  3964. * Has been validated
  3965. * @readonly
  3966. */
  3967. get valid(): boolean;
  3968. /** Has been updated trigger event. */
  3969. update(): void;
  3970. /**
  3971. * This can be overridden to start preloading a resource
  3972. * or do any other prepare step.
  3973. * @protected
  3974. * @returns Handle the validate event
  3975. */
  3976. load(): Promise<Resource>;
  3977. /**
  3978. * The width of the resource.
  3979. * @readonly
  3980. */
  3981. get width(): number;
  3982. /**
  3983. * The height of the resource.
  3984. * @readonly
  3985. */
  3986. get height(): number;
  3987. /**
  3988. * Uploads the texture or returns false if it cant for some reason. Override this.
  3989. * @param renderer - yeah, renderer!
  3990. * @param baseTexture - the texture
  3991. * @param glTexture - texture instance for this webgl context
  3992. * @returns - true is success
  3993. */
  3994. abstract upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean;
  3995. /**
  3996. * Set the style, optional to override
  3997. * @param _renderer - yeah, renderer!
  3998. * @param _baseTexture - the texture
  3999. * @param _glTexture - texture instance for this webgl context
  4000. * @returns - `true` is success
  4001. */
  4002. style(_renderer: Renderer, _baseTexture: BaseTexture, _glTexture: GLTexture): boolean;
  4003. /** Clean up anything, this happens when destroying is ready. */
  4004. dispose(): void;
  4005. /**
  4006. * Call when destroying resource, unbind any BaseTexture object
  4007. * before calling this method, as reference counts are maintained
  4008. * internally.
  4009. */
  4010. destroy(): void;
  4011. /**
  4012. * Abstract, used to auto-detect resource type.
  4013. * @param {*} _source - The source object
  4014. * @param {string} _extension - The extension of source, if set
  4015. */
  4016. static test(_source: unknown, _extension?: string): boolean;
  4017. }
  4018. /**
  4019. * @memberof PIXI
  4020. * @namespace resources
  4021. * @see PIXI
  4022. * @deprecated since 6.0.0
  4023. */
  4024. export declare const resources: {};
  4025. /**
  4026. * System plugin to the renderer to manage scissor masking.
  4027. *
  4028. * Scissor masking discards pixels outside of a rectangle called the scissor box. The scissor box is in the framebuffer
  4029. * viewport's space; however, the mask's rectangle is projected from world-space to viewport space automatically
  4030. * by this system.
  4031. * @memberof PIXI
  4032. */
  4033. export declare class ScissorSystem extends AbstractMaskSystem {
  4034. /**
  4035. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  4036. */
  4037. constructor(renderer: Renderer);
  4038. getStackLength(): number;
  4039. /**
  4040. * evaluates _boundsTransformed, _scissorRect for MaskData
  4041. * @param maskData
  4042. */
  4043. calcScissorRect(maskData: MaskData): void;
  4044. private static isMatrixRotated;
  4045. /**
  4046. * Test, whether the object can be scissor mask with current renderer projection.
  4047. * Calls "calcScissorRect()" if its true.
  4048. * @param maskData - mask data
  4049. * @returns whether Whether the object can be scissor mask
  4050. */
  4051. testScissor(maskData: MaskData): boolean;
  4052. private roundFrameToPixels;
  4053. /**
  4054. * Applies the Mask and adds it to the current stencil stack.
  4055. * @author alvin
  4056. * @param maskData - The mask data.
  4057. */
  4058. push(maskData: MaskData): void;
  4059. /**
  4060. * This should be called after a mask is popped off the mask stack. It will rebind the scissor box to be latest with the
  4061. * last mask in the stack.
  4062. *
  4063. * This can also be called when you directly modify the scissor box and want to restore PixiJS state.
  4064. * @param maskData - The mask data.
  4065. */
  4066. pop(maskData?: MaskData): void;
  4067. /**
  4068. * Setup renderer to use the current scissor data.
  4069. * @private
  4070. */
  4071. _useCurrent(): void;
  4072. }
  4073. /**
  4074. * A helper class for shaders.
  4075. * @memberof PIXI
  4076. */
  4077. export declare class Shader {
  4078. /** Program that the shader uses. */
  4079. program: Program;
  4080. uniformGroup: UniformGroup;
  4081. /**
  4082. * Used internally to bind uniform buffer objects.
  4083. * @ignore
  4084. */
  4085. uniformBindCount: number;
  4086. disposeRunner: Runner;
  4087. /**
  4088. * @param program - The program the shader will use.
  4089. * @param uniforms - Custom uniforms to use to augment the built-in ones.
  4090. */
  4091. constructor(program: Program, uniforms?: Dict<any>);
  4092. checkUniformExists(name: string, group: UniformGroup): boolean;
  4093. destroy(): void;
  4094. /**
  4095. * Shader uniform values, shortcut for `uniformGroup.uniforms`.
  4096. * @readonly
  4097. */
  4098. get uniforms(): Dict<any>;
  4099. /**
  4100. * A short hand function to create a shader based of a vertex and fragment shader.
  4101. * @param vertexSrc - The source of the vertex shader.
  4102. * @param fragmentSrc - The source of the fragment shader.
  4103. * @param uniforms - Custom uniforms to use to augment the built-in ones.
  4104. * @returns A shiny new PixiJS shader!
  4105. */
  4106. static from(vertexSrc?: string, fragmentSrc?: string, uniforms?: Dict<any>): Shader;
  4107. }
  4108. /**
  4109. * System plugin to the renderer to manage shaders.
  4110. * @memberof PIXI
  4111. */
  4112. export declare class ShaderSystem implements ISystem {
  4113. /**
  4114. * The current WebGL rendering context.
  4115. * @member {WebGLRenderingContext}
  4116. */
  4117. protected gl: IRenderingContext;
  4118. shader: Shader;
  4119. program: Program;
  4120. id: number;
  4121. destroyed: boolean;
  4122. /** Cache to holds the generated functions. Stored against UniformObjects unique signature. */
  4123. private cache;
  4124. private _uboCache;
  4125. private renderer;
  4126. /** @param renderer - The renderer this System works for. */
  4127. constructor(renderer: Renderer);
  4128. /**
  4129. * Overrideable function by `@pixi/unsafe-eval` to silence
  4130. * throwing an error if platform doesn't support unsafe-evals.
  4131. * @private
  4132. */
  4133. systemCheck(): void;
  4134. protected contextChange(gl: IRenderingContext): void;
  4135. /**
  4136. * Changes the current shader to the one given in parameter.
  4137. * @param shader - the new shader
  4138. * @param dontSync - false if the shader should automatically sync its uniforms.
  4139. * @returns the glProgram that belongs to the shader.
  4140. */
  4141. bind(shader: Shader, dontSync?: boolean): GLProgram;
  4142. /**
  4143. * Uploads the uniforms values to the currently bound shader.
  4144. * @param uniforms - the uniforms values that be applied to the current shader
  4145. */
  4146. setUniforms(uniforms: Dict<any>): void;
  4147. /**
  4148. * Syncs uniforms on the group
  4149. * @param group - the uniform group to sync
  4150. * @param syncData - this is data that is passed to the sync function and any nested sync functions
  4151. */
  4152. syncUniformGroup(group: UniformGroup, syncData?: any): void;
  4153. /**
  4154. * Overrideable by the @pixi/unsafe-eval package to use static syncUniforms instead.
  4155. * @param group
  4156. * @param glProgram
  4157. * @param syncData
  4158. */
  4159. syncUniforms(group: UniformGroup, glProgram: GLProgram, syncData: any): void;
  4160. createSyncGroups(group: UniformGroup): UniformsSyncCallback_2;
  4161. /**
  4162. * Syncs uniform buffers
  4163. * @param group - the uniform buffer group to sync
  4164. * @param name - the name of the uniform buffer
  4165. */
  4166. syncUniformBufferGroup(group: UniformGroup, name?: string): void;
  4167. /**
  4168. * Will create a function that uploads a uniform buffer using the STD140 standard.
  4169. * The upload function will then be cached for future calls
  4170. * If a group is manually managed, then a simple upload function is generated
  4171. * @param group - the uniform buffer group to sync
  4172. * @param glProgram - the gl program to attach the uniform bindings to
  4173. * @param name - the name of the uniform buffer (must exist on the shader)
  4174. */
  4175. protected createSyncBufferGroup(group: UniformGroup, glProgram: GLProgram, name: string): UniformsSyncCallback_2;
  4176. /**
  4177. * Takes a uniform group and data and generates a unique signature for them.
  4178. * @param group - The uniform group to get signature of
  4179. * @param group.uniforms
  4180. * @param uniformData - Uniform information generated by the shader
  4181. * @param preFix
  4182. * @returns Unique signature of the uniform group
  4183. */
  4184. private getSignature;
  4185. /**
  4186. * Returns the underlying GLShade rof the currently bound shader.
  4187. *
  4188. * This can be handy for when you to have a little more control over the setting of your uniforms.
  4189. * @returns The glProgram for the currently bound Shader for this context
  4190. */
  4191. getGlProgram(): GLProgram;
  4192. /**
  4193. * Generates a glProgram version of the Shader provided.
  4194. * @param shader - The shader that the glProgram will be based on.
  4195. * @returns A shiny new glProgram!
  4196. */
  4197. generateProgram(shader: Shader): GLProgram;
  4198. /** Resets ShaderSystem state, does not affect WebGL state. */
  4199. reset(): void;
  4200. /**
  4201. * Disposes shader.
  4202. * If disposing one equals with current shader, set current as null.
  4203. * @param shader - Shader object
  4204. */
  4205. disposeShader(shader: Shader): void;
  4206. /** Destroys this System and removes all its textures. */
  4207. destroy(): void;
  4208. }
  4209. /**
  4210. * This handles a Sprite acting as a mask, as opposed to a Graphic.
  4211. *
  4212. * WebGL only.
  4213. * @memberof PIXI
  4214. */
  4215. export declare class SpriteMaskFilter extends Filter {
  4216. /** @private */
  4217. _maskSprite: IMaskTarget;
  4218. /** Mask matrix */
  4219. maskMatrix: Matrix;
  4220. /**
  4221. * @param {PIXI.Sprite} sprite - The target sprite.
  4222. */
  4223. constructor(sprite: IMaskTarget);
  4224. /**
  4225. * @param vertexSrc - The source of the vertex shader.
  4226. * @param fragmentSrc - The source of the fragment shader.
  4227. * @param uniforms - Custom uniforms to use to augment the built-in ones.
  4228. */
  4229. constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: Dict<any>);
  4230. /**
  4231. * Sprite mask
  4232. * @type {PIXI.DisplayObject}
  4233. */
  4234. get maskSprite(): IMaskTarget;
  4235. set maskSprite(value: IMaskTarget);
  4236. /**
  4237. * Applies the filter
  4238. * @param filterManager - The renderer to retrieve the filter from
  4239. * @param input - The input render target.
  4240. * @param output - The target to output to.
  4241. * @param clearMode - Should the output be cleared before rendering to it.
  4242. */
  4243. apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clearMode: CLEAR_MODES): void;
  4244. }
  4245. /**
  4246. * This is a WebGL state, and is is passed to {@link PIXI.StateSystem}.
  4247. *
  4248. * Each mesh rendered may require WebGL to be in a different state.
  4249. * For example you may want different blend mode or to enable polygon offsets
  4250. * @memberof PIXI
  4251. */
  4252. export declare class State {
  4253. data: number;
  4254. _blendMode: BLEND_MODES;
  4255. _polygonOffset: number;
  4256. constructor();
  4257. /**
  4258. * Activates blending of the computed fragment color values.
  4259. * @default true
  4260. */
  4261. get blend(): boolean;
  4262. set blend(value: boolean);
  4263. /**
  4264. * Activates adding an offset to depth values of polygon's fragments
  4265. * @default false
  4266. */
  4267. get offsets(): boolean;
  4268. set offsets(value: boolean);
  4269. /**
  4270. * Activates culling of polygons.
  4271. * @default false
  4272. */
  4273. get culling(): boolean;
  4274. set culling(value: boolean);
  4275. /**
  4276. * Activates depth comparisons and updates to the depth buffer.
  4277. * @default false
  4278. */
  4279. get depthTest(): boolean;
  4280. set depthTest(value: boolean);
  4281. /**
  4282. * Enables or disables writing to the depth buffer.
  4283. * @default true
  4284. */
  4285. get depthMask(): boolean;
  4286. set depthMask(value: boolean);
  4287. /**
  4288. * Specifies whether or not front or back-facing polygons can be culled.
  4289. * @default false
  4290. */
  4291. get clockwiseFrontFace(): boolean;
  4292. set clockwiseFrontFace(value: boolean);
  4293. /**
  4294. * The blend mode to be applied when this state is set. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  4295. * Setting this mode to anything other than NO_BLEND will automatically switch blending on.
  4296. * @default PIXI.BLEND_MODES.NORMAL
  4297. */
  4298. get blendMode(): BLEND_MODES;
  4299. set blendMode(value: BLEND_MODES);
  4300. /**
  4301. * The polygon offset. Setting this property to anything other than 0 will automatically enable polygon offset fill.
  4302. * @default 0
  4303. */
  4304. get polygonOffset(): number;
  4305. set polygonOffset(value: number);
  4306. toString(): string;
  4307. static for2d(): State;
  4308. }
  4309. /**
  4310. * System plugin to the renderer to manage WebGL state machines.
  4311. * @memberof PIXI
  4312. */
  4313. export declare class StateSystem implements ISystem {
  4314. /**
  4315. * State ID
  4316. * @readonly
  4317. */
  4318. stateId: number;
  4319. /**
  4320. * Polygon offset
  4321. * @readonly
  4322. */
  4323. polygonOffset: number;
  4324. /**
  4325. * Blend mode
  4326. * @default PIXI.BLEND_MODES.NONE
  4327. * @readonly
  4328. */
  4329. blendMode: BLEND_MODES;
  4330. /** Whether current blend equation is different */
  4331. protected _blendEq: boolean;
  4332. /**
  4333. * GL context
  4334. * @member {WebGLRenderingContext}
  4335. * @readonly
  4336. */
  4337. protected gl: IRenderingContext;
  4338. protected blendModes: number[][];
  4339. /**
  4340. * Collection of calls
  4341. * @member {Function[]}
  4342. */
  4343. protected readonly map: Array<(value: boolean) => void>;
  4344. /**
  4345. * Collection of check calls
  4346. * @member {Function[]}
  4347. */
  4348. protected readonly checks: Array<(system: this, state: State) => void>;
  4349. /**
  4350. * Default WebGL State
  4351. * @readonly
  4352. */
  4353. protected defaultState: State;
  4354. constructor();
  4355. contextChange(gl: IRenderingContext): void;
  4356. /**
  4357. * Sets the current state
  4358. * @param {*} state - The state to set.
  4359. */
  4360. set(state: State): void;
  4361. /**
  4362. * Sets the state, when previous state is unknown.
  4363. * @param {*} state - The state to set
  4364. */
  4365. forceState(state: State): void;
  4366. /**
  4367. * Sets whether to enable or disable blending.
  4368. * @param value - Turn on or off WebGl blending.
  4369. */
  4370. setBlend(value: boolean): void;
  4371. /**
  4372. * Sets whether to enable or disable polygon offset fill.
  4373. * @param value - Turn on or off webgl polygon offset testing.
  4374. */
  4375. setOffset(value: boolean): void;
  4376. /**
  4377. * Sets whether to enable or disable depth test.
  4378. * @param value - Turn on or off webgl depth testing.
  4379. */
  4380. setDepthTest(value: boolean): void;
  4381. /**
  4382. * Sets whether to enable or disable depth mask.
  4383. * @param value - Turn on or off webgl depth mask.
  4384. */
  4385. setDepthMask(value: boolean): void;
  4386. /**
  4387. * Sets whether to enable or disable cull face.
  4388. * @param {boolean} value - Turn on or off webgl cull face.
  4389. */
  4390. setCullFace(value: boolean): void;
  4391. /**
  4392. * Sets the gl front face.
  4393. * @param {boolean} value - true is clockwise and false is counter-clockwise
  4394. */
  4395. setFrontFace(value: boolean): void;
  4396. /**
  4397. * Sets the blend mode.
  4398. * @param {number} value - The blend mode to set to.
  4399. */
  4400. setBlendMode(value: number): void;
  4401. /**
  4402. * Sets the polygon offset.
  4403. * @param {number} value - the polygon offset
  4404. * @param {number} scale - the polygon offset scale
  4405. */
  4406. setPolygonOffset(value: number, scale: number): void;
  4407. /** Resets all the logic and disables the VAOs. */
  4408. reset(): void;
  4409. /**
  4410. * Checks to see which updates should be checked based on which settings have been activated.
  4411. *
  4412. * For example, if blend is enabled then we should check the blend modes each time the state is changed
  4413. * or if polygon fill is activated then we need to check if the polygon offset changes.
  4414. * The idea is that we only check what we have too.
  4415. * @param func - the checking function to add or remove
  4416. * @param value - should the check function be added or removed.
  4417. */
  4418. updateCheck(func: (system: this, state: State) => void, value: boolean): void;
  4419. /**
  4420. * A private little wrapper function that we call to check the blend mode.
  4421. * @param system - the System to perform the state check on
  4422. * @param state - the state that the blendMode will pulled from
  4423. */
  4424. private static checkBlendMode;
  4425. /**
  4426. * A private little wrapper function that we call to check the polygon offset.
  4427. * @param system - the System to perform the state check on
  4428. * @param state - the state that the blendMode will pulled from
  4429. */
  4430. private static checkPolygonOffset;
  4431. /**
  4432. * @ignore
  4433. */
  4434. destroy(): void;
  4435. }
  4436. /**
  4437. * System plugin to the renderer to manage stencils (used for masks).
  4438. * @memberof PIXI
  4439. */
  4440. export declare class StencilSystem extends AbstractMaskSystem {
  4441. /**
  4442. * @param renderer - The renderer this System works for.
  4443. */
  4444. constructor(renderer: Renderer);
  4445. getStackLength(): number;
  4446. /**
  4447. * Applies the Mask and adds it to the current stencil stack.
  4448. * @param maskData - The mask data
  4449. */
  4450. push(maskData: MaskData): void;
  4451. /**
  4452. * Pops stencil mask. MaskData is already removed from stack
  4453. * @param {PIXI.DisplayObject} maskObject - object of popped mask data
  4454. */
  4455. pop(maskObject: IMaskTarget): void;
  4456. /**
  4457. * Setup renderer to use the current stencil data.
  4458. * @private
  4459. */
  4460. _useCurrent(): void;
  4461. }
  4462. /**
  4463. * Resource type for SVG elements and graphics.
  4464. * @memberof PIXI
  4465. */
  4466. export declare class SVGResource extends BaseImageResource {
  4467. /** Base64 encoded SVG element or URL for SVG file. */
  4468. readonly svg: string;
  4469. /** The source scale to apply when rasterizing on load. */
  4470. readonly scale: number;
  4471. /** A width override for rasterization on load. */
  4472. readonly _overrideWidth: number;
  4473. /** A height override for rasterization on load. */
  4474. readonly _overrideHeight: number;
  4475. /** Call when completely loaded. */
  4476. private _resolve;
  4477. /** Promise when loading */
  4478. private _load;
  4479. /** Cross origin value to use */
  4480. private _crossorigin?;
  4481. /**
  4482. * @param sourceBase64 - Base64 encoded SVG element or URL for SVG file.
  4483. * @param {object} [options] - Options to use
  4484. * @param {number} [options.scale=1] - Scale to apply to SVG. Overridden by...
  4485. * @param {number} [options.width] - Rasterize SVG this wide. Aspect ratio preserved if height not specified.
  4486. * @param {number} [options.height] - Rasterize SVG this high. Aspect ratio preserved if width not specified.
  4487. * @param {boolean} [options.autoLoad=true] - Start loading right away.
  4488. */
  4489. constructor(sourceBase64: string, options?: ISVGResourceOptions);
  4490. load(): Promise<SVGResource>;
  4491. /** Loads an SVG image from `imageUrl` or `data URL`. */
  4492. private _loadSvg;
  4493. /**
  4494. * Get size from an svg string using a regular expression.
  4495. * @param svgString - a serialized svg element
  4496. * @returns - image extension
  4497. */
  4498. static getSize(svgString?: string): ISize;
  4499. /** Destroys this texture. */
  4500. dispose(): void;
  4501. /**
  4502. * Used to auto-detect the type of resource.
  4503. * @param {*} source - The source object
  4504. * @param {string} extension - The extension of source, if set
  4505. * @returns {boolean} - If the source is a SVG source or data file
  4506. */
  4507. static test(source: unknown, extension?: string): boolean;
  4508. /**
  4509. * Regular expression for SVG XML document.
  4510. * @example &lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;!-- image/svg --&gt;&lt;svg
  4511. * @readonly
  4512. */
  4513. static SVG_XML: RegExp;
  4514. /**
  4515. * Regular expression for SVG size.
  4516. * @example &lt;svg width="100" height="100"&gt;&lt;/svg&gt;
  4517. * @readonly
  4518. */
  4519. static SVG_SIZE: RegExp;
  4520. }
  4521. /**
  4522. * Use the ISystem interface instead.
  4523. * @deprecated since 6.1.0
  4524. * @memberof PIXI
  4525. */
  4526. export declare class System implements ISystem {
  4527. /** Reference to the main renderer */
  4528. renderer: Renderer;
  4529. /**
  4530. * @param renderer - Reference to Renderer
  4531. */
  4532. constructor(renderer: Renderer);
  4533. /** Destroy and don't use after this. */
  4534. destroy(): void;
  4535. }
  4536. /**
  4537. * @memberof PIXI
  4538. * @namespace systems
  4539. * @see PIXI
  4540. * @deprecated since 6.0.0
  4541. */
  4542. export declare const systems: {};
  4543. export declare interface Texture extends GlobalMixins.Texture, EventEmitter {
  4544. }
  4545. /**
  4546. * A texture stores the information that represents an image or part of an image.
  4547. *
  4548. * It cannot be added to the display list directly; instead use it as the texture for a Sprite.
  4549. * If no frame is provided for a texture, then the whole image is used.
  4550. *
  4551. * You can directly create a texture from an image and then reuse it multiple times like this :
  4552. *
  4553. * ```js
  4554. * let texture = PIXI.Texture.from('assets/image.png');
  4555. * let sprite1 = new PIXI.Sprite(texture);
  4556. * let sprite2 = new PIXI.Sprite(texture);
  4557. * ```
  4558. *
  4559. * If you didnt pass the texture frame to constructor, it enables `noFrame` mode:
  4560. * it subscribes on baseTexture events, it automatically resizes at the same time as baseTexture.
  4561. *
  4562. * Textures made from SVGs, loaded or not, cannot be used before the file finishes processing.
  4563. * You can check for this by checking the sprite's _textureID property.
  4564. * ```js
  4565. * var texture = PIXI.Texture.from('assets/image.svg');
  4566. * var sprite1 = new PIXI.Sprite(texture);
  4567. * //sprite1._textureID should not be undefined if the texture has finished processing the SVG file
  4568. * ```
  4569. * You can use a ticker or rAF to ensure your sprites load the finished textures after processing. See issue #3068.
  4570. * @memberof PIXI
  4571. * @typeParam R - The BaseTexture's Resource type.
  4572. */
  4573. export declare class Texture<R extends Resource = Resource> extends EventEmitter {
  4574. /** The base texture that this texture uses. */
  4575. baseTexture: BaseTexture<R>;
  4576. /** This is the area of original texture, before it was put in atlas. */
  4577. orig: Rectangle;
  4578. /**
  4579. * This is the trimmed area of original texture, before it was put in atlas
  4580. * Please call `updateUvs()` after you change coordinates of `trim` manually.
  4581. */
  4582. trim: Rectangle;
  4583. /** This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. */
  4584. valid: boolean;
  4585. /**
  4586. * Does this Texture have any frame data assigned to it?
  4587. *
  4588. * This mode is enabled automatically if no frame was passed inside constructor.
  4589. *
  4590. * In this mode texture is subscribed to baseTexture events, and fires `update` on any change.
  4591. *
  4592. * Beware, after loading or resize of baseTexture event can fired two times!
  4593. * If you want more control, subscribe on baseTexture itself.
  4594. *
  4595. * ```js
  4596. * texture.on('update', () => {});
  4597. * ```
  4598. *
  4599. * Any assignment of `frame` switches off `noFrame` mode.
  4600. */
  4601. noFrame: boolean;
  4602. /**
  4603. * Anchor point that is used as default if sprite is created with this texture.
  4604. * Changing the `defaultAnchor` at a later point of time will not update Sprite's anchor point.
  4605. * @default {0,0}
  4606. */
  4607. defaultAnchor: Point;
  4608. /** Default TextureMatrix instance for this texture. By default, that object is not created because its heavy. */
  4609. uvMatrix: TextureMatrix;
  4610. protected _rotate: number;
  4611. /**
  4612. * Update ID is observed by sprites and TextureMatrix instances.
  4613. * Call updateUvs() to increment it.
  4614. * @protected
  4615. */
  4616. _updateID: number;
  4617. /**
  4618. * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
  4619. * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)
  4620. */
  4621. _frame: Rectangle;
  4622. /**
  4623. * The WebGL UV data cache. Can be used as quad UV.
  4624. * @protected
  4625. */
  4626. _uvs: TextureUvs;
  4627. /**
  4628. * The ids under which this Texture has been added to the texture cache. This is
  4629. * automatically set as long as Texture.addToCache is used, but may not be set if a
  4630. * Texture is added directly to the TextureCache array.
  4631. */
  4632. textureCacheIds: Array<string>;
  4633. /**
  4634. * @param baseTexture - The base texture source to create the texture from
  4635. * @param frame - The rectangle frame of the texture to show
  4636. * @param orig - The area of original texture
  4637. * @param trim - Trimmed rectangle of original texture
  4638. * @param rotate - indicates how the texture was rotated by texture packer. See {@link PIXI.groupD8}
  4639. * @param anchor - Default anchor point used for sprite placement / rotation
  4640. */
  4641. constructor(baseTexture: BaseTexture<R>, frame?: Rectangle, orig?: Rectangle, trim?: Rectangle, rotate?: number, anchor?: IPointData);
  4642. /**
  4643. * Updates this texture on the gpu.
  4644. *
  4645. * Calls the TextureResource update.
  4646. *
  4647. * If you adjusted `frame` manually, please call `updateUvs()` instead.
  4648. */
  4649. update(): void;
  4650. /**
  4651. * Called when the base texture is updated
  4652. * @protected
  4653. * @param baseTexture - The base texture.
  4654. */
  4655. onBaseTextureUpdated(baseTexture: BaseTexture): void;
  4656. /**
  4657. * Destroys this texture
  4658. * @param [destroyBase=false] - Whether to destroy the base texture as well
  4659. */
  4660. destroy(destroyBase?: boolean): void;
  4661. /**
  4662. * Creates a new texture object that acts the same as this one.
  4663. * @returns - The new texture
  4664. */
  4665. clone(): Texture;
  4666. /**
  4667. * Updates the internal WebGL UV cache. Use it after you change `frame` or `trim` of the texture.
  4668. * Call it after changing the frame
  4669. */
  4670. updateUvs(): void;
  4671. /**
  4672. * Helper function that creates a new Texture based on the source you provide.
  4673. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  4674. * @param {string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|PIXI.BaseTexture} source -
  4675. * Source or array of sources to create texture from
  4676. * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
  4677. * @param {string} [options.pixiIdPrefix=pixiid] - If a source has no id, this is the prefix of the generated id
  4678. * @param {boolean} [strict] - Enforce strict-mode, see {@link PIXI.settings.STRICT_TEXTURE_CACHE}.
  4679. * @returns {PIXI.Texture} The newly created texture
  4680. */
  4681. static from<R extends Resource = Resource, RO = any>(source: TextureSource | TextureSource[], options?: IBaseTextureOptions<RO>, strict?: boolean): Texture<R>;
  4682. /**
  4683. * Useful for loading textures via URLs. Use instead of `Texture.from` because
  4684. * it does a better job of handling failed URLs more effectively. This also ignores
  4685. * `PIXI.settings.STRICT_TEXTURE_CACHE`. Works for Videos, SVGs, Images.
  4686. * @param url - The remote URL or array of URLs to load.
  4687. * @param options - Optional options to include
  4688. * @returns - A Promise that resolves to a Texture.
  4689. */
  4690. static fromURL<R extends Resource = Resource, RO = any>(url: string | string[], options?: IBaseTextureOptions<RO>): Promise<Texture<R>>;
  4691. /**
  4692. * Create a new Texture with a BufferResource from a Float32Array.
  4693. * RGBA values are floats from 0 to 1.
  4694. * @param {Float32Array|Uint8Array} buffer - The optional array to use, if no data
  4695. * is provided, a new Float32Array is created.
  4696. * @param width - Width of the resource
  4697. * @param height - Height of the resource
  4698. * @param options - See {@link PIXI.BaseTexture}'s constructor for options.
  4699. * @returns - The resulting new BaseTexture
  4700. */
  4701. static fromBuffer(buffer: Float32Array | Uint8Array, width: number, height: number, options?: IBaseTextureOptions<ISize>): Texture<BufferResource>;
  4702. /**
  4703. * Create a texture from a source and add to the cache.
  4704. * @param {HTMLImageElement|HTMLCanvasElement|string} source - The input source.
  4705. * @param imageUrl - File name of texture, for cache and resolving resolution.
  4706. * @param name - Human readable name for the texture cache. If no name is
  4707. * specified, only `imageUrl` will be used as the cache ID.
  4708. * @param options
  4709. * @returns - Output texture
  4710. */
  4711. static fromLoader<R extends Resource = Resource>(source: HTMLImageElement | HTMLCanvasElement | string, imageUrl: string, name?: string, options?: IBaseTextureOptions): Promise<Texture<R>>;
  4712. /**
  4713. * Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object.
  4714. * @param texture - The Texture to add to the cache.
  4715. * @param id - The id that the Texture will be stored against.
  4716. */
  4717. static addToCache(texture: Texture, id: string): void;
  4718. /**
  4719. * Remove a Texture from the global TextureCache.
  4720. * @param texture - id of a Texture to be removed, or a Texture instance itself
  4721. * @returns - The Texture that was removed
  4722. */
  4723. static removeFromCache(texture: string | Texture): Texture | null;
  4724. /**
  4725. * Returns resolution of baseTexture
  4726. * @readonly
  4727. */
  4728. get resolution(): number;
  4729. /**
  4730. * The frame specifies the region of the base texture that this texture uses.
  4731. * Please call `updateUvs()` after you change coordinates of `frame` manually.
  4732. */
  4733. get frame(): Rectangle;
  4734. set frame(frame: Rectangle);
  4735. /**
  4736. * Indicates whether the texture is rotated inside the atlas
  4737. * set to 2 to compensate for texture packer rotation
  4738. * set to 6 to compensate for spine packer rotation
  4739. * can be used to rotate or mirror sprites
  4740. * See {@link PIXI.groupD8} for explanation
  4741. */
  4742. get rotate(): number;
  4743. set rotate(rotate: number);
  4744. /** The width of the Texture in pixels. */
  4745. get width(): number;
  4746. /** The height of the Texture in pixels. */
  4747. get height(): number;
  4748. /** Utility function for BaseTexture|Texture cast. */
  4749. castToBaseTexture(): BaseTexture;
  4750. private static _EMPTY;
  4751. private static _WHITE;
  4752. /** An empty texture, used often to not have to create multiple empty textures. Can not be destroyed. */
  4753. static get EMPTY(): Texture<Resource>;
  4754. /** A white texture of 16x16 size, used for graphics and other things Can not be destroyed. */
  4755. static get WHITE(): Texture<CanvasResource>;
  4756. }
  4757. /**
  4758. * System plugin to the renderer to manage texture garbage collection on the GPU,
  4759. * ensuring that it does not get clogged up with textures that are no longer being used.
  4760. * @memberof PIXI
  4761. */
  4762. export declare class TextureGCSystem implements ISystem {
  4763. /**
  4764. * Count
  4765. * @readonly
  4766. */
  4767. count: number;
  4768. /**
  4769. * Check count
  4770. * @readonly
  4771. */
  4772. checkCount: number;
  4773. /**
  4774. * Maximum idle time, in seconds
  4775. * @see PIXI.settings.GC_MAX_IDLE
  4776. */
  4777. maxIdle: number;
  4778. /**
  4779. * Maximum number of item to check
  4780. * @see PIXI.settings.GC_MAX_CHECK_COUNT
  4781. */
  4782. checkCountMax: number;
  4783. /**
  4784. * Current garbage collection mode
  4785. * @see PIXI.settings.GC_MODE
  4786. */
  4787. mode: GC_MODES;
  4788. private renderer;
  4789. /** @param renderer - The renderer this System works for. */
  4790. constructor(renderer: Renderer);
  4791. /**
  4792. * Checks to see when the last time a texture was used
  4793. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  4794. */
  4795. protected postrender(): void;
  4796. /**
  4797. * Checks to see when the last time a texture was used
  4798. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  4799. */
  4800. run(): void;
  4801. /**
  4802. * Removes all the textures within the specified displayObject and its children from the GPU
  4803. * @param {PIXI.DisplayObject} displayObject - the displayObject to remove the textures from.
  4804. */
  4805. unload(displayObject: IUnloadableTexture): void;
  4806. destroy(): void;
  4807. }
  4808. /**
  4809. * Class controls uv mapping from Texture normal space to BaseTexture normal space.
  4810. *
  4811. * Takes `trim` and `rotate` into account. May contain clamp settings for Meshes and TilingSprite.
  4812. *
  4813. * Can be used in Texture `uvMatrix` field, or separately, you can use different clamp settings on the same texture.
  4814. * If you want to add support for texture region of certain feature or filter, that's what you're looking for.
  4815. *
  4816. * Takes track of Texture changes through `_lastTextureID` private field.
  4817. * Use `update()` method call to track it from outside.
  4818. * @see PIXI.Texture
  4819. * @see PIXI.Mesh
  4820. * @see PIXI.TilingSprite
  4821. * @memberof PIXI
  4822. */
  4823. export declare class TextureMatrix {
  4824. /**
  4825. * Matrix operation that converts texture region coords to texture coords
  4826. * @readonly
  4827. */
  4828. mapCoord: Matrix;
  4829. /**
  4830. * Changes frame clamping
  4831. * Works with TilingSprite and Mesh
  4832. * Change to 1.5 if you texture has repeated right and bottom lines, that leads to smoother borders
  4833. * @default 0
  4834. */
  4835. clampOffset: number;
  4836. /**
  4837. * Changes frame clamping
  4838. * Works with TilingSprite and Mesh
  4839. * Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas
  4840. * @default 0.5
  4841. */
  4842. clampMargin: number;
  4843. /**
  4844. * Clamp region for normalized coords, left-top pixel center in xy , bottom-right in zw.
  4845. * Calculated based on clampOffset.
  4846. */
  4847. readonly uClampFrame: Float32Array;
  4848. /** Normalized clamp offset. Calculated based on clampOffset. */
  4849. readonly uClampOffset: Float32Array;
  4850. /**
  4851. * Tracks Texture frame changes.
  4852. * @protected
  4853. */
  4854. _textureID: number;
  4855. /**
  4856. * Tracks Texture frame changes.
  4857. * @protected
  4858. */
  4859. _updateID: number;
  4860. _texture: Texture;
  4861. /**
  4862. * If texture size is the same as baseTexture.
  4863. * @default false
  4864. * @readonly
  4865. */
  4866. isSimple: boolean;
  4867. /**
  4868. * @param texture - observed texture
  4869. * @param clampMargin - Changes frame clamping, 0.5 by default. Use -0.5 for extra border.
  4870. */
  4871. constructor(texture: Texture, clampMargin?: number);
  4872. /** Texture property. */
  4873. get texture(): Texture;
  4874. set texture(value: Texture);
  4875. /**
  4876. * Multiplies uvs array to transform
  4877. * @param uvs - mesh uvs
  4878. * @param [out=uvs] - output
  4879. * @returns - output
  4880. */
  4881. multiplyUvs(uvs: Float32Array, out?: Float32Array): Float32Array;
  4882. /**
  4883. * Updates matrices if texture was changed.
  4884. * @param [forceUpdate=false] - if true, matrices will be updated any case
  4885. * @returns - Whether or not it was updated
  4886. */
  4887. update(forceUpdate?: boolean): boolean;
  4888. }
  4889. export declare type TextureSource = string | BaseTexture | ImageSource;
  4890. /**
  4891. * System plugin to the renderer to manage textures.
  4892. * @memberof PIXI
  4893. */
  4894. export declare class TextureSystem implements ISystem {
  4895. /**
  4896. * Bound textures.
  4897. * @readonly
  4898. */
  4899. boundTextures: BaseTexture[];
  4900. /**
  4901. * List of managed textures.
  4902. * @readonly
  4903. */
  4904. managedTextures: Array<BaseTexture>;
  4905. /** Whether glTexture with int/uint sampler type was uploaded. */
  4906. protected hasIntegerTextures: boolean;
  4907. protected CONTEXT_UID: number;
  4908. protected gl: IRenderingContext;
  4909. protected internalFormats: {
  4910. [type: number]: {
  4911. [format: number]: number;
  4912. };
  4913. };
  4914. protected webGLVersion: number;
  4915. /**
  4916. * BaseTexture value that shows that we don't know what is bound.
  4917. * @readonly
  4918. */
  4919. protected unknownTexture: BaseTexture;
  4920. /**
  4921. * Did someone temper with textures state? We'll overwrite them when we need to unbind something.
  4922. * @private
  4923. */
  4924. protected _unknownBoundTextures: boolean;
  4925. /**
  4926. * Current location.
  4927. * @readonly
  4928. */
  4929. currentLocation: number;
  4930. emptyTextures: {
  4931. [key: number]: GLTexture;
  4932. };
  4933. private renderer;
  4934. /**
  4935. * @param renderer - The renderer this system works for.
  4936. */
  4937. constructor(renderer: Renderer);
  4938. /** Sets up the renderer context and necessary buffers. */
  4939. contextChange(): void;
  4940. /**
  4941. * Bind a texture to a specific location
  4942. *
  4943. * If you want to unbind something, please use `unbind(texture)` instead of `bind(null, textureLocation)`
  4944. * @param texture - Texture to bind
  4945. * @param [location=0] - Location to bind at
  4946. */
  4947. bind(texture: Texture | BaseTexture, location?: number): void;
  4948. /** Resets texture location and bound textures Actual `bind(null, i)` calls will be performed at next `unbind()` call */
  4949. reset(): void;
  4950. /**
  4951. * Unbind a texture.
  4952. * @param texture - Texture to bind
  4953. */
  4954. unbind(texture?: BaseTexture): void;
  4955. /**
  4956. * Ensures that current boundTextures all have FLOAT sampler type,
  4957. * see {@link PIXI.SAMPLER_TYPES} for explanation.
  4958. * @param maxTextures - number of locations to check
  4959. */
  4960. ensureSamplerType(maxTextures: number): void;
  4961. /**
  4962. * Initialize a texture
  4963. * @private
  4964. * @param texture - Texture to initialize
  4965. */
  4966. initTexture(texture: BaseTexture): GLTexture;
  4967. initTextureType(texture: BaseTexture, glTexture: GLTexture): void;
  4968. /**
  4969. * Update a texture
  4970. * @private
  4971. * @param {PIXI.BaseTexture} texture - Texture to initialize
  4972. */
  4973. updateTexture(texture: BaseTexture): void;
  4974. /**
  4975. * Deletes the texture from WebGL
  4976. * @private
  4977. * @param texture - the texture to destroy
  4978. * @param [skipRemove=false] - Whether to skip removing the texture from the TextureManager.
  4979. */
  4980. destroyTexture(texture: BaseTexture | Texture, skipRemove?: boolean): void;
  4981. /**
  4982. * Update texture style such as mipmap flag
  4983. * @private
  4984. * @param {PIXI.BaseTexture} texture - Texture to update
  4985. */
  4986. updateTextureStyle(texture: BaseTexture): void;
  4987. /**
  4988. * Set style for texture
  4989. * @private
  4990. * @param texture - Texture to update
  4991. * @param glTexture
  4992. */
  4993. setStyle(texture: BaseTexture, glTexture: GLTexture): void;
  4994. destroy(): void;
  4995. }
  4996. /**
  4997. * Stores a texture's frame in UV coordinates, in
  4998. * which everything lies in the rectangle `[(0,0), (1,0),
  4999. * (1,1), (0,1)]`.
  5000. *
  5001. * | Corner | Coordinates |
  5002. * |--------------|-------------|
  5003. * | Top-Left | `(x0,y0)` |
  5004. * | Top-Right | `(x1,y1)` |
  5005. * | Bottom-Right | `(x2,y2)` |
  5006. * | Bottom-Left | `(x3,y3)` |
  5007. * @protected
  5008. * @memberof PIXI
  5009. */
  5010. export declare class TextureUvs {
  5011. /** X-component of top-left corner `(x0,y0)`. */
  5012. x0: number;
  5013. /** Y-component of top-left corner `(x0,y0)`. */
  5014. y0: number;
  5015. /** X-component of top-right corner `(x1,y1)`. */
  5016. x1: number;
  5017. /** Y-component of top-right corner `(x1,y1)`. */
  5018. y1: number;
  5019. /** X-component of bottom-right corner `(x2,y2)`. */
  5020. x2: number;
  5021. /** Y-component of bottom-right corner `(x2,y2)`. */
  5022. y2: number;
  5023. /** X-component of bottom-left corner `(x3,y3)`. */
  5024. x3: number;
  5025. /** Y-component of bottom-right corner `(x3,y3)`. */
  5026. y3: number;
  5027. uvsFloat32: Float32Array;
  5028. constructor();
  5029. /**
  5030. * Sets the texture Uvs based on the given frame information.
  5031. * @protected
  5032. * @param frame - The frame of the texture
  5033. * @param baseFrame - The base frame of the texture
  5034. * @param rotate - Rotation of frame, see {@link PIXI.groupD8}
  5035. */
  5036. set(frame: Rectangle, baseFrame: ISize, rotate: number): void;
  5037. toString(): string;
  5038. }
  5039. declare interface UBOElement {
  5040. data: IUniformData;
  5041. offset: number;
  5042. dataLen: number;
  5043. dirty: number;
  5044. }
  5045. /**
  5046. * Uniform group holds uniform map and some ID's for work
  5047. *
  5048. * `UniformGroup` has two modes:
  5049. *
  5050. * 1: Normal mode
  5051. * Normal mode will upload the uniforms with individual function calls as required
  5052. *
  5053. * 2: Uniform buffer mode
  5054. * This mode will treat the uniforms as a uniform buffer. You can pass in either a buffer that you manually handle, or
  5055. * or a generic object that PixiJS will automatically map to a buffer for you.
  5056. * For maximum benefits, make Ubo UniformGroups static, and only update them each frame.
  5057. *
  5058. * Rules of UBOs:
  5059. * - UBOs only work with WebGL2, so make sure you have a fallback!
  5060. * - Only floats are supported (including vec[2,3,4], mat[2,3,4])
  5061. * - Samplers cannot be used in ubo's (a GPU limitation)
  5062. * - You must ensure that the object you pass in exactly matches in the shader ubo structure.
  5063. * Otherwise, weirdness will ensue!
  5064. * - The name of the ubo object added to the group must match exactly the name of the ubo in the shader.
  5065. *
  5066. * ```
  5067. * // ubo in shader:
  5068. * uniform myCoolData { // declaring a ubo..
  5069. * mat4 uCoolMatrix;
  5070. * float uFloatyMcFloatFace
  5071. *
  5072. *
  5073. * // a new uniform buffer object..
  5074. * const myCoolData = new UniformBufferGroup({
  5075. * uCoolMatrix: new Matrix(),
  5076. * uFloatyMcFloatFace: 23,
  5077. * }}
  5078. *
  5079. * // build a shader...
  5080. * const shader = Shader.from(srcVert, srcFrag, {
  5081. * myCoolData // name matches the ubo name in the shader. will be processed accordingly.
  5082. * })
  5083. *
  5084. * ```
  5085. * @memberof PIXI
  5086. */
  5087. export declare class UniformGroup<LAYOUT = Dict<any>> {
  5088. /**
  5089. * Uniform values
  5090. * @member {object}
  5091. */
  5092. readonly uniforms: LAYOUT;
  5093. /**
  5094. * Its a group and not a single uniforms.
  5095. * @default true
  5096. */
  5097. readonly group: boolean;
  5098. /**
  5099. * unique id
  5100. * @protected
  5101. */
  5102. id: number;
  5103. syncUniforms: Dict<UniformsSyncCallback_2>;
  5104. /**
  5105. * Dirty version
  5106. * @protected
  5107. */
  5108. dirtyId: number;
  5109. /** Flag for if uniforms wont be changed after creation. */
  5110. static: boolean;
  5111. /** Flags whether this group is treated like a uniform buffer object. */
  5112. ubo: boolean;
  5113. buffer?: Buffer_2;
  5114. autoManage: boolean;
  5115. /**
  5116. * @param {object | Buffer} [uniforms] - Custom uniforms to use to augment the built-in ones. Or a pixi buffer.
  5117. * @param isStatic - Uniforms wont be changed after creation.
  5118. * @param isUbo - If true, will treat this uniform group as a uniform buffer object.
  5119. */
  5120. constructor(uniforms: LAYOUT | Buffer_2, isStatic?: boolean, isUbo?: boolean);
  5121. update(): void;
  5122. add(name: string, uniforms: Dict<any>, _static?: boolean): void;
  5123. static from(uniforms: Dict<any> | Buffer_2, _static?: boolean, _ubo?: boolean): UniformGroup;
  5124. /**
  5125. * A short hand function for creating a static UBO UniformGroup.
  5126. * @param uniforms - the ubo item
  5127. * @param _static - should this be updated each time it is used? defaults to true here!
  5128. */
  5129. static uboFrom(uniforms: Dict<any> | Buffer_2, _static?: boolean): UniformGroup;
  5130. }
  5131. export declare const uniformParsers: IUniformParser[];
  5132. export declare type UniformsSyncCallback = (...args: any[]) => void;
  5133. declare type UniformsSyncCallback_2 = (...args: any[]) => void;
  5134. /**
  5135. * String of the current PIXI version.
  5136. * @memberof PIXI
  5137. */
  5138. export declare const VERSION = "$_VERSION";
  5139. /**
  5140. * Resource type for {@code HTMLVideoElement}.
  5141. * @memberof PIXI
  5142. */
  5143. export declare class VideoResource extends BaseImageResource {
  5144. /** Override the source to be the video element. */
  5145. source: HTMLVideoElement;
  5146. /**
  5147. * `true` to use PIXI.Ticker.shared to auto update the base texture.
  5148. * @default true
  5149. */
  5150. protected _autoUpdate: boolean;
  5151. /**
  5152. * `true` if the instance is currently connected to PIXI.Ticker.shared to auto update the base texture.
  5153. * @default false
  5154. */
  5155. protected _isConnectedToTicker: boolean;
  5156. protected _updateFPS: number;
  5157. protected _msToNextUpdate: number;
  5158. /**
  5159. * When set to true will automatically play videos used by this texture once
  5160. * they are loaded. If false, it will not modify the playing state.
  5161. * @default true
  5162. */
  5163. protected autoPlay: boolean;
  5164. /**
  5165. * Promise when loading.
  5166. * @default null
  5167. */
  5168. private _load;
  5169. /** Callback when completed with load. */
  5170. private _resolve;
  5171. /**
  5172. * @param {HTMLVideoElement|object|string|Array<string|object>} source - Video element to use.
  5173. * @param {object} [options] - Options to use
  5174. * @param {boolean} [options.autoLoad=true] - Start loading the video immediately
  5175. * @param {boolean} [options.autoPlay=true] - Start playing video immediately
  5176. * @param {number} [options.updateFPS=0] - How many times a second to update the texture from the video.
  5177. * Leave at 0 to update at every render.
  5178. * @param {boolean} [options.crossorigin=true] - Load image using cross origin
  5179. */
  5180. constructor(source?: HTMLVideoElement | Array<string | IVideoResourceOptionsElement> | string, options?: IVideoResourceOptions);
  5181. /**
  5182. * Trigger updating of the texture.
  5183. * @param _deltaTime - time delta since last tick
  5184. */
  5185. update(_deltaTime?: number): void;
  5186. /**
  5187. * Start preloading the video resource.
  5188. * @returns {Promise<void>} Handle the validate event
  5189. */
  5190. load(): Promise<VideoResource>;
  5191. /**
  5192. * Handle video error events.
  5193. * @param event
  5194. */
  5195. private _onError;
  5196. /**
  5197. * Returns true if the underlying source is playing.
  5198. * @returns - True if playing.
  5199. */
  5200. private _isSourcePlaying;
  5201. /**
  5202. * Returns true if the underlying source is ready for playing.
  5203. * @returns - True if ready.
  5204. */
  5205. private _isSourceReady;
  5206. /** Runs the update loop when the video is ready to play. */
  5207. private _onPlayStart;
  5208. /** Fired when a pause event is triggered, stops the update loop. */
  5209. private _onPlayStop;
  5210. /** Fired when the video is loaded and ready to play. */
  5211. private _onCanPlay;
  5212. /** Destroys this texture. */
  5213. dispose(): void;
  5214. /** Should the base texture automatically update itself, set to true by default. */
  5215. get autoUpdate(): boolean;
  5216. set autoUpdate(value: boolean);
  5217. /**
  5218. * How many times a second to update the texture from the video. Leave at 0 to update at every render.
  5219. * A lower fps can help performance, as updating the texture at 60fps on a 30ps video may not be efficient.
  5220. */
  5221. get updateFPS(): number;
  5222. set updateFPS(value: number);
  5223. /**
  5224. * Used to auto-detect the type of resource.
  5225. * @param {*} source - The source object
  5226. * @param {string} extension - The extension of source, if set
  5227. * @returns {boolean} `true` if video source
  5228. */
  5229. static test(source: unknown, extension?: string): source is HTMLVideoElement;
  5230. /**
  5231. * List of common video file extensions supported by VideoResource.
  5232. * @readonly
  5233. */
  5234. static TYPES: Array<string>;
  5235. /**
  5236. * Map of video MIME types that can't be directly derived from file extensions.
  5237. * @readonly
  5238. */
  5239. static MIME_TYPES: Dict<string>;
  5240. }
  5241. /**
  5242. * Flexible wrapper around `ArrayBuffer` that also provides typed array views on demand.
  5243. * @memberof PIXI
  5244. */
  5245. export declare class ViewableBuffer {
  5246. size: number;
  5247. /** Underlying `ArrayBuffer` that holds all the data and is of capacity `this.size`. */
  5248. rawBinaryData: ArrayBuffer;
  5249. /** View on the raw binary data as a `Uint32Array`. */
  5250. uint32View: Uint32Array;
  5251. /** View on the raw binary data as a `Float32Array`. */
  5252. float32View: Float32Array;
  5253. private _int8View;
  5254. private _uint8View;
  5255. private _int16View;
  5256. private _uint16View;
  5257. private _int32View;
  5258. /**
  5259. * @param length - The size of the buffer in bytes.
  5260. */
  5261. constructor(length: number);
  5262. /**
  5263. * @param arrayBuffer - The source array buffer.
  5264. */
  5265. constructor(arrayBuffer: ArrayBuffer);
  5266. /** View on the raw binary data as a `Int8Array`. */
  5267. get int8View(): Int8Array;
  5268. /** View on the raw binary data as a `Uint8Array`. */
  5269. get uint8View(): Uint8Array;
  5270. /** View on the raw binary data as a `Int16Array`. */
  5271. get int16View(): Int16Array;
  5272. /** View on the raw binary data as a `Uint16Array`. */
  5273. get uint16View(): Uint16Array;
  5274. /** View on the raw binary data as a `Int32Array`. */
  5275. get int32View(): Int32Array;
  5276. /**
  5277. * Returns the view of the given type.
  5278. * @param type - One of `int8`, `uint8`, `int16`,
  5279. * `uint16`, `int32`, `uint32`, and `float32`.
  5280. * @returns - typed array of given type
  5281. */
  5282. view(type: string): ITypedArray;
  5283. /** Destroys all buffer references. Do not use after calling this. */
  5284. destroy(): void;
  5285. static sizeOf(type: string): number;
  5286. }
  5287. declare interface WEBGL_compressed_texture_atc {
  5288. COMPRESSED_RGB_ATC_WEBGL: number;
  5289. COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: number;
  5290. COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: number;
  5291. }
  5292. declare interface WEBGL_compressed_texture_etc1_2 {
  5293. COMPRESSED_RGB_ETC1_WEBGL: number;
  5294. }
  5295. declare interface WEBGL_compressed_texture_etc_2 {
  5296. COMPRESSED_R11_EAC: number;
  5297. COMPRESSED_SIGNED_R11_EAC: number;
  5298. COMPRESSED_RG11_EAC: number;
  5299. COMPRESSED_SIGNED_RG11_EAC: number;
  5300. COMPRESSED_RGB8_ETC2: number;
  5301. COMPRESSED_RGBA8_ETC2_EAC: number;
  5302. COMPRESSED_SRGB8_ETC2: number;
  5303. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;
  5304. COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
  5305. COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
  5306. }
  5307. declare interface WEBGL_compressed_texture_pvrtc_2 {
  5308. COMPRESSED_RGB_PVRTC_4BPPV1_IMG: number;
  5309. COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: number;
  5310. COMPRESSED_RGB_PVRTC_2BPPV1_IMG: number;
  5311. COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: number;
  5312. }
  5313. declare interface WebGLExtensions {
  5314. drawBuffers?: WEBGL_draw_buffers;
  5315. depthTexture?: OES_texture_float;
  5316. loseContext?: WEBGL_lose_context;
  5317. vertexArrayObject?: OES_vertex_array_object;
  5318. anisotropicFiltering?: EXT_texture_filter_anisotropic;
  5319. uint32ElementIndex?: OES_element_index_uint;
  5320. floatTexture?: OES_texture_float;
  5321. floatTextureLinear?: OES_texture_float_linear;
  5322. textureHalfFloat?: OES_texture_half_float;
  5323. textureHalfFloatLinear?: OES_texture_half_float_linear;
  5324. colorBufferFloat?: WEBGL_color_buffer_float;
  5325. s3tc?: WEBGL_compressed_texture_s3tc;
  5326. s3tc_sRGB?: WEBGL_compressed_texture_s3tc_srgb;
  5327. etc?: WEBGL_compressed_texture_etc_2;
  5328. etc1?: WEBGL_compressed_texture_etc1_2;
  5329. pvrtc?: WEBGL_compressed_texture_pvrtc_2;
  5330. atc?: WEBGL_compressed_texture_atc;
  5331. astc?: WEBGL_compressed_texture_astc;
  5332. }
  5333. export * from "@pixi/extensions";
  5334. export { }