llvovolume.cpp 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505
  1. /**
  2. * @file llvovolume.cpp
  3. * @brief LLVOVolume class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. // A "volume" is a box, cylinder, sphere, or other primitive shape.
  33. #include "llviewerprecompiledheaders.h"
  34. #include <sstream>
  35. #include "llvovolume.h"
  36. #include "imageids.h"
  37. #include "llanimationstates.h"
  38. #include "llavatarappearancedefines.h"
  39. #include "lldir.h"
  40. #include "hbfastmap.h"
  41. #include "llfasttimer.h"
  42. #include "llmaterialtable.h"
  43. #include "llmatrix4a.h"
  44. #include "llmediaentry.h"
  45. #include "llpluginclassmedia.h" // For code in the mediaEvent handler
  46. #include "llprimitive.h"
  47. #include "llsdutil.h"
  48. #include "llvolume.h"
  49. #include "llvolumemessage.h"
  50. #include "llvolumemgr.h"
  51. #include "llvolumeoctree.h"
  52. #include "llmessage.h"
  53. #include "object_flags.h"
  54. #include "llagent.h"
  55. #include "llappearancemgr.h"
  56. #include "lldrawable.h"
  57. #include "lldrawpoolalpha.h"
  58. #include "lldrawpoolavatar.h"
  59. #include "lldrawpoolbump.h"
  60. #include "llface.h"
  61. #include "llflexibleobject.h"
  62. #include "llfloatertools.h"
  63. #include "llgltfmateriallist.h"
  64. #include "llhudmanager.h"
  65. #include "llmaterialmgr.h"
  66. #include "llmediadataclient.h"
  67. #include "llpipeline.h"
  68. //MK
  69. #include "mkrlinterface.h"
  70. //mk
  71. #include "llselectmgr.h"
  72. #include "llskinningutil.h"
  73. #include "llsky.h"
  74. #include "llspatialpartition.h"
  75. #include "lltexturefetch.h"
  76. #include "llviewercamera.h"
  77. #include "llviewercontrol.h"
  78. #include "llviewerdisplay.h" // For gCubeSnapshot
  79. #include "llviewermediafocus.h"
  80. #include "llviewerobjectlist.h"
  81. #include "llviewerregion.h"
  82. #include "llviewershadermgr.h"
  83. #include "llviewertextureanim.h"
  84. #include "llviewertexturelist.h"
  85. #include "llvoavatarpuppet.h"
  86. #include "llvoavatarself.h"
  87. #include "llvocache.h"
  88. #include "llworld.h"
  89. using namespace LLAvatarAppearanceDefines;
  90. constexpr F32 FORCE_SIMPLE_RENDER_AREA = 512.f;
  91. constexpr F32 FORCE_CULL_AREA = 8.f;
  92. bool LLVOVolume::sAnimateTextures = true;
  93. U32 LLVOVolume::sRenderMaxVBOSize = 4096;
  94. F32 LLVOVolume::sLODFactor = 1.f;
  95. F32 LLVOVolume::sDistanceFactor = 1.f;
  96. S32 LLVOVolume::sNumLODChanges = 0;
  97. LLPointer<LLObjectMediaDataClient> LLVOVolume::sObjectMediaClient = NULL;
  98. LLPointer<LLObjectMediaNavigateClient> LLVOVolume::sObjectMediaNavigateClient = NULL;
  99. uuid_list_t LLVOVolume::sObjectMediaPending;
  100. constexpr U32 MAX_FACE_COUNT = 4096U;
  101. S32 LLVolumeGeometryManager::sInstanceCount = 0;
  102. LLFace** LLVolumeGeometryManager::sFullbrightFaces[2] = { NULL };
  103. LLFace** LLVolumeGeometryManager::sBumpFaces[2] = { NULL };
  104. LLFace** LLVolumeGeometryManager::sSimpleFaces[2] = { NULL };
  105. LLFace** LLVolumeGeometryManager::sNormFaces[2] = { NULL };
  106. LLFace** LLVolumeGeometryManager::sSpecFaces[2] = { NULL };
  107. LLFace** LLVolumeGeometryManager::sNormSpecFaces[2] = { NULL };
  108. LLFace** LLVolumeGeometryManager::sPbrFaces[2] = { NULL };
  109. LLFace** LLVolumeGeometryManager::sAlphaFaces[2] = { NULL };
  110. // Implementation class of LLMediaDataClientObject. See llmediadataclient.h
  111. class LLMediaDataClientObjectImpl final : public LLMediaDataClientObject
  112. {
  113. public:
  114. LLMediaDataClientObjectImpl(LLVOVolume* obj, bool is_new)
  115. : mObject(obj),
  116. mNew(is_new)
  117. {
  118. mObject->addMDCImpl();
  119. }
  120. ~LLMediaDataClientObjectImpl() override
  121. {
  122. mObject->removeMDCImpl();
  123. }
  124. LL_INLINE U8 getMediaDataCount() const override
  125. {
  126. return mObject->getNumTEs();
  127. }
  128. LLSD getMediaDataLLSD(U8 index) const override
  129. {
  130. LLSD result;
  131. LLTextureEntry* tep = mObject->getTE(index);
  132. if (tep)
  133. {
  134. llassert((tep->getMediaData() != NULL) == tep->hasMedia());
  135. if (tep->getMediaData())
  136. {
  137. result = tep->getMediaData()->asLLSD();
  138. // *HACK: workaround bug in asLLSD() where whitelist is not set
  139. // properly. See DEV-41949
  140. if (!result.has(LLMediaEntry::WHITELIST_KEY))
  141. {
  142. result[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
  143. }
  144. }
  145. }
  146. return result;
  147. }
  148. bool isCurrentMediaUrl(U8 index, const std::string& url) const override
  149. {
  150. LLTextureEntry* tep = mObject->getTE(index);
  151. if (tep && tep->getMediaData())
  152. {
  153. return tep->getMediaData()->getCurrentURL() == url;
  154. }
  155. return url.empty();
  156. }
  157. LL_INLINE LLUUID getID() const override { return mObject->getID(); }
  158. LL_INLINE void mediaNavigateBounceBack(U8 index) override
  159. {
  160. mObject->mediaNavigateBounceBack(index);
  161. }
  162. LL_INLINE bool hasMedia() const override
  163. {
  164. return mObject->hasMedia();
  165. }
  166. LL_INLINE void updateObjectMediaData(LLSD const& data,
  167. const std::string& ver) override
  168. {
  169. mObject->updateObjectMediaData(data, ver);
  170. }
  171. F64 getMediaInterest() const override
  172. {
  173. F64 interest = mObject->getTotalMediaInterest();
  174. if (interest < 0.0)
  175. {
  176. // media interest not valid yet, try pixel area
  177. interest = mObject->getPixelArea();
  178. // *HACK: force recalculation of pixel area if interest is the
  179. // "magic default" of 1024.
  180. if (interest == 1024.0)
  181. {
  182. const_cast<LLVOVolume*>((LLVOVolume*)mObject)->setPixelAreaAndAngle();
  183. interest = mObject->getPixelArea();
  184. }
  185. }
  186. return interest;
  187. }
  188. LL_INLINE bool isInterestingEnough() const override
  189. {
  190. return LLViewerMedia::isInterestingEnough(mObject, getMediaInterest());
  191. }
  192. LL_INLINE const std::string& getCapabilityUrl(const char* name) const override
  193. {
  194. return mObject->getRegion()->getCapability(name);
  195. }
  196. LL_INLINE bool isDead() const override { return mObject->isDead(); }
  197. LL_INLINE U32 getMediaVersion() const override
  198. {
  199. return LLTextureEntry::getVersionFromMediaVersionString(mObject->getMediaURL());
  200. }
  201. LL_INLINE bool isNew() const override { return mNew; }
  202. private:
  203. LLPointer<LLVOVolume> mObject;
  204. bool mNew;
  205. };
  206. ///////////////////////////////////////////////////////////////////////////////
  207. // LLVOVolume class
  208. ///////////////////////////////////////////////////////////////////////////////
  209. LLVOVolume::LLVOVolume(const LLUUID& id, LLViewerRegion* regionp)
  210. : LLViewerObject(id, LL_PCODE_VOLUME, regionp),
  211. mVolumeImpl(NULL),
  212. mTextureAnimp(NULL),
  213. mTexAnimMode(0),
  214. mVObjRadius(LLVector3(1.f, 1.f, 0.5f).length()),
  215. mLastDistance(0.f),
  216. mLOD(0),
  217. mLockMaxLOD(false),
  218. mLODChanged(false),
  219. mVolumeChanged(false),
  220. mSculptChanged(false),
  221. mInMeshCache(false),
  222. mInSkinCache(false),
  223. mSkinInfoFailed(false),
  224. mColorChanged(false),
  225. mFaceMappingChanged(false),
  226. mServerDrawableUpdateCount(0),
  227. mLastServerDrawableUpdate(0.f),
  228. mSpotLightPriority(0.f),
  229. mLastFetchedMediaVersion(-1),
  230. mMDCImplCount(0),
  231. mLastRiggingInfoLOD(-1)
  232. {
  233. mRelativeXform.setIdentity();
  234. mRelativeXformInvTrans.setIdentity();
  235. mNumFaces = 0;
  236. mMediaImplList.resize(getNumTEs());
  237. memset(&mIndexInTex, 0,
  238. sizeof(S32) * LLRender::NUM_VOLUME_TEXTURE_CHANNELS);
  239. }
  240. LLVOVolume::~LLVOVolume()
  241. {
  242. if (mTextureAnimp)
  243. {
  244. delete mTextureAnimp;
  245. mTextureAnimp = NULL;
  246. }
  247. if (mVolumeImpl)
  248. {
  249. delete mVolumeImpl;
  250. mVolumeImpl = NULL;
  251. }
  252. if (!mMediaImplList.empty())
  253. {
  254. for (U32 i = 0, count = mMediaImplList.size(); i < count; ++i)
  255. {
  256. if (mMediaImplList[i].notNull())
  257. {
  258. mMediaImplList[i]->removeObject(this);
  259. }
  260. }
  261. }
  262. mCostData = NULL;
  263. }
  264. void LLVOVolume::markDead()
  265. {
  266. if (mDead)
  267. {
  268. return;
  269. }
  270. // Only call unregisterVolume() when 'this' actually got registered in the
  271. // mesh repository, else do not loose our time ! HB
  272. if (mInMeshCache || mInSkinCache)
  273. {
  274. gMeshRepo.unregisterVolume(this, mInMeshCache, mInSkinCache);
  275. }
  276. sObjectMediaPending.erase(mID);
  277. if (mMDCImplCount > 0 &&
  278. (sObjectMediaClient || sObjectMediaNavigateClient))
  279. {
  280. LLMediaDataClientObject::ptr_t obj =
  281. new LLMediaDataClientObjectImpl(const_cast<LLVOVolume*>(this),
  282. false);
  283. if (sObjectMediaClient)
  284. {
  285. sObjectMediaClient->removeFromQueue(obj);
  286. }
  287. if (sObjectMediaNavigateClient)
  288. {
  289. sObjectMediaNavigateClient->removeFromQueue(obj);
  290. }
  291. }
  292. // Detach all media impls from this object
  293. for (U32 i = 0, count = mMediaImplList.size(); i < count; ++i)
  294. {
  295. removeMediaImpl(i);
  296. }
  297. if (mSculptTexture.notNull())
  298. {
  299. mSculptTexture->removeVolume(LLRender::SCULPT_TEX, this);
  300. }
  301. if (mLightTexture.notNull())
  302. {
  303. mLightTexture->removeVolume(LLRender::LIGHT_TEX, this);
  304. }
  305. // Unregister unconditionally, in case mIsHeroProbe is corrupted. HB
  306. gPipeline.mHeroProbeManager.unregisterViewerObject(this);
  307. LLViewerObject::markDead();
  308. }
  309. //static
  310. void LLVOVolume::initClass()
  311. {
  312. updateSettings();
  313. initSharedMedia();
  314. }
  315. //static
  316. void LLVOVolume::updateSettings()
  317. {
  318. sRenderMaxVBOSize = llmin(gSavedSettings.getU32("RenderMaxVBOSize"), 32U);
  319. sLODFactor = llclamp(gSavedSettings.getF32("RenderVolumeLODFactor"), 0.1f,
  320. 9.f);
  321. sDistanceFactor = 1.f - 0.1f * sLODFactor;
  322. }
  323. //static
  324. void LLVOVolume::initSharedMedia()
  325. {
  326. // gSavedSettings better be around
  327. if (!gSavedSettings.getBool("EnableStreamingMedia") ||
  328. !gSavedSettings.getBool("PrimMediaMasterEnabled"))
  329. {
  330. // Make sure all shared media are unloaded
  331. LLViewerMedia::setAllMediaEnabled(false, false);
  332. // Make sure the media clients will not be called uselessly
  333. sObjectMediaClient = NULL;
  334. sObjectMediaNavigateClient = NULL;
  335. return;
  336. }
  337. F32 queue_delay = gSavedSettings.getF32("PrimMediaRequestQueueDelay");
  338. F32 retry_delay = gSavedSettings.getF32("PrimMediaRetryTimerDelay");
  339. U32 max_retries = gSavedSettings.getU32("PrimMediaMaxRetries");
  340. U32 sorted_size = gSavedSettings.getU32("PrimMediaMaxSortedQueueSize");
  341. U32 rr_size = gSavedSettings.getU32("PrimMediaMaxRoundRobinQueueSize");
  342. sObjectMediaClient = new LLObjectMediaDataClient(queue_delay, retry_delay,
  343. max_retries, sorted_size,
  344. rr_size);
  345. sObjectMediaNavigateClient =
  346. new LLObjectMediaNavigateClient(queue_delay, retry_delay, max_retries,
  347. sorted_size, rr_size);
  348. if (sObjectMediaPending.empty())
  349. {
  350. return;
  351. }
  352. // Fetch any media that got queued while media support was off. HB
  353. for (uuid_list_t::iterator it = sObjectMediaPending.begin(),
  354. end = sObjectMediaPending.end();
  355. it != end; ++it)
  356. {
  357. LLViewerObject* objectp = gObjectList.findObject(*it);
  358. if (objectp && !objectp->isDead())
  359. {
  360. LLVOVolume* volp = objectp->asVolume();
  361. if (volp)
  362. {
  363. volp->requestMediaDataUpdate(true);
  364. }
  365. }
  366. }
  367. sObjectMediaPending.clear();
  368. }
  369. //static
  370. void LLVOVolume::cleanupClass()
  371. {
  372. sObjectMediaClient = NULL;
  373. sObjectMediaNavigateClient = NULL;
  374. llinfos << "Number of LOD cache hits: " << LLVolume::sLODCacheHit
  375. << " - Cache misses: " << LLVolume::sLODCacheMiss << llendl;
  376. }
  377. U32 LLVOVolume::processUpdateMessage(LLMessageSystem* mesgsys,
  378. void** user_data, U32 block_num,
  379. EObjectUpdateType update_type,
  380. LLDataPacker* dp)
  381. {
  382. static LLCachedControl<bool> kill_bogus_objects(gSavedSettings,
  383. "KillBogusObjects");
  384. bool old_volume_changed = mVolumeChanged;
  385. bool old_mapping_changed = mFaceMappingChanged;
  386. bool old_color_changed = mColorChanged;
  387. // Do base class updates...
  388. U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data,
  389. block_num, update_type,
  390. dp);
  391. LLUUID sculpt_id;
  392. U8 sculpt_type = 0;
  393. if (isSculpted())
  394. {
  395. const LLSculptParams* sculpt_params = getSculptParams();
  396. if (sculpt_params)
  397. {
  398. sculpt_id = sculpt_params->getSculptTexture();
  399. sculpt_type = sculpt_params->getSculptType();
  400. }
  401. }
  402. if (!dp)
  403. {
  404. if (update_type == OUT_FULL)
  405. {
  406. ////////////////////////////////
  407. // Unpack texture animation data
  408. if (mesgsys->getSizeFast(_PREHASH_ObjectData, block_num,
  409. _PREHASH_TextureAnim))
  410. {
  411. if (!mTextureAnimp)
  412. {
  413. mTextureAnimp = new LLViewerTextureAnim(this);
  414. }
  415. else if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
  416. {
  417. mTextureAnimp->reset();
  418. }
  419. mTexAnimMode = 0;
  420. mTextureAnimp->unpackTAMessage(mesgsys, block_num);
  421. }
  422. else if (mTextureAnimp)
  423. {
  424. delete mTextureAnimp;
  425. mTextureAnimp = NULL;
  426. for (S32 i = 0, count = getNumTEs(); i < count; ++i)
  427. {
  428. LLFace* facep = mDrawable->getFace(i);
  429. if (facep && facep->mTextureMatrix)
  430. {
  431. delete facep->mTextureMatrix;
  432. facep->mTextureMatrix = NULL;
  433. }
  434. }
  435. gPipeline.markTextured(mDrawable);
  436. mFaceMappingChanged = true;
  437. mTexAnimMode = 0;
  438. }
  439. // Unpack volume data
  440. LLVolumeParams volume_params;
  441. bool success =
  442. LLVolumeMessage::unpackVolumeParams(&volume_params, mesgsys,
  443. _PREHASH_ObjectData,
  444. block_num);
  445. if (!success)
  446. {
  447. llwarns_once << "Bogus volume parameters in object " << getID()
  448. << " at " << getPositionRegion() << " owned by "
  449. << mOwnerID << llendl;
  450. if (mRegionp)
  451. {
  452. // Do not cache this bogus object
  453. mRegionp->addCacheMissFull(getLocalID());
  454. }
  455. if (kill_bogus_objects)
  456. {
  457. gObjectList.mBlackListedObjects.emplace(getID());
  458. gObjectList.killObject(this);
  459. return INVALID_UPDATE;
  460. }
  461. }
  462. volume_params.setSculptID(sculpt_id, sculpt_type);
  463. if (setVolume(volume_params, 0))
  464. {
  465. markForUpdate();
  466. }
  467. }
  468. // Sigh, this needs to be done AFTER the volume is set as well,
  469. // otherwise bad stuff happens...
  470. ////////////////////////////
  471. // Unpack texture entry data
  472. S32 result = unpackTEMessage(mesgsys, _PREHASH_ObjectData,
  473. (S32)block_num);
  474. if (result == TEM_INVALID)
  475. {
  476. llwarns_once << "Bogus TE data in object " << getID() << " at "
  477. << getPositionRegion() << " owned by " << mOwnerID
  478. << llendl;
  479. if (mRegionp)
  480. {
  481. // Do not cache this bogus object
  482. mRegionp->addCacheMissFull(getLocalID());
  483. }
  484. if (kill_bogus_objects)
  485. {
  486. gObjectList.mBlackListedObjects.emplace(getID());
  487. gObjectList.killObject(this);
  488. return INVALID_UPDATE;
  489. }
  490. }
  491. if (result & TEM_CHANGE_MEDIA)
  492. {
  493. retval |= MEDIA_FLAGS_CHANGED;
  494. }
  495. }
  496. else if (update_type != OUT_TERSE_IMPROVED)
  497. {
  498. LLVolumeParams volume_params;
  499. bool success = LLVolumeMessage::unpackVolumeParams(&volume_params,
  500. *dp);
  501. if (!success)
  502. {
  503. llwarns_once << "Bogus volume parameters in object " << getID()
  504. << " at " << getPositionRegion() << " owned by "
  505. << mOwnerID << llendl;
  506. if (mRegionp)
  507. {
  508. // Do not cache this bogus object
  509. mRegionp->addCacheMissFull(getLocalID());
  510. }
  511. if (kill_bogus_objects)
  512. {
  513. gObjectList.mBlackListedObjects.emplace(getID());
  514. gObjectList.killObject(this);
  515. return INVALID_UPDATE;
  516. }
  517. }
  518. volume_params.setSculptID(sculpt_id, sculpt_type);
  519. if (setVolume(volume_params, 0))
  520. {
  521. markForUpdate();
  522. }
  523. S32 result = unpackTEMessage(*dp);
  524. if (result == TEM_INVALID)
  525. {
  526. llwarns_once << "Bogus TE data in object " << getID() << " at "
  527. << getPositionRegion() << " owned by " << mOwnerID
  528. << llendl;
  529. if (mRegionp)
  530. {
  531. // Do not cache this bogus object
  532. mRegionp->addCacheMissFull(getLocalID());
  533. }
  534. if (kill_bogus_objects)
  535. {
  536. gObjectList.mBlackListedObjects.emplace(getID());
  537. gObjectList.killObject(this);
  538. return INVALID_UPDATE;
  539. }
  540. }
  541. else if (result & TEM_CHANGE_MEDIA)
  542. {
  543. retval |= MEDIA_FLAGS_CHANGED;
  544. }
  545. U32 value = dp->getPassFlags();
  546. if (value & 0x40)
  547. {
  548. if (!mTextureAnimp)
  549. {
  550. mTextureAnimp = new LLViewerTextureAnim(this);
  551. }
  552. else if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
  553. {
  554. mTextureAnimp->reset();
  555. }
  556. mTexAnimMode = 0;
  557. mTextureAnimp->unpackTAMessage(*dp);
  558. }
  559. else if (mTextureAnimp)
  560. {
  561. delete mTextureAnimp;
  562. mTextureAnimp = NULL;
  563. for (S32 i = 0, count = getNumTEs(); i < count; ++i)
  564. {
  565. LLFace* facep = mDrawable->getFace(i);
  566. if (facep && facep->mTextureMatrix)
  567. {
  568. delete facep->mTextureMatrix;
  569. facep->mTextureMatrix = NULL;
  570. }
  571. }
  572. gPipeline.markTextured(mDrawable);
  573. mFaceMappingChanged = true;
  574. mTexAnimMode = 0;
  575. }
  576. if (value & 0x400)
  577. {
  578. // Particle system (new)
  579. unpackParticleSource(*dp, mOwnerID, false);
  580. }
  581. }
  582. else
  583. {
  584. S32 texture_length = mesgsys->getSizeFast(_PREHASH_ObjectData,
  585. block_num,
  586. _PREHASH_TextureEntry);
  587. if (texture_length)
  588. {
  589. U8 tdpbuffer[1024];
  590. LLDataPackerBinaryBuffer tdp(tdpbuffer, 1024);
  591. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  592. _PREHASH_TextureEntry,
  593. tdpbuffer, 0, block_num, 1024);
  594. S32 result = unpackTEMessage(tdp);
  595. if (result & TEM_CHANGE_MEDIA)
  596. {
  597. retval |= MEDIA_FLAGS_CHANGED;
  598. }
  599. // On the fly TE updates break batches: isolate in octree.
  600. if (result &
  601. (TEM_CHANGE_TEXTURE | TEM_CHANGE_COLOR | TEM_CHANGE_MEDIA))
  602. {
  603. shrinkWrap();
  604. }
  605. }
  606. }
  607. if (retval & (MEDIA_URL_REMOVED | MEDIA_URL_ADDED | MEDIA_URL_UPDATED |
  608. MEDIA_FLAGS_CHANGED))
  609. {
  610. // If only the media URL changed, and it is not a media version URL,
  611. // ignore it
  612. if (!((retval & (MEDIA_URL_ADDED | MEDIA_URL_UPDATED)) &&
  613. mMedia && !mMedia->mMediaURL.empty() &&
  614. !LLTextureEntry::isMediaVersionString(mMedia->mMediaURL)))
  615. {
  616. // If the media changed at all, request new media data
  617. LL_DEBUGS("MediaOnAPrim") << "Media update: " << getID()
  618. << ": retval=" << retval << " Media URL: "
  619. << (mMedia ? mMedia->mMediaURL : std::string(""))
  620. << LL_ENDL;
  621. requestMediaDataUpdate(retval & MEDIA_FLAGS_CHANGED);
  622. }
  623. else
  624. {
  625. llinfos << "Ignoring media update for: " << getID()
  626. << " Media URL: "
  627. << (mMedia ? mMedia->mMediaURL : std::string(""))
  628. << llendl;
  629. }
  630. }
  631. // ... and clean up any media impls
  632. cleanUpMediaImpls();
  633. if (!mLODChanged &&
  634. ((!old_volume_changed && mVolumeChanged) ||
  635. (!old_mapping_changed && mFaceMappingChanged) ||
  636. (!old_color_changed && mColorChanged)))
  637. {
  638. onDrawableUpdateFromServer();
  639. }
  640. return retval;
  641. }
  642. void LLVOVolume::onDrawableUpdateFromServer()
  643. {
  644. constexpr U32 UPDATES_UNTIL_ACTIVE = 8;
  645. constexpr F32 UPDATES_COUNT_TIMEOUT = 60.f;
  646. if (mDrawable.isNull() || mDrawable->isActive())
  647. {
  648. return; // Nothing to do
  649. }
  650. if (gFrameTimeSeconds > mLastServerDrawableUpdate + UPDATES_COUNT_TIMEOUT)
  651. {
  652. // Reset the count to 1 since there has not been an update in a
  653. // while. HB
  654. mServerDrawableUpdateCount = 1;
  655. }
  656. else if (++mServerDrawableUpdateCount > UPDATES_UNTIL_ACTIVE)
  657. {
  658. LL_DEBUGS("DrawableUpdates") << "Making " << getID() << " active."
  659. << LL_ENDL;
  660. mDrawable->makeActive();
  661. }
  662. mLastServerDrawableUpdate = gFrameTimeSeconds;
  663. }
  664. void LLVOVolume::animateTextures()
  665. {
  666. if (mDead || !mTextureAnimp) return;
  667. // Animated texture break batches: isolate in octree.
  668. shrinkWrap();
  669. F32 off_s = 0.f, off_t = 0.f, scale_s = 1.f, scale_t = 1.f, rot = 0.f;
  670. S32 result = mTextureAnimp->animateTextures(off_s, off_t, scale_s, scale_t,
  671. rot);
  672. if (result)
  673. {
  674. if (!mTexAnimMode)
  675. {
  676. mFaceMappingChanged = true;
  677. gPipeline.markTextured(mDrawable);
  678. }
  679. mTexAnimMode = result | mTextureAnimp->mMode;
  680. S32 start = 0, end = mDrawable->getNumFaces() - 1;
  681. if (mTextureAnimp->mFace >= 0 && mTextureAnimp->mFace <= end)
  682. {
  683. start = end = mTextureAnimp->mFace;
  684. }
  685. LLVector3 trans, scale;
  686. LLMatrix4a scale_mat, tex_mat;
  687. static const LLVector3 translation(-0.5f, -0.5f, 0.f);
  688. for (S32 i = start; i <= end; ++i)
  689. {
  690. LLFace* facep = mDrawable->getFace(i);
  691. if (!facep ||
  692. (facep->getVirtualSize() < MIN_TEX_ANIM_SIZE &&
  693. facep->mTextureMatrix))
  694. {
  695. continue;
  696. }
  697. const LLTextureEntry* tep = facep->getTextureEntry();
  698. if (!tep)
  699. {
  700. continue;
  701. }
  702. if (!facep->mTextureMatrix)
  703. {
  704. facep->mTextureMatrix = new LLMatrix4();
  705. }
  706. if (!(result & LLViewerTextureAnim::ROTATE))
  707. {
  708. tep->getRotation(&rot);
  709. }
  710. if (!(result & LLViewerTextureAnim::TRANSLATE))
  711. {
  712. tep->getOffset(&off_s, &off_t);
  713. }
  714. trans.set(LLVector3(off_s + 0.5f, off_t + 0.5f, 0.f));
  715. if (!(result & LLViewerTextureAnim::SCALE))
  716. {
  717. tep->getScale(&scale_s, &scale_t);
  718. }
  719. scale.set(scale_s, scale_t, 1.f);
  720. tex_mat.setIdentity();
  721. tex_mat.translateAffine(translation);
  722. static const LLVector4a z_neg_axis(0.f, 0.f, -1.f);
  723. tex_mat.setMul(gl_gen_rot(rot * RAD_TO_DEG, z_neg_axis), tex_mat);
  724. scale_mat.setIdentity();
  725. scale_mat.applyScaleAffine(scale);
  726. tex_mat.setMul(scale_mat, tex_mat); // Left mul
  727. tex_mat.translateAffine(trans);
  728. facep->mTextureMatrix->set(tex_mat.getF32ptr());
  729. }
  730. }
  731. else if (mTexAnimMode && mTextureAnimp->mRate == 0)
  732. {
  733. U8 start, count;
  734. if (mTextureAnimp->mFace == -1)
  735. {
  736. start = 0;
  737. count = getNumTEs();
  738. }
  739. else
  740. {
  741. start = (U8)mTextureAnimp->mFace;
  742. count = 1;
  743. }
  744. for (S32 i = start; i < start + count; ++i)
  745. {
  746. if (mTexAnimMode & LLViewerTextureAnim::TRANSLATE)
  747. {
  748. setTEOffset(i, mTextureAnimp->mOffS, mTextureAnimp->mOffT);
  749. }
  750. if (mTexAnimMode & LLViewerTextureAnim::SCALE)
  751. {
  752. setTEScale(i, mTextureAnimp->mScaleS, mTextureAnimp->mScaleT);
  753. }
  754. if (mTexAnimMode & LLViewerTextureAnim::ROTATE)
  755. {
  756. setTERotation(i, mTextureAnimp->mRot);
  757. }
  758. }
  759. gPipeline.markTextured(mDrawable);
  760. mFaceMappingChanged = true;
  761. mTexAnimMode = 0;
  762. }
  763. }
  764. void LLVOVolume::updateTextures()
  765. {
  766. constexpr F32 TEXTURE_AREA_REFRESH_TIME = 5.f; // seconds
  767. if (mTextureUpdateTimer.getElapsedTimeF32() < TEXTURE_AREA_REFRESH_TIME)
  768. {
  769. return;
  770. }
  771. updateTextureVirtualSize();
  772. static LLCachedControl<bool> destroy(gSavedSettings,
  773. "DestroyUnseenVolumeVB");
  774. if (!destroy || mDrawable.isNull() || isVisible() || mDrawable->isActive())
  775. {
  776. return;
  777. }
  778. // Delete vertex buffer to free up some VRAM
  779. LLSpatialGroup* groupp = mDrawable->getSpatialGroup();
  780. if (groupp &&
  781. (groupp->mVertexBuffer.notNull() || !groupp->mBufferMap.empty() ||
  782. !groupp->mDrawMap.empty()))
  783. {
  784. groupp->destroyGL(true);
  785. // Flag the group as having changed geometry so it gets a rebuild next
  786. // time it becomes visible
  787. groupp->setState(LLSpatialGroup::GEOM_DIRTY |
  788. LLSpatialGroup::MESH_DIRTY |
  789. LLSpatialGroup::NEW_DRAWINFO);
  790. }
  791. }
  792. bool LLVOVolume::isVisible() const
  793. {
  794. if (mDrawable.notNull() && mDrawable->isVisible())
  795. {
  796. return true;
  797. }
  798. #if 0
  799. if (isHUDAttachment())
  800. {
  801. return true;
  802. }
  803. #endif
  804. if (isAttachment())
  805. {
  806. LLViewerObject* objp = (LLViewerObject*)getParent();
  807. while (objp && !objp->isAvatar())
  808. {
  809. objp = (LLViewerObject*)objp->getParent();
  810. }
  811. return objp && objp->mDrawable.notNull() &&
  812. objp->mDrawable->isVisible();
  813. }
  814. return false;
  815. }
  816. // Updates the pixel area of all faces
  817. void LLVOVolume::updateTextureVirtualSize(bool forced)
  818. {
  819. if (mDrawable.isNull() || gCubeSnapshot)
  820. {
  821. return;
  822. }
  823. if (!forced)
  824. {
  825. if (!isVisible())
  826. {
  827. // Do not load textures for non-visible faces
  828. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  829. {
  830. LLFace* face = mDrawable->getFace(i);
  831. if (face)
  832. {
  833. face->setPixelArea(0.f);
  834. face->setVirtualSize(0.f);
  835. }
  836. }
  837. return;
  838. }
  839. if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SIMPLE))
  840. {
  841. return;
  842. }
  843. }
  844. if (LLViewerTexture::sDontLoadVolumeTextures ||
  845. gTextureFetchp->mDebugPause)
  846. {
  847. return;
  848. }
  849. mTextureUpdateTimer.reset();
  850. F32 old_area = mPixelArea;
  851. mPixelArea = 0.f;
  852. const S32 num_faces = mDrawable->getNumFaces();
  853. F32 min_vsize = 999999999.f, max_vsize = 0.f;
  854. bool is_ours = permYouOwner();
  855. bool is_hud = isHUDAttachment();
  856. bool debug_tex_area =
  857. gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA);
  858. bool debug_tex_prio =
  859. gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY);
  860. bool debug_face_alpha =
  861. gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_FACE_AREA);
  862. for (S32 i = 0; i < num_faces; ++i)
  863. {
  864. LLFace* face = mDrawable->getFace(i);
  865. if (!face) continue;
  866. const LLTextureEntry* tep = face->getTextureEntry();
  867. LLViewerTexture* imagep = face->getTexture();
  868. if (!imagep || !tep || face->mExtents[0].equals3(face->mExtents[1]))
  869. {
  870. continue;
  871. }
  872. F32 vsize;
  873. F32 old_size = face->getVirtualSize();
  874. if (is_hud)
  875. {
  876. // Rez our attachments faster and at full details !
  877. imagep->setBoostLevel(LLGLTexture::BOOST_HUD);
  878. // ... and do not discard our attachments textures
  879. imagep->dontDiscard();
  880. // Treat as full screen
  881. vsize = (F32)gViewerCamera.getScreenPixelArea();
  882. face->setPixelArea(vsize);
  883. }
  884. else
  885. {
  886. vsize = face->getTextureVirtualSize();
  887. // Rez our attachments faster and at full details !
  888. if (is_ours && isAttachment())
  889. {
  890. imagep->setBoostLevel(LLGLTexture::BOOST_HUD);
  891. // ... and do not discard our attachments textures
  892. imagep->dontDiscard();
  893. }
  894. }
  895. mPixelArea = llmax(mPixelArea, face->getPixelArea());
  896. if (face->mTextureMatrix)
  897. {
  898. // Animating textures also rez badly in Snowglobe because the
  899. // actual displayed area is only a fraction (corresponding to one
  900. // frame) of the animating texture. Let's fix that here. HB
  901. if (mTextureAnimp && mTextureAnimp->mScaleS > 0.f &&
  902. mTextureAnimp->mScaleT > 0.f)
  903. {
  904. // Adjust to take into account the actual frame size which is
  905. // only a portion of the animating texture.
  906. vsize /= mTextureAnimp->mScaleS / mTextureAnimp->mScaleT;
  907. }
  908. // If the face has gotten small enough to turn off texture
  909. // animation and texture animation is running, rebuild the render
  910. // batch for this face to turn off texture animation.
  911. if ((vsize < MIN_TEX_ANIM_SIZE && old_size >= MIN_TEX_ANIM_SIZE) ||
  912. (vsize >= MIN_TEX_ANIM_SIZE && old_size < MIN_TEX_ANIM_SIZE))
  913. {
  914. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  915. }
  916. }
  917. face->setVirtualSize(vsize);
  918. if (!is_hud)
  919. {
  920. imagep->addTextureStats(vsize);
  921. }
  922. if (debug_tex_area)
  923. {
  924. if (vsize < min_vsize)
  925. {
  926. min_vsize = vsize;
  927. }
  928. if (vsize > max_vsize)
  929. {
  930. max_vsize = vsize;
  931. }
  932. }
  933. else if (debug_tex_prio)
  934. {
  935. LLViewerFetchedTexture* texp =
  936. LLViewerTextureManager::staticCast(imagep);
  937. if (texp)
  938. {
  939. F32 pri = texp->getDecodePriority();
  940. pri = llmax(pri, 0.f);
  941. if (pri < min_vsize)
  942. {
  943. min_vsize = pri;
  944. }
  945. if (pri > max_vsize)
  946. {
  947. max_vsize = pri;
  948. }
  949. }
  950. }
  951. else if (debug_face_alpha)
  952. {
  953. F32 pri = mPixelArea;
  954. if (pri < min_vsize)
  955. {
  956. min_vsize = pri;
  957. }
  958. if (pri > max_vsize)
  959. {
  960. max_vsize = pri;
  961. }
  962. }
  963. }
  964. if (isSculpted())
  965. {
  966. // Note: sets mSculptTexture to NULL if this is a mesh object:
  967. updateSculptTexture();
  968. if (mSculptTexture.notNull())
  969. {
  970. mSculptTexture->setForSculpt();
  971. if (!mSculptTexture->isCachedRawImageReady())
  972. {
  973. S32 lod = llmin(mLOD, 3);
  974. F32 lodf = (F32)(lod + 1) * 0.25f;
  975. F32 tex_size = lodf * MAX_SCULPT_REZ;
  976. mSculptTexture->addTextureStats(2.f * tex_size * tex_size, false);
  977. // If the sculpty very close to the view point, load first
  978. LLVector3 look_at = getPositionAgent() -
  979. gViewerCamera.getOrigin();
  980. F32 dist = look_at.normalize();
  981. F32 cos_to_view_dir = look_at * gViewerCamera.getXAxis();
  982. F32 prio = 0.8f *
  983. LLFace::calcImportanceToCamera(cos_to_view_dir,
  984. dist);
  985. mSculptTexture->setAdditionalDecodePriority(prio);
  986. }
  987. // Try to match the texture:
  988. S32 texture_discard = mSculptTexture->getCachedRawImageLevel();
  989. S32 current_discard = getVolume() ? getVolume()->getSculptLevel()
  990. : -2;
  991. if (texture_discard >= 0 && // Texture has some data available
  992. // Texture has more data than last rebuild
  993. (texture_discard < current_discard ||
  994. // No previous rebuild
  995. current_discard < 0))
  996. {
  997. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  998. mSculptChanged = true;
  999. }
  1000. if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SCULPTED))
  1001. {
  1002. setDebugText(llformat("T%d C%d V%d\n%dx%d",
  1003. texture_discard, current_discard,
  1004. getVolume() ?
  1005. getVolume()->getSculptLevel() : -2,
  1006. mSculptTexture->getHeight(),
  1007. mSculptTexture->getWidth()));
  1008. }
  1009. }
  1010. }
  1011. if (getLightTextureID().notNull())
  1012. {
  1013. const LLLightImageParams* params = getLightImageParams();
  1014. if (params)
  1015. {
  1016. const LLUUID& id = params->getLightTexture();
  1017. mLightTexture =
  1018. LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT,
  1019. true,
  1020. LLGLTexture::BOOST_ALM);
  1021. if (mLightTexture.notNull())
  1022. {
  1023. F32 rad = getLightRadius();
  1024. F32 vsize = gPipeline.calcPixelArea(getPositionAgent(),
  1025. LLVector3(rad, rad, rad),
  1026. gViewerCamera);
  1027. mLightTexture->addTextureStats(vsize);
  1028. }
  1029. }
  1030. }
  1031. if (debug_tex_area)
  1032. {
  1033. setDebugText(llformat("%.0f:%.0f", sqrtf(min_vsize),
  1034. sqrtf(max_vsize)));
  1035. }
  1036. else if (debug_tex_prio)
  1037. {
  1038. setDebugText(llformat("%.0f:%.0f", sqrtf(min_vsize),
  1039. sqrtf(max_vsize)));
  1040. }
  1041. else if (debug_face_alpha)
  1042. {
  1043. setDebugText(llformat("%.0f:%.0f", sqrtf(min_vsize),
  1044. sqrtf(max_vsize)));
  1045. }
  1046. else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_SIZE))
  1047. {
  1048. std::map<U64, std::string> tex_list;
  1049. std::map<U64, std::string>::iterator it;
  1050. std::string faces;
  1051. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  1052. {
  1053. LLFace* facep = mDrawable->getFace(i);
  1054. if (!facep) continue;
  1055. LLViewerTexture* vtexp = facep->getTexture();
  1056. if (!vtexp) continue;
  1057. LLViewerFetchedTexture* texp = vtexp->asFetched();
  1058. if (!texp) continue;
  1059. faces = llformat("%d", i);
  1060. U64 size = ((U64)texp->getWidth() << 32) + (U64)texp->getHeight();
  1061. it = tex_list.find(size);
  1062. if (it == tex_list.end())
  1063. {
  1064. tex_list.emplace(size, faces);
  1065. }
  1066. else
  1067. {
  1068. tex_list.emplace(size, it->second + " " + faces);
  1069. }
  1070. }
  1071. std::map<U64, std::string>::iterator end = tex_list.end();
  1072. std::string output;
  1073. for (it = tex_list.begin(); it != end; ++it)
  1074. {
  1075. U64 size = it->first;
  1076. S32 width = (S32)(size >> 32);
  1077. S32 height = (S32)(size & 0x00000000ffffffff);
  1078. faces = llformat("%dx%d (%s)", width, height, it->second.c_str());
  1079. if (!output.empty())
  1080. {
  1081. output += "\n";
  1082. }
  1083. output += faces;
  1084. }
  1085. setDebugText(output);
  1086. }
  1087. if (mPixelArea == 0)
  1088. {
  1089. // Flexi phasing issues make this happen
  1090. mPixelArea = old_area;
  1091. }
  1092. }
  1093. void LLVOVolume::setTexture(S32 face)
  1094. {
  1095. llassert(face < getNumTEs());
  1096. gGL.getTexUnit(0)->bind(getTEImage(face));
  1097. }
  1098. void LLVOVolume::setScale(const LLVector3& scale, bool damped)
  1099. {
  1100. if (scale != getScale())
  1101. {
  1102. // Store local radius
  1103. LLViewerObject::setScale(scale);
  1104. if (mVolumeImpl)
  1105. {
  1106. mVolumeImpl->onSetScale(scale, damped);
  1107. }
  1108. updateRadius();
  1109. if (mDrawable.notNull())
  1110. {
  1111. // Since drawable transforms do not include scale, changing volume
  1112. // scale requires a rebuild of volume verts.
  1113. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_POSITION);
  1114. shrinkWrap();
  1115. }
  1116. }
  1117. }
  1118. LLFace* LLVOVolume::addFace(S32 f)
  1119. {
  1120. const LLTextureEntry* tep = getTE(f);
  1121. LLViewerTexture* imagep = getTEImage(f);
  1122. if (tep && tep->getMaterialParams().notNull())
  1123. {
  1124. return mDrawable->addFace(tep, imagep, getTENormalMap(f),
  1125. getTESpecularMap(f));
  1126. }
  1127. return mDrawable->addFace(tep, imagep);
  1128. }
  1129. LLDrawable* LLVOVolume::createDrawable()
  1130. {
  1131. gPipeline.allocDrawable(this);
  1132. mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
  1133. S32 max_tes_to_set = getNumTEs();
  1134. for (S32 i = 0; i < max_tes_to_set; ++i)
  1135. {
  1136. addFace(i);
  1137. }
  1138. mNumFaces = max_tes_to_set;
  1139. if (isAttachment())
  1140. {
  1141. mDrawable->makeActive();
  1142. }
  1143. if (getIsLight())
  1144. {
  1145. // Add it to the pipeline mLightSet
  1146. gPipeline.setLight(mDrawable, true);
  1147. }
  1148. if (isReflectionProbe())
  1149. {
  1150. updateReflectionProbePtr();
  1151. }
  1152. updateRadius();
  1153. // Force_update = true to avoid non-alpha mDistance update being optimized
  1154. // away
  1155. mDrawable->updateDistance(gViewerCamera, true);
  1156. return mDrawable;
  1157. }
  1158. bool LLVOVolume::setVolume(const LLVolumeParams& params_in, S32 detail,
  1159. bool unique_volume)
  1160. {
  1161. mCostData = NULL; // Reset cost data cache since parameters changed
  1162. LLVolumeParams volume_params = params_in;
  1163. S32 last_lod;
  1164. if (mVolumep.notNull())
  1165. {
  1166. last_lod =
  1167. LLVolumeLODGroup::getVolumeDetailFromScale(mVolumep->getDetail());
  1168. }
  1169. else
  1170. {
  1171. last_lod = -1;
  1172. }
  1173. bool is404 = false;
  1174. S32 lod = mLOD;
  1175. if (isSculpted())
  1176. {
  1177. // If it is a mesh
  1178. if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) ==
  1179. LL_SCULPT_TYPE_MESH)
  1180. {
  1181. lod = gMeshRepo.getActualMeshLOD(volume_params, lod);
  1182. if (lod == -1)
  1183. {
  1184. is404 = true;
  1185. lod = 0;
  1186. }
  1187. else
  1188. {
  1189. mLOD = lod; // Adopt the actual mesh LOD
  1190. }
  1191. }
  1192. }
  1193. // Check if we need to change implementations
  1194. bool is_flexible = volume_params.getPathParams().getCurveType() ==
  1195. LL_PCODE_PATH_FLEXIBLE;
  1196. if (is_flexible)
  1197. {
  1198. setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, true, false);
  1199. if (!mVolumeImpl)
  1200. {
  1201. mVolumeImpl = new LLVolumeImplFlexible(this,
  1202. getFlexibleObjectData());
  1203. }
  1204. }
  1205. else
  1206. {
  1207. // Mark the parameter not in use
  1208. setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, false, false);
  1209. if (mVolumeImpl)
  1210. {
  1211. delete mVolumeImpl;
  1212. mVolumeImpl = NULL;
  1213. if (mDrawable.notNull())
  1214. {
  1215. // Undo the damage we did to this matrix
  1216. mDrawable->updateXform(false);
  1217. }
  1218. }
  1219. }
  1220. if (is404)
  1221. {
  1222. setIcon(LLViewerTextureManager::getFetchedTextureFromFile("inv_item_mesh.tga"));
  1223. // Render prim proxy when mesh loading attempts give up
  1224. volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_NONE);
  1225. }
  1226. bool res = LLPrimitive::setVolume(volume_params, lod,
  1227. mVolumeImpl &&
  1228. mVolumeImpl->isVolumeUnique());
  1229. if (!res && !mSculptChanged)
  1230. {
  1231. return false;
  1232. }
  1233. mFaceMappingChanged = true;
  1234. if (mVolumeImpl)
  1235. {
  1236. mVolumeImpl->onSetVolume(volume_params, mLOD);
  1237. }
  1238. updateSculptTexture();
  1239. if (!isSculpted())
  1240. {
  1241. return true;
  1242. }
  1243. LLVolume* volp = getVolume();
  1244. if (!volp)
  1245. {
  1246. return false;
  1247. }
  1248. // If it is a mesh
  1249. if ((volume_params.getSculptType() &
  1250. LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
  1251. {
  1252. if (mSkinInfo.notNull() &&
  1253. mSkinInfo->mMeshID != volume_params.getSculptID())
  1254. {
  1255. mSkinInfo = NULL;
  1256. mSkinInfoFailed = false;
  1257. }
  1258. if (volp && !volp->isMeshAssetLoaded())
  1259. {
  1260. // Load request not yet issued, request pipeline load this mesh
  1261. S32 available_lod = gMeshRepo.loadMesh(this, volume_params, lod,
  1262. last_lod);
  1263. if (available_lod != lod)
  1264. {
  1265. LLPrimitive::setVolume(volume_params, available_lod);
  1266. }
  1267. }
  1268. if (mSkinInfo.isNull() && !mSkinInfoFailed)
  1269. {
  1270. const LLMeshSkinInfo* skin_infop =
  1271. gMeshRepo.getSkinInfo(volume_params.getSculptID(), this);
  1272. if (skin_infop)
  1273. {
  1274. notifySkinInfoLoaded((LLMeshSkinInfo*)skin_infop);
  1275. }
  1276. }
  1277. }
  1278. // Otherwise it should be sculptie
  1279. else
  1280. {
  1281. sculpt();
  1282. }
  1283. return true;
  1284. }
  1285. void LLVOVolume::updateSculptTexture()
  1286. {
  1287. LLPointer<LLViewerFetchedTexture> old_sculpt = mSculptTexture;
  1288. if (isSculpted() && !isMesh())
  1289. {
  1290. const LLSculptParams* sculpt_params = getSculptParams();
  1291. if (sculpt_params)
  1292. {
  1293. const LLUUID& id = sculpt_params->getSculptTexture();
  1294. if (id.notNull())
  1295. {
  1296. mSculptTexture =
  1297. LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT,
  1298. true,
  1299. LLGLTexture::BOOST_NONE,
  1300. LLViewerTexture::LOD_TEXTURE);
  1301. }
  1302. }
  1303. mSkinInfoFailed = false;
  1304. mSkinInfo = NULL;
  1305. }
  1306. else
  1307. {
  1308. mSculptTexture = NULL;
  1309. }
  1310. if (mSculptTexture != old_sculpt)
  1311. {
  1312. if (old_sculpt.notNull())
  1313. {
  1314. old_sculpt->removeVolume(LLRender::SCULPT_TEX, this);
  1315. }
  1316. if (mSculptTexture.notNull())
  1317. {
  1318. mSculptTexture->addVolume(LLRender::SCULPT_TEX, this);
  1319. }
  1320. }
  1321. }
  1322. void LLVOVolume::updateVisualComplexity()
  1323. {
  1324. LLVOAvatar* avatarp = getAvatarAncestor();
  1325. if (avatarp)
  1326. {
  1327. avatarp->updateVisualComplexity();
  1328. }
  1329. LLVOAvatar* rigged_avatarp = getAvatar();
  1330. if (rigged_avatarp && rigged_avatarp != avatarp)
  1331. {
  1332. rigged_avatarp->updateVisualComplexity();
  1333. }
  1334. }
  1335. void LLVOVolume::notifyMeshLoaded()
  1336. {
  1337. mCostData = NULL; // Reset cost data cache since mesh changed
  1338. mSculptChanged = true;
  1339. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
  1340. LLVOAvatar* avatarp = getAvatar();
  1341. if (avatarp && !isAnimatedObject())
  1342. {
  1343. avatarp->addAttachmentOverridesForObject(this);
  1344. }
  1345. LLVOAvatarPuppet* puppetp = getPuppetAvatar();
  1346. if (puppetp)
  1347. {
  1348. puppetp->addAttachmentOverridesForObject(this);
  1349. }
  1350. updateVisualComplexity();
  1351. }
  1352. void LLVOVolume::notifySkinInfoLoaded(LLMeshSkinInfo* skinp)
  1353. {
  1354. mSkinInfoFailed = false;
  1355. mSkinInfo = skinp;
  1356. notifyMeshLoaded();
  1357. }
  1358. void LLVOVolume::notifySkinInfoUnavailable()
  1359. {
  1360. mSkinInfoFailed = true;
  1361. mSkinInfo = NULL;
  1362. }
  1363. // This replaces generate() for sculpted surfaces
  1364. void LLVOVolume::sculpt()
  1365. {
  1366. if (mSculptTexture.isNull())
  1367. {
  1368. return;
  1369. }
  1370. U16 sculpt_height = 0;
  1371. U16 sculpt_width = 0;
  1372. S8 sculpt_components = 0;
  1373. const U8* sculpt_data = NULL;
  1374. S32 discard_level = mSculptTexture->getCachedRawImageLevel();
  1375. LLImageRaw* raw_image = mSculptTexture->getCachedRawImage();
  1376. S32 max_discard = mSculptTexture->getMaxDiscardLevel();
  1377. if (discard_level > max_discard)
  1378. {
  1379. discard_level = max_discard; // Clamp to the best we can do
  1380. }
  1381. if (discard_level > MAX_DISCARD_LEVEL)
  1382. {
  1383. return; // We think data is not ready yet.
  1384. }
  1385. S32 current_discard = getVolume()->getSculptLevel();
  1386. if (current_discard < -2)
  1387. {
  1388. llwarns << "Current discard of sculpty at " << current_discard
  1389. << " is less than -2 !" << llendl;
  1390. // Corrupted volume... do not update the sculpty
  1391. return;
  1392. }
  1393. else if (current_discard > MAX_DISCARD_LEVEL)
  1394. {
  1395. #if 0 // Disabled to avoid log spam. *FIXME: find the cause for that spam
  1396. llwarns << "Current discard of sculpty at " << current_discard
  1397. << " is more than the allowed max of " << MAX_DISCARD_LEVEL
  1398. << llendl;
  1399. #endif
  1400. // Corrupted volume... do not update the sculpty
  1401. return;
  1402. }
  1403. if (current_discard == discard_level)
  1404. {
  1405. // No work to do here
  1406. return;
  1407. }
  1408. if (!raw_image)
  1409. {
  1410. llassert(discard_level < 0);
  1411. sculpt_width = 0;
  1412. sculpt_height = 0;
  1413. sculpt_data = NULL;
  1414. }
  1415. else
  1416. {
  1417. sculpt_height = raw_image->getHeight();
  1418. sculpt_width = raw_image->getWidth();
  1419. sculpt_components = raw_image->getComponents();
  1420. sculpt_data = raw_image->getData();
  1421. }
  1422. getVolume()->sculpt(sculpt_width, sculpt_height, sculpt_components,
  1423. sculpt_data, discard_level,
  1424. mSculptTexture->isMissingAsset());
  1425. // Notify rebuild any other VOVolumes that reference this sculpty volume
  1426. for (S32 i = 0,
  1427. count = mSculptTexture->getNumVolumes(LLRender::SCULPT_TEX);
  1428. i < count; ++i)
  1429. {
  1430. LLVOVolume* volp =
  1431. (*(mSculptTexture->getVolumeList(LLRender::SCULPT_TEX)))[i];
  1432. if (volp != this && volp->getVolume() == getVolume())
  1433. {
  1434. gPipeline.markRebuild(volp->mDrawable,
  1435. LLDrawable::REBUILD_GEOMETRY);
  1436. }
  1437. }
  1438. }
  1439. S32 LLVOVolume::computeLODDetail(F32 distance, F32 radius, F32 lod_factor)
  1440. {
  1441. if (LLPipeline::sDynamicLOD)
  1442. {
  1443. // We have got LOD in the profile, and in the twist. Use radius.
  1444. F32 tan_angle = ll_round(lod_factor * radius / distance, 0.01f);
  1445. return LLVolumeLODGroup::getDetailFromTan(tan_angle);
  1446. }
  1447. return llclamp((S32)(sqrtf(radius) * lod_factor * 4.f), 0, 3);
  1448. }
  1449. bool LLVOVolume::calcLOD()
  1450. {
  1451. if (mDrawable.isNull())
  1452. {
  1453. return false;
  1454. }
  1455. // Locked to max LOD objects, selected objects and HUD attachments always
  1456. // rendered at max LOD
  1457. if (mLockMaxLOD || isSelected() || isHUDAttachment())
  1458. {
  1459. if (mLOD == 3)
  1460. {
  1461. return false;
  1462. }
  1463. mLOD = 3;
  1464. return true;
  1465. }
  1466. F32 radius;
  1467. F32 distance;
  1468. LLVolume* volumep = getVolume();
  1469. if (mDrawable->isState(LLDrawable::RIGGED))
  1470. {
  1471. LLVOAvatar* avatarp = getAvatar();
  1472. if (!avatarp)
  1473. {
  1474. llwarns << "NULL avatar pointer for rigged drawable" << llendl;
  1475. clearRiggedVolume(); // Bogus volume: clear it. HB
  1476. return false;
  1477. }
  1478. if (avatarp->mDrawable.isNull())
  1479. {
  1480. llwarns << "No drawable for avatar associated to rigged drawable"
  1481. << llendl;
  1482. clearRiggedVolume(); // Bogus volume: clear it. HB
  1483. return false;
  1484. }
  1485. distance = avatarp->mDrawable->mDistanceWRTCamera;
  1486. if (avatarp->isPuppetAvatar())
  1487. {
  1488. // Handle volumes in an animated object as a special case
  1489. const LLVector3* boxp = avatarp->getLastAnimExtents();
  1490. radius = (boxp[1] - boxp[0]).length() * 0.5f;
  1491. }
  1492. else
  1493. {
  1494. #if 1 // SL-937: add dynamic box handling for rigged mesh on regular
  1495. // avatars
  1496. const LLVector3* boxp = avatarp->getLastAnimExtents();
  1497. radius = (boxp[1] - boxp[0]).length();
  1498. #else
  1499. radius = avatarp->getBinRadius();
  1500. #endif
  1501. }
  1502. }
  1503. else
  1504. {
  1505. if (volumep)
  1506. {
  1507. radius = volumep->mLODScaleBias.scaledVec(getScale()).length();
  1508. }
  1509. else
  1510. {
  1511. llwarns_once << "NULL volume associated with drawable " << std::hex
  1512. << mDrawable.get() << std::dec << llendl;
  1513. radius = getScale().length();
  1514. }
  1515. distance = mDrawable->mDistanceWRTCamera;
  1516. }
  1517. if (distance <= 0.f || radius <= 0.f)
  1518. {
  1519. return false;
  1520. }
  1521. radius = ll_round(radius, 0.01f);
  1522. distance *= sDistanceFactor;
  1523. static LLCachedControl<F32> mesh_boost(gSavedSettings,
  1524. "MeshLODBoostFactor");
  1525. F32 boost_factor = 1.f;
  1526. if (mesh_boost > 1.f && isMesh())
  1527. {
  1528. boost_factor = llclamp((F32)mesh_boost, 1.f, 4.f);
  1529. }
  1530. // Boost LOD when you are REALLY close
  1531. F32 ramp_dist = sLODFactor * 2.f * boost_factor;
  1532. if (distance < ramp_dist)
  1533. {
  1534. distance /= ramp_dist;
  1535. distance *= distance;
  1536. distance *= ramp_dist;
  1537. }
  1538. distance = ll_round(distance * (F_PI / 3.f), 0.01f);
  1539. static LLCachedControl<F32> hysteresis(gSavedSettings,
  1540. "DistanceHysteresisLOD");
  1541. // Avoid blinking objects due to LOD changing every few frames because of
  1542. // LOD-dependant (since bounding-box dependant) distance changes. HB
  1543. if (mLastDistance > 0.f && fabs(mLastDistance - distance) < hysteresis)
  1544. {
  1545. distance = mLastDistance;
  1546. }
  1547. else
  1548. {
  1549. mLastDistance = distance;
  1550. }
  1551. F32 lod_factor = sLODFactor;
  1552. static LLCachedControl<bool> ignore_fov_zoom(gSavedSettings,
  1553. "IgnoreFOVZoomForLODs");
  1554. if (!ignore_fov_zoom)
  1555. {
  1556. lod_factor *= DEFAULT_FIELD_OF_VIEW / gViewerCamera.getDefaultFOV();
  1557. }
  1558. lod_factor *= boost_factor;
  1559. S32 cur_detail = computeLODDetail(distance, radius, lod_factor);
  1560. if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LOD_INFO))
  1561. {
  1562. setDebugText(llformat("%d (d=%.2f/r=%.2f)", cur_detail, distance,
  1563. radius));
  1564. }
  1565. if (cur_detail == mLOD)
  1566. {
  1567. return false;
  1568. }
  1569. mAppAngle = ll_round(atan2f(mDrawable->getRadius(),
  1570. mDrawable->mDistanceWRTCamera) * RAD_TO_DEG,
  1571. 0.01f);
  1572. mLOD = cur_detail;
  1573. return true;
  1574. }
  1575. bool LLVOVolume::updateLOD()
  1576. {
  1577. if (mDrawable.isNull())
  1578. {
  1579. return false;
  1580. }
  1581. if (calcLOD())
  1582. {
  1583. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  1584. mLODChanged = true;
  1585. return true;
  1586. }
  1587. F32 new_radius = getBinRadius();
  1588. F32 old_radius = mDrawable->getBinRadius();
  1589. if (new_radius < old_radius * 0.9f || new_radius > old_radius * 1.1f)
  1590. {
  1591. gPipeline.markPartitionMove(mDrawable);
  1592. }
  1593. return LLViewerObject::updateLOD();
  1594. }
  1595. void LLVOVolume::tempSetLOD(S32 lod)
  1596. {
  1597. mLOD = lod;
  1598. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  1599. mLODChanged = true;
  1600. }
  1601. bool LLVOVolume::setDrawableParent(LLDrawable* parentp)
  1602. {
  1603. if (!LLViewerObject::setDrawableParent(parentp))
  1604. {
  1605. // No change in drawable parent
  1606. return false;
  1607. }
  1608. if (!mDrawable->isRoot())
  1609. {
  1610. // Rebuild vertices in parent relative space
  1611. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  1612. if (mDrawable->isActive() && !parentp->isActive())
  1613. {
  1614. parentp->makeActive();
  1615. }
  1616. else if (mDrawable->isStatic() && parentp->isActive())
  1617. {
  1618. mDrawable->makeActive();
  1619. }
  1620. }
  1621. return true;
  1622. }
  1623. void LLVOVolume::updateFaceFlags()
  1624. {
  1625. if (mDrawable.isNull())
  1626. {
  1627. llwarns << "NULL drawable !" << llendl;
  1628. return;
  1629. }
  1630. for (S32 i = 0, count = llmin(getVolume()->getNumFaces(),
  1631. mDrawable->getNumFaces());
  1632. i < count; ++i)
  1633. {
  1634. LLFace* facep = mDrawable->getFace(i);
  1635. if (facep)
  1636. {
  1637. LLTextureEntry* tep = getTE(i);
  1638. if (!tep) continue;
  1639. bool fullbright = tep->getFullbright();
  1640. facep->clearState(LLFace::FULLBRIGHT | LLFace::HUD_RENDER |
  1641. LLFace::LIGHT);
  1642. if (fullbright || mMaterial == LL_MCODE_LIGHT)
  1643. {
  1644. facep->setState(LLFace::FULLBRIGHT);
  1645. }
  1646. if (mDrawable->isLight())
  1647. {
  1648. facep->setState(LLFace::LIGHT);
  1649. }
  1650. if (isHUDAttachment())
  1651. {
  1652. facep->setState(LLFace::HUD_RENDER);
  1653. }
  1654. }
  1655. }
  1656. }
  1657. bool LLVOVolume::setParent(LLViewerObject* parentp)
  1658. {
  1659. bool ret = false;
  1660. LLViewerObject* old_parentp = (LLViewerObject*)getParent();
  1661. if (parentp != old_parentp)
  1662. {
  1663. ret = LLViewerObject::setParent(parentp);
  1664. if (ret && mDrawable)
  1665. {
  1666. gPipeline.markMoved(mDrawable);
  1667. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  1668. }
  1669. onReparent(old_parentp, parentp);
  1670. }
  1671. return ret;
  1672. }
  1673. void LLVOVolume::regenFaces()
  1674. {
  1675. // Remove existing faces
  1676. bool count_changed = mNumFaces != getNumTEs();
  1677. if (count_changed)
  1678. {
  1679. deleteFaces();
  1680. // Add new faces
  1681. mNumFaces = getNumTEs();
  1682. }
  1683. S32 media_count = mMediaImplList.size();
  1684. for (S32 i = 0; i < mNumFaces; ++i)
  1685. {
  1686. LLFace* facep = count_changed ? addFace(i) : mDrawable->getFace(i);
  1687. if (!facep) continue;
  1688. facep->setTEOffset(i);
  1689. facep->setDiffuseMap(getTEImage(i));
  1690. if (facep->getTextureEntry()->getMaterialParams().notNull())
  1691. {
  1692. facep->setNormalMap(getTENormalMap(i));
  1693. facep->setSpecularMap(getTESpecularMap(i));
  1694. }
  1695. facep->setViewerObject(this);
  1696. if (i >= media_count || mMediaImplList[i].isNull())
  1697. {
  1698. continue;
  1699. }
  1700. // If the face had media on it, this will have broken the link between
  1701. // the LLViewerMediaTexture and the face. Re-establish the link.
  1702. const LLUUID& id = mMediaImplList[i]->getMediaTextureID();
  1703. LLViewerMediaTexture* media_texp =
  1704. LLViewerTextureManager::findMediaTexture(id);
  1705. if (media_texp)
  1706. {
  1707. media_texp->addMediaToFace(facep);
  1708. }
  1709. }
  1710. if (!count_changed)
  1711. {
  1712. updateFaceFlags();
  1713. }
  1714. }
  1715. bool LLVOVolume::genBBoxes(bool force_global, bool update_bounds)
  1716. {
  1717. bool rebuild = mDrawable->isState(LLDrawable::REBUILD_VOLUME |
  1718. LLDrawable::REBUILD_POSITION |
  1719. LLDrawable::REBUILD_RIGGED);
  1720. LLVolume* volumep = mRiggedVolume.get();
  1721. if (volumep)
  1722. {
  1723. // With 'false', this will remove unused rigged volumes, which we are
  1724. // not currently very aggressive about.
  1725. updateRiggedVolume(false);
  1726. }
  1727. else
  1728. {
  1729. volumep = getVolume();
  1730. if (!volumep)
  1731. {
  1732. llwarns_sparse << "NULL volume. Skipping." << llendl;
  1733. return false;
  1734. }
  1735. }
  1736. bool res = true;
  1737. LLVector4a min, max;
  1738. min.clear();
  1739. max.clear();
  1740. force_global |= mVolumeImpl && mVolumeImpl->isVolumeGlobal();
  1741. bool any_valid_boxes = false;
  1742. for (S32 i = 0, count = llmin(volumep->getNumVolumeFaces(),
  1743. mDrawable->getNumFaces(),
  1744. (S32)getNumTEs()); i < count; ++i)
  1745. {
  1746. LLFace* facep = mDrawable->getFace(i);
  1747. if (!facep)
  1748. {
  1749. continue;
  1750. }
  1751. bool face_res = facep->genVolumeBBoxes(*volumep, i, mRelativeXform,
  1752. force_global);
  1753. res &= face_res;
  1754. if (!face_res)
  1755. {
  1756. // MAINT-8264: ignore bboxes of ill-formed faces.
  1757. continue;
  1758. }
  1759. if (rebuild)
  1760. {
  1761. if (!any_valid_boxes)
  1762. {
  1763. min = facep->mExtents[0];
  1764. max = facep->mExtents[1];
  1765. any_valid_boxes = true;
  1766. }
  1767. else
  1768. {
  1769. min.setMin(min, facep->mExtents[0]);
  1770. max.setMax(max, facep->mExtents[1]);
  1771. }
  1772. }
  1773. }
  1774. if (any_valid_boxes)
  1775. {
  1776. if (rebuild && update_bounds)
  1777. {
  1778. mDrawable->setSpatialExtents(min, max);
  1779. bool has_avatar = false;
  1780. if (isRiggedMesh())
  1781. {
  1782. // When editing any attachment, skip entirely the 'has_avatar'
  1783. // optimization for rigged mesh octree/batching, and revert to
  1784. // the old code. The reason for this is that the new optimized
  1785. // code breaks our work-around (see the "EditedMeshLOD" debug
  1786. // setting usage) for broken rigged mesh LODs while edited (and
  1787. // the mesh LOD sometimes even stays broken after edit without
  1788. // that work-around). HB
  1789. if (!LLFloaterTools::isVisible() ||
  1790. !gSelectMgr.selectionIsAvatarAttachment())
  1791. {
  1792. if (isAnimatedObject())
  1793. {
  1794. LLVOAvatarPuppet* puppetp = getPuppetAvatar();
  1795. has_avatar = puppetp && puppetp->mPlaying;
  1796. }
  1797. else
  1798. {
  1799. has_avatar = isAttachment() && getAvatar();
  1800. }
  1801. }
  1802. }
  1803. if (has_avatar)
  1804. {
  1805. // Put all rigged drawables in the same octree node for
  1806. // better batching.
  1807. mDrawable->setPositionGroup(LLVector4a::getZero());
  1808. }
  1809. else
  1810. {
  1811. min.add(max);
  1812. min.mul(0.5f);
  1813. mDrawable->setPositionGroup(min);
  1814. }
  1815. }
  1816. updateRadius();
  1817. mDrawable->movePartition();
  1818. }
  1819. return res;
  1820. }
  1821. void LLVOVolume::preRebuild()
  1822. {
  1823. if (mVolumeImpl)
  1824. {
  1825. mVolumeImpl->preRebuild();
  1826. }
  1827. }
  1828. void LLVOVolume::updateRelativeXform(bool force_identity)
  1829. {
  1830. if (mVolumeImpl)
  1831. {
  1832. mVolumeImpl->updateRelativeXform(force_identity);
  1833. return;
  1834. }
  1835. static LLVector3 vec3_x(1.f, 0.f, 0.f);
  1836. static LLVector3 vec3_y(0.f, 1.f, 0.f);
  1837. static LLVector3 vec3_z(0.f, 0.f, 1.f);
  1838. LLDrawable* drawable = mDrawable;
  1839. if (drawable->isState(LLDrawable::RIGGED) && mRiggedVolume.notNull())
  1840. {
  1841. // Rigged volume (which is in agent space) is used for generating
  1842. // bounding boxes etc. Inverse of render matrix should go to
  1843. // partition space
  1844. mRelativeXform = getRenderMatrix();
  1845. F32* dst = mRelativeXformInvTrans.getF32ptr();
  1846. F32* src = mRelativeXform.getF32ptr();
  1847. dst[0] = src[0];
  1848. dst[1] = src[1];
  1849. dst[2] = src[2];
  1850. dst[3] = src[4];
  1851. dst[4] = src[5];
  1852. dst[5] = src[6];
  1853. dst[6] = src[8];
  1854. dst[7] = src[9];
  1855. dst[8] = src[10];
  1856. mRelativeXform.invert();
  1857. mRelativeXformInvTrans.transpose();
  1858. }
  1859. else if (drawable->isActive() || force_identity)
  1860. {
  1861. // Setup relative transforms
  1862. LLQuaternion delta_rot;
  1863. LLVector3 delta_pos;
  1864. // Matrix from local space to parent relative/global space
  1865. if (!force_identity && !drawable->isSpatialRoot())
  1866. {
  1867. delta_rot = mDrawable->getRotation();
  1868. delta_pos = mDrawable->getPosition();
  1869. }
  1870. LLVector3 delta_scale = mDrawable->getScale();
  1871. // Vertex transform (4x4)
  1872. LLVector3 x_axis = LLVector3(delta_scale.mV[VX], 0.f, 0.f) * delta_rot;
  1873. LLVector3 y_axis = LLVector3(0.f, delta_scale.mV[VY], 0.f) * delta_rot;
  1874. LLVector3 z_axis = LLVector3(0.f, 0.f, delta_scale.mV[VZ]) * delta_rot;
  1875. mRelativeXform.initRows(LLVector4(x_axis, 0.f),
  1876. LLVector4(y_axis, 0.f),
  1877. LLVector4(z_axis, 0.f),
  1878. LLVector4(delta_pos, 1.f));
  1879. // Compute inverse transpose for normals
  1880. // grumble - invert is NOT a matrix invert, so we do it by hand:
  1881. LLMatrix3 rot_inverse = LLMatrix3(~delta_rot);
  1882. LLMatrix3 scale_inverse;
  1883. scale_inverse.setRows(vec3_x / delta_scale.mV[VX],
  1884. vec3_y / delta_scale.mV[VY],
  1885. vec3_z / delta_scale.mV[VZ]);
  1886. mRelativeXformInvTrans = rot_inverse * scale_inverse;
  1887. mRelativeXformInvTrans.transpose();
  1888. }
  1889. else
  1890. {
  1891. LLVector3 pos = getPosition();
  1892. LLVector3 scale = getScale();
  1893. LLQuaternion rot = getRotation();
  1894. if (mParent)
  1895. {
  1896. pos *= mParent->getRotation();
  1897. pos += mParent->getPosition();
  1898. rot *= mParent->getRotation();
  1899. }
  1900. #if 0
  1901. pos += getRegion()->getOriginAgent();
  1902. #endif
  1903. LLVector3 x_axis = LLVector3(scale.mV[VX], 0.f, 0.f) * rot;
  1904. LLVector3 y_axis = LLVector3(0.f, scale.mV[VY], 0.f) * rot;
  1905. LLVector3 z_axis = LLVector3(0.f, 0.f, scale.mV[VZ]) * rot;
  1906. mRelativeXform.initRows(LLVector4(x_axis, 0.f),
  1907. LLVector4(y_axis, 0.f),
  1908. LLVector4(z_axis, 0.f),
  1909. LLVector4(pos, 1.f));
  1910. // Compute inverse transpose for normals
  1911. LLMatrix3 rot_inverse = LLMatrix3(~rot);
  1912. LLMatrix3 scale_inverse;
  1913. scale_inverse.setRows(vec3_x / scale.mV[VX],
  1914. vec3_y / scale.mV[VY],
  1915. vec3_z / scale.mV[VZ]);
  1916. mRelativeXformInvTrans = rot_inverse * scale_inverse;
  1917. mRelativeXformInvTrans.transpose();
  1918. }
  1919. }
  1920. bool LLVOVolume::lodOrSculptChanged(LLDrawable* drawable, bool& update_bounds)
  1921. {
  1922. LLVolume* old_volumep = getVolume();
  1923. if (!old_volumep)
  1924. {
  1925. return false;
  1926. }
  1927. F32 old_lod = old_volumep->getDetail();
  1928. S32 old_num_faces = old_volumep->getNumFaces();;
  1929. old_volumep = NULL;
  1930. LLVolume* new_volumep = getVolume();
  1931. {
  1932. LL_FAST_TIMER(FTM_GEN_VOLUME);
  1933. const LLVolumeParams& volume_params = new_volumep->getParams();
  1934. setVolume(volume_params, 0);
  1935. }
  1936. F32 new_lod = new_volumep->getDetail();
  1937. S32 new_num_faces = new_volumep->getNumFaces();
  1938. new_volumep = NULL;
  1939. bool regen_faces = false;
  1940. if (new_lod != old_lod || mSculptChanged)
  1941. {
  1942. if (mDrawable->isState(LLDrawable::RIGGED))
  1943. {
  1944. updateVisualComplexity();
  1945. }
  1946. sNumLODChanges += new_num_faces;
  1947. if (new_lod > old_lod || mSculptChanged)
  1948. {
  1949. update_bounds = true;
  1950. }
  1951. if ((S32)getNumTEs() != getVolume()->getNumFaces())
  1952. {
  1953. // Mesh loading may change number of faces.
  1954. setNumTEs(getVolume()->getNumFaces());
  1955. }
  1956. // For face->genVolumeTriangles()
  1957. drawable->setState(LLDrawable::REBUILD_VOLUME);
  1958. {
  1959. LL_FAST_TIMER(FTM_GEN_TRIANGLES);
  1960. regen_faces = new_num_faces != old_num_faces ||
  1961. mNumFaces != (S32)getNumTEs();
  1962. if (regen_faces)
  1963. {
  1964. regenFaces();
  1965. }
  1966. if (mSculptChanged)
  1967. {
  1968. // Changes in sculpt maps can thrash an object bounding box
  1969. // without triggering a spatial group bounding box update:
  1970. // force spatial group to update bounding boxes.
  1971. LLSpatialGroup* group = mDrawable->getSpatialGroup();
  1972. if (group)
  1973. {
  1974. group->unbound();
  1975. }
  1976. }
  1977. }
  1978. }
  1979. return regen_faces;
  1980. }
  1981. bool LLVOVolume::updateGeometry(LLDrawable* drawablep)
  1982. {
  1983. LL_FAST_TIMER(FTM_UPDATE_PRIMITIVES);
  1984. if (isDead() || !drawablep || drawablep->isDead() || mDrawable.isNull() ||
  1985. mDrawable->isDead())
  1986. {
  1987. return true;
  1988. }
  1989. if (mDrawable->isState(LLDrawable::REBUILD_RIGGED))
  1990. {
  1991. updateRiggedVolume(false);
  1992. genBBoxes(false);
  1993. mDrawable->clearState(LLDrawable::REBUILD_RIGGED);
  1994. }
  1995. if (mVolumeImpl)
  1996. {
  1997. bool res;
  1998. {
  1999. LL_FAST_TIMER(FTM_GEN_FLEX);
  2000. res = mVolumeImpl->doUpdateGeometry(drawablep);
  2001. }
  2002. updateFaceFlags();
  2003. return res;
  2004. }
  2005. LLSpatialGroup* groupp = drawablep->getSpatialGroup();
  2006. if (groupp)
  2007. {
  2008. groupp->dirtyMesh();
  2009. }
  2010. updateRelativeXform();
  2011. // Not sure why this is happening, but it is...
  2012. if (mDrawable.isNull() || mDrawable->isDead())
  2013. {
  2014. llwarns << "NULL or dead drawable detected. Aborted." << llendl;
  2015. return true; // No update to complete
  2016. }
  2017. // This should be true in most cases, unless we are sure no octree update
  2018. // is needed.
  2019. bool update_bounds = mRiggedVolume.notNull() ||
  2020. mDrawable->isState(LLDrawable::REBUILD_POSITION) ||
  2021. !mDrawable->getSpatialExtents()->isFinite3();
  2022. if (mVolumeChanged || mFaceMappingChanged)
  2023. {
  2024. dirtySpatialGroup();
  2025. bool was_regen_faces = false;
  2026. update_bounds = true;
  2027. if (mVolumeChanged)
  2028. {
  2029. was_regen_faces = lodOrSculptChanged(drawablep, update_bounds);
  2030. drawablep->setState(LLDrawable::REBUILD_VOLUME);
  2031. }
  2032. else if (mSculptChanged || mLODChanged || mColorChanged)
  2033. {
  2034. was_regen_faces = lodOrSculptChanged(drawablep, update_bounds);
  2035. }
  2036. if (!was_regen_faces)
  2037. {
  2038. LL_FAST_TIMER(FTM_GEN_TRIANGLES);
  2039. regenFaces();
  2040. }
  2041. }
  2042. else if (mLODChanged || mSculptChanged || mColorChanged)
  2043. {
  2044. dirtySpatialGroup();
  2045. lodOrSculptChanged(drawablep, update_bounds);
  2046. constexpr U32 rigged = LLDrawable::REBUILD_RIGGED | LLDrawable::RIGGED;
  2047. if (drawablep->isState(rigged))
  2048. {
  2049. updateRiggedVolume(false);
  2050. }
  2051. }
  2052. // Generate bounding boxes if needed, and update the object size in the
  2053. // octree
  2054. genBBoxes(false, update_bounds);
  2055. // Update face flags
  2056. updateFaceFlags();
  2057. mVolumeChanged = mLODChanged = mSculptChanged = mColorChanged =
  2058. mFaceMappingChanged = false;
  2059. return LLViewerObject::updateGeometry(drawablep);
  2060. }
  2061. //virtual
  2062. void LLVOVolume::updateFaceSize(S32 idx)
  2063. {
  2064. if (mDrawable->getNumFaces() <= idx)
  2065. {
  2066. return;
  2067. }
  2068. LLFace* facep = mDrawable->getFace(idx);
  2069. if (!facep)
  2070. {
  2071. return;
  2072. }
  2073. if (idx >= getVolume()->getNumVolumeFaces())
  2074. {
  2075. facep->setSize(0, 0, true);
  2076. }
  2077. else
  2078. {
  2079. const LLVolumeFace& vol_face = getVolume()->getVolumeFace(idx);
  2080. facep->setSize(vol_face.mNumVertices, vol_face.mNumIndices,
  2081. // volume faces must be padded for 16-byte alignment
  2082. true);
  2083. }
  2084. }
  2085. //virtual
  2086. void LLVOVolume::setNumTEs(U8 num_tes)
  2087. {
  2088. U8 old_num_tes = getNumTEs();
  2089. if (old_num_tes && old_num_tes < num_tes) // new faces added
  2090. {
  2091. LLViewerObject::setNumTEs(num_tes);
  2092. // Duplicate the last media textures if exists.
  2093. if (mMediaImplList.size() >= old_num_tes &&
  2094. mMediaImplList[old_num_tes - 1].notNull())
  2095. {
  2096. mMediaImplList.resize(num_tes);
  2097. const LLTextureEntry* tep = getTE(old_num_tes - 1);
  2098. for (U8 i = old_num_tes; i < num_tes; ++i)
  2099. {
  2100. setTE(i, *tep);
  2101. mMediaImplList[i] = mMediaImplList[old_num_tes - 1];
  2102. }
  2103. mMediaImplList[old_num_tes - 1]->setUpdated(true);
  2104. }
  2105. return;
  2106. }
  2107. if (old_num_tes > num_tes && mMediaImplList.size() > num_tes)
  2108. {
  2109. // Old faces removed
  2110. for (U8 i = num_tes, end = mMediaImplList.size(); i < end; ++i)
  2111. {
  2112. removeMediaImpl(i);
  2113. }
  2114. mMediaImplList.resize(num_tes);
  2115. }
  2116. LLViewerObject::setNumTEs(num_tes);
  2117. }
  2118. //virtual
  2119. void LLVOVolume::setTEImage(U8 te, LLViewerTexture* imagep)
  2120. {
  2121. bool changed = getTEImage(te) != imagep;
  2122. LLViewerObject::setTEImage(te, imagep);
  2123. if (changed)
  2124. {
  2125. gPipeline.markTextured(mDrawable);
  2126. mFaceMappingChanged = true;
  2127. }
  2128. }
  2129. //virtual
  2130. S32 LLVOVolume::setTETexture(U8 te, const LLUUID& uuid)
  2131. {
  2132. S32 res = LLViewerObject::setTETexture(te, uuid);
  2133. if (res)
  2134. {
  2135. if (mDrawable.notNull())
  2136. {
  2137. gPipeline.markTextured(mDrawable);
  2138. // Dynamic texture changes break batches: isolate in octree.
  2139. shrinkWrap();
  2140. }
  2141. mFaceMappingChanged = true;
  2142. }
  2143. return res;
  2144. }
  2145. //virtual
  2146. S32 LLVOVolume::setTEColor(U8 te, const LLColor3& color)
  2147. {
  2148. return setTEColor(te, LLColor4(color));
  2149. }
  2150. //virtual
  2151. S32 LLVOVolume::setTEColor(U8 te, const LLColor4& color)
  2152. {
  2153. const LLTextureEntry* tep = getTE(te);
  2154. if (!tep)
  2155. {
  2156. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  2157. << llendl;
  2158. return 0;
  2159. }
  2160. if (color == tep->getColor())
  2161. {
  2162. return 0;
  2163. }
  2164. if (color.mV[3] != tep->getAlpha())
  2165. {
  2166. gPipeline.markTextured(mDrawable);
  2167. // Treat this alpha change as an LoD update since render batches may
  2168. // need to get rebuilt
  2169. mLODChanged = true;
  2170. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  2171. }
  2172. S32 retval = LLPrimitive::setTEColor(te, color);
  2173. if (retval && mDrawable.notNull())
  2174. {
  2175. // These should only happen on updates which are not the initial
  2176. // update.
  2177. mColorChanged = true;
  2178. mDrawable->setState(LLDrawable::REBUILD_COLOR);
  2179. shrinkWrap();
  2180. dirtyMesh();
  2181. }
  2182. return retval;
  2183. }
  2184. //virtual
  2185. S32 LLVOVolume::setTEBumpmap(U8 te, U8 bumpmap)
  2186. {
  2187. S32 res = LLViewerObject::setTEBumpmap(te, bumpmap);
  2188. if (res)
  2189. {
  2190. gPipeline.markTextured(mDrawable);
  2191. mFaceMappingChanged = true;
  2192. }
  2193. return res;
  2194. }
  2195. //virtual
  2196. S32 LLVOVolume::setTETexGen(U8 te, U8 texgen)
  2197. {
  2198. S32 res = LLViewerObject::setTETexGen(te, texgen);
  2199. if (res)
  2200. {
  2201. gPipeline.markTextured(mDrawable);
  2202. mFaceMappingChanged = true;
  2203. }
  2204. return res;
  2205. }
  2206. //virtual
  2207. S32 LLVOVolume::setTEMediaTexGen(U8 te, U8 media)
  2208. {
  2209. S32 res = LLViewerObject::setTEMediaTexGen(te, media);
  2210. if (res)
  2211. {
  2212. gPipeline.markTextured(mDrawable);
  2213. mFaceMappingChanged = true;
  2214. }
  2215. return res;
  2216. }
  2217. //virtual
  2218. S32 LLVOVolume::setTEShiny(U8 te, U8 shiny)
  2219. {
  2220. S32 res = LLViewerObject::setTEShiny(te, shiny);
  2221. if (res)
  2222. {
  2223. gPipeline.markTextured(mDrawable);
  2224. mFaceMappingChanged = true;
  2225. }
  2226. return res;
  2227. }
  2228. //virtual
  2229. S32 LLVOVolume::setTEFullbright(U8 te, U8 fullbright)
  2230. {
  2231. S32 res = LLViewerObject::setTEFullbright(te, fullbright);
  2232. if (res)
  2233. {
  2234. gPipeline.markTextured(mDrawable);
  2235. mFaceMappingChanged = true;
  2236. }
  2237. return res;
  2238. }
  2239. //virtual
  2240. S32 LLVOVolume::setTEBumpShinyFullbright(U8 te, U8 bump)
  2241. {
  2242. S32 res = LLViewerObject::setTEBumpShinyFullbright(te, bump);
  2243. if (res)
  2244. {
  2245. gPipeline.markTextured(mDrawable);
  2246. mFaceMappingChanged = true;
  2247. }
  2248. return res;
  2249. }
  2250. //virtual
  2251. S32 LLVOVolume::setTEMediaFlags(U8 te, U8 media_flags)
  2252. {
  2253. S32 res = LLViewerObject::setTEMediaFlags(te, media_flags);
  2254. if (res)
  2255. {
  2256. gPipeline.markTextured(mDrawable);
  2257. mFaceMappingChanged = true;
  2258. }
  2259. return res;
  2260. }
  2261. //virtual
  2262. S32 LLVOVolume::setTEGlow(U8 te, F32 glow)
  2263. {
  2264. S32 res = LLViewerObject::setTEGlow(te, glow);
  2265. if (res)
  2266. {
  2267. if (mDrawable.notNull())
  2268. {
  2269. gPipeline.markTextured(mDrawable);
  2270. shrinkWrap();
  2271. }
  2272. mFaceMappingChanged = true;
  2273. }
  2274. return res;
  2275. }
  2276. //static
  2277. void LLVOVolume::setTEMaterialParamsCallbackTE(const LLUUID& objid,
  2278. const LLMaterialID& matidp,
  2279. const LLMaterialPtr paramsp,
  2280. U32 te)
  2281. {
  2282. LLVOVolume* volp = (LLVOVolume*)gObjectList.findObject(objid);
  2283. if (!volp) return; // stale callback for removed object
  2284. if (te >= volp->getNumTEs())
  2285. {
  2286. llwarns << "Got a callback for materialid " << matidp.asString()
  2287. << " with an out of range face number: " << te << ". Ignoring."
  2288. << llendl;
  2289. return;
  2290. }
  2291. LLTextureEntry* tep = volp->getTE(te);
  2292. if (tep && tep->getMaterialID() == matidp)
  2293. {
  2294. LL_DEBUGS("Materials") << "Applying materialid " << matidp.asString()
  2295. << " to face " << te << LL_ENDL;
  2296. volp->setTEMaterialParams(te, paramsp);
  2297. }
  2298. }
  2299. //virtual
  2300. S32 LLVOVolume::setTEMaterialID(U8 te, const LLMaterialID& matidp)
  2301. {
  2302. S32 res = LLViewerObject::setTEMaterialID(te, matidp);
  2303. LL_DEBUGS("Materials") << "te = "<< (S32)te << " - materialid = "
  2304. << matidp.asString() << " - result: " << res;
  2305. bool sel = gSelectMgr.getSelection()->contains(this, te);
  2306. LL_CONT << (sel ? "," : ", not") << " selected" << LL_ENDL;
  2307. if (res == TEM_CHANGE_NONE)
  2308. {
  2309. return res;
  2310. }
  2311. LLViewerRegion* regionp = getRegion();
  2312. if (!regionp)
  2313. {
  2314. return res;
  2315. }
  2316. LLMaterialMgr* matmgrp = LLMaterialMgr::getInstance();
  2317. matmgrp->getTE(regionp->getRegionID(), matidp, te,
  2318. boost::bind(&LLVOVolume::setTEMaterialParamsCallbackTE,
  2319. getID(), _1, _2, _3));
  2320. setChanged(ALL_CHANGED);
  2321. if (mDrawable.notNull())
  2322. {
  2323. gPipeline.markTextured(mDrawable);
  2324. gPipeline.markRebuild(mDrawable);
  2325. }
  2326. mFaceMappingChanged = true;
  2327. return res;
  2328. }
  2329. #if LL_FIX_MAT_TRANSPARENCY
  2330. // Here, we have confirmation about texture creation, check our wait-list and
  2331. // make changes, or return false
  2332. bool LLVOVolume::notifyAboutCreatingTexture(LLViewerTexture* texp)
  2333. {
  2334. std::pair<mmap_uuid_map_t::iterator, mmap_uuid_map_t::iterator> range =
  2335. mWaitingTextureInfo.equal_range(texp->getID());
  2336. typedef fast_hmap<U8, LLMaterialPtr> map_te_material_t;
  2337. map_te_material_t new_material;
  2338. for (mmap_uuid_map_t::iterator it = range.first;
  2339. it != range.second; ++it)
  2340. {
  2341. LLMaterialPtr cur_matp = getTEMaterialParams(it->second.te);
  2342. if (cur_matp.isNull()) continue;
  2343. // Here we have interest in DIFFUSE_MAP only !
  2344. if (it->second.map == LLRender::DIFFUSE_MAP &&
  2345. texp->getPrimaryFormat() != GL_RGBA)
  2346. {
  2347. // Let's check the diffuse mode
  2348. U8 mode = cur_matp->getDiffuseAlphaMode();
  2349. if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND ||
  2350. mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE ||
  2351. mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
  2352. {
  2353. // We have non 32 bits texture with DIFFUSE_ALPHA_MODE_* so set
  2354. // mode to DIFFUSE_ALPHA_MODE_NONE instead
  2355. LLMaterialPtr matp = NULL;
  2356. map_te_material_t::iterator it2 =
  2357. new_material.find(it->second.te);
  2358. if (it2 == new_material.end())
  2359. {
  2360. matp = new LLMaterial(cur_matp->asLLSD());
  2361. new_material.emplace(it->second.te, matp);
  2362. }
  2363. else
  2364. {
  2365. matp = it2->second;
  2366. }
  2367. matp->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
  2368. }
  2369. }
  2370. }
  2371. if (new_material.empty() || !getRegion())
  2372. {
  2373. // Clear the wait-list
  2374. mWaitingTextureInfo.erase(range.first, range.second);
  2375. return false;
  2376. }
  2377. // Setup new materials
  2378. const LLUUID& regiond_id = getRegion()->getRegionID();
  2379. LLMaterialMgr* matmgrp = LLMaterialMgr::getInstance();
  2380. for (map_te_material_t::const_iterator it = new_material.begin(),
  2381. end = new_material.end();
  2382. it != end; ++it)
  2383. {
  2384. matmgrp->setLocalMaterial(regiond_id, it->second);
  2385. LLViewerObject::setTEMaterialParams(it->first, it->second);
  2386. }
  2387. // Clear the wait-list
  2388. mWaitingTextureInfo.erase(range.first, range.second);
  2389. return true;
  2390. }
  2391. // Here, if we wait information about the texture and it is missing, then
  2392. // depending on the texture map (diffuse, normal, or specular), we make changes
  2393. // in material and confirm it. If not return false.
  2394. bool LLVOVolume::notifyAboutMissingAsset(LLViewerTexture* texp)
  2395. {
  2396. std::pair<mmap_uuid_map_t::iterator, mmap_uuid_map_t::iterator> range =
  2397. mWaitingTextureInfo.equal_range(texp->getID());
  2398. if (range.first == range.second)
  2399. {
  2400. return false;
  2401. }
  2402. typedef fast_hmap<U8, LLMaterialPtr> map_te_material_t;
  2403. map_te_material_t new_material;
  2404. for (mmap_uuid_map_t::iterator it = range.first;
  2405. it != range.second; ++it)
  2406. {
  2407. LLMaterialPtr cur_matp = getTEMaterialParams(it->second.te);
  2408. if (cur_matp.isNull()) continue;
  2409. switch (it->second.map)
  2410. {
  2411. case LLRender::DIFFUSE_MAP:
  2412. {
  2413. if (cur_matp->getDiffuseAlphaMode() !=
  2414. LLMaterial::DIFFUSE_ALPHA_MODE_NONE)
  2415. {
  2416. // Switch to DIFFUSE_ALPHA_MODE_NONE
  2417. LLMaterialPtr matp;
  2418. map_te_material_t::iterator it2 =
  2419. new_material.find(it->second.te);
  2420. if (it2 == new_material.end())
  2421. {
  2422. matp = new LLMaterial(cur_matp->asLLSD());
  2423. new_material.emplace(it->second.te, matp);
  2424. }
  2425. else
  2426. {
  2427. matp = it2->second;
  2428. }
  2429. matp->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
  2430. }
  2431. break;
  2432. }
  2433. case LLRender::NORMAL_MAP:
  2434. {
  2435. // Reset material texture id
  2436. LLMaterialPtr matp;
  2437. map_te_material_t::iterator it2 =
  2438. new_material.find(it->second.te);
  2439. if (it2 == new_material.end())
  2440. {
  2441. matp = new LLMaterial(cur_matp->asLLSD());
  2442. new_material.emplace(it->second.te, matp);
  2443. }
  2444. else
  2445. {
  2446. matp = it2->second;
  2447. }
  2448. matp->setNormalID(LLUUID::null);
  2449. break;
  2450. }
  2451. case LLRender::SPECULAR_MAP:
  2452. {
  2453. // Reset material texture id
  2454. LLMaterialPtr matp;
  2455. map_te_material_t::iterator it2 =
  2456. new_material.find(it->second.te);
  2457. if (it2 == new_material.end())
  2458. {
  2459. matp = new LLMaterial(cur_matp->asLLSD());
  2460. new_material.emplace(it->second.te, matp);
  2461. }
  2462. else
  2463. {
  2464. matp = it2->second;
  2465. }
  2466. matp->setSpecularID(LLUUID::null);
  2467. }
  2468. default:
  2469. break;
  2470. }
  2471. }
  2472. if (new_material.empty() || !getRegion())
  2473. {
  2474. // Clear the wait-list
  2475. mWaitingTextureInfo.erase(range.first, range.second);
  2476. return false;
  2477. }
  2478. // Setup new materials
  2479. const LLUUID& regiond_id = getRegion()->getRegionID();
  2480. LLMaterialMgr* matmgrp = LLMaterialMgr::getInstance();
  2481. for (map_te_material_t::const_iterator it = new_material.begin(),
  2482. end = new_material.end();
  2483. it != end; ++it)
  2484. {
  2485. matmgrp->setLocalMaterial(regiond_id, it->second);
  2486. LLViewerObject::setTEMaterialParams(it->first, it->second);
  2487. }
  2488. // Clear the wait-list
  2489. mWaitingTextureInfo.erase(range.first, range.second);
  2490. return true;
  2491. }
  2492. #endif
  2493. //virtual
  2494. S32 LLVOVolume::setTEMaterialParams(U8 te, const LLMaterialPtr paramsp)
  2495. {
  2496. #if LL_FIX_MAT_TRANSPARENCY
  2497. LLMaterialPtr matp = const_cast<LLMaterialPtr&>(paramsp);
  2498. if (paramsp)
  2499. {
  2500. LLMaterialPtr new_matp = NULL;
  2501. LLViewerTexture* img_diffuse = getTEImage(te);
  2502. if (img_diffuse)
  2503. {
  2504. if (img_diffuse->getPrimaryFormat() == 0 &&
  2505. !img_diffuse->isMissingAsset())
  2506. {
  2507. // Texture information is missing, wait for it
  2508. mWaitingTextureInfo.emplace(img_diffuse->getID(),
  2509. material_info(LLRender::DIFFUSE_MAP,
  2510. te));
  2511. }
  2512. else
  2513. {
  2514. bool set_diffuse_none = img_diffuse->isMissingAsset();
  2515. if (!set_diffuse_none)
  2516. {
  2517. U8 mode = paramsp->getDiffuseAlphaMode();
  2518. if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND ||
  2519. mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK ||
  2520. mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE)
  2521. {
  2522. LLTextureEntry* tep = getTE(te);
  2523. bool baked = tep &&
  2524. LLAvatarAppearanceDictionary::isBakedImageId(tep->getID());
  2525. if (!baked &&
  2526. img_diffuse->getPrimaryFormat() != GL_RGBA)
  2527. {
  2528. set_diffuse_none = true;
  2529. }
  2530. }
  2531. }
  2532. if (set_diffuse_none)
  2533. {
  2534. // Substitute this material with DIFFUSE_ALPHA_MODE_NONE
  2535. new_matp = new LLMaterial(paramsp->asLLSD());
  2536. new_matp->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
  2537. }
  2538. }
  2539. }
  2540. else
  2541. {
  2542. llwarns_sparse << "Missing diffuse channel for material !" << llendl;
  2543. llassert(false);
  2544. }
  2545. const LLUUID& normal_id = paramsp->getNormalID();
  2546. if (normal_id.notNull())
  2547. {
  2548. LLViewerTexture* img_normal = getTENormalMap(te);
  2549. if (img_normal && img_normal->isMissingAsset() &&
  2550. img_normal->getID() == normal_id)
  2551. {
  2552. if (!new_matp)
  2553. {
  2554. new_matp = new LLMaterial(paramsp->asLLSD());
  2555. }
  2556. new_matp->setNormalID(LLUUID::null);
  2557. }
  2558. else if (!img_normal || img_normal->getPrimaryFormat() == 0)
  2559. {
  2560. // Texture information is missing, wait for it
  2561. mWaitingTextureInfo.emplace(normal_id,
  2562. material_info(LLRender::NORMAL_MAP,
  2563. te));
  2564. }
  2565. }
  2566. const LLUUID& specular_id = paramsp->getSpecularID();
  2567. if (specular_id.notNull())
  2568. {
  2569. LLViewerTexture* img_specular = getTESpecularMap(te);
  2570. if (img_specular && img_specular->isMissingAsset() &&
  2571. img_specular->getID() == specular_id)
  2572. {
  2573. if (!new_matp)
  2574. {
  2575. new_matp = new LLMaterial(paramsp->asLLSD());
  2576. }
  2577. new_matp->setSpecularID(LLUUID::null);
  2578. }
  2579. else if (!img_specular || img_specular->getPrimaryFormat() == 0)
  2580. {
  2581. // Texture information is missing, wait for it
  2582. mWaitingTextureInfo.emplace(specular_id,
  2583. material_info(LLRender::SPECULAR_MAP,
  2584. te));
  2585. }
  2586. }
  2587. if (new_matp && getRegion())
  2588. {
  2589. matp = new_matp;
  2590. const LLUUID& regiond_id = getRegion()->getRegionID();
  2591. LLMaterialMgr::getInstance()->setLocalMaterial(regiond_id, matp);
  2592. }
  2593. }
  2594. S32 res = LLViewerObject::setTEMaterialParams(te, matp);
  2595. LL_DEBUGS("Materials") << "te = "<< (S32)te << ", material = "
  2596. << (matp ? matp->asLLSD() : LLSD("null"))
  2597. << ", res = " << res;
  2598. #else
  2599. S32 res = LLViewerObject::setTEMaterialParams(te, paramsp);
  2600. LL_DEBUGS("Materials") << "te = "<< (S32)te << ", material = "
  2601. << (paramsp ? paramsp->asLLSD() : LLSD("null"))
  2602. << ", res = " << res;
  2603. #endif
  2604. bool sel = gSelectMgr.getSelection()->contains(this, te);
  2605. LL_CONT << (sel ? "," : ", not") << " selected" << LL_ENDL;
  2606. setChanged(ALL_CHANGED);
  2607. if (mDrawable.notNull())
  2608. {
  2609. gPipeline.markTextured(mDrawable);
  2610. gPipeline.markRebuild(mDrawable);
  2611. }
  2612. mFaceMappingChanged = true;
  2613. return TEM_CHANGE_TEXTURE;
  2614. }
  2615. //virtual
  2616. S32 LLVOVolume::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* matp)
  2617. {
  2618. S32 retval = LLViewerObject::setTEGLTFMaterialOverride(te, matp);
  2619. if (retval == TEM_CHANGE_TEXTURE)
  2620. {
  2621. if (mDrawable.notNull())
  2622. {
  2623. gPipeline.markTextured(mDrawable);
  2624. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
  2625. }
  2626. mFaceMappingChanged = true;
  2627. }
  2628. return retval;
  2629. }
  2630. //virtual
  2631. S32 LLVOVolume::setTEScale(U8 te, F32 s, F32 t)
  2632. {
  2633. S32 res = LLViewerObject::setTEScale(te, s, t);
  2634. if (res)
  2635. {
  2636. gPipeline.markTextured(mDrawable);
  2637. mFaceMappingChanged = true;
  2638. }
  2639. return res;
  2640. }
  2641. //virtual
  2642. S32 LLVOVolume::setTEScaleS(U8 te, F32 s)
  2643. {
  2644. S32 res = LLViewerObject::setTEScaleS(te, s);
  2645. if (res)
  2646. {
  2647. gPipeline.markTextured(mDrawable);
  2648. mFaceMappingChanged = true;
  2649. }
  2650. return res;
  2651. }
  2652. //virtual
  2653. S32 LLVOVolume::setTEScaleT(U8 te, F32 t)
  2654. {
  2655. S32 res = LLViewerObject::setTEScaleT(te, t);
  2656. if (res)
  2657. {
  2658. gPipeline.markTextured(mDrawable);
  2659. mFaceMappingChanged = true;
  2660. }
  2661. return res;
  2662. }
  2663. bool LLVOVolume::hasMedia() const
  2664. {
  2665. for (U8 i = 0, count = getNumTEs(); i < count; ++i)
  2666. {
  2667. const LLTextureEntry* tep = getTE(i);
  2668. if (tep && tep->hasMedia())
  2669. {
  2670. return true;
  2671. }
  2672. }
  2673. return false;
  2674. }
  2675. LLVector3 LLVOVolume::getApproximateFaceNormal(U8 face_id)
  2676. {
  2677. LLVolume* volp = getVolume();
  2678. if (volp && face_id < volp->getNumVolumeFaces())
  2679. {
  2680. LLVector4a result;
  2681. // Necessary since LLVector4a members are not initialized on creation
  2682. result.clear();
  2683. const LLVolumeFace& face = volp->getVolumeFace(face_id);
  2684. for (S32 i = 0, count = face.mNumVertices; i < count; ++i)
  2685. {
  2686. result.add(face.mNormals[i]);
  2687. }
  2688. LLVector3 ret(result.getF32ptr());
  2689. ret = volumeDirectionToAgent(ret);
  2690. ret.normalize();
  2691. return ret;
  2692. }
  2693. return LLVector3();
  2694. }
  2695. void LLVOVolume::requestMediaDataUpdate(bool is_new)
  2696. {
  2697. if (sObjectMediaClient)
  2698. {
  2699. sObjectMediaClient->fetchMedia(new LLMediaDataClientObjectImpl(this,
  2700. is_new));
  2701. }
  2702. else
  2703. {
  2704. // Store this volume Id, in case the user decides to enable media. HB
  2705. sObjectMediaPending.emplace(mID);
  2706. }
  2707. }
  2708. bool LLVOVolume::isMediaDataBeingFetched() const
  2709. {
  2710. if (!sObjectMediaClient)
  2711. {
  2712. return false;
  2713. }
  2714. // It is OK to const_cast this away since this is just a wrapper class that
  2715. // is only going to do a lookup.
  2716. LLVOVolume* self = const_cast<LLVOVolume*>(this);
  2717. return sObjectMediaClient->isInQueue(new LLMediaDataClientObjectImpl(self,
  2718. false));
  2719. }
  2720. void LLVOVolume::cleanUpMediaImpls()
  2721. {
  2722. // Iterate through our TEs and remove any Impls that are no longer used
  2723. for (U8 i = 0, count = getNumTEs(); i < count; ++i)
  2724. {
  2725. const LLTextureEntry* tep = getTE(i);
  2726. if (tep && !tep->hasMedia())
  2727. {
  2728. // Delete the media implement !
  2729. removeMediaImpl(i);
  2730. }
  2731. }
  2732. }
  2733. // media_data_array is an array of media entry maps, media_version is the
  2734. // version string in the response.
  2735. void LLVOVolume::updateObjectMediaData(const LLSD& media_data_array,
  2736. const std::string& media_version)
  2737. {
  2738. U32 fetched_version =
  2739. LLTextureEntry::getVersionFromMediaVersionString(media_version);
  2740. // Only update it if it is newer !
  2741. if ((S32)fetched_version <= mLastFetchedMediaVersion)
  2742. {
  2743. return;
  2744. }
  2745. mLastFetchedMediaVersion = fetched_version;
  2746. LLSD::array_const_iterator iter = media_data_array.beginArray();
  2747. LLSD::array_const_iterator end = media_data_array.endArray();
  2748. U8 tex_idx = 0;
  2749. for ( ; iter != end; ++iter, ++tex_idx)
  2750. {
  2751. syncMediaData(tex_idx, *iter, false, false);
  2752. }
  2753. }
  2754. void LLVOVolume::syncMediaData(S32 tex_idx, const LLSD& media_data,
  2755. bool merge, bool ignore_agent)
  2756. {
  2757. if (mDead)
  2758. {
  2759. // If the object has been marked dead, do not process media updates.
  2760. return;
  2761. }
  2762. LLTextureEntry* tep = getTE(tex_idx);
  2763. if (!tep)
  2764. {
  2765. return;
  2766. }
  2767. LL_DEBUGS("MediaOnAPrim") << "BEFORE: tex_idx = " << tex_idx
  2768. << " hasMedia = " << tep->hasMedia() << " : ";
  2769. if (tep->getMediaData())
  2770. {
  2771. LL_CONT << ll_pretty_print_sd(tep->getMediaData()->asLLSD());
  2772. }
  2773. else
  2774. {
  2775. LL_CONT << "NULL MEDIA DATA";
  2776. }
  2777. LL_CONT << LL_ENDL;
  2778. std::string previous_url;
  2779. LLMediaEntry* mep = tep->getMediaData();
  2780. if (mep)
  2781. {
  2782. // Save the "current url" from before the update so we can tell if
  2783. // it changes.
  2784. previous_url = mep->getCurrentURL();
  2785. }
  2786. if (merge)
  2787. {
  2788. tep->mergeIntoMediaData(media_data);
  2789. }
  2790. else
  2791. {
  2792. // XXX Question: what if the media data is undefined LLSD, but the
  2793. // update we got above said that we have media flags?? Here we clobber
  2794. // that, assuming the data from the service is more up-to-date.
  2795. tep->updateMediaData(media_data);
  2796. }
  2797. mep = tep->getMediaData();
  2798. if (mep)
  2799. {
  2800. bool update_from_self = !ignore_agent &&
  2801. LLTextureEntry::getAgentIDFromMediaVersionString(getMediaURL()) == gAgentID;
  2802. viewer_media_t media_impl =
  2803. LLViewerMedia::updateMediaImpl(mep, previous_url, update_from_self);
  2804. addMediaImpl(media_impl, tex_idx);
  2805. }
  2806. else
  2807. {
  2808. removeMediaImpl(tex_idx);
  2809. }
  2810. LL_DEBUGS("MediaOnAPrim") << "AFTER: tex_idx = " << tex_idx
  2811. << " hasMedia = " << tep->hasMedia() << " : ";
  2812. if (tep->getMediaData())
  2813. {
  2814. LL_CONT << ll_pretty_print_sd(tep->getMediaData()->asLLSD());
  2815. }
  2816. else
  2817. {
  2818. LL_CONT << "NULL MEDIA DATA";
  2819. }
  2820. LL_CONT << LL_ENDL;
  2821. }
  2822. void LLVOVolume::mediaNavigateBounceBack(U8 tex_idx)
  2823. {
  2824. // Find the media entry for this navigate
  2825. const LLMediaEntry* mep = NULL;
  2826. viewer_media_t impl = getMediaImpl(tex_idx);
  2827. LLTextureEntry* tep = getTE(tex_idx);
  2828. if (tep)
  2829. {
  2830. mep = tep->getMediaData();
  2831. }
  2832. if (mep && impl)
  2833. {
  2834. std::string url = mep->getCurrentURL();
  2835. // Look for a ":", if not there, assume "http://"
  2836. if (!url.empty() && url.find(':') == std::string::npos)
  2837. {
  2838. url = "http://" + url;
  2839. }
  2840. // If the url we are trying to "bounce back" to either empty or not
  2841. // allowed by the whitelist, try the home url. If *that* does not work,
  2842. // set the media as failed and unload it
  2843. if (url.empty() || !mep->checkCandidateUrl(url))
  2844. {
  2845. url = mep->getHomeURL();
  2846. // Look for a ":", if not there, assume "http://"
  2847. if (!url.empty() && url.find(':') == std::string::npos)
  2848. {
  2849. url = "http://" + url;
  2850. }
  2851. }
  2852. if (url.empty() || !mep->checkCandidateUrl(url))
  2853. {
  2854. // The url to navigate back to is not good, and we have nowhere
  2855. // else to go.
  2856. llwarns << "FAILED to bounce back URL \"" << url
  2857. << "\" -- unloading impl" << llendl;
  2858. impl->setMediaFailed(true);
  2859. }
  2860. else if (impl->getCurrentMediaURL() != url)
  2861. {
  2862. // Okay, navigate now
  2863. llinfos << "bouncing back to URL: " << url << llendl;
  2864. impl->navigateTo(url, "", false, true);
  2865. }
  2866. }
  2867. }
  2868. bool LLVOVolume::hasMediaPermission(const LLMediaEntry* media_entry,
  2869. MediaPermType perm_type)
  2870. {
  2871. // NOTE: This logic ALMOST duplicates the logic in the server (in
  2872. // particular, in llmediaservice.cpp).
  2873. if (!media_entry) return false; // XXX should we assert here?
  2874. // The agent has permissions if:
  2875. // - world permissions are on, or
  2876. // - group permissions are on, and agent_id is in the group, or
  2877. // - agent permissions are on, and agent_id is the owner
  2878. // *NOTE: We *used* to check for modify permissions here (i.e. permissions
  2879. // were granted if permModify() was true). However, this doesn't make
  2880. // sense in the viewer: we do not want to show controls or allow
  2881. // interaction if the author has deemed it so. See DEV-42115.
  2882. U8 media_perms = perm_type ==
  2883. MEDIA_PERM_INTERACT ? media_entry->getPermsInteract()
  2884. : media_entry->getPermsControl();
  2885. // World permissions
  2886. if ((media_perms & LLMediaEntry::PERM_ANYONE) != 0)
  2887. {
  2888. return true;
  2889. }
  2890. // Group permissions
  2891. else if ((media_perms & LLMediaEntry::PERM_GROUP) != 0)
  2892. {
  2893. LLPermissions* obj_perm;
  2894. obj_perm = gSelectMgr.findObjectPermissions(this);
  2895. if (obj_perm && gAgent.isInGroup(obj_perm->getGroup()))
  2896. {
  2897. return true;
  2898. }
  2899. }
  2900. // Owner permissions
  2901. else if ((media_perms & LLMediaEntry::PERM_OWNER) != 0 && permYouOwner())
  2902. {
  2903. return true;
  2904. }
  2905. return false;
  2906. }
  2907. void LLVOVolume::mediaNavigated(LLViewerMediaImpl* impl,
  2908. LLPluginClassMedia* plugin,
  2909. std::string new_location)
  2910. {
  2911. bool block_navigation = false;
  2912. // FIXME: if/when we allow the same media impl to be used by multiple
  2913. // faces, the logic here will need to be fixed to deal with multiple face
  2914. // indices.
  2915. S32 face_index = getFaceIndexWithMediaImpl(impl, -1);
  2916. // Find the media entry for this navigate
  2917. LLMediaEntry* mep = NULL;
  2918. LLTextureEntry* tep = getTE(face_index);
  2919. if (tep)
  2920. {
  2921. mep = tep->getMediaData();
  2922. }
  2923. if (mep)
  2924. {
  2925. if (!mep->checkCandidateUrl(new_location))
  2926. {
  2927. block_navigation = true;
  2928. }
  2929. if (!block_navigation && !hasMediaPermission(mep, MEDIA_PERM_INTERACT))
  2930. {
  2931. block_navigation = true;
  2932. }
  2933. }
  2934. else
  2935. {
  2936. llwarns_sparse << "Could not find media entry" << llendl;
  2937. }
  2938. if (block_navigation)
  2939. {
  2940. llinfos << "blocking navigate to URI " << new_location << llendl;
  2941. // "bounce back" to the current URL from the media entry
  2942. mediaNavigateBounceBack(face_index);
  2943. }
  2944. else if (sObjectMediaNavigateClient)
  2945. {
  2946. LL_DEBUGS("MediaOnAPrim") << "broadcasting navigate with URI "
  2947. << new_location << LL_ENDL;
  2948. sObjectMediaNavigateClient->navigate(new LLMediaDataClientObjectImpl(this,
  2949. false),
  2950. face_index, new_location);
  2951. }
  2952. }
  2953. void LLVOVolume::mediaEvent(LLViewerMediaImpl* impl,
  2954. LLPluginClassMedia* plugin,
  2955. LLViewerMediaObserver::EMediaEvent event)
  2956. {
  2957. switch (event)
  2958. {
  2959. case LLViewerMediaObserver::MEDIA_EVENT_LOCATION_CHANGED:
  2960. {
  2961. switch (impl->getNavState())
  2962. {
  2963. case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED:
  2964. // This is the first location changed event after the start
  2965. // of a non-server-directed nav. It may need to be
  2966. // broadcast or bounced back.
  2967. mediaNavigated(impl, plugin, plugin->getLocation());
  2968. break;
  2969. case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED_SPURIOUS:
  2970. // This navigate didn't change the current URL.
  2971. LL_DEBUGS("MediaOnAPrim") << "NOT broadcasting navigate (spurious)"
  2972. << LL_ENDL;
  2973. break;
  2974. case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_FIRST_LOCATION_CHANGED:
  2975. // This is the first location changed event after the start
  2976. // of a server-directed nav. do not broadcast it.
  2977. llinfos << "NOT broadcasting navigate (server-directed)"
  2978. << llendl;
  2979. break;
  2980. default:
  2981. // This is a subsequent location-changed due to a redirect.
  2982. // do not broadcast.
  2983. llinfos << "NOT broadcasting navigate (redirect)"
  2984. << llendl;
  2985. }
  2986. break;
  2987. }
  2988. case LLViewerMediaObserver::MEDIA_EVENT_NAVIGATE_COMPLETE:
  2989. {
  2990. switch (impl->getNavState())
  2991. {
  2992. case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED:
  2993. // This is the first location changed event after the start
  2994. // of a non-server-directed nav. It may need to be
  2995. // broadcast or bounced back.
  2996. mediaNavigated(impl, plugin, plugin->getNavigateURI());
  2997. break;
  2998. case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED_SPURIOUS:
  2999. // This navigate didn't change the current URL.
  3000. LL_DEBUGS("MediaOnAPrim") << "NOT broadcasting navigate (spurious)"
  3001. << LL_ENDL;
  3002. break;
  3003. case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_COMPLETE_BEFORE_LOCATION_CHANGED:
  3004. // This is the the navigate complete event from a
  3005. // server-directed nav. do not broadcast it.
  3006. llinfos << "NOT broadcasting navigate (server-directed)"
  3007. << llendl;
  3008. break;
  3009. default:
  3010. // For all other states, the navigate should have been
  3011. // handled by LOCATION_CHANGED events already.
  3012. break;
  3013. }
  3014. break;
  3015. }
  3016. default:
  3017. break;
  3018. }
  3019. }
  3020. void LLVOVolume::sendMediaDataUpdate()
  3021. {
  3022. if (!sObjectMediaClient)
  3023. {
  3024. return;
  3025. }
  3026. sObjectMediaClient->updateMedia(new LLMediaDataClientObjectImpl(this,
  3027. false));
  3028. }
  3029. void LLVOVolume::removeMediaImpl(S32 tex_idx)
  3030. {
  3031. S32 media_count = mMediaImplList.size();
  3032. if (tex_idx >= media_count || mMediaImplList[tex_idx].isNull())
  3033. {
  3034. return;
  3035. }
  3036. // Make the face referencing to mMediaImplList[tex_idx] to point back to
  3037. // the old texture.
  3038. if (mDrawable.notNull() && tex_idx < mDrawable->getNumFaces())
  3039. {
  3040. LLFace* facep = mDrawable->getFace(tex_idx);
  3041. if (facep)
  3042. {
  3043. const LLUUID& id = mMediaImplList[tex_idx]->getMediaTextureID();
  3044. LLViewerMediaTexture* media_tex =
  3045. LLViewerTextureManager::findMediaTexture(id);
  3046. if (media_tex)
  3047. {
  3048. media_tex->removeMediaFromFace(facep);
  3049. }
  3050. }
  3051. }
  3052. // Check if some other face(s) of this object reference(s)to this media
  3053. // impl.
  3054. S32 i;
  3055. for (i = 0; i < media_count; ++i)
  3056. {
  3057. if (i != tex_idx && mMediaImplList[i] == mMediaImplList[tex_idx])
  3058. {
  3059. break;
  3060. }
  3061. }
  3062. if (i == media_count) // This object does not need this media impl.
  3063. {
  3064. mMediaImplList[tex_idx]->removeObject(this);
  3065. }
  3066. mMediaImplList[tex_idx] = NULL;
  3067. }
  3068. void LLVOVolume::addMediaImpl(LLViewerMediaImpl* media_implp, S32 tex_idx)
  3069. {
  3070. if ((S32)mMediaImplList.size() < tex_idx + 1)
  3071. {
  3072. mMediaImplList.resize(tex_idx + 1);
  3073. }
  3074. if (mMediaImplList[tex_idx].notNull())
  3075. {
  3076. if (mMediaImplList[tex_idx] == media_implp)
  3077. {
  3078. return;
  3079. }
  3080. removeMediaImpl(tex_idx);
  3081. }
  3082. mMediaImplList[tex_idx] = media_implp;
  3083. media_implp->addObject(this);
  3084. // Add the face to show the media if it is in playing
  3085. if (mDrawable.notNull())
  3086. {
  3087. LLFace* facep = NULL;
  3088. if (tex_idx < mDrawable->getNumFaces())
  3089. {
  3090. facep = mDrawable->getFace(tex_idx);
  3091. }
  3092. if (facep)
  3093. {
  3094. LLViewerMediaTexture* media_texp =
  3095. LLViewerTextureManager::findMediaTexture(mMediaImplList[tex_idx]->getMediaTextureID());
  3096. if (media_texp)
  3097. {
  3098. media_texp->addMediaToFace(facep);
  3099. }
  3100. }
  3101. else // The face is not available now, start media on this face later.
  3102. {
  3103. media_implp->setUpdated(true);
  3104. }
  3105. }
  3106. }
  3107. viewer_media_t LLVOVolume::getMediaImpl(U8 face_id) const
  3108. {
  3109. if (face_id < mMediaImplList.size())
  3110. {
  3111. return mMediaImplList[face_id];
  3112. }
  3113. return NULL;
  3114. }
  3115. F64 LLVOVolume::getTotalMediaInterest() const
  3116. {
  3117. // If this object is currently focused, this object has "high" interest
  3118. if (LLViewerMediaFocus::getInstance()->getFocusedObjectID() == getID())
  3119. {
  3120. return F64_MAX;
  3121. }
  3122. F64 interest = -1.0; // means not interested;
  3123. // If this object is selected, this object has "high" interest, but since
  3124. // there can be more than one, we still add in calculated impl interest
  3125. // XXX Sadly, 'contains()' doesn't take a const :(
  3126. if (gSelectMgr.getSelection()->contains(const_cast<LLVOVolume*>(this)))
  3127. {
  3128. interest = F64_MAX * 0.5;
  3129. }
  3130. for (S32 i = 0, end = getNumTEs(); i < end; ++i)
  3131. {
  3132. const viewer_media_t& impl = getMediaImpl(i);
  3133. if (impl.notNull())
  3134. {
  3135. if (interest == -1.0)
  3136. {
  3137. interest = 0.0;
  3138. }
  3139. interest += impl->getInterest();
  3140. }
  3141. }
  3142. return interest;
  3143. }
  3144. S32 LLVOVolume::getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl,
  3145. S32 start_face_id)
  3146. {
  3147. for (S32 face_id = start_face_id + 1, end = mMediaImplList.size();
  3148. face_id < end; ++face_id)
  3149. {
  3150. if (mMediaImplList[face_id] == media_impl)
  3151. {
  3152. return face_id;
  3153. }
  3154. }
  3155. return -1;
  3156. }
  3157. void LLVOVolume::setLightTextureID(const LLUUID& id)
  3158. {
  3159. // Same as mLightTexture, but initializes if necessary:
  3160. LLViewerTexture* old_texturep = getLightTexture();
  3161. if (id.notNull())
  3162. {
  3163. if (!hasLightTexture())
  3164. {
  3165. setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, true,
  3166. true);
  3167. }
  3168. else if (old_texturep)
  3169. {
  3170. old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
  3171. }
  3172. LLLightImageParams* param_block = getLightImageParams();
  3173. if (param_block && param_block->getLightTexture() != id)
  3174. {
  3175. param_block->setLightTexture(id);
  3176. parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
  3177. }
  3178. // New light texture
  3179. LLViewerTexture* new_texturep = getLightTexture();
  3180. if (new_texturep)
  3181. {
  3182. new_texturep->addVolume(LLRender::LIGHT_TEX, this);
  3183. }
  3184. }
  3185. else if (hasLightTexture())
  3186. {
  3187. if (old_texturep)
  3188. {
  3189. old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
  3190. }
  3191. setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, false, true);
  3192. parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
  3193. mLightTexture = NULL;
  3194. }
  3195. }
  3196. void LLVOVolume::setSpotLightParams(const LLVector3& params)
  3197. {
  3198. LLLightImageParams* param_block = getLightImageParams();
  3199. if (param_block && param_block->getParams() != params)
  3200. {
  3201. param_block->setParams(params);
  3202. parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
  3203. }
  3204. }
  3205. void LLVOVolume::setIsLight(bool is_light)
  3206. {
  3207. if (is_light != getIsLight())
  3208. {
  3209. if (is_light)
  3210. {
  3211. setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, true, true);
  3212. // Add it to the pipeline light set.
  3213. gPipeline.setLight(mDrawable, true);
  3214. }
  3215. else
  3216. {
  3217. setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, false, true);
  3218. // Not a light. Remove it from the pipeline light set.
  3219. gPipeline.setLight(mDrawable, false);
  3220. }
  3221. }
  3222. }
  3223. void LLVOVolume::setLightLinearColor(const LLColor3& color)
  3224. {
  3225. LLLightParams* param_block = getLightParams();
  3226. if (!param_block || param_block->getLinearColor() == color)
  3227. {
  3228. return;
  3229. }
  3230. param_block->setLinearColor(LLColor4(color,
  3231. param_block->getLinearColor().mV[3]));
  3232. parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
  3233. gPipeline.markTextured(mDrawable);
  3234. mFaceMappingChanged = true;
  3235. }
  3236. void LLVOVolume::setLightIntensity(F32 intensity)
  3237. {
  3238. LLLightParams* param_block = getLightParams();
  3239. if (!param_block || param_block->getLinearColor().mV[3] == intensity)
  3240. {
  3241. return;
  3242. }
  3243. param_block->setLinearColor(LLColor4(LLColor3(param_block->getLinearColor()),
  3244. intensity));
  3245. parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
  3246. }
  3247. void LLVOVolume::setLightRadius(F32 radius)
  3248. {
  3249. LLLightParams* param_block = getLightParams();
  3250. if (param_block && param_block->getRadius() != radius)
  3251. {
  3252. param_block->setRadius(radius);
  3253. parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
  3254. }
  3255. }
  3256. void LLVOVolume::setLightFalloff(F32 falloff)
  3257. {
  3258. LLLightParams* param_block = getLightParams();
  3259. if (param_block && param_block->getFalloff() != falloff)
  3260. {
  3261. param_block->setFalloff(falloff);
  3262. parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
  3263. }
  3264. }
  3265. void LLVOVolume::setLightCutoff(F32 cutoff)
  3266. {
  3267. LLLightParams* param_block = getLightParams();
  3268. if (param_block && param_block->getCutoff() != cutoff)
  3269. {
  3270. param_block->setCutoff(cutoff);
  3271. parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
  3272. }
  3273. }
  3274. bool LLVOVolume::getIsLight() const
  3275. {
  3276. return getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT);
  3277. }
  3278. LLColor3 LLVOVolume::getLightLinearBaseColor() const
  3279. {
  3280. const LLLightParams* param_block = getLightParams();
  3281. return param_block ? LLColor3(param_block->getLinearColor())
  3282. : LLColor3::white;
  3283. }
  3284. LLColor3 LLVOVolume::getLightLinearColor() const
  3285. {
  3286. const LLLightParams* param_block = getLightParams();
  3287. return param_block ? LLColor3(param_block->getLinearColor()) *
  3288. param_block->getLinearColor().mV[3]
  3289. : LLColor3::white;
  3290. }
  3291. LLColor3 LLVOVolume::getLightSRGBColor() const
  3292. {
  3293. LLColor3 ret = getLightLinearColor();
  3294. ret = srgbColor3(ret);
  3295. return ret;
  3296. }
  3297. const LLUUID& LLVOVolume::getLightTextureID() const
  3298. {
  3299. const LLLightImageParams* param_block = getLightImageParams();
  3300. return param_block ? param_block->getLightTexture() : LLUUID::null;
  3301. }
  3302. LLVector3 LLVOVolume::getSpotLightParams() const
  3303. {
  3304. const LLLightImageParams* param_block = getLightImageParams();
  3305. return param_block ? param_block->getParams() : LLVector3::zero;
  3306. }
  3307. void LLVOVolume::updateSpotLightPriority()
  3308. {
  3309. if (gCubeSnapshot)
  3310. {
  3311. return;
  3312. }
  3313. LLVector3 pos = mDrawable->getPositionAgent();
  3314. LLVector3 at(0.f, 0.f, -1.f);
  3315. at *= getRenderRotation();
  3316. F32 r = getLightRadius() * 0.5f;
  3317. pos += at * r;
  3318. at = gViewerCamera.getAtAxis();
  3319. pos -= at * r;
  3320. mSpotLightPriority = gPipeline.calcPixelArea(pos, LLVector3(r, r, r),
  3321. gViewerCamera);
  3322. if (mLightTexture.notNull())
  3323. {
  3324. mLightTexture->addTextureStats(mSpotLightPriority);
  3325. mLightTexture->setBoostLevel(LLGLTexture::BOOST_CLOUDS);
  3326. }
  3327. }
  3328. bool LLVOVolume::isLightSpotlight() const
  3329. {
  3330. const LLLightImageParams* params = getLightImageParams();
  3331. return params && params->isLightSpotlight();
  3332. }
  3333. LLViewerTexture* LLVOVolume::getLightTexture()
  3334. {
  3335. const LLUUID& id = getLightTextureID();
  3336. if (id.isNull())
  3337. {
  3338. mLightTexture = NULL;
  3339. }
  3340. else if (mLightTexture.isNull() || id != mLightTexture->getID())
  3341. {
  3342. mLightTexture =
  3343. LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, true,
  3344. LLGLTexture::BOOST_ALM);
  3345. }
  3346. return mLightTexture;
  3347. }
  3348. F32 LLVOVolume::getLightIntensity() const
  3349. {
  3350. const LLLightParams* param_block = getLightParams();
  3351. return param_block ? param_block->getLinearColor().mV[3] : 1.f;
  3352. }
  3353. F32 LLVOVolume::getLightRadius() const
  3354. {
  3355. const LLLightParams* param_block = getLightParams();
  3356. return param_block ? param_block->getRadius() : 0.f;
  3357. }
  3358. F32 LLVOVolume::getLightFalloff(F32 fudge_factor) const
  3359. {
  3360. const LLLightParams* param_block = getLightParams();
  3361. return param_block ? param_block->getFalloff() * fudge_factor : 0.f;
  3362. }
  3363. F32 LLVOVolume::getLightCutoff() const
  3364. {
  3365. const LLLightParams* param_block = getLightParams();
  3366. return param_block ? param_block->getCutoff() : 0.f;
  3367. }
  3368. bool LLVOVolume::isReflectionProbe() const
  3369. {
  3370. return getParameterEntryInUse(LLNetworkData::PARAMS_REFLECTION_PROBE);
  3371. }
  3372. bool LLVOVolume::setIsReflectionProbe(bool is_probe)
  3373. {
  3374. bool changed = is_probe != isReflectionProbe();
  3375. if (changed)
  3376. {
  3377. setParameterEntryInUse(LLNetworkData::PARAMS_REFLECTION_PROBE,
  3378. is_probe, true);
  3379. }
  3380. updateReflectionProbePtr();
  3381. return changed;
  3382. }
  3383. bool LLVOVolume::setReflectionProbeAmbiance(F32 ambiance)
  3384. {
  3385. LLReflectionProbeParams* paramsp = getReflectionProbeParams();
  3386. if (paramsp && paramsp->getAmbiance() != ambiance)
  3387. {
  3388. paramsp->setAmbiance(ambiance);
  3389. parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
  3390. return true;
  3391. }
  3392. return false;
  3393. }
  3394. bool LLVOVolume::setReflectionProbeNearClip(F32 near_clip)
  3395. {
  3396. LLReflectionProbeParams* paramsp = getReflectionProbeParams();
  3397. if (paramsp && paramsp->getClipDistance() != near_clip)
  3398. {
  3399. paramsp->setClipDistance(near_clip);
  3400. parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
  3401. return true;
  3402. }
  3403. return false;
  3404. }
  3405. bool LLVOVolume::setReflectionProbeIsBox(bool is_box)
  3406. {
  3407. LLReflectionProbeParams* paramsp = getReflectionProbeParams();
  3408. if (paramsp && paramsp->getIsBox() != is_box)
  3409. {
  3410. paramsp->setIsBox(is_box);
  3411. parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
  3412. return true;
  3413. }
  3414. return false;
  3415. }
  3416. bool LLVOVolume::setReflectionProbeIsDynamic(bool is_dynamic)
  3417. {
  3418. LLReflectionProbeParams* paramsp = getReflectionProbeParams();
  3419. if (paramsp && paramsp->getIsDynamic() != is_dynamic)
  3420. {
  3421. paramsp->setIsDynamic(is_dynamic);
  3422. parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
  3423. return true;
  3424. }
  3425. return false;
  3426. }
  3427. bool LLVOVolume::setReflectionProbeIsMirror(bool is_mirror)
  3428. {
  3429. LLReflectionProbeParams* paramsp = getReflectionProbeParams();
  3430. if (paramsp && paramsp->getIsMirror() != is_mirror)
  3431. {
  3432. if (is_mirror)
  3433. {
  3434. gPipeline.mHeroProbeManager.registerViewerObject(this);
  3435. }
  3436. else
  3437. {
  3438. gPipeline.mHeroProbeManager.unregisterViewerObject(this);
  3439. }
  3440. paramsp->setIsMirror(is_mirror);
  3441. parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
  3442. return true;
  3443. }
  3444. return false;
  3445. }
  3446. F32 LLVOVolume::getReflectionProbeAmbiance() const
  3447. {
  3448. const LLReflectionProbeParams* paramsp =
  3449. (const LLReflectionProbeParams*)getReflectionProbeParams();
  3450. return paramsp ? paramsp->getAmbiance() : 0.f;
  3451. }
  3452. F32 LLVOVolume::getReflectionProbeNearClip() const
  3453. {
  3454. const LLReflectionProbeParams* paramsp =
  3455. (const LLReflectionProbeParams*)getReflectionProbeParams();
  3456. return paramsp ? paramsp->getClipDistance() : 0.f;
  3457. }
  3458. bool LLVOVolume::getReflectionProbeIsBox() const
  3459. {
  3460. const LLReflectionProbeParams* paramsp =
  3461. (const LLReflectionProbeParams*)getReflectionProbeParams();
  3462. return paramsp && paramsp->getIsBox();
  3463. }
  3464. bool LLVOVolume::getReflectionProbeIsDynamic() const
  3465. {
  3466. const LLReflectionProbeParams* paramsp =
  3467. (const LLReflectionProbeParams*)getReflectionProbeParams();
  3468. return paramsp && paramsp->getIsDynamic();
  3469. }
  3470. bool LLVOVolume::getReflectionProbeIsMirror() const
  3471. {
  3472. const LLReflectionProbeParams* paramsp =
  3473. (const LLReflectionProbeParams*)getReflectionProbeParams();
  3474. return paramsp && paramsp->getIsMirror();
  3475. }
  3476. U32 LLVOVolume::getVolumeInterfaceID() const
  3477. {
  3478. return mVolumeImpl ? mVolumeImpl->getID() : 0;
  3479. }
  3480. bool LLVOVolume::isFlexible() const
  3481. {
  3482. return getParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE);
  3483. }
  3484. bool LLVOVolume::isSculpted() const
  3485. {
  3486. return getParameterEntryInUse(LLNetworkData::PARAMS_SCULPT);
  3487. }
  3488. bool LLVOVolume::isMesh() const
  3489. {
  3490. if (isSculpted())
  3491. {
  3492. const LLSculptParams* params = getSculptParams();
  3493. if (params)
  3494. {
  3495. U8 sculpt_type = params->getSculptType();
  3496. if ((sculpt_type & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
  3497. {
  3498. return true;
  3499. }
  3500. }
  3501. }
  3502. return false;
  3503. }
  3504. bool LLVOVolume::hasLightTexture() const
  3505. {
  3506. return getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE);
  3507. }
  3508. bool LLVOVolume::isVolumeGlobal() const
  3509. {
  3510. return mVolumeImpl ? mVolumeImpl->isVolumeGlobal()
  3511. : mRiggedVolume.notNull();
  3512. }
  3513. bool LLVOVolume::canBeFlexible() const
  3514. {
  3515. U8 path = getVolume()->getParams().getPathParams().getCurveType();
  3516. return path == LL_PCODE_PATH_FLEXIBLE || path == LL_PCODE_PATH_LINE;
  3517. }
  3518. bool LLVOVolume::setIsFlexible(bool is_flexible)
  3519. {
  3520. bool res = false;
  3521. bool was_flexible = isFlexible();
  3522. LLVolumeParams volume_params;
  3523. if (is_flexible)
  3524. {
  3525. if (!was_flexible)
  3526. {
  3527. volume_params = getVolume()->getParams();
  3528. U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
  3529. volume_params.setType(profile_and_hole, LL_PCODE_PATH_FLEXIBLE);
  3530. res = true;
  3531. setFlags(FLAGS_USE_PHYSICS, false);
  3532. setFlags(FLAGS_PHANTOM, true);
  3533. setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, true, true);
  3534. if (mDrawable.notNull())
  3535. {
  3536. mDrawable->makeActive();
  3537. }
  3538. }
  3539. }
  3540. else if (was_flexible)
  3541. {
  3542. volume_params = getVolume()->getParams();
  3543. U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
  3544. volume_params.setType(profile_and_hole, LL_PCODE_PATH_LINE);
  3545. res = true;
  3546. setFlags(FLAGS_PHANTOM, false);
  3547. setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, false, true);
  3548. }
  3549. if (res)
  3550. {
  3551. res = setVolume(volume_params, 1);
  3552. if (res)
  3553. {
  3554. markForUpdate();
  3555. }
  3556. }
  3557. return res;
  3558. }
  3559. const LLMeshSkinInfo* LLVOVolume::getSkinInfo() const
  3560. {
  3561. return getVolume() ? mSkinInfo : nullptr;
  3562. }
  3563. bool LLVOVolume::isRiggedMesh() const
  3564. {
  3565. return isMesh() && getSkinInfo();
  3566. }
  3567. U32 LLVOVolume::getExtendedMeshFlags() const
  3568. {
  3569. const LLExtendedMeshParams* param_blockp = getExtendedMeshParams();
  3570. return param_blockp ? param_blockp->getFlags() : 0;
  3571. }
  3572. void LLVOVolume::onSetExtendedMeshFlags(U32 flags)
  3573. {
  3574. if (mDrawable.notNull())
  3575. {
  3576. // Need to trigger rebuildGeom(), which is where puppet avatars get
  3577. // created/removed.
  3578. getRootEdit()->recursiveMarkForUpdate();
  3579. }
  3580. if (isAttachment())
  3581. {
  3582. LLVOAvatar* avatarp = getAvatarAncestor();
  3583. if (avatarp)
  3584. {
  3585. updateVisualComplexity();
  3586. avatarp->updateAttachmentOverrides();
  3587. }
  3588. }
  3589. }
  3590. void LLVOVolume::setExtendedMeshFlags(U32 flags)
  3591. {
  3592. U32 curr_flags = getExtendedMeshFlags();
  3593. if (curr_flags != flags)
  3594. {
  3595. setParameterEntryInUse(LLNetworkData::PARAMS_EXTENDED_MESH, true,
  3596. true);
  3597. LLExtendedMeshParams* param_blockp = getExtendedMeshParams();
  3598. if (param_blockp)
  3599. {
  3600. param_blockp->setFlags(flags);
  3601. }
  3602. parameterChanged(LLNetworkData::PARAMS_EXTENDED_MESH, true);
  3603. onSetExtendedMeshFlags(flags);
  3604. }
  3605. }
  3606. bool LLVOVolume::canBeAnimatedObject() const
  3607. {
  3608. F32 est_tris = recursiveGetEstTrianglesMax();
  3609. F32 max_tris = getAnimatedObjectMaxTris();
  3610. if (est_tris < 0 || est_tris > getAnimatedObjectMaxTris())
  3611. {
  3612. LL_DEBUGS("Mesh") << "Estimated triangles amount " << est_tris
  3613. << " out of limit 0-" << max_tris << LL_ENDL;
  3614. return false;
  3615. }
  3616. return true;
  3617. }
  3618. bool LLVOVolume::isAnimatedObject() const
  3619. {
  3620. LLVOVolume* root_volp = (LLVOVolume*)getRootEdit();
  3621. return root_volp &&
  3622. (root_volp->getExtendedMeshFlags() &
  3623. LLExtendedMeshParams::ANIMATED_MESH_ENABLED_FLAG) != 0;
  3624. }
  3625. // Called any time parenting changes for a volume. Update flags and puppet
  3626. // avatar accordingly. This is called after parent has been changed to
  3627. // new_parent.
  3628. //virtual
  3629. void LLVOVolume::onReparent(LLViewerObject* old_parentp,
  3630. LLViewerObject* new_parentp)
  3631. {
  3632. LLVOVolume* old_volp = old_parentp ? old_parentp->asVolume() : NULL;
  3633. // AXON: depending on whether animated objects can be attached, we may want
  3634. // to include or remove the isAvatar() check.
  3635. if (new_parentp && !new_parentp->isAvatar())
  3636. {
  3637. if (mPuppetAvatar.notNull())
  3638. {
  3639. mPuppetAvatar->markForDeath();
  3640. mPuppetAvatar = NULL;
  3641. }
  3642. }
  3643. if (old_volp && old_volp->isAnimatedObject())
  3644. {
  3645. LLVOAvatarPuppet* puppetp = old_volp->getPuppetAvatar();
  3646. if (puppetp)
  3647. {
  3648. // We have been removed from an animated object, need to do cleanup
  3649. puppetp->updateAttachmentOverrides();
  3650. puppetp->updateAnimations();
  3651. }
  3652. }
  3653. }
  3654. // This needs to be called after onReparent(), because mChildList is not
  3655. // updated until the end of addChild()
  3656. //virtual
  3657. void LLVOVolume::afterReparent()
  3658. {
  3659. if (isAnimatedObject())
  3660. {
  3661. LLVOAvatarPuppet* puppetp = getPuppetAvatar();
  3662. if (puppetp)
  3663. {
  3664. #if 0
  3665. puppetp->rebuildAttachmentOverrides();
  3666. #endif
  3667. puppetp->updateAnimations();
  3668. }
  3669. }
  3670. }
  3671. //virtual
  3672. void LLVOVolume::updateRiggingInfo()
  3673. {
  3674. if (!isRiggedMesh() || (mLOD != 3 && mLOD <= mLastRiggingInfoLOD))
  3675. {
  3676. return;
  3677. }
  3678. const LLMeshSkinInfo* skinp = getSkinInfo();
  3679. if (!skinp) return;
  3680. LLVOAvatar* avatarp = getAvatar();
  3681. if (!avatarp) return;
  3682. LLVolume* volp = getVolume();
  3683. if (!volp) return;
  3684. // Rigging info may need update
  3685. mJointRiggingInfoTab.clear();
  3686. for (S32 i = 0, count = volp->getNumVolumeFaces(); i < count; ++i)
  3687. {
  3688. LLVolumeFace& vol_face = volp->getVolumeFace(i);
  3689. LLSkinningUtil::updateRiggingInfo(skinp, avatarp, vol_face);
  3690. if (vol_face.mJointRiggingInfoTab.size())
  3691. {
  3692. mJointRiggingInfoTab.merge(vol_face.mJointRiggingInfoTab);
  3693. }
  3694. }
  3695. mLastRiggingInfoLOD = mLOD;
  3696. }
  3697. void LLVOVolume::generateSilhouette(LLSelectNode* nodep,
  3698. const LLVector3& view_point)
  3699. {
  3700. LLVolume* volp = getVolume();
  3701. if (volp && getRegion())
  3702. {
  3703. LLVector3 view_vector;
  3704. view_vector = view_point;
  3705. // Transform view vector into volume space
  3706. view_vector -= getRenderPosition();
  3707. #if 0
  3708. mDrawable->mDistanceWRTCamera = view_vector.length();
  3709. #endif
  3710. LLQuaternion world_rot = getRenderRotation();
  3711. view_vector = view_vector * ~world_rot;
  3712. if (!isVolumeGlobal())
  3713. {
  3714. LLVector3 obj_scale = getScale();
  3715. LLVector3 inv_obj_scale(1.f / obj_scale.mV[VX],
  3716. 1.f / obj_scale.mV[VY],
  3717. 1.f / obj_scale.mV[VZ]);
  3718. view_vector.scaleVec(inv_obj_scale);
  3719. }
  3720. updateRelativeXform();
  3721. LLMatrix4 trans_mat = mRelativeXform;
  3722. if (mDrawable->isStatic())
  3723. {
  3724. trans_mat.translate(getRegion()->getOriginAgent());
  3725. }
  3726. volp->generateSilhouetteVertices(nodep->mSilhouetteVertices,
  3727. nodep->mSilhouetteNormals,
  3728. view_vector, trans_mat,
  3729. mRelativeXformInvTrans,
  3730. nodep->getTESelectMask());
  3731. nodep->mSilhouetteGenerated = true;
  3732. }
  3733. }
  3734. void LLVOVolume::deleteFaces()
  3735. {
  3736. S32 face_count = mNumFaces;
  3737. if (mDrawable.notNull())
  3738. {
  3739. mDrawable->deleteFaces(0, face_count);
  3740. }
  3741. mNumFaces = 0;
  3742. }
  3743. void LLVOVolume::updateRadius()
  3744. {
  3745. if (mDrawable.notNull())
  3746. {
  3747. mVObjRadius = getScale().length();
  3748. mDrawable->setRadius(mVObjRadius);
  3749. }
  3750. }
  3751. bool LLVOVolume::isAttachment() const
  3752. {
  3753. return mAttachmentState != 0;
  3754. }
  3755. bool LLVOVolume::isHUDAttachment() const
  3756. {
  3757. // *NOTE: we assume hud attachment points are in defined range since this
  3758. // range is constant for backwards compatibility reasons this is probably a
  3759. // reasonable assumption to make.
  3760. S32 attachment_id = ATTACHMENT_ID_FROM_STATE(mAttachmentState);
  3761. return attachment_id >= 31 && attachment_id <= 38;
  3762. }
  3763. const LLMatrix4& LLVOVolume::getRenderMatrix() const
  3764. {
  3765. if (mDrawable->isActive() && !mDrawable->isRoot())
  3766. {
  3767. return mDrawable->getParent()->getWorldMatrix();
  3768. }
  3769. return mDrawable->getWorldMatrix();
  3770. }
  3771. // Returns a base cost and adds textures to passed in set. Total cost is
  3772. // returned value + 5 * size of the resulting set. Cannot include cost of
  3773. // textures, as they may be re-used in linked children, and cost should only be
  3774. // increased for unique textures -Nyx
  3775. /**************************************************************************
  3776. * The calculation in this method should not be modified by third party
  3777. * viewers, since it is used to limit rendering and should be uniform for
  3778. * everyone. If you have suggested improvements, submit them to the official
  3779. * viewer for consideration.
  3780. *************************************************************************/
  3781. U32 LLVOVolume::getRenderCost(texture_cost_t& textures) const
  3782. {
  3783. if (mDrawable.isNull()) return 0;
  3784. // Per-prim costs, determined experimentally
  3785. constexpr U32 ARC_PARTICLE_COST = 1;
  3786. // Default value
  3787. constexpr U32 ARC_PARTICLE_MAX = 2048;
  3788. // Multiplier for texture resolution - performance tested
  3789. constexpr F32 ARC_TEXTURE_COST_BY_128 = 16.f / 128.f;
  3790. // Cost for light-producing prims
  3791. constexpr U32 ARC_LIGHT_COST = 500;
  3792. // Cost per media-enabled face
  3793. constexpr U32 ARC_MEDIA_FACE_COST = 1500;
  3794. // Per-prim multipliers (tested based on performances)
  3795. constexpr F32 ARC_GLOW_MULT = 1.5f;
  3796. constexpr F32 ARC_BUMP_MULT = 1.25f;
  3797. constexpr F32 ARC_FLEXI_MULT = 5.f;
  3798. constexpr F32 ARC_SHINY_MULT = 1.6f;
  3799. constexpr F32 ARC_INVISI_COST = 1.2f;
  3800. constexpr F32 ARC_WEIGHTED_MESH = 1.2f;
  3801. // Tested to have negligible impact
  3802. constexpr F32 ARC_PLANAR_COST = 1.f;
  3803. constexpr F32 ARC_ANIM_TEX_COST = 4.f;
  3804. // 4x max based on performance
  3805. constexpr F32 ARC_ALPHA_COST = 4.f;
  3806. // Note: this object might not have a volume (e.g. if it is an avatar).
  3807. U32 num_triangles = 0;
  3808. LLVolume* volp = getVolume();
  3809. if (volp)
  3810. {
  3811. LLMeshCostData* costs = getCostData();
  3812. if (costs)
  3813. {
  3814. if (isAnimatedObject() && isRiggedMesh())
  3815. {
  3816. // AXON: scaling here is to make animated object versus non
  3817. // animated object ARC proportional to the corresponding
  3818. // calculations for streaming cost.
  3819. num_triangles = (U32)(ANIMATED_OBJECT_COST_PER_KTRI * 0.001f *
  3820. costs->getEstTrisForStreamingCost() /
  3821. 0.06f);
  3822. }
  3823. else
  3824. {
  3825. F32 radius = getScale().length() * 0.5f;
  3826. num_triangles = costs->getRadiusWeightedTris(radius);
  3827. }
  3828. }
  3829. }
  3830. if (num_triangles <= 0)
  3831. {
  3832. num_triangles = 4;
  3833. }
  3834. if (volp && isSculpted() && !isMesh())
  3835. {
  3836. const LLSculptParams* sculpt_params = getSculptParams();
  3837. if (sculpt_params)
  3838. {
  3839. const LLUUID& sculpt_id = sculpt_params->getSculptTexture();
  3840. if (!textures.count(sculpt_id))
  3841. {
  3842. LLViewerFetchedTexture* tex =
  3843. LLViewerTextureManager::getFetchedTexture(sculpt_id);
  3844. if (tex)
  3845. {
  3846. S32 cost = 256 +
  3847. (S32)(ARC_TEXTURE_COST_BY_128 *
  3848. (F32)(tex->getFullHeight() +
  3849. tex->getFullWidth()));
  3850. textures[sculpt_id] = cost;
  3851. }
  3852. }
  3853. }
  3854. }
  3855. // These are multipliers flags: do not add per-face.
  3856. bool invisi = false;
  3857. bool shiny = false;
  3858. bool glow = false;
  3859. bool alpha = false;
  3860. bool animtex = false;
  3861. bool bump = false;
  3862. bool planar = false;
  3863. // Per media-face shame
  3864. U32 media_faces = 0;
  3865. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  3866. {
  3867. const LLFace* face = mDrawable->getFace(i);
  3868. if (!face) continue;
  3869. const LLViewerTexture* texp = face->getTexture();
  3870. if (texp)
  3871. {
  3872. const LLUUID& tex_id = texp->getID();
  3873. if (!textures.count(tex_id))
  3874. {
  3875. S32 cost = 0;
  3876. S8 type = texp->getType();
  3877. if (type == LLViewerTexture::FETCHED_TEXTURE ||
  3878. type == LLViewerTexture::LOD_TEXTURE)
  3879. {
  3880. const LLViewerFetchedTexture* ftexp =
  3881. (LLViewerFetchedTexture*)texp;
  3882. if (ftexp->getFTType() == FTT_LOCAL_FILE &&
  3883. (tex_id == IMG_ALPHA_GRAD_2D ||
  3884. tex_id == IMG_ALPHA_GRAD))
  3885. {
  3886. // These two textures appear to switch between each
  3887. // other, but are of different sizes (4x256 and
  3888. // 256x256). Hard-code cost from larger one to not
  3889. // cause random complexity changes.
  3890. cost = 320;
  3891. }
  3892. }
  3893. if (cost == 0)
  3894. {
  3895. cost = 256 +
  3896. (S32)(ARC_TEXTURE_COST_BY_128 *
  3897. (F32)(texp->getFullHeight() +
  3898. texp->getFullWidth()));
  3899. }
  3900. textures[tex_id] = cost;
  3901. }
  3902. }
  3903. if (face->isInAlphaPool())
  3904. {
  3905. alpha = true;
  3906. }
  3907. else if (texp && texp->getPrimaryFormat() == GL_ALPHA)
  3908. {
  3909. invisi = true;
  3910. }
  3911. if (face->hasMedia())
  3912. {
  3913. ++media_faces;
  3914. }
  3915. animtex |= face->mTextureMatrix != NULL;
  3916. const LLTextureEntry* te = face->getTextureEntry();
  3917. if (te)
  3918. {
  3919. bump |= te->getBumpmap() != 0;
  3920. shiny |= te->getShiny() != 0;
  3921. glow |= te->hasGlow();
  3922. planar |= te->getTexGen() != 0;
  3923. }
  3924. }
  3925. // Shame currently has the "base" cost of 1 point per 15 triangles, min 2.
  3926. F32 shame = num_triangles * 5.f;
  3927. shame = shame < 2.f ? 2.f : shame;
  3928. // Multiply by per-face modifiers
  3929. if (planar)
  3930. {
  3931. shame *= ARC_PLANAR_COST;
  3932. }
  3933. if (animtex)
  3934. {
  3935. shame *= ARC_ANIM_TEX_COST;
  3936. }
  3937. if (alpha)
  3938. {
  3939. shame *= ARC_ALPHA_COST;
  3940. }
  3941. if (invisi)
  3942. {
  3943. shame *= ARC_INVISI_COST;
  3944. }
  3945. if (glow)
  3946. {
  3947. shame *= ARC_GLOW_MULT;
  3948. }
  3949. if (bump)
  3950. {
  3951. shame *= ARC_BUMP_MULT;
  3952. }
  3953. if (shiny)
  3954. {
  3955. shame *= ARC_SHINY_MULT;
  3956. }
  3957. if (isRiggedMesh())
  3958. {
  3959. shame *= ARC_WEIGHTED_MESH;
  3960. }
  3961. if (isFlexible())
  3962. {
  3963. shame *= ARC_FLEXI_MULT;
  3964. }
  3965. // Add additional costs
  3966. if (isParticleSource())
  3967. {
  3968. const LLPartSysData* part_sys_data = &(mPartSourcep->mPartSysData);
  3969. const LLPartData* part_data = &(part_sys_data->mPartData);
  3970. U32 num_particles = (U32)(part_sys_data->mBurstPartCount *
  3971. llceil(part_data->mMaxAge /
  3972. part_sys_data->mBurstRate));
  3973. num_particles = num_particles > ARC_PARTICLE_MAX ? ARC_PARTICLE_MAX
  3974. : num_particles;
  3975. F32 part_size = (llmax(part_data->mStartScale[0],
  3976. part_data->mEndScale[0]) +
  3977. llmax(part_data->mStartScale[1],
  3978. part_data->mEndScale[1])) * 0.5f;
  3979. shame += num_particles * part_size * ARC_PARTICLE_COST;
  3980. }
  3981. if (getIsLight())
  3982. {
  3983. shame += ARC_LIGHT_COST;
  3984. }
  3985. if (media_faces)
  3986. {
  3987. shame += media_faces * ARC_MEDIA_FACE_COST;
  3988. }
  3989. // Streaming cost for animated objects includes a fixed cost per linkset.
  3990. // Add a corresponding charge here translated into triangles, but not
  3991. // weighted by any graphics properties.
  3992. if (isAnimatedObject() && isRootEdit())
  3993. {
  3994. shame += ANIMATED_OBJECT_BASE_COST * 5.f / 0.06f;
  3995. }
  3996. return (U32)shame;
  3997. }
  3998. //virtual
  3999. F32 LLVOVolume::getEstTrianglesMax() const
  4000. {
  4001. LLVolume* volp = getVolume();
  4002. if (volp && isMesh())
  4003. {
  4004. return gMeshRepo.getEstTrianglesMax(volp->getParams().getSculptID());
  4005. }
  4006. return 0.f;
  4007. }
  4008. //virtual
  4009. F32 LLVOVolume::getEstTrianglesStreamingCost() const
  4010. {
  4011. LLVolume* volp = getVolume();
  4012. if (volp && isMesh())
  4013. {
  4014. return gMeshRepo.getEstTrianglesStreamingCost(volp->getParams().getSculptID());
  4015. }
  4016. return 0.f;
  4017. }
  4018. F32 LLVOVolume::getStreamingCost(S32* bytes, S32* visible_bytes,
  4019. F32* unscaled_value) const
  4020. {
  4021. LLMeshCostData* cost_data = getCostData();
  4022. if (!cost_data)
  4023. {
  4024. return 0.f;
  4025. }
  4026. F32 cost = 0.f;
  4027. bool animated = isAnimatedObject();
  4028. if (animated && isRootEdit())
  4029. {
  4030. // Root object of an animated object has this to account for skeleton
  4031. // overhead.
  4032. cost = ANIMATED_OBJECT_BASE_COST;
  4033. }
  4034. F32 radius = getScale().length() * 0.5f;
  4035. if (isMesh() && animated && isRiggedMesh())
  4036. {
  4037. cost += cost_data->getTriangleBasedStreamingCost();
  4038. }
  4039. else
  4040. {
  4041. cost += cost_data->getRadiusBasedStreamingCost(radius);
  4042. }
  4043. if (bytes)
  4044. {
  4045. *bytes = cost_data->getSizeTotal();
  4046. }
  4047. if (visible_bytes)
  4048. {
  4049. *visible_bytes = cost_data->getSizeByLOD(mLOD);
  4050. }
  4051. if (unscaled_value)
  4052. {
  4053. *unscaled_value = cost_data->getRadiusWeightedTris(radius);
  4054. }
  4055. return cost;
  4056. }
  4057. LLMeshCostData* LLVOVolume::getCostData() const
  4058. {
  4059. if (mCostData.notNull())
  4060. {
  4061. return mCostData.get();
  4062. }
  4063. LLVolume* volp = getVolume();
  4064. if (volp) // Paranoia
  4065. {
  4066. if (isMesh())
  4067. {
  4068. mCostData = gMeshRepo.getCostData(volp->getParams().getSculptID());
  4069. }
  4070. else
  4071. {
  4072. mCostData = new LLMeshCostData();
  4073. S32 counts[4];
  4074. volp->getLoDTriangleCounts(counts);
  4075. if (!mCostData->init(counts[0] * 10, counts[1] * 10,
  4076. counts[2] * 10, counts[3] * 10))
  4077. {
  4078. mCostData = NULL;
  4079. }
  4080. }
  4081. }
  4082. return mCostData.get();
  4083. }
  4084. U32 LLVOVolume::getTriangleCount(S32* vcount) const
  4085. {
  4086. LLVolume* volp = getVolume();
  4087. return volp ? volp->getNumTriangles(vcount) : 0;
  4088. }
  4089. U32 LLVOVolume::getHighLODTriangleCount()
  4090. {
  4091. U32 ret = 0;
  4092. LLVolume* volp = getVolume();
  4093. if (!isSculpted())
  4094. {
  4095. LLVolume* refp = gVolumeMgrp->refVolume(volp->getParams(), 3);
  4096. if (refp)
  4097. {
  4098. ret = refp->getNumTriangles();
  4099. gVolumeMgrp->unrefVolume(refp);
  4100. }
  4101. }
  4102. else if (isMesh())
  4103. {
  4104. LLVolume* refp = gVolumeMgrp->refVolume(volp->getParams(), 3);
  4105. if (refp)
  4106. {
  4107. if (!refp->isMeshAssetLoaded() || !refp->getNumVolumeFaces())
  4108. {
  4109. gMeshRepo.loadMesh(this, volp->getParams(), LLModel::LOD_HIGH);
  4110. }
  4111. ret = refp->getNumTriangles();
  4112. gVolumeMgrp->unrefVolume(refp);
  4113. }
  4114. }
  4115. else
  4116. {
  4117. // Default sculpts have a constant number of triangles: 31 rows of 31
  4118. // columns of quads for a 32x32 vertex patch.
  4119. ret = 31 * 2 * 31;
  4120. }
  4121. return ret;
  4122. }
  4123. //virtual
  4124. void LLVOVolume::parameterChanged(U16 param_type, bool local_origin)
  4125. {
  4126. LLViewerObject::parameterChanged(param_type, local_origin);
  4127. }
  4128. //virtual
  4129. void LLVOVolume::parameterChanged(U16 param_type, LLNetworkData* datap,
  4130. bool in_use, bool local_origin)
  4131. {
  4132. LLViewerObject::parameterChanged(param_type, datap, in_use, local_origin);
  4133. if (mVolumeImpl)
  4134. {
  4135. mVolumeImpl->onParameterChanged(param_type, datap, in_use,
  4136. local_origin);
  4137. }
  4138. if (!local_origin && param_type == LLNetworkData::PARAMS_EXTENDED_MESH)
  4139. {
  4140. U32 extended_mesh_flags = getExtendedMeshFlags();
  4141. bool enabled = (extended_mesh_flags &
  4142. LLExtendedMeshParams::ANIMATED_MESH_ENABLED_FLAG) != 0;
  4143. // AXON: this is kind of a guess. Better if we could compare the before
  4144. // and after flags directly. What about cases where there is no puppet
  4145. // avatar for optimization reasons ?
  4146. bool was_enabled = getPuppetAvatar() != NULL;
  4147. if (enabled != was_enabled)
  4148. {
  4149. onSetExtendedMeshFlags(extended_mesh_flags);
  4150. }
  4151. }
  4152. if (mDrawable.notNull())
  4153. {
  4154. bool is_light = getIsLight();
  4155. if (is_light != mDrawable->isState(LLDrawable::LIGHT))
  4156. {
  4157. gPipeline.setLight(mDrawable, is_light);
  4158. }
  4159. }
  4160. updateReflectionProbePtr();
  4161. }
  4162. void LLVOVolume::updateReflectionProbePtr(bool recreate)
  4163. {
  4164. bool is_probe = isReflectionProbe();
  4165. if (!is_probe || recreate || !gUsePBRShaders)
  4166. {
  4167. if (mReflectionProbe.notNull())
  4168. {
  4169. // Unhook from reflection probe manager
  4170. mReflectionProbe->mViewerObject = NULL;
  4171. mReflectionProbe = NULL;
  4172. }
  4173. // Unregister unconditionally, in case mIsHeroProbe is corrupted. HB
  4174. gPipeline.mHeroProbeManager.unregisterViewerObject(this);
  4175. if (!recreate)
  4176. {
  4177. return;
  4178. }
  4179. }
  4180. if (is_probe && mReflectionProbe.isNull())
  4181. {
  4182. if (LLPipeline::sRenderMirrors && getReflectionProbeIsMirror())
  4183. {
  4184. // Note: mIsHeroProbe is automatically set by this method. HB
  4185. gPipeline.mHeroProbeManager.registerViewerObject(this);
  4186. }
  4187. else
  4188. {
  4189. mReflectionProbe =
  4190. gPipeline.mReflectionMapManager.registerViewerObject(this);
  4191. }
  4192. }
  4193. }
  4194. void LLVOVolume::setSelected(bool sel)
  4195. {
  4196. LLViewerObject::setSelected(sel);
  4197. if (isAnimatedObject())
  4198. {
  4199. getRootEdit()->recursiveMarkForUpdate();
  4200. }
  4201. else
  4202. {
  4203. markForUpdate();
  4204. }
  4205. }
  4206. void LLVOVolume::updateSpatialExtents(LLVector4a&, LLVector4a&)
  4207. {
  4208. }
  4209. F32 LLVOVolume::getBinRadius()
  4210. {
  4211. static LLCachedControl<bool> new_bin_radius(gSavedSettings,
  4212. "UseNewBinRadiusCompute");
  4213. static LLCachedControl<S32> size_factor(gSavedSettings,
  4214. "OctreeStaticObjectSizeFactor");
  4215. static LLCachedControl<S32> att_size_factor(gSavedSettings,
  4216. "OctreeAttachmentSizeFactor");
  4217. static LLCachedControl<LLVector3> dist_factor(gSavedSettings,
  4218. "OctreeDistanceFactor");
  4219. static LLCachedControl<LLVector3> alpha_factor(gSavedSettings,
  4220. "OctreeAlphaDistanceFactor");
  4221. bool shrink_wrap = mShouldShrinkWrap || mDrawable->isAnimating();
  4222. bool alpha_wrap = false;
  4223. if (!isHUDAttachment() &&
  4224. (!new_bin_radius ||
  4225. mDrawable->mDistanceWRTCamera < alpha_factor().mV[2]))
  4226. {
  4227. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  4228. {
  4229. LLFace* face = mDrawable->getFace(i);
  4230. if (face && face->isInAlphaPool() && !face->canRenderAsMask())
  4231. {
  4232. alpha_wrap = true;
  4233. break;
  4234. }
  4235. }
  4236. }
  4237. else
  4238. {
  4239. shrink_wrap = false;
  4240. }
  4241. F32 radius;
  4242. if (new_bin_radius)
  4243. {
  4244. if (alpha_wrap)
  4245. {
  4246. const LLVector3& bounds = getScale();
  4247. radius = llmin(bounds.mV[0], bounds.mV[1], bounds.mV[2]) * 0.5f;
  4248. }
  4249. else if (shrink_wrap)
  4250. {
  4251. radius = mDrawable->getRadius() * 0.25f;
  4252. }
  4253. else
  4254. {
  4255. radius = llmax(1.f, mDrawable->getRadius(), size_factor);
  4256. }
  4257. }
  4258. else if (alpha_wrap)
  4259. {
  4260. const LLVector3& bounds = getScale();
  4261. radius = llmin(bounds.mV[0], bounds.mV[1], bounds.mV[2]) * 0.5f;
  4262. radius *= 1.f + mDrawable->mDistanceWRTCamera * alpha_factor().mV[1];
  4263. radius += mDrawable->mDistanceWRTCamera * alpha_factor().mV[0];
  4264. }
  4265. else if (shrink_wrap)
  4266. {
  4267. const LLVector4a* extp = mDrawable->getSpatialExtents();
  4268. LLVector4a rad;
  4269. rad.setSub(extp[1], extp[0]);
  4270. radius = rad.getLength3().getF32() * 0.5f;
  4271. }
  4272. else if (mDrawable->isStatic())
  4273. {
  4274. F32 szf = llmax(1.f, size_factor);
  4275. radius = llmax(mDrawable->getRadius(), szf);
  4276. radius = powf(radius, 1.f + szf / radius);
  4277. radius *= 1.f + mDrawable->mDistanceWRTCamera * dist_factor().mV[1];
  4278. radius += mDrawable->mDistanceWRTCamera * dist_factor().mV[0];
  4279. }
  4280. else if (mDrawable->getVObj()->isAttachment())
  4281. {
  4282. F32 attachment_size_factor = llmax(1.f, att_size_factor);
  4283. radius = llmax(1.f, mDrawable->getRadius()) * attachment_size_factor;
  4284. }
  4285. else
  4286. {
  4287. radius = mDrawable->getRadius();
  4288. radius *= 1.f + mDrawable->mDistanceWRTCamera * dist_factor().mV[1];
  4289. radius += mDrawable->mDistanceWRTCamera * dist_factor().mV[0];
  4290. }
  4291. return llclamp(radius, 0.5f, 256.f);
  4292. }
  4293. const LLVector3 LLVOVolume::getPivotPositionAgent() const
  4294. {
  4295. return mVolumeImpl ? mVolumeImpl->getPivotPosition()
  4296. : LLViewerObject::getPivotPositionAgent();
  4297. }
  4298. void LLVOVolume::onShift(const LLVector4a& shift_vector)
  4299. {
  4300. if (mVolumeImpl)
  4301. {
  4302. mVolumeImpl->onShift(shift_vector);
  4303. }
  4304. updateRelativeXform();
  4305. }
  4306. const LLMatrix4& LLVOVolume::getWorldMatrix(LLXformMatrix* xform) const
  4307. {
  4308. return mVolumeImpl ? mVolumeImpl->getWorldMatrix(xform)
  4309. : xform->getWorldMatrix();
  4310. }
  4311. //virtual
  4312. void LLVOVolume::markForUpdate(bool rebuild_all)
  4313. {
  4314. if (mDrawable.notNull())
  4315. {
  4316. shrinkWrap();
  4317. }
  4318. LLViewerObject::markForUpdate(rebuild_all);
  4319. mVolumeChanged = true;
  4320. }
  4321. LLVector3 LLVOVolume::agentPositionToVolume(const LLVector3& pos) const
  4322. {
  4323. LLVector3 ret = pos - getRenderPosition();
  4324. ret = ret * ~getRenderRotation();
  4325. if (!isVolumeGlobal())
  4326. {
  4327. LLVector3 obj_scale = getScale();
  4328. LLVector3 inv_obj_scale(1.f / obj_scale.mV[VX], 1.f / obj_scale.mV[VY],
  4329. 1.f / obj_scale.mV[VZ]);
  4330. ret.scaleVec(inv_obj_scale);
  4331. }
  4332. return ret;
  4333. }
  4334. LLVector3 LLVOVolume::agentDirectionToVolume(const LLVector3& dir) const
  4335. {
  4336. LLVector3 ret = dir * ~getRenderRotation();
  4337. LLVector3 obj_scale = isVolumeGlobal() ? LLVector3(1,1,1) : getScale();
  4338. ret.scaleVec(obj_scale);
  4339. return ret;
  4340. }
  4341. LLVector3 LLVOVolume::volumePositionToAgent(const LLVector3& dir) const
  4342. {
  4343. LLVector3 ret = dir;
  4344. if (!isVolumeGlobal())
  4345. {
  4346. LLVector3 obj_scale = getScale();
  4347. ret.scaleVec(obj_scale);
  4348. }
  4349. ret *= getRenderRotation();
  4350. ret += getRenderPosition();
  4351. return ret;
  4352. }
  4353. LLVector3 LLVOVolume::volumeDirectionToAgent(const LLVector3& dir) const
  4354. {
  4355. LLVector3 ret = dir;
  4356. LLVector3 obj_scale = isVolumeGlobal() ? LLVector3(1.f, 1.f, 1.f)
  4357. : getScale();
  4358. LLVector3 inv_obj_scale(1.f / obj_scale.mV[VX], 1.f / obj_scale.mV[VY],
  4359. 1.f / obj_scale.mV[VZ]);
  4360. ret.scaleVec(inv_obj_scale);
  4361. ret = ret * getRenderRotation();
  4362. return ret;
  4363. }
  4364. bool LLVOVolume::lineSegmentIntersect(const LLVector4a& start,
  4365. const LLVector4a& end,
  4366. S32 face,
  4367. bool pick_transparent,
  4368. bool pick_rigged,
  4369. S32* face_hitp,
  4370. LLVector4a* intersection,
  4371. LLVector2* tex_coord,
  4372. LLVector4a* normal,
  4373. LLVector4a* tangent)
  4374. {
  4375. if (!mCanSelect || mDrawable.isNull() || mDrawable->isDead() ||
  4376. #if 0
  4377. (gSelectMgr.mHideSelectedObjects && isSelected()) ||
  4378. #endif
  4379. !gPipeline.hasRenderType(mDrawable->getRenderType()))
  4380. {
  4381. return false;
  4382. }
  4383. LLVolume* volp = getVolume();
  4384. if (!volp)
  4385. {
  4386. return false;
  4387. }
  4388. bool transform = true;
  4389. if (mDrawable->isState(LLDrawable::RIGGED))
  4390. {
  4391. LLVOAvatar* avatarp = getAvatar();
  4392. if (!avatarp || avatarp->isDead())
  4393. {
  4394. // Cannot intersect a rigged attachment associated with a NULL or
  4395. // dead avatar. HB
  4396. llwarns << (avatarp ? "Dead" : "NULL")
  4397. << " avatar for intersected rigged volume." << llendl;
  4398. clearRiggedVolume();
  4399. return false;
  4400. }
  4401. if (pick_rigged || (avatarp->isSelf() && LLFloaterTools::isVisible()))
  4402. {
  4403. updateRiggedVolume(true, LLRiggedVolume::DO_NOT_UPDATE_FACES);
  4404. volp = mRiggedVolume;
  4405. transform = false;
  4406. }
  4407. else
  4408. {
  4409. // Cannot pick rigged attachments on other avatars or when not in
  4410. // build mode
  4411. return false;
  4412. }
  4413. }
  4414. LLVector4a local_start = start;
  4415. LLVector4a local_end = end;
  4416. if (transform)
  4417. {
  4418. LLVector3 v_start(start.getF32ptr());
  4419. LLVector3 v_end(end.getF32ptr());
  4420. v_start = agentPositionToVolume(v_start);
  4421. v_end = agentPositionToVolume(v_end);
  4422. local_start.load3(v_start.mV);
  4423. local_end.load3(v_end.mV);
  4424. }
  4425. LLVector4a p, n, tn;
  4426. LLVector2 tc;
  4427. if (intersection)
  4428. {
  4429. p = *intersection;
  4430. }
  4431. if (tex_coord)
  4432. {
  4433. tc = *tex_coord;
  4434. }
  4435. if (normal)
  4436. {
  4437. n = *normal;
  4438. }
  4439. if (tangent)
  4440. {
  4441. tn = *tangent;
  4442. }
  4443. S32 start_face, end_face;
  4444. if (face == -1)
  4445. {
  4446. start_face = 0;
  4447. end_face = volp->getNumVolumeFaces();
  4448. }
  4449. else
  4450. {
  4451. start_face = face;
  4452. end_face = face + 1;
  4453. }
  4454. pick_transparent |= isHiglightedOrBeacon();
  4455. bool ret = false;
  4456. S32 face_hit = -1;
  4457. bool special_cursor = specialHoverCursor();
  4458. S32 num_faces = mDrawable->getNumFaces();
  4459. for (S32 i = start_face; i < end_face; ++i)
  4460. {
  4461. if (!special_cursor && !pick_transparent && getTE(i) &&
  4462. getTE(i)->isTransparent())
  4463. {
  4464. // Do not attempt to pick completely transparent faces unless
  4465. // pick_transparent is true
  4466. continue;
  4467. }
  4468. // This calculates the bounding box of the skinned mesh from scratch.
  4469. // It is actually quite expensive, but not nearly as expensive as
  4470. // building a full octree. rebuild_face_octrees = false because an
  4471. // octree for this face will be built later only if needed for narrow
  4472. // phase picking.
  4473. updateRiggedVolume(true, i, false);
  4474. face_hit = volp->lineSegmentIntersect(local_start, local_end, i, &p,
  4475. &tc, &n, &tn);
  4476. if (face_hit < 0 || face_hit >= num_faces)
  4477. {
  4478. continue;
  4479. }
  4480. LLFace* face = mDrawable->getFace(face_hit);
  4481. if (!face)
  4482. {
  4483. continue;
  4484. }
  4485. bool ignore_alpha = false;
  4486. const LLTextureEntry* tep = face->getTextureEntry();
  4487. if (tep)
  4488. {
  4489. LLMaterial* matp = tep->getMaterialParams();
  4490. if (matp)
  4491. {
  4492. U8 mode = matp->getDiffuseAlphaMode();
  4493. if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE ||
  4494. mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE ||
  4495. (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK &&
  4496. matp->getAlphaMaskCutoff() == 0))
  4497. {
  4498. ignore_alpha = true;
  4499. }
  4500. }
  4501. }
  4502. if (ignore_alpha || pick_transparent || !face->getTexture() ||
  4503. !face->getTexture()->hasGLTexture() ||
  4504. face->getTexture()->getMask(face->surfaceToTexture(tc, p, n)))
  4505. {
  4506. local_end = p;
  4507. if (face_hitp)
  4508. {
  4509. *face_hitp = face_hit;
  4510. }
  4511. if (intersection)
  4512. {
  4513. if (transform)
  4514. {
  4515. LLVector3 v_p(p.getF32ptr());
  4516. // Must map back to agent space:
  4517. intersection->load3(volumePositionToAgent(v_p).mV);
  4518. }
  4519. else
  4520. {
  4521. *intersection = p;
  4522. }
  4523. }
  4524. if (normal)
  4525. {
  4526. if (transform)
  4527. {
  4528. LLVector3 v_n(n.getF32ptr());
  4529. normal->load3(volumeDirectionToAgent(v_n).mV);
  4530. }
  4531. else
  4532. {
  4533. *normal = n;
  4534. }
  4535. (*normal).normalize3fast();
  4536. }
  4537. if (tangent)
  4538. {
  4539. if (transform)
  4540. {
  4541. LLVector3 v_tn(tn.getF32ptr());
  4542. LLVector4a trans_tangent;
  4543. trans_tangent.load3(volumeDirectionToAgent(v_tn).mV);
  4544. LLVector4Logical mask;
  4545. mask.clear();
  4546. mask.setElement<3>();
  4547. tangent->setSelectWithMask(mask, tn, trans_tangent);
  4548. }
  4549. else
  4550. {
  4551. *tangent = tn;
  4552. }
  4553. (*tangent).normalize3fast();
  4554. }
  4555. if (tex_coord)
  4556. {
  4557. *tex_coord = tc;
  4558. }
  4559. ret = true;
  4560. }
  4561. }
  4562. return ret;
  4563. }
  4564. bool LLVOVolume::treatAsRigged()
  4565. {
  4566. return isSelected() && mDrawable.notNull() &&
  4567. mDrawable->isState(LLDrawable::RIGGED) &&
  4568. (isAttachment() || isAnimatedObject());
  4569. }
  4570. void LLVOVolume::clearRiggedVolume()
  4571. {
  4572. if (mRiggedVolume.notNull())
  4573. {
  4574. mRiggedVolume = NULL;
  4575. updateRelativeXform();
  4576. }
  4577. }
  4578. // Updates mRiggedVolume to match current animation frame of avatar. Also
  4579. // updates position/size in octree.
  4580. void LLVOVolume::updateRiggedVolume(bool force_treat_as_rigged, S32 face_index,
  4581. bool rebuild_face_octrees)
  4582. {
  4583. if (isDead())
  4584. {
  4585. return;
  4586. }
  4587. if (!force_treat_as_rigged && !treatAsRigged())
  4588. {
  4589. clearRiggedVolume();
  4590. return;
  4591. }
  4592. LLVolume* volp = getVolume();
  4593. if (!volp) return;
  4594. const LLMeshSkinInfo* skinp = getSkinInfo();
  4595. if (!skinp)
  4596. {
  4597. clearRiggedVolume();
  4598. return;
  4599. }
  4600. LLVOAvatar* avatarp = getAvatar();
  4601. if (!avatarp || avatarp->isDead())
  4602. {
  4603. clearRiggedVolume();
  4604. return;
  4605. }
  4606. if (!mRiggedVolume)
  4607. {
  4608. LLVolumeParams p;
  4609. mRiggedVolume = new LLRiggedVolume(p);
  4610. updateRelativeXform();
  4611. }
  4612. mRiggedVolume->update(skinp, avatarp, volp, face_index,
  4613. rebuild_face_octrees);
  4614. }
  4615. void LLRiggedVolume::update(const LLMeshSkinInfo* skinp, LLVOAvatar* avatarp,
  4616. const LLVolume* volp, S32 face_index,
  4617. bool rebuild_face_octrees)
  4618. {
  4619. LL_FAST_TIMER(FTM_UPDATE_RIGGED_VOLUME);
  4620. bool copy = volp->getNumVolumeFaces() != getNumVolumeFaces();
  4621. if (!copy)
  4622. {
  4623. for (S32 i = 0, count = volp->getNumVolumeFaces(); i < count; ++i)
  4624. {
  4625. const LLVolumeFace& src_face = volp->getVolumeFace(i);
  4626. const LLVolumeFace& dst_face = getVolumeFace(i);
  4627. if (src_face.mNumIndices != dst_face.mNumIndices ||
  4628. src_face.mNumVertices != dst_face.mNumVertices)
  4629. {
  4630. copy = true;
  4631. break;
  4632. }
  4633. }
  4634. }
  4635. if (copy)
  4636. {
  4637. copyVolumeFaces(volp);
  4638. }
  4639. else if (!avatarp || avatarp->isDead() ||
  4640. avatarp->getMotionController().isReallyPaused())
  4641. {
  4642. return;
  4643. }
  4644. S32 face_begin, face_end;
  4645. if (face_index == DO_NOT_UPDATE_FACES)
  4646. {
  4647. face_begin = face_end = 0;
  4648. }
  4649. else if (face_index == UPDATE_ALL_FACES)
  4650. {
  4651. face_begin = 0;
  4652. face_end = volp->getNumVolumeFaces();
  4653. }
  4654. else
  4655. {
  4656. face_begin = face_index;
  4657. face_end = face_begin + 1;
  4658. }
  4659. // Build matrix palette
  4660. U32 count = 0;
  4661. const LLMatrix4a* matp = avatarp->getRiggedMatrix4a(skinp, count);
  4662. LLVector4a t, dst, size;
  4663. LLMatrix4a final_mat, bind_shape_matrix;
  4664. bind_shape_matrix.loadu(skinp->mBindShapeMatrix);
  4665. for (S32 i = face_begin; i < face_end; ++i)
  4666. {
  4667. const LLVolumeFace& vol_face = volp->getVolumeFace(i);
  4668. LLVolumeFace& dst_face = mVolumeFaces[i];
  4669. LLVector4a* weight = vol_face.mWeights;
  4670. if (!weight) continue;
  4671. LLSkinningUtil::checkSkinWeights(weight, dst_face.mNumVertices, skinp);
  4672. LLVector4a* pos = dst_face.mPositions;
  4673. if (pos && dst_face.mExtents)
  4674. {
  4675. for (S32 j = 0; j < dst_face.mNumVertices; ++j)
  4676. {
  4677. LLSkinningUtil::getPerVertexSkinMatrix(weight[j], matp,
  4678. final_mat);
  4679. LLVector4a& v = vol_face.mPositions[j];
  4680. bind_shape_matrix.affineTransform(v, t);
  4681. final_mat.affineTransform(t, dst);
  4682. pos[j] = dst;
  4683. }
  4684. // Update bounding box
  4685. LLVector4a& min = dst_face.mExtents[0];
  4686. LLVector4a& max = dst_face.mExtents[1];
  4687. min = pos[0];
  4688. max = pos[1];
  4689. for (S32 j = 1; j < dst_face.mNumVertices; ++j)
  4690. {
  4691. min.setMin(min, pos[j]);
  4692. max.setMax(max, pos[j]);
  4693. }
  4694. dst_face.mCenter->setAdd(dst_face.mExtents[0],
  4695. dst_face.mExtents[1]);
  4696. dst_face.mCenter->mul(0.5f);
  4697. if (rebuild_face_octrees)
  4698. {
  4699. LL_FAST_TIMER(FTM_RIGGED_OCTREE);
  4700. dst_face.destroyOctree();
  4701. dst_face.createOctree();
  4702. }
  4703. }
  4704. }
  4705. }
  4706. U32 LLVOVolume::getPartitionType() const
  4707. {
  4708. if (isHUDAttachment())
  4709. {
  4710. return LLViewerRegion::PARTITION_HUD;
  4711. }
  4712. if (isAnimatedObject() && getPuppetAvatar())
  4713. {
  4714. return LLViewerRegion::PARTITION_PUPPET;
  4715. }
  4716. if (isAttachment())
  4717. {
  4718. return LLViewerRegion::PARTITION_AVATAR;
  4719. }
  4720. return LLViewerRegion::PARTITION_VOLUME;
  4721. }
  4722. ///////////////////////////////////////////////////////////////////////////////
  4723. // LLVolumePartition class (declared in llspatialpartition.h)
  4724. ///////////////////////////////////////////////////////////////////////////////
  4725. LLVolumePartition::LLVolumePartition(LLViewerRegion* regionp)
  4726. : LLSpatialPartition(LLVOVolume::VERTEX_DATA_MASK, true, regionp),
  4727. LLVolumeGeometryManager()
  4728. {
  4729. mLODPeriod = 32;
  4730. mDepthMask = false;
  4731. mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
  4732. mPartitionType = LLViewerRegion::PARTITION_VOLUME;
  4733. mSlopRatio = 0.25f;
  4734. }
  4735. ///////////////////////////////////////////////////////////////////////////////
  4736. // LLVolumeBridge class (declared in llspatialpartition.h)
  4737. ///////////////////////////////////////////////////////////////////////////////
  4738. LLVolumeBridge::LLVolumeBridge(LLDrawable* drawablep, LLViewerRegion* regionp)
  4739. : LLSpatialBridge(drawablep, true, LLVOVolume::VERTEX_DATA_MASK, regionp),
  4740. LLVolumeGeometryManager()
  4741. {
  4742. mDepthMask = false;
  4743. mLODPeriod = 32;
  4744. mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
  4745. mPartitionType = LLViewerRegion::PARTITION_BRIDGE;
  4746. mSlopRatio = 0.25f;
  4747. }
  4748. ///////////////////////////////////////////////////////////////////////////////
  4749. // LLAvatarBridge class (declared in llspatialpartition.h)
  4750. ///////////////////////////////////////////////////////////////////////////////
  4751. LLAvatarBridge::LLAvatarBridge(LLDrawable* drawablep,
  4752. LLViewerRegion* regionp)
  4753. : LLVolumeBridge(drawablep, regionp)
  4754. {
  4755. mDrawableType = LLPipeline::RENDER_TYPE_AVATAR;
  4756. mPartitionType = LLViewerRegion::PARTITION_AVATAR;
  4757. }
  4758. ///////////////////////////////////////////////////////////////////////////////
  4759. // LLPuppetBridge class (declared in llspatialpartition.h)
  4760. ///////////////////////////////////////////////////////////////////////////////
  4761. LLPuppetBridge::LLPuppetBridge(LLDrawable* drawablep,
  4762. LLViewerRegion* regionp)
  4763. : LLVolumeBridge(drawablep, regionp)
  4764. {
  4765. mDrawableType = LLPipeline::RENDER_TYPE_PUPPET;
  4766. mPartitionType = LLViewerRegion::PARTITION_PUPPET;
  4767. }
  4768. ///////////////////////////////////////////////////////////////////////////////
  4769. // LLVolumeGeometryManager class (declared in llspatialpartition.h)
  4770. ///////////////////////////////////////////////////////////////////////////////
  4771. LLVolumeGeometryManager::LLVolumeGeometryManager()
  4772. : LLGeometryManager()
  4773. {
  4774. if (sInstanceCount == 0)
  4775. {
  4776. allocateFaces(MAX_FACE_COUNT);
  4777. }
  4778. ++sInstanceCount;
  4779. }
  4780. LLVolumeGeometryManager::~LLVolumeGeometryManager()
  4781. {
  4782. llassert(sInstanceCount > 0);
  4783. --sInstanceCount;
  4784. if (sInstanceCount <= 0)
  4785. {
  4786. freeFaces();
  4787. sInstanceCount = 0;
  4788. }
  4789. }
  4790. void LLVolumeGeometryManager::allocateFaces(U32 max_face_count)
  4791. {
  4792. size_t bytes = max_face_count * sizeof(LLFace*);
  4793. for (U32 i = 0; i < 2; ++i)
  4794. {
  4795. sFullbrightFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4796. sBumpFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4797. sSimpleFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4798. sNormFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4799. sSpecFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4800. sNormSpecFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4801. sPbrFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4802. sAlphaFaces[i] = (LLFace**)ll_aligned_malloc(bytes, 64);
  4803. }
  4804. }
  4805. void LLVolumeGeometryManager::freeFaces()
  4806. {
  4807. for (U32 i = 0; i < 2; ++i)
  4808. {
  4809. ll_aligned_free(sFullbrightFaces[i]);
  4810. ll_aligned_free(sBumpFaces[i]);
  4811. ll_aligned_free(sSimpleFaces[i]);
  4812. ll_aligned_free(sNormFaces[i]);
  4813. ll_aligned_free(sSpecFaces[i]);
  4814. ll_aligned_free(sNormSpecFaces[i]);
  4815. ll_aligned_free(sPbrFaces[i]);
  4816. ll_aligned_free(sAlphaFaces[i]);
  4817. sFullbrightFaces[i] = NULL;
  4818. sBumpFaces[i] = NULL;
  4819. sSimpleFaces[i] = NULL;
  4820. sNormFaces[i] = NULL;
  4821. sSpecFaces[i] = NULL;
  4822. sNormSpecFaces[i] = NULL;
  4823. sPbrFaces[i] = NULL;
  4824. sAlphaFaces[i] = NULL;
  4825. }
  4826. }
  4827. // Helper function for opacity test during rendering
  4828. static bool opaque_face(const LLFace* facep, const LLTextureEntry* tep)
  4829. {
  4830. if (facep->isState(LLFace::USE_FACE_COLOR))
  4831. {
  4832. return facep->getFaceColor().mV[3] >= 0.999f;
  4833. }
  4834. return tep->isOpaque();
  4835. }
  4836. void LLVolumeGeometryManager::registerFace(LLSpatialGroup* groupp,
  4837. LLFace* facep, U32 type)
  4838. {
  4839. LL_FAST_TIMER(FTM_REGISTER_FACE);
  4840. if (!facep || !groupp) return; // Paranoia
  4841. if (facep->getViewerObject()->isSelected() &&
  4842. //MK
  4843. (!gRLenabled || !gRLInterface.mContainsEdit) &&
  4844. //mk
  4845. gSelectMgr.mHideSelectedObjects)
  4846. {
  4847. return;
  4848. }
  4849. const LLTextureEntry* tep = facep->getTextureEntry();
  4850. if (!tep)
  4851. {
  4852. llwarns_sparse << "NULL texture entry pointer. Aborting." << llendl;
  4853. return;
  4854. }
  4855. bool rigged = facep->isState(LLFace::RIGGED);
  4856. // Add face to drawmap
  4857. LLSpatialGroup::drawmap_elem_t& draw_vec =
  4858. groupp->mDrawMap[rigged ? type + 1 : type];
  4859. bool fullbright = type == LLRenderPass::PASS_FULLBRIGHT ||
  4860. type == LLRenderPass::PASS_INVISIBLE ||
  4861. type == LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK ||
  4862. (type == LLRenderPass::PASS_ALPHA &&
  4863. facep->isState(LLFace::FULLBRIGHT)) ||
  4864. tep->getFullbright();
  4865. if (!fullbright && type != LLRenderPass::PASS_GLOW &&
  4866. !facep->getVertexBuffer()->hasDataType(LLVertexBuffer::TYPE_NORMAL))
  4867. {
  4868. llwarns_sparse << "Non fullbright face has no normals !" << llendl;
  4869. return;
  4870. }
  4871. F32 vsize = facep->getVirtualSize(); // *TODO: adjust by texture scale ?
  4872. const LLMatrix4* tex_mat = NULL;
  4873. if (vsize >= MIN_TEX_ANIM_SIZE && facep->isState(LLFace::TEXTURE_ANIM))
  4874. {
  4875. tex_mat = facep->mTextureMatrix;
  4876. }
  4877. LLDrawable* drawable = facep->getDrawable();
  4878. if (!drawable) return; // Paranoia
  4879. const LLMatrix4* model_mat = NULL;
  4880. if (!rigged) // Rigged meshes ignore their model matrix
  4881. {
  4882. if (drawable->isState(LLDrawable::ANIMATED_CHILD))
  4883. {
  4884. model_mat = &drawable->getWorldMatrix();
  4885. }
  4886. else if (drawable->isActive())
  4887. {
  4888. model_mat = &drawable->getRenderMatrix();
  4889. }
  4890. else if (drawable->getRegion())
  4891. {
  4892. model_mat = &(drawable->getRegion()->mRenderMatrix);
  4893. }
  4894. #if 1
  4895. if (model_mat && model_mat->isIdentity())
  4896. {
  4897. model_mat = NULL;
  4898. }
  4899. #endif
  4900. }
  4901. U8 bump = type == LLRenderPass::PASS_BUMP ||
  4902. type == LLRenderPass::PASS_POST_BUMP ? tep->getBumpmap() : 0;
  4903. U8 shiny = tep->getShiny();
  4904. U8 index = facep->getTextureIndex();
  4905. LLViewerTexture* texp = facep->getTexture();
  4906. bool is_media_tex = facep->hasMedia() ||
  4907. (texp &&
  4908. texp->getType() == LLViewerTexture::MEDIA_TEXTURE);
  4909. LLMaterial* matp = tep->getMaterialParams().get();
  4910. bool has_alm = !is_media_tex && matp;
  4911. LLGLTFMaterial* rmatp = tep->getGLTFRenderMaterial();
  4912. LLFetchedGLTFMaterial* gltfp = rmatp ? rmatp->asFetched() : NULL;
  4913. bool has_pbr = !is_media_tex && gltfp;
  4914. // When we do have a PBR material, check to see if we also have a legacy
  4915. // material or a non-default diffuse texture as fallbacks for rendering in
  4916. // non-PBR viewers. HB
  4917. bool has_legacy = has_pbr && (has_alm || !tep->isDefault());
  4918. // See if this face pertains to an attachment (used for RLV below) and to
  4919. // one of the agent's attachments (used for materials types accounting). HB
  4920. LLViewerObject* vobjp = facep->getViewerObject();
  4921. bool is_attachment = vobjp->isAttachment();
  4922. bool agent_attachment = is_attachment && vobjp->permYouOwner();
  4923. //MK
  4924. // If @camtextures is set, do not show any texture in world (but show
  4925. // attachments normally)
  4926. if (!is_media_tex && gRLenabled && gRLInterface.mContainsCamTextures &&
  4927. gRLInterface.mCamTexturesCustom.notNull() && !is_attachment)
  4928. {
  4929. // Switch to the cam texture and white color. This replaces the
  4930. // original hack which assigned mCamTexturesCustom to texp, and which
  4931. // did not properly work... HB
  4932. if (!facep->isState(LLFace::USE_RLV_TEXTURE))
  4933. {
  4934. facep->switchDiffuseTex(gRLInterface.mCamTexturesCustom->getID());
  4935. facep->setFaceColor(LLColor4::white);
  4936. facep->setState(LLFace::USE_RLV_TEXTURE);
  4937. gRLInterface.mNeedsVisibilityRefresh = true;
  4938. }
  4939. // Do not show any material, just the diffuse texture. HB
  4940. matp = NULL;
  4941. gltfp = NULL;
  4942. }
  4943. // No @camtextures restriction: restore face texture if needed. HB
  4944. else if (facep->isState(LLFace::USE_RLV_TEXTURE))
  4945. {
  4946. // Reset to diffuse texture and color
  4947. facep->switchDiffuseTex(tep->getID());
  4948. facep->unsetFaceColor();
  4949. facep->clearState(LLFace::USE_RLV_TEXTURE);
  4950. gRLInterface.mNeedsVisibilityRefresh = true;
  4951. }
  4952. //mk
  4953. // *HACK: when we have a GLTF material and are not rendering in PBR mode,
  4954. // and the face does not have any fallback diffuse texture set, try and
  4955. // use the base color texture for the diffuse channel.
  4956. // Note: we use the USE_FACE_COLOR state as a marker for overridden diffuse
  4957. // texture; this is OK, since the only other use for this state is with sky
  4958. // and classic cloud faces, which do not bear a GLTF material. HB
  4959. bool has_basecolor = false;
  4960. static LLCachedControl<U32> use_basecolor(gSavedSettings,
  4961. "RenderUseBasecolorAsDiffuse");
  4962. // Do NOT touch the diffuse texture when it is bearing a media texture,
  4963. // since it then itself makes use of switchTexture() on the diffuse
  4964. // channel, which would cause conflicts. Also, when we have a legacy
  4965. // material, we should not either override its diffuse texture (considering
  4966. // that in this case the creator did provide an adequate legacy material in
  4967. // excesss of the PBR material). HB
  4968. bool may_touch_diffuse = !is_media_tex && gltfp && !matp &&
  4969. !gUsePBRShaders;
  4970. const LLUUID& basecolor_id = may_touch_diffuse ? gltfp->getBaseColorId()
  4971. : LLUUID::null;
  4972. bool got_base_color_tex = basecolor_id.notNull();
  4973. if (may_touch_diffuse && use_basecolor &&
  4974. (got_base_color_tex || use_basecolor > 2) &&
  4975. // Note: we do not apply our hack while editing this face: we want to
  4976. // still be able to see and edit the diffuse texture on GLTF-enabled
  4977. // faces. HB
  4978. (!tep->isSelected() || !LLFloaterTools::isVisible()))
  4979. {
  4980. if (got_base_color_tex && (use_basecolor > 1 || !has_legacy))
  4981. {
  4982. // Set to base color texture and color
  4983. facep->switchDiffuseTex(basecolor_id);
  4984. facep->setFaceColor(gltfp->mBaseColor);
  4985. has_basecolor = true;
  4986. }
  4987. else if (use_basecolor > 2)
  4988. {
  4989. // Set texture to blank and color to base color
  4990. facep->switchDiffuseTex(IMG_BLANK);
  4991. facep->setFaceColor(gltfp->mBaseColor);
  4992. has_basecolor = true;
  4993. }
  4994. else if (facep->isState(LLFace::USE_FACE_COLOR))
  4995. {
  4996. // Reset to diffuse texture and color
  4997. facep->switchDiffuseTex(tep->getID());
  4998. facep->unsetFaceColor();
  4999. }
  5000. }
  5001. else if (may_touch_diffuse && facep->isState(LLFace::USE_FACE_COLOR))
  5002. {
  5003. // Reset to diffuse texture and color
  5004. facep->switchDiffuseTex(tep->getID());
  5005. facep->unsetFaceColor();
  5006. }
  5007. // Render without the GLTF material when we are not in PBR mode. HB
  5008. if (!gUsePBRShaders)
  5009. {
  5010. gltfp = NULL;
  5011. }
  5012. LLUUID mat_id;
  5013. if (gltfp)
  5014. {
  5015. mat_id = gltfp->getHash();
  5016. if (!is_media_tex)
  5017. {
  5018. // No media texture, face texture will be unused
  5019. texp = NULL;
  5020. }
  5021. // Do not use any legacy material when we do have a PBR material to
  5022. // render with. HB
  5023. matp = NULL;
  5024. }
  5025. else if (matp)
  5026. {
  5027. #if 0 // No need to slow down rendering with a live hashing of each
  5028. // material ! HB
  5029. mat_id = matp->getHash();
  5030. #else // Instead, just copy the material Id into mat_id. HB
  5031. mat_id = tep->getMaterialID().asUUID();
  5032. #endif
  5033. }
  5034. U32 shader_mask = 0xFFFFFFFF; // No shader
  5035. if (matp)
  5036. {
  5037. bool is_alpha = facep->getPoolType() == LLDrawPool::POOL_ALPHA ||
  5038. !opaque_face(facep, tep);
  5039. if (type == LLRenderPass::PASS_ALPHA)
  5040. {
  5041. shader_mask =
  5042. matp->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_BLEND,
  5043. is_alpha);
  5044. }
  5045. else
  5046. {
  5047. shader_mask =
  5048. matp->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_DEFAULT,
  5049. is_alpha);
  5050. }
  5051. }
  5052. S32 idx = draw_vec.size() - 1;
  5053. LLDrawInfo* dinfop = idx >= 0 ? draw_vec[idx].get() : NULL;
  5054. bool batchable = false;
  5055. if (dinfop && index < FACE_DO_NOT_BATCH_TEXTURES &&
  5056. facep->canBatchTexture())
  5057. {
  5058. if (index < dinfop->mTextureList.size())
  5059. {
  5060. if (dinfop->mTextureList[index].isNull())
  5061. {
  5062. batchable = true;
  5063. dinfop->mTextureList[index] = texp;
  5064. dinfop->mTextureListVSize[index] = vsize;
  5065. }
  5066. else if (dinfop->mTextureList[index] == texp)
  5067. {
  5068. // This face's texture index can be used with this batch
  5069. batchable = true;
  5070. if (dinfop->mTextureListVSize[index] < vsize)
  5071. {
  5072. dinfop->mTextureListVSize[index] = vsize;
  5073. }
  5074. }
  5075. }
  5076. else
  5077. {
  5078. // Texture list can be expanded to fit this texture index
  5079. batchable = true;
  5080. }
  5081. }
  5082. if (dinfop &&
  5083. dinfop->mVertexBuffer == facep->getVertexBuffer() &&
  5084. dinfop->mEnd == facep->getGeomIndex() - 1 &&
  5085. (batchable || dinfop->mTexture == texp) &&
  5086. #if LL_DARWIN
  5087. (S32)(dinfop->mEnd - dinfop->mStart +
  5088. facep->getGeomCount()) <= gGLManager.mGLMaxVertexRange &&
  5089. (S32)(dinfop->mCount +
  5090. facep->getIndicesCount()) <= gGLManager.mGLMaxIndexRange &&
  5091. #endif
  5092. dinfop->mMaterialID == mat_id &&
  5093. dinfop->mFullbright == fullbright &&
  5094. dinfop->mBump == bump &&
  5095. // Need to break batches when a material is shared, but legacy shiny is
  5096. // different
  5097. (!matp || dinfop->mShiny == shiny) &&
  5098. dinfop->mTextureMatrix == tex_mat &&
  5099. dinfop->mModelMatrix == model_mat &&
  5100. dinfop->mShaderMask == shader_mask &&
  5101. dinfop->mAvatar == facep->mAvatar &&
  5102. dinfop->getSkinHash() == facep->getSkinHash())
  5103. {
  5104. dinfop->mCount += facep->getIndicesCount();
  5105. dinfop->mEnd += facep->getGeomCount();
  5106. dinfop->mVSize = llmax(dinfop->mVSize, vsize);
  5107. if (index < FACE_DO_NOT_BATCH_TEXTURES &&
  5108. index >= dinfop->mTextureList.size())
  5109. {
  5110. dinfop->mTextureList.resize(index + 1);
  5111. dinfop->mTextureListVSize.resize(index + 1);
  5112. dinfop->mTextureList[index] = texp;
  5113. dinfop->mTextureListVSize[index] = vsize;
  5114. }
  5115. dinfop->validate();
  5116. update_min_max(dinfop->mExtents[0], dinfop->mExtents[1],
  5117. facep->mExtents[0]);
  5118. update_min_max(dinfop->mExtents[0], dinfop->mExtents[1],
  5119. facep->mExtents[1]);
  5120. // Remember if this face pertains to one of the agent's avatar
  5121. // attachments. HB
  5122. dinfop->mIsAgentAttachment = agent_attachment;
  5123. // Store material usage stats for this face. HB
  5124. dinfop->mHasALM = has_alm;
  5125. dinfop->mHasPBR = has_pbr;
  5126. dinfop->mHasLegacyFallback = has_legacy;
  5127. dinfop->mHasBasecolorFallback = has_basecolor;
  5128. }
  5129. else
  5130. {
  5131. U32 start = facep->getGeomIndex();
  5132. U32 end = start + facep->getGeomCount() - 1;
  5133. U32 offset = facep->getIndicesStart();
  5134. U32 count = facep->getIndicesCount();
  5135. LLPointer<LLDrawInfo> draw_info =
  5136. new LLDrawInfo(start, end, count, offset, texp,
  5137. facep->getVertexBuffer(), fullbright, bump);
  5138. draw_vec.push_back(draw_info);
  5139. draw_info->mVSize = vsize;
  5140. draw_info->mTextureMatrix = tex_mat;
  5141. draw_info->mModelMatrix = model_mat;
  5142. draw_info->mBump = bump;
  5143. draw_info->mShiny = shiny;
  5144. static const F32 alpha[4] = { 0.f, 0.25f, 0.5f, 0.75f };
  5145. F32 spec = alpha[shiny & TEM_SHINY_MASK];
  5146. draw_info->mSpecColor.set(spec, spec, spec, spec);
  5147. draw_info->mEnvIntensity = spec;
  5148. draw_info->mSpecularMap = NULL;
  5149. draw_info->mMaterial = matp;
  5150. draw_info->mGLTFMaterial = gltfp;
  5151. draw_info->mShaderMask = shader_mask;
  5152. draw_info->mAvatar = facep->mAvatar;
  5153. draw_info->mSkinInfo = facep->mSkinInfo;
  5154. // Remember if this face pertains to one of the agent's avatar
  5155. // attachments. HB
  5156. draw_info->mIsAgentAttachment = agent_attachment;
  5157. // Store material usage stats for this face. HB
  5158. draw_info->mHasALM = has_alm;
  5159. draw_info->mHasPBR = has_pbr;
  5160. draw_info->mHasLegacyFallback = has_legacy;
  5161. draw_info->mHasBasecolorFallback = has_basecolor;
  5162. if (gltfp)
  5163. {
  5164. // Just remember the material Id; render pools will reference the
  5165. // GLTF material.
  5166. draw_info->mMaterialID = mat_id;
  5167. }
  5168. else if (matp)
  5169. {
  5170. // We have a material. Update our draw info accordingly.
  5171. draw_info->mMaterialID = mat_id;
  5172. S32 te_offset = facep->getTEOffset();
  5173. if (matp->getSpecularID().notNull())
  5174. {
  5175. const LLColor4U& spec_col = matp->getSpecularLightColor();
  5176. F32 alpha = (F32)matp->getSpecularLightExponent() * ONE255TH;
  5177. draw_info->mSpecColor.set(spec_col.mV[0] * ONE255TH,
  5178. spec_col.mV[1] * ONE255TH,
  5179. spec_col.mV[2] * ONE255TH, alpha);
  5180. draw_info->mEnvIntensity = matp->getEnvironmentIntensity() *
  5181. ONE255TH;
  5182. draw_info->mSpecularMap =
  5183. facep->getViewerObject()->getTESpecularMap(te_offset);
  5184. }
  5185. draw_info->mAlphaMaskCutoff = matp->getAlphaMaskCutoff() *
  5186. ONE255TH;
  5187. draw_info->mDiffuseAlphaMode = matp->getDiffuseAlphaMode();
  5188. draw_info->mNormalMap =
  5189. facep->getViewerObject()->getTENormalMap(te_offset);
  5190. }
  5191. else if (type == LLRenderPass::PASS_GRASS)
  5192. {
  5193. draw_info->mAlphaMaskCutoff = 0.5f;
  5194. }
  5195. else
  5196. {
  5197. draw_info->mAlphaMaskCutoff = 0.33f;
  5198. }
  5199. #if 0 // Always populate the draw_info
  5200. if (type == LLRenderPass::PASS_ALPHA)
  5201. #endif
  5202. {
  5203. facep->setDrawInfo(draw_info); // For alpha sorting
  5204. }
  5205. draw_info->mExtents[0] = facep->mExtents[0];
  5206. draw_info->mExtents[1] = facep->mExtents[1];
  5207. if (index < FACE_DO_NOT_BATCH_TEXTURES)
  5208. {
  5209. // Initialize texture list for texture batching
  5210. draw_info->mTextureList.resize(index + 1);
  5211. draw_info->mTextureListVSize.resize(index + 1);
  5212. draw_info->mTextureList[index] = texp;
  5213. draw_info->mTextureListVSize[index] = vsize;
  5214. }
  5215. draw_info->validate();
  5216. }
  5217. }
  5218. // Adds a face pointer to a list of face pointers without going over MAX_COUNT
  5219. template<typename T>
  5220. static inline void add_face(T*** list, U32* count, T* face)
  5221. {
  5222. if (face->isState(LLFace::RIGGED))
  5223. {
  5224. if (count[1] < MAX_FACE_COUNT)
  5225. {
  5226. list[1][count[1]++] = face;
  5227. }
  5228. }
  5229. else if (count[0] < MAX_FACE_COUNT)
  5230. {
  5231. list[0][count[0]++] = face;
  5232. }
  5233. }
  5234. // Returns the index in linkset for a given object (0 for root prim)
  5235. static U32 get_linkset_index(const LLVOVolume* vobjp)
  5236. {
  5237. if (vobjp->isRootEdit())
  5238. {
  5239. return 0;
  5240. }
  5241. U32 idx = 1;
  5242. const LLViewerObject* rootp = vobjp->getRootEdit();
  5243. if (!rootp) // Paranoia
  5244. {
  5245. return idx;
  5246. }
  5247. LLViewerObject::const_child_list_t& child_list = rootp->getChildren();
  5248. for (LLViewerObject::const_child_list_t::const_iterator
  5249. iter = child_list.begin(), end = child_list.end();
  5250. iter != end; ++iter, ++idx)
  5251. {
  5252. if (iter->get() == vobjp)
  5253. {
  5254. break;
  5255. }
  5256. }
  5257. return idx;
  5258. }
  5259. // Helper function for transparency test during rendering
  5260. static bool transparent_face(const LLGLTFMaterial* gltfp, const LLFace* facep,
  5261. const LLTextureEntry* tep)
  5262. {
  5263. if (tep->hasGlow())
  5264. {
  5265. return false;
  5266. }
  5267. if (gltfp)
  5268. {
  5269. return gltfp->mBaseColor.mV[3] < 0.001f;
  5270. }
  5271. if (facep->isState(LLFace::USE_FACE_COLOR))
  5272. {
  5273. return facep->getFaceColor().mV[3] < 0.001f;
  5274. }
  5275. return tep->isTransparent();
  5276. }
  5277. //virtual
  5278. void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* groupp)
  5279. {
  5280. LL_FAST_TIMER(FTM_REBUILD_VBO);
  5281. if (groupp->isDead())
  5282. {
  5283. return;
  5284. }
  5285. if (groupp->changeLOD())
  5286. {
  5287. groupp->mLastUpdateDistance = groupp->mDistance;
  5288. }
  5289. groupp->mLastUpdateViewAngle = groupp->mViewAngle;
  5290. if (!groupp->hasState(LLSpatialGroup::GEOM_DIRTY |
  5291. LLSpatialGroup::ALPHA_DIRTY))
  5292. {
  5293. if (groupp->hasState(LLSpatialGroup::MESH_DIRTY))
  5294. {
  5295. rebuildMesh(groupp);
  5296. }
  5297. return;
  5298. }
  5299. groupp->mBuilt = 1.f;
  5300. LLVOAvatar* voavp = NULL;
  5301. LLVOAvatar* voattachavp = NULL;
  5302. LLSpatialPartition* partp = groupp->getSpatialPartition();
  5303. if (!partp) return; // Paranoia
  5304. LLSpatialBridge* bridge = partp->asBridge();
  5305. LLVOVolume* vovolp = NULL;
  5306. if (bridge)
  5307. {
  5308. LLViewerObject* vobjp =
  5309. bridge->mDrawable ? bridge->mDrawable->getVObj().get() : NULL;
  5310. if (vobjp)
  5311. {
  5312. if (bridge->mAvatar.isNull())
  5313. {
  5314. bridge->mAvatar = vobjp->getAvatar();
  5315. }
  5316. voattachavp = vobjp->getAvatarAncestor();
  5317. vovolp = vobjp->asVolume();
  5318. }
  5319. voavp = bridge->mAvatar;
  5320. }
  5321. if (voattachavp)
  5322. {
  5323. voattachavp->subtractAttachmentBytes(groupp->mGeometryBytes);
  5324. voattachavp->subtractAttachmentArea(groupp->mSurfaceArea);
  5325. }
  5326. if (voavp && voavp != voattachavp)
  5327. {
  5328. voavp->subtractAttachmentBytes(groupp->mGeometryBytes);
  5329. voavp->subtractAttachmentArea(groupp->mSurfaceArea);
  5330. }
  5331. if (vovolp)
  5332. {
  5333. vovolp->updateVisualComplexity();
  5334. }
  5335. groupp->mGeometryBytes = 0;
  5336. groupp->mSurfaceArea = 0.f;
  5337. // Cache object box size since it might be used for determining visibility
  5338. const LLVector4a* bounds = groupp->getObjectBounds();
  5339. groupp->mObjectBoxSize = llmax(bounds[1].getLength3().getF32(), 10.f);
  5340. groupp->clearDrawMap();
  5341. U32 fullbright_count[2] = { 0 };
  5342. U32 bump_count[2] = { 0 };
  5343. U32 simple_count[2] = { 0 };
  5344. U32 alpha_count[2] = { 0 };
  5345. U32 norm_count[2] = { 0 };
  5346. U32 spec_count[2] = { 0 };
  5347. U32 normspec_count[2] = { 0 };
  5348. U32 pbr_count[2] = { 0 };
  5349. U32 vertex_size =
  5350. (U32)LLVertexBuffer::calcVertexSize(partp->mVertexDataMask);
  5351. U32 max_vertices = LLVOVolume::sRenderMaxVBOSize * 1024 / vertex_size;
  5352. max_vertices = llmin(max_vertices, 65535U);
  5353. U32 cur_total = 0;
  5354. static LLCachedControl<U32> render_max_node_size(gSavedSettings,
  5355. "RenderMaxNodeSize");
  5356. U32 max_total = render_max_node_size * 1024U / vertex_size;
  5357. static LLCachedControl<F32> mesh_boost(gSavedSettings,
  5358. "MeshLODBoostFactor");
  5359. F32 mesh_geom_factor = 1.f;
  5360. if (mesh_boost > 1.f)
  5361. {
  5362. mesh_geom_factor =
  5363. 1.f / llmin((F32)mesh_boost * mesh_boost * mesh_boost, 16.f);
  5364. }
  5365. bool use_wl_shaders = gPipeline.canUseWindLightShaders();
  5366. bool debugging_alpha = LLDrawPoolAlpha::sShowDebugAlpha;
  5367. bool emissive = false;
  5368. {
  5369. LL_FAST_TIMER(FTM_REBUILD_VOLUME_FACE_LIST);
  5370. static LLCachedControl<U32> use_basecolor(gSavedSettings,
  5371. "RenderUseBasecolorAsDiffuse");
  5372. // Get all the faces into a list
  5373. for (LLSpatialGroup::element_iter it = groupp->getDataBegin();
  5374. it != groupp->getDataEnd(); ++it)
  5375. {
  5376. LLDrawable* drawablep = (LLDrawable*)(*it)->getDrawable();
  5377. if (!drawablep || drawablep->isDead() ||
  5378. drawablep->isState(LLDrawable::FORCE_INVISIBLE))
  5379. {
  5380. continue;
  5381. }
  5382. LLVOVolume* vobjp = drawablep->getVOVolume();
  5383. if (!vobjp || vobjp->isDead())
  5384. {
  5385. continue;
  5386. }
  5387. LLVolume* volp = vobjp->getVolume();
  5388. if (!volp)
  5389. {
  5390. continue;
  5391. }
  5392. if (gUsePBRShaders || use_basecolor)
  5393. {
  5394. // *HACK: brute force this check every time a drawable gets
  5395. // rebuilt.
  5396. for (S32 i = 0, count = drawablep->getNumFaces(); i < count;
  5397. ++i)
  5398. {
  5399. vobjp->updateTEMaterialTextures(i);
  5400. }
  5401. // Apply any pending material overrides
  5402. gGLTFMaterialList.applyQueuedOverrides(vobjp);
  5403. }
  5404. F32 geom_count_factor = 1.f;
  5405. bool is_mesh = vobjp->isMesh();
  5406. if (is_mesh)
  5407. {
  5408. if (!gMeshRepo.meshRezEnabled() || !volp->isMeshAssetLoaded())
  5409. {
  5410. continue;
  5411. }
  5412. geom_count_factor = mesh_geom_factor;
  5413. }
  5414. vobjp->updatePuppetAvatar();
  5415. const LLVector3& scale = vobjp->getScale();
  5416. groupp->mSurfaceArea += volp->getSurfaceArea() *
  5417. llmax(scale.mV[0], scale.mV[1],
  5418. scale.mV[2]);
  5419. {
  5420. LL_FAST_TIMER(FTM_VOLUME_TEXTURES);
  5421. vobjp->updateTextureVirtualSize(true);
  5422. }
  5423. vobjp->preRebuild();
  5424. drawablep->clearState(LLDrawable::HAS_ALPHA);
  5425. // *TODO: clean up the mess with all the avatar pointers. HB
  5426. LLVOAvatarPuppet* pup = vobjp->getPuppetAvatar();
  5427. voavp = pup;
  5428. bool animated = vobjp->isAnimatedObject();
  5429. LLVOAvatar* vobj_av = vobjp->getAvatar();
  5430. LLVOAvatar* avatarp = NULL;
  5431. const LLMeshSkinInfo* skin_infop = is_mesh ? vobjp->getSkinInfo()
  5432. : NULL;
  5433. if (skin_infop)
  5434. {
  5435. avatarp = animated ? voavp : vobj_av;
  5436. }
  5437. if (avatarp)
  5438. {
  5439. avatarp->addAttachmentOverridesForObject(vobjp, NULL, false);
  5440. }
  5441. U32 linkset_index = get_linkset_index(vobjp);
  5442. // Standard rigged attachment (non animated mesh)
  5443. bool rigged = !animated && skin_infop && vobjp->isAttachment();
  5444. // Animated objects. Have to check for isRiggedMesh() to exclude
  5445. // static objects in animated object linksets.
  5446. rigged |= animated && vobjp->isRiggedMesh() && pup && pup->mPlaying;
  5447. bool is_rigged = false;
  5448. // For each face
  5449. for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
  5450. {
  5451. LLFace* facep = drawablep->getFace(i);
  5452. if (!facep)
  5453. {
  5454. continue;
  5455. }
  5456. const LLTextureEntry* tep = facep->getTextureEntry();
  5457. if (!tep)
  5458. {
  5459. continue;
  5460. }
  5461. LLGLTFMaterial* gltfp = NULL;
  5462. if (gUsePBRShaders)
  5463. {
  5464. gltfp = tep->getGLTFRenderMaterial();
  5465. }
  5466. // Order by linkset index first and face index second
  5467. facep->setDrawOrderIndex(linkset_index * 100 + i);
  5468. // ALWAYS null out vertex buffer on rebuild: if the face lands
  5469. // in a render batch, it will recover its vertex buffer
  5470. // reference from the spatial group
  5471. facep->setVertexBuffer(NULL);
  5472. // Sum up face verts and indices
  5473. drawablep->updateFaceSize(i);
  5474. if (rigged)
  5475. {
  5476. if (!facep->isState(LLFace::RIGGED))
  5477. {
  5478. // Completely reset vertex buffer
  5479. facep->clearVertexBuffer();
  5480. }
  5481. facep->setState(LLFace::RIGGED);
  5482. facep->mSkinInfo = (LLMeshSkinInfo*)skin_infop;
  5483. facep->mAvatar = avatarp;
  5484. is_rigged = true;
  5485. }
  5486. else if (facep->isState(LLFace::RIGGED))
  5487. {
  5488. // Face is not rigged but used to be, remove from rigged
  5489. // face pool
  5490. facep->clearState(LLFace::RIGGED);
  5491. facep->mSkinInfo = NULL;
  5492. facep->mAvatar = NULL;
  5493. }
  5494. if (facep->getIndicesCount() <= 0 ||
  5495. facep->getGeomCount() <= 0)
  5496. {
  5497. facep->clearVertexBuffer();
  5498. continue;
  5499. }
  5500. if (cur_total > max_total)
  5501. {
  5502. llwarns_sparse << "Skipping rendering due to excessive node size."
  5503. << llendl;
  5504. facep->clearVertexBuffer();
  5505. continue;
  5506. }
  5507. if (facep->hasGeometry() &&
  5508. // *FIXME: getPixelArea() is sometimes incorrect for rigged
  5509. // meshes (thus the test for 'rigged', which is a hack).
  5510. (rigged || facep->getPixelArea() > FORCE_CULL_AREA))
  5511. {
  5512. cur_total += facep->getGeomCount() * geom_count_factor;
  5513. LLViewerTexture* texp = facep->getTexture();
  5514. if (tep->hasGlow())
  5515. {
  5516. emissive = true;
  5517. }
  5518. if (facep->isState(LLFace::TEXTURE_ANIM) &&
  5519. !vobjp->mTexAnimMode)
  5520. {
  5521. facep->clearState(LLFace::TEXTURE_ANIM);
  5522. }
  5523. bool force_simple =
  5524. facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA;
  5525. U32 type = gPipeline.getPoolTypeFromTE(tep, texp);
  5526. if (gltfp &&
  5527. gltfp->mAlphaMode != LLGLTFMaterial::ALPHA_MODE_BLEND)
  5528. {
  5529. type = LLDrawPool::POOL_MAT_PBR;
  5530. }
  5531. else if (type != LLDrawPool::POOL_ALPHA && force_simple)
  5532. {
  5533. type = LLDrawPool::POOL_SIMPLE;
  5534. }
  5535. facep->setPoolType(type);
  5536. if (!gltfp && vobjp->isHUDAttachment())
  5537. {
  5538. facep->setState(LLFace::FULLBRIGHT);
  5539. }
  5540. if (vobjp->mTextureAnimp && vobjp->mTexAnimMode)
  5541. {
  5542. if (vobjp->mTextureAnimp->mFace <= -1)
  5543. {
  5544. for (S32 face = 0, count2 = vobjp->getNumTEs();
  5545. face < count2; ++face)
  5546. {
  5547. LLFace* facep2 = drawablep->getFace(face);
  5548. if (facep2)
  5549. {
  5550. facep2->setState(LLFace::TEXTURE_ANIM);
  5551. }
  5552. }
  5553. }
  5554. else if (vobjp->mTextureAnimp->mFace <
  5555. vobjp->getNumTEs())
  5556. {
  5557. LLFace* facep2 =
  5558. drawablep->getFace(vobjp->mTextureAnimp->mFace);
  5559. if (facep2)
  5560. {
  5561. facep2->setState(LLFace::TEXTURE_ANIM);
  5562. }
  5563. }
  5564. }
  5565. if (type == LLDrawPool::POOL_ALPHA)
  5566. {
  5567. if (facep->canRenderAsMask())
  5568. {
  5569. // Can be treated as alpha mask
  5570. add_face(sSimpleFaces, simple_count, facep);
  5571. }
  5572. else
  5573. {
  5574. bool transparent = transparent_face(gltfp, facep,
  5575. tep);
  5576. if (!transparent)
  5577. {
  5578. // Only treat as alpha in the pipeline if not
  5579. // fully transparent
  5580. drawablep->setState(LLDrawable::HAS_ALPHA);
  5581. add_face(sAlphaFaces, alpha_count, facep);
  5582. }
  5583. else if (debugging_alpha)
  5584. {
  5585. // When debugging alpha, also add fully
  5586. // transparent faces.
  5587. add_face(sAlphaFaces, alpha_count, facep);
  5588. }
  5589. }
  5590. }
  5591. else
  5592. {
  5593. if (drawablep->isState(LLDrawable::REBUILD_VOLUME))
  5594. {
  5595. facep->mLastUpdateTime = gFrameTimeSeconds;
  5596. }
  5597. if (use_wl_shaders)
  5598. {
  5599. LLMaterial* matp = NULL;
  5600. if (LLPipeline::sRenderDeferred && !gltfp &&
  5601. tep->getMaterialID().notNull())
  5602. {
  5603. matp = tep->getMaterialParams().get();
  5604. }
  5605. if (matp)
  5606. {
  5607. // If face got an emboss bump map, it needs
  5608. // tangents.
  5609. U8 bump = tep->getBumpmap();
  5610. if ((bump && bump < 18) ||
  5611. matp->getNormalID().notNull())
  5612. {
  5613. if (matp->getSpecularID().notNull())
  5614. {
  5615. add_face(sNormSpecFaces, normspec_count,
  5616. facep);
  5617. }
  5618. // Has normal map: needs texcoord1 and
  5619. // tangent
  5620. else
  5621. {
  5622. add_face(sNormFaces, norm_count,
  5623. facep);
  5624. }
  5625. }
  5626. else if (matp->getSpecularID().notNull())
  5627. {
  5628. // Has specular map but no normal map,
  5629. // needs texcoord2
  5630. add_face(sSpecFaces, spec_count, facep);
  5631. }
  5632. // Has neither specular map nor normal map,
  5633. // only needs texcoord0
  5634. else
  5635. {
  5636. add_face(sSimpleFaces, simple_count,
  5637. facep);
  5638. }
  5639. }
  5640. else if (gltfp)
  5641. {
  5642. add_face(sPbrFaces, pbr_count, facep);
  5643. }
  5644. else if (tep->getBumpmap())
  5645. {
  5646. // Needs normal + tangent
  5647. add_face(sBumpFaces, bump_count, facep);
  5648. }
  5649. else if (tep->getShiny() || !tep->getFullbright())
  5650. {
  5651. // Needs normal
  5652. add_face(sSimpleFaces, simple_count, facep);
  5653. }
  5654. else
  5655. {
  5656. // Does not need normal
  5657. facep->setState(LLFace::FULLBRIGHT);
  5658. add_face(sFullbrightFaces, fullbright_count,
  5659. facep);
  5660. }
  5661. }
  5662. else if (tep->getBumpmap())
  5663. {
  5664. // Needs normal + tangent
  5665. add_face(sBumpFaces, bump_count, facep);
  5666. }
  5667. else if (tep->getShiny() || !tep->getFullbright())
  5668. {
  5669. // Needs normal
  5670. add_face(sSimpleFaces, simple_count, facep);
  5671. }
  5672. else
  5673. {
  5674. // Does not need normal
  5675. facep->setState(LLFace::FULLBRIGHT);
  5676. add_face(sFullbrightFaces, fullbright_count,
  5677. facep);
  5678. }
  5679. }
  5680. }
  5681. else
  5682. {
  5683. // Face has no renderable geometry
  5684. facep->clearVertexBuffer();
  5685. }
  5686. }
  5687. if (is_rigged)
  5688. {
  5689. if (!drawablep->isState(LLDrawable::RIGGED))
  5690. {
  5691. drawablep->setState(LLDrawable::RIGGED);
  5692. LLDrawable* rootp = drawablep->getRoot();
  5693. if (rootp != drawablep)
  5694. {
  5695. rootp->setState(LLDrawable::RIGGED_CHILD);
  5696. }
  5697. // First time this is drawable is being marked as rigged,
  5698. // do another LoD update to use avatar bounding box
  5699. vobjp->updateLOD();
  5700. }
  5701. }
  5702. else
  5703. {
  5704. drawablep->clearState(LLDrawable::RIGGED);
  5705. vobjp->updateRiggedVolume(false);
  5706. }
  5707. }
  5708. }
  5709. // NOTE: MAP_TEXTURE_INDEX is part of BASE_MASK since it was always added
  5710. // anyway as in 'extra_mask' to all masks in LL's original code. HB
  5711. constexpr U32 BASE_MASK = LLVertexBuffer::MAP_TEXTURE_INDEX |
  5712. LLVertexBuffer::MAP_TEXCOORD0 |
  5713. LLVertexBuffer::MAP_VERTEX |
  5714. LLVertexBuffer::MAP_COLOR;
  5715. // Process non-alpha faces
  5716. U32 simple_mask = BASE_MASK | LLVertexBuffer::MAP_NORMAL;
  5717. // hack to give alpha verts their own VBO
  5718. U32 alpha_mask = simple_mask | 0x80000000;
  5719. U32 bump_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD1;
  5720. U32 fullbright_mask = BASE_MASK;
  5721. U32 norm_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD1 |
  5722. LLVertexBuffer::MAP_TANGENT;
  5723. U32 normspec_mask = norm_mask | LLVertexBuffer::MAP_TEXCOORD2;
  5724. U32 spec_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD2;
  5725. U32 pbr_mask = simple_mask | LLVertexBuffer::MAP_TANGENT;
  5726. if (emissive)
  5727. {
  5728. // Emissive faces are present, add emissive bit to preserve batching
  5729. simple_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5730. alpha_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5731. bump_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5732. fullbright_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5733. norm_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5734. normspec_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5735. spec_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5736. pbr_mask |= LLVertexBuffer::MAP_EMISSIVE;
  5737. }
  5738. bool batch_textures =
  5739. gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 1;
  5740. if (batch_textures)
  5741. {
  5742. bump_mask |= LLVertexBuffer::MAP_TANGENT;
  5743. alpha_mask |= LLVertexBuffer::MAP_TANGENT |
  5744. LLVertexBuffer::MAP_TEXCOORD1 |
  5745. LLVertexBuffer::MAP_TEXCOORD2;
  5746. }
  5747. U32 extra_mask = 0;
  5748. for (U32 rigged = 0; rigged < 2; ++rigged)
  5749. {
  5750. genDrawInfo(groupp, simple_mask | extra_mask, sSimpleFaces[rigged],
  5751. simple_count[rigged], false, batch_textures, rigged);
  5752. genDrawInfo(groupp, fullbright_mask | extra_mask,
  5753. sFullbrightFaces[rigged], fullbright_count[rigged], false,
  5754. batch_textures, rigged);
  5755. genDrawInfo(groupp, alpha_mask | extra_mask, sAlphaFaces[rigged],
  5756. alpha_count[rigged], true, batch_textures, rigged);
  5757. genDrawInfo(groupp, bump_mask | extra_mask, sBumpFaces[rigged],
  5758. bump_count[rigged], false, false, rigged);
  5759. genDrawInfo(groupp, norm_mask | extra_mask, sNormFaces[rigged],
  5760. norm_count[rigged], false, false, rigged);
  5761. genDrawInfo(groupp, spec_mask | extra_mask, sSpecFaces[rigged],
  5762. spec_count[rigged], false, false, rigged);
  5763. genDrawInfo(groupp, normspec_mask | extra_mask, sNormSpecFaces[rigged],
  5764. normspec_count[rigged], false, false, rigged);
  5765. if (gUsePBRShaders)
  5766. {
  5767. genDrawInfo(groupp, pbr_mask | extra_mask, sPbrFaces[rigged],
  5768. pbr_count[rigged], false, false, rigged);
  5769. }
  5770. // For the second pass (rigged), add weights
  5771. extra_mask = LLVertexBuffer::MAP_WEIGHT4;
  5772. }
  5773. // Drawables have been rebuilt, clear rebuild status
  5774. for (LLSpatialGroup::element_iter it = groupp->getDataBegin(),
  5775. end = groupp->getDataEnd();
  5776. it != end; ++it)
  5777. {
  5778. LLDrawable* drawablep = (LLDrawable*)(*it)->getDrawable();
  5779. if (drawablep)
  5780. {
  5781. drawablep->clearState(LLDrawable::REBUILD_ALL);
  5782. }
  5783. }
  5784. groupp->mLastUpdateTime = gFrameTimeSeconds;
  5785. groupp->mBuilt = 1.f;
  5786. groupp->clearState(LLSpatialGroup::GEOM_DIRTY |
  5787. LLSpatialGroup::ALPHA_DIRTY);
  5788. if (voattachavp)
  5789. {
  5790. voattachavp->addAttachmentBytes(groupp->mGeometryBytes);
  5791. voattachavp->addAttachmentArea(groupp->mSurfaceArea);
  5792. }
  5793. if (voavp && voavp != voattachavp)
  5794. {
  5795. voavp->addAttachmentBytes(groupp->mGeometryBytes);
  5796. voavp->addAttachmentArea(groupp->mSurfaceArea);
  5797. }
  5798. }
  5799. //virtual
  5800. void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* groupp)
  5801. {
  5802. if (!groupp || !groupp->hasState(LLSpatialGroup::MESH_DIRTY) ||
  5803. groupp->hasState(LLSpatialGroup::GEOM_DIRTY))
  5804. {
  5805. llassert(false);
  5806. return;
  5807. }
  5808. LL_FAST_TIMER(FTM_VOLUME_GEOM);
  5809. groupp->mBuilt = 1.f;
  5810. for (LLSpatialGroup::element_iter it = groupp->getDataBegin(),
  5811. end = groupp->getDataEnd();
  5812. it != end; ++it)
  5813. {
  5814. LLDrawable* drawablep = (LLDrawable*)(*it)->getDrawable();
  5815. if (!drawablep || drawablep->isDead() ||
  5816. !drawablep->isState(LLDrawable::REBUILD_ALL))
  5817. {
  5818. continue;
  5819. }
  5820. LLVOVolume* vobjp = drawablep->getVOVolume();
  5821. if (!vobjp || vobjp->getLOD() == -1)
  5822. {
  5823. continue;
  5824. }
  5825. LLVolume* volp = vobjp->getVolume();
  5826. if (!volp)
  5827. {
  5828. continue;
  5829. }
  5830. vobjp->preRebuild();
  5831. if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
  5832. {
  5833. vobjp->updateRelativeXform(true);
  5834. }
  5835. for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
  5836. {
  5837. LLFace* face = drawablep->getFace(i);
  5838. if (!face) continue;
  5839. LLVertexBuffer* buffp = face->getVertexBuffer();
  5840. if (!buffp) continue;
  5841. if (!face->getGeometryVolume(*volp, face->getTEOffset(),
  5842. vobjp->getRelativeXform(),
  5843. vobjp->getRelativeXformInvTrans(),
  5844. face->getGeomIndex()))
  5845. {
  5846. // Something gone wrong with the vertex buffer accounting,
  5847. // rebuild this group
  5848. groupp->dirtyGeom();
  5849. gPipeline.markRebuild(groupp);
  5850. }
  5851. buffp->unmapBuffer();
  5852. }
  5853. if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
  5854. {
  5855. vobjp->updateRelativeXform();
  5856. }
  5857. drawablep->clearState(LLDrawable::REBUILD_ALL);
  5858. }
  5859. // Do not forget alpha
  5860. if (groupp)
  5861. {
  5862. LLVertexBuffer* buffp = groupp->mVertexBuffer.get();
  5863. if (buffp)
  5864. {
  5865. buffp->unmapBuffer();
  5866. }
  5867. }
  5868. groupp->clearState(LLSpatialGroup::MESH_DIRTY |
  5869. LLSpatialGroup::NEW_DRAWINFO);
  5870. }
  5871. struct CompareBatchBreaker
  5872. {
  5873. bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
  5874. {
  5875. const LLTextureEntry* lte = lhs->getTextureEntry();
  5876. const LLTextureEntry* rte = rhs->getTextureEntry();
  5877. if (lte->getBumpmap() != rte->getBumpmap())
  5878. {
  5879. return lte->getBumpmap() < rte->getBumpmap();
  5880. }
  5881. if (lte->getFullbright() != rte->getFullbright())
  5882. {
  5883. return lte->getFullbright() < rte->getFullbright();
  5884. }
  5885. if (LLPipeline::sRenderDeferred &&
  5886. lte->getMaterialID() != rte->getMaterialID())
  5887. {
  5888. return lte->getMaterialID() < rte->getMaterialID();
  5889. }
  5890. if (lte->getShiny() != rte->getShiny())
  5891. {
  5892. return lte->getShiny() < rte->getShiny();
  5893. }
  5894. if (lhs->getTexture() != rhs->getTexture())
  5895. {
  5896. return lhs->getTexture() < rhs->getTexture();
  5897. }
  5898. // All else being equal, maintain consistent draw order
  5899. return lhs->getDrawOrderIndex() < rhs->getDrawOrderIndex();
  5900. }
  5901. };
  5902. #if 0 // Not used any more: see below for rigged mesh draw order. HB
  5903. struct CompareBatchBreakerRigged
  5904. {
  5905. bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
  5906. {
  5907. const LLTextureEntry* lte = lhs->getTextureEntry();
  5908. const LLTextureEntry* rte = rhs->getTextureEntry();
  5909. if (lhs->mAvatar != rhs->mAvatar)
  5910. {
  5911. return lhs->mAvatar < rhs->mAvatar;
  5912. }
  5913. if (lhs->mSkinInfo->mHash != rhs->mSkinInfo->mHash)
  5914. {
  5915. return lhs->mSkinInfo->mHash < rhs->mSkinInfo->mHash;
  5916. }
  5917. // "Inherit from non-rigged behaviour
  5918. if (lte->getBumpmap() != rte->getBumpmap())
  5919. {
  5920. return lte->getBumpmap() < rte->getBumpmap();
  5921. }
  5922. if (lte->getFullbright() != rte->getFullbright())
  5923. {
  5924. return lte->getFullbright() < rte->getFullbright();
  5925. }
  5926. if (LLPipeline::sRenderDeferred &&
  5927. lte->getMaterialID() != rte->getMaterialID())
  5928. {
  5929. return lte->getMaterialID() < rte->getMaterialID();
  5930. }
  5931. if (lte->getShiny() != rte->getShiny())
  5932. {
  5933. return lte->getShiny() < rte->getShiny();
  5934. }
  5935. if (lhs->getTexture() != rhs->getTexture())
  5936. {
  5937. return lhs->getTexture() < rhs->getTexture();
  5938. }
  5939. // All else being equal, maintain consistent draw order
  5940. return lhs->getDrawOrderIndex() < rhs->getDrawOrderIndex();
  5941. }
  5942. };
  5943. #endif
  5944. struct CompareDrawOrder
  5945. {
  5946. LL_INLINE bool operator()(const LLFace* const& lhs,
  5947. const LLFace* const& rhs)
  5948. {
  5949. #if 1 // Still sort by avatar. HB
  5950. if (lhs->mAvatar != rhs->mAvatar)
  5951. {
  5952. return lhs->mAvatar < rhs->mAvatar;
  5953. }
  5954. #endif
  5955. return lhs->getDrawOrderIndex() < rhs->getDrawOrderIndex();
  5956. }
  5957. };
  5958. void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* groupp, U32 mask,
  5959. LLFace** faces, U32 face_count,
  5960. bool distance_sort,
  5961. bool batch_textures, bool rigged)
  5962. {
  5963. LL_FAST_TIMER(FTM_REBUILD_VOLUME_GEN_DRAW_INFO);
  5964. // Calculate maximum number of vertices to store in a single buffer
  5965. U32 max_vertices =
  5966. (LLVOVolume::sRenderMaxVBOSize * 1024) /
  5967. LLVertexBuffer::calcVertexSize(groupp->getSpatialPartition()->mVertexDataMask);
  5968. max_vertices = llmin(max_vertices, 65535U);
  5969. {
  5970. LL_FAST_TIMER(FTM_GEN_DRAW_INFO_SORT);
  5971. if (rigged)
  5972. {
  5973. #if 0 // This does not work: we need to *always* preserve legacy draw
  5974. // order for rigged meshes ! HB
  5975. if (distance_sort)
  5976. {
  5977. // Preserve legacy draw order for rigged faces
  5978. std::sort(faces, faces + face_count, CompareDrawOrder());
  5979. }
  5980. else
  5981. {
  5982. // Sort faces by things that break batches, including avatar
  5983. // and mesh Id
  5984. std::sort(faces, faces + face_count,
  5985. CompareBatchBreakerRigged());
  5986. }
  5987. #else
  5988. // Preserve legacy draw order for rigged faces
  5989. std::sort(faces, faces + face_count, CompareDrawOrder());
  5990. #endif
  5991. }
  5992. else if (distance_sort)
  5993. {
  5994. // Sort faces by distance
  5995. std::sort(faces, faces + face_count,
  5996. LLFace::CompareDistanceGreater());
  5997. }
  5998. else
  5999. {
  6000. // Sort faces by things that break batches
  6001. std::sort(faces, faces + face_count, CompareBatchBreaker());
  6002. }
  6003. }
  6004. bool hud_group = groupp->isHUDGroup();
  6005. LLFace** face_iter = faces;
  6006. LLFace** end_faces = faces + face_count;
  6007. LLSpatialGroup::buffer_map_t buffer_map;
  6008. S32 tex_idx_channels = 1;
  6009. if (gUsePBRShaders)
  6010. {
  6011. tex_idx_channels = LLShaderMgr::sIndexedTextureChannels;
  6012. }
  6013. else if (LLPipeline::sRenderDeferred && distance_sort)
  6014. {
  6015. tex_idx_channels =
  6016. gDeferredAlphaProgram.mFeatures.mIndexedTextureChannels;
  6017. }
  6018. else if (gGLManager.mGLSLVersionMajor > 1 ||
  6019. gGLManager.mGLSLVersionMinor >= 30)
  6020. {
  6021. // - 1 to always reserve one for shiny for now just for simplicity
  6022. tex_idx_channels = LLShaderMgr::sIndexedTextureChannels - 1;
  6023. }
  6024. //MK
  6025. bool restricted_vision = gRLenabled && gRLInterface.mVisionRestricted;
  6026. F32 cam_dist_max_squared = EXTREMUM;
  6027. LLVector3 joint_pos;
  6028. if (restricted_vision)
  6029. {
  6030. LLJoint* ref_joint = gRLInterface.getCamDistDrawFromJoint();
  6031. if (ref_joint)
  6032. {
  6033. // Calculate the position of the avatar here so we do not have to
  6034. // do it for each face
  6035. joint_pos = ref_joint->getWorldPosition();
  6036. cam_dist_max_squared = gRLInterface.mCamDistDrawMax;
  6037. cam_dist_max_squared *= cam_dist_max_squared;
  6038. }
  6039. else
  6040. {
  6041. restricted_vision = false;
  6042. }
  6043. }
  6044. //mk
  6045. bool not_debugging_alpha = !LLDrawPoolAlpha::sShowDebugAlpha;
  6046. while (face_iter != end_faces)
  6047. {
  6048. // Pull off next face
  6049. LLFace* facep = *face_iter;
  6050. if (!facep) continue; // Paranoia
  6051. //MK
  6052. bool is_far_face = false;
  6053. if (restricted_vision)
  6054. {
  6055. LLVector3 face_offset = facep->getPositionAgent() - joint_pos;
  6056. is_far_face = face_offset.lengthSquared() > cam_dist_max_squared;
  6057. }
  6058. //mk
  6059. const LLTextureEntry* tep = facep->getTextureEntry();
  6060. if (!tep) continue; // Paranoia
  6061. LLMaterialPtr matp = tep->getMaterialParams();
  6062. LLMaterialID mat_id = tep->getMaterialID();
  6063. LLViewerTexture* texp = distance_sort ? NULL : facep->getTexture();
  6064. U32 index_count = facep->getIndicesCount();
  6065. U32 geom_count = facep->getGeomCount();
  6066. // Sum up vertices needed for this render batch
  6067. LLFace** i = face_iter;
  6068. ++i;
  6069. constexpr U32 MAX_TEXTURE_COUNT = 32;
  6070. LLViewerTexture* texture_list[MAX_TEXTURE_COUNT];
  6071. U32 texture_count = 0;
  6072. {
  6073. LL_FAST_TIMER(FTM_GEN_DRAW_INFO_FACE_SIZE);
  6074. if (batch_textures)
  6075. {
  6076. U8 cur_tex = 0;
  6077. facep->setTextureIndex(cur_tex);
  6078. if (texture_count < MAX_TEXTURE_COUNT)
  6079. {
  6080. texture_list[texture_count++] = texp;
  6081. }
  6082. if (facep->canBatchTexture())
  6083. {
  6084. // Populate texture_list with any textures that can be
  6085. // batched. Move i to the next unbatchable face.
  6086. while (i != end_faces)
  6087. {
  6088. facep = *i;
  6089. if (!facep->canBatchTexture())
  6090. {
  6091. facep->setTextureIndex(0);
  6092. break;
  6093. }
  6094. if (facep->getTexture() != texp)
  6095. {
  6096. if (distance_sort)
  6097. {
  6098. // Textures might be out of order, see if
  6099. // texture exists in current batch
  6100. bool found = false;
  6101. for (U32 tex_idx = 0; tex_idx < texture_count;
  6102. ++tex_idx)
  6103. {
  6104. if (facep->getTexture() ==
  6105. texture_list[tex_idx])
  6106. {
  6107. cur_tex = tex_idx;
  6108. found = true;
  6109. break;
  6110. }
  6111. }
  6112. if (!found)
  6113. {
  6114. cur_tex = texture_count;
  6115. }
  6116. }
  6117. else
  6118. {
  6119. ++cur_tex;
  6120. }
  6121. if (cur_tex >= tex_idx_channels)
  6122. {
  6123. // Cut batches when index channels are depleted
  6124. break;
  6125. }
  6126. texp = facep->getTexture();
  6127. if (texture_count < MAX_TEXTURE_COUNT)
  6128. {
  6129. texture_list[texture_count++] = texp;
  6130. }
  6131. }
  6132. if (geom_count + facep->getGeomCount() > max_vertices)
  6133. {
  6134. // Cut batches on geom count too big
  6135. break;
  6136. }
  6137. ++i;
  6138. index_count += facep->getIndicesCount();
  6139. geom_count += facep->getGeomCount();
  6140. facep->setTextureIndex(cur_tex);
  6141. }
  6142. }
  6143. else
  6144. {
  6145. facep->setTextureIndex(0);
  6146. }
  6147. texp = texture_list[0];
  6148. }
  6149. else
  6150. {
  6151. while (i != end_faces &&
  6152. (distance_sort || (*i)->getTexture() == texp))
  6153. {
  6154. facep = *i;
  6155. const LLTextureEntry* next_tep = facep->getTextureEntry();
  6156. if (next_tep && next_tep->getMaterialID() != mat_id)
  6157. {
  6158. break;
  6159. }
  6160. // Face has no texture index
  6161. facep->mDrawInfo = NULL;
  6162. facep->setTextureIndex(FACE_DO_NOT_BATCH_TEXTURES);
  6163. if (geom_count + facep->getGeomCount() > max_vertices)
  6164. {
  6165. // Cut batches on geom count too big
  6166. break;
  6167. }
  6168. ++i;
  6169. index_count += facep->getIndicesCount();
  6170. geom_count += facep->getGeomCount();
  6171. }
  6172. }
  6173. }
  6174. // Create vertex buffer
  6175. LLPointer<LLVertexBuffer> buffp;
  6176. {
  6177. buffp = createVertexBuffer(mask);
  6178. if (!buffp->allocateBuffer(geom_count, index_count))
  6179. {
  6180. llwarns << "Failure to resize a vertex buffer with "
  6181. << geom_count << " vertices and " << index_count
  6182. << " indices" << llendl;
  6183. buffp = NULL;
  6184. }
  6185. }
  6186. if (buffp.notNull())
  6187. {
  6188. groupp->mGeometryBytes += buffp->getSize() +
  6189. buffp->getIndicesSize();
  6190. buffer_map[mask][*face_iter].push_back(buffp);
  6191. }
  6192. // Add face geometry
  6193. U32 indices_index = 0;
  6194. U16 index_offset = 0;
  6195. bool can_use_vertex_shaders = gPipeline.shadersLoaded();
  6196. while (face_iter < i)
  6197. {
  6198. // Update face indices for new buffer
  6199. facep = *face_iter;
  6200. if (buffp.isNull())
  6201. {
  6202. // Bulk allocation failed
  6203. facep->setVertexBuffer(buffp);
  6204. facep->setSize(0, 0); // Mark as no geometry
  6205. ++face_iter;
  6206. continue;
  6207. }
  6208. facep->setIndicesIndex(indices_index);
  6209. facep->setGeomIndex(index_offset);
  6210. facep->setVertexBuffer(buffp);
  6211. if (batch_textures &&
  6212. facep->getTextureIndex() == FACE_DO_NOT_BATCH_TEXTURES)
  6213. {
  6214. llwarns_sparse << "Invalid texture index. Skipping." << llendl;
  6215. ++face_iter;
  6216. continue;
  6217. }
  6218. // For debugging, set last time face was updated vs moved
  6219. facep->updateRebuildFlags();
  6220. // Copy face geometry into vertex buffer
  6221. LLDrawable* drawablep = facep->getDrawable();
  6222. LLVOVolume* vobjp = drawablep->getVOVolume();
  6223. LLVolume* volp = vobjp->getVolume();
  6224. if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
  6225. {
  6226. vobjp->updateRelativeXform(true);
  6227. }
  6228. U32 te_idx = facep->getTEOffset();
  6229. if (!facep->getGeometryVolume(*volp, te_idx,
  6230. vobjp->getRelativeXform(),
  6231. vobjp->getRelativeXformInvTrans(),
  6232. index_offset, true))
  6233. {
  6234. llwarns << "Failed to get geometry for face !" << llendl;
  6235. }
  6236. if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
  6237. {
  6238. vobjp->updateRelativeXform(false);
  6239. }
  6240. index_offset += facep->getGeomCount();
  6241. indices_index += facep->getIndicesCount();
  6242. // Append face to appropriate render batch
  6243. bool force_simple =
  6244. facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA;
  6245. bool fullbright = facep->isState(LLFace::FULLBRIGHT);
  6246. if ((mask & LLVertexBuffer::MAP_NORMAL) == 0)
  6247. {
  6248. // Paranoia check to make sure GL does not try to read
  6249. // non-existant normals
  6250. fullbright = true;
  6251. }
  6252. const LLTextureEntry* tep = facep->getTextureEntry();
  6253. LLGLTFMaterial* gltfp = NULL;
  6254. if (gUsePBRShaders)
  6255. {
  6256. // Do not render objects which act as a handle for a gLTF
  6257. // scene, unless we are in build mode. HB
  6258. if (vobjp && vobjp->mGLTFAsset.notNull() &&
  6259. !LLFloaterTools::isVisible())
  6260. {
  6261. ++face_iter;
  6262. continue;
  6263. }
  6264. gltfp = tep->getGLTFRenderMaterial();
  6265. }
  6266. if (hud_group && !gltfp)
  6267. {
  6268. // All hud attachments are fullbright
  6269. fullbright = true;
  6270. }
  6271. bool is_transparent = transparent_face(gltfp, facep, tep);
  6272. // Do not render transparent faces, unless we highlight transparent
  6273. if (not_debugging_alpha && is_transparent)
  6274. {
  6275. ++face_iter;
  6276. continue;
  6277. }
  6278. texp = facep->getTexture();
  6279. bool is_alpha = facep->getPoolType() == LLDrawPool::POOL_ALPHA;
  6280. // Ignore legacy material when PBR material is present
  6281. bool can_be_shiny = !gltfp;
  6282. bool has_glow = tep->hasGlow();
  6283. LLMaterial* matp = gltfp ? NULL : tep->getMaterialParams().get();
  6284. U8 diffuse_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
  6285. if (matp)
  6286. {
  6287. diffuse_mode = matp->getDiffuseAlphaMode();
  6288. can_be_shiny =
  6289. diffuse_mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE ||
  6290. diffuse_mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE;
  6291. }
  6292. bool use_legacy_bump = tep->getBumpmap() &&
  6293. tep->getBumpmap() < 18 &&
  6294. (!matp || matp->getNormalID().isNull());
  6295. bool is_opaque = opaque_face(facep, tep);
  6296. if (!is_opaque && !is_alpha && !gltfp)
  6297. {
  6298. is_alpha = true;
  6299. }
  6300. //MK
  6301. if (restricted_vision)
  6302. {
  6303. // Due to a rendering bug, we must completely ignore the alpha
  6304. // and fullbright of any object (except our own attachments and
  6305. // 100% invisible objects) when the vision is restricted
  6306. LLDrawable* drawablep = facep->getDrawable();
  6307. LLVOVolume* vobjp = drawablep->getVOVolume();
  6308. if ((is_alpha || fullbright) && !is_transparent)
  6309. {
  6310. if (vobjp && vobjp->getAvatar() != gAgentAvatarp)
  6311. {
  6312. // If this is an attachment with alpha or full bright
  6313. // and its wearer is farther than the vision range, do
  6314. // not render it at all
  6315. if (is_far_face && vobjp->isAttachment())
  6316. {
  6317. ++face_iter;
  6318. continue;
  6319. }
  6320. else if (vobjp->flagPhantom())
  6321. {
  6322. // If the object is phantom, no need to even render
  6323. // it at all. If it is solid, then a blind avatar
  6324. // will have to "see" it since it may bump into it
  6325. ++face_iter;
  6326. continue;
  6327. }
  6328. else if (is_far_face)
  6329. {
  6330. is_alpha = fullbright = can_be_shiny = false;
  6331. is_opaque = true;
  6332. }
  6333. }
  6334. }
  6335. else if (is_transparent && !(vobjp && vobjp->isAttachment()))
  6336. {
  6337. // Completely transparent and not an attachment => do not
  6338. // bother rendering it at all (even when highlighting
  6339. // transparent)
  6340. ++face_iter;
  6341. continue;
  6342. }
  6343. }
  6344. //mk
  6345. if (gltfp)
  6346. {
  6347. // All other parameters ignored when PBR material is present
  6348. if (gltfp->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND)
  6349. {
  6350. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6351. }
  6352. else if (gltfp->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK)
  6353. {
  6354. registerFace(groupp, facep,
  6355. LLRenderPass::PASS_MAT_PBR_ALPHA_MASK);
  6356. }
  6357. else
  6358. {
  6359. registerFace(groupp, facep, LLRenderPass::PASS_MAT_PBR);
  6360. }
  6361. }
  6362. else if (matp && !hud_group && LLPipeline::sRenderDeferred)
  6363. {
  6364. bool material_pass = false;
  6365. // Do NOT use 'fullbright' for this logic or you risk sending
  6366. // things without normals down the materials pipeline and will
  6367. // render poorly if not crash NORSPEC-240,314
  6368. if (tep->getFullbright())
  6369. {
  6370. if (diffuse_mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
  6371. {
  6372. if (is_opaque)
  6373. {
  6374. registerFace(groupp, facep,
  6375. LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
  6376. }
  6377. else
  6378. {
  6379. registerFace(groupp, facep,
  6380. LLRenderPass::PASS_ALPHA);
  6381. }
  6382. }
  6383. else if (is_alpha)
  6384. {
  6385. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6386. }
  6387. else if (!restricted_vision && // mk
  6388. (tep->getShiny() > 0 ||
  6389. matp->getSpecularID().notNull()))
  6390. {
  6391. material_pass = true;
  6392. }
  6393. else if (is_opaque)
  6394. {
  6395. registerFace(groupp, facep,
  6396. LLRenderPass::PASS_FULLBRIGHT);
  6397. }
  6398. else
  6399. {
  6400. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6401. }
  6402. }
  6403. else if (!is_opaque)
  6404. {
  6405. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6406. }
  6407. else if (use_legacy_bump)
  6408. {
  6409. // We have a material AND legacy bump settings, but no
  6410. // normal map
  6411. registerFace(groupp, facep, LLRenderPass::PASS_BUMP);
  6412. }
  6413. else
  6414. {
  6415. material_pass = true;
  6416. }
  6417. if (material_pass &&
  6418. diffuse_mode != LLMaterial::DIFFUSE_ALPHA_MODE_DEFAULT)
  6419. {
  6420. static const U32 pass[] =
  6421. {
  6422. LLRenderPass::PASS_MATERIAL,
  6423. LLRenderPass::PASS_ALPHA, // PASS_MATERIAL_ALPHA,
  6424. LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
  6425. LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
  6426. LLRenderPass::PASS_SPECMAP,
  6427. LLRenderPass::PASS_ALPHA, // PASS_SPECMAP_BLEND,
  6428. LLRenderPass::PASS_SPECMAP_MASK,
  6429. LLRenderPass::PASS_SPECMAP_EMISSIVE,
  6430. LLRenderPass::PASS_NORMMAP,
  6431. LLRenderPass::PASS_ALPHA, // PASS_NORMMAP_BLEND,
  6432. LLRenderPass::PASS_NORMMAP_MASK,
  6433. LLRenderPass::PASS_NORMMAP_EMISSIVE,
  6434. LLRenderPass::PASS_NORMSPEC,
  6435. LLRenderPass::PASS_ALPHA, // PASS_NORMSPEC_BLEND,
  6436. LLRenderPass::PASS_NORMSPEC_MASK,
  6437. LLRenderPass::PASS_NORMSPEC_EMISSIVE,
  6438. };
  6439. // *HACK: this should never happen, but sometimes we get a
  6440. // material that thinks it has alpha blending when it ought
  6441. // not.
  6442. U8 mode = diffuse_mode;
  6443. if (!distance_sort &&
  6444. mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)
  6445. {
  6446. mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
  6447. }
  6448. U32 mask = matp->getShaderMask(mode, is_alpha);
  6449. // *HACK: this should also never happen, but sometimes we
  6450. // get here and the material thinks it has a specmap now
  6451. // even though it did not appear to have a specmap when the
  6452. // face was added to the list of faces.
  6453. U32 vb_mask = facep->getVertexBuffer()->getTypeMask();
  6454. if ((mask & LLVertexBuffer::TYPE_TEXCOORD2) &&
  6455. !(vb_mask & LLVertexBuffer::MAP_TEXCOORD2))
  6456. {
  6457. mask &= ~LLVertexBuffer::TYPE_TEXCOORD2;
  6458. }
  6459. mask = llmin(mask, sizeof(pass) / sizeof(U32) - 1);
  6460. registerFace(groupp, facep, pass[mask]);
  6461. }
  6462. }
  6463. else if (matp)
  6464. {
  6465. U8 mode = diffuse_mode;
  6466. is_alpha |= mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
  6467. if (is_alpha)
  6468. {
  6469. mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
  6470. }
  6471. if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
  6472. {
  6473. registerFace(groupp, facep,
  6474. fullbright ? LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK
  6475. : LLRenderPass::PASS_ALPHA_MASK);
  6476. }
  6477. else if (is_alpha)
  6478. {
  6479. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6480. }
  6481. else if (can_be_shiny && can_use_vertex_shaders &&
  6482. tep->getShiny())
  6483. {
  6484. registerFace(groupp, facep,
  6485. fullbright ? LLRenderPass::PASS_FULLBRIGHT_SHINY
  6486. : LLRenderPass::PASS_SHINY);
  6487. }
  6488. else
  6489. {
  6490. registerFace(groupp, facep,
  6491. fullbright ? LLRenderPass::PASS_FULLBRIGHT
  6492. : LLRenderPass::PASS_SIMPLE);
  6493. }
  6494. }
  6495. else if (is_alpha)
  6496. {
  6497. // When the face itself is 100% transparent, do not render
  6498. // unless we are highlighting transparent
  6499. if (not_debugging_alpha && !has_glow &&
  6500. facep->getRenderColor().mV[3] < 0.001f)
  6501. {
  6502. ++face_iter;
  6503. continue;
  6504. }
  6505. // Can we safely treat this as an alpha mask ?
  6506. else if (facep->canRenderAsMask() &&
  6507. !(gUsePBRShaders && hud_group))
  6508. {
  6509. if (tep->getFullbright())
  6510. {
  6511. registerFace(groupp, facep,
  6512. LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
  6513. }
  6514. else
  6515. {
  6516. registerFace(groupp, facep,
  6517. LLRenderPass::PASS_ALPHA_MASK);
  6518. }
  6519. }
  6520. else
  6521. {
  6522. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA);
  6523. }
  6524. }
  6525. else if (can_be_shiny && can_use_vertex_shaders && tep->getShiny())
  6526. {
  6527. // Shiny
  6528. if (texp->getPrimaryFormat() == GL_ALPHA)
  6529. {
  6530. // Invisiprim + shiny
  6531. registerFace(groupp, facep,
  6532. LLRenderPass::PASS_INVISI_SHINY);
  6533. registerFace(groupp, facep, LLRenderPass::PASS_INVISIBLE);
  6534. }
  6535. else if (!hud_group && LLPipeline::sRenderDeferred)
  6536. {
  6537. // Deferred rendering
  6538. if (tep->getFullbright())
  6539. {
  6540. // Register in post deferred fullbright shiny pass
  6541. registerFace(groupp, facep,
  6542. LLRenderPass::PASS_FULLBRIGHT_SHINY);
  6543. if (tep->getBumpmap())
  6544. {
  6545. // Register in post deferred bump pass
  6546. registerFace(groupp, facep,
  6547. LLRenderPass::PASS_POST_BUMP);
  6548. }
  6549. }
  6550. else if (use_legacy_bump)
  6551. {
  6552. // Register in deferred bump pass
  6553. registerFace(groupp, facep, LLRenderPass::PASS_BUMP);
  6554. }
  6555. else
  6556. {
  6557. // Register in deferred simple pass (deferred simple
  6558. // includes shiny)
  6559. llassert(mask & LLVertexBuffer::MAP_NORMAL);
  6560. registerFace(groupp, facep, LLRenderPass::PASS_SIMPLE);
  6561. }
  6562. }
  6563. else if (fullbright)
  6564. {
  6565. // Not deferred, register in standard fullbright shiny pass
  6566. registerFace(groupp, facep,
  6567. LLRenderPass::PASS_FULLBRIGHT_SHINY);
  6568. }
  6569. else
  6570. {
  6571. // Not deferred or fullbright, register in standard shiny
  6572. // pass
  6573. registerFace(groupp, facep, LLRenderPass::PASS_SHINY);
  6574. }
  6575. }
  6576. else // Not alpha and not shiny
  6577. {
  6578. if (!is_alpha && texp->getPrimaryFormat() == GL_ALPHA)
  6579. {
  6580. // Invisiprim
  6581. registerFace(groupp, facep, LLRenderPass::PASS_INVISIBLE);
  6582. }
  6583. else if (fullbright)
  6584. {
  6585. // Fullbright
  6586. if (matp &&
  6587. diffuse_mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
  6588. {
  6589. registerFace(groupp, facep,
  6590. LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
  6591. }
  6592. else
  6593. {
  6594. registerFace(groupp, facep,
  6595. LLRenderPass::PASS_FULLBRIGHT);
  6596. }
  6597. if (!hud_group && LLPipeline::sRenderDeferred &&
  6598. use_legacy_bump)
  6599. {
  6600. // If this is the deferred render and a bump map is
  6601. // present, register in post deferred bump
  6602. registerFace(groupp, facep,
  6603. LLRenderPass::PASS_POST_BUMP);
  6604. }
  6605. }
  6606. else if (LLPipeline::sRenderDeferred && use_legacy_bump)
  6607. {
  6608. // Non-shiny or fullbright deferred bump
  6609. registerFace(groupp, facep, LLRenderPass::PASS_BUMP);
  6610. }
  6611. // All around simple from there
  6612. else if (matp &&
  6613. diffuse_mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
  6614. {
  6615. llassert(mask & LLVertexBuffer::MAP_NORMAL);
  6616. // Material alpha mask can be respected in non-deferred
  6617. registerFace(groupp, facep, LLRenderPass::PASS_ALPHA_MASK);
  6618. }
  6619. else
  6620. {
  6621. llassert(mask & LLVertexBuffer::MAP_NORMAL);
  6622. registerFace(groupp, facep, LLRenderPass::PASS_SIMPLE);
  6623. }
  6624. if (!can_use_vertex_shaders && !is_alpha && tep->getShiny())
  6625. {
  6626. // Shiny has an extra pass when shaders are disabled
  6627. registerFace(groupp, facep, LLRenderPass::PASS_SHINY);
  6628. }
  6629. }
  6630. // Not sure why this is here, and looks like it might cause bump
  6631. // mapped objects to get rendered redundantly -- davep 5/11/2010
  6632. if (!is_alpha && (hud_group || !LLPipeline::sRenderDeferred))
  6633. {
  6634. llassert((mask & LLVertexBuffer::MAP_NORMAL) || fullbright);
  6635. facep->setPoolType(fullbright ? LLDrawPool::POOL_FULLBRIGHT
  6636. : LLDrawPool::POOL_SIMPLE);
  6637. if (!force_simple && use_legacy_bump)
  6638. {
  6639. registerFace(groupp, facep, LLRenderPass::PASS_BUMP);
  6640. }
  6641. }
  6642. if (!is_alpha && has_glow && LLPipeline::RenderGlow)
  6643. {
  6644. //MK
  6645. if (is_far_face)
  6646. {
  6647. registerFace(groupp, facep, LLRenderPass::PASS_SIMPLE);
  6648. }
  6649. else
  6650. //mk
  6651. if (gltfp)
  6652. {
  6653. registerFace(groupp, facep, LLRenderPass::PASS_PBR_GLOW);
  6654. }
  6655. else
  6656. {
  6657. registerFace(groupp, facep, LLRenderPass::PASS_GLOW);
  6658. }
  6659. }
  6660. ++face_iter;
  6661. }
  6662. if (buffp.notNull())
  6663. {
  6664. buffp->unmapBuffer();
  6665. }
  6666. }
  6667. // Replace old buffer map with the new one (swapping them is by far the
  6668. // fastest way to do this). HB
  6669. groupp->mBufferMap[mask].swap(buffer_map[mask]);
  6670. }
  6671. //virtual
  6672. void LLGeometryManager::addGeometryCount(LLSpatialGroup* groupp,
  6673. U32& vertex_count, U32& index_count)
  6674. {
  6675. // Clear off any old faces
  6676. mFaceList.clear();
  6677. // For each drawable
  6678. for (LLSpatialGroup::element_iter it = groupp->getDataBegin(),
  6679. end = groupp->getDataEnd();
  6680. it != end; ++it)
  6681. {
  6682. LLDrawable* drawablep = (LLDrawable*)(*it)->getDrawable();
  6683. if (!drawablep || drawablep->isDead())
  6684. {
  6685. continue;
  6686. }
  6687. // For each face
  6688. for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
  6689. {
  6690. // Sum up face verts and indices
  6691. drawablep->updateFaceSize(i);
  6692. LLFace* facep = drawablep->getFace(i);
  6693. if (facep)
  6694. {
  6695. if (facep->hasGeometry() &&
  6696. facep->getPixelArea() > FORCE_CULL_AREA &&
  6697. facep->getGeomCount() + vertex_count <= 65536)
  6698. {
  6699. vertex_count += facep->getGeomCount();
  6700. index_count += facep->getIndicesCount();
  6701. // Remember face (for sorting)
  6702. mFaceList.push_back(facep);
  6703. }
  6704. else
  6705. {
  6706. facep->clearVertexBuffer();
  6707. }
  6708. }
  6709. }
  6710. }
  6711. }
  6712. LLHUDPartition::LLHUDPartition(LLViewerRegion* regionp)
  6713. : LLBridgePartition(regionp)
  6714. {
  6715. mPartitionType = LLViewerRegion::PARTITION_HUD;
  6716. mDrawableType = LLPipeline::RENDER_TYPE_HUD;
  6717. mSlopRatio = 0.f;
  6718. mLODPeriod = 1;
  6719. }