000-mesalib-xdemos.patch 400 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774
  1. diff -Naurp Mesa-7.8.1/progs/xdemos/corender.c Mesa-7.8.1.patched/progs/xdemos/corender.c
  2. --- Mesa-7.8.1/progs/xdemos/corender.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ Mesa-7.8.1.patched/progs/xdemos/corender.c 2010-06-13 13:45:06.789793146 +0200
  4. @@ -0,0 +1,400 @@
  5. +/**
  6. + * Example of cooperative rendering into one window by two processes.
  7. + * The first instance of the program creates the GLX window.
  8. + * The second instance of the program gets the window ID from the first
  9. + * and draws into it.
  10. + * Socket IPC is used for synchronization.
  11. + *
  12. + * Usage:
  13. + * 1. run 'corender &'
  14. + * 2. run 'corender 2' (any arg will do)
  15. + *
  16. + * Brian Paul
  17. + * 11 Oct 2007
  18. + */
  19. +
  20. +
  21. +#include <GL/gl.h>
  22. +#include <GL/glx.h>
  23. +#include <assert.h>
  24. +#include <math.h>
  25. +#include <stdio.h>
  26. +#include <stdlib.h>
  27. +#include <X11/keysym.h>
  28. +#include <unistd.h>
  29. +#include "ipc.h"
  30. +
  31. +
  32. +#ifndef M_PI
  33. +#define M_PI 3.14159265358979323846
  34. +#endif
  35. +
  36. +static int MyID = 0; /* 0 or 1 */
  37. +static int WindowID = 0;
  38. +static GLXContext Context = 0;
  39. +static int Width = 700, Height = 350;
  40. +static int Rot = 0;
  41. +static int Sock = 0;
  42. +
  43. +static GLfloat Red[4] = {1.0, 0.2, 0.2, 1.0};
  44. +static GLfloat Blue[4] = {0.2, 0.2, 1.0, 1.0};
  45. +
  46. +static int Sync = 1; /** synchronized rendering? */
  47. +
  48. +
  49. +static void
  50. +setup_ipc(void)
  51. +{
  52. + int k, port = 10001;
  53. +
  54. + if (MyID == 0) {
  55. + /* I'm the first one, wait for connection from second */
  56. + k = CreatePort(&port);
  57. + assert(k != -1);
  58. +
  59. + printf("Waiting for connection from another 'corender'\n");
  60. + Sock = AcceptConnection(k);
  61. + assert(Sock != -1);
  62. +
  63. + printf("Got connection, sending windowID\n");
  64. +
  65. + /* send windowID */
  66. + SendData(Sock, &WindowID, sizeof(WindowID));
  67. + }
  68. + else {
  69. + /* I'm the second one, connect to first */
  70. + char hostname[1000];
  71. +
  72. + MyHostName(hostname, 1000);
  73. + Sock = Connect(hostname, port);
  74. + assert(Sock != -1);
  75. +
  76. + /* get windowID */
  77. + ReceiveData(Sock, &WindowID, sizeof(WindowID));
  78. + printf("Contacted first 'corender', getting WindowID\n");
  79. + }
  80. +}
  81. +
  82. +
  83. +
  84. +/** from GLUT */
  85. +static void
  86. +doughnut(GLfloat r, GLfloat R, GLint nsides, GLint rings)
  87. +{
  88. + int i, j;
  89. + GLfloat theta, phi, theta1;
  90. + GLfloat cosTheta, sinTheta;
  91. + GLfloat cosTheta1, sinTheta1;
  92. + GLfloat ringDelta, sideDelta;
  93. +
  94. + ringDelta = 2.0 * M_PI / rings;
  95. + sideDelta = 2.0 * M_PI / nsides;
  96. +
  97. + theta = 0.0;
  98. + cosTheta = 1.0;
  99. + sinTheta = 0.0;
  100. + for (i = rings - 1; i >= 0; i--) {
  101. + theta1 = theta + ringDelta;
  102. + cosTheta1 = cos(theta1);
  103. + sinTheta1 = sin(theta1);
  104. + glBegin(GL_QUAD_STRIP);
  105. + phi = 0.0;
  106. + for (j = nsides; j >= 0; j--) {
  107. + GLfloat cosPhi, sinPhi, dist;
  108. +
  109. + phi += sideDelta;
  110. + cosPhi = cos(phi);
  111. + sinPhi = sin(phi);
  112. + dist = R + r * cosPhi;
  113. +
  114. + glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
  115. + glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
  116. + glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
  117. + glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
  118. + }
  119. + glEnd();
  120. + theta = theta1;
  121. + cosTheta = cosTheta1;
  122. + sinTheta = sinTheta1;
  123. + }
  124. +}
  125. +
  126. +
  127. +static void
  128. +redraw(Display *dpy)
  129. +{
  130. + int dbg = 0;
  131. +
  132. + glXMakeCurrent(dpy, WindowID, Context);
  133. + glEnable(GL_LIGHTING);
  134. + glEnable(GL_LIGHT0);
  135. + glEnable(GL_DEPTH_TEST);
  136. + glClearColor(0.5, 0.5, 0.5, 0.0);
  137. +
  138. + if (MyID == 0) {
  139. + /* First process */
  140. +
  141. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  142. +
  143. + glPushMatrix();
  144. + glTranslatef(-1, 0, 0);
  145. + glRotatef(Rot, 1, 0, 0);
  146. + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Red);
  147. + doughnut(0.5, 2.0, 20, 30);
  148. + glPopMatrix();
  149. +
  150. + glFinish();
  151. + if (!Sync) {
  152. + usleep(1000*10);
  153. + }
  154. +
  155. + /* signal second process to render */
  156. + if (Sync) {
  157. + int code = 1;
  158. + if (dbg) printf("0: send signal\n");
  159. + SendData(Sock, &code, sizeof(code));
  160. + SendData(Sock, &Rot, sizeof(Rot));
  161. + }
  162. +
  163. + /* wait for second process to finish rendering */
  164. + if (Sync) {
  165. + int code = 0;
  166. + if (dbg) printf("0: wait signal\n");
  167. + ReceiveData(Sock, &code, sizeof(code));
  168. + if (dbg) printf("0: got signal\n");
  169. + assert(code == 2);
  170. + }
  171. +
  172. + }
  173. + else {
  174. + /* Second process */
  175. +
  176. + /* wait for first process's signal for me to render */
  177. + if (Sync) {
  178. + int code = 0;
  179. + if (dbg) printf("1: wait signal\n");
  180. + ReceiveData(Sock, &code, sizeof(code));
  181. + ReceiveData(Sock, &Rot, sizeof(Rot));
  182. +
  183. + if (dbg) printf("1: got signal\n");
  184. + assert(code == 1);
  185. + }
  186. +
  187. + /* XXX this clear should not be here, but for some reason, it
  188. + * makes things _mostly_ work correctly w/ NVIDIA's driver.
  189. + * There's only occasional glitches.
  190. + * Without this glClear(), depth buffer for the second process
  191. + * is pretty much broken.
  192. + */
  193. + /* glClear(GL_DEPTH_BUFFER_BIT); */
  194. +
  195. + glPushMatrix();
  196. + glTranslatef(1, 0, 0);
  197. + glRotatef(Rot + 90 , 1, 0, 0);
  198. + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Blue);
  199. + doughnut(0.5, 2.0, 20, 30);
  200. + glPopMatrix();
  201. + glFinish();
  202. +
  203. + glXSwapBuffers(dpy, WindowID);
  204. + usleep(1000*10);
  205. +
  206. + /* signal first process that I'm done rendering */
  207. + if (Sync) {
  208. + int code = 2;
  209. + if (dbg) printf("1: send signal\n");
  210. + SendData(Sock, &code, sizeof(code));
  211. + }
  212. + }
  213. +}
  214. +
  215. +
  216. +static void
  217. +resize(Display *dpy, int width, int height)
  218. +{
  219. + float ar = (float) width / height;
  220. +
  221. + glXMakeCurrent(dpy, WindowID, Context);
  222. +
  223. + glViewport(0, 0, width, height);
  224. + glMatrixMode(GL_PROJECTION);
  225. + glLoadIdentity();
  226. + glFrustum(-ar, ar, 1.0, -1.0, 5.0, 200.0);
  227. + glMatrixMode(GL_MODELVIEW);
  228. + glLoadIdentity();
  229. + glTranslatef(0, 0, -15);
  230. +
  231. + Width = width;
  232. + Height = height;
  233. +}
  234. +
  235. +
  236. +
  237. +static void
  238. +set_window_title(Display *dpy, Window win, const char *title)
  239. +{
  240. + XSizeHints sizehints;
  241. + sizehints.flags = 0;
  242. + XSetStandardProperties(dpy, win, title, title,
  243. + None, (char **)NULL, 0, &sizehints);
  244. +}
  245. +
  246. +
  247. +static Window
  248. +make_gl_window(Display *dpy, XVisualInfo *visinfo, int width, int height)
  249. +{
  250. + int scrnum;
  251. + XSetWindowAttributes attr;
  252. + unsigned long mask;
  253. + Window root;
  254. + Window win;
  255. + int x = 0, y = 0;
  256. + char *name = NULL;
  257. +
  258. + scrnum = DefaultScreen( dpy );
  259. + root = RootWindow( dpy, scrnum );
  260. +
  261. + /* window attributes */
  262. + attr.background_pixel = 0;
  263. + attr.border_pixel = 0;
  264. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  265. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  266. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  267. +
  268. + win = XCreateWindow( dpy, root, x, y, width, height,
  269. + 0, visinfo->depth, InputOutput,
  270. + visinfo->visual, mask, &attr );
  271. +
  272. + /* set hints and properties */
  273. + {
  274. + XSizeHints sizehints;
  275. + sizehints.x = x;
  276. + sizehints.y = y;
  277. + sizehints.width = width;
  278. + sizehints.height = height;
  279. + sizehints.flags = USSize | USPosition;
  280. + XSetNormalHints(dpy, win, &sizehints);
  281. + XSetStandardProperties(dpy, win, name, name,
  282. + None, (char **)NULL, 0, &sizehints);
  283. + }
  284. +
  285. + return win;
  286. +}
  287. +
  288. +
  289. +static void
  290. +set_event_mask(Display *dpy, Window win)
  291. +{
  292. + XSetWindowAttributes attr;
  293. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  294. + XChangeWindowAttributes(dpy, win, CWEventMask, &attr);
  295. +}
  296. +
  297. +
  298. +static void
  299. +event_loop(Display *dpy)
  300. +{
  301. + while (1) {
  302. + while (XPending(dpy) > 0) {
  303. + XEvent event;
  304. + XNextEvent(dpy, &event);
  305. +
  306. + switch (event.type) {
  307. + case Expose:
  308. + redraw(dpy);
  309. + break;
  310. + case ConfigureNotify:
  311. + resize(dpy, event.xconfigure.width, event.xconfigure.height);
  312. + break;
  313. + case KeyPress:
  314. + {
  315. + char buffer[10];
  316. + int r, code;
  317. + code = XLookupKeysym(&event.xkey, 0);
  318. + if (code == XK_Left) {
  319. + }
  320. + else {
  321. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  322. + NULL, NULL);
  323. + if (buffer[0] == 27) {
  324. + exit(0);
  325. + }
  326. + }
  327. + }
  328. + default:
  329. + /* nothing */
  330. + ;
  331. + }
  332. + }
  333. +
  334. + if (MyID == 0 || !Sync)
  335. + Rot += 1;
  336. + redraw(dpy);
  337. + }
  338. +}
  339. +
  340. +
  341. +static XVisualInfo *
  342. +choose_visual(Display *dpy)
  343. +{
  344. + int attribs[] = { GLX_RGBA,
  345. + GLX_RED_SIZE, 1,
  346. + GLX_GREEN_SIZE, 1,
  347. + GLX_BLUE_SIZE, 1,
  348. + GLX_DOUBLEBUFFER,
  349. + GLX_DEPTH_SIZE, 1,
  350. + None };
  351. + int scrnum = DefaultScreen( dpy );
  352. + return glXChooseVisual(dpy, scrnum, attribs);
  353. +}
  354. +
  355. +
  356. +static void
  357. +parse_opts(int argc, char *argv[])
  358. +{
  359. + if (argc > 1) {
  360. + MyID = 1;
  361. + }
  362. +}
  363. +
  364. +
  365. +int
  366. +main( int argc, char *argv[] )
  367. +{
  368. + Display *dpy;
  369. + XVisualInfo *visinfo;
  370. +
  371. + parse_opts(argc, argv);
  372. +
  373. + dpy = XOpenDisplay(NULL);
  374. +
  375. + visinfo = choose_visual(dpy);
  376. +
  377. + Context = glXCreateContext( dpy, visinfo, NULL, True );
  378. + if (!Context) {
  379. + printf("Error: glXCreateContext failed\n");
  380. + exit(1);
  381. + }
  382. +
  383. + if (MyID == 0) {
  384. + WindowID = make_gl_window(dpy, visinfo, Width, Height);
  385. + set_window_title(dpy, WindowID, "corender");
  386. + XMapWindow(dpy, WindowID);
  387. + /*printf("WindowID 0x%x\n", (int) WindowID);*/
  388. + }
  389. +
  390. + /* do ipc hand-shake here */
  391. + setup_ipc();
  392. + assert(Sock);
  393. + assert(WindowID);
  394. +
  395. + if (MyID == 1) {
  396. + set_event_mask(dpy, WindowID);
  397. + }
  398. +
  399. + resize(dpy, Width, Height);
  400. +
  401. + event_loop(dpy);
  402. +
  403. + return 0;
  404. +}
  405. diff -Naurp Mesa-7.8.1/progs/xdemos/glsync.c Mesa-7.8.1.patched/progs/xdemos/glsync.c
  406. --- Mesa-7.8.1/progs/xdemos/glsync.c 1970-01-01 01:00:00.000000000 +0100
  407. +++ Mesa-7.8.1.patched/progs/xdemos/glsync.c 2010-06-13 13:45:06.789793146 +0200
  408. @@ -0,0 +1,295 @@
  409. +/*
  410. + * Copyright © 2007 Intel Corporation
  411. + *
  412. + * Permission is hereby granted, free of charge, to any person obtaining a
  413. + * copy of this software and associated documentation files (the "Software"),
  414. + * to deal in the Software without restriction, including without limitation
  415. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  416. + * and/or sell copies of the Software, and to permit persons to whom the
  417. + * Software is furnished to do so, subject to the following conditions:
  418. + *
  419. + * The above copyright notice and this permission notice (including the next
  420. + * paragraph) shall be included in all copies or substantial portions of the
  421. + * Software.
  422. + *
  423. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  424. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  425. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  426. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  427. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  428. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  429. + * IN THE SOFTWARE.
  430. + *
  431. + * Authors:
  432. + * Jesse Barnes <jesse.barnes@intel.com>
  433. + *
  434. + */
  435. +
  436. +/** @file glsync.c
  437. + * The program is simple: it paints a window alternating colors (red &
  438. + * white) either as fast as possible or synchronized to vblank events
  439. + *
  440. + * If run normally, the program should display a window that exhibits
  441. + * significant tearing between red and white colors (e.g. you might get
  442. + * a "waterfall" effect of red and white horizontal bars).
  443. + *
  444. + * If run with the '-s b' option, the program should synchronize the
  445. + * window color changes with the vertical blank period, resulting in a
  446. + * window that looks orangish with a high frequency flicker (which may
  447. + * be invisible). If the window is moved to another screen, this
  448. + * property should be preserved. If the window spans two screens, it
  449. + * shouldn't tear on whichever screen most of the window is on; the
  450. + * portion on the other screen may show some tearing (like the
  451. + * waterfall effect above).
  452. + *
  453. + * Other options include '-w <width>' and '-h <height' to set the
  454. + * window size.
  455. + */
  456. +#include <stdio.h>
  457. +#include <stdlib.h>
  458. +#include <string.h>
  459. +#include <unistd.h>
  460. +#include <GL/gl.h>
  461. +#include <GL/glu.h>
  462. +#include <GL/glx.h>
  463. +#include <GL/glxext.h>
  464. +#include <X11/X.h>
  465. +#include <X11/Xlib.h>
  466. +#include <X11/Xutil.h>
  467. +
  468. +void (*video_sync_get)();
  469. +void (*video_sync)();
  470. +void (*swap_interval)();
  471. +
  472. +static int GLXExtensionSupported(Display *dpy, const char *extension)
  473. +{
  474. + const char *extensionsString, *pos;
  475. +
  476. + extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
  477. +
  478. + pos = strstr(extensionsString, extension);
  479. +
  480. + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
  481. + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
  482. + return 1;
  483. +
  484. + return 0;
  485. +}
  486. +
  487. +extern char *optarg;
  488. +extern int optind, opterr, optopt;
  489. +static char optstr[] = "w:h:s:vi:";
  490. +
  491. +enum sync_type {
  492. + none = 0,
  493. + sgi_video_sync,
  494. + buffer_swap
  495. +};
  496. +
  497. +static void usage(char *name)
  498. +{
  499. + printf("usage: %s [-w <width>] [-h <height>] [-s<sync method>] "
  500. + "[-v]\n", name);
  501. + printf("\t-s<sync method>:\n");
  502. + printf("\t\tn: none\n");
  503. + printf("\t\ts: SGI video sync extension\n");
  504. + printf("\t\tb: buffer swap\n");
  505. + printf("\t-i<swap interval>\n");
  506. + printf("\t-v: verbose (print count)\n");
  507. + exit(-1);
  508. +}
  509. +
  510. +int main(int argc, char *argv[])
  511. +{
  512. + Display *disp;
  513. + XVisualInfo *pvi;
  514. + XSetWindowAttributes swa;
  515. + GLint last_val = -1, count = 0;
  516. + Window winGL;
  517. + GLXContext context;
  518. + int dummy;
  519. + Atom wmDelete;
  520. + enum sync_type waitforsync = none;
  521. + int width = 500, height = 500, verbose = 0, interval = 1;
  522. + int c, i = 1;
  523. + int ret;
  524. + int attribs[] = { GLX_RGBA,
  525. + GLX_RED_SIZE, 1,
  526. + GLX_GREEN_SIZE, 1,
  527. + GLX_BLUE_SIZE, 1,
  528. + None };
  529. + int db_attribs[] = { GLX_RGBA,
  530. + GLX_RED_SIZE, 1,
  531. + GLX_GREEN_SIZE, 1,
  532. + GLX_BLUE_SIZE, 1,
  533. + GLX_DOUBLEBUFFER,
  534. + GLX_DEPTH_SIZE, 1,
  535. + None };
  536. + XSizeHints sizehints;
  537. +
  538. + opterr = 0;
  539. + while ((c = getopt(argc, argv, optstr)) != -1) {
  540. + switch (c) {
  541. + case 'w':
  542. + width = atoi(optarg);
  543. + break;
  544. + case 'h':
  545. + height = atoi(optarg);
  546. + break;
  547. + case 's':
  548. + switch (optarg[0]) {
  549. + case 'n':
  550. + waitforsync = none;
  551. + break;
  552. + case 's':
  553. + waitforsync = sgi_video_sync;
  554. + break;
  555. + case 'b':
  556. + waitforsync = buffer_swap;
  557. + break;
  558. + default:
  559. + usage(argv[0]);
  560. + break;
  561. + }
  562. + break;
  563. + case 'v':
  564. + verbose = 1;
  565. + break;
  566. + case 'i':
  567. + interval = atoi(optarg);
  568. + break;
  569. + default:
  570. + usage(argv[0]);
  571. + break;
  572. + }
  573. + }
  574. +
  575. + disp = XOpenDisplay(NULL);
  576. + if (!disp) {
  577. + fprintf(stderr, "failed to open display\n");
  578. + return -1;
  579. + }
  580. +
  581. + if (!glXQueryExtension(disp, &dummy, &dummy)) {
  582. + fprintf(stderr, "glXQueryExtension failed\n");
  583. + return -1;
  584. + }
  585. +
  586. + if (!GLXExtensionSupported(disp, "GLX_SGI_video_sync")) {
  587. + fprintf(stderr, "GLX_SGI_video_sync not supported, exiting\n");
  588. + return -1;
  589. + }
  590. +
  591. + if (waitforsync != buffer_swap) {
  592. + pvi = glXChooseVisual(disp, DefaultScreen(disp), attribs);
  593. + } else {
  594. + pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs);
  595. + }
  596. +
  597. + if (!pvi) {
  598. + fprintf(stderr, "failed to choose visual, exiting\n");
  599. + return -1;
  600. + }
  601. +
  602. + pvi->screen = DefaultScreen(disp);
  603. +
  604. + swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
  605. + pvi->visual, AllocNone);
  606. + swa.border_pixel = 0;
  607. + swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
  608. + StructureNotifyMask;
  609. + winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
  610. + 0, 0,
  611. + width, height,
  612. + 0, pvi->depth, InputOutput, pvi->visual,
  613. + CWBorderPixel | CWColormap | CWEventMask, &swa);
  614. + if (!winGL) {
  615. + fprintf(stderr, "window creation failed\n");
  616. + return -1;
  617. + }
  618. + wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
  619. + XSetWMProtocols(disp, winGL, &wmDelete, 1);
  620. +
  621. + sizehints.x = 0;
  622. + sizehints.y = 0;
  623. + sizehints.width = width;
  624. + sizehints.height = height;
  625. + sizehints.flags = USSize | USPosition;
  626. +
  627. + XSetNormalHints(disp, winGL, &sizehints);
  628. + XSetStandardProperties(disp, winGL, "glsync test", "glsync text",
  629. + None, NULL, 0, &sizehints);
  630. +
  631. + context = glXCreateContext(disp, pvi, NULL, GL_TRUE);
  632. + if (!context) {
  633. + fprintf(stderr, "failed to create glx context\n");
  634. + return -1;
  635. + }
  636. +
  637. + XMapWindow(disp, winGL);
  638. + ret = glXMakeCurrent(disp, winGL, context);
  639. + if (!ret) {
  640. + fprintf(stderr, "failed to make context current: %d\n", ret);
  641. + }
  642. +
  643. + video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI");
  644. + video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI");
  645. +
  646. + swap_interval = glXGetProcAddress((unsigned char *)"glXSwapIntervalSGI");
  647. +
  648. + if (!video_sync_get || !video_sync || !swap_interval) {
  649. + fprintf(stderr, "failed to get sync functions\n");
  650. + return -1;
  651. + }
  652. +
  653. + if (waitforsync == buffer_swap) {
  654. + swap_interval(interval);
  655. + fprintf(stderr, "set swap interval to %d\n", interval);
  656. + }
  657. + video_sync_get(&count);
  658. + count++;
  659. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  660. + while (i++) {
  661. + /* Alternate colors to make tearing obvious */
  662. + if (i & 1) {
  663. + glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  664. + glColor3f(1.0f, 1.0f, 1.0f);
  665. + } else {
  666. + glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
  667. + glColor3f(1.0f, 0.0f, 0.0f);
  668. + }
  669. +
  670. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  671. + glRectf(0, 0, width, height);
  672. +
  673. + /* Wait for vsync */
  674. + if (waitforsync == sgi_video_sync) {
  675. + if (verbose)
  676. + fprintf(stderr, "waiting on count %d\n", count);
  677. + video_sync(2, (count + 1) % 2, &count);
  678. + if (count < last_val)
  679. + fprintf(stderr, "error: vblank count went backwards: %d -> %d\n", last_val, count);
  680. + if (count == last_val)
  681. + fprintf(stderr, "error: count didn't change: %d\n", count);
  682. + last_val = count;
  683. + glFlush();
  684. + } else if (waitforsync == buffer_swap) {
  685. + glXSwapBuffers(disp, winGL);
  686. + } else {
  687. + video_sync_get(&count);
  688. + sleep(1);
  689. + glFinish();
  690. + }
  691. +
  692. + if (verbose) {
  693. + video_sync_get(&count);
  694. + fprintf(stderr, "current count: %d\n", count);
  695. + }
  696. + }
  697. +
  698. + XDestroyWindow(disp, winGL);
  699. + glXDestroyContext(disp, context);
  700. + XCloseDisplay(disp);
  701. +
  702. + return 0;
  703. +}
  704. diff -Naurp Mesa-7.8.1/progs/xdemos/glthreads.c Mesa-7.8.1.patched/progs/xdemos/glthreads.c
  705. --- Mesa-7.8.1/progs/xdemos/glthreads.c 1970-01-01 01:00:00.000000000 +0100
  706. +++ Mesa-7.8.1.patched/progs/xdemos/glthreads.c 2010-06-13 13:45:06.789793146 +0200
  707. @@ -0,0 +1,716 @@
  708. +/*
  709. + * Copyright (C) 2000 Brian Paul All Rights Reserved.
  710. + *
  711. + * Permission is hereby granted, free of charge, to any person obtaining a
  712. + * copy of this software and associated documentation files (the "Software"),
  713. + * to deal in the Software without restriction, including without limitation
  714. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  715. + * and/or sell copies of the Software, and to permit persons to whom the
  716. + * Software is furnished to do so, subject to the following conditions:
  717. + *
  718. + * The above copyright notice and this permission notice shall be included
  719. + * in all copies or substantial portions of the Software.
  720. + *
  721. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  722. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  723. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  724. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  725. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  726. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  727. + */
  728. +
  729. +
  730. +/*
  731. + * This program tests GLX thread safety.
  732. + * Command line options:
  733. + * -p Open a display connection for each thread
  734. + * -l Enable application-side locking
  735. + * -n <num threads> Number of threads to create (default is 2)
  736. + * -display <display name> Specify X display (default is $DISPLAY)
  737. + * -t Use texture mapping
  738. + *
  739. + * Brian Paul 20 July 2000
  740. + */
  741. +
  742. +
  743. +/*
  744. + * Notes:
  745. + * - Each thread gets its own GLX context.
  746. + *
  747. + * - The GLX contexts share texture objects.
  748. + *
  749. + * - When 't' is pressed to update the texture image, the window/thread which
  750. + * has input focus is signalled to change the texture. The other threads
  751. + * should see the updated texture the next time they call glBindTexture.
  752. + */
  753. +
  754. +
  755. +#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */
  756. +
  757. +#include <assert.h>
  758. +#include <GL/gl.h>
  759. +#include <GL/glx.h>
  760. +#include <math.h>
  761. +#include <stdio.h>
  762. +#include <stdlib.h>
  763. +#include <string.h>
  764. +#include <unistd.h>
  765. +#include <pthread.h>
  766. +
  767. +
  768. +/*
  769. + * Each window/thread/context:
  770. + */
  771. +struct winthread {
  772. + Display *Dpy;
  773. + int Index;
  774. + pthread_t Thread;
  775. + Window Win;
  776. + GLXContext Context;
  777. + float Angle;
  778. + int WinWidth, WinHeight;
  779. + GLboolean NewSize;
  780. + GLboolean Initialized;
  781. + GLboolean MakeNewTexture;
  782. +};
  783. +
  784. +
  785. +#define MAX_WINTHREADS 100
  786. +static struct winthread WinThreads[MAX_WINTHREADS];
  787. +static int NumWinThreads = 0;
  788. +static volatile GLboolean ExitFlag = GL_FALSE;
  789. +
  790. +static GLboolean MultiDisplays = 0;
  791. +static GLboolean Locking = 0;
  792. +static GLboolean Texture = GL_FALSE;
  793. +static GLuint TexObj = 12;
  794. +static GLboolean Animate = GL_TRUE;
  795. +
  796. +static pthread_mutex_t Mutex;
  797. +static pthread_cond_t CondVar;
  798. +static pthread_mutex_t CondMutex;
  799. +
  800. +
  801. +static void
  802. +Error(const char *msg)
  803. +{
  804. + fprintf(stderr, "Error: %s\n", msg);
  805. + exit(1);
  806. +}
  807. +
  808. +
  809. +static void
  810. +signal_redraw(void)
  811. +{
  812. + pthread_mutex_lock(&CondMutex);
  813. + pthread_cond_broadcast(&CondVar);
  814. + pthread_mutex_unlock(&CondMutex);
  815. +}
  816. +
  817. +
  818. +static void
  819. +MakeNewTexture(struct winthread *wt)
  820. +{
  821. +#define TEX_SIZE 128
  822. + static float step = 0.0;
  823. + GLfloat image[TEX_SIZE][TEX_SIZE][4];
  824. + GLint width;
  825. + int i, j;
  826. +
  827. + for (j = 0; j < TEX_SIZE; j++) {
  828. + for (i = 0; i < TEX_SIZE; i++) {
  829. + float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE;
  830. + float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE;
  831. + float r = dt * dt + ds * ds + step;
  832. + image[j][i][0] =
  833. + image[j][i][1] =
  834. + image[j][i][2] = 0.75 + 0.25 * cos(r);
  835. + image[j][i][3] = 1.0;
  836. + }
  837. + }
  838. +
  839. + step += 0.5;
  840. +
  841. + glBindTexture(GL_TEXTURE_2D, TexObj);
  842. +
  843. + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
  844. + if (width) {
  845. + assert(width == TEX_SIZE);
  846. + /* sub-tex replace */
  847. + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE,
  848. + GL_RGBA, GL_FLOAT, image);
  849. + }
  850. + else {
  851. + /* create new */
  852. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  853. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  854. +
  855. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
  856. + GL_RGBA, GL_FLOAT, image);
  857. + }
  858. +}
  859. +
  860. +
  861. +
  862. +/* draw a colored cube */
  863. +static void
  864. +draw_object(void)
  865. +{
  866. + glPushMatrix();
  867. + glScalef(0.75, 0.75, 0.75);
  868. +
  869. + glColor3f(1, 0, 0);
  870. +
  871. + if (Texture) {
  872. + glBindTexture(GL_TEXTURE_2D, TexObj);
  873. + glEnable(GL_TEXTURE_2D);
  874. + }
  875. + else {
  876. + glDisable(GL_TEXTURE_2D);
  877. + }
  878. +
  879. + glBegin(GL_QUADS);
  880. +
  881. + /* -X */
  882. + glColor3f(0, 1, 1);
  883. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  884. + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
  885. + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
  886. + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  887. +
  888. + /* +X */
  889. + glColor3f(1, 0, 0);
  890. + glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
  891. + glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
  892. + glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
  893. + glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
  894. +
  895. + /* -Y */
  896. + glColor3f(1, 0, 1);
  897. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  898. + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  899. + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
  900. + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  901. +
  902. + /* +Y */
  903. + glColor3f(0, 1, 0);
  904. + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
  905. + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
  906. + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  907. + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  908. +
  909. + /* -Z */
  910. + glColor3f(1, 1, 0);
  911. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  912. + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  913. + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
  914. + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
  915. +
  916. + /* +Y */
  917. + glColor3f(0, 0, 1);
  918. + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
  919. + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
  920. + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  921. + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  922. +
  923. + glEnd();
  924. +
  925. + glPopMatrix();
  926. +}
  927. +
  928. +
  929. +/* signal resize of given window */
  930. +static void
  931. +resize(struct winthread *wt, int w, int h)
  932. +{
  933. + wt->NewSize = GL_TRUE;
  934. + wt->WinWidth = w;
  935. + wt->WinHeight = h;
  936. + if (!Animate)
  937. + signal_redraw();
  938. +}
  939. +
  940. +
  941. +/*
  942. + * We have an instance of this for each thread.
  943. + */
  944. +static void
  945. +draw_loop(struct winthread *wt)
  946. +{
  947. + while (!ExitFlag) {
  948. +
  949. + if (Locking)
  950. + pthread_mutex_lock(&Mutex);
  951. +
  952. + glXMakeCurrent(wt->Dpy, wt->Win, wt->Context);
  953. + if (!wt->Initialized) {
  954. + printf("glthreads: %d: GL_RENDERER = %s\n", wt->Index,
  955. + (char *) glGetString(GL_RENDERER));
  956. + if (Texture /*&& wt->Index == 0*/) {
  957. + MakeNewTexture(wt);
  958. + }
  959. + wt->Initialized = GL_TRUE;
  960. + }
  961. +
  962. + if (Locking)
  963. + pthread_mutex_unlock(&Mutex);
  964. +
  965. + glEnable(GL_DEPTH_TEST);
  966. +
  967. + if (wt->NewSize) {
  968. + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight;
  969. + glViewport(0, 0, wt->WinWidth, wt->WinHeight);
  970. + glMatrixMode(GL_PROJECTION);
  971. + glLoadIdentity();
  972. + glFrustum(-w, w, -1.0, 1.0, 1.5, 10);
  973. + glMatrixMode(GL_MODELVIEW);
  974. + glLoadIdentity();
  975. + glTranslatef(0, 0, -2.5);
  976. + wt->NewSize = GL_FALSE;
  977. + }
  978. +
  979. + if (wt->MakeNewTexture) {
  980. + MakeNewTexture(wt);
  981. + wt->MakeNewTexture = GL_FALSE;
  982. + }
  983. +
  984. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  985. +
  986. + glPushMatrix();
  987. + glRotatef(wt->Angle, 0, 1, 0);
  988. + glRotatef(wt->Angle, 1, 0, 0);
  989. + glScalef(0.7, 0.7, 0.7);
  990. + draw_object();
  991. + glPopMatrix();
  992. +
  993. + if (Locking)
  994. + pthread_mutex_lock(&Mutex);
  995. +
  996. + glXSwapBuffers(wt->Dpy, wt->Win);
  997. +
  998. + if (Locking)
  999. + pthread_mutex_unlock(&Mutex);
  1000. +
  1001. + if (Animate) {
  1002. + usleep(5000);
  1003. + }
  1004. + else {
  1005. + /* wait for signal to draw */
  1006. + pthread_mutex_lock(&CondMutex);
  1007. + pthread_cond_wait(&CondVar, &CondMutex);
  1008. + pthread_mutex_unlock(&CondMutex);
  1009. + }
  1010. + wt->Angle += 1.0;
  1011. + }
  1012. +}
  1013. +
  1014. +
  1015. +static void
  1016. +keypress(XEvent *event, struct winthread *wt)
  1017. +{
  1018. + char buf[100];
  1019. + KeySym keySym;
  1020. + XComposeStatus stat;
  1021. +
  1022. + XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat);
  1023. +
  1024. + switch (keySym) {
  1025. + case XK_Escape:
  1026. + /* tell all threads to exit */
  1027. + if (!Animate) {
  1028. + signal_redraw();
  1029. + }
  1030. + ExitFlag = GL_TRUE;
  1031. + /*printf("exit draw_loop %d\n", wt->Index);*/
  1032. + return;
  1033. + case XK_t:
  1034. + case XK_T:
  1035. + if (Texture) {
  1036. + wt->MakeNewTexture = GL_TRUE;
  1037. + if (!Animate)
  1038. + signal_redraw();
  1039. + }
  1040. + break;
  1041. + case XK_a:
  1042. + case XK_A:
  1043. + Animate = !Animate;
  1044. + if (Animate) /* yes, prev Animate state! */
  1045. + signal_redraw();
  1046. + break;
  1047. + case XK_s:
  1048. + case XK_S:
  1049. + if (!Animate)
  1050. + signal_redraw();
  1051. + break;
  1052. + default:
  1053. + ; /* nop */
  1054. + }
  1055. +}
  1056. +
  1057. +
  1058. +/*
  1059. + * The main process thread runs this loop.
  1060. + * Single display connection for all threads.
  1061. + */
  1062. +static void
  1063. +event_loop(Display *dpy)
  1064. +{
  1065. + XEvent event;
  1066. + int i;
  1067. +
  1068. + assert(!MultiDisplays);
  1069. +
  1070. + while (!ExitFlag) {
  1071. +
  1072. + if (Locking) {
  1073. + while (1) {
  1074. + int k;
  1075. + pthread_mutex_lock(&Mutex);
  1076. + k = XPending(dpy);
  1077. + if (k) {
  1078. + XNextEvent(dpy, &event);
  1079. + pthread_mutex_unlock(&Mutex);
  1080. + break;
  1081. + }
  1082. + pthread_mutex_unlock(&Mutex);
  1083. + usleep(5000);
  1084. + }
  1085. + }
  1086. + else {
  1087. + XNextEvent(dpy, &event);
  1088. + }
  1089. +
  1090. + switch (event.type) {
  1091. + case ConfigureNotify:
  1092. + /* Find winthread for this event's window */
  1093. + for (i = 0; i < NumWinThreads; i++) {
  1094. + struct winthread *wt = &WinThreads[i];
  1095. + if (event.xconfigure.window == wt->Win) {
  1096. + resize(wt, event.xconfigure.width,
  1097. + event.xconfigure.height);
  1098. + break;
  1099. + }
  1100. + }
  1101. + break;
  1102. + case KeyPress:
  1103. + for (i = 0; i < NumWinThreads; i++) {
  1104. + struct winthread *wt = &WinThreads[i];
  1105. + if (event.xkey.window == wt->Win) {
  1106. + keypress(&event, wt);
  1107. + break;
  1108. + }
  1109. + }
  1110. + break;
  1111. + default:
  1112. + /*no-op*/ ;
  1113. + }
  1114. + }
  1115. +}
  1116. +
  1117. +
  1118. +/*
  1119. + * Separate display connection for each thread.
  1120. + */
  1121. +static void
  1122. +event_loop_multi(void)
  1123. +{
  1124. + XEvent event;
  1125. + int w = 0;
  1126. +
  1127. + assert(MultiDisplays);
  1128. +
  1129. + while (!ExitFlag) {
  1130. + struct winthread *wt = &WinThreads[w];
  1131. + if (XPending(wt->Dpy)) {
  1132. + XNextEvent(wt->Dpy, &event);
  1133. + switch (event.type) {
  1134. + case ConfigureNotify:
  1135. + resize(wt, event.xconfigure.width, event.xconfigure.height);
  1136. + break;
  1137. + case KeyPress:
  1138. + keypress(&event, wt);
  1139. + break;
  1140. + default:
  1141. + ; /* nop */
  1142. + }
  1143. + }
  1144. + w = (w + 1) % NumWinThreads;
  1145. + usleep(5000);
  1146. + }
  1147. +}
  1148. +
  1149. +
  1150. +
  1151. +/*
  1152. + * we'll call this once for each thread, before the threads are created.
  1153. + */
  1154. +static void
  1155. +create_window(struct winthread *wt, GLXContext shareCtx)
  1156. +{
  1157. + Window win;
  1158. + GLXContext ctx;
  1159. + int attrib[] = { GLX_RGBA,
  1160. + GLX_RED_SIZE, 1,
  1161. + GLX_GREEN_SIZE, 1,
  1162. + GLX_BLUE_SIZE, 1,
  1163. + GLX_DEPTH_SIZE, 1,
  1164. + GLX_DOUBLEBUFFER,
  1165. + None };
  1166. + int scrnum;
  1167. + XSetWindowAttributes attr;
  1168. + unsigned long mask;
  1169. + Window root;
  1170. + XVisualInfo *visinfo;
  1171. + int width = 160, height = 160;
  1172. + int xpos = (wt->Index % 8) * (width + 10);
  1173. + int ypos = (wt->Index / 8) * (width + 20);
  1174. +
  1175. + scrnum = DefaultScreen(wt->Dpy);
  1176. + root = RootWindow(wt->Dpy, scrnum);
  1177. +
  1178. + visinfo = glXChooseVisual(wt->Dpy, scrnum, attrib);
  1179. + if (!visinfo) {
  1180. + Error("Unable to find RGB, Z, double-buffered visual");
  1181. + }
  1182. +
  1183. + /* window attributes */
  1184. + attr.background_pixel = 0;
  1185. + attr.border_pixel = 0;
  1186. + attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone);
  1187. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  1188. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  1189. +
  1190. + win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height,
  1191. + 0, visinfo->depth, InputOutput,
  1192. + visinfo->visual, mask, &attr);
  1193. + if (!win) {
  1194. + Error("Couldn't create window");
  1195. + }
  1196. +
  1197. + {
  1198. + XSizeHints sizehints;
  1199. + sizehints.x = xpos;
  1200. + sizehints.y = ypos;
  1201. + sizehints.width = width;
  1202. + sizehints.height = height;
  1203. + sizehints.flags = USSize | USPosition;
  1204. + XSetNormalHints(wt->Dpy, win, &sizehints);
  1205. + XSetStandardProperties(wt->Dpy, win, "glthreads", "glthreads",
  1206. + None, (char **)NULL, 0, &sizehints);
  1207. + }
  1208. +
  1209. +
  1210. + ctx = glXCreateContext(wt->Dpy, visinfo, shareCtx, True);
  1211. + if (!ctx) {
  1212. + Error("Couldn't create GLX context");
  1213. + }
  1214. +
  1215. + XMapWindow(wt->Dpy, win);
  1216. + XSync(wt->Dpy, 0);
  1217. +
  1218. + /* save the info for this window/context */
  1219. + wt->Win = win;
  1220. + wt->Context = ctx;
  1221. + wt->Angle = 0.0;
  1222. + wt->WinWidth = width;
  1223. + wt->WinHeight = height;
  1224. + wt->NewSize = GL_TRUE;
  1225. +}
  1226. +
  1227. +
  1228. +/*
  1229. + * Called by pthread_create()
  1230. + */
  1231. +static void *
  1232. +thread_function(void *p)
  1233. +{
  1234. + struct winthread *wt = (struct winthread *) p;
  1235. + draw_loop(wt);
  1236. + return NULL;
  1237. +}
  1238. +
  1239. +
  1240. +/*
  1241. + * called before exit to wait for all threads to finish
  1242. + */
  1243. +static void
  1244. +clean_up(void)
  1245. +{
  1246. + int i;
  1247. +
  1248. + /* wait for threads to finish */
  1249. + for (i = 0; i < NumWinThreads; i++) {
  1250. + pthread_join(WinThreads[i].Thread, NULL);
  1251. + }
  1252. +
  1253. + for (i = 0; i < NumWinThreads; i++) {
  1254. + glXDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context);
  1255. + XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win);
  1256. + }
  1257. +}
  1258. +
  1259. +
  1260. +static void
  1261. +usage(void)
  1262. +{
  1263. + printf("glthreads: test of GL thread safety (any key = exit)\n");
  1264. + printf("Usage:\n");
  1265. + printf(" glthreads [options]\n");
  1266. + printf("Options:\n");
  1267. + printf(" -display DISPLAYNAME Specify display string\n");
  1268. + printf(" -n NUMTHREADS Number of threads to create\n");
  1269. + printf(" -p Use a separate display connection for each thread\n");
  1270. + printf(" -l Use application-side locking\n");
  1271. + printf(" -t Enable texturing\n");
  1272. + printf("Keyboard:\n");
  1273. + printf(" Esc Exit\n");
  1274. + printf(" t Change texture image (requires -t option)\n");
  1275. + printf(" a Toggle animation\n");
  1276. + printf(" s Step rotation (when not animating)\n");
  1277. +}
  1278. +
  1279. +
  1280. +int
  1281. +main(int argc, char *argv[])
  1282. +{
  1283. + char *displayName = NULL;
  1284. + int numThreads = 2;
  1285. + Display *dpy = NULL;
  1286. + int i;
  1287. + Status threadStat;
  1288. +
  1289. + if (argc == 1) {
  1290. + usage();
  1291. + }
  1292. + else {
  1293. + int i;
  1294. + for (i = 1; i < argc; i++) {
  1295. + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
  1296. + displayName = argv[i + 1];
  1297. + i++;
  1298. + }
  1299. + else if (strcmp(argv[i], "-p") == 0) {
  1300. + MultiDisplays = 1;
  1301. + }
  1302. + else if (strcmp(argv[i], "-l") == 0) {
  1303. + Locking = 1;
  1304. + }
  1305. + else if (strcmp(argv[i], "-t") == 0) {
  1306. + Texture = 1;
  1307. + }
  1308. + else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) {
  1309. + numThreads = atoi(argv[i + 1]);
  1310. + if (numThreads < 1)
  1311. + numThreads = 1;
  1312. + else if (numThreads > MAX_WINTHREADS)
  1313. + numThreads = MAX_WINTHREADS;
  1314. + i++;
  1315. + }
  1316. + else {
  1317. + usage();
  1318. + exit(1);
  1319. + }
  1320. + }
  1321. + }
  1322. +
  1323. + if (Locking)
  1324. + printf("glthreads: Using explicit locks around Xlib calls.\n");
  1325. + else
  1326. + printf("glthreads: No explict locking.\n");
  1327. +
  1328. + if (MultiDisplays)
  1329. + printf("glthreads: Per-thread display connections.\n");
  1330. + else
  1331. + printf("glthreads: Single display connection.\n");
  1332. +
  1333. + /*
  1334. + * VERY IMPORTANT: call XInitThreads() before any other Xlib functions.
  1335. + */
  1336. + if (!MultiDisplays) {
  1337. + if (!Locking) {
  1338. + threadStat = XInitThreads();
  1339. + if (threadStat) {
  1340. + printf("XInitThreads() returned %d (success)\n", (int) threadStat);
  1341. + }
  1342. + else {
  1343. + printf("XInitThreads() returned 0 (failure- this program may fail)\n");
  1344. + }
  1345. + }
  1346. +
  1347. + dpy = XOpenDisplay(displayName);
  1348. + if (!dpy) {
  1349. + fprintf(stderr, "Unable to open display %s\n", XDisplayName(displayName));
  1350. + return -1;
  1351. + }
  1352. + }
  1353. +
  1354. + pthread_mutex_init(&Mutex, NULL);
  1355. + pthread_mutex_init(&CondMutex, NULL);
  1356. + pthread_cond_init(&CondVar, NULL);
  1357. +
  1358. + printf("glthreads: creating windows\n");
  1359. +
  1360. + NumWinThreads = numThreads;
  1361. +
  1362. + /* Create the GLX windows and contexts */
  1363. + for (i = 0; i < numThreads; i++) {
  1364. + GLXContext share;
  1365. +
  1366. + if (MultiDisplays) {
  1367. + WinThreads[i].Dpy = XOpenDisplay(displayName);
  1368. + assert(WinThreads[i].Dpy);
  1369. + }
  1370. + else {
  1371. + WinThreads[i].Dpy = dpy;
  1372. + }
  1373. + WinThreads[i].Index = i;
  1374. + WinThreads[i].Initialized = GL_FALSE;
  1375. +
  1376. + share = (Texture && i > 0) ? WinThreads[0].Context : 0;
  1377. +
  1378. + create_window(&WinThreads[i], share);
  1379. + }
  1380. +
  1381. + printf("glthreads: creating threads\n");
  1382. +
  1383. + /* Create the threads */
  1384. + for (i = 0; i < numThreads; i++) {
  1385. + pthread_create(&WinThreads[i].Thread, NULL, thread_function,
  1386. + (void*) &WinThreads[i]);
  1387. + printf("glthreads: Created thread %p\n", (void *) WinThreads[i].Thread);
  1388. + }
  1389. +
  1390. + if (MultiDisplays)
  1391. + event_loop_multi();
  1392. + else
  1393. + event_loop(dpy);
  1394. +
  1395. + clean_up();
  1396. +
  1397. + if (MultiDisplays) {
  1398. + for (i = 0; i < numThreads; i++) {
  1399. + XCloseDisplay(WinThreads[i].Dpy);
  1400. + }
  1401. + }
  1402. + else {
  1403. + XCloseDisplay(dpy);
  1404. + }
  1405. +
  1406. + return 0;
  1407. +}
  1408. +
  1409. +
  1410. +#else /* PTHREADS */
  1411. +
  1412. +
  1413. +#include <stdio.h>
  1414. +
  1415. +int
  1416. +main(int argc, char *argv[])
  1417. +{
  1418. + printf("Sorry, this program wasn't compiled with PTHREADS defined.\n");
  1419. + return 0;
  1420. +}
  1421. +
  1422. +
  1423. +#endif /* PTHREADS */
  1424. diff -Naurp Mesa-7.8.1/progs/xdemos/glxcontexts.c Mesa-7.8.1.patched/progs/xdemos/glxcontexts.c
  1425. --- Mesa-7.8.1/progs/xdemos/glxcontexts.c 1970-01-01 01:00:00.000000000 +0100
  1426. +++ Mesa-7.8.1.patched/progs/xdemos/glxcontexts.c 2010-06-13 13:45:06.789793146 +0200
  1427. @@ -0,0 +1,548 @@
  1428. +/*
  1429. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  1430. + *
  1431. + * Permission is hereby granted, free of charge, to any person obtaining a
  1432. + * copy of this software and associated documentation files (the "Software"),
  1433. + * to deal in the Software without restriction, including without limitation
  1434. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1435. + * and/or sell copies of the Software, and to permit persons to whom the
  1436. + * Software is furnished to do so, subject to the following conditions:
  1437. + *
  1438. + * The above copyright notice and this permission notice shall be included
  1439. + * in all copies or substantial portions of the Software.
  1440. + *
  1441. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1442. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1443. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  1444. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  1445. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1446. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1447. + */
  1448. +
  1449. +/*
  1450. + * Version of glxgears that creates/destroys the rendering context for each
  1451. + * frame. Also periodically destroy/recreate the window.
  1452. + * Good for finding memory leaks, etc.
  1453. + *
  1454. + * Command line options:
  1455. + * -info print GL implementation information
  1456. + *
  1457. + */
  1458. +
  1459. +
  1460. +#include <assert.h>
  1461. +#include <math.h>
  1462. +#include <stdlib.h>
  1463. +#include <stdio.h>
  1464. +#include <string.h>
  1465. +#include <X11/Xlib.h>
  1466. +#include <X11/keysym.h>
  1467. +#include <GL/gl.h>
  1468. +#include <GL/glx.h>
  1469. +
  1470. +
  1471. +#define BENCHMARK
  1472. +
  1473. +#ifdef BENCHMARK
  1474. +
  1475. +/* XXX this probably isn't very portable */
  1476. +
  1477. +#include <sys/time.h>
  1478. +#include <unistd.h>
  1479. +
  1480. +/* return current time (in seconds) */
  1481. +static double
  1482. +current_time(void)
  1483. +{
  1484. + struct timeval tv;
  1485. +#ifdef __VMS
  1486. + (void) gettimeofday(&tv, NULL );
  1487. +#else
  1488. + struct timezone tz;
  1489. + (void) gettimeofday(&tv, &tz);
  1490. +#endif
  1491. + return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  1492. +}
  1493. +
  1494. +#else /*BENCHMARK*/
  1495. +
  1496. +/* dummy */
  1497. +static double
  1498. +current_time(void)
  1499. +{
  1500. + /* update this function for other platforms! */
  1501. + static double t = 0.0;
  1502. + static int warn = 1;
  1503. + if (warn) {
  1504. + fprintf(stderr, "Warning: current_time() not implemented!!\n");
  1505. + warn = 0;
  1506. + }
  1507. + return t += 1.0;
  1508. +}
  1509. +
  1510. +#endif /*BENCHMARK*/
  1511. +
  1512. +
  1513. +
  1514. +#ifndef M_PI
  1515. +#define M_PI 3.14159265
  1516. +#endif
  1517. +
  1518. +
  1519. +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  1520. +static GLint gear1, gear2, gear3;
  1521. +static GLfloat angle = 0.0;
  1522. +
  1523. +static XVisualInfo *visinfo = NULL;
  1524. +static int WinWidth = 300, WinHeight = 300;
  1525. +
  1526. +
  1527. +/*
  1528. + *
  1529. + * Draw a gear wheel. You'll probably want to call this function when
  1530. + * building a display list since we do a lot of trig here.
  1531. + *
  1532. + * Input: inner_radius - radius of hole at center
  1533. + * outer_radius - radius at center of teeth
  1534. + * width - width of gear
  1535. + * teeth - number of teeth
  1536. + * tooth_depth - depth of tooth
  1537. + */
  1538. +static void
  1539. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  1540. + GLint teeth, GLfloat tooth_depth)
  1541. +{
  1542. + GLint i;
  1543. + GLfloat r0, r1, r2;
  1544. + GLfloat angle, da;
  1545. + GLfloat u, v, len;
  1546. +
  1547. + r0 = inner_radius;
  1548. + r1 = outer_radius - tooth_depth / 2.0;
  1549. + r2 = outer_radius + tooth_depth / 2.0;
  1550. +
  1551. + da = 2.0 * M_PI / teeth / 4.0;
  1552. +
  1553. + glShadeModel(GL_FLAT);
  1554. +
  1555. + glNormal3f(0.0, 0.0, 1.0);
  1556. +
  1557. + /* draw front face */
  1558. + glBegin(GL_QUAD_STRIP);
  1559. + for (i = 0; i <= teeth; i++) {
  1560. + angle = i * 2.0 * M_PI / teeth;
  1561. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  1562. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  1563. + if (i < teeth) {
  1564. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  1565. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1566. + width * 0.5);
  1567. + }
  1568. + }
  1569. + glEnd();
  1570. +
  1571. + /* draw front sides of teeth */
  1572. + glBegin(GL_QUADS);
  1573. + da = 2.0 * M_PI / teeth / 4.0;
  1574. + for (i = 0; i < teeth; i++) {
  1575. + angle = i * 2.0 * M_PI / teeth;
  1576. +
  1577. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  1578. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  1579. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  1580. + width * 0.5);
  1581. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1582. + width * 0.5);
  1583. + }
  1584. + glEnd();
  1585. +
  1586. + glNormal3f(0.0, 0.0, -1.0);
  1587. +
  1588. + /* draw back face */
  1589. + glBegin(GL_QUAD_STRIP);
  1590. + for (i = 0; i <= teeth; i++) {
  1591. + angle = i * 2.0 * M_PI / teeth;
  1592. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  1593. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  1594. + if (i < teeth) {
  1595. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1596. + -width * 0.5);
  1597. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  1598. + }
  1599. + }
  1600. + glEnd();
  1601. +
  1602. + /* draw back sides of teeth */
  1603. + glBegin(GL_QUADS);
  1604. + da = 2.0 * M_PI / teeth / 4.0;
  1605. + for (i = 0; i < teeth; i++) {
  1606. + angle = i * 2.0 * M_PI / teeth;
  1607. +
  1608. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1609. + -width * 0.5);
  1610. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  1611. + -width * 0.5);
  1612. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  1613. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  1614. + }
  1615. + glEnd();
  1616. +
  1617. + /* draw outward faces of teeth */
  1618. + glBegin(GL_QUAD_STRIP);
  1619. + for (i = 0; i < teeth; i++) {
  1620. + angle = i * 2.0 * M_PI / teeth;
  1621. +
  1622. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  1623. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  1624. + u = r2 * cos(angle + da) - r1 * cos(angle);
  1625. + v = r2 * sin(angle + da) - r1 * sin(angle);
  1626. + len = sqrt(u * u + v * v);
  1627. + u /= len;
  1628. + v /= len;
  1629. + glNormal3f(v, -u, 0.0);
  1630. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  1631. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  1632. + glNormal3f(cos(angle), sin(angle), 0.0);
  1633. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  1634. + width * 0.5);
  1635. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  1636. + -width * 0.5);
  1637. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  1638. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  1639. + glNormal3f(v, -u, 0.0);
  1640. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1641. + width * 0.5);
  1642. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  1643. + -width * 0.5);
  1644. + glNormal3f(cos(angle), sin(angle), 0.0);
  1645. + }
  1646. +
  1647. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  1648. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  1649. +
  1650. + glEnd();
  1651. +
  1652. + glShadeModel(GL_SMOOTH);
  1653. +
  1654. + /* draw inside radius cylinder */
  1655. + glBegin(GL_QUAD_STRIP);
  1656. + for (i = 0; i <= teeth; i++) {
  1657. + angle = i * 2.0 * M_PI / teeth;
  1658. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  1659. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  1660. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  1661. + }
  1662. + glEnd();
  1663. +}
  1664. +
  1665. +
  1666. +static void
  1667. +do_draw(void)
  1668. +{
  1669. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1670. +
  1671. + glPushMatrix();
  1672. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  1673. + glRotatef(view_roty, 0.0, 1.0, 0.0);
  1674. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  1675. +
  1676. + glPushMatrix();
  1677. + glTranslatef(-3.0, -2.0, 0.0);
  1678. + glRotatef(angle, 0.0, 0.0, 1.0);
  1679. + glCallList(gear1);
  1680. + glPopMatrix();
  1681. +
  1682. + glPushMatrix();
  1683. + glTranslatef(3.1, -2.0, 0.0);
  1684. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  1685. + glCallList(gear2);
  1686. + glPopMatrix();
  1687. +
  1688. + glPushMatrix();
  1689. + glTranslatef(-3.1, 4.2, 0.0);
  1690. + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  1691. + glCallList(gear3);
  1692. + glPopMatrix();
  1693. +
  1694. + glPopMatrix();
  1695. +}
  1696. +
  1697. +
  1698. +/* new window size or exposure */
  1699. +static void
  1700. +reshape(int width, int height)
  1701. +{
  1702. + glViewport(0, 0, (GLint) width, (GLint) height);
  1703. +
  1704. + {
  1705. + GLfloat h = (GLfloat) height / (GLfloat) width;
  1706. +
  1707. + glMatrixMode(GL_PROJECTION);
  1708. + glLoadIdentity();
  1709. + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  1710. + }
  1711. +
  1712. + glMatrixMode(GL_MODELVIEW);
  1713. + glLoadIdentity();
  1714. + glTranslatef(0.0, 0.0, -40.0);
  1715. +}
  1716. +
  1717. +
  1718. +static void
  1719. +init(void)
  1720. +{
  1721. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  1722. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  1723. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  1724. + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  1725. +
  1726. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  1727. + glEnable(GL_CULL_FACE);
  1728. + glEnable(GL_LIGHTING);
  1729. + glEnable(GL_LIGHT0);
  1730. + glEnable(GL_DEPTH_TEST);
  1731. +
  1732. + /* make the gears */
  1733. + gear1 = glGenLists(1);
  1734. + glNewList(gear1, GL_COMPILE);
  1735. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  1736. + gear(1.0, 4.0, 1.0, 20, 0.7);
  1737. + glEndList();
  1738. +
  1739. + gear2 = glGenLists(1);
  1740. + glNewList(gear2, GL_COMPILE);
  1741. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  1742. + gear(0.5, 2.0, 2.0, 10, 0.7);
  1743. + glEndList();
  1744. +
  1745. + gear3 = glGenLists(1);
  1746. + glNewList(gear3, GL_COMPILE);
  1747. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  1748. + gear(1.3, 2.0, 0.5, 10, 0.7);
  1749. + glEndList();
  1750. +
  1751. + glEnable(GL_NORMALIZE);
  1752. +}
  1753. +
  1754. +
  1755. +static void
  1756. +draw( Display *dpy, Window win )
  1757. +{
  1758. + GLXContext ctx;
  1759. +
  1760. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  1761. + if (!ctx) {
  1762. + printf("Error: glXCreateContext failed\n");
  1763. + exit(1);
  1764. + }
  1765. +
  1766. + glXMakeCurrent(dpy, win, ctx);
  1767. +
  1768. + init();
  1769. +
  1770. + reshape(WinWidth, WinHeight);
  1771. +
  1772. + do_draw();
  1773. +
  1774. + glDeleteLists(gear1, 1);
  1775. + glDeleteLists(gear2, 1);
  1776. + glDeleteLists(gear3, 1);
  1777. +
  1778. + glXSwapBuffers(dpy, win);
  1779. + glXDestroyContext(dpy, ctx);
  1780. +}
  1781. +
  1782. +
  1783. +/*
  1784. + * Create an RGB, double-buffered window.
  1785. + * Return the window and context handles.
  1786. + */
  1787. +static void
  1788. +make_window( Display *dpy, const char *name,
  1789. + int x, int y, int width, int height,
  1790. + Window *winRet)
  1791. +{
  1792. + int attribs[] = { GLX_RGBA,
  1793. + GLX_RED_SIZE, 1,
  1794. + GLX_GREEN_SIZE, 1,
  1795. + GLX_BLUE_SIZE, 1,
  1796. + GLX_DOUBLEBUFFER,
  1797. + GLX_DEPTH_SIZE, 1,
  1798. + None };
  1799. + int scrnum;
  1800. + XSetWindowAttributes attr;
  1801. + unsigned long mask;
  1802. + Window root;
  1803. + Window win;
  1804. +
  1805. + scrnum = DefaultScreen( dpy );
  1806. + root = RootWindow( dpy, scrnum );
  1807. +
  1808. + if (visinfo)
  1809. + XFree(visinfo);
  1810. +
  1811. + visinfo = glXChooseVisual( dpy, scrnum, attribs );
  1812. + if (!visinfo) {
  1813. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  1814. + exit(1);
  1815. + }
  1816. +
  1817. + /* window attributes */
  1818. + attr.background_pixel = 0;
  1819. + attr.border_pixel = 0;
  1820. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  1821. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  1822. + attr.override_redirect = 0;
  1823. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
  1824. +
  1825. + win = XCreateWindow( dpy, root, x, y, width, height,
  1826. + 0, visinfo->depth, InputOutput,
  1827. + visinfo->visual, mask, &attr );
  1828. +
  1829. + /* set hints and properties */
  1830. + {
  1831. + XSizeHints sizehints;
  1832. + sizehints.x = x;
  1833. + sizehints.y = y;
  1834. + sizehints.width = width;
  1835. + sizehints.height = height;
  1836. + sizehints.flags = USSize | USPosition;
  1837. + XSetNormalHints(dpy, win, &sizehints);
  1838. + XSetStandardProperties(dpy, win, name, name,
  1839. + None, (char **)NULL, 0, &sizehints);
  1840. + }
  1841. +
  1842. + *winRet = win;
  1843. +}
  1844. +
  1845. +
  1846. +static void
  1847. +event_loop(Display *dpy)
  1848. +{
  1849. + Window win;
  1850. + make_window(dpy, "glxgears", 0, 0, WinWidth, WinHeight, &win);
  1851. + XMapWindow(dpy, win);
  1852. +
  1853. + while (1) {
  1854. + while (XPending(dpy) > 0) {
  1855. + XEvent event;
  1856. + XNextEvent(dpy, &event);
  1857. + switch (event.type) {
  1858. + case Expose:
  1859. + /* we'll redraw below */
  1860. + break;
  1861. + case ConfigureNotify:
  1862. + WinWidth = event.xconfigure.width;
  1863. + WinHeight = event.xconfigure.height;
  1864. + break;
  1865. + case KeyPress:
  1866. + {
  1867. + char buffer[10];
  1868. + int r, code;
  1869. + code = XLookupKeysym(&event.xkey, 0);
  1870. + if (code == XK_Left) {
  1871. + view_roty += 5.0;
  1872. + }
  1873. + else if (code == XK_Right) {
  1874. + view_roty -= 5.0;
  1875. + }
  1876. + else if (code == XK_Up) {
  1877. + view_rotx += 5.0;
  1878. + }
  1879. + else if (code == XK_Down) {
  1880. + view_rotx -= 5.0;
  1881. + }
  1882. + else {
  1883. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  1884. + NULL, NULL);
  1885. + if (buffer[0] == 27) {
  1886. + /* escape */
  1887. + return;
  1888. + }
  1889. + }
  1890. + }
  1891. + }
  1892. + }
  1893. +
  1894. + {
  1895. + static int frames = 0;
  1896. + static double tRot0 = -1.0, tRate0 = -1.0;
  1897. + double dt, t = current_time();
  1898. + if (tRot0 < 0.0)
  1899. + tRot0 = t;
  1900. + dt = t - tRot0;
  1901. + tRot0 = t;
  1902. +
  1903. + /* advance rotation for next frame */
  1904. + angle += 70.0 * dt; /* 70 degrees per second */
  1905. + if (angle > 3600.0)
  1906. + angle -= 3600.0;
  1907. +
  1908. + draw( dpy, win );
  1909. +
  1910. + frames++;
  1911. +
  1912. + if (tRate0 < 0.0)
  1913. + tRate0 = t;
  1914. +
  1915. + if (t - tRate0 >= 1.0) {
  1916. + GLfloat seconds = t - tRate0;
  1917. + GLfloat fps = frames / seconds;
  1918. + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
  1919. + fps);
  1920. + tRate0 = t;
  1921. +
  1922. + /* Destroy window and create new one */
  1923. + XDestroyWindow(dpy, win);
  1924. + make_window(dpy, "glxgears",
  1925. + (int)(fps * 100) % 100, (int)(fps * 100) % 100, /* x,y */
  1926. + WinWidth, WinHeight, &win);
  1927. + XMapWindow(dpy, win);
  1928. +
  1929. + frames = 0;
  1930. + }
  1931. + }
  1932. + }
  1933. +}
  1934. +
  1935. +
  1936. +int
  1937. +main(int argc, char *argv[])
  1938. +{
  1939. + Display *dpy;
  1940. + char *dpyName = NULL;
  1941. + GLboolean printInfo = GL_FALSE;
  1942. + int i;
  1943. +
  1944. + for (i = 1; i < argc; i++) {
  1945. + if (strcmp(argv[i], "-display") == 0) {
  1946. + dpyName = argv[i+1];
  1947. + i++;
  1948. + }
  1949. + else if (strcmp(argv[i], "-info") == 0) {
  1950. + printInfo = GL_TRUE;
  1951. + }
  1952. + else
  1953. + printf("Warrning: unknown parameter: %s\n", argv[i]);
  1954. + }
  1955. +
  1956. + dpy = XOpenDisplay(dpyName);
  1957. + if (!dpy) {
  1958. + fprintf(stderr, "Error: couldn't open display %s\n",
  1959. + XDisplayName(dpyName));
  1960. + return -1;
  1961. + }
  1962. +
  1963. + if (printInfo) {
  1964. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  1965. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  1966. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  1967. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  1968. + }
  1969. +
  1970. + event_loop(dpy);
  1971. +
  1972. + XCloseDisplay(dpy);
  1973. +
  1974. + return 0;
  1975. +}
  1976. diff -Naurp Mesa-7.8.1/progs/xdemos/glxdemo.c Mesa-7.8.1.patched/progs/xdemos/glxdemo.c
  1977. --- Mesa-7.8.1/progs/xdemos/glxdemo.c 1970-01-01 01:00:00.000000000 +0100
  1978. +++ Mesa-7.8.1.patched/progs/xdemos/glxdemo.c 2010-06-13 13:45:06.789793146 +0200
  1979. @@ -0,0 +1,127 @@
  1980. +
  1981. +
  1982. +/*
  1983. + * A demonstration of using the GLX functions. This program is in the
  1984. + * public domain.
  1985. + *
  1986. + * Brian Paul
  1987. + */
  1988. +
  1989. +#include <GL/gl.h>
  1990. +#include <GL/glx.h>
  1991. +#include <stdio.h>
  1992. +#include <stdlib.h>
  1993. +
  1994. +
  1995. +
  1996. +static void redraw( Display *dpy, Window w )
  1997. +{
  1998. + printf("Redraw event\n");
  1999. +
  2000. + glClear( GL_COLOR_BUFFER_BIT );
  2001. +
  2002. + glColor3f( 1.0, 1.0, 0.0 );
  2003. + glRectf( -0.8, -0.8, 0.8, 0.8 );
  2004. +
  2005. + glXSwapBuffers( dpy, w );
  2006. +}
  2007. +
  2008. +
  2009. +
  2010. +static void resize( unsigned int width, unsigned int height )
  2011. +{
  2012. + printf("Resize event\n");
  2013. + glViewport( 0, 0, width, height );
  2014. + glMatrixMode( GL_PROJECTION );
  2015. + glLoadIdentity();
  2016. + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
  2017. +}
  2018. +
  2019. +
  2020. +
  2021. +static Window make_rgb_db_window( Display *dpy,
  2022. + unsigned int width, unsigned int height )
  2023. +{
  2024. + int attrib[] = { GLX_RGBA,
  2025. + GLX_RED_SIZE, 1,
  2026. + GLX_GREEN_SIZE, 1,
  2027. + GLX_BLUE_SIZE, 1,
  2028. + GLX_DOUBLEBUFFER,
  2029. + None };
  2030. + int scrnum;
  2031. + XSetWindowAttributes attr;
  2032. + unsigned long mask;
  2033. + Window root;
  2034. + Window win;
  2035. + GLXContext ctx;
  2036. + XVisualInfo *visinfo;
  2037. +
  2038. + scrnum = DefaultScreen( dpy );
  2039. + root = RootWindow( dpy, scrnum );
  2040. +
  2041. + visinfo = glXChooseVisual( dpy, scrnum, attrib );
  2042. + if (!visinfo) {
  2043. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  2044. + exit(1);
  2045. + }
  2046. +
  2047. + /* window attributes */
  2048. + attr.background_pixel = 0;
  2049. + attr.border_pixel = 0;
  2050. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  2051. + attr.event_mask = StructureNotifyMask | ExposureMask;
  2052. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  2053. +
  2054. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  2055. + 0, visinfo->depth, InputOutput,
  2056. + visinfo->visual, mask, &attr );
  2057. +
  2058. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  2059. + if (!ctx) {
  2060. + printf("Error: glXCreateContext failed\n");
  2061. + exit(1);
  2062. + }
  2063. +
  2064. + glXMakeCurrent( dpy, win, ctx );
  2065. +
  2066. + return win;
  2067. +}
  2068. +
  2069. +
  2070. +static void event_loop( Display *dpy )
  2071. +{
  2072. + XEvent event;
  2073. +
  2074. + while (1) {
  2075. + XNextEvent( dpy, &event );
  2076. +
  2077. + switch (event.type) {
  2078. + case Expose:
  2079. + redraw( dpy, event.xany.window );
  2080. + break;
  2081. + case ConfigureNotify:
  2082. + resize( event.xconfigure.width, event.xconfigure.height );
  2083. + break;
  2084. + }
  2085. + }
  2086. +}
  2087. +
  2088. +
  2089. +
  2090. +int main( int argc, char *argv[] )
  2091. +{
  2092. + Display *dpy;
  2093. + Window win;
  2094. +
  2095. + dpy = XOpenDisplay(NULL);
  2096. +
  2097. + win = make_rgb_db_window( dpy, 300, 300 );
  2098. +
  2099. + glShadeModel( GL_FLAT );
  2100. + glClearColor( 0.5, 0.5, 0.5, 1.0 );
  2101. +
  2102. + XMapWindow( dpy, win );
  2103. +
  2104. + event_loop( dpy );
  2105. + return 0;
  2106. +}
  2107. diff -Naurp Mesa-7.8.1/progs/xdemos/glxgears.c Mesa-7.8.1.patched/progs/xdemos/glxgears.c
  2108. --- Mesa-7.8.1/progs/xdemos/glxgears.c 1970-01-01 01:00:00.000000000 +0100
  2109. +++ Mesa-7.8.1.patched/progs/xdemos/glxgears.c 2010-06-13 13:45:06.789793146 +0200
  2110. @@ -0,0 +1,787 @@
  2111. +/*
  2112. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  2113. + *
  2114. + * Permission is hereby granted, free of charge, to any person obtaining a
  2115. + * copy of this software and associated documentation files (the "Software"),
  2116. + * to deal in the Software without restriction, including without limitation
  2117. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2118. + * and/or sell copies of the Software, and to permit persons to whom the
  2119. + * Software is furnished to do so, subject to the following conditions:
  2120. + *
  2121. + * The above copyright notice and this permission notice shall be included
  2122. + * in all copies or substantial portions of the Software.
  2123. + *
  2124. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2125. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2126. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  2127. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2128. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2129. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2130. + */
  2131. +
  2132. +/*
  2133. + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
  2134. + * Port by Brian Paul 23 March 2001
  2135. + *
  2136. + * See usage() below for command line options.
  2137. + */
  2138. +
  2139. +
  2140. +#include <math.h>
  2141. +#include <stdlib.h>
  2142. +#include <stdio.h>
  2143. +#include <string.h>
  2144. +#include <X11/Xlib.h>
  2145. +#include <X11/keysym.h>
  2146. +#include <GL/gl.h>
  2147. +#include <GL/glx.h>
  2148. +#include <GL/glxext.h>
  2149. +
  2150. +#ifndef GLX_MESA_swap_control
  2151. +#define GLX_MESA_swap_control 1
  2152. +typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void);
  2153. +#endif
  2154. +
  2155. +
  2156. +#define BENCHMARK
  2157. +
  2158. +#ifdef BENCHMARK
  2159. +
  2160. +/* XXX this probably isn't very portable */
  2161. +
  2162. +#include <sys/time.h>
  2163. +#include <unistd.h>
  2164. +
  2165. +/* return current time (in seconds) */
  2166. +static double
  2167. +current_time(void)
  2168. +{
  2169. + struct timeval tv;
  2170. +#ifdef __VMS
  2171. + (void) gettimeofday(&tv, NULL );
  2172. +#else
  2173. + struct timezone tz;
  2174. + (void) gettimeofday(&tv, &tz);
  2175. +#endif
  2176. + return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  2177. +}
  2178. +
  2179. +#else /*BENCHMARK*/
  2180. +
  2181. +/* dummy */
  2182. +static double
  2183. +current_time(void)
  2184. +{
  2185. + /* update this function for other platforms! */
  2186. + static double t = 0.0;
  2187. + static int warn = 1;
  2188. + if (warn) {
  2189. + fprintf(stderr, "Warning: current_time() not implemented!!\n");
  2190. + warn = 0;
  2191. + }
  2192. + return t += 1.0;
  2193. +}
  2194. +
  2195. +#endif /*BENCHMARK*/
  2196. +
  2197. +
  2198. +
  2199. +#ifndef M_PI
  2200. +#define M_PI 3.14159265
  2201. +#endif
  2202. +
  2203. +
  2204. +/** Event handler results: */
  2205. +#define NOP 0
  2206. +#define EXIT 1
  2207. +#define DRAW 2
  2208. +
  2209. +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  2210. +static GLint gear1, gear2, gear3;
  2211. +static GLfloat angle = 0.0;
  2212. +
  2213. +static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
  2214. +static GLboolean stereo = GL_FALSE; /* Enable stereo. */
  2215. +static GLboolean animate = GL_TRUE; /* Animation */
  2216. +static GLfloat eyesep = 5.0; /* Eye separation. */
  2217. +static GLfloat fix_point = 40.0; /* Fixation point distance. */
  2218. +static GLfloat left, right, asp; /* Stereo frustum params. */
  2219. +
  2220. +
  2221. +/*
  2222. + *
  2223. + * Draw a gear wheel. You'll probably want to call this function when
  2224. + * building a display list since we do a lot of trig here.
  2225. + *
  2226. + * Input: inner_radius - radius of hole at center
  2227. + * outer_radius - radius at center of teeth
  2228. + * width - width of gear
  2229. + * teeth - number of teeth
  2230. + * tooth_depth - depth of tooth
  2231. + */
  2232. +static void
  2233. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  2234. + GLint teeth, GLfloat tooth_depth)
  2235. +{
  2236. + GLint i;
  2237. + GLfloat r0, r1, r2;
  2238. + GLfloat angle, da;
  2239. + GLfloat u, v, len;
  2240. +
  2241. + r0 = inner_radius;
  2242. + r1 = outer_radius - tooth_depth / 2.0;
  2243. + r2 = outer_radius + tooth_depth / 2.0;
  2244. +
  2245. + da = 2.0 * M_PI / teeth / 4.0;
  2246. +
  2247. + glShadeModel(GL_FLAT);
  2248. +
  2249. + glNormal3f(0.0, 0.0, 1.0);
  2250. +
  2251. + /* draw front face */
  2252. + glBegin(GL_QUAD_STRIP);
  2253. + for (i = 0; i <= teeth; i++) {
  2254. + angle = i * 2.0 * M_PI / teeth;
  2255. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  2256. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  2257. + if (i < teeth) {
  2258. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  2259. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2260. + width * 0.5);
  2261. + }
  2262. + }
  2263. + glEnd();
  2264. +
  2265. + /* draw front sides of teeth */
  2266. + glBegin(GL_QUADS);
  2267. + da = 2.0 * M_PI / teeth / 4.0;
  2268. + for (i = 0; i < teeth; i++) {
  2269. + angle = i * 2.0 * M_PI / teeth;
  2270. +
  2271. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  2272. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  2273. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  2274. + width * 0.5);
  2275. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2276. + width * 0.5);
  2277. + }
  2278. + glEnd();
  2279. +
  2280. + glNormal3f(0.0, 0.0, -1.0);
  2281. +
  2282. + /* draw back face */
  2283. + glBegin(GL_QUAD_STRIP);
  2284. + for (i = 0; i <= teeth; i++) {
  2285. + angle = i * 2.0 * M_PI / teeth;
  2286. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  2287. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  2288. + if (i < teeth) {
  2289. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2290. + -width * 0.5);
  2291. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  2292. + }
  2293. + }
  2294. + glEnd();
  2295. +
  2296. + /* draw back sides of teeth */
  2297. + glBegin(GL_QUADS);
  2298. + da = 2.0 * M_PI / teeth / 4.0;
  2299. + for (i = 0; i < teeth; i++) {
  2300. + angle = i * 2.0 * M_PI / teeth;
  2301. +
  2302. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2303. + -width * 0.5);
  2304. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  2305. + -width * 0.5);
  2306. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  2307. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  2308. + }
  2309. + glEnd();
  2310. +
  2311. + /* draw outward faces of teeth */
  2312. + glBegin(GL_QUAD_STRIP);
  2313. + for (i = 0; i < teeth; i++) {
  2314. + angle = i * 2.0 * M_PI / teeth;
  2315. +
  2316. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  2317. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  2318. + u = r2 * cos(angle + da) - r1 * cos(angle);
  2319. + v = r2 * sin(angle + da) - r1 * sin(angle);
  2320. + len = sqrt(u * u + v * v);
  2321. + u /= len;
  2322. + v /= len;
  2323. + glNormal3f(v, -u, 0.0);
  2324. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  2325. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  2326. + glNormal3f(cos(angle), sin(angle), 0.0);
  2327. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  2328. + width * 0.5);
  2329. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  2330. + -width * 0.5);
  2331. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  2332. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  2333. + glNormal3f(v, -u, 0.0);
  2334. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2335. + width * 0.5);
  2336. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  2337. + -width * 0.5);
  2338. + glNormal3f(cos(angle), sin(angle), 0.0);
  2339. + }
  2340. +
  2341. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  2342. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  2343. +
  2344. + glEnd();
  2345. +
  2346. + glShadeModel(GL_SMOOTH);
  2347. +
  2348. + /* draw inside radius cylinder */
  2349. + glBegin(GL_QUAD_STRIP);
  2350. + for (i = 0; i <= teeth; i++) {
  2351. + angle = i * 2.0 * M_PI / teeth;
  2352. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  2353. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  2354. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  2355. + }
  2356. + glEnd();
  2357. +}
  2358. +
  2359. +
  2360. +static void
  2361. +draw(void)
  2362. +{
  2363. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2364. +
  2365. + glPushMatrix();
  2366. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  2367. + glRotatef(view_roty, 0.0, 1.0, 0.0);
  2368. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  2369. +
  2370. + glPushMatrix();
  2371. + glTranslatef(-3.0, -2.0, 0.0);
  2372. + glRotatef(angle, 0.0, 0.0, 1.0);
  2373. + glCallList(gear1);
  2374. + glPopMatrix();
  2375. +
  2376. + glPushMatrix();
  2377. + glTranslatef(3.1, -2.0, 0.0);
  2378. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  2379. + glCallList(gear2);
  2380. + glPopMatrix();
  2381. +
  2382. + glPushMatrix();
  2383. + glTranslatef(-3.1, 4.2, 0.0);
  2384. + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  2385. + glCallList(gear3);
  2386. + glPopMatrix();
  2387. +
  2388. + glPopMatrix();
  2389. +}
  2390. +
  2391. +
  2392. +static void
  2393. +draw_gears(void)
  2394. +{
  2395. + if (stereo) {
  2396. + /* First left eye. */
  2397. + glDrawBuffer(GL_BACK_LEFT);
  2398. +
  2399. + glMatrixMode(GL_PROJECTION);
  2400. + glLoadIdentity();
  2401. + glFrustum(left, right, -asp, asp, 5.0, 60.0);
  2402. +
  2403. + glMatrixMode(GL_MODELVIEW);
  2404. +
  2405. + glPushMatrix();
  2406. + glTranslated(+0.5 * eyesep, 0.0, 0.0);
  2407. + draw();
  2408. + glPopMatrix();
  2409. +
  2410. + /* Then right eye. */
  2411. + glDrawBuffer(GL_BACK_RIGHT);
  2412. +
  2413. + glMatrixMode(GL_PROJECTION);
  2414. + glLoadIdentity();
  2415. + glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
  2416. +
  2417. + glMatrixMode(GL_MODELVIEW);
  2418. +
  2419. + glPushMatrix();
  2420. + glTranslated(-0.5 * eyesep, 0.0, 0.0);
  2421. + draw();
  2422. + glPopMatrix();
  2423. + }
  2424. + else {
  2425. + draw();
  2426. + }
  2427. +}
  2428. +
  2429. +
  2430. +/** Draw single frame, do SwapBuffers, compute FPS */
  2431. +static void
  2432. +draw_frame(Display *dpy, Window win)
  2433. +{
  2434. + static int frames = 0;
  2435. + static double tRot0 = -1.0, tRate0 = -1.0;
  2436. + double dt, t = current_time();
  2437. +
  2438. + if (tRot0 < 0.0)
  2439. + tRot0 = t;
  2440. + dt = t - tRot0;
  2441. + tRot0 = t;
  2442. +
  2443. + if (animate) {
  2444. + /* advance rotation for next frame */
  2445. + angle += 70.0 * dt; /* 70 degrees per second */
  2446. + if (angle > 3600.0)
  2447. + angle -= 3600.0;
  2448. + }
  2449. +
  2450. + draw_gears();
  2451. + glXSwapBuffers(dpy, win);
  2452. +
  2453. + frames++;
  2454. +
  2455. + if (tRate0 < 0.0)
  2456. + tRate0 = t;
  2457. + if (t - tRate0 >= 5.0) {
  2458. + GLfloat seconds = t - tRate0;
  2459. + GLfloat fps = frames / seconds;
  2460. + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
  2461. + fps);
  2462. + tRate0 = t;
  2463. + frames = 0;
  2464. + }
  2465. +}
  2466. +
  2467. +
  2468. +/* new window size or exposure */
  2469. +static void
  2470. +reshape(int width, int height)
  2471. +{
  2472. + glViewport(0, 0, (GLint) width, (GLint) height);
  2473. +
  2474. + if (stereo) {
  2475. + GLfloat w;
  2476. +
  2477. + asp = (GLfloat) height / (GLfloat) width;
  2478. + w = fix_point * (1.0 / 5.0);
  2479. +
  2480. + left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
  2481. + right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
  2482. + }
  2483. + else {
  2484. + GLfloat h = (GLfloat) height / (GLfloat) width;
  2485. +
  2486. + glMatrixMode(GL_PROJECTION);
  2487. + glLoadIdentity();
  2488. + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  2489. + }
  2490. +
  2491. + glMatrixMode(GL_MODELVIEW);
  2492. + glLoadIdentity();
  2493. + glTranslatef(0.0, 0.0, -40.0);
  2494. +}
  2495. +
  2496. +
  2497. +
  2498. +static void
  2499. +init(void)
  2500. +{
  2501. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  2502. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  2503. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  2504. + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  2505. +
  2506. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  2507. + glEnable(GL_CULL_FACE);
  2508. + glEnable(GL_LIGHTING);
  2509. + glEnable(GL_LIGHT0);
  2510. + glEnable(GL_DEPTH_TEST);
  2511. +
  2512. + /* make the gears */
  2513. + gear1 = glGenLists(1);
  2514. + glNewList(gear1, GL_COMPILE);
  2515. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  2516. + gear(1.0, 4.0, 1.0, 20, 0.7);
  2517. + glEndList();
  2518. +
  2519. + gear2 = glGenLists(1);
  2520. + glNewList(gear2, GL_COMPILE);
  2521. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  2522. + gear(0.5, 2.0, 2.0, 10, 0.7);
  2523. + glEndList();
  2524. +
  2525. + gear3 = glGenLists(1);
  2526. + glNewList(gear3, GL_COMPILE);
  2527. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  2528. + gear(1.3, 2.0, 0.5, 10, 0.7);
  2529. + glEndList();
  2530. +
  2531. + glEnable(GL_NORMALIZE);
  2532. +}
  2533. +
  2534. +
  2535. +/**
  2536. + * Remove window border/decorations.
  2537. + */
  2538. +static void
  2539. +no_border( Display *dpy, Window w)
  2540. +{
  2541. + static const unsigned MWM_HINTS_DECORATIONS = (1 << 1);
  2542. + static const int PROP_MOTIF_WM_HINTS_ELEMENTS = 5;
  2543. +
  2544. + typedef struct
  2545. + {
  2546. + unsigned long flags;
  2547. + unsigned long functions;
  2548. + unsigned long decorations;
  2549. + long inputMode;
  2550. + unsigned long status;
  2551. + } PropMotifWmHints;
  2552. +
  2553. + PropMotifWmHints motif_hints;
  2554. + Atom prop, proptype;
  2555. + unsigned long flags = 0;
  2556. +
  2557. + /* setup the property */
  2558. + motif_hints.flags = MWM_HINTS_DECORATIONS;
  2559. + motif_hints.decorations = flags;
  2560. +
  2561. + /* get the atom for the property */
  2562. + prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True );
  2563. + if (!prop) {
  2564. + /* something went wrong! */
  2565. + return;
  2566. + }
  2567. +
  2568. + /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */
  2569. + proptype = prop;
  2570. +
  2571. + XChangeProperty( dpy, w, /* display, window */
  2572. + prop, proptype, /* property, type */
  2573. + 32, /* format: 32-bit datums */
  2574. + PropModeReplace, /* mode */
  2575. + (unsigned char *) &motif_hints, /* data */
  2576. + PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */
  2577. + );
  2578. +}
  2579. +
  2580. +
  2581. +/*
  2582. + * Create an RGB, double-buffered window.
  2583. + * Return the window and context handles.
  2584. + */
  2585. +static void
  2586. +make_window( Display *dpy, const char *name,
  2587. + int x, int y, int width, int height,
  2588. + Window *winRet, GLXContext *ctxRet)
  2589. +{
  2590. + int attribs[] = { GLX_RGBA,
  2591. + GLX_RED_SIZE, 1,
  2592. + GLX_GREEN_SIZE, 1,
  2593. + GLX_BLUE_SIZE, 1,
  2594. + GLX_DOUBLEBUFFER,
  2595. + GLX_DEPTH_SIZE, 1,
  2596. + None };
  2597. + int stereoAttribs[] = { GLX_RGBA,
  2598. + GLX_RED_SIZE, 1,
  2599. + GLX_GREEN_SIZE, 1,
  2600. + GLX_BLUE_SIZE, 1,
  2601. + GLX_DOUBLEBUFFER,
  2602. + GLX_DEPTH_SIZE, 1,
  2603. + GLX_STEREO,
  2604. + None };
  2605. + int scrnum;
  2606. + XSetWindowAttributes attr;
  2607. + unsigned long mask;
  2608. + Window root;
  2609. + Window win;
  2610. + GLXContext ctx;
  2611. + XVisualInfo *visinfo;
  2612. +
  2613. + scrnum = DefaultScreen( dpy );
  2614. + root = RootWindow( dpy, scrnum );
  2615. +
  2616. + if (fullscreen) {
  2617. + x = 0; y = 0;
  2618. + width = DisplayWidth( dpy, scrnum );
  2619. + height = DisplayHeight( dpy, scrnum );
  2620. + }
  2621. +
  2622. + if (stereo)
  2623. + visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
  2624. + else
  2625. + visinfo = glXChooseVisual( dpy, scrnum, attribs );
  2626. + if (!visinfo) {
  2627. + if (stereo) {
  2628. + printf("Error: couldn't get an RGB, "
  2629. + "Double-buffered, Stereo visual\n");
  2630. + } else
  2631. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  2632. + exit(1);
  2633. + }
  2634. +
  2635. + /* window attributes */
  2636. + attr.background_pixel = 0;
  2637. + attr.border_pixel = 0;
  2638. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  2639. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  2640. + /* XXX this is a bad way to get a borderless window! */
  2641. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  2642. +
  2643. + win = XCreateWindow( dpy, root, x, y, width, height,
  2644. + 0, visinfo->depth, InputOutput,
  2645. + visinfo->visual, mask, &attr );
  2646. +
  2647. + if (fullscreen)
  2648. + no_border(dpy, win);
  2649. +
  2650. + /* set hints and properties */
  2651. + {
  2652. + XSizeHints sizehints;
  2653. + sizehints.x = x;
  2654. + sizehints.y = y;
  2655. + sizehints.width = width;
  2656. + sizehints.height = height;
  2657. + sizehints.flags = USSize | USPosition;
  2658. + XSetNormalHints(dpy, win, &sizehints);
  2659. + XSetStandardProperties(dpy, win, name, name,
  2660. + None, (char **)NULL, 0, &sizehints);
  2661. + }
  2662. +
  2663. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  2664. + if (!ctx) {
  2665. + printf("Error: glXCreateContext failed\n");
  2666. + exit(1);
  2667. + }
  2668. +
  2669. + XFree(visinfo);
  2670. +
  2671. + *winRet = win;
  2672. + *ctxRet = ctx;
  2673. +}
  2674. +
  2675. +
  2676. +/**
  2677. + * Determine whether or not a GLX extension is supported.
  2678. + */
  2679. +static int
  2680. +is_glx_extension_supported(Display *dpy, const char *query)
  2681. +{
  2682. + const int scrnum = DefaultScreen(dpy);
  2683. + const char *glx_extensions = NULL;
  2684. + const size_t len = strlen(query);
  2685. + const char *ptr;
  2686. +
  2687. + if (glx_extensions == NULL) {
  2688. + glx_extensions = glXQueryExtensionsString(dpy, scrnum);
  2689. + }
  2690. +
  2691. + ptr = strstr(glx_extensions, query);
  2692. + return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
  2693. +}
  2694. +
  2695. +
  2696. +/**
  2697. + * Attempt to determine whether or not the display is synched to vblank.
  2698. + */
  2699. +static void
  2700. +query_vsync(Display *dpy, GLXDrawable drawable)
  2701. +{
  2702. + int interval = 0;
  2703. +
  2704. +#if defined(GLX_EXT_swap_control)
  2705. + if (is_glx_extension_supported(dpy, "GLX_EXT_swap_control")) {
  2706. + unsigned int tmp = -1;
  2707. + glXQueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &tmp);
  2708. + interval = tmp;
  2709. + } else
  2710. +#endif
  2711. + if (is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) {
  2712. + PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA =
  2713. + (PFNGLXGETSWAPINTERVALMESAPROC)
  2714. + glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA");
  2715. +
  2716. + interval = (*pglXGetSwapIntervalMESA)();
  2717. + } else if (is_glx_extension_supported(dpy, "GLX_SGI_swap_control")) {
  2718. + /* The default swap interval with this extension is 1. Assume that it
  2719. + * is set to the default.
  2720. + *
  2721. + * Many Mesa-based drivers default to 0, but all of these drivers also
  2722. + * export GLX_MESA_swap_control. In that case, this branch will never
  2723. + * be taken, and the correct result should be reported.
  2724. + */
  2725. + interval = 1;
  2726. + }
  2727. +
  2728. +
  2729. + if (interval > 0) {
  2730. + printf("Running synchronized to the vertical refresh. The framerate should be\n");
  2731. + if (interval == 1) {
  2732. + printf("approximately the same as the monitor refresh rate.\n");
  2733. + } else if (interval > 1) {
  2734. + printf("approximately 1/%d the monitor refresh rate.\n",
  2735. + interval);
  2736. + }
  2737. + }
  2738. +}
  2739. +
  2740. +/**
  2741. + * Handle one X event.
  2742. + * \return NOP, EXIT or DRAW
  2743. + */
  2744. +static int
  2745. +handle_event(Display *dpy, Window win, XEvent *event)
  2746. +{
  2747. + (void) dpy;
  2748. + (void) win;
  2749. +
  2750. + switch (event->type) {
  2751. + case Expose:
  2752. + return DRAW;
  2753. + case ConfigureNotify:
  2754. + reshape(event->xconfigure.width, event->xconfigure.height);
  2755. + break;
  2756. + case KeyPress:
  2757. + {
  2758. + char buffer[10];
  2759. + int r, code;
  2760. + code = XLookupKeysym(&event->xkey, 0);
  2761. + if (code == XK_Left) {
  2762. + view_roty += 5.0;
  2763. + }
  2764. + else if (code == XK_Right) {
  2765. + view_roty -= 5.0;
  2766. + }
  2767. + else if (code == XK_Up) {
  2768. + view_rotx += 5.0;
  2769. + }
  2770. + else if (code == XK_Down) {
  2771. + view_rotx -= 5.0;
  2772. + }
  2773. + else {
  2774. + r = XLookupString(&event->xkey, buffer, sizeof(buffer),
  2775. + NULL, NULL);
  2776. + if (buffer[0] == 27) {
  2777. + /* escape */
  2778. + return EXIT;
  2779. + }
  2780. + else if (buffer[0] == 'a' || buffer[0] == 'A') {
  2781. + animate = !animate;
  2782. + }
  2783. + }
  2784. + return DRAW;
  2785. + }
  2786. + }
  2787. + return NOP;
  2788. +}
  2789. +
  2790. +
  2791. +static void
  2792. +event_loop(Display *dpy, Window win)
  2793. +{
  2794. + while (1) {
  2795. + int op;
  2796. + while (!animate || XPending(dpy) > 0) {
  2797. + XEvent event;
  2798. + XNextEvent(dpy, &event);
  2799. + op = handle_event(dpy, win, &event);
  2800. + if (op == EXIT)
  2801. + return;
  2802. + else if (op == DRAW)
  2803. + break;
  2804. + }
  2805. +
  2806. + draw_frame(dpy, win);
  2807. + }
  2808. +}
  2809. +
  2810. +
  2811. +static void
  2812. +usage(void)
  2813. +{
  2814. + printf("Usage:\n");
  2815. + printf(" -display <displayname> set the display to run on\n");
  2816. + printf(" -stereo run in stereo mode\n");
  2817. + printf(" -fullscreen run in fullscreen mode\n");
  2818. + printf(" -info display OpenGL renderer info\n");
  2819. + printf(" -geometry WxH+X+Y window geometry\n");
  2820. +}
  2821. +
  2822. +
  2823. +int
  2824. +main(int argc, char *argv[])
  2825. +{
  2826. + unsigned int winWidth = 300, winHeight = 300;
  2827. + int x = 0, y = 0;
  2828. + Display *dpy;
  2829. + Window win;
  2830. + GLXContext ctx;
  2831. + char *dpyName = NULL;
  2832. + GLboolean printInfo = GL_FALSE;
  2833. + int i;
  2834. +
  2835. + for (i = 1; i < argc; i++) {
  2836. + if (strcmp(argv[i], "-display") == 0) {
  2837. + dpyName = argv[i+1];
  2838. + i++;
  2839. + }
  2840. + else if (strcmp(argv[i], "-info") == 0) {
  2841. + printInfo = GL_TRUE;
  2842. + }
  2843. + else if (strcmp(argv[i], "-stereo") == 0) {
  2844. + stereo = GL_TRUE;
  2845. + }
  2846. + else if (strcmp(argv[i], "-fullscreen") == 0) {
  2847. + fullscreen = GL_TRUE;
  2848. + }
  2849. + else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
  2850. + XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
  2851. + i++;
  2852. + }
  2853. + else {
  2854. + usage();
  2855. + return -1;
  2856. + }
  2857. + }
  2858. +
  2859. + dpy = XOpenDisplay(dpyName);
  2860. + if (!dpy) {
  2861. + printf("Error: couldn't open display %s\n",
  2862. + dpyName ? dpyName : getenv("DISPLAY"));
  2863. + return -1;
  2864. + }
  2865. +
  2866. + make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
  2867. + XMapWindow(dpy, win);
  2868. + glXMakeCurrent(dpy, win, ctx);
  2869. + query_vsync(dpy, win);
  2870. +
  2871. + if (printInfo) {
  2872. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  2873. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  2874. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  2875. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  2876. + }
  2877. +
  2878. + init();
  2879. +
  2880. + /* Set initial projection/viewing transformation.
  2881. + * We can't be sure we'll get a ConfigureNotify event when the window
  2882. + * first appears.
  2883. + */
  2884. + reshape(winWidth, winHeight);
  2885. +
  2886. + event_loop(dpy, win);
  2887. +
  2888. + glDeleteLists(gear1, 1);
  2889. + glDeleteLists(gear2, 1);
  2890. + glDeleteLists(gear3, 1);
  2891. + glXMakeCurrent(dpy, None, NULL);
  2892. + glXDestroyContext(dpy, ctx);
  2893. + XDestroyWindow(dpy, win);
  2894. + XCloseDisplay(dpy);
  2895. +
  2896. + return 0;
  2897. +}
  2898. diff -Naurp Mesa-7.8.1/progs/xdemos/glxgears_fbconfig.c Mesa-7.8.1.patched/progs/xdemos/glxgears_fbconfig.c
  2899. --- Mesa-7.8.1/progs/xdemos/glxgears_fbconfig.c 1970-01-01 01:00:00.000000000 +0100
  2900. +++ Mesa-7.8.1.patched/progs/xdemos/glxgears_fbconfig.c 2010-06-13 13:45:06.788792936 +0200
  2901. @@ -0,0 +1,632 @@
  2902. +/*
  2903. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  2904. + *
  2905. + * Permission is hereby granted, free of charge, to any person obtaining a
  2906. + * copy of this software and associated documentation files (the "Software"),
  2907. + * to deal in the Software without restriction, including without limitation
  2908. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2909. + * and/or sell copies of the Software, and to permit persons to whom the
  2910. + * Software is furnished to do so, subject to the following conditions:
  2911. + *
  2912. + * The above copyright notice and this permission notice shall be included
  2913. + * in all copies or substantial portions of the Software.
  2914. + *
  2915. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2916. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2917. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  2918. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2919. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2920. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2921. + */
  2922. +
  2923. +/**
  2924. + * \file glxgears_fbconfig.c
  2925. + * Yet-another-version of gears. Originally ported to GLX by Brian Paul on
  2926. + * 23 March 2001. Modified to use fbconfigs by Ian Romanick on 10 Feb 2004.
  2927. + *
  2928. + * Command line options:
  2929. + * -info print GL implementation information
  2930. + *
  2931. + * \author Brian Paul
  2932. + * \author Ian Romanick <idr@us.ibm.com>
  2933. + */
  2934. +
  2935. +
  2936. +#define GLX_GLXEXT_PROTOTYPES
  2937. +
  2938. +#include <math.h>
  2939. +#include <stdlib.h>
  2940. +#include <stdio.h>
  2941. +#include <string.h>
  2942. +#include <X11/Xlib.h>
  2943. +#include <X11/keysym.h>
  2944. +#include <GL/gl.h>
  2945. +#include <GL/glx.h>
  2946. +#include <GL/glxext.h>
  2947. +#include <assert.h>
  2948. +#include "pbutil.h"
  2949. +
  2950. +static PFNGLXCHOOSEFBCONFIGPROC choose_fbconfig = NULL;
  2951. +static PFNGLXGETVISUALFROMFBCONFIGPROC get_visual_from_fbconfig = NULL;
  2952. +static PFNGLXCREATENEWCONTEXTPROC create_new_context = NULL;
  2953. +static PFNGLXCREATEWINDOWPROC create_window = NULL;
  2954. +static PFNGLXDESTROYWINDOWPROC destroy_window = NULL;
  2955. +
  2956. +#define BENCHMARK
  2957. +
  2958. +#ifdef BENCHMARK
  2959. +
  2960. +/* XXX this probably isn't very portable */
  2961. +
  2962. +#include <sys/time.h>
  2963. +#include <unistd.h>
  2964. +
  2965. +/* return current time (in seconds) */
  2966. +static int
  2967. +current_time(void)
  2968. +{
  2969. + struct timeval tv;
  2970. +#ifdef __VMS
  2971. + (void) gettimeofday(&tv, NULL );
  2972. +#else
  2973. + struct timezone tz;
  2974. + (void) gettimeofday(&tv, &tz);
  2975. +#endif
  2976. + return (int) tv.tv_sec;
  2977. +}
  2978. +
  2979. +#else /*BENCHMARK*/
  2980. +
  2981. +/* dummy */
  2982. +static int
  2983. +current_time(void)
  2984. +{
  2985. + return 0;
  2986. +}
  2987. +
  2988. +#endif /*BENCHMARK*/
  2989. +
  2990. +
  2991. +
  2992. +#ifndef M_PI
  2993. +#define M_PI 3.14159265
  2994. +#endif
  2995. +
  2996. +
  2997. +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  2998. +static GLint gear1, gear2, gear3;
  2999. +static GLfloat angle = 0.0;
  3000. +
  3001. +
  3002. +/*
  3003. + *
  3004. + * Draw a gear wheel. You'll probably want to call this function when
  3005. + * building a display list since we do a lot of trig here.
  3006. + *
  3007. + * Input: inner_radius - radius of hole at center
  3008. + * outer_radius - radius at center of teeth
  3009. + * width - width of gear
  3010. + * teeth - number of teeth
  3011. + * tooth_depth - depth of tooth
  3012. + */
  3013. +static void
  3014. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  3015. + GLint teeth, GLfloat tooth_depth)
  3016. +{
  3017. + GLint i;
  3018. + GLfloat r0, r1, r2;
  3019. + GLfloat angle, da;
  3020. + GLfloat u, v, len;
  3021. +
  3022. + r0 = inner_radius;
  3023. + r1 = outer_radius - tooth_depth / 2.0;
  3024. + r2 = outer_radius + tooth_depth / 2.0;
  3025. +
  3026. + da = 2.0 * M_PI / teeth / 4.0;
  3027. +
  3028. + glShadeModel(GL_FLAT);
  3029. +
  3030. + glNormal3f(0.0, 0.0, 1.0);
  3031. +
  3032. + /* draw front face */
  3033. + glBegin(GL_QUAD_STRIP);
  3034. + for (i = 0; i <= teeth; i++) {
  3035. + angle = i * 2.0 * M_PI / teeth;
  3036. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3037. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3038. + if (i < teeth) {
  3039. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3040. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3041. + width * 0.5);
  3042. + }
  3043. + }
  3044. + glEnd();
  3045. +
  3046. + /* draw front sides of teeth */
  3047. + glBegin(GL_QUADS);
  3048. + da = 2.0 * M_PI / teeth / 4.0;
  3049. + for (i = 0; i < teeth; i++) {
  3050. + angle = i * 2.0 * M_PI / teeth;
  3051. +
  3052. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3053. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  3054. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3055. + width * 0.5);
  3056. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3057. + width * 0.5);
  3058. + }
  3059. + glEnd();
  3060. +
  3061. + glNormal3f(0.0, 0.0, -1.0);
  3062. +
  3063. + /* draw back face */
  3064. + glBegin(GL_QUAD_STRIP);
  3065. + for (i = 0; i <= teeth; i++) {
  3066. + angle = i * 2.0 * M_PI / teeth;
  3067. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3068. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3069. + if (i < teeth) {
  3070. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3071. + -width * 0.5);
  3072. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3073. + }
  3074. + }
  3075. + glEnd();
  3076. +
  3077. + /* draw back sides of teeth */
  3078. + glBegin(GL_QUADS);
  3079. + da = 2.0 * M_PI / teeth / 4.0;
  3080. + for (i = 0; i < teeth; i++) {
  3081. + angle = i * 2.0 * M_PI / teeth;
  3082. +
  3083. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3084. + -width * 0.5);
  3085. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3086. + -width * 0.5);
  3087. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  3088. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3089. + }
  3090. + glEnd();
  3091. +
  3092. + /* draw outward faces of teeth */
  3093. + glBegin(GL_QUAD_STRIP);
  3094. + for (i = 0; i < teeth; i++) {
  3095. + angle = i * 2.0 * M_PI / teeth;
  3096. +
  3097. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3098. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3099. + u = r2 * cos(angle + da) - r1 * cos(angle);
  3100. + v = r2 * sin(angle + da) - r1 * sin(angle);
  3101. + len = sqrt(u * u + v * v);
  3102. + u /= len;
  3103. + v /= len;
  3104. + glNormal3f(v, -u, 0.0);
  3105. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  3106. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  3107. + glNormal3f(cos(angle), sin(angle), 0.0);
  3108. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3109. + width * 0.5);
  3110. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3111. + -width * 0.5);
  3112. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  3113. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  3114. + glNormal3f(v, -u, 0.0);
  3115. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3116. + width * 0.5);
  3117. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3118. + -width * 0.5);
  3119. + glNormal3f(cos(angle), sin(angle), 0.0);
  3120. + }
  3121. +
  3122. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  3123. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  3124. +
  3125. + glEnd();
  3126. +
  3127. + glShadeModel(GL_SMOOTH);
  3128. +
  3129. + /* draw inside radius cylinder */
  3130. + glBegin(GL_QUAD_STRIP);
  3131. + for (i = 0; i <= teeth; i++) {
  3132. + angle = i * 2.0 * M_PI / teeth;
  3133. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  3134. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3135. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3136. + }
  3137. + glEnd();
  3138. +}
  3139. +
  3140. +
  3141. +static void
  3142. +draw(void)
  3143. +{
  3144. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  3145. +
  3146. + glPushMatrix();
  3147. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  3148. + glRotatef(view_roty, 0.0, 1.0, 0.0);
  3149. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  3150. +
  3151. + glPushMatrix();
  3152. + glTranslatef(-3.0, -2.0, 0.0);
  3153. + glRotatef(angle, 0.0, 0.0, 1.0);
  3154. + glCallList(gear1);
  3155. + glPopMatrix();
  3156. +
  3157. + glPushMatrix();
  3158. + glTranslatef(3.1, -2.0, 0.0);
  3159. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  3160. + glCallList(gear2);
  3161. + glPopMatrix();
  3162. +
  3163. + glPushMatrix();
  3164. + glTranslatef(-3.1, 4.2, 0.0);
  3165. + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  3166. + glCallList(gear3);
  3167. + glPopMatrix();
  3168. +
  3169. + glPopMatrix();
  3170. +}
  3171. +
  3172. +
  3173. +/* new window size or exposure */
  3174. +static void
  3175. +reshape(int width, int height)
  3176. +{
  3177. + GLfloat h = (GLfloat) height / (GLfloat) width;
  3178. +
  3179. + glViewport(0, 0, (GLint) width, (GLint) height);
  3180. + glMatrixMode(GL_PROJECTION);
  3181. + glLoadIdentity();
  3182. + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  3183. + glMatrixMode(GL_MODELVIEW);
  3184. + glLoadIdentity();
  3185. + glTranslatef(0.0, 0.0, -40.0);
  3186. +}
  3187. +
  3188. +
  3189. +static void
  3190. +init(void)
  3191. +{
  3192. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  3193. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  3194. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  3195. + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  3196. +
  3197. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  3198. + glEnable(GL_CULL_FACE);
  3199. + glEnable(GL_LIGHTING);
  3200. + glEnable(GL_LIGHT0);
  3201. + glEnable(GL_DEPTH_TEST);
  3202. +
  3203. + /* make the gears */
  3204. + gear1 = glGenLists(1);
  3205. + glNewList(gear1, GL_COMPILE);
  3206. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  3207. + gear(1.0, 4.0, 1.0, 20, 0.7);
  3208. + glEndList();
  3209. +
  3210. + gear2 = glGenLists(1);
  3211. + glNewList(gear2, GL_COMPILE);
  3212. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  3213. + gear(0.5, 2.0, 2.0, 10, 0.7);
  3214. + glEndList();
  3215. +
  3216. + gear3 = glGenLists(1);
  3217. + glNewList(gear3, GL_COMPILE);
  3218. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  3219. + gear(1.3, 2.0, 0.5, 10, 0.7);
  3220. + glEndList();
  3221. +
  3222. + glEnable(GL_NORMALIZE);
  3223. +}
  3224. +
  3225. +
  3226. +static GLXWindow
  3227. +dummy_create_window(Display *dpy, GLXFBConfig config, Window win,
  3228. + const int *attrib_list)
  3229. +{
  3230. + (void) dpy;
  3231. + (void) config;
  3232. + (void) attrib_list;
  3233. +
  3234. + return (GLXWindow) win;
  3235. +}
  3236. +
  3237. +
  3238. +static void
  3239. +dummy_destroy_window(Display *dpy, GLXWindow win)
  3240. +{
  3241. + (void) dpy;
  3242. + (void) win;
  3243. +}
  3244. +
  3245. +
  3246. +/**
  3247. + * Initialize fbconfig related function pointers.
  3248. + */
  3249. +static void
  3250. +init_fbconfig_functions(Display *dpy, int scrnum)
  3251. +{
  3252. + const char * glx_extensions;
  3253. + const char * match;
  3254. + static const char ext_name[] = "GLX_SGIX_fbconfig";
  3255. + const size_t len = strlen( ext_name );
  3256. + int major;
  3257. + int minor;
  3258. + GLboolean ext_version_supported;
  3259. + GLboolean glx_1_3_supported;
  3260. +
  3261. +
  3262. + /* Determine if GLX 1.3 or greater is supported.
  3263. + */
  3264. + glXQueryVersion(dpy, & major, & minor);
  3265. + glx_1_3_supported = (major == 1) && (minor >= 3);
  3266. +
  3267. + /* Determine if GLX_SGIX_fbconfig is supported.
  3268. + */
  3269. + glx_extensions = glXQueryExtensionsString(dpy, scrnum);
  3270. + match = strstr( glx_extensions, ext_name );
  3271. +
  3272. + ext_version_supported = (match != NULL)
  3273. + && ((match[len] == '\0') || (match[len] == ' '));
  3274. +
  3275. + printf( "GLX 1.3 is %ssupported.\n",
  3276. + (glx_1_3_supported) ? "" : "not " );
  3277. + printf( "%s is %ssupported.\n",
  3278. + ext_name, (ext_version_supported) ? "" : "not " );
  3279. +
  3280. + if ( glx_1_3_supported ) {
  3281. + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC)
  3282. + glXGetProcAddressARB((GLubyte *) "glXChooseFBConfig");
  3283. + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)
  3284. + glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfig");
  3285. + create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
  3286. + glXGetProcAddressARB((GLubyte *) "glXCreateNewContext");
  3287. + create_window = (PFNGLXCREATEWINDOWPROC)
  3288. + glXGetProcAddressARB((GLubyte *) "glXCreateWindow");
  3289. + destroy_window = (PFNGLXDESTROYWINDOWPROC)
  3290. + glXGetProcAddressARB((GLubyte *) "glXDestroyWindow");
  3291. + }
  3292. + else if ( ext_version_supported ) {
  3293. + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC)
  3294. + glXGetProcAddressARB((GLubyte *) "glXChooseFBConfigSGIX");
  3295. + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)
  3296. + glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfigSGIX");
  3297. + create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
  3298. + glXGetProcAddressARB((GLubyte *) "glXCreateContextWithConfigSGIX");
  3299. + create_window = dummy_create_window;
  3300. + destroy_window = dummy_destroy_window;
  3301. + }
  3302. + else {
  3303. + printf( "This demo requires either GLX 1.3 or %s be supported.\n",
  3304. + ext_name );
  3305. + exit(1);
  3306. + }
  3307. +
  3308. + if ( choose_fbconfig == NULL ) {
  3309. + printf( "glXChooseFBConfig not found!\n" );
  3310. + exit(1);
  3311. + }
  3312. +
  3313. + if ( get_visual_from_fbconfig == NULL ) {
  3314. + printf( "glXGetVisualFromFBConfig not found!\n" );
  3315. + exit(1);
  3316. + }
  3317. +
  3318. + if ( create_new_context == NULL ) {
  3319. + printf( "glXCreateNewContext not found!\n" );
  3320. + exit(1);
  3321. + }
  3322. +}
  3323. +
  3324. +
  3325. +/*
  3326. + * Create an RGB, double-buffered window.
  3327. + * Return the window and context handles.
  3328. + */
  3329. +static void
  3330. +make_window( Display *dpy, const char *name,
  3331. + int x, int y, int width, int height,
  3332. + Window *winRet, GLXWindow *glxWinRet, GLXContext *ctxRet)
  3333. +{
  3334. + int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
  3335. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  3336. + GLX_RED_SIZE, 1,
  3337. + GLX_GREEN_SIZE, 1,
  3338. + GLX_BLUE_SIZE, 1,
  3339. + GLX_DOUBLEBUFFER, GL_TRUE,
  3340. + GLX_DEPTH_SIZE, 1,
  3341. + None };
  3342. + GLXFBConfig * fbconfig;
  3343. + int num_configs;
  3344. + int scrnum;
  3345. + int i;
  3346. + XSetWindowAttributes attr;
  3347. + unsigned long mask;
  3348. + Window root;
  3349. + Window win;
  3350. + GLXWindow glxWin;
  3351. + GLXContext ctx;
  3352. + XVisualInfo *visinfo;
  3353. +
  3354. + scrnum = DefaultScreen( dpy );
  3355. + root = RootWindow( dpy, scrnum );
  3356. +
  3357. + init_fbconfig_functions(dpy, scrnum);
  3358. + fbconfig = (*choose_fbconfig)(dpy, scrnum, attrib, & num_configs);
  3359. + if (fbconfig == NULL) {
  3360. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  3361. + exit(1);
  3362. + }
  3363. +
  3364. + printf("\nThe following fbconfigs meet the requirements. The first one "
  3365. + "will be used.\n\n");
  3366. + for ( i = 0 ; i < num_configs ; i++ ) {
  3367. + PrintFBConfigInfo(dpy, scrnum, fbconfig[i], GL_TRUE);
  3368. + }
  3369. +
  3370. + /* window attributes */
  3371. + visinfo = (*get_visual_from_fbconfig)(dpy, fbconfig[0]);
  3372. + assert(visinfo != NULL);
  3373. + attr.background_pixel = 0;
  3374. + attr.border_pixel = 0;
  3375. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  3376. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  3377. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  3378. +
  3379. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  3380. + 0, visinfo->depth, InputOutput,
  3381. + visinfo->visual, mask, &attr );
  3382. +
  3383. + /* set hints and properties */
  3384. + {
  3385. + XSizeHints sizehints;
  3386. + sizehints.x = x;
  3387. + sizehints.y = y;
  3388. + sizehints.width = width;
  3389. + sizehints.height = height;
  3390. + sizehints.flags = USSize | USPosition;
  3391. + XSetNormalHints(dpy, win, &sizehints);
  3392. + XSetStandardProperties(dpy, win, name, name,
  3393. + None, (char **)NULL, 0, &sizehints);
  3394. + }
  3395. +
  3396. + glxWin = (*create_window)(dpy, fbconfig[0], win, NULL);
  3397. +
  3398. + ctx = (*create_new_context)(dpy, fbconfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
  3399. + if (!ctx) {
  3400. + printf("Error: glXCreateNewContext failed\n");
  3401. + exit(1);
  3402. + }
  3403. +
  3404. + XFree(fbconfig);
  3405. +
  3406. + *glxWinRet = glxWin;
  3407. + *winRet = win;
  3408. + *ctxRet = ctx;
  3409. +}
  3410. +
  3411. +
  3412. +static void
  3413. +event_loop(Display *dpy, GLXWindow win)
  3414. +{
  3415. + while (1) {
  3416. + while (XPending(dpy) > 0) {
  3417. + XEvent event;
  3418. + XNextEvent(dpy, &event);
  3419. + switch (event.type) {
  3420. + case Expose:
  3421. + /* we'll redraw below */
  3422. + break;
  3423. + case ConfigureNotify:
  3424. + reshape(event.xconfigure.width, event.xconfigure.height);
  3425. + break;
  3426. + case KeyPress:
  3427. + {
  3428. + char buffer[10];
  3429. + int r, code;
  3430. + code = XLookupKeysym(&event.xkey, 0);
  3431. + if (code == XK_Left) {
  3432. + view_roty += 5.0;
  3433. + }
  3434. + else if (code == XK_Right) {
  3435. + view_roty -= 5.0;
  3436. + }
  3437. + else if (code == XK_Up) {
  3438. + view_rotx += 5.0;
  3439. + }
  3440. + else if (code == XK_Down) {
  3441. + view_rotx -= 5.0;
  3442. + }
  3443. + else {
  3444. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  3445. + NULL, NULL);
  3446. + if (buffer[0] == 27) {
  3447. + /* escape */
  3448. + return;
  3449. + }
  3450. + }
  3451. + }
  3452. + }
  3453. + }
  3454. +
  3455. + /* next frame */
  3456. + angle += 2.0;
  3457. +
  3458. + draw();
  3459. + glXSwapBuffers(dpy, win);
  3460. +
  3461. + /* calc framerate */
  3462. + {
  3463. + static int t0 = -1;
  3464. + static int frames = 0;
  3465. + int t = current_time();
  3466. +
  3467. + if (t0 < 0)
  3468. + t0 = t;
  3469. +
  3470. + frames++;
  3471. +
  3472. + if (t - t0 >= 5.0) {
  3473. + GLfloat seconds = t - t0;
  3474. + GLfloat fps = frames / seconds;
  3475. + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
  3476. + fps);
  3477. + t0 = t;
  3478. + frames = 0;
  3479. + }
  3480. + }
  3481. + }
  3482. +}
  3483. +
  3484. +
  3485. +int
  3486. +main(int argc, char *argv[])
  3487. +{
  3488. + Display *dpy;
  3489. + Window win;
  3490. + GLXWindow glxWin;
  3491. + GLXContext ctx;
  3492. + const char *dpyName = NULL;
  3493. + GLboolean printInfo = GL_FALSE;
  3494. + int i;
  3495. +
  3496. + for (i = 1; i < argc; i++) {
  3497. + if (strcmp(argv[i], "-display") == 0) {
  3498. + dpyName = argv[i+1];
  3499. + i++;
  3500. + }
  3501. + else if (strcmp(argv[i], "-info") == 0) {
  3502. + printInfo = GL_TRUE;
  3503. + }
  3504. + }
  3505. +
  3506. + dpy = XOpenDisplay(dpyName);
  3507. + if (!dpy) {
  3508. + printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
  3509. + return -1;
  3510. + }
  3511. +
  3512. + make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &glxWin, &ctx);
  3513. + XMapWindow(dpy, win);
  3514. + glXMakeCurrent(dpy, glxWin, ctx);
  3515. +
  3516. + if (printInfo) {
  3517. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  3518. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  3519. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  3520. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  3521. + }
  3522. +
  3523. + init();
  3524. +
  3525. + event_loop(dpy, glxWin);
  3526. +
  3527. + glXDestroyContext(dpy, ctx);
  3528. + destroy_window(dpy, glxWin);
  3529. + XDestroyWindow(dpy, win);
  3530. + XCloseDisplay(dpy);
  3531. +
  3532. + return 0;
  3533. +}
  3534. diff -Naurp Mesa-7.8.1/progs/xdemos/glxgears_pixmap.c Mesa-7.8.1.patched/progs/xdemos/glxgears_pixmap.c
  3535. --- Mesa-7.8.1/progs/xdemos/glxgears_pixmap.c 1970-01-01 01:00:00.000000000 +0100
  3536. +++ Mesa-7.8.1.patched/progs/xdemos/glxgears_pixmap.c 2010-06-13 13:45:06.789793146 +0200
  3537. @@ -0,0 +1,547 @@
  3538. +/*
  3539. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  3540. + * Copyright (C) 2008 Red Hat, Inc All Rights Reserved.
  3541. + *
  3542. + * Permission is hereby granted, free of charge, to any person obtaining a
  3543. + * copy of this software and associated documentation files (the "Software"),
  3544. + * to deal in the Software without restriction, including without limitation
  3545. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  3546. + * and/or sell copies of the Software, and to permit persons to whom the
  3547. + * Software is furnished to do so, subject to the following conditions:
  3548. + *
  3549. + * The above copyright notice and this permission notice shall be included
  3550. + * in all copies or substantial portions of the Software.
  3551. + *
  3552. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3553. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3554. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  3555. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  3556. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3557. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  3558. + */
  3559. +
  3560. +/**
  3561. + * \file glxgears_pixmap.c
  3562. + * Yet-another-version of gears. Originally ported to GLX by Brian Paul on
  3563. + * 23 March 2001. Modified to use fbconfigs by Ian Romanick on 10 Feb 2004.
  3564. + *
  3565. + * Command line options:
  3566. + * -info print GL implementation information
  3567. + *
  3568. + * \author Brian Paul
  3569. + * \author Ian Romanick <idr@us.ibm.com>
  3570. + * \author Kristian Hoegsberg <krh@redhat.com>
  3571. + */
  3572. +
  3573. +
  3574. +#define GLX_GLXEXT_PROTOTYPES
  3575. +
  3576. +#include <math.h>
  3577. +#include <stdlib.h>
  3578. +#include <stdio.h>
  3579. +#include <string.h>
  3580. +#include <X11/Xlib.h>
  3581. +#include <X11/keysym.h>
  3582. +#include <GL/gl.h>
  3583. +#include <GL/glx.h>
  3584. +#include <GL/glxext.h>
  3585. +#include <assert.h>
  3586. +#include "pbutil.h"
  3587. +
  3588. +#define BENCHMARK
  3589. +
  3590. +#ifdef BENCHMARK
  3591. +
  3592. +/* XXX this probably isn't very portable */
  3593. +
  3594. +#include <sys/time.h>
  3595. +#include <unistd.h>
  3596. +
  3597. +/* return current time (in seconds) */
  3598. +static int
  3599. +current_time(void)
  3600. +{
  3601. + struct timeval tv;
  3602. +#ifdef __VMS
  3603. + (void) gettimeofday(&tv, NULL );
  3604. +#else
  3605. + struct timezone tz;
  3606. + (void) gettimeofday(&tv, &tz);
  3607. +#endif
  3608. + return (int) tv.tv_sec;
  3609. +}
  3610. +
  3611. +#else /*BENCHMARK*/
  3612. +
  3613. +/* dummy */
  3614. +static int
  3615. +current_time(void)
  3616. +{
  3617. + return 0;
  3618. +}
  3619. +
  3620. +#endif /*BENCHMARK*/
  3621. +
  3622. +
  3623. +
  3624. +#ifndef M_PI
  3625. +#define M_PI 3.14159265
  3626. +#endif
  3627. +
  3628. +
  3629. +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  3630. +static GLint gear1, gear2, gear3;
  3631. +static GLfloat angle = 0.0;
  3632. +
  3633. +
  3634. +/*
  3635. + *
  3636. + * Draw a gear wheel. You'll probably want to call this function when
  3637. + * building a display list since we do a lot of trig here.
  3638. + *
  3639. + * Input: inner_radius - radius of hole at center
  3640. + * outer_radius - radius at center of teeth
  3641. + * width - width of gear
  3642. + * teeth - number of teeth
  3643. + * tooth_depth - depth of tooth
  3644. + */
  3645. +static void
  3646. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  3647. + GLint teeth, GLfloat tooth_depth)
  3648. +{
  3649. + GLint i;
  3650. + GLfloat r0, r1, r2;
  3651. + GLfloat angle, da;
  3652. + GLfloat u, v, len;
  3653. +
  3654. + r0 = inner_radius;
  3655. + r1 = outer_radius - tooth_depth / 2.0;
  3656. + r2 = outer_radius + tooth_depth / 2.0;
  3657. +
  3658. + da = 2.0 * M_PI / teeth / 4.0;
  3659. +
  3660. + glShadeModel(GL_FLAT);
  3661. +
  3662. + glNormal3f(0.0, 0.0, 1.0);
  3663. +
  3664. + /* draw front face */
  3665. + glBegin(GL_QUAD_STRIP);
  3666. + for (i = 0; i <= teeth; i++) {
  3667. + angle = i * 2.0 * M_PI / teeth;
  3668. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3669. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3670. + if (i < teeth) {
  3671. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3672. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3673. + width * 0.5);
  3674. + }
  3675. + }
  3676. + glEnd();
  3677. +
  3678. + /* draw front sides of teeth */
  3679. + glBegin(GL_QUADS);
  3680. + da = 2.0 * M_PI / teeth / 4.0;
  3681. + for (i = 0; i < teeth; i++) {
  3682. + angle = i * 2.0 * M_PI / teeth;
  3683. +
  3684. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3685. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  3686. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3687. + width * 0.5);
  3688. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3689. + width * 0.5);
  3690. + }
  3691. + glEnd();
  3692. +
  3693. + glNormal3f(0.0, 0.0, -1.0);
  3694. +
  3695. + /* draw back face */
  3696. + glBegin(GL_QUAD_STRIP);
  3697. + for (i = 0; i <= teeth; i++) {
  3698. + angle = i * 2.0 * M_PI / teeth;
  3699. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3700. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3701. + if (i < teeth) {
  3702. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3703. + -width * 0.5);
  3704. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3705. + }
  3706. + }
  3707. + glEnd();
  3708. +
  3709. + /* draw back sides of teeth */
  3710. + glBegin(GL_QUADS);
  3711. + da = 2.0 * M_PI / teeth / 4.0;
  3712. + for (i = 0; i < teeth; i++) {
  3713. + angle = i * 2.0 * M_PI / teeth;
  3714. +
  3715. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3716. + -width * 0.5);
  3717. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3718. + -width * 0.5);
  3719. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  3720. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3721. + }
  3722. + glEnd();
  3723. +
  3724. + /* draw outward faces of teeth */
  3725. + glBegin(GL_QUAD_STRIP);
  3726. + for (i = 0; i < teeth; i++) {
  3727. + angle = i * 2.0 * M_PI / teeth;
  3728. +
  3729. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  3730. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  3731. + u = r2 * cos(angle + da) - r1 * cos(angle);
  3732. + v = r2 * sin(angle + da) - r1 * sin(angle);
  3733. + len = sqrt(u * u + v * v);
  3734. + u /= len;
  3735. + v /= len;
  3736. + glNormal3f(v, -u, 0.0);
  3737. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  3738. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  3739. + glNormal3f(cos(angle), sin(angle), 0.0);
  3740. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3741. + width * 0.5);
  3742. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  3743. + -width * 0.5);
  3744. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  3745. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  3746. + glNormal3f(v, -u, 0.0);
  3747. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3748. + width * 0.5);
  3749. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  3750. + -width * 0.5);
  3751. + glNormal3f(cos(angle), sin(angle), 0.0);
  3752. + }
  3753. +
  3754. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  3755. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  3756. +
  3757. + glEnd();
  3758. +
  3759. + glShadeModel(GL_SMOOTH);
  3760. +
  3761. + /* draw inside radius cylinder */
  3762. + glBegin(GL_QUAD_STRIP);
  3763. + for (i = 0; i <= teeth; i++) {
  3764. + angle = i * 2.0 * M_PI / teeth;
  3765. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  3766. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  3767. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  3768. + }
  3769. + glEnd();
  3770. +}
  3771. +
  3772. +
  3773. +static void
  3774. +draw(void)
  3775. +{
  3776. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  3777. +
  3778. + glPushMatrix();
  3779. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  3780. + glRotatef(view_roty, 0.0, 1.0, 0.0);
  3781. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  3782. +
  3783. + glPushMatrix();
  3784. + glTranslatef(-3.0, -2.0, 0.0);
  3785. + glRotatef(angle, 0.0, 0.0, 1.0);
  3786. + glCallList(gear1);
  3787. + glPopMatrix();
  3788. +
  3789. + glPushMatrix();
  3790. + glTranslatef(3.1, -2.0, 0.0);
  3791. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  3792. + glCallList(gear2);
  3793. + glPopMatrix();
  3794. +
  3795. + glPushMatrix();
  3796. + glTranslatef(-3.1, 4.2, 0.0);
  3797. + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  3798. + glCallList(gear3);
  3799. + glPopMatrix();
  3800. +
  3801. + glPopMatrix();
  3802. +}
  3803. +
  3804. +
  3805. +struct gears {
  3806. + Window win;
  3807. + GLXContext ctx;
  3808. + Pixmap pixmap;
  3809. + GLXPixmap glxpixmap;
  3810. + GC gc;
  3811. + int width, height;
  3812. +};
  3813. +
  3814. +
  3815. +/* new window size or exposure */
  3816. +static void
  3817. +reshape(struct gears *gears, int width, int height)
  3818. +{
  3819. + gears->width = width;
  3820. + gears->height = height;
  3821. +}
  3822. +
  3823. +
  3824. +static void
  3825. +init(int width, int height)
  3826. +{
  3827. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  3828. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  3829. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  3830. + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  3831. + GLfloat h = (GLfloat) height / (GLfloat) width;
  3832. +
  3833. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  3834. + glEnable(GL_CULL_FACE);
  3835. + glEnable(GL_LIGHTING);
  3836. + glEnable(GL_LIGHT0);
  3837. + glEnable(GL_DEPTH_TEST);
  3838. +
  3839. + /* make the gears */
  3840. + gear1 = glGenLists(1);
  3841. + glNewList(gear1, GL_COMPILE);
  3842. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  3843. + gear(1.0, 4.0, 1.0, 20, 0.7);
  3844. + glEndList();
  3845. +
  3846. + gear2 = glGenLists(1);
  3847. + glNewList(gear2, GL_COMPILE);
  3848. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  3849. + gear(0.5, 2.0, 2.0, 10, 0.7);
  3850. + glEndList();
  3851. +
  3852. + gear3 = glGenLists(1);
  3853. + glNewList(gear3, GL_COMPILE);
  3854. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  3855. + gear(1.3, 2.0, 0.5, 10, 0.7);
  3856. + glEndList();
  3857. +
  3858. + glEnable(GL_NORMALIZE);
  3859. +
  3860. + glViewport(0, 0, (GLint) width, (GLint) height);
  3861. + glMatrixMode(GL_PROJECTION);
  3862. + glLoadIdentity();
  3863. + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  3864. + glMatrixMode(GL_MODELVIEW);
  3865. + glLoadIdentity();
  3866. + glTranslatef(0.0, 0.0, -40.0);
  3867. +}
  3868. +
  3869. +/*
  3870. + * Create an RGB, double-buffered window.
  3871. + * Return the window and context handles.
  3872. + */
  3873. +static void
  3874. +make_window( Display *dpy, const char *name,
  3875. + int x, int y, int width, int height, struct gears *gears)
  3876. +{
  3877. + int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
  3878. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  3879. + GLX_RED_SIZE, 1,
  3880. + GLX_GREEN_SIZE, 1,
  3881. + GLX_BLUE_SIZE, 1,
  3882. + GLX_DOUBLEBUFFER, GL_FALSE,
  3883. + GLX_DEPTH_SIZE, 1,
  3884. + None };
  3885. + GLXFBConfig * fbconfig;
  3886. + int num_configs;
  3887. + int scrnum;
  3888. + XSetWindowAttributes attr;
  3889. + unsigned long mask;
  3890. + Window root;
  3891. + XVisualInfo *visinfo;
  3892. +
  3893. + gears->width = width;
  3894. + gears->height = height;
  3895. +
  3896. + scrnum = DefaultScreen( dpy );
  3897. + root = RootWindow( dpy, scrnum );
  3898. +
  3899. + fbconfig = glXChooseFBConfig(dpy, scrnum, attrib, & num_configs);
  3900. + if (fbconfig == NULL) {
  3901. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  3902. + exit(1);
  3903. + }
  3904. +
  3905. + /* window attributes */
  3906. + visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[0]);
  3907. + assert(visinfo != NULL);
  3908. + attr.background_pixel = 0;
  3909. + attr.border_pixel = 0;
  3910. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  3911. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  3912. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  3913. +
  3914. + gears->win = XCreateWindow( dpy, root, 0, 0, width, height,
  3915. + 0, visinfo->depth, InputOutput,
  3916. + visinfo->visual, mask, &attr );
  3917. +
  3918. + /* set hints and properties */
  3919. + {
  3920. + XSizeHints sizehints;
  3921. + sizehints.x = x;
  3922. + sizehints.y = y;
  3923. + sizehints.width = width;
  3924. + sizehints.height = height;
  3925. + sizehints.flags = USSize | USPosition;
  3926. + XSetNormalHints(dpy, gears->win, &sizehints);
  3927. + XSetStandardProperties(dpy, gears->win, name, name,
  3928. + None, (char **)NULL, 0, &sizehints);
  3929. + }
  3930. +
  3931. + gears->gc = XCreateGC(dpy, gears->win, 0, NULL);
  3932. +
  3933. + gears->pixmap = XCreatePixmap(dpy, gears->win,
  3934. + width, height, visinfo->depth);
  3935. + if (!gears->pixmap) {
  3936. + printf("Error: XCreatePixmap failed\n");
  3937. + exit(-1);
  3938. + }
  3939. +
  3940. + gears->glxpixmap = glXCreatePixmap(dpy, fbconfig[0], gears->pixmap, NULL);
  3941. + if (!gears->glxpixmap) {
  3942. + printf("Error: glXCreatePixmap failed\n");
  3943. + exit(-1);
  3944. + }
  3945. +
  3946. + gears->ctx = glXCreateNewContext(dpy, fbconfig[0],
  3947. + GLX_RGBA_TYPE, NULL, GL_TRUE);
  3948. + if (!gears->ctx) {
  3949. + printf("Error: glXCreateNewContext failed\n");
  3950. + exit(1);
  3951. + }
  3952. +
  3953. + XFree(fbconfig);
  3954. +}
  3955. +
  3956. +
  3957. +static void
  3958. +event_loop(Display *dpy, struct gears *gears)
  3959. +{
  3960. + int x, y;
  3961. +
  3962. + while (1) {
  3963. + while (XPending(dpy) > 0) {
  3964. + XEvent event;
  3965. + XNextEvent(dpy, &event);
  3966. + switch (event.type) {
  3967. + case Expose:
  3968. + /* we'll redraw below */
  3969. + break;
  3970. + case ConfigureNotify:
  3971. + reshape(gears, event.xconfigure.width, event.xconfigure.height);
  3972. + break;
  3973. + case KeyPress:
  3974. + {
  3975. + char buffer[10];
  3976. + int r, code;
  3977. + code = XLookupKeysym(&event.xkey, 0);
  3978. + if (code == XK_Left) {
  3979. + view_roty += 5.0;
  3980. + }
  3981. + else if (code == XK_Right) {
  3982. + view_roty -= 5.0;
  3983. + }
  3984. + else if (code == XK_Up) {
  3985. + view_rotx += 5.0;
  3986. + }
  3987. + else if (code == XK_Down) {
  3988. + view_rotx -= 5.0;
  3989. + }
  3990. + else {
  3991. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  3992. + NULL, NULL);
  3993. + if (buffer[0] == 27) {
  3994. + /* escape */
  3995. + return;
  3996. + }
  3997. + }
  3998. + }
  3999. + }
  4000. + }
  4001. +
  4002. + /* next frame */
  4003. + angle += 2.0;
  4004. +
  4005. + draw();
  4006. + glFinish();
  4007. +
  4008. + for (x = 0; x < gears->width; x += 100)
  4009. + for (y = 0; y < gears->width; y += 100)
  4010. + XCopyArea(dpy, gears->pixmap, gears->win, gears->gc,
  4011. + 50, 50, 100, 100, x, y);
  4012. +
  4013. + /* calc framerate */
  4014. + {
  4015. + static int t0 = -1;
  4016. + static int frames = 0;
  4017. + int t = current_time();
  4018. +
  4019. + if (t0 < 0)
  4020. + t0 = t;
  4021. +
  4022. + frames++;
  4023. +
  4024. + if (t - t0 >= 5.0) {
  4025. + GLfloat seconds = t - t0;
  4026. + GLfloat fps = frames / seconds;
  4027. + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
  4028. + fps);
  4029. + t0 = t;
  4030. + frames = 0;
  4031. + }
  4032. + }
  4033. + }
  4034. +}
  4035. +
  4036. +
  4037. +int
  4038. +main(int argc, char *argv[])
  4039. +{
  4040. + Display *dpy;
  4041. + const char *dpyName = NULL;
  4042. + GLboolean printInfo = GL_FALSE;
  4043. + struct gears gears;
  4044. + int i, width = 200, height = 200;
  4045. +
  4046. + for (i = 1; i < argc; i++) {
  4047. + if (strcmp(argv[i], "-display") == 0) {
  4048. + dpyName = argv[i+1];
  4049. + i++;
  4050. + }
  4051. + else if (strcmp(argv[i], "-info") == 0) {
  4052. + printInfo = GL_TRUE;
  4053. + }
  4054. + }
  4055. +
  4056. + dpy = XOpenDisplay(dpyName);
  4057. + if (!dpy) {
  4058. + printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
  4059. + return -1;
  4060. + }
  4061. +
  4062. + make_window(dpy, "glxgears", 0, 0, width, height, &gears);
  4063. + XMapWindow(dpy, gears.win);
  4064. + glXMakeCurrent(dpy, gears.glxpixmap, gears.ctx);
  4065. +
  4066. + if (printInfo) {
  4067. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  4068. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  4069. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  4070. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  4071. + }
  4072. +
  4073. + init(width, height);
  4074. +
  4075. + event_loop(dpy, &gears);
  4076. +
  4077. + glXDestroyContext(dpy, gears.ctx);
  4078. + XDestroyWindow(dpy, gears.win);
  4079. + glXDestroyPixmap(dpy, gears.pixmap);
  4080. + XFreePixmap(dpy, gears.pixmap);
  4081. + XCloseDisplay(dpy);
  4082. +
  4083. + return 0;
  4084. +}
  4085. diff -Naurp Mesa-7.8.1/progs/xdemos/glxheads.c Mesa-7.8.1.patched/progs/xdemos/glxheads.c
  4086. --- Mesa-7.8.1/progs/xdemos/glxheads.c 1970-01-01 01:00:00.000000000 +0100
  4087. +++ Mesa-7.8.1.patched/progs/xdemos/glxheads.c 2010-06-13 13:45:06.789793146 +0200
  4088. @@ -0,0 +1,313 @@
  4089. +
  4090. +/*
  4091. + * Exercise multiple GLX connections on multiple X displays.
  4092. + * Direct GLX contexts are attempted first, then indirect.
  4093. + * Each window will display a spinning green triangle.
  4094. + *
  4095. + * Copyright (C) 2000 Brian Paul All Rights Reserved.
  4096. + *
  4097. + * Permission is hereby granted, free of charge, to any person obtaining a
  4098. + * copy of this software and associated documentation files (the "Software"),
  4099. + * to deal in the Software without restriction, including without limitation
  4100. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  4101. + * and/or sell copies of the Software, and to permit persons to whom the
  4102. + * Software is furnished to do so, subject to the following conditions:
  4103. + *
  4104. + * The above copyright notice and this permission notice shall be included
  4105. + * in all copies or substantial portions of the Software.
  4106. + *
  4107. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4108. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4109. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  4110. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  4111. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4112. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4113. + */
  4114. +
  4115. +
  4116. +#include <GL/gl.h>
  4117. +#include <GL/glx.h>
  4118. +#include <stdio.h>
  4119. +#include <stdlib.h>
  4120. +#include <string.h>
  4121. +#include <unistd.h>
  4122. +
  4123. +
  4124. +
  4125. +/*
  4126. + * Each display/window/context:
  4127. + */
  4128. +struct head {
  4129. + char DisplayName[1000];
  4130. + Display *Dpy;
  4131. + Window Win;
  4132. + GLXContext Context;
  4133. + float Angle;
  4134. + char Renderer[1000];
  4135. + char Vendor[1000];
  4136. + char Version[1000];
  4137. +};
  4138. +
  4139. +
  4140. +#define MAX_HEADS 20
  4141. +static struct head Heads[MAX_HEADS];
  4142. +static int NumHeads = 0;
  4143. +
  4144. +
  4145. +static void
  4146. +Error(const char *display, const char *msg)
  4147. +{
  4148. + fprintf(stderr, "Error on display %s - %s\n", XDisplayName(display), msg);
  4149. + exit(1);
  4150. +}
  4151. +
  4152. +
  4153. +static struct head *
  4154. +AddHead(const char *displayName)
  4155. +{
  4156. + Display *dpy;
  4157. + Window win;
  4158. + GLXContext ctx;
  4159. + int attrib[] = { GLX_RGBA,
  4160. + GLX_RED_SIZE, 1,
  4161. + GLX_GREEN_SIZE, 1,
  4162. + GLX_BLUE_SIZE, 1,
  4163. + GLX_DOUBLEBUFFER,
  4164. + None };
  4165. + int scrnum;
  4166. + XSetWindowAttributes attr;
  4167. + unsigned long mask;
  4168. + Window root;
  4169. + XVisualInfo *visinfo;
  4170. + int width = 300, height = 300;
  4171. + int xpos = 10, ypos = 10;
  4172. +
  4173. + if (NumHeads >= MAX_HEADS)
  4174. + return NULL;
  4175. +
  4176. + dpy = XOpenDisplay(displayName);
  4177. + if (!dpy) {
  4178. + Error(displayName, "Unable to open display");
  4179. + return NULL;
  4180. + }
  4181. +
  4182. + scrnum = DefaultScreen(dpy);
  4183. + root = RootWindow(dpy, scrnum);
  4184. +
  4185. + visinfo = glXChooseVisual(dpy, scrnum, attrib);
  4186. + if (!visinfo) {
  4187. + Error(displayName, "Unable to find RGB, double-buffered visual");
  4188. + return NULL;
  4189. + }
  4190. +
  4191. + /* window attributes */
  4192. + attr.background_pixel = 0;
  4193. + attr.border_pixel = 0;
  4194. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  4195. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  4196. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  4197. +
  4198. + win = XCreateWindow(dpy, root, 0, 0, width, height,
  4199. + 0, visinfo->depth, InputOutput,
  4200. + visinfo->visual, mask, &attr);
  4201. + if (!win) {
  4202. + Error(displayName, "Couldn't create window");
  4203. + return NULL;
  4204. + }
  4205. +
  4206. + {
  4207. + XSizeHints sizehints;
  4208. + sizehints.x = xpos;
  4209. + sizehints.y = ypos;
  4210. + sizehints.width = width;
  4211. + sizehints.height = height;
  4212. + sizehints.flags = USSize | USPosition;
  4213. + XSetNormalHints(dpy, win, &sizehints);
  4214. + XSetStandardProperties(dpy, win, displayName, displayName,
  4215. + None, (char **)NULL, 0, &sizehints);
  4216. + }
  4217. +
  4218. +
  4219. + ctx = glXCreateContext(dpy, visinfo, NULL, True);
  4220. + if (!ctx) {
  4221. + Error(displayName, "Couldn't create GLX context");
  4222. + return NULL;
  4223. + }
  4224. +
  4225. + XMapWindow(dpy, win);
  4226. +
  4227. + if (!glXMakeCurrent(dpy, win, ctx)) {
  4228. + Error(displayName, "glXMakeCurrent failed");
  4229. + printf("glXMakeCurrent failed in Redraw()\n");
  4230. + return NULL;
  4231. + }
  4232. +
  4233. + /* save the info for this head */
  4234. + {
  4235. + struct head *h = &Heads[NumHeads];
  4236. + const char * tmp;
  4237. +
  4238. + if (strlen(displayName) + 1 > sizeof(h->DisplayName)) {
  4239. + Error(displayName, "displayName string length overflow");
  4240. + return NULL;
  4241. + }
  4242. + strcpy(h->DisplayName, displayName);
  4243. +
  4244. + h->Dpy = dpy;
  4245. + h->Win = win;
  4246. + h->Context = ctx;
  4247. + h->Angle = 0.0;
  4248. +
  4249. + tmp = (char *) glGetString(GL_VERSION);
  4250. + if (strlen(tmp) + 1 > sizeof(h->Version)) {
  4251. + Error(displayName, "GL_VERSION string length overflow");
  4252. + return NULL;
  4253. + }
  4254. + strcpy(h->Version, tmp);
  4255. +
  4256. + tmp = (char *) glGetString(GL_VENDOR);
  4257. + if (strlen(tmp) + 1 > sizeof(h->Vendor)) {
  4258. + Error(displayName, "GL_VENDOR string length overflow");
  4259. + return NULL;
  4260. + }
  4261. + strcpy(h->Vendor, tmp);
  4262. +
  4263. + tmp = (char *) glGetString(GL_RENDERER);
  4264. + if (strlen(tmp) + 1 > sizeof(h->Renderer)) {
  4265. + Error(displayName, "GL_RENDERER string length overflow");
  4266. + return NULL;
  4267. + }
  4268. + strcpy(h->Renderer, tmp);
  4269. +
  4270. + NumHeads++;
  4271. + return &Heads[NumHeads-1];
  4272. + }
  4273. +
  4274. +}
  4275. +
  4276. +
  4277. +static void
  4278. +Redraw(struct head *h)
  4279. +{
  4280. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  4281. + Error(h->DisplayName, "glXMakeCurrent failed");
  4282. + printf("glXMakeCurrent failed in Redraw()\n");
  4283. + return;
  4284. + }
  4285. +
  4286. + h->Angle += 1.0;
  4287. +
  4288. + glShadeModel(GL_FLAT);
  4289. + glClearColor(0.5, 0.5, 0.5, 1.0);
  4290. + glClear(GL_COLOR_BUFFER_BIT);
  4291. +
  4292. + /* draw green triangle */
  4293. + glColor3f(0.0, 1.0, 0.0);
  4294. + glPushMatrix();
  4295. + glRotatef(h->Angle, 0, 0, 1);
  4296. + glBegin(GL_TRIANGLES);
  4297. + glVertex2f(0, 0.8);
  4298. + glVertex2f(-0.8, -0.7);
  4299. + glVertex2f(0.8, -0.7);
  4300. + glEnd();
  4301. + glPopMatrix();
  4302. +
  4303. + glXSwapBuffers(h->Dpy, h->Win);
  4304. +}
  4305. +
  4306. +
  4307. +
  4308. +static void
  4309. +Resize(const struct head *h, unsigned int width, unsigned int height)
  4310. +{
  4311. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  4312. + Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
  4313. + return;
  4314. + }
  4315. + glFlush();
  4316. + glViewport(0, 0, width, height);
  4317. + glMatrixMode(GL_PROJECTION);
  4318. + glLoadIdentity();
  4319. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  4320. +}
  4321. +
  4322. +
  4323. +
  4324. +static void
  4325. +EventLoop(void)
  4326. +{
  4327. + while (1) {
  4328. + int i;
  4329. + for (i = 0; i < NumHeads; i++) {
  4330. + struct head *h = &Heads[i];
  4331. + while (XPending(h->Dpy) > 0) {
  4332. + XEvent event;
  4333. + XNextEvent(h->Dpy, &event);
  4334. + if (event.xany.window == h->Win) {
  4335. + switch (event.type) {
  4336. + case Expose:
  4337. + Redraw(h);
  4338. + break;
  4339. + case ConfigureNotify:
  4340. + Resize(h, event.xconfigure.width, event.xconfigure.height);
  4341. + break;
  4342. + case KeyPress:
  4343. + return;
  4344. + default:
  4345. + /*no-op*/ ;
  4346. + }
  4347. + }
  4348. + else {
  4349. + printf("window mismatch\n");
  4350. + }
  4351. + }
  4352. + Redraw(h);
  4353. + }
  4354. + usleep(1);
  4355. + }
  4356. +}
  4357. +
  4358. +
  4359. +
  4360. +static void
  4361. +PrintInfo(const struct head *h)
  4362. +{
  4363. + printf("Name: %s\n", h->DisplayName);
  4364. + printf(" Display: %p\n", (void *) h->Dpy);
  4365. + printf(" Window: 0x%x\n", (int) h->Win);
  4366. + printf(" Context: 0x%lx\n", (long) h->Context);
  4367. + printf(" GL_VERSION: %s\n", h->Version);
  4368. + printf(" GL_VENDOR: %s\n", h->Vendor);
  4369. + printf(" GL_RENDERER: %s\n", h->Renderer);
  4370. +}
  4371. +
  4372. +
  4373. +int
  4374. +main(int argc, char *argv[])
  4375. +{
  4376. + int i;
  4377. + if (argc == 1) {
  4378. + struct head *h;
  4379. + printf("glxheads: exercise multiple GLX connections (any key = exit)\n");
  4380. + printf("Usage:\n");
  4381. + printf(" glxheads xdisplayname ...\n");
  4382. + printf("Example:\n");
  4383. + printf(" glxheads :0 mars:0 venus:1\n");
  4384. +
  4385. + h = AddHead(XDisplayName(NULL));
  4386. + if (h)
  4387. + PrintInfo(h);
  4388. + }
  4389. + else {
  4390. + for (i = 1; i < argc; i++) {
  4391. + const char *name = argv[i];
  4392. + struct head *h = AddHead(name);
  4393. + if (h) {
  4394. + PrintInfo(h);
  4395. + }
  4396. + }
  4397. + }
  4398. +
  4399. + EventLoop();
  4400. + return 0;
  4401. +}
  4402. diff -Naurp Mesa-7.8.1/progs/xdemos/glxinfo.c Mesa-7.8.1.patched/progs/xdemos/glxinfo.c
  4403. --- Mesa-7.8.1/progs/xdemos/glxinfo.c 1970-01-01 01:00:00.000000000 +0100
  4404. +++ Mesa-7.8.1.patched/progs/xdemos/glxinfo.c 2010-06-13 13:45:06.788792936 +0200
  4405. @@ -0,0 +1,1195 @@
  4406. +/*
  4407. + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
  4408. + *
  4409. + * Permission is hereby granted, free of charge, to any person obtaining a
  4410. + * copy of this software and associated documentation files (the "Software"),
  4411. + * to deal in the Software without restriction, including without limitation
  4412. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  4413. + * and/or sell copies of the Software, and to permit persons to whom the
  4414. + * Software is furnished to do so, subject to the following conditions:
  4415. + *
  4416. + * The above copyright notice and this permission notice shall be included
  4417. + * in all copies or substantial portions of the Software.
  4418. + *
  4419. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4420. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4421. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  4422. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  4423. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4424. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4425. + */
  4426. +
  4427. +
  4428. +/*
  4429. + * This program is a work-alike of the IRIX glxinfo program.
  4430. + * Command line options:
  4431. + * -t print wide table
  4432. + * -v print verbose information
  4433. + * -display DisplayName specify the X display to interogate
  4434. + * -b only print ID of "best" visual on screen 0
  4435. + * -i use indirect rendering connection only
  4436. + * -l print interesting OpenGL limits (added 5 Sep 2002)
  4437. + *
  4438. + * Brian Paul 26 January 2000
  4439. + */
  4440. +
  4441. +#define GLX_GLXEXT_PROTOTYPES
  4442. +
  4443. +#include <X11/Xlib.h>
  4444. +#include <X11/Xutil.h>
  4445. +#include <GL/gl.h>
  4446. +#include <GL/glx.h>
  4447. +#include <stdio.h>
  4448. +#include <string.h>
  4449. +#include <stdlib.h>
  4450. +
  4451. +
  4452. +#ifndef GLX_NONE_EXT
  4453. +#define GLX_NONE_EXT 0x8000
  4454. +#endif
  4455. +
  4456. +#ifndef GLX_TRANSPARENT_RGB
  4457. +#define GLX_TRANSPARENT_RGB 0x8008
  4458. +#endif
  4459. +
  4460. +#ifndef GLX_RGBA_BIT
  4461. +#define GLX_RGBA_BIT 0x00000001
  4462. +#endif
  4463. +
  4464. +#ifndef GLX_COLOR_INDEX_BIT
  4465. +#define GLX_COLOR_INDEX_BIT 0x00000002
  4466. +#endif
  4467. +
  4468. +typedef enum
  4469. +{
  4470. + Normal,
  4471. + Wide,
  4472. + Verbose
  4473. +} InfoMode;
  4474. +
  4475. +
  4476. +struct visual_attribs
  4477. +{
  4478. + /* X visual attribs */
  4479. + int id;
  4480. + int klass;
  4481. + int depth;
  4482. + int redMask, greenMask, blueMask;
  4483. + int colormapSize;
  4484. + int bitsPerRGB;
  4485. +
  4486. + /* GL visual attribs */
  4487. + int supportsGL;
  4488. + int transparentType;
  4489. + int transparentRedValue;
  4490. + int transparentGreenValue;
  4491. + int transparentBlueValue;
  4492. + int transparentAlphaValue;
  4493. + int transparentIndexValue;
  4494. + int bufferSize;
  4495. + int level;
  4496. + int render_type;
  4497. + int doubleBuffer;
  4498. + int stereo;
  4499. + int auxBuffers;
  4500. + int redSize, greenSize, blueSize, alphaSize;
  4501. + int depthSize;
  4502. + int stencilSize;
  4503. + int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
  4504. + int numSamples, numMultisample;
  4505. + int visualCaveat;
  4506. +};
  4507. +
  4508. +
  4509. +/*
  4510. + * Print a list of extensions, with word-wrapping.
  4511. + */
  4512. +static void
  4513. +print_extension_list(const char *ext)
  4514. +{
  4515. + const char *indentString = " ";
  4516. + const int indent = 4;
  4517. + const int max = 79;
  4518. + int width, i, j;
  4519. +
  4520. + if (!ext || !ext[0])
  4521. + return;
  4522. +
  4523. + width = indent;
  4524. + printf("%s", indentString);
  4525. + i = j = 0;
  4526. + while (1) {
  4527. + if (ext[j] == ' ' || ext[j] == 0) {
  4528. + /* found end of an extension name */
  4529. + const int len = j - i;
  4530. + if (width + len > max) {
  4531. + /* start a new line */
  4532. + printf("\n");
  4533. + width = indent;
  4534. + printf("%s", indentString);
  4535. + }
  4536. + /* print the extension name between ext[i] and ext[j] */
  4537. + while (i < j) {
  4538. + printf("%c", ext[i]);
  4539. + i++;
  4540. + }
  4541. + /* either we're all done, or we'll continue with next extension */
  4542. + width += len + 1;
  4543. + if (ext[j] == 0) {
  4544. + break;
  4545. + }
  4546. + else {
  4547. + i++;
  4548. + j++;
  4549. + if (ext[j] == 0)
  4550. + break;
  4551. + printf(", ");
  4552. + width += 2;
  4553. + }
  4554. + }
  4555. + j++;
  4556. + }
  4557. + printf("\n");
  4558. +}
  4559. +
  4560. +
  4561. +static void
  4562. +print_display_info(Display *dpy)
  4563. +{
  4564. + printf("name of display: %s\n", DisplayString(dpy));
  4565. +}
  4566. +
  4567. +
  4568. +/**
  4569. + * Print interesting limits for vertex/fragment programs.
  4570. + */
  4571. +static void
  4572. +print_program_limits(GLenum target)
  4573. +{
  4574. +#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
  4575. + struct token_name {
  4576. + GLenum token;
  4577. + const char *name;
  4578. + };
  4579. + static const struct token_name common_limits[] = {
  4580. + { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
  4581. + { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
  4582. + { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
  4583. + { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
  4584. + { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
  4585. + { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
  4586. + { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
  4587. + { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
  4588. + { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
  4589. + { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
  4590. + { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
  4591. + { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
  4592. + { (GLenum) 0, NULL }
  4593. + };
  4594. + static const struct token_name fragment_limits[] = {
  4595. + { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
  4596. + { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
  4597. + { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
  4598. + { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
  4599. + { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
  4600. + { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
  4601. + { (GLenum) 0, NULL }
  4602. + };
  4603. +
  4604. + PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC)
  4605. + glXGetProcAddressARB((GLubyte *) "glGetProgramivARB");
  4606. +
  4607. + GLint max[1];
  4608. + int i;
  4609. +
  4610. + if (target == GL_VERTEX_PROGRAM_ARB) {
  4611. + printf(" GL_VERTEX_PROGRAM_ARB:\n");
  4612. + }
  4613. + else if (target == GL_FRAGMENT_PROGRAM_ARB) {
  4614. + printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
  4615. + }
  4616. + else {
  4617. + return; /* something's wrong */
  4618. + }
  4619. +
  4620. + for (i = 0; common_limits[i].token; i++) {
  4621. + GetProgramivARB_func(target, common_limits[i].token, max);
  4622. + if (glGetError() == GL_NO_ERROR) {
  4623. + printf(" %s = %d\n", common_limits[i].name, max[0]);
  4624. + }
  4625. + }
  4626. + if (target == GL_FRAGMENT_PROGRAM_ARB) {
  4627. + for (i = 0; fragment_limits[i].token; i++) {
  4628. + GetProgramivARB_func(target, fragment_limits[i].token, max);
  4629. + if (glGetError() == GL_NO_ERROR) {
  4630. + printf(" %s = %d\n", fragment_limits[i].name, max[0]);
  4631. + }
  4632. + }
  4633. + }
  4634. +#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
  4635. +}
  4636. +
  4637. +
  4638. +/**
  4639. + * Print interesting limits for vertex/fragment shaders.
  4640. + */
  4641. +static void
  4642. +print_shader_limits(GLenum target)
  4643. +{
  4644. + struct token_name {
  4645. + GLenum token;
  4646. + const char *name;
  4647. + };
  4648. +#if defined(GL_ARB_vertex_shader)
  4649. + static const struct token_name vertex_limits[] = {
  4650. + { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
  4651. + { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
  4652. + { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
  4653. + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
  4654. + { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
  4655. + { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
  4656. + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
  4657. + { (GLenum) 0, NULL }
  4658. + };
  4659. +#endif
  4660. +#if defined(GL_ARB_fragment_shader)
  4661. + static const struct token_name fragment_limits[] = {
  4662. + { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
  4663. + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
  4664. + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
  4665. + { (GLenum) 0, NULL }
  4666. + };
  4667. +#endif
  4668. + GLint max[1];
  4669. + int i;
  4670. +
  4671. +#if defined(GL_ARB_vertex_shader)
  4672. + if (target == GL_VERTEX_SHADER_ARB) {
  4673. + printf(" GL_VERTEX_SHADER_ARB:\n");
  4674. + for (i = 0; vertex_limits[i].token; i++) {
  4675. + glGetIntegerv(vertex_limits[i].token, max);
  4676. + if (glGetError() == GL_NO_ERROR) {
  4677. + printf(" %s = %d\n", vertex_limits[i].name, max[0]);
  4678. + }
  4679. + }
  4680. + }
  4681. +#endif
  4682. +#if defined(GL_ARB_fragment_shader)
  4683. + if (target == GL_FRAGMENT_SHADER_ARB) {
  4684. + printf(" GL_FRAGMENT_SHADER_ARB:\n");
  4685. + for (i = 0; fragment_limits[i].token; i++) {
  4686. + glGetIntegerv(fragment_limits[i].token, max);
  4687. + if (glGetError() == GL_NO_ERROR) {
  4688. + printf(" %s = %d\n", fragment_limits[i].name, max[0]);
  4689. + }
  4690. + }
  4691. + }
  4692. +#endif
  4693. +}
  4694. +
  4695. +
  4696. +/**
  4697. + * Print interesting OpenGL implementation limits.
  4698. + */
  4699. +static void
  4700. +print_limits(const char *extensions)
  4701. +{
  4702. + struct token_name {
  4703. + GLuint count;
  4704. + GLenum token;
  4705. + const char *name;
  4706. + };
  4707. + static const struct token_name limits[] = {
  4708. + { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
  4709. + { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
  4710. + { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
  4711. + { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
  4712. + { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
  4713. + { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
  4714. + { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
  4715. + { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
  4716. + { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
  4717. + { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
  4718. + { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
  4719. + { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
  4720. + { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
  4721. + { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
  4722. + { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
  4723. + { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
  4724. + { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
  4725. + { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
  4726. + { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
  4727. + { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
  4728. + { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
  4729. +#if defined(GL_ARB_texture_cube_map)
  4730. + { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
  4731. +#endif
  4732. +#if defined(GLX_NV_texture_rectangle)
  4733. + { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
  4734. +#endif
  4735. +#if defined(GL_ARB_texture_compression)
  4736. + { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
  4737. +#endif
  4738. +#if defined(GL_ARB_multitexture)
  4739. + { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
  4740. +#endif
  4741. +#if defined(GL_EXT_texture_lod_bias)
  4742. + { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
  4743. +#endif
  4744. +#if defined(GL_EXT_texture_filter_anisotropic)
  4745. + { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
  4746. +#endif
  4747. +#if defined(GL_ARB_draw_buffers)
  4748. + { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" },
  4749. +#endif
  4750. + { 0, (GLenum) 0, NULL }
  4751. + };
  4752. + GLint i, max[2];
  4753. +
  4754. + printf("OpenGL limits:\n");
  4755. + for (i = 0; limits[i].count; i++) {
  4756. + glGetIntegerv(limits[i].token, max);
  4757. + if (glGetError() == GL_NO_ERROR) {
  4758. + if (limits[i].count == 1)
  4759. + printf(" %s = %d\n", limits[i].name, max[0]);
  4760. + else /* XXX fix if we ever query something with more than 2 values */
  4761. + printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
  4762. + }
  4763. + }
  4764. +
  4765. + /* these don't fit into the above mechanism, unfortunately */
  4766. + glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
  4767. + glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
  4768. + if (glGetError() == GL_NONE) {
  4769. + printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
  4770. + }
  4771. +
  4772. +#if defined(GL_ARB_vertex_program)
  4773. + if (strstr(extensions, "GL_ARB_vertex_program")) {
  4774. + print_program_limits(GL_VERTEX_PROGRAM_ARB);
  4775. + }
  4776. +#endif
  4777. +#if defined(GL_ARB_fragment_program)
  4778. + if (strstr(extensions, "GL_ARB_fragment_program")) {
  4779. + print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
  4780. + }
  4781. +#endif
  4782. +#if defined(GL_ARB_vertex_shader)
  4783. + if (strstr(extensions, "GL_ARB_vertex_shader")) {
  4784. + print_shader_limits(GL_VERTEX_SHADER_ARB);
  4785. + }
  4786. +#endif
  4787. +#if defined(GL_ARB_fragment_shader)
  4788. + if (strstr(extensions, "GL_ARB_fragment_shader")) {
  4789. + print_shader_limits(GL_FRAGMENT_SHADER_ARB);
  4790. + }
  4791. +#endif
  4792. +}
  4793. +
  4794. +
  4795. +static void
  4796. +print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
  4797. +{
  4798. + Window win;
  4799. + int attribSingle[] = {
  4800. + GLX_RGBA,
  4801. + GLX_RED_SIZE, 1,
  4802. + GLX_GREEN_SIZE, 1,
  4803. + GLX_BLUE_SIZE, 1,
  4804. + None };
  4805. + int attribDouble[] = {
  4806. + GLX_RGBA,
  4807. + GLX_RED_SIZE, 1,
  4808. + GLX_GREEN_SIZE, 1,
  4809. + GLX_BLUE_SIZE, 1,
  4810. + GLX_DOUBLEBUFFER,
  4811. + None };
  4812. +
  4813. + XSetWindowAttributes attr;
  4814. + unsigned long mask;
  4815. + Window root;
  4816. + GLXContext ctx = NULL;
  4817. + XVisualInfo *visinfo;
  4818. + int width = 100, height = 100;
  4819. +
  4820. + root = RootWindow(dpy, scrnum);
  4821. +
  4822. + /*
  4823. + * Find a basic GLX visual. We'll then create a rendering context and
  4824. + * query various info strings.
  4825. + */
  4826. + visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
  4827. + if (!visinfo)
  4828. + visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
  4829. +
  4830. + if (visinfo)
  4831. + ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
  4832. +
  4833. +#ifdef GLX_VERSION_1_3
  4834. + /* Try glXChooseFBConfig() if glXChooseVisual didn't work.
  4835. + * XXX when would that happen?
  4836. + */
  4837. + if (!visinfo) {
  4838. + int fbAttribSingle[] = {
  4839. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  4840. + GLX_RED_SIZE, 1,
  4841. + GLX_GREEN_SIZE, 1,
  4842. + GLX_BLUE_SIZE, 1,
  4843. + GLX_DOUBLEBUFFER, GL_FALSE,
  4844. + None };
  4845. + int fbAttribDouble[] = {
  4846. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  4847. + GLX_RED_SIZE, 1,
  4848. + GLX_GREEN_SIZE, 1,
  4849. + GLX_BLUE_SIZE, 1,
  4850. + GLX_DOUBLEBUFFER, GL_TRUE,
  4851. + None };
  4852. + GLXFBConfig *configs = NULL;
  4853. + int nConfigs;
  4854. +
  4855. + configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
  4856. + if (!configs)
  4857. + configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
  4858. +
  4859. + if (configs) {
  4860. + visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
  4861. + ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
  4862. + XFree(configs);
  4863. + }
  4864. + }
  4865. +#endif
  4866. +
  4867. + if (!visinfo) {
  4868. + fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
  4869. + return;
  4870. + }
  4871. +
  4872. + if (!ctx) {
  4873. + fprintf(stderr, "Error: glXCreateContext failed\n");
  4874. + XFree(visinfo);
  4875. + return;
  4876. + }
  4877. +
  4878. + attr.background_pixel = 0;
  4879. + attr.border_pixel = 0;
  4880. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  4881. + attr.event_mask = StructureNotifyMask | ExposureMask;
  4882. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  4883. + win = XCreateWindow(dpy, root, 0, 0, width, height,
  4884. + 0, visinfo->depth, InputOutput,
  4885. + visinfo->visual, mask, &attr);
  4886. +
  4887. + if (glXMakeCurrent(dpy, win, ctx)) {
  4888. + const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
  4889. + const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
  4890. + const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
  4891. + const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
  4892. + const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
  4893. + const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
  4894. + const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
  4895. + const char *glVendor = (const char *) glGetString(GL_VENDOR);
  4896. + const char *glRenderer = (const char *) glGetString(GL_RENDERER);
  4897. + const char *glVersion = (const char *) glGetString(GL_VERSION);
  4898. + const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
  4899. + int glxVersionMajor;
  4900. + int glxVersionMinor;
  4901. + char *displayName = NULL;
  4902. + char *colon = NULL, *period = NULL;
  4903. +
  4904. + if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
  4905. + fprintf(stderr, "Error: glXQueryVersion failed\n");
  4906. + exit(1);
  4907. + }
  4908. +
  4909. + /* Strip the screen number from the display name, if present. */
  4910. + if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
  4911. + fprintf(stderr, "Error: malloc() failed\n");
  4912. + exit(1);
  4913. + }
  4914. + strcpy(displayName, DisplayString(dpy));
  4915. + colon = strrchr(displayName, ':');
  4916. + if (colon) {
  4917. + period = strchr(colon, '.');
  4918. + if (period)
  4919. + *period = '\0';
  4920. + }
  4921. + printf("display: %s screen: %d\n", displayName, scrnum);
  4922. + free(displayName);
  4923. + printf("direct rendering: ");
  4924. + if (glXIsDirect(dpy, ctx)) {
  4925. + printf("Yes\n");
  4926. + } else {
  4927. + if (!allowDirect) {
  4928. + printf("No (-i specified)\n");
  4929. + } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
  4930. + printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
  4931. + } else {
  4932. + printf("No (If you want to find out why, try setting "
  4933. + "LIBGL_DEBUG=verbose)\n");
  4934. + }
  4935. + }
  4936. + printf("server glx vendor string: %s\n", serverVendor);
  4937. + printf("server glx version string: %s\n", serverVersion);
  4938. + printf("server glx extensions:\n");
  4939. + print_extension_list(serverExtensions);
  4940. + printf("client glx vendor string: %s\n", clientVendor);
  4941. + printf("client glx version string: %s\n", clientVersion);
  4942. + printf("client glx extensions:\n");
  4943. + print_extension_list(clientExtensions);
  4944. + printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
  4945. + printf("GLX extensions:\n");
  4946. + print_extension_list(glxExtensions);
  4947. + printf("OpenGL vendor string: %s\n", glVendor);
  4948. + printf("OpenGL renderer string: %s\n", glRenderer);
  4949. + printf("OpenGL version string: %s\n", glVersion);
  4950. +#ifdef GL_VERSION_2_0
  4951. + if (glVersion[0] >= '2' && glVersion[1] == '.') {
  4952. + char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
  4953. + printf("OpenGL shading language version string: %s\n", v);
  4954. + }
  4955. +#endif
  4956. +
  4957. + printf("OpenGL extensions:\n");
  4958. + print_extension_list(glExtensions);
  4959. + if (limits)
  4960. + print_limits(glExtensions);
  4961. + }
  4962. + else {
  4963. + fprintf(stderr, "Error: glXMakeCurrent failed\n");
  4964. + }
  4965. +
  4966. + glXDestroyContext(dpy, ctx);
  4967. + XFree(visinfo);
  4968. + XDestroyWindow(dpy, win);
  4969. +}
  4970. +
  4971. +
  4972. +static const char *
  4973. +visual_class_name(int cls)
  4974. +{
  4975. + switch (cls) {
  4976. + case StaticColor:
  4977. + return "StaticColor";
  4978. + case PseudoColor:
  4979. + return "PseudoColor";
  4980. + case StaticGray:
  4981. + return "StaticGray";
  4982. + case GrayScale:
  4983. + return "GrayScale";
  4984. + case TrueColor:
  4985. + return "TrueColor";
  4986. + case DirectColor:
  4987. + return "DirectColor";
  4988. + default:
  4989. + return "";
  4990. + }
  4991. +}
  4992. +
  4993. +
  4994. +static const char *
  4995. +visual_class_abbrev(int cls)
  4996. +{
  4997. + switch (cls) {
  4998. + case StaticColor:
  4999. + return "sc";
  5000. + case PseudoColor:
  5001. + return "pc";
  5002. + case StaticGray:
  5003. + return "sg";
  5004. + case GrayScale:
  5005. + return "gs";
  5006. + case TrueColor:
  5007. + return "tc";
  5008. + case DirectColor:
  5009. + return "dc";
  5010. + default:
  5011. + return "";
  5012. + }
  5013. +}
  5014. +
  5015. +static const char *
  5016. +visual_render_type_name(int type)
  5017. +{
  5018. + switch (type) {
  5019. + case GLX_RGBA_BIT:
  5020. + return "rgba";
  5021. + case GLX_COLOR_INDEX_BIT:
  5022. + return "ci";
  5023. + case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
  5024. + return "rgba|ci";
  5025. + default:
  5026. + return "";
  5027. + }
  5028. +}
  5029. +
  5030. +static GLboolean
  5031. +get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
  5032. + struct visual_attribs *attribs)
  5033. +{
  5034. + const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
  5035. + int rgba;
  5036. +
  5037. + memset(attribs, 0, sizeof(struct visual_attribs));
  5038. +
  5039. + attribs->id = vInfo->visualid;
  5040. +#if defined(__cplusplus) || defined(c_plusplus)
  5041. + attribs->klass = vInfo->c_class;
  5042. +#else
  5043. + attribs->klass = vInfo->class;
  5044. +#endif
  5045. + attribs->depth = vInfo->depth;
  5046. + attribs->redMask = vInfo->red_mask;
  5047. + attribs->greenMask = vInfo->green_mask;
  5048. + attribs->blueMask = vInfo->blue_mask;
  5049. + attribs->colormapSize = vInfo->colormap_size;
  5050. + attribs->bitsPerRGB = vInfo->bits_per_rgb;
  5051. +
  5052. + if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
  5053. + !attribs->supportsGL)
  5054. + return GL_FALSE;
  5055. + glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
  5056. + glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
  5057. + glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
  5058. + if (rgba)
  5059. + attribs->render_type = GLX_RGBA_BIT;
  5060. + else
  5061. + attribs->render_type = GLX_COLOR_INDEX_BIT;
  5062. +
  5063. + glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
  5064. + glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
  5065. + glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
  5066. + glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
  5067. + glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
  5068. + glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
  5069. + glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
  5070. + glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
  5071. + glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
  5072. + glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
  5073. + glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
  5074. + glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
  5075. + glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
  5076. +
  5077. + /* get transparent pixel stuff */
  5078. + glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
  5079. + if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
  5080. + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
  5081. + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
  5082. + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
  5083. + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
  5084. + }
  5085. + else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
  5086. + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
  5087. + }
  5088. +
  5089. + /* multisample attribs */
  5090. +#ifdef GLX_ARB_multisample
  5091. + if (ext && strstr(ext, "GLX_ARB_multisample")) {
  5092. + glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
  5093. + glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
  5094. + }
  5095. +#endif
  5096. + else {
  5097. + attribs->numSamples = 0;
  5098. + attribs->numMultisample = 0;
  5099. + }
  5100. +
  5101. +#if defined(GLX_EXT_visual_rating)
  5102. + if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
  5103. + glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
  5104. + }
  5105. + else {
  5106. + attribs->visualCaveat = GLX_NONE_EXT;
  5107. + }
  5108. +#else
  5109. + attribs->visualCaveat = 0;
  5110. +#endif
  5111. +
  5112. + return GL_TRUE;
  5113. +}
  5114. +
  5115. +#ifdef GLX_VERSION_1_3
  5116. +
  5117. +static int
  5118. +glx_token_to_visual_class(int visual_type)
  5119. +{
  5120. + switch (visual_type) {
  5121. + case GLX_TRUE_COLOR:
  5122. + return TrueColor;
  5123. + case GLX_DIRECT_COLOR:
  5124. + return DirectColor;
  5125. + case GLX_PSEUDO_COLOR:
  5126. + return PseudoColor;
  5127. + case GLX_STATIC_COLOR:
  5128. + return StaticColor;
  5129. + case GLX_GRAY_SCALE:
  5130. + return GrayScale;
  5131. + case GLX_STATIC_GRAY:
  5132. + return StaticGray;
  5133. + case GLX_NONE:
  5134. + default:
  5135. + return None;
  5136. + }
  5137. +}
  5138. +
  5139. +static GLboolean
  5140. +get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
  5141. + struct visual_attribs *attribs)
  5142. +{
  5143. + int visual_type;
  5144. +
  5145. + memset(attribs, 0, sizeof(struct visual_attribs));
  5146. +
  5147. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
  5148. +
  5149. +#if 0
  5150. + attribs->depth = vInfo->depth;
  5151. + attribs->redMask = vInfo->red_mask;
  5152. + attribs->greenMask = vInfo->green_mask;
  5153. + attribs->blueMask = vInfo->blue_mask;
  5154. + attribs->colormapSize = vInfo->colormap_size;
  5155. + attribs->bitsPerRGB = vInfo->bits_per_rgb;
  5156. +#endif
  5157. +
  5158. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
  5159. + attribs->klass = glx_token_to_visual_class(visual_type);
  5160. +
  5161. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
  5162. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
  5163. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
  5164. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
  5165. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
  5166. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
  5167. +
  5168. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
  5169. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
  5170. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
  5171. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
  5172. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
  5173. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
  5174. +
  5175. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
  5176. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
  5177. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
  5178. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
  5179. +
  5180. + /* get transparent pixel stuff */
  5181. + glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
  5182. + if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
  5183. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
  5184. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
  5185. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
  5186. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
  5187. + }
  5188. + else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
  5189. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
  5190. + }
  5191. +
  5192. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
  5193. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
  5194. + glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
  5195. +
  5196. + return GL_TRUE;
  5197. +}
  5198. +
  5199. +#endif
  5200. +
  5201. +
  5202. +
  5203. +static void
  5204. +print_visual_attribs_verbose(const struct visual_attribs *attribs)
  5205. +{
  5206. + printf("Visual ID: %x depth=%d class=%s\n",
  5207. + attribs->id, attribs->depth, visual_class_name(attribs->klass));
  5208. + printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
  5209. + attribs->bufferSize, attribs->level,
  5210. + visual_render_type_name(attribs->render_type),
  5211. + attribs->doubleBuffer, attribs->stereo);
  5212. + printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  5213. + attribs->redSize, attribs->greenSize,
  5214. + attribs->blueSize, attribs->alphaSize);
  5215. + printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
  5216. + attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
  5217. + printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  5218. + attribs->accumRedSize, attribs->accumGreenSize,
  5219. + attribs->accumBlueSize, attribs->accumAlphaSize);
  5220. + printf(" multiSample=%d multiSampleBuffers=%d\n",
  5221. + attribs->numSamples, attribs->numMultisample);
  5222. +#ifdef GLX_EXT_visual_rating
  5223. + if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
  5224. + printf(" visualCaveat=None\n");
  5225. + else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
  5226. + printf(" visualCaveat=Slow\n");
  5227. + else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
  5228. + printf(" visualCaveat=Nonconformant\n");
  5229. +#endif
  5230. + if (attribs->transparentType == GLX_NONE) {
  5231. + printf(" Opaque.\n");
  5232. + }
  5233. + else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
  5234. + printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
  5235. + }
  5236. + else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
  5237. + printf(" Transparent index=%d\n",attribs->transparentIndexValue);
  5238. + }
  5239. +}
  5240. +
  5241. +
  5242. +static void
  5243. +print_visual_attribs_short_header(void)
  5244. +{
  5245. + printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
  5246. + printf(" id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n");
  5247. + printf("----------------------------------------------------------------------\n");
  5248. +}
  5249. +
  5250. +
  5251. +static void
  5252. +print_visual_attribs_short(const struct visual_attribs *attribs)
  5253. +{
  5254. + char *caveat = NULL;
  5255. +#ifdef GLX_EXT_visual_rating
  5256. + if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
  5257. + caveat = "None";
  5258. + else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
  5259. + caveat = "Slow";
  5260. + else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
  5261. + caveat = "Ncon";
  5262. + else
  5263. + caveat = "None";
  5264. +#else
  5265. + caveat = "None";
  5266. +#endif
  5267. +
  5268. + printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
  5269. + attribs->id,
  5270. + attribs->depth,
  5271. + visual_class_abbrev(attribs->klass),
  5272. + attribs->transparentType != GLX_NONE,
  5273. + attribs->bufferSize,
  5274. + attribs->level,
  5275. + (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
  5276. + (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
  5277. + attribs->doubleBuffer ? 'y' : '.',
  5278. + attribs->stereo ? 'y' : '.',
  5279. + attribs->redSize, attribs->greenSize,
  5280. + attribs->blueSize, attribs->alphaSize,
  5281. + attribs->auxBuffers,
  5282. + attribs->depthSize,
  5283. + attribs->stencilSize
  5284. + );
  5285. +
  5286. + printf(" %2d %2d %2d %2d %2d %1d %s\n",
  5287. + attribs->accumRedSize, attribs->accumGreenSize,
  5288. + attribs->accumBlueSize, attribs->accumAlphaSize,
  5289. + attribs->numSamples, attribs->numMultisample,
  5290. + caveat
  5291. + );
  5292. +}
  5293. +
  5294. +
  5295. +static void
  5296. +print_visual_attribs_long_header(void)
  5297. +{
  5298. + printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
  5299. + printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
  5300. + printf("----------------------------------------------------------------------------------------------------\n");
  5301. +}
  5302. +
  5303. +
  5304. +static void
  5305. +print_visual_attribs_long(const struct visual_attribs *attribs)
  5306. +{
  5307. + printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
  5308. + attribs->id,
  5309. + attribs->depth,
  5310. + visual_class_name(attribs->klass),
  5311. + attribs->transparentType != GLX_NONE,
  5312. + attribs->bufferSize,
  5313. + attribs->level,
  5314. + visual_render_type_name(attribs->render_type),
  5315. + attribs->doubleBuffer,
  5316. + attribs->stereo,
  5317. + attribs->redSize, attribs->greenSize,
  5318. + attribs->blueSize, attribs->alphaSize
  5319. + );
  5320. +
  5321. + printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
  5322. + attribs->auxBuffers,
  5323. + attribs->depthSize,
  5324. + attribs->stencilSize,
  5325. + attribs->accumRedSize, attribs->accumGreenSize,
  5326. + attribs->accumBlueSize, attribs->accumAlphaSize,
  5327. + attribs->numSamples, attribs->numMultisample
  5328. + );
  5329. +}
  5330. +
  5331. +
  5332. +static void
  5333. +print_visual_info(Display *dpy, int scrnum, InfoMode mode)
  5334. +{
  5335. + XVisualInfo theTemplate;
  5336. + XVisualInfo *visuals;
  5337. + int numVisuals, numGlxVisuals;
  5338. + long mask;
  5339. + int i;
  5340. + struct visual_attribs attribs;
  5341. +
  5342. + /* get list of all visuals on this screen */
  5343. + theTemplate.screen = scrnum;
  5344. + mask = VisualScreenMask;
  5345. + visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
  5346. +
  5347. + numGlxVisuals = 0;
  5348. + for (i = 0; i < numVisuals; i++) {
  5349. + if (get_visual_attribs(dpy, &visuals[i], &attribs))
  5350. + numGlxVisuals++;
  5351. + }
  5352. +
  5353. + if (numGlxVisuals == 0)
  5354. + return;
  5355. +
  5356. + printf("%d GLX Visuals\n", numGlxVisuals);
  5357. +
  5358. + if (mode == Normal)
  5359. + print_visual_attribs_short_header();
  5360. + else if (mode == Wide)
  5361. + print_visual_attribs_long_header();
  5362. +
  5363. + for (i = 0; i < numVisuals; i++) {
  5364. + if (!get_visual_attribs(dpy, &visuals[i], &attribs))
  5365. + continue;
  5366. +
  5367. + if (mode == Verbose)
  5368. + print_visual_attribs_verbose(&attribs);
  5369. + else if (mode == Normal)
  5370. + print_visual_attribs_short(&attribs);
  5371. + else if (mode == Wide)
  5372. + print_visual_attribs_long(&attribs);
  5373. + }
  5374. + printf("\n");
  5375. +
  5376. + XFree(visuals);
  5377. +}
  5378. +
  5379. +#ifdef GLX_VERSION_1_3
  5380. +
  5381. +static void
  5382. +print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
  5383. +{
  5384. + int numFBConfigs = 0;
  5385. + struct visual_attribs attribs;
  5386. + GLXFBConfig *fbconfigs;
  5387. + int i;
  5388. +
  5389. + /* get list of all fbconfigs on this screen */
  5390. + fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
  5391. +
  5392. + if (numFBConfigs == 0) {
  5393. + XFree(fbconfigs);
  5394. + return;
  5395. + }
  5396. +
  5397. + printf("%d GLXFBConfigs:\n", numFBConfigs);
  5398. + if (mode == Normal)
  5399. + print_visual_attribs_short_header();
  5400. + else if (mode == Wide)
  5401. + print_visual_attribs_long_header();
  5402. +
  5403. + for (i = 0; i < numFBConfigs; i++) {
  5404. + get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
  5405. +
  5406. + if (mode == Verbose)
  5407. + print_visual_attribs_verbose(&attribs);
  5408. + else if (mode == Normal)
  5409. + print_visual_attribs_short(&attribs);
  5410. + else if (mode == Wide)
  5411. + print_visual_attribs_long(&attribs);
  5412. + }
  5413. + printf("\n");
  5414. +
  5415. + XFree(fbconfigs);
  5416. +}
  5417. +
  5418. +#endif
  5419. +
  5420. +/*
  5421. + * Stand-alone Mesa doesn't really implement the GLX protocol so it
  5422. + * doesn't really know the GLX attributes associated with an X visual.
  5423. + * The first time a visual is presented to Mesa's pseudo-GLX it
  5424. + * attaches ancilliary buffers to it (like depth and stencil).
  5425. + * But that usually only works if glXChooseVisual is used.
  5426. + * This function calls glXChooseVisual() to sort of "prime the pump"
  5427. + * for Mesa's GLX so that the visuals that get reported actually
  5428. + * reflect what applications will see.
  5429. + * This has no effect when using true GLX.
  5430. + */
  5431. +static void
  5432. +mesa_hack(Display *dpy, int scrnum)
  5433. +{
  5434. + static int attribs[] = {
  5435. + GLX_RGBA,
  5436. + GLX_RED_SIZE, 1,
  5437. + GLX_GREEN_SIZE, 1,
  5438. + GLX_BLUE_SIZE, 1,
  5439. + GLX_DEPTH_SIZE, 1,
  5440. + GLX_STENCIL_SIZE, 1,
  5441. + GLX_ACCUM_RED_SIZE, 1,
  5442. + GLX_ACCUM_GREEN_SIZE, 1,
  5443. + GLX_ACCUM_BLUE_SIZE, 1,
  5444. + GLX_ACCUM_ALPHA_SIZE, 1,
  5445. + GLX_DOUBLEBUFFER,
  5446. + None
  5447. + };
  5448. + XVisualInfo *visinfo;
  5449. +
  5450. + visinfo = glXChooseVisual(dpy, scrnum, attribs);
  5451. + if (visinfo)
  5452. + XFree(visinfo);
  5453. +}
  5454. +
  5455. +
  5456. +/*
  5457. + * Examine all visuals to find the so-called best one.
  5458. + * We prefer deepest RGBA buffer with depth, stencil and accum
  5459. + * that has no caveats.
  5460. + */
  5461. +static int
  5462. +find_best_visual(Display *dpy, int scrnum)
  5463. +{
  5464. + XVisualInfo theTemplate;
  5465. + XVisualInfo *visuals;
  5466. + int numVisuals;
  5467. + long mask;
  5468. + int i;
  5469. + struct visual_attribs bestVis;
  5470. +
  5471. + /* get list of all visuals on this screen */
  5472. + theTemplate.screen = scrnum;
  5473. + mask = VisualScreenMask;
  5474. + visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
  5475. +
  5476. + /* init bestVis with first visual info */
  5477. + get_visual_attribs(dpy, &visuals[0], &bestVis);
  5478. +
  5479. + /* try to find a "better" visual */
  5480. + for (i = 1; i < numVisuals; i++) {
  5481. + struct visual_attribs vis;
  5482. +
  5483. + get_visual_attribs(dpy, &visuals[i], &vis);
  5484. +
  5485. + /* always skip visuals with caveats */
  5486. + if (vis.visualCaveat != GLX_NONE_EXT)
  5487. + continue;
  5488. +
  5489. + /* see if this vis is better than bestVis */
  5490. + if ((!bestVis.supportsGL && vis.supportsGL) ||
  5491. + (bestVis.visualCaveat != GLX_NONE_EXT) ||
  5492. + (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
  5493. + (!bestVis.doubleBuffer && vis.doubleBuffer) ||
  5494. + (bestVis.redSize < vis.redSize) ||
  5495. + (bestVis.greenSize < vis.greenSize) ||
  5496. + (bestVis.blueSize < vis.blueSize) ||
  5497. + (bestVis.alphaSize < vis.alphaSize) ||
  5498. + (bestVis.depthSize < vis.depthSize) ||
  5499. + (bestVis.stencilSize < vis.stencilSize) ||
  5500. + (bestVis.accumRedSize < vis.accumRedSize)) {
  5501. + /* found a better visual */
  5502. + bestVis = vis;
  5503. + }
  5504. + }
  5505. +
  5506. + XFree(visuals);
  5507. +
  5508. + return bestVis.id;
  5509. +}
  5510. +
  5511. +
  5512. +static void
  5513. +usage(void)
  5514. +{
  5515. + printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
  5516. + printf("\t-v: Print visuals info in verbose form.\n");
  5517. + printf("\t-t: Print verbose table.\n");
  5518. + printf("\t-display <dname>: Print GLX visuals on specified server.\n");
  5519. + printf("\t-h: This information.\n");
  5520. + printf("\t-i: Force an indirect rendering context.\n");
  5521. + printf("\t-b: Find the 'best' visual and print its number.\n");
  5522. + printf("\t-l: Print interesting OpenGL limits.\n");
  5523. +}
  5524. +
  5525. +
  5526. +int
  5527. +main(int argc, char *argv[])
  5528. +{
  5529. + char *displayName = NULL;
  5530. + Display *dpy;
  5531. + int numScreens, scrnum;
  5532. + InfoMode mode = Normal;
  5533. + GLboolean findBest = GL_FALSE;
  5534. + GLboolean limits = GL_FALSE;
  5535. + Bool allowDirect = True;
  5536. + int i;
  5537. +
  5538. + for (i = 1; i < argc; i++) {
  5539. + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
  5540. + displayName = argv[i + 1];
  5541. + i++;
  5542. + }
  5543. + else if (strcmp(argv[i], "-t") == 0) {
  5544. + mode = Wide;
  5545. + }
  5546. + else if (strcmp(argv[i], "-v") == 0) {
  5547. + mode = Verbose;
  5548. + }
  5549. + else if (strcmp(argv[i], "-b") == 0) {
  5550. + findBest = GL_TRUE;
  5551. + }
  5552. + else if (strcmp(argv[i], "-i") == 0) {
  5553. + allowDirect = False;
  5554. + }
  5555. + else if (strcmp(argv[i], "-l") == 0) {
  5556. + limits = GL_TRUE;
  5557. + }
  5558. + else if (strcmp(argv[i], "-h") == 0) {
  5559. + usage();
  5560. + return 0;
  5561. + }
  5562. + else {
  5563. + printf("Unknown option `%s'\n", argv[i]);
  5564. + usage();
  5565. + return 0;
  5566. + }
  5567. + }
  5568. +
  5569. + dpy = XOpenDisplay(displayName);
  5570. + if (!dpy) {
  5571. + fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
  5572. + return -1;
  5573. + }
  5574. +
  5575. + if (findBest) {
  5576. + int b;
  5577. + mesa_hack(dpy, 0);
  5578. + b = find_best_visual(dpy, 0);
  5579. + printf("%d\n", b);
  5580. + }
  5581. + else {
  5582. + numScreens = ScreenCount(dpy);
  5583. + print_display_info(dpy);
  5584. + for (scrnum = 0; scrnum < numScreens; scrnum++) {
  5585. + mesa_hack(dpy, scrnum);
  5586. + print_screen_info(dpy, scrnum, allowDirect, limits);
  5587. + printf("\n");
  5588. + print_visual_info(dpy, scrnum, mode);
  5589. +#ifdef GLX_VERSION_1_3
  5590. + print_fbconfig_info(dpy, scrnum, mode);
  5591. +#endif
  5592. + if (scrnum + 1 < numScreens)
  5593. + printf("\n\n");
  5594. + }
  5595. + }
  5596. +
  5597. + XCloseDisplay(dpy);
  5598. +
  5599. + return 0;
  5600. +}
  5601. diff -Naurp Mesa-7.8.1/progs/xdemos/glxpbdemo.c Mesa-7.8.1.patched/progs/xdemos/glxpbdemo.c
  5602. --- Mesa-7.8.1/progs/xdemos/glxpbdemo.c 1970-01-01 01:00:00.000000000 +0100
  5603. +++ Mesa-7.8.1.patched/progs/xdemos/glxpbdemo.c 2010-06-13 13:45:06.789793146 +0200
  5604. @@ -0,0 +1,431 @@
  5605. +
  5606. +/*
  5607. + * This program demonstrates how to do "off-screen" rendering using
  5608. + * the GLX pixel buffer extension.
  5609. + *
  5610. + * Written by Brian Paul for the "OpenGL and Window System Integration"
  5611. + * course presented at SIGGRAPH '97. Updated on 5 October 2002.
  5612. + *
  5613. + * Updated on 31 January 2004 to use native GLX by
  5614. + * Andrew P. Lentvorski, Jr. <bsder@allcaps.org>
  5615. + *
  5616. + * Usage:
  5617. + * glxpbdemo width height imgfile
  5618. + * Where:
  5619. + * width is the width, in pixels, of the image to generate.
  5620. + * height is the height, in pixels, of the image to generate.
  5621. + * imgfile is the name of the PPM image file to write.
  5622. + *
  5623. + *
  5624. + * This demo draws 3-D boxes with random orientation.
  5625. + *
  5626. + * On machines such as the SGI Indigo you may have to reconfigure your
  5627. + * display/X server to enable pbuffers. Look in the /usr/gfx/ucode/MGRAS/vof/
  5628. + * directory for display configurations with the _pbuf suffix. Use
  5629. + * setmon -x <vof> to configure your X server and display for pbuffers.
  5630. + *
  5631. + * O2 systems seem to support pbuffers well.
  5632. + *
  5633. + */
  5634. +
  5635. +#include <string.h>
  5636. +#include <stdio.h>
  5637. +#include <stdlib.h>
  5638. +#include <X11/Xlib.h>
  5639. +#include <GL/glx.h>
  5640. +
  5641. +/* Some ugly global vars */
  5642. +static GLXFBConfig gFBconfig = 0;
  5643. +static Display *gDpy = NULL;
  5644. +static int gScreen = 0;
  5645. +static GLXPbuffer gPBuffer = 0;
  5646. +static int gWidth, gHeight;
  5647. +
  5648. +
  5649. +/*
  5650. + * Test for appropriate version of GLX to run this program
  5651. + * Input: dpy - the X display
  5652. + * screen - screen number
  5653. + * Return: 0 = GLX not available.
  5654. + * 1 = GLX available.
  5655. + */
  5656. +static int
  5657. +RuntimeQueryGLXVersion(Display *dpy, int screen)
  5658. +{
  5659. +#if defined(GLX_VERSION_1_3) || defined(GLX_VERSION_1_4)
  5660. + char *glxversion;
  5661. +
  5662. + glxversion = (char *) glXGetClientString(dpy, GLX_VERSION);
  5663. + if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4")))
  5664. + return 0;
  5665. +
  5666. + glxversion = (char *) glXQueryServerString(dpy, screen, GLX_VERSION);
  5667. + if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4")))
  5668. + return 0;
  5669. +
  5670. + return 1;
  5671. +#else
  5672. + return 0;
  5673. +#endif
  5674. +}
  5675. +
  5676. +
  5677. +
  5678. +/*
  5679. + * Create the pbuffer and return a GLXPbuffer handle.
  5680. + */
  5681. +static GLXPbuffer
  5682. +MakePbuffer( Display *dpy, int screen, int width, int height )
  5683. +{
  5684. + GLXFBConfig *fbConfigs;
  5685. + GLXFBConfig chosenFBConfig;
  5686. + GLXPbuffer pBuffer = None;
  5687. +
  5688. + int nConfigs;
  5689. + int fbconfigid;
  5690. +
  5691. + int fbAttribs[] = {
  5692. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  5693. + GLX_DEPTH_SIZE, 1,
  5694. + GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_PBUFFER_BIT,
  5695. + None
  5696. + };
  5697. +
  5698. + int pbAttribs[] = {
  5699. + GLX_PBUFFER_WIDTH, 0,
  5700. + GLX_PBUFFER_HEIGHT, 0,
  5701. + GLX_LARGEST_PBUFFER, False,
  5702. + GLX_PRESERVED_CONTENTS, False,
  5703. + None
  5704. + };
  5705. +
  5706. + pbAttribs[1] = width;
  5707. + pbAttribs[3] = height;
  5708. +
  5709. + fbConfigs = glXChooseFBConfig(dpy, screen, fbAttribs, &nConfigs);
  5710. +
  5711. + if (0 == nConfigs || !fbConfigs) {
  5712. + printf("Error: glxChooseFBConfig failed\n");
  5713. + XFree(fbConfigs);
  5714. + XCloseDisplay(dpy);
  5715. + return 0;
  5716. + }
  5717. +
  5718. + chosenFBConfig = fbConfigs[0];
  5719. +
  5720. + glXGetFBConfigAttrib(dpy, chosenFBConfig, GLX_FBCONFIG_ID, &fbconfigid);
  5721. + printf("Chose 0x%x as fbconfigid\n", fbconfigid);
  5722. +
  5723. + /* Create the pbuffer using first fbConfig in the list that works. */
  5724. + pBuffer = glXCreatePbuffer(dpy, chosenFBConfig, pbAttribs);
  5725. +
  5726. + if (pBuffer) {
  5727. + gFBconfig = chosenFBConfig;
  5728. + gWidth = width;
  5729. + gHeight = height;
  5730. + }
  5731. +
  5732. + XFree(fbConfigs);
  5733. +
  5734. + return pBuffer;
  5735. +}
  5736. +
  5737. +
  5738. +
  5739. +/*
  5740. + * Do all the X / GLX setup stuff.
  5741. + */
  5742. +static int
  5743. +Setup(int width, int height)
  5744. +{
  5745. +#if defined(GLX_VERSION_1_3) || defined(GLX_VERSION_1_4)
  5746. + GLXContext glCtx;
  5747. +
  5748. + /* Open the X display */
  5749. + gDpy = XOpenDisplay(NULL);
  5750. + if (!gDpy) {
  5751. + printf("Error: couldn't open default X display.\n");
  5752. + return 0;
  5753. + }
  5754. +
  5755. + /* Get default screen */
  5756. + gScreen = DefaultScreen(gDpy);
  5757. +
  5758. + /* Test that GLX is available */
  5759. + if (!RuntimeQueryGLXVersion(gDpy, gScreen)) {
  5760. + printf("Error: GLX 1.3 or 1.4 not available\n");
  5761. + XCloseDisplay(gDpy);
  5762. + return 0;
  5763. + }
  5764. +
  5765. + /* Create Pbuffer */
  5766. + gPBuffer = MakePbuffer( gDpy, gScreen, width, height );
  5767. + if (gPBuffer==None) {
  5768. + printf("Error: couldn't create pbuffer\n");
  5769. + XCloseDisplay(gDpy);
  5770. + return 0;
  5771. + }
  5772. +
  5773. + /* Create GLX context */
  5774. + glCtx = glXCreateNewContext(gDpy, gFBconfig, GLX_RGBA_TYPE, NULL, True);
  5775. + if (glCtx) {
  5776. + if (!glXIsDirect(gDpy, glCtx)) {
  5777. + printf("Warning: using indirect GLXContext\n");
  5778. + }
  5779. + }
  5780. + else {
  5781. + printf("Error: Couldn't create GLXContext\n");
  5782. + XCloseDisplay(gDpy);
  5783. + return 0;
  5784. + }
  5785. +
  5786. + /* Bind context to pbuffer */
  5787. + if (!glXMakeCurrent(gDpy, gPBuffer, glCtx)) {
  5788. + printf("Error: glXMakeCurrent failed\n");
  5789. + XCloseDisplay(gDpy);
  5790. + return 0;
  5791. + }
  5792. +
  5793. + return 1; /* Success!! */
  5794. +#else
  5795. + printf("Error: GLX version 1.3 or 1.4 not available at compile time\n");
  5796. + return 0;
  5797. +#endif
  5798. +}
  5799. +
  5800. +
  5801. +
  5802. +/* One-time GL setup */
  5803. +static void
  5804. +InitGL(void)
  5805. +{
  5806. + static GLfloat pos[4] = {0.0, 0.0, 10.0, 0.0};
  5807. + glEnable(GL_LIGHTING);
  5808. + glEnable(GL_LIGHT0);
  5809. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  5810. + glEnable(GL_NORMALIZE);
  5811. + glEnable(GL_DEPTH_TEST);
  5812. + glEnable(GL_CULL_FACE);
  5813. +
  5814. + glViewport(0, 0, gWidth, gHeight);
  5815. + glMatrixMode( GL_PROJECTION );
  5816. + glLoadIdentity();
  5817. + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  5818. + glMatrixMode( GL_MODELVIEW );
  5819. + glLoadIdentity();
  5820. + glTranslatef( 0.0, 0.0, -15.0 );
  5821. +
  5822. +}
  5823. +
  5824. +
  5825. +/* Return random float in [0,1] */
  5826. +static float
  5827. +Random(void)
  5828. +{
  5829. + int i = rand();
  5830. + return (float) (i % 1000) / 1000.0;
  5831. +}
  5832. +
  5833. +
  5834. +static void
  5835. +RandomColor(void)
  5836. +{
  5837. + GLfloat c[4];
  5838. + c[0] = Random();
  5839. + c[1] = Random();
  5840. + c[2] = Random();
  5841. + c[3] = 1.0;
  5842. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c);
  5843. +}
  5844. +
  5845. +
  5846. +/* This function borrowed from Mark Kilgard's GLUT */
  5847. +static void
  5848. +drawBox(GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1,
  5849. + GLfloat z0, GLfloat z1, GLenum type)
  5850. +{
  5851. + static GLfloat n[6][3] =
  5852. + {
  5853. + {-1.0, 0.0, 0.0},
  5854. + {0.0, 1.0, 0.0},
  5855. + {1.0, 0.0, 0.0},
  5856. + {0.0, -1.0, 0.0},
  5857. + {0.0, 0.0, 1.0},
  5858. + {0.0, 0.0, -1.0}
  5859. + };
  5860. + static GLint faces[6][4] =
  5861. + {
  5862. + {0, 1, 2, 3},
  5863. + {3, 2, 6, 7},
  5864. + {7, 6, 5, 4},
  5865. + {4, 5, 1, 0},
  5866. + {5, 6, 2, 1},
  5867. + {7, 4, 0, 3}
  5868. + };
  5869. + GLfloat v[8][3], tmp;
  5870. + GLint i;
  5871. +
  5872. + if (x0 > x1) {
  5873. + tmp = x0;
  5874. + x0 = x1;
  5875. + x1 = tmp;
  5876. + }
  5877. + if (y0 > y1) {
  5878. + tmp = y0;
  5879. + y0 = y1;
  5880. + y1 = tmp;
  5881. + }
  5882. + if (z0 > z1) {
  5883. + tmp = z0;
  5884. + z0 = z1;
  5885. + z1 = tmp;
  5886. + }
  5887. + v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0;
  5888. + v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1;
  5889. + v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
  5890. + v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
  5891. + v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0;
  5892. + v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1;
  5893. +
  5894. + for (i = 0; i < 6; i++) {
  5895. + glBegin(type);
  5896. + glNormal3fv(&n[i][0]);
  5897. + glVertex3fv(&v[faces[i][0]][0]);
  5898. + glVertex3fv(&v[faces[i][1]][0]);
  5899. + glVertex3fv(&v[faces[i][2]][0]);
  5900. + glVertex3fv(&v[faces[i][3]][0]);
  5901. + glEnd();
  5902. + }
  5903. +}
  5904. +
  5905. +
  5906. +
  5907. +/* Render a scene */
  5908. +static void
  5909. +Render(void)
  5910. +{
  5911. + int NumBoxes = 100;
  5912. + int i;
  5913. +
  5914. + InitGL();
  5915. + glClearColor(0.2, 0.2, 0.9, 0.0);
  5916. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  5917. +
  5918. + for (i=0;i<NumBoxes;i++) {
  5919. + float tx = -2.0 + 4.0 * Random();
  5920. + float ty = -2.0 + 4.0 * Random();
  5921. + float tz = 4.0 - 16.0 * Random();
  5922. + float sx = 0.1 + Random() * 0.4;
  5923. + float sy = 0.1 + Random() * 0.4;
  5924. + float sz = 0.1 + Random() * 0.4;
  5925. + float rx = Random();
  5926. + float ry = Random();
  5927. + float rz = Random();
  5928. + float ra = Random() * 360.0;
  5929. + glPushMatrix();
  5930. + glTranslatef(tx, ty, tz);
  5931. + glRotatef(ra, rx, ry, rz);
  5932. + glScalef(sx, sy, sz);
  5933. + RandomColor();
  5934. + drawBox(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, GL_POLYGON);
  5935. + glPopMatrix();
  5936. + }
  5937. +
  5938. + glFinish();
  5939. +}
  5940. +
  5941. +
  5942. +
  5943. +static void
  5944. +WriteFile(const char *filename)
  5945. +{
  5946. + FILE *f;
  5947. + GLubyte *image;
  5948. + int i;
  5949. +
  5950. + image = malloc(gWidth * gHeight * 3 * sizeof(GLubyte));
  5951. + if (!image) {
  5952. + printf("Error: couldn't allocate image buffer\n");
  5953. + return;
  5954. + }
  5955. +
  5956. + glPixelStorei(GL_PACK_ALIGNMENT, 1);
  5957. + glReadPixels(0, 0, gWidth, gHeight, GL_RGB, GL_UNSIGNED_BYTE, image);
  5958. +
  5959. + f = fopen(filename, "w");
  5960. + if (!f) {
  5961. + printf("Couldn't open image file: %s\n", filename);
  5962. + return;
  5963. + }
  5964. + fprintf(f,"P6\n");
  5965. + fprintf(f,"# ppm-file created by %s\n", "trdemo2");
  5966. + fprintf(f,"%i %i\n", gWidth, gHeight);
  5967. + fprintf(f,"255\n");
  5968. + fclose(f);
  5969. + f = fopen(filename, "ab"); /* now append binary data */
  5970. + if (!f) {
  5971. + printf("Couldn't append to image file: %s\n", filename);
  5972. + return;
  5973. + }
  5974. +
  5975. + for (i=0;i<gHeight;i++) {
  5976. + GLubyte *rowPtr;
  5977. + /* Remember, OpenGL images are bottom to top. Have to reverse. */
  5978. + rowPtr = image + (gHeight-1-i) * gWidth*3;
  5979. + fwrite(rowPtr, 1, gWidth*3, f);
  5980. + }
  5981. +
  5982. + fclose(f);
  5983. + free(image);
  5984. +
  5985. + printf("Wrote %d by %d image file: %s\n", gWidth, gHeight, filename);
  5986. +}
  5987. +
  5988. +
  5989. +
  5990. +/*
  5991. + * Print message describing command line parameters.
  5992. + */
  5993. +static void
  5994. +Usage(const char *appName)
  5995. +{
  5996. + printf("Usage:\n");
  5997. + printf(" %s width height imgfile\n", appName);
  5998. + printf("Where imgfile is a ppm file\n");
  5999. +}
  6000. +
  6001. +
  6002. +
  6003. +int
  6004. +main(int argc, char *argv[])
  6005. +{
  6006. + if (argc!=4) {
  6007. + Usage(argv[0]);
  6008. + }
  6009. + else {
  6010. + int width = atoi(argv[1]);
  6011. + int height = atoi(argv[2]);
  6012. + char *fileName = argv[3];
  6013. + if (width<=0) {
  6014. + printf("Error: width parameter must be at least 1.\n");
  6015. + return 1;
  6016. + }
  6017. + if (height<=0) {
  6018. + printf("Error: height parameter must be at least 1.\n");
  6019. + return 1;
  6020. + }
  6021. + if (!Setup(width, height)) {
  6022. + return 1;
  6023. + }
  6024. +
  6025. + printf("Setup completed\n");
  6026. + Render();
  6027. + printf("Render completed.\n");
  6028. + WriteFile(fileName);
  6029. + printf("File write completed.\n");
  6030. +
  6031. + glXDestroyPbuffer( gDpy, gPBuffer );
  6032. + }
  6033. + return 0;
  6034. +}
  6035. +
  6036. diff -Naurp Mesa-7.8.1/progs/xdemos/glxpixmap.c Mesa-7.8.1.patched/progs/xdemos/glxpixmap.c
  6037. --- Mesa-7.8.1/progs/xdemos/glxpixmap.c 1970-01-01 01:00:00.000000000 +0100
  6038. +++ Mesa-7.8.1.patched/progs/xdemos/glxpixmap.c 2010-06-13 13:45:06.788792936 +0200
  6039. @@ -0,0 +1,187 @@
  6040. +
  6041. +
  6042. +/*
  6043. + * A demonstration of using the GLXPixmap functions. This program is in
  6044. + * the public domain.
  6045. + *
  6046. + * Brian Paul
  6047. + */
  6048. +
  6049. +
  6050. +#include <GL/gl.h>
  6051. +#define GLX_GLXEXT_PROTOTYPES
  6052. +#include <GL/glx.h>
  6053. +#include <stdio.h>
  6054. +#include <stdlib.h>
  6055. +#include <string.h>
  6056. +
  6057. +
  6058. +static GLXContext ctx;
  6059. +static XVisualInfo *visinfo;
  6060. +static GC gc;
  6061. +
  6062. +
  6063. +
  6064. +static Window make_rgb_window( Display *dpy,
  6065. + unsigned int width, unsigned int height )
  6066. +{
  6067. + const int sbAttrib[] = { GLX_RGBA,
  6068. + GLX_RED_SIZE, 1,
  6069. + GLX_GREEN_SIZE, 1,
  6070. + GLX_BLUE_SIZE, 1,
  6071. + None };
  6072. + const int dbAttrib[] = { GLX_RGBA,
  6073. + GLX_RED_SIZE, 1,
  6074. + GLX_GREEN_SIZE, 1,
  6075. + GLX_BLUE_SIZE, 1,
  6076. + GLX_DOUBLEBUFFER,
  6077. + None };
  6078. + int scrnum;
  6079. + XSetWindowAttributes attr;
  6080. + unsigned long mask;
  6081. + Window root;
  6082. + Window win;
  6083. +
  6084. + scrnum = DefaultScreen( dpy );
  6085. + root = RootWindow( dpy, scrnum );
  6086. +
  6087. + visinfo = glXChooseVisual( dpy, scrnum, (int *) sbAttrib );
  6088. + if (!visinfo) {
  6089. + visinfo = glXChooseVisual( dpy, scrnum, (int *) dbAttrib );
  6090. + if (!visinfo) {
  6091. + printf("Error: couldn't get an RGB visual\n");
  6092. + exit(1);
  6093. + }
  6094. + }
  6095. +
  6096. + /* window attributes */
  6097. + attr.background_pixel = 0;
  6098. + attr.border_pixel = 0;
  6099. + /* TODO: share root colormap if possible */
  6100. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  6101. + attr.event_mask = StructureNotifyMask | ExposureMask;
  6102. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  6103. +
  6104. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  6105. + 0, visinfo->depth, InputOutput,
  6106. + visinfo->visual, mask, &attr );
  6107. +
  6108. + /* make an X GC so we can do XCopyArea later */
  6109. + gc = XCreateGC( dpy, win, 0, NULL );
  6110. +
  6111. + /* need indirect context */
  6112. + ctx = glXCreateContext( dpy, visinfo, NULL, False );
  6113. + if (!ctx) {
  6114. + printf("Error: glXCreateContext failed\n");
  6115. + exit(-1);
  6116. + }
  6117. +
  6118. + printf("Direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
  6119. +
  6120. + return win;
  6121. +}
  6122. +
  6123. +
  6124. +static GLXPixmap make_pixmap( Display *dpy, Window win,
  6125. + unsigned int width, unsigned int height,
  6126. + Pixmap *pixmap)
  6127. +{
  6128. + Pixmap pm;
  6129. + GLXPixmap glxpm;
  6130. + XWindowAttributes attr;
  6131. +
  6132. + pm = XCreatePixmap( dpy, win, width, height, visinfo->depth );
  6133. + if (!pm) {
  6134. + printf("Error: XCreatePixmap failed\n");
  6135. + exit(-1);
  6136. + }
  6137. +
  6138. + XGetWindowAttributes( dpy, win, &attr );
  6139. +
  6140. + /*
  6141. + * IMPORTANT:
  6142. + * Use the glXCreateGLXPixmapMESA funtion when using Mesa because
  6143. + * Mesa needs to know the colormap associated with a pixmap in order
  6144. + * to render correctly. This is because Mesa allows RGB rendering
  6145. + * into any kind of visual, not just TrueColor or DirectColor.
  6146. + */
  6147. +#ifdef GLX_MESA_pixmap_colormap
  6148. + if (strstr(glXQueryExtensionsString(dpy, 0), "GLX_MESA_pixmap_colormap")) {
  6149. + /* stand-alone Mesa, specify the colormap */
  6150. + glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap );
  6151. + }
  6152. + else {
  6153. + glxpm = glXCreateGLXPixmap( dpy, visinfo, pm );
  6154. + }
  6155. +#else
  6156. + /* This will work with Mesa too if the visual is TrueColor or DirectColor */
  6157. + glxpm = glXCreateGLXPixmap( dpy, visinfo, pm );
  6158. +#endif
  6159. +
  6160. + if (!glxpm) {
  6161. + printf("Error: GLXCreateGLXPixmap failed\n");
  6162. + exit(-1);
  6163. + }
  6164. +
  6165. + *pixmap = pm;
  6166. +
  6167. + return glxpm;
  6168. +}
  6169. +
  6170. +
  6171. +
  6172. +static void event_loop( Display *dpy, GLXPixmap pm )
  6173. +{
  6174. + XEvent event;
  6175. +
  6176. + while (1) {
  6177. + XNextEvent( dpy, &event );
  6178. +
  6179. + switch (event.type) {
  6180. + case Expose:
  6181. + printf("Redraw\n");
  6182. + /* copy the image from GLXPixmap to window */
  6183. + XCopyArea( dpy, pm, event.xany.window, /* src, dest */
  6184. + gc, 0, 0, 300, 300, /* gc, src pos, size */
  6185. + 0, 0 ); /* dest pos */
  6186. + break;
  6187. + case ConfigureNotify:
  6188. + /* nothing */
  6189. + break;
  6190. + }
  6191. + }
  6192. +}
  6193. +
  6194. +
  6195. +
  6196. +int main( int argc, char *argv[] )
  6197. +{
  6198. + Display *dpy;
  6199. + Window win;
  6200. + Pixmap pm;
  6201. + GLXPixmap glxpm;
  6202. +
  6203. + dpy = XOpenDisplay(NULL);
  6204. +
  6205. + win = make_rgb_window( dpy, 300, 300 );
  6206. + glxpm = make_pixmap( dpy, win, 300, 300, &pm );
  6207. +
  6208. + glXMakeCurrent( dpy, glxpm, ctx );
  6209. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  6210. +
  6211. + /* Render an image into the pixmap */
  6212. + glShadeModel( GL_FLAT );
  6213. + glClearColor( 0.5, 0.5, 0.5, 1.0 );
  6214. + glClear( GL_COLOR_BUFFER_BIT );
  6215. + glViewport( 0, 0, 300, 300 );
  6216. + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
  6217. + glColor3f( 0.0, 1.0, 1.0 );
  6218. + glRectf( -0.75, -0.75, 0.75, 0.75 );
  6219. + glFlush();
  6220. + glXWaitGL();
  6221. +
  6222. + XMapWindow( dpy, win );
  6223. +
  6224. + event_loop( dpy, pm );
  6225. + return 0;
  6226. +}
  6227. diff -Naurp Mesa-7.8.1/progs/xdemos/glxsnoop.c Mesa-7.8.1.patched/progs/xdemos/glxsnoop.c
  6228. --- Mesa-7.8.1/progs/xdemos/glxsnoop.c 1970-01-01 01:00:00.000000000 +0100
  6229. +++ Mesa-7.8.1.patched/progs/xdemos/glxsnoop.c 2010-06-13 13:45:06.788792936 +0200
  6230. @@ -0,0 +1,377 @@
  6231. +/**
  6232. + * Display/snoop the z/stencil/back/front buffers of another app's window.
  6233. + * Also, an example of the need for shared ancillary renderbuffers.
  6234. + *
  6235. + * Hint: use 'xwininfo' to get a window's ID.
  6236. + *
  6237. + * Brian Paul
  6238. + * 11 Oct 2007
  6239. + */
  6240. +
  6241. +#define GL_GLEXT_PROTOTYPES
  6242. +
  6243. +#include <GL/gl.h>
  6244. +#include <GL/glx.h>
  6245. +#include <stdio.h>
  6246. +#include <stdlib.h>
  6247. +#include <string.h>
  6248. +#include <X11/keysym.h>
  6249. +
  6250. +
  6251. +#define Z_BUFFER 1
  6252. +#define STENCIL_BUFFER 2
  6253. +#define BACK_BUFFER 3
  6254. +#define FRONT_BUFFER 4
  6255. +
  6256. +
  6257. +static int Buffer = BACK_BUFFER;
  6258. +static int WindowID = 0;
  6259. +static const char *DisplayName = NULL;
  6260. +static GLXContext Context = 0;
  6261. +static int Width, Height;
  6262. +
  6263. +
  6264. +/**
  6265. + * Grab the z/stencil/back/front image from the srcWin and display it
  6266. + * (possibly converted to grayscale) in the dstWin.
  6267. + */
  6268. +static void
  6269. +redraw(Display *dpy, Window srcWin, Window dstWin )
  6270. +{
  6271. + GLubyte *image = malloc(Width * Height * 4);
  6272. +
  6273. + glXMakeCurrent(dpy, srcWin, Context);
  6274. + glPixelStorei(GL_PACK_ALIGNMENT, 1);
  6275. + if (Buffer == BACK_BUFFER) {
  6276. + glReadBuffer(GL_BACK);
  6277. + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
  6278. + }
  6279. + else if (Buffer == FRONT_BUFFER) {
  6280. + glReadBuffer(GL_FRONT);
  6281. + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
  6282. + }
  6283. + else if (Buffer == Z_BUFFER) {
  6284. + GLfloat *z = malloc(Width * Height * sizeof(GLfloat));
  6285. + int i;
  6286. + glReadPixels(0, 0, Width, Height, GL_DEPTH_COMPONENT, GL_FLOAT, z);
  6287. + for (i = 0; i < Width * Height; i++) {
  6288. + image[i*4+0] =
  6289. + image[i*4+1] =
  6290. + image[i*4+2] = (GLint) (255.0 * z[i]);
  6291. + image[i*4+3] = 255;
  6292. + }
  6293. + free(z);
  6294. + }
  6295. + else if (Buffer == STENCIL_BUFFER) {
  6296. + GLubyte *sten = malloc(Width * Height * sizeof(GLubyte));
  6297. + int i, min = 100, max = -1;
  6298. + float step;
  6299. + int sz;
  6300. + glGetIntegerv(GL_STENCIL_BITS, &sz);
  6301. + glReadPixels(0, 0, Width, Height,
  6302. + GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, sten);
  6303. + /* find min/max for converting stencil to grayscale */
  6304. + for (i = 0; i < Width * Height; i++) {
  6305. + if (sten[i] < min)
  6306. + min = sten[i];
  6307. + if (sten[i] > max)
  6308. + max = sten[i];
  6309. + }
  6310. + if (min == max)
  6311. + step = 0;
  6312. + else
  6313. + step = 255.0 / (float) (max - min);
  6314. + for (i = 0; i < Width * Height; i++) {
  6315. + image[i*4+0] =
  6316. + image[i*4+1] =
  6317. + image[i*4+2] = (GLint) ((sten[i] - min) * step);
  6318. + image[i*4+3] = 255;
  6319. + }
  6320. + free(sten);
  6321. + }
  6322. +
  6323. + glXMakeCurrent(dpy, dstWin, Context);
  6324. + glWindowPos2iARB(0, 0);
  6325. + glDrawBuffer(GL_FRONT);
  6326. + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
  6327. + glFlush();
  6328. +
  6329. + free(image);
  6330. +}
  6331. +
  6332. +
  6333. +static void
  6334. +set_window_title(Display *dpy, Window win, const char *title)
  6335. +{
  6336. + XSizeHints sizehints;
  6337. + sizehints.flags = 0;
  6338. + XSetStandardProperties(dpy, win, title, title,
  6339. + None, (char **)NULL, 0, &sizehints);
  6340. +}
  6341. +
  6342. +
  6343. +static Window
  6344. +make_gl_window(Display *dpy, XVisualInfo *visinfo, int width, int height)
  6345. +{
  6346. + int scrnum;
  6347. + XSetWindowAttributes attr;
  6348. + unsigned long mask;
  6349. + Window root;
  6350. + Window win;
  6351. + int x = 0, y = 0;
  6352. + char *name = NULL;
  6353. +
  6354. + scrnum = DefaultScreen( dpy );
  6355. + root = RootWindow( dpy, scrnum );
  6356. +
  6357. + /* window attributes */
  6358. + attr.background_pixel = 0;
  6359. + attr.border_pixel = 0;
  6360. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  6361. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  6362. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  6363. +
  6364. + win = XCreateWindow( dpy, root, x, y, width, height,
  6365. + 0, visinfo->depth, InputOutput,
  6366. + visinfo->visual, mask, &attr );
  6367. +
  6368. + /* set hints and properties */
  6369. + {
  6370. + XSizeHints sizehints;
  6371. + sizehints.x = x;
  6372. + sizehints.y = y;
  6373. + sizehints.width = width;
  6374. + sizehints.height = height;
  6375. + sizehints.flags = USSize | USPosition;
  6376. + XSetNormalHints(dpy, win, &sizehints);
  6377. + XSetStandardProperties(dpy, win, name, name,
  6378. + None, (char **)NULL, 0, &sizehints);
  6379. + }
  6380. +
  6381. + return win;
  6382. +}
  6383. +
  6384. +
  6385. +static void
  6386. +update_window_title(Display *dpy, Window win)
  6387. +{
  6388. + char title[1000], *buf;
  6389. +
  6390. + switch (Buffer) {
  6391. + case Z_BUFFER:
  6392. + buf = "Z";
  6393. + break;
  6394. + case STENCIL_BUFFER:
  6395. + buf = "Stencil";
  6396. + break;
  6397. + case BACK_BUFFER:
  6398. + buf = "Back";
  6399. + break;
  6400. + case FRONT_BUFFER:
  6401. + buf = "Front";
  6402. + break;
  6403. + default:
  6404. + buf = "";
  6405. + }
  6406. +
  6407. + sprintf(title, "glxsnoop window 0x%x (%s buffer)", (int) WindowID, buf);
  6408. +
  6409. + set_window_title(dpy, win, title);
  6410. +}
  6411. +
  6412. +
  6413. +static void
  6414. +keypress(Display *dpy, Window win, char key)
  6415. +{
  6416. + switch (key) {
  6417. + case 27:
  6418. + /* escape */
  6419. + exit(0);
  6420. + break;
  6421. + case 's':
  6422. + Buffer = STENCIL_BUFFER;
  6423. + break;
  6424. + case 'z':
  6425. + Buffer = Z_BUFFER;
  6426. + break;
  6427. + case 'f':
  6428. + Buffer = FRONT_BUFFER;
  6429. + break;
  6430. + case 'b':
  6431. + Buffer = BACK_BUFFER;
  6432. + break;
  6433. + default:
  6434. + return;
  6435. + }
  6436. +
  6437. + update_window_title(dpy, win);
  6438. + redraw(dpy, WindowID, win);
  6439. +}
  6440. +
  6441. +
  6442. +static void
  6443. +event_loop(Display *dpy, Window win)
  6444. +{
  6445. + XEvent event;
  6446. +
  6447. + while (1) {
  6448. + XNextEvent( dpy, &event );
  6449. +
  6450. + switch (event.type) {
  6451. + case Expose:
  6452. + redraw(dpy, WindowID, win);
  6453. + break;
  6454. + case ConfigureNotify:
  6455. + /*resize( event.xconfigure.width, event.xconfigure.height );*/
  6456. + break;
  6457. + case KeyPress:
  6458. + {
  6459. + char buffer[10];
  6460. + int r, code;
  6461. + code = XLookupKeysym(&event.xkey, 0);
  6462. + if (code == XK_Left) {
  6463. + }
  6464. + else {
  6465. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  6466. + NULL, NULL);
  6467. + keypress(dpy, win, buffer[0]);
  6468. + }
  6469. + }
  6470. + default:
  6471. + /* nothing */
  6472. + ;
  6473. + }
  6474. + }
  6475. +}
  6476. +
  6477. +
  6478. +static VisualID
  6479. +get_window_visualid(Display *dpy, Window win)
  6480. +{
  6481. + XWindowAttributes attr;
  6482. +
  6483. + if (XGetWindowAttributes(dpy, win, &attr)) {
  6484. + return attr.visual->visualid;
  6485. + }
  6486. + else {
  6487. + return 0;
  6488. + }
  6489. +}
  6490. +
  6491. +
  6492. +static void
  6493. +get_window_size(Display *dpy, Window win, int *w, int *h)
  6494. +{
  6495. + XWindowAttributes attr;
  6496. +
  6497. + if (XGetWindowAttributes(dpy, win, &attr)) {
  6498. + *w = attr.width;
  6499. + *h = attr.height;
  6500. + }
  6501. + else {
  6502. + *w = *h = 0;
  6503. + }
  6504. +}
  6505. +
  6506. +
  6507. +static XVisualInfo *
  6508. +visualid_to_visualinfo(Display *dpy, VisualID vid)
  6509. +{
  6510. + XVisualInfo *vinfo, templ;
  6511. + long mask;
  6512. + int n;
  6513. +
  6514. + templ.visualid = vid;
  6515. + mask = VisualIDMask;
  6516. +
  6517. + vinfo = XGetVisualInfo(dpy, mask, &templ, &n);
  6518. + return vinfo;
  6519. +}
  6520. +
  6521. +
  6522. +static void
  6523. +key_usage(void)
  6524. +{
  6525. + printf("Keyboard:\n");
  6526. + printf(" z - display Z buffer\n");
  6527. + printf(" s - display stencil buffer\n");
  6528. + printf(" f - display front color buffer\n");
  6529. + printf(" b - display back buffer\n");
  6530. +}
  6531. +
  6532. +
  6533. +static void
  6534. +usage(void)
  6535. +{
  6536. + printf("Usage: glxsnoop [-display dpy] windowID\n");
  6537. + key_usage();
  6538. +}
  6539. +
  6540. +
  6541. +static void
  6542. +parse_opts(int argc, char *argv[])
  6543. +{
  6544. + int i;
  6545. +
  6546. + for (i = 1; i < argc; i++) {
  6547. + if (strcmp(argv[i], "-h") == 0) {
  6548. + usage();
  6549. + exit(0);
  6550. + }
  6551. + else if (strcmp(argv[i], "-display") == 0) {
  6552. + DisplayName = argv[i + 1];
  6553. + i++;
  6554. + }
  6555. + else {
  6556. + if (argv[i][0] == '0' && argv[i][1] == 'x') {
  6557. + /* hex */
  6558. + WindowID = strtol(argv[i], NULL, 16);
  6559. + }
  6560. + else {
  6561. + WindowID = atoi(argv[i]);
  6562. + }
  6563. + break;
  6564. + }
  6565. + }
  6566. +
  6567. + if (!WindowID) {
  6568. + usage();
  6569. + exit(0);
  6570. + }
  6571. +}
  6572. +
  6573. +
  6574. +int
  6575. +main( int argc, char *argv[] )
  6576. +{
  6577. + Display *dpy;
  6578. + VisualID vid;
  6579. + XVisualInfo *visinfo;
  6580. + Window win;
  6581. +
  6582. + parse_opts(argc, argv);
  6583. +
  6584. + key_usage();
  6585. +
  6586. + dpy = XOpenDisplay(DisplayName);
  6587. +
  6588. + /* find the VisualID for the named window */
  6589. + vid = get_window_visualid(dpy, WindowID);
  6590. + get_window_size(dpy, WindowID, &Width, &Height);
  6591. +
  6592. + visinfo = visualid_to_visualinfo(dpy, vid);
  6593. +
  6594. + Context = glXCreateContext( dpy, visinfo, NULL, True );
  6595. + if (!Context) {
  6596. + printf("Error: glXCreateContext failed\n");
  6597. + exit(1);
  6598. + }
  6599. +
  6600. + win = make_gl_window(dpy, visinfo, Width, Height);
  6601. + XMapWindow(dpy, win);
  6602. + update_window_title(dpy, win);
  6603. +
  6604. + event_loop( dpy, win );
  6605. +
  6606. + return 0;
  6607. +}
  6608. diff -Naurp Mesa-7.8.1/progs/xdemos/glxswapcontrol.c Mesa-7.8.1.patched/progs/xdemos/glxswapcontrol.c
  6609. --- Mesa-7.8.1/progs/xdemos/glxswapcontrol.c 1970-01-01 01:00:00.000000000 +0100
  6610. +++ Mesa-7.8.1.patched/progs/xdemos/glxswapcontrol.c 2010-06-13 13:45:06.788792936 +0200
  6611. @@ -0,0 +1,893 @@
  6612. +/*
  6613. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  6614. + *
  6615. + * Permission is hereby granted, free of charge, to any person obtaining a
  6616. + * copy of this software and associated documentation files (the "Software"),
  6617. + * to deal in the Software without restriction, including without limitation
  6618. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  6619. + * and/or sell copies of the Software, and to permit persons to whom the
  6620. + * Software is furnished to do so, subject to the following conditions:
  6621. + *
  6622. + * The above copyright notice and this permission notice shall be included
  6623. + * in all copies or substantial portions of the Software.
  6624. + *
  6625. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6626. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6627. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  6628. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  6629. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  6630. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  6631. + */
  6632. +
  6633. +/*
  6634. + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
  6635. + * Port by Brian Paul 23 March 2001
  6636. + *
  6637. + * Modified by Ian Romanick <idr@us.ibm.com> 09 April 2003 to support
  6638. + * GLX_{MESA,SGI}_swap_control and GLX_OML_sync_control.
  6639. + *
  6640. + * Command line options:
  6641. + * -display Name of the display to use.
  6642. + * -info print GL implementation information
  6643. + * -swap N Attempt to set the swap interval to 1/N second
  6644. + * -forcegetrate Get the display refresh rate even if the required GLX
  6645. + * extension is not supported.
  6646. + */
  6647. +
  6648. +
  6649. +#include <math.h>
  6650. +#include <stdlib.h>
  6651. +#include <stdio.h>
  6652. +#include <string.h>
  6653. +#include <X11/Xlib.h>
  6654. +#include <X11/keysym.h>
  6655. +#ifndef __VMS
  6656. +/*# include <stdint.h>*/
  6657. +#endif
  6658. +# define GLX_GLXEXT_PROTOTYPES
  6659. +#include <GL/gl.h>
  6660. +#include <GL/glx.h>
  6661. +
  6662. +#ifndef GLX_MESA_swap_control
  6663. +typedef GLint ( * PFNGLXSWAPINTERVALMESAPROC) (unsigned interval);
  6664. +typedef GLint ( * PFNGLXGETSWAPINTERVALMESAPROC) ( void );
  6665. +#endif
  6666. +
  6667. +#if !defined( GLX_OML_sync_control ) && defined( _STDINT_H )
  6668. +#define GLX_OML_sync_control 1
  6669. +typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator);
  6670. +#endif
  6671. +
  6672. +#ifndef GLX_MESA_swap_frame_usage
  6673. +#define GLX_MESA_swap_frame_usage 1
  6674. +typedef int ( * PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float * usage );
  6675. +#endif
  6676. +
  6677. +#define BENCHMARK
  6678. +
  6679. +PFNGLXGETFRAMEUSAGEMESAPROC get_frame_usage = NULL;
  6680. +
  6681. +#ifdef BENCHMARK
  6682. +
  6683. +/* XXX this probably isn't very portable */
  6684. +
  6685. +#include <sys/time.h>
  6686. +#include <unistd.h>
  6687. +
  6688. +#define NUL '\0'
  6689. +
  6690. +/* return current time (in seconds) */
  6691. +static int
  6692. +current_time(void)
  6693. +{
  6694. + struct timeval tv;
  6695. +#ifdef __VMS
  6696. + (void) gettimeofday(&tv, NULL );
  6697. +#else
  6698. + struct timezone tz;
  6699. + (void) gettimeofday(&tv, &tz);
  6700. +#endif
  6701. + return (int) tv.tv_sec;
  6702. +}
  6703. +
  6704. +#else /*BENCHMARK*/
  6705. +
  6706. +/* dummy */
  6707. +static int
  6708. +current_time(void)
  6709. +{
  6710. + return 0;
  6711. +}
  6712. +
  6713. +#endif /*BENCHMARK*/
  6714. +
  6715. +
  6716. +
  6717. +#ifndef M_PI
  6718. +#define M_PI 3.14159265
  6719. +#endif
  6720. +
  6721. +
  6722. +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  6723. +static GLint gear1, gear2, gear3;
  6724. +static GLfloat angle = 0.0;
  6725. +
  6726. +static GLboolean has_OML_sync_control = GL_FALSE;
  6727. +static GLboolean has_SGI_swap_control = GL_FALSE;
  6728. +static GLboolean has_MESA_swap_control = GL_FALSE;
  6729. +static GLboolean has_MESA_swap_frame_usage = GL_FALSE;
  6730. +
  6731. +static char ** extension_table = NULL;
  6732. +static unsigned num_extensions;
  6733. +
  6734. +static GLboolean use_ztrick = GL_FALSE;
  6735. +static GLfloat aspectX = 1.0f, aspectY = 1.0f;
  6736. +
  6737. +/*
  6738. + *
  6739. + * Draw a gear wheel. You'll probably want to call this function when
  6740. + * building a display list since we do a lot of trig here.
  6741. + *
  6742. + * Input: inner_radius - radius of hole at center
  6743. + * outer_radius - radius at center of teeth
  6744. + * width - width of gear
  6745. + * teeth - number of teeth
  6746. + * tooth_depth - depth of tooth
  6747. + */
  6748. +static void
  6749. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  6750. + GLint teeth, GLfloat tooth_depth)
  6751. +{
  6752. + GLint i;
  6753. + GLfloat r0, r1, r2;
  6754. + GLfloat angle, da;
  6755. + GLfloat u, v, len;
  6756. +
  6757. + r0 = inner_radius;
  6758. + r1 = outer_radius - tooth_depth / 2.0;
  6759. + r2 = outer_radius + tooth_depth / 2.0;
  6760. +
  6761. + da = 2.0 * M_PI / teeth / 4.0;
  6762. +
  6763. + glShadeModel(GL_FLAT);
  6764. +
  6765. + glNormal3f(0.0, 0.0, 1.0);
  6766. +
  6767. + /* draw front face */
  6768. + glBegin(GL_QUAD_STRIP);
  6769. + for (i = 0; i <= teeth; i++) {
  6770. + angle = i * 2.0 * M_PI / teeth;
  6771. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  6772. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  6773. + if (i < teeth) {
  6774. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  6775. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6776. + width * 0.5);
  6777. + }
  6778. + }
  6779. + glEnd();
  6780. +
  6781. + /* draw front sides of teeth */
  6782. + glBegin(GL_QUADS);
  6783. + da = 2.0 * M_PI / teeth / 4.0;
  6784. + for (i = 0; i < teeth; i++) {
  6785. + angle = i * 2.0 * M_PI / teeth;
  6786. +
  6787. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  6788. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  6789. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  6790. + width * 0.5);
  6791. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6792. + width * 0.5);
  6793. + }
  6794. + glEnd();
  6795. +
  6796. + glNormal3f(0.0, 0.0, -1.0);
  6797. +
  6798. + /* draw back face */
  6799. + glBegin(GL_QUAD_STRIP);
  6800. + for (i = 0; i <= teeth; i++) {
  6801. + angle = i * 2.0 * M_PI / teeth;
  6802. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  6803. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  6804. + if (i < teeth) {
  6805. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6806. + -width * 0.5);
  6807. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  6808. + }
  6809. + }
  6810. + glEnd();
  6811. +
  6812. + /* draw back sides of teeth */
  6813. + glBegin(GL_QUADS);
  6814. + da = 2.0 * M_PI / teeth / 4.0;
  6815. + for (i = 0; i < teeth; i++) {
  6816. + angle = i * 2.0 * M_PI / teeth;
  6817. +
  6818. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6819. + -width * 0.5);
  6820. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  6821. + -width * 0.5);
  6822. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  6823. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  6824. + }
  6825. + glEnd();
  6826. +
  6827. + /* draw outward faces of teeth */
  6828. + glBegin(GL_QUAD_STRIP);
  6829. + for (i = 0; i < teeth; i++) {
  6830. + angle = i * 2.0 * M_PI / teeth;
  6831. +
  6832. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  6833. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  6834. + u = r2 * cos(angle + da) - r1 * cos(angle);
  6835. + v = r2 * sin(angle + da) - r1 * sin(angle);
  6836. + len = sqrt(u * u + v * v);
  6837. + u /= len;
  6838. + v /= len;
  6839. + glNormal3f(v, -u, 0.0);
  6840. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  6841. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  6842. + glNormal3f(cos(angle), sin(angle), 0.0);
  6843. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  6844. + width * 0.5);
  6845. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  6846. + -width * 0.5);
  6847. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  6848. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  6849. + glNormal3f(v, -u, 0.0);
  6850. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6851. + width * 0.5);
  6852. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  6853. + -width * 0.5);
  6854. + glNormal3f(cos(angle), sin(angle), 0.0);
  6855. + }
  6856. +
  6857. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  6858. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  6859. +
  6860. + glEnd();
  6861. +
  6862. + glShadeModel(GL_SMOOTH);
  6863. +
  6864. + /* draw inside radius cylinder */
  6865. + glBegin(GL_QUAD_STRIP);
  6866. + for (i = 0; i <= teeth; i++) {
  6867. + angle = i * 2.0 * M_PI / teeth;
  6868. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  6869. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  6870. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  6871. + }
  6872. + glEnd();
  6873. +}
  6874. +
  6875. +
  6876. +static void
  6877. +draw(void)
  6878. +{
  6879. + if ( use_ztrick ) {
  6880. + static GLboolean flip = GL_FALSE;
  6881. + static const GLfloat vert[4][3] = {
  6882. + { -1, -1, -0.999 },
  6883. + { 1, -1, -0.999 },
  6884. + { 1, 1, -0.999 },
  6885. + { -1, 1, -0.999 }
  6886. + };
  6887. + static const GLfloat col[4][3] = {
  6888. + { 1.0, 0.6, 0.0 },
  6889. + { 1.0, 0.6, 0.0 },
  6890. + { 0.0, 0.0, 0.0 },
  6891. + { 0.0, 0.0, 0.0 },
  6892. + };
  6893. +
  6894. + if ( flip ) {
  6895. + glDepthRange(0, 0.5);
  6896. + glDepthFunc(GL_LEQUAL);
  6897. + }
  6898. + else {
  6899. + glDepthRange(1.0, 0.4999);
  6900. + glDepthFunc(GL_GEQUAL);
  6901. + }
  6902. +
  6903. + flip = !flip;
  6904. +
  6905. + /* The famous Quake "Z trick" only works when the whole screen is
  6906. + * re-drawn each frame.
  6907. + */
  6908. +
  6909. + glMatrixMode(GL_MODELVIEW);
  6910. + glLoadIdentity();
  6911. + glMatrixMode(GL_PROJECTION);
  6912. + glLoadIdentity();
  6913. + glOrtho(-1, 1, -1, 1, -1, 1);
  6914. + glDisable(GL_LIGHTING);
  6915. + glShadeModel(GL_SMOOTH);
  6916. +
  6917. + glEnableClientState( GL_VERTEX_ARRAY );
  6918. + glEnableClientState( GL_COLOR_ARRAY );
  6919. + glVertexPointer( 3, GL_FLOAT, 0, vert );
  6920. + glColorPointer( 3, GL_FLOAT, 0, col );
  6921. + glDrawArrays( GL_POLYGON, 0, 4 );
  6922. + glDisableClientState( GL_COLOR_ARRAY );
  6923. + glDisableClientState( GL_VERTEX_ARRAY );
  6924. +
  6925. + glMatrixMode(GL_PROJECTION);
  6926. + glLoadIdentity();
  6927. + glFrustum(-aspectX, aspectX, -aspectY, aspectY, 5.0, 60.0);
  6928. +
  6929. + glEnable(GL_LIGHTING);
  6930. +
  6931. + glMatrixMode(GL_MODELVIEW);
  6932. + glLoadIdentity();
  6933. + glTranslatef(0.0, 0.0, -45.0);
  6934. + }
  6935. + else {
  6936. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  6937. + }
  6938. +
  6939. + glPushMatrix();
  6940. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  6941. + glRotatef(view_roty, 0.0, 1.0, 0.0);
  6942. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  6943. +
  6944. + glPushMatrix();
  6945. + glTranslatef(-3.0, -2.0, 0.0);
  6946. + glRotatef(angle, 0.0, 0.0, 1.0);
  6947. + glCallList(gear1);
  6948. + glPopMatrix();
  6949. +
  6950. + glPushMatrix();
  6951. + glTranslatef(3.1, -2.0, 0.0);
  6952. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  6953. + glCallList(gear2);
  6954. + glPopMatrix();
  6955. +
  6956. + glPushMatrix();
  6957. + glTranslatef(-3.1, 4.2, 0.0);
  6958. + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  6959. + glCallList(gear3);
  6960. + glPopMatrix();
  6961. +
  6962. + glPopMatrix();
  6963. +}
  6964. +
  6965. +
  6966. +/* new window size or exposure */
  6967. +static void
  6968. +reshape(int width, int height)
  6969. +{
  6970. + if (width > height) {
  6971. + aspectX = (GLfloat) width / (GLfloat) height;
  6972. + aspectY = 1.0;
  6973. + }
  6974. + else {
  6975. + aspectX = 1.0;
  6976. + aspectY = (GLfloat) height / (GLfloat) width;
  6977. + }
  6978. +
  6979. + glViewport(0, 0, (GLint) width, (GLint) height);
  6980. + glMatrixMode(GL_PROJECTION);
  6981. + glLoadIdentity();
  6982. +
  6983. + glFrustum(-aspectX, aspectX, -aspectY, aspectY, 5.0, 60.0);
  6984. + glMatrixMode(GL_MODELVIEW);
  6985. + glLoadIdentity();
  6986. + glTranslatef(0.0, 0.0, -45.0);
  6987. +}
  6988. +
  6989. +
  6990. +static void
  6991. +init(void)
  6992. +{
  6993. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  6994. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  6995. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  6996. + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  6997. +
  6998. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  6999. + glEnable(GL_CULL_FACE);
  7000. + glEnable(GL_LIGHTING);
  7001. + glEnable(GL_LIGHT0);
  7002. + glEnable(GL_DEPTH_TEST);
  7003. +
  7004. + /* make the gears */
  7005. + gear1 = glGenLists(1);
  7006. + glNewList(gear1, GL_COMPILE);
  7007. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  7008. + gear(1.0, 4.0, 1.0, 20, 0.7);
  7009. + glEndList();
  7010. +
  7011. + gear2 = glGenLists(1);
  7012. + glNewList(gear2, GL_COMPILE);
  7013. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  7014. + gear(0.5, 2.0, 2.0, 10, 0.7);
  7015. + glEndList();
  7016. +
  7017. + gear3 = glGenLists(1);
  7018. + glNewList(gear3, GL_COMPILE);
  7019. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  7020. + gear(1.3, 2.0, 0.5, 10, 0.7);
  7021. + glEndList();
  7022. +
  7023. + glEnable(GL_NORMALIZE);
  7024. +}
  7025. +
  7026. +
  7027. +/**
  7028. + * Remove window border/decorations.
  7029. + */
  7030. +static void
  7031. +no_border( Display *dpy, Window w)
  7032. +{
  7033. + static const unsigned MWM_HINTS_DECORATIONS = (1 << 1);
  7034. + static const int PROP_MOTIF_WM_HINTS_ELEMENTS = 5;
  7035. +
  7036. + typedef struct
  7037. + {
  7038. + unsigned long flags;
  7039. + unsigned long functions;
  7040. + unsigned long decorations;
  7041. + long inputMode;
  7042. + unsigned long status;
  7043. + } PropMotifWmHints;
  7044. +
  7045. + PropMotifWmHints motif_hints;
  7046. + Atom prop, proptype;
  7047. + unsigned long flags = 0;
  7048. +
  7049. + /* setup the property */
  7050. + motif_hints.flags = MWM_HINTS_DECORATIONS;
  7051. + motif_hints.decorations = flags;
  7052. +
  7053. + /* get the atom for the property */
  7054. + prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True );
  7055. + if (!prop) {
  7056. + /* something went wrong! */
  7057. + return;
  7058. + }
  7059. +
  7060. + /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */
  7061. + proptype = prop;
  7062. +
  7063. + XChangeProperty( dpy, w, /* display, window */
  7064. + prop, proptype, /* property, type */
  7065. + 32, /* format: 32-bit datums */
  7066. + PropModeReplace, /* mode */
  7067. + (unsigned char *) &motif_hints, /* data */
  7068. + PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */
  7069. + );
  7070. +}
  7071. +
  7072. +
  7073. +/*
  7074. + * Create an RGB, double-buffered window.
  7075. + * Return the window and context handles.
  7076. + */
  7077. +static void
  7078. +make_window( Display *dpy, const char *name,
  7079. + int x, int y, int width, int height, GLboolean fullscreen,
  7080. + Window *winRet, GLXContext *ctxRet)
  7081. +{
  7082. + int attrib[] = { GLX_RGBA,
  7083. + GLX_RED_SIZE, 1,
  7084. + GLX_GREEN_SIZE, 1,
  7085. + GLX_BLUE_SIZE, 1,
  7086. + GLX_DOUBLEBUFFER,
  7087. + GLX_DEPTH_SIZE, 1,
  7088. + None };
  7089. + int scrnum;
  7090. + XSetWindowAttributes attr;
  7091. + unsigned long mask;
  7092. + Window root;
  7093. + Window win;
  7094. + GLXContext ctx;
  7095. + XVisualInfo *visinfo;
  7096. +
  7097. + scrnum = DefaultScreen( dpy );
  7098. + root = RootWindow( dpy, scrnum );
  7099. +
  7100. + if (fullscreen) {
  7101. + x = y = 0;
  7102. + width = DisplayWidth( dpy, scrnum );
  7103. + height = DisplayHeight( dpy, scrnum );
  7104. + }
  7105. +
  7106. + visinfo = glXChooseVisual( dpy, scrnum, attrib );
  7107. + if (!visinfo) {
  7108. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  7109. + exit(1);
  7110. + }
  7111. +
  7112. + /* window attributes */
  7113. + attr.background_pixel = 0;
  7114. + attr.border_pixel = 0;
  7115. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  7116. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  7117. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  7118. +
  7119. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  7120. + 0, visinfo->depth, InputOutput,
  7121. + visinfo->visual, mask, &attr );
  7122. +
  7123. + /* set hints and properties */
  7124. + {
  7125. + XSizeHints sizehints;
  7126. + sizehints.x = x;
  7127. + sizehints.y = y;
  7128. + sizehints.width = width;
  7129. + sizehints.height = height;
  7130. + sizehints.flags = USSize | USPosition;
  7131. + XSetNormalHints(dpy, win, &sizehints);
  7132. + XSetStandardProperties(dpy, win, name, name,
  7133. + None, (char **)NULL, 0, &sizehints);
  7134. + }
  7135. +
  7136. + if (fullscreen)
  7137. + no_border(dpy, win);
  7138. +
  7139. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  7140. + if (!ctx) {
  7141. + printf("Error: glXCreateContext failed\n");
  7142. + exit(1);
  7143. + }
  7144. +
  7145. + XFree(visinfo);
  7146. +
  7147. + *winRet = win;
  7148. + *ctxRet = ctx;
  7149. +}
  7150. +
  7151. +
  7152. +static void
  7153. +event_loop(Display *dpy, Window win)
  7154. +{
  7155. + float frame_usage = 0.0;
  7156. +
  7157. + while (1) {
  7158. + while (XPending(dpy) > 0) {
  7159. + XEvent event;
  7160. + XNextEvent(dpy, &event);
  7161. + switch (event.type) {
  7162. + case Expose:
  7163. + /* we'll redraw below */
  7164. + break;
  7165. + case ConfigureNotify:
  7166. + reshape(event.xconfigure.width, event.xconfigure.height);
  7167. + break;
  7168. + case KeyPress:
  7169. + {
  7170. + char buffer[10];
  7171. + int r, code;
  7172. + code = XLookupKeysym(&event.xkey, 0);
  7173. + if (code == XK_Left) {
  7174. + view_roty += 5.0;
  7175. + }
  7176. + else if (code == XK_Right) {
  7177. + view_roty -= 5.0;
  7178. + }
  7179. + else if (code == XK_Up) {
  7180. + view_rotx += 5.0;
  7181. + }
  7182. + else if (code == XK_Down) {
  7183. + view_rotx -= 5.0;
  7184. + }
  7185. + else {
  7186. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  7187. + NULL, NULL);
  7188. + if (buffer[0] == 27) {
  7189. + /* escape */
  7190. + return;
  7191. + }
  7192. + }
  7193. + }
  7194. + }
  7195. + }
  7196. +
  7197. + /* next frame */
  7198. + angle += 2.0;
  7199. +
  7200. + draw();
  7201. +
  7202. + glXSwapBuffers(dpy, win);
  7203. +
  7204. + if ( get_frame_usage != NULL ) {
  7205. + GLfloat temp;
  7206. +
  7207. + (*get_frame_usage)( dpy, win, & temp );
  7208. + frame_usage += temp;
  7209. + }
  7210. +
  7211. + /* calc framerate */
  7212. + {
  7213. + static int t0 = -1;
  7214. + static int frames = 0;
  7215. + int t = current_time();
  7216. +
  7217. + if (t0 < 0)
  7218. + t0 = t;
  7219. +
  7220. + frames++;
  7221. +
  7222. + if (t - t0 >= 5.0) {
  7223. + GLfloat seconds = t - t0;
  7224. + GLfloat fps = frames / seconds;
  7225. + if ( get_frame_usage != NULL ) {
  7226. + printf("%d frames in %3.1f seconds = %6.3f FPS (%3.1f%% usage)\n",
  7227. + frames, seconds, fps,
  7228. + (frame_usage * 100.0) / (float) frames );
  7229. + }
  7230. + else {
  7231. + printf("%d frames in %3.1f seconds = %6.3f FPS\n",
  7232. + frames, seconds, fps);
  7233. + }
  7234. +
  7235. + t0 = t;
  7236. + frames = 0;
  7237. + frame_usage = 0.0;
  7238. + }
  7239. + }
  7240. + }
  7241. +}
  7242. +
  7243. +
  7244. +/**
  7245. + * Display the refresh rate of the display using the GLX_OML_sync_control
  7246. + * extension.
  7247. + */
  7248. +static void
  7249. +show_refresh_rate( Display * dpy )
  7250. +{
  7251. +#if defined(GLX_OML_sync_control) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  7252. + PFNGLXGETMSCRATEOMLPROC get_msc_rate;
  7253. + int32_t n;
  7254. + int32_t d;
  7255. +
  7256. + get_msc_rate = (PFNGLXGETMSCRATEOMLPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetMscRateOML" );
  7257. + if ( get_msc_rate != NULL ) {
  7258. + (*get_msc_rate)( dpy, glXGetCurrentDrawable(), &n, &d );
  7259. + printf( "refresh rate: %.1fHz\n", (float) n / d );
  7260. + return;
  7261. + }
  7262. +#endif
  7263. + printf( "glXGetMscRateOML not supported.\n" );
  7264. +}
  7265. +
  7266. +
  7267. +/**
  7268. + * Fill in the table of extension strings from a supplied extensions string
  7269. + * (as returned by glXQueryExtensionsString).
  7270. + *
  7271. + * \param string String of GLX extensions.
  7272. + * \sa is_extension_supported
  7273. + */
  7274. +static void
  7275. +make_extension_table( const char * string )
  7276. +{
  7277. + char ** string_tab;
  7278. + unsigned num_strings;
  7279. + unsigned base;
  7280. + unsigned idx;
  7281. + unsigned i;
  7282. +
  7283. + /* Count the number of spaces in the string. That gives a base-line
  7284. + * figure for the number of extension in the string.
  7285. + */
  7286. +
  7287. + num_strings = 1;
  7288. + for ( i = 0 ; string[i] != NUL ; i++ ) {
  7289. + if ( string[i] == ' ' ) {
  7290. + num_strings++;
  7291. + }
  7292. + }
  7293. +
  7294. + string_tab = (char **) malloc( sizeof( char * ) * num_strings );
  7295. + if ( string_tab == NULL ) {
  7296. + return;
  7297. + }
  7298. +
  7299. + base = 0;
  7300. + idx = 0;
  7301. +
  7302. + while ( string[ base ] != NUL ) {
  7303. + /* Determine the length of the next extension string.
  7304. + */
  7305. +
  7306. + for ( i = 0
  7307. + ; (string[ base + i ] != NUL) && (string[ base + i ] != ' ')
  7308. + ; i++ ) {
  7309. + /* empty */ ;
  7310. + }
  7311. +
  7312. + if ( i > 0 ) {
  7313. + /* If the string was non-zero length, add it to the table. We
  7314. + * can get zero length strings if there is a space at the end of
  7315. + * the string or if there are two (or more) spaces next to each
  7316. + * other in the string.
  7317. + */
  7318. +
  7319. + string_tab[ idx ] = malloc( sizeof( char ) * (i + 1) );
  7320. + if ( string_tab[ idx ] == NULL ) {
  7321. + return;
  7322. + }
  7323. +
  7324. + (void) memcpy( string_tab[ idx ], & string[ base ], i );
  7325. + string_tab[ idx ][i] = NUL;
  7326. + idx++;
  7327. + }
  7328. +
  7329. +
  7330. + /* Skip to the start of the next extension string.
  7331. + */
  7332. +
  7333. + for ( base += i
  7334. + ; (string[ base ] == ' ') && (string[ base ] != NUL)
  7335. + ; base++ ) {
  7336. + /* empty */ ;
  7337. + }
  7338. + }
  7339. +
  7340. + extension_table = string_tab;
  7341. + num_extensions = idx;
  7342. +}
  7343. +
  7344. +
  7345. +/**
  7346. + * Determine of an extension is supported. The extension string table
  7347. + * must have already be initialized by calling \c make_extension_table.
  7348. + *
  7349. + * \praram ext Extension to be tested.
  7350. + * \return GL_TRUE of the extension is supported, GL_FALSE otherwise.
  7351. + * \sa make_extension_table
  7352. + */
  7353. +static GLboolean
  7354. +is_extension_supported( const char * ext )
  7355. +{
  7356. + unsigned i;
  7357. +
  7358. + for ( i = 0 ; i < num_extensions ; i++ ) {
  7359. + if ( strcmp( ext, extension_table[i] ) == 0 ) {
  7360. + return GL_TRUE;
  7361. + }
  7362. + }
  7363. +
  7364. + return GL_FALSE;
  7365. +}
  7366. +
  7367. +
  7368. +int
  7369. +main(int argc, char *argv[])
  7370. +{
  7371. + Display *dpy;
  7372. + Window win;
  7373. + GLXContext ctx;
  7374. + char *dpyName = NULL;
  7375. + int swap_interval = 1;
  7376. + GLboolean do_swap_interval = GL_FALSE;
  7377. + GLboolean force_get_rate = GL_FALSE;
  7378. + GLboolean fullscreen = GL_FALSE;
  7379. + GLboolean printInfo = GL_FALSE;
  7380. + int i;
  7381. + PFNGLXSWAPINTERVALMESAPROC set_swap_interval = NULL;
  7382. + PFNGLXGETSWAPINTERVALMESAPROC get_swap_interval = NULL;
  7383. + int width = 300, height = 300;
  7384. +
  7385. + for (i = 1; i < argc; i++) {
  7386. + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
  7387. + dpyName = argv[i+1];
  7388. + i++;
  7389. + }
  7390. + else if (strcmp(argv[i], "-info") == 0) {
  7391. + printInfo = GL_TRUE;
  7392. + }
  7393. + else if (strcmp(argv[i], "-swap") == 0 && i + 1 < argc) {
  7394. + swap_interval = atoi( argv[i+1] );
  7395. + do_swap_interval = GL_TRUE;
  7396. + i++;
  7397. + }
  7398. + else if (strcmp(argv[i], "-forcegetrate") == 0) {
  7399. + /* This option was put in because some DRI drivers don't support the
  7400. + * full GLX_OML_sync_control extension, but they do support
  7401. + * glXGetMscRateOML.
  7402. + */
  7403. + force_get_rate = GL_TRUE;
  7404. + }
  7405. + else if (strcmp(argv[i], "-fullscreen") == 0) {
  7406. + fullscreen = GL_TRUE;
  7407. + }
  7408. + else if (strcmp(argv[i], "-ztrick") == 0) {
  7409. + use_ztrick = GL_TRUE;
  7410. + }
  7411. + else if (strcmp(argv[i], "-help") == 0) {
  7412. + printf("Usage:\n");
  7413. + printf(" gears [options]\n");
  7414. + printf("Options:\n");
  7415. + printf(" -help Print this information\n");
  7416. + printf(" -display displayName Specify X display\n");
  7417. + printf(" -info Display GL information\n");
  7418. + printf(" -swap N Swap no more than once per N vertical refreshes\n");
  7419. + printf(" -forcegetrate Try to use glXGetMscRateOML function\n");
  7420. + printf(" -fullscreen Full-screen window\n");
  7421. + return 0;
  7422. + }
  7423. + }
  7424. +
  7425. + dpy = XOpenDisplay(dpyName);
  7426. + if (!dpy) {
  7427. + printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
  7428. + return -1;
  7429. + }
  7430. +
  7431. + make_window(dpy, "glxgears", 0, 0, width, height, fullscreen, &win, &ctx);
  7432. + XMapWindow(dpy, win);
  7433. + glXMakeCurrent(dpy, win, ctx);
  7434. +
  7435. + make_extension_table( (char *) glXQueryExtensionsString(dpy,DefaultScreen(dpy)) );
  7436. + has_OML_sync_control = is_extension_supported( "GLX_OML_sync_control" );
  7437. + has_SGI_swap_control = is_extension_supported( "GLX_SGI_swap_control" );
  7438. + has_MESA_swap_control = is_extension_supported( "GLX_MESA_swap_control" );
  7439. + has_MESA_swap_frame_usage = is_extension_supported( "GLX_MESA_swap_frame_usage" );
  7440. +
  7441. + if ( has_MESA_swap_control ) {
  7442. + set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalMESA" );
  7443. + get_swap_interval = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetSwapIntervalMESA" );
  7444. + }
  7445. + else if ( has_SGI_swap_control ) {
  7446. + set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalSGI" );
  7447. + }
  7448. +
  7449. +
  7450. + if ( has_MESA_swap_frame_usage ) {
  7451. + get_frame_usage = (PFNGLXGETFRAMEUSAGEMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetFrameUsageMESA" );
  7452. + }
  7453. +
  7454. +
  7455. + if (printInfo) {
  7456. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  7457. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  7458. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  7459. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  7460. + if ( has_OML_sync_control || force_get_rate ) {
  7461. + show_refresh_rate( dpy );
  7462. + }
  7463. +
  7464. + if ( get_swap_interval != NULL ) {
  7465. + printf("Default swap interval = %d\n", (*get_swap_interval)() );
  7466. + }
  7467. + }
  7468. +
  7469. + if ( do_swap_interval ) {
  7470. + if ( set_swap_interval != NULL ) {
  7471. + if ( ((swap_interval == 0) && !has_MESA_swap_control)
  7472. + || (swap_interval < 0) ) {
  7473. + printf( "Swap interval must be non-negative or greater than zero "
  7474. + "if GLX_MESA_swap_control is not supported.\n" );
  7475. + }
  7476. + else {
  7477. + (*set_swap_interval)( swap_interval );
  7478. + }
  7479. +
  7480. + if ( printInfo && (get_swap_interval != NULL) ) {
  7481. + printf("Current swap interval = %d\n", (*get_swap_interval)() );
  7482. + }
  7483. + }
  7484. + else {
  7485. + printf("Unable to set swap-interval. Neither GLX_SGI_swap_control "
  7486. + "nor GLX_MESA_swap_control are supported.\n" );
  7487. + }
  7488. + }
  7489. +
  7490. + init();
  7491. +
  7492. + /* Set initial projection/viewing transformation.
  7493. + * same as glxgears.c
  7494. + */
  7495. + reshape(width, height);
  7496. +
  7497. + event_loop(dpy, win);
  7498. +
  7499. + glXDestroyContext(dpy, ctx);
  7500. + XDestroyWindow(dpy, win);
  7501. + XCloseDisplay(dpy);
  7502. +
  7503. + return 0;
  7504. +}
  7505. diff -Naurp Mesa-7.8.1/progs/xdemos/ipc.c Mesa-7.8.1.patched/progs/xdemos/ipc.c
  7506. --- Mesa-7.8.1/progs/xdemos/ipc.c 1970-01-01 01:00:00.000000000 +0100
  7507. +++ Mesa-7.8.1.patched/progs/xdemos/ipc.c 2010-06-13 13:45:06.789793146 +0200
  7508. @@ -0,0 +1,264 @@
  7509. +/* Copyright (c) 2003 Tungsten Graphics, Inc.
  7510. + *
  7511. + * Permission is hereby granted, free of charge, to any person obtaining
  7512. + * a copy of this software and associated documentation files ("the
  7513. + * Software"), to deal in the Software without restriction, including
  7514. + * without limitation the rights to use, copy, modify, merge, publish,
  7515. + * distribute, sublicense, and/or sell copies of the Software, and to
  7516. + * permit persons to whom the Software is furnished to do so, subject to
  7517. + * the following conditions: The above copyright notice, the Tungsten
  7518. + * Graphics splash screen, and this permission notice shall be included
  7519. + * in all copies or substantial portions of the Software. THE SOFTWARE
  7520. + * IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  7521. + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7522. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  7523. + * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7524. + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7525. + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  7526. + * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  7527. + */
  7528. +
  7529. +/*
  7530. + * Simple IPC API
  7531. + * Brian Paul
  7532. + */
  7533. +
  7534. +
  7535. +#include <assert.h>
  7536. +#include <stdio.h>
  7537. +#include <string.h>
  7538. +#include <sys/types.h>
  7539. +#include <netinet/in.h>
  7540. +#include <netinet/tcp.h>
  7541. +#include <arpa/inet.h>
  7542. +#include <netdb.h>
  7543. +#include <unistd.h>
  7544. +#include <sys/socket.h>
  7545. +#include "ipc.h"
  7546. +
  7547. +#if defined(IRIX) || defined(irix)
  7548. +typedef int socklen_t;
  7549. +#endif
  7550. +
  7551. +#define NO_DELAY 1
  7552. +
  7553. +#define DEFAULT_MASTER_PORT 7011
  7554. +
  7555. +
  7556. +/*
  7557. + * Return my hostname in <nameOut>.
  7558. + * Return 1 for success, 0 for error.
  7559. + */
  7560. +int
  7561. +MyHostName(char *nameOut, int maxNameLength)
  7562. +{
  7563. + int k = gethostname(nameOut, maxNameLength);
  7564. + return k==0;
  7565. +}
  7566. +
  7567. +
  7568. +/*
  7569. + * Create a socket attached to a port. Later, we can call AcceptConnection
  7570. + * on the socket returned from this function.
  7571. + * Return the new socket number or -1 if error.
  7572. + */
  7573. +int
  7574. +CreatePort(int *port)
  7575. +{
  7576. + char hostname[1000];
  7577. + struct sockaddr_in servaddr;
  7578. + struct hostent *hp;
  7579. + int so_reuseaddr = 1;
  7580. + int tcp_nodelay = 1;
  7581. + int sock, k;
  7582. +
  7583. + /* create socket */
  7584. + sock = socket(AF_INET, SOCK_STREAM, 0);
  7585. + assert(sock > 2);
  7586. +
  7587. + /* get my host name */
  7588. + k = gethostname(hostname, 1000);
  7589. + assert(k == 0);
  7590. +
  7591. + /* get hostent info */
  7592. + hp = gethostbyname(hostname);
  7593. + assert(hp);
  7594. +
  7595. + /* initialize the servaddr struct */
  7596. + memset(&servaddr, 0, sizeof(servaddr) );
  7597. + servaddr.sin_family = AF_INET;
  7598. + servaddr.sin_port = htons((unsigned short) (*port));
  7599. + memcpy((char *) &servaddr.sin_addr, hp->h_addr,
  7600. + sizeof(servaddr.sin_addr));
  7601. +
  7602. + /* deallocate when we exit */
  7603. + k = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
  7604. + (char *) &so_reuseaddr, sizeof(so_reuseaddr));
  7605. + assert(k==0);
  7606. +
  7607. + /* send packets immediately */
  7608. +#if NO_DELAY
  7609. + k = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
  7610. + (char *) &tcp_nodelay, sizeof(tcp_nodelay));
  7611. + assert(k==0);
  7612. +#endif
  7613. +
  7614. + if (*port == 0)
  7615. + *port = DEFAULT_MASTER_PORT;
  7616. +
  7617. + k = 1;
  7618. + while (k && (*port < 65534)) {
  7619. + /* bind our address to the socket */
  7620. + servaddr.sin_port = htons((unsigned short) (*port));
  7621. + k = bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
  7622. + if (k)
  7623. + *port = *port + 1;
  7624. + }
  7625. +
  7626. +#if 0
  7627. + printf("###### Real Port: %d\n", *port);
  7628. +#endif
  7629. +
  7630. + /* listen for connections */
  7631. + k = listen(sock, 100);
  7632. + assert(k == 0);
  7633. +
  7634. + return sock;
  7635. +}
  7636. +
  7637. +
  7638. +/*
  7639. + * Accept a connection on the named socket.
  7640. + * Return a new socket for the new connection, or -1 if error.
  7641. + */
  7642. +int
  7643. +AcceptConnection(int socket)
  7644. +{
  7645. + struct sockaddr addr;
  7646. + socklen_t addrLen;
  7647. + int newSock;
  7648. +
  7649. + addrLen = sizeof(addr);
  7650. + newSock = accept(socket, &addr, &addrLen);
  7651. + if (newSock == 1)
  7652. + return -1;
  7653. + else
  7654. + return newSock;
  7655. +}
  7656. +
  7657. +
  7658. +/*
  7659. + * Contact the server running on the given host on the named port.
  7660. + * Return socket number or -1 if error.
  7661. + */
  7662. +int
  7663. +Connect(const char *hostname, int port)
  7664. +{
  7665. + struct sockaddr_in servaddr;
  7666. + struct hostent *hp;
  7667. + int sock, k;
  7668. + int tcp_nodelay = 1;
  7669. +
  7670. + assert(port);
  7671. +
  7672. + sock = socket(AF_INET, SOCK_STREAM, 0);
  7673. + assert(sock >= 0);
  7674. +
  7675. + hp = gethostbyname(hostname);
  7676. + assert(hp);
  7677. +
  7678. + memset(&servaddr, 0, sizeof(servaddr));
  7679. + servaddr.sin_family = AF_INET;
  7680. + servaddr.sin_port = htons((unsigned short) port);
  7681. + memcpy((char *) &servaddr.sin_addr, hp->h_addr, sizeof(servaddr.sin_addr));
  7682. +
  7683. + k = connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
  7684. + if (k != 0) {
  7685. + perror("Connect:");
  7686. + return -1;
  7687. + }
  7688. +
  7689. +#if NO_DELAY
  7690. + /* send packets immediately */
  7691. + k = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
  7692. + (char *) &tcp_nodelay, sizeof(tcp_nodelay));
  7693. + assert(k==0);
  7694. +#endif
  7695. +
  7696. + return sock;
  7697. +}
  7698. +
  7699. +
  7700. +void
  7701. +CloseSocket(int socket)
  7702. +{
  7703. + close(socket);
  7704. +}
  7705. +
  7706. +
  7707. +int
  7708. +SendData(int socket, const void *data, int bytes)
  7709. +{
  7710. + int sent = 0;
  7711. + int b;
  7712. +
  7713. + while (sent < bytes) {
  7714. + b = write(socket, (char *) data + sent, bytes - sent);
  7715. + if (b <= 0)
  7716. + return -1; /* something broke */
  7717. + sent += b;
  7718. + }
  7719. + return sent;
  7720. +}
  7721. +
  7722. +
  7723. +int
  7724. +ReceiveData(int socket, void *data, int bytes)
  7725. +{
  7726. + int received = 0, b;
  7727. +
  7728. + while (received < bytes) {
  7729. + b = read(socket, (char *) data + received, bytes - received);
  7730. + if (b <= 0)
  7731. + return -1;
  7732. + received += b;
  7733. + }
  7734. + return received;
  7735. +}
  7736. +
  7737. +
  7738. +int
  7739. +SendString(int socket, const char *str)
  7740. +{
  7741. + const int len = strlen(str);
  7742. + int sent, b;
  7743. +
  7744. + /* first, send a 4-byte length indicator */
  7745. + b = write(socket, &len, sizeof(len));
  7746. + if (b <= 0)
  7747. + return -1;
  7748. +
  7749. + sent = SendData(socket, str, len);
  7750. + assert(sent == len);
  7751. + return sent;
  7752. +}
  7753. +
  7754. +
  7755. +int
  7756. +ReceiveString(int socket, char *str, int maxLen)
  7757. +{
  7758. + int len, received, b;
  7759. +
  7760. + /* first, read 4 bytes to see how long of string to receive */
  7761. + b = read(socket, &len, sizeof(len));
  7762. + if (b <= 0)
  7763. + return -1;
  7764. +
  7765. + assert(len <= maxLen); /* XXX fix someday */
  7766. + assert(len >= 0);
  7767. + received = ReceiveData(socket, str, len);
  7768. + assert(received != -1);
  7769. + assert(received == len);
  7770. + str[len] = 0;
  7771. + return received;
  7772. +}
  7773. diff -Naurp Mesa-7.8.1/progs/xdemos/ipc.h Mesa-7.8.1.patched/progs/xdemos/ipc.h
  7774. --- Mesa-7.8.1/progs/xdemos/ipc.h 1970-01-01 01:00:00.000000000 +0100
  7775. +++ Mesa-7.8.1.patched/progs/xdemos/ipc.h 2010-06-13 13:45:06.789793146 +0200
  7776. @@ -0,0 +1,16 @@
  7777. +#ifndef IPC_H
  7778. +#define IPC_H
  7779. +
  7780. +
  7781. +extern int MyHostName(char *nameOut, int maxNameLength);
  7782. +extern int CreatePort(int *port);
  7783. +extern int AcceptConnection(int socket);
  7784. +extern int Connect(const char *hostname, int port);
  7785. +extern void CloseSocket(int socket);
  7786. +extern int SendData(int socket, const void *data, int bytes);
  7787. +extern int ReceiveData(int socket, void *data, int bytes);
  7788. +extern int SendString(int socket, const char *str);
  7789. +extern int ReceiveString(int socket, char *str, int maxLen);
  7790. +
  7791. +
  7792. +#endif /* IPC_H */
  7793. diff -Naurp Mesa-7.8.1/progs/xdemos/Makefile Mesa-7.8.1.patched/progs/xdemos/Makefile
  7794. --- Mesa-7.8.1/progs/xdemos/Makefile 1970-01-01 01:00:00.000000000 +0100
  7795. +++ Mesa-7.8.1.patched/progs/xdemos/Makefile 2010-06-13 13:45:06.788792936 +0200
  7796. @@ -0,0 +1,103 @@
  7797. +# progs/xdemos/Makefile
  7798. +
  7799. +TOP = ../..
  7800. +include $(TOP)/configs/current
  7801. +
  7802. +
  7803. +INCDIR = $(TOP)/include
  7804. +
  7805. +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
  7806. +
  7807. +# Add X11 and pthread libs to satisfy GNU gold.
  7808. +APP_LIB_DEPS += -lX11 -lpthread
  7809. +
  7810. +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS)
  7811. +
  7812. +PROGS = \
  7813. + corender \
  7814. + glsync \
  7815. + glthreads \
  7816. + glxdemo \
  7817. + glxgears \
  7818. + glxgears_fbconfig \
  7819. + glxgears_pixmap \
  7820. + glxcontexts \
  7821. + glxheads \
  7822. + glxinfo \
  7823. + glxpixmap \
  7824. + glxpbdemo \
  7825. + glxsnoop \
  7826. + glxswapcontrol \
  7827. + manywin \
  7828. + msctest \
  7829. + multictx \
  7830. + offset \
  7831. + omlsync \
  7832. + overlay \
  7833. + pbinfo \
  7834. + pbdemo \
  7835. + sharedtex \
  7836. + sharedtex_mt \
  7837. + texture_from_pixmap \
  7838. + wincopy \
  7839. + xfont \
  7840. + xrotfontdemo
  7841. +
  7842. +# Don't build these by default because of extra library dependencies
  7843. +EXTRA_PROGS = \
  7844. + shape \
  7845. + yuvrect_client \
  7846. + xdemo
  7847. +
  7848. +
  7849. +
  7850. +##### RULES #####
  7851. +
  7852. +.o: $(LIB_DEP)
  7853. + $(APP_CC) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
  7854. +
  7855. +.c.o:
  7856. + $(APP_CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) $< -c -o $@
  7857. +
  7858. +
  7859. +##### TARGETS #####
  7860. +
  7861. +default: $(PROGS)
  7862. +
  7863. +$(PROGS): $(PROGS:%=%.o)
  7864. +
  7865. +extra: $(EXTRA_PROGS)
  7866. +
  7867. +
  7868. +clean:
  7869. + -rm -f $(PROGS) $(EXTRA_PROGS)
  7870. + -rm -f *.o *~
  7871. +
  7872. +
  7873. +# special cases
  7874. +pbutil.o: pbutil.h
  7875. +pbinfo.o: pbutil.h
  7876. +pbinfo: pbinfo.o pbutil.o
  7877. + $(APP_CC) $(CFLAGS) $(LDFLAGS) pbinfo.o pbutil.o $(LIBS) -o $@
  7878. +
  7879. +pbdemo.o: pbutil.h
  7880. +pbdemo: pbdemo.o pbutil.o
  7881. + $(APP_CC) $(CFLAGS) $(LDFLAGS) pbdemo.o pbutil.o $(LIBS) -o $@
  7882. +
  7883. +glxgears_fbconfig.o: pbutil.h
  7884. +glxgears_fbconfig: glxgears_fbconfig.o pbutil.o
  7885. + $(APP_CC) $(CFLAGS) $(LDFLAGS) glxgears_fbconfig.o pbutil.o $(LIBS) -o $@
  7886. +
  7887. +xuserotfont.o: xuserotfont.h
  7888. +xrotfontdemo.o: xuserotfont.h
  7889. +xrotfontdemo: xrotfontdemo.o xuserotfont.o
  7890. + $(APP_CC) $(CFLAGS) $(LDFLAGS) xrotfontdemo.o xuserotfont.o $(LIBS) -o $@
  7891. +
  7892. +ipc.o: ipc.h
  7893. +corender.o: ipc.h
  7894. +corender: corender.o ipc.o
  7895. + $(APP_CC) $(CFLAGS) $(LDFLAGS) corender.o ipc.o $(LIBS) -o $@
  7896. +
  7897. +yuvrect_client: yuvrect_client.o
  7898. + $(APP_CC) $(CFLAGS) $< $(LDFLAGS) $(LIBS) -l$(GLU_LIB) -o $@
  7899. +
  7900. diff -Naurp Mesa-7.8.1/progs/xdemos/manywin.c Mesa-7.8.1.patched/progs/xdemos/manywin.c
  7901. --- Mesa-7.8.1/progs/xdemos/manywin.c 1970-01-01 01:00:00.000000000 +0100
  7902. +++ Mesa-7.8.1.patched/progs/xdemos/manywin.c 2010-06-13 13:45:06.789793146 +0200
  7903. @@ -0,0 +1,421 @@
  7904. +/*
  7905. + * Create N GLX windows/contexts and render to them in round-robin order.
  7906. + * Also, have the contexts share all texture objects.
  7907. + * Press 'd' to delete a texture, 'u' to unbind it.
  7908. + *
  7909. + * Copyright (C) 2000 Brian Paul All Rights Reserved.
  7910. + *
  7911. + * Permission is hereby granted, free of charge, to any person obtaining a
  7912. + * copy of this software and associated documentation files (the "Software"),
  7913. + * to deal in the Software without restriction, including without limitation
  7914. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7915. + * and/or sell copies of the Software, and to permit persons to whom the
  7916. + * Software is furnished to do so, subject to the following conditions:
  7917. + *
  7918. + * The above copyright notice and this permission notice shall be included
  7919. + * in all copies or substantial portions of the Software.
  7920. + *
  7921. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7922. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7923. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  7924. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  7925. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  7926. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  7927. + */
  7928. +
  7929. +
  7930. +#include <GL/gl.h>
  7931. +#include <GL/glx.h>
  7932. +#include <assert.h>
  7933. +#include <stdio.h>
  7934. +#include <stdlib.h>
  7935. +#include <string.h>
  7936. +#include <unistd.h>
  7937. +#include <X11/keysym.h>
  7938. +
  7939. +
  7940. +/*
  7941. + * Each display/window/context:
  7942. + */
  7943. +struct head {
  7944. + char DisplayName[1000];
  7945. + Display *Dpy;
  7946. + Window Win;
  7947. + GLXContext Context;
  7948. + float Angle;
  7949. + char Renderer[1000];
  7950. + char Vendor[1000];
  7951. + char Version[1000];
  7952. +};
  7953. +
  7954. +
  7955. +#define MAX_HEADS 200
  7956. +static struct head Heads[MAX_HEADS];
  7957. +static int NumHeads = 0;
  7958. +static GLboolean SwapSeparate = GL_TRUE;
  7959. +static GLuint TexObj = 0;
  7960. +
  7961. +
  7962. +static void
  7963. +Error(const char *display, const char *msg)
  7964. +{
  7965. + fprintf(stderr, "Error on display %s - %s\n", XDisplayName(display), msg);
  7966. + exit(1);
  7967. +}
  7968. +
  7969. +
  7970. +static struct head *
  7971. +AddHead(const char *displayName, const char *name)
  7972. +{
  7973. + Display *dpy;
  7974. + Window win;
  7975. + GLXContext ctx;
  7976. + int attrib[] = { GLX_RGBA,
  7977. + GLX_RED_SIZE, 1,
  7978. + GLX_GREEN_SIZE, 1,
  7979. + GLX_BLUE_SIZE, 1,
  7980. + GLX_DOUBLEBUFFER,
  7981. + None };
  7982. + int scrnum;
  7983. + XSetWindowAttributes attr;
  7984. + unsigned long mask;
  7985. + Window root;
  7986. + XVisualInfo *visinfo;
  7987. + int width = 90, height = 90;
  7988. + int xpos = 0, ypos = 0;
  7989. +
  7990. + if (NumHeads >= MAX_HEADS)
  7991. + return NULL;
  7992. +
  7993. + dpy = XOpenDisplay(displayName);
  7994. + if (!dpy) {
  7995. + Error(displayName, "Unable to open display");
  7996. + return NULL;
  7997. + }
  7998. +
  7999. + scrnum = DefaultScreen(dpy);
  8000. + root = RootWindow(dpy, scrnum);
  8001. +
  8002. + visinfo = glXChooseVisual(dpy, scrnum, attrib);
  8003. + if (!visinfo) {
  8004. + Error(displayName, "Unable to find RGB, double-buffered visual");
  8005. + return NULL;
  8006. + }
  8007. +
  8008. + /* window attributes */
  8009. + xpos = (NumHeads % 10) * 100;
  8010. + ypos = (NumHeads / 10) * 100;
  8011. + printf("%d, %d\n", xpos, ypos);
  8012. + attr.background_pixel = 0;
  8013. + attr.border_pixel = 0;
  8014. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  8015. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  8016. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  8017. +
  8018. + win = XCreateWindow(dpy, root, xpos, ypos, width, height,
  8019. + 0, visinfo->depth, InputOutput,
  8020. + visinfo->visual, mask, &attr);
  8021. + if (!win) {
  8022. + Error(displayName, "Couldn't create window");
  8023. + return NULL;
  8024. + }
  8025. +
  8026. + {
  8027. + XSizeHints sizehints;
  8028. + sizehints.x = xpos;
  8029. + sizehints.y = ypos;
  8030. + sizehints.width = width;
  8031. + sizehints.height = height;
  8032. + sizehints.flags = USSize | USPosition;
  8033. + XSetNormalHints(dpy, win, &sizehints);
  8034. + XSetStandardProperties(dpy, win, name, name,
  8035. + None, (char **)NULL, 0, &sizehints);
  8036. + }
  8037. +
  8038. + if (NumHeads == 0) {
  8039. + ctx = glXCreateContext(dpy, visinfo, NULL, True);
  8040. + }
  8041. + else {
  8042. + /* share textures & dlists with 0th context */
  8043. + printf("sharing\n");
  8044. + ctx = glXCreateContext(dpy, visinfo, Heads[0].Context, True);
  8045. + }
  8046. + if (!ctx) {
  8047. + Error(displayName, "Couldn't create GLX context");
  8048. + return NULL;
  8049. + }
  8050. +
  8051. + XMapWindow(dpy, win);
  8052. +
  8053. + if (!glXMakeCurrent(dpy, win, ctx)) {
  8054. + Error(displayName, "glXMakeCurrent failed");
  8055. + printf("glXMakeCurrent failed in Redraw()\n");
  8056. + return NULL;
  8057. + }
  8058. +
  8059. + if (NumHeads == 0) {
  8060. + /* create texture object now */
  8061. + static const GLubyte checker[2][2][4] = {
  8062. + { {255, 255, 255, 255}, { 0, 0, 0, 255} },
  8063. + { { 0, 0, 0, 0}, {255, 255, 255, 255} }
  8064. + };
  8065. + glGenTextures(1, &TexObj);
  8066. + assert(TexObj);
  8067. + glBindTexture(GL_TEXTURE_2D, TexObj);
  8068. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGB,
  8069. + GL_UNSIGNED_BYTE, checker);
  8070. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  8071. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  8072. + }
  8073. + else {
  8074. + /* bind 0th context's texture in this context too */
  8075. + assert(TexObj);
  8076. + glBindTexture(GL_TEXTURE_2D, TexObj);
  8077. + }
  8078. + glEnable(GL_TEXTURE_2D);
  8079. +
  8080. + /* save the info for this head */
  8081. + {
  8082. + struct head *h = &Heads[NumHeads];
  8083. + const char * tmp;
  8084. +
  8085. + if (strlen(name) + 1 > sizeof(h->DisplayName)) {
  8086. + Error(displayName, "name string overflow");
  8087. + return NULL;
  8088. + }
  8089. + strcpy(h->DisplayName, name);
  8090. +
  8091. + h->Dpy = dpy;
  8092. + h->Win = win;
  8093. + h->Context = ctx;
  8094. + h->Angle = 0.0;
  8095. +
  8096. + tmp = (char *) glGetString(GL_VERSION);
  8097. + if (strlen(tmp) + 1 > sizeof(h->Version)) {
  8098. + Error(displayName, "GL_VERSION string overflow");
  8099. + return NULL;
  8100. + }
  8101. + strcpy(h->Version, tmp);
  8102. +
  8103. + tmp = (char *) glGetString(GL_VENDOR);
  8104. + if (strlen(tmp) + 1 > sizeof(h->Vendor)) {
  8105. + Error(displayName, "GL_VENDOR string overflow");
  8106. + return NULL;
  8107. + }
  8108. + strcpy(h->Vendor, tmp);
  8109. +
  8110. + tmp = (char *) glGetString(GL_RENDERER);
  8111. + if (strlen(tmp) + 1 > sizeof(h->Renderer)) {
  8112. + Error(displayName, "GL_RENDERER string overflow");
  8113. + return NULL;
  8114. + }
  8115. + strcpy(h->Renderer, tmp);
  8116. +
  8117. + NumHeads++;
  8118. + return &Heads[NumHeads-1];
  8119. + }
  8120. +
  8121. +}
  8122. +
  8123. +
  8124. +static void
  8125. +DestroyHeads(void)
  8126. +{
  8127. + int i;
  8128. + for (i = 0; i < NumHeads; i++) {
  8129. + XDestroyWindow(Heads[i].Dpy, Heads[i].Win);
  8130. + glXDestroyContext(Heads[i].Dpy, Heads[i].Context);
  8131. + XCloseDisplay(Heads[i].Dpy);
  8132. + }
  8133. +}
  8134. +
  8135. +
  8136. +static void
  8137. +Redraw(struct head *h)
  8138. +{
  8139. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  8140. + Error(h->DisplayName, "glXMakeCurrent failed");
  8141. + printf("glXMakeCurrent failed in Redraw()\n");
  8142. + return;
  8143. + }
  8144. +
  8145. + h->Angle += 1.0;
  8146. +
  8147. + glShadeModel(GL_FLAT);
  8148. + glClearColor(0.5, 0.5, 0.5, 1.0);
  8149. + glClear(GL_COLOR_BUFFER_BIT);
  8150. +
  8151. + /* draw green triangle */
  8152. + glColor3f(0.0, 1.0, 0.0);
  8153. + glPushMatrix();
  8154. + glRotatef(h->Angle, 0, 0, 1);
  8155. + glBegin(GL_TRIANGLES);
  8156. + glTexCoord2f(0.5, 1.0); glVertex2f(0, 0.8);
  8157. + glTexCoord2f(0.0, 0.0); glVertex2f(-0.8, -0.7);
  8158. + glTexCoord2f(1.0, 0.0); glVertex2f(0.8, -0.7);
  8159. + glEnd();
  8160. + glPopMatrix();
  8161. +
  8162. + if (!SwapSeparate)
  8163. + glXSwapBuffers(h->Dpy, h->Win);
  8164. +}
  8165. +
  8166. +
  8167. +static void
  8168. +Swap(struct head *h)
  8169. +{
  8170. + glXSwapBuffers(h->Dpy, h->Win);
  8171. +}
  8172. +
  8173. +
  8174. +static void
  8175. +Resize(const struct head *h, unsigned int width, unsigned int height)
  8176. +{
  8177. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  8178. + Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
  8179. + return;
  8180. + }
  8181. + glFlush();
  8182. + glViewport(0, 0, width, height);
  8183. + glMatrixMode(GL_PROJECTION);
  8184. + glLoadIdentity();
  8185. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  8186. +}
  8187. +
  8188. +
  8189. +
  8190. +static void
  8191. +EventLoop(void)
  8192. +{
  8193. + while (1) {
  8194. + int i;
  8195. + for (i = 0; i < NumHeads; i++) {
  8196. + struct head *h = &Heads[i];
  8197. + while (XPending(h->Dpy) > 0) {
  8198. + XEvent event;
  8199. + XNextEvent(h->Dpy, &event);
  8200. + if (event.xany.window == h->Win) {
  8201. + switch (event.type) {
  8202. + case Expose:
  8203. + Redraw(h);
  8204. + if (SwapSeparate)
  8205. + Swap(h);
  8206. + break;
  8207. + case ConfigureNotify:
  8208. + Resize(h, event.xconfigure.width, event.xconfigure.height);
  8209. + break;
  8210. + case KeyPress:
  8211. + {
  8212. + char buf[100];
  8213. + KeySym keySym;
  8214. + XComposeStatus stat;
  8215. + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
  8216. + switch (keySym) {
  8217. + case XK_Escape:
  8218. + return;
  8219. + break;
  8220. + case XK_d:
  8221. + case XK_D:
  8222. + printf("Delete Texture in window %d\n", i);
  8223. + glXMakeCurrent(h->Dpy, h->Win, h->Context);
  8224. + glDeleteTextures(1, &TexObj);
  8225. + break;
  8226. + case XK_u:
  8227. + case XK_U:
  8228. + printf("Unbind Texture in window %d\n", i);
  8229. + glXMakeCurrent(h->Dpy, h->Win, h->Context);
  8230. + glBindTexture(GL_TEXTURE_2D, 0);
  8231. + break;
  8232. + }
  8233. + }
  8234. + break;
  8235. + default:
  8236. + /*no-op*/ ;
  8237. + }
  8238. + }
  8239. + else {
  8240. + printf("window mismatch\n");
  8241. + }
  8242. + }
  8243. + }
  8244. +
  8245. + /* redraw all windows */
  8246. + for (i = 0; i < NumHeads; i++) {
  8247. + Redraw(&Heads[i]);
  8248. + }
  8249. + /* swapbuffers on all windows, if not already done */
  8250. + if (SwapSeparate) {
  8251. + for (i = 0; i < NumHeads; i++) {
  8252. + Swap(&Heads[i]);
  8253. + }
  8254. + }
  8255. + usleep(1);
  8256. + }
  8257. +}
  8258. +
  8259. +
  8260. +
  8261. +static void
  8262. +PrintInfo(const struct head *h)
  8263. +{
  8264. + printf("Name: %s\n", h->DisplayName);
  8265. + printf(" Display: %p\n", (void *) h->Dpy);
  8266. + printf(" Window: 0x%x\n", (int) h->Win);
  8267. + printf(" Context: 0x%lx\n", (long) h->Context);
  8268. + printf(" GL_VERSION: %s\n", h->Version);
  8269. + printf(" GL_VENDOR: %s\n", h->Vendor);
  8270. + printf(" GL_RENDERER: %s\n", h->Renderer);
  8271. +}
  8272. +
  8273. +
  8274. +int
  8275. +main(int argc, char *argv[])
  8276. +{
  8277. + char *dpyName = NULL;
  8278. + int i;
  8279. +
  8280. + if (argc == 1) {
  8281. + printf("manywin: open N simultaneous glx windows\n");
  8282. + printf("Usage:\n");
  8283. + printf(" manywin [-s] numWindows\n");
  8284. + printf("Options:\n");
  8285. + printf(" -s = swap immediately after drawing (see src code)\n");
  8286. + printf("Example:\n");
  8287. + printf(" manywin 10\n");
  8288. + return 0;
  8289. + }
  8290. + else {
  8291. + int n = 3;
  8292. + for (i = 1; i < argc; i++) {
  8293. + if (strcmp(argv[i], "-s") == 0) {
  8294. + SwapSeparate = GL_FALSE;
  8295. + }
  8296. + else if (strcmp(argv[i], "-display") == 0 && i < argc) {
  8297. + dpyName = argv[i+1];
  8298. + i++;
  8299. + }
  8300. + else {
  8301. + n = atoi(argv[i]);
  8302. + }
  8303. + }
  8304. + if (n < 1)
  8305. + n = 1;
  8306. + if (n > MAX_HEADS)
  8307. + n = MAX_HEADS;
  8308. +
  8309. + printf("%d windows\n", n);
  8310. + for (i = 0; i < n; i++) {
  8311. + char name[100];
  8312. + struct head *h;
  8313. + sprintf(name, "%d", i);
  8314. + h = AddHead(dpyName, name);
  8315. + if (h) {
  8316. + PrintInfo(h);
  8317. + }
  8318. + }
  8319. + }
  8320. +
  8321. + EventLoop();
  8322. + DestroyHeads();
  8323. + return 0;
  8324. +}
  8325. diff -Naurp Mesa-7.8.1/progs/xdemos/msctest.c Mesa-7.8.1.patched/progs/xdemos/msctest.c
  8326. --- Mesa-7.8.1/progs/xdemos/msctest.c 1970-01-01 01:00:00.000000000 +0100
  8327. +++ Mesa-7.8.1.patched/progs/xdemos/msctest.c 2010-06-13 13:45:06.789793146 +0200
  8328. @@ -0,0 +1,195 @@
  8329. +/*
  8330. + * Copyright © 2009 Intel Corporation
  8331. + *
  8332. + * Permission is hereby granted, free of charge, to any person obtaining a
  8333. + * copy of this software and associated documentation files (the "Software"),
  8334. + * to deal in the Software without restriction, including without limitation
  8335. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8336. + * and/or sell copies of the Software, and to permit persons to whom the
  8337. + * Software is furnished to do so, subject to the following conditions:
  8338. + *
  8339. + * The above copyright notice and this permission notice (including the next
  8340. + * paragraph) shall be included in all copies or substantial portions of the
  8341. + * Software.
  8342. + *
  8343. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  8344. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  8345. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  8346. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  8347. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  8348. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  8349. + * IN THE SOFTWARE.
  8350. + *
  8351. + * Authors:
  8352. + * Jesse Barnes <jesse.barnes@intel.com>
  8353. + *
  8354. + */
  8355. +
  8356. +/** @file msctest.c
  8357. + * Simple test for MSC functionality.
  8358. + */
  8359. +#include <stdio.h>
  8360. +#include <stdlib.h>
  8361. +#include <string.h>
  8362. +#include <unistd.h>
  8363. +#include <GL/gl.h>
  8364. +#include <GL/glu.h>
  8365. +#include <GL/glx.h>
  8366. +#include <GL/glxext.h>
  8367. +#include <X11/X.h>
  8368. +#include <X11/Xlib.h>
  8369. +#include <X11/Xutil.h>
  8370. +
  8371. +void (*get_sync_values)(Display *dpy, Window winGL, int64_t *ust, int64_t *msc, int64_t *sbc);
  8372. +void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc);
  8373. +
  8374. +static int GLXExtensionSupported(Display *dpy, const char *extension)
  8375. +{
  8376. + const char *extensionsString, *pos;
  8377. +
  8378. + extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
  8379. +
  8380. + pos = strstr(extensionsString, extension);
  8381. +
  8382. + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
  8383. + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
  8384. + return 1;
  8385. +
  8386. + return 0;
  8387. +}
  8388. +
  8389. +extern char *optarg;
  8390. +extern int optind, opterr, optopt;
  8391. +static char optstr[] = "v";
  8392. +
  8393. +static void usage(char *name)
  8394. +{
  8395. + printf("usage: %s\n", name);
  8396. + exit(-1);
  8397. +}
  8398. +
  8399. +int main(int argc, char *argv[])
  8400. +{
  8401. + Display *disp;
  8402. + XVisualInfo *pvi;
  8403. + XSetWindowAttributes swa;
  8404. + int attrib[14];
  8405. + Window winGL;
  8406. + GLXContext context;
  8407. + int dummy;
  8408. + Atom wmDelete;
  8409. + int verbose = 0, width = 200, height = 200;
  8410. + int c, i = 1;
  8411. + int64_t ust, msc, sbc;
  8412. +
  8413. + opterr = 0;
  8414. + while ((c = getopt(argc, argv, optstr)) != -1) {
  8415. + switch (c) {
  8416. + case 'v':
  8417. + verbose = 1;
  8418. + break;
  8419. + default:
  8420. + usage(argv[0]);
  8421. + break;
  8422. + }
  8423. + }
  8424. +
  8425. + disp = XOpenDisplay(NULL);
  8426. + if (!disp) {
  8427. + fprintf(stderr, "failed to open display\n");
  8428. + return -1;
  8429. + }
  8430. +
  8431. + if (!glXQueryExtension(disp, &dummy, &dummy)) {
  8432. + fprintf(stderr, "glXQueryExtension failed\n");
  8433. + return -1;
  8434. + }
  8435. +
  8436. + if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) {
  8437. + fprintf(stderr, "GLX_OML_sync_control not supported, exiting\n");
  8438. + return -1;
  8439. + }
  8440. +
  8441. + attrib[0] = GLX_RGBA;
  8442. + attrib[1] = 1;
  8443. + attrib[2] = GLX_RED_SIZE;
  8444. + attrib[3] = 1;
  8445. + attrib[4] = GLX_GREEN_SIZE;
  8446. + attrib[5] = 1;
  8447. + attrib[6] = GLX_BLUE_SIZE;
  8448. + attrib[7] = 1;
  8449. + attrib[8] = GLX_DOUBLEBUFFER;
  8450. + attrib[9] = 1;
  8451. + attrib[10] = None;
  8452. +
  8453. + pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
  8454. + if (!pvi) {
  8455. + fprintf(stderr, "failed to choose visual, exiting\n");
  8456. + return -1;
  8457. + }
  8458. +
  8459. + context = glXCreateContext(disp, pvi, None, GL_TRUE);
  8460. + if (!context) {
  8461. + fprintf(stderr, "failed to create glx context\n");
  8462. + return -1;
  8463. + }
  8464. +
  8465. + pvi->screen = DefaultScreen(disp);
  8466. +
  8467. + swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
  8468. + pvi->visual, AllocNone);
  8469. + swa.border_pixel = 0;
  8470. + swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
  8471. + StructureNotifyMask;
  8472. + winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
  8473. + 0, 0,
  8474. + width, height,
  8475. + 0, pvi->depth, InputOutput, pvi->visual,
  8476. + CWBorderPixel | CWColormap | CWEventMask, &swa);
  8477. + if (!winGL) {
  8478. + fprintf(stderr, "window creation failed\n");
  8479. + return -1;
  8480. + }
  8481. + wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
  8482. + XSetWMProtocols(disp, winGL, &wmDelete, 1);
  8483. +
  8484. + XSetStandardProperties(disp, winGL, "msc test", "msc text",
  8485. + None, NULL, 0, NULL);
  8486. +
  8487. + XMapRaised(disp, winGL);
  8488. +
  8489. + glXMakeCurrent(disp, winGL, context);
  8490. +
  8491. + get_sync_values = (void *)glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
  8492. + wait_sync = (void *)glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
  8493. +
  8494. + if (!get_sync_values || !wait_sync) {
  8495. + fprintf(stderr, "failed to get sync values function\n");
  8496. + return -1;
  8497. + }
  8498. +
  8499. + while (i++) {
  8500. + get_sync_values(disp, winGL, &ust, &msc, &sbc);
  8501. + fprintf(stderr, "ust: %llu, msc: %llu, sbc: %llu\n", ust, msc,
  8502. + sbc);
  8503. +
  8504. + /* Alternate colors to make tearing obvious */
  8505. + if (i & 1)
  8506. + glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  8507. + else
  8508. + glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
  8509. + glClear(GL_COLOR_BUFFER_BIT);
  8510. + glXSwapBuffers(disp, winGL);
  8511. + wait_sync(disp, winGL, 0, 60, 0, &ust, &msc, &sbc);
  8512. + fprintf(stderr,
  8513. + "wait returned ust: %llu, msc: %llu, sbc: %llu\n",
  8514. + ust, msc, sbc);
  8515. + sleep(1);
  8516. + }
  8517. +
  8518. + XDestroyWindow(disp, winGL);
  8519. + glXDestroyContext(disp, context);
  8520. + XCloseDisplay(disp);
  8521. +
  8522. + return 0;
  8523. +}
  8524. diff -Naurp Mesa-7.8.1/progs/xdemos/multictx.c Mesa-7.8.1.patched/progs/xdemos/multictx.c
  8525. --- Mesa-7.8.1/progs/xdemos/multictx.c 1970-01-01 01:00:00.000000000 +0100
  8526. +++ Mesa-7.8.1.patched/progs/xdemos/multictx.c 2010-06-13 13:45:06.789793146 +0200
  8527. @@ -0,0 +1,585 @@
  8528. +/*
  8529. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
  8530. + *
  8531. + * Permission is hereby granted, free of charge, to any person obtaining a
  8532. + * copy of this software and associated documentation files (the "Software"),
  8533. + * to deal in the Software without restriction, including without limitation
  8534. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8535. + * and/or sell copies of the Software, and to permit persons to whom the
  8536. + * Software is furnished to do so, subject to the following conditions:
  8537. + *
  8538. + * The above copyright notice and this permission notice shall be included
  8539. + * in all copies or substantial portions of the Software.
  8540. + *
  8541. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8542. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  8543. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  8544. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  8545. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  8546. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  8547. + */
  8548. +
  8549. +/*
  8550. + * Test rendering with two contexts into one window.
  8551. + * Setup different rendering state for each context to check that
  8552. + * context switching is handled properly.
  8553. + *
  8554. + * Brian Paul
  8555. + * 6 Aug 2009
  8556. + */
  8557. +
  8558. +
  8559. +#include <math.h>
  8560. +#include <stdlib.h>
  8561. +#include <stdio.h>
  8562. +#include <string.h>
  8563. +#include <sys/time.h>
  8564. +#include <unistd.h>
  8565. +#include <X11/Xlib.h>
  8566. +#include <X11/keysym.h>
  8567. +#include <GL/gl.h>
  8568. +#include <GL/glx.h>
  8569. +
  8570. +
  8571. +
  8572. +#ifndef M_PI
  8573. +#define M_PI 3.14159265
  8574. +#endif
  8575. +
  8576. +
  8577. +/** Event handler results: */
  8578. +#define NOP 0
  8579. +#define EXIT 1
  8580. +#define DRAW 2
  8581. +
  8582. +static GLfloat view_rotx = 0.0, view_roty = 210.0, view_rotz = 0.0;
  8583. +static GLint gear1, gear2;
  8584. +static GLfloat angle = 0.0;
  8585. +
  8586. +static GLboolean animate = GL_TRUE; /* Animation */
  8587. +
  8588. +
  8589. +static double
  8590. +current_time(void)
  8591. +{
  8592. + struct timeval tv;
  8593. +#ifdef __VMS
  8594. + (void) gettimeofday(&tv, NULL );
  8595. +#else
  8596. + struct timezone tz;
  8597. + (void) gettimeofday(&tv, &tz);
  8598. +#endif
  8599. + return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  8600. +}
  8601. +
  8602. +
  8603. +/*
  8604. + *
  8605. + * Draw a gear wheel. You'll probably want to call this function when
  8606. + * building a display list since we do a lot of trig here.
  8607. + *
  8608. + * Input: inner_radius - radius of hole at center
  8609. + * outer_radius - radius at center of teeth
  8610. + * width - width of gear
  8611. + * teeth - number of teeth
  8612. + * tooth_depth - depth of tooth
  8613. + */
  8614. +static void
  8615. +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  8616. + GLint teeth, GLfloat tooth_depth)
  8617. +{
  8618. + GLint i;
  8619. + GLfloat r0, r1, r2;
  8620. + GLfloat angle, da;
  8621. + GLfloat u, v, len;
  8622. +
  8623. + r0 = inner_radius;
  8624. + r1 = outer_radius - tooth_depth / 2.0;
  8625. + r2 = outer_radius + tooth_depth / 2.0;
  8626. +
  8627. + da = 2.0 * M_PI / teeth / 4.0;
  8628. +
  8629. + glShadeModel(GL_FLAT);
  8630. +
  8631. + glNormal3f(0.0, 0.0, 1.0);
  8632. +
  8633. + /* draw front face */
  8634. + glBegin(GL_QUAD_STRIP);
  8635. + for (i = 0; i <= teeth; i++) {
  8636. + angle = i * 2.0 * M_PI / teeth;
  8637. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  8638. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  8639. + if (i < teeth) {
  8640. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  8641. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8642. + width * 0.5);
  8643. + }
  8644. + }
  8645. + glEnd();
  8646. +
  8647. + /* draw front sides of teeth */
  8648. + glBegin(GL_QUADS);
  8649. + da = 2.0 * M_PI / teeth / 4.0;
  8650. + for (i = 0; i < teeth; i++) {
  8651. + angle = i * 2.0 * M_PI / teeth;
  8652. +
  8653. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  8654. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  8655. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  8656. + width * 0.5);
  8657. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8658. + width * 0.5);
  8659. + }
  8660. + glEnd();
  8661. +
  8662. + glNormal3f(0.0, 0.0, -1.0);
  8663. +
  8664. + /* draw back face */
  8665. + glBegin(GL_QUAD_STRIP);
  8666. + for (i = 0; i <= teeth; i++) {
  8667. + angle = i * 2.0 * M_PI / teeth;
  8668. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  8669. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  8670. + if (i < teeth) {
  8671. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8672. + -width * 0.5);
  8673. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  8674. + }
  8675. + }
  8676. + glEnd();
  8677. +
  8678. + /* draw back sides of teeth */
  8679. + glBegin(GL_QUADS);
  8680. + da = 2.0 * M_PI / teeth / 4.0;
  8681. + for (i = 0; i < teeth; i++) {
  8682. + angle = i * 2.0 * M_PI / teeth;
  8683. +
  8684. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8685. + -width * 0.5);
  8686. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  8687. + -width * 0.5);
  8688. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  8689. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  8690. + }
  8691. + glEnd();
  8692. +
  8693. + /* draw outward faces of teeth */
  8694. + glBegin(GL_QUAD_STRIP);
  8695. + for (i = 0; i < teeth; i++) {
  8696. + angle = i * 2.0 * M_PI / teeth;
  8697. +
  8698. + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  8699. + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  8700. + u = r2 * cos(angle + da) - r1 * cos(angle);
  8701. + v = r2 * sin(angle + da) - r1 * sin(angle);
  8702. + len = sqrt(u * u + v * v);
  8703. + u /= len;
  8704. + v /= len;
  8705. + glNormal3f(v, -u, 0.0);
  8706. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  8707. + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  8708. + glNormal3f(cos(angle), sin(angle), 0.0);
  8709. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  8710. + width * 0.5);
  8711. + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  8712. + -width * 0.5);
  8713. + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  8714. + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  8715. + glNormal3f(v, -u, 0.0);
  8716. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8717. + width * 0.5);
  8718. + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  8719. + -width * 0.5);
  8720. + glNormal3f(cos(angle), sin(angle), 0.0);
  8721. + }
  8722. +
  8723. + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  8724. + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  8725. +
  8726. + glEnd();
  8727. +
  8728. + glShadeModel(GL_SMOOTH);
  8729. +
  8730. + /* draw inside radius cylinder */
  8731. + glBegin(GL_QUAD_STRIP);
  8732. + for (i = 0; i <= teeth; i++) {
  8733. + angle = i * 2.0 * M_PI / teeth;
  8734. + glNormal3f(-cos(angle), -sin(angle), 0.0);
  8735. + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  8736. + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  8737. + }
  8738. + glEnd();
  8739. +}
  8740. +
  8741. +
  8742. +static void
  8743. +draw(int ctx)
  8744. +{
  8745. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  8746. +
  8747. + glPushMatrix();
  8748. + glRotatef(view_rotx, 1.0, 0.0, 0.0);
  8749. + glRotatef(view_roty + angle, 0.0, 1.0, 0.0);
  8750. + glRotatef(view_rotz, 0.0, 0.0, 1.0);
  8751. +
  8752. + if (ctx == 0) {
  8753. + glDisable(GL_CULL_FACE);
  8754. + glPushMatrix();
  8755. + glRotatef(angle, 0.0, 0.0, 1.0);
  8756. + glCallList(gear1);
  8757. + glPopMatrix();
  8758. + /* This should not effect the other context's rendering */
  8759. + glEnable(GL_CULL_FACE);
  8760. + glCullFace(GL_FRONT_AND_BACK);
  8761. + }
  8762. + else {
  8763. + glPushMatrix();
  8764. + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  8765. + glCallList(gear2);
  8766. + glPopMatrix();
  8767. + }
  8768. +
  8769. + glPopMatrix();
  8770. +
  8771. + /* this flush is important since we'll be switching contexts next */
  8772. + glFlush();
  8773. +}
  8774. +
  8775. +
  8776. +
  8777. +static void
  8778. +draw_frame(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2)
  8779. +{
  8780. + static double tRot0 = -1.0;
  8781. + double dt, t = current_time();
  8782. +
  8783. + if (tRot0 < 0.0)
  8784. + tRot0 = t;
  8785. + dt = t - tRot0;
  8786. + tRot0 = t;
  8787. +
  8788. + if (animate) {
  8789. + /* advance rotation for next frame */
  8790. + angle += 70.0 * dt; /* 70 degrees per second */
  8791. + if (angle > 3600.0)
  8792. + angle -= 3600.0;
  8793. + }
  8794. +
  8795. + glXMakeCurrent(dpy, (GLXDrawable) win, ctx1);
  8796. + draw(0);
  8797. +
  8798. + glXMakeCurrent(dpy, (GLXDrawable) win, ctx2);
  8799. + draw(1);
  8800. +
  8801. + glXSwapBuffers(dpy, win);
  8802. +}
  8803. +
  8804. +
  8805. +/* new window size or exposure */
  8806. +static void
  8807. +reshape(Display *dpy, Window win,
  8808. + GLXContext ctx1, GLXContext ctx2, int width, int height)
  8809. +{
  8810. + int i;
  8811. +
  8812. + width /= 2;
  8813. +
  8814. + /* loop: left half of window, right half of window */
  8815. + for (i = 0; i < 2; i++) {
  8816. + if (i == 0)
  8817. + glXMakeCurrent(dpy, win, ctx1);
  8818. + else
  8819. + glXMakeCurrent(dpy, win, ctx2);
  8820. +
  8821. + glViewport(width * i, 0, width, height);
  8822. + glScissor(width * i, 0, width, height);
  8823. +
  8824. + {
  8825. + GLfloat h = (GLfloat) height / (GLfloat) width;
  8826. +
  8827. + glMatrixMode(GL_PROJECTION);
  8828. + glLoadIdentity();
  8829. + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  8830. + }
  8831. +
  8832. + glMatrixMode(GL_MODELVIEW);
  8833. + glLoadIdentity();
  8834. + glTranslatef(0.0, 0.0, -30.0);
  8835. + }
  8836. +}
  8837. +
  8838. +
  8839. +
  8840. +static void
  8841. +init(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2)
  8842. +{
  8843. + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  8844. + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  8845. + static GLfloat green[4] = { 0.0, 0.8, 0.2, 0.5 };
  8846. + /*static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };*/
  8847. +
  8848. + /* first ctx */
  8849. + {
  8850. + static GLuint stipple[32] = {
  8851. + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff,
  8852. + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff,
  8853. +
  8854. + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
  8855. + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
  8856. +
  8857. + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff,
  8858. + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff,
  8859. +
  8860. + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
  8861. + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00
  8862. + };
  8863. +
  8864. + glXMakeCurrent(dpy, win, ctx1);
  8865. +
  8866. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  8867. + glEnable(GL_LIGHTING);
  8868. + glEnable(GL_LIGHT0);
  8869. + glEnable(GL_DEPTH_TEST);
  8870. +
  8871. + gear1 = glGenLists(1);
  8872. + glNewList(gear1, GL_COMPILE);
  8873. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  8874. + gear(1.0, 4.0, 1.0, 20, 0.7);
  8875. + glEndList();
  8876. +
  8877. + glEnable(GL_NORMALIZE);
  8878. + glEnable(GL_SCISSOR_TEST);
  8879. + glClearColor(0.4, 0.4, 0.4, 1.0);
  8880. +
  8881. + glPolygonStipple((GLubyte *) stipple);
  8882. + glEnable(GL_POLYGON_STIPPLE);
  8883. + }
  8884. +
  8885. + /* second ctx */
  8886. + {
  8887. + glXMakeCurrent(dpy, win, ctx2);
  8888. +
  8889. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  8890. + glEnable(GL_LIGHTING);
  8891. + glEnable(GL_LIGHT0);
  8892. + glEnable(GL_DEPTH_TEST);
  8893. +
  8894. + gear2 = glGenLists(1);
  8895. + glNewList(gear2, GL_COMPILE);
  8896. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  8897. + gear(1.5, 3.0, 1.5, 16, 0.7);
  8898. + glEndList();
  8899. +
  8900. + glEnable(GL_NORMALIZE);
  8901. + glEnable(GL_SCISSOR_TEST);
  8902. + glClearColor(0.6, 0.6, 0.6, 1.0);
  8903. +
  8904. + glEnable(GL_BLEND);
  8905. + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  8906. + }
  8907. +}
  8908. +
  8909. +
  8910. +/**
  8911. + * Create an RGB, double-buffered window.
  8912. + * Return the window and two context handles.
  8913. + */
  8914. +static void
  8915. +make_window_and_contexts( Display *dpy, const char *name,
  8916. + int x, int y, int width, int height,
  8917. + Window *winRet,
  8918. + GLXContext *ctxRet1,
  8919. + GLXContext *ctxRet2)
  8920. +{
  8921. + int attribs[] = { GLX_RGBA,
  8922. + GLX_RED_SIZE, 1,
  8923. + GLX_GREEN_SIZE, 1,
  8924. + GLX_BLUE_SIZE, 1,
  8925. + GLX_DOUBLEBUFFER,
  8926. + GLX_DEPTH_SIZE, 1,
  8927. + None };
  8928. + int scrnum;
  8929. + XSetWindowAttributes attr;
  8930. + unsigned long mask;
  8931. + Window root;
  8932. + Window win;
  8933. + XVisualInfo *visinfo;
  8934. +
  8935. + scrnum = DefaultScreen( dpy );
  8936. + root = RootWindow( dpy, scrnum );
  8937. +
  8938. + visinfo = glXChooseVisual( dpy, scrnum, attribs );
  8939. + if (!visinfo) {
  8940. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  8941. + exit(1);
  8942. + }
  8943. +
  8944. + /* window attributes */
  8945. + attr.background_pixel = 0;
  8946. + attr.border_pixel = 0;
  8947. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  8948. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  8949. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  8950. +
  8951. + win = XCreateWindow( dpy, root, x, y, width, height,
  8952. + 0, visinfo->depth, InputOutput,
  8953. + visinfo->visual, mask, &attr );
  8954. +
  8955. + /* set hints and properties */
  8956. + {
  8957. + XSizeHints sizehints;
  8958. + sizehints.x = x;
  8959. + sizehints.y = y;
  8960. + sizehints.width = width;
  8961. + sizehints.height = height;
  8962. + sizehints.flags = USSize | USPosition;
  8963. + XSetNormalHints(dpy, win, &sizehints);
  8964. + XSetStandardProperties(dpy, win, name, name,
  8965. + None, (char **)NULL, 0, &sizehints);
  8966. + }
  8967. +
  8968. + *winRet = win;
  8969. + *ctxRet1 = glXCreateContext( dpy, visinfo, NULL, True );
  8970. + *ctxRet2 = glXCreateContext( dpy, visinfo, NULL, True );
  8971. +
  8972. + if (!*ctxRet1 || !*ctxRet2) {
  8973. + printf("Error: glXCreateContext failed\n");
  8974. + exit(1);
  8975. + }
  8976. +
  8977. + XFree(visinfo);
  8978. +}
  8979. +
  8980. +
  8981. +/**
  8982. + * Handle one X event.
  8983. + * \return NOP, EXIT or DRAW
  8984. + */
  8985. +static int
  8986. +handle_event(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2,
  8987. + XEvent *event)
  8988. +{
  8989. + (void) dpy;
  8990. + (void) win;
  8991. +
  8992. + switch (event->type) {
  8993. + case Expose:
  8994. + return DRAW;
  8995. + case ConfigureNotify:
  8996. + reshape(dpy, win, ctx1, ctx2,
  8997. + event->xconfigure.width, event->xconfigure.height);
  8998. + break;
  8999. + case KeyPress:
  9000. + {
  9001. + char buffer[10];
  9002. + int r, code;
  9003. + code = XLookupKeysym(&event->xkey, 0);
  9004. + if (code == XK_Left) {
  9005. + view_roty += 5.0;
  9006. + }
  9007. + else if (code == XK_Right) {
  9008. + view_roty -= 5.0;
  9009. + }
  9010. + else if (code == XK_Up) {
  9011. + view_rotx += 5.0;
  9012. + }
  9013. + else if (code == XK_Down) {
  9014. + view_rotx -= 5.0;
  9015. + }
  9016. + else {
  9017. + r = XLookupString(&event->xkey, buffer, sizeof(buffer),
  9018. + NULL, NULL);
  9019. + if (buffer[0] == 27) {
  9020. + /* escape */
  9021. + return EXIT;
  9022. + }
  9023. + else if (buffer[0] == 'a' || buffer[0] == 'A') {
  9024. + animate = !animate;
  9025. + }
  9026. + }
  9027. + return DRAW;
  9028. + }
  9029. + }
  9030. + return NOP;
  9031. +}
  9032. +
  9033. +
  9034. +static void
  9035. +event_loop(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2)
  9036. +{
  9037. + while (1) {
  9038. + int op;
  9039. + while (!animate || XPending(dpy) > 0) {
  9040. + XEvent event;
  9041. + XNextEvent(dpy, &event);
  9042. + op = handle_event(dpy, win, ctx1, ctx2, &event);
  9043. + if (op == EXIT)
  9044. + return;
  9045. + else if (op == DRAW)
  9046. + break;
  9047. + }
  9048. +
  9049. + draw_frame(dpy, win, ctx1, ctx2);
  9050. + }
  9051. +}
  9052. +
  9053. +
  9054. +int
  9055. +main(int argc, char *argv[])
  9056. +{
  9057. + unsigned int winWidth = 800, winHeight = 400;
  9058. + int x = 0, y = 0;
  9059. + Display *dpy;
  9060. + Window win;
  9061. + GLXContext ctx1, ctx2;
  9062. + char *dpyName = NULL;
  9063. + GLboolean printInfo = GL_FALSE;
  9064. + int i;
  9065. +
  9066. + for (i = 1; i < argc; i++) {
  9067. + if (strcmp(argv[i], "-display") == 0) {
  9068. + dpyName = argv[i+1];
  9069. + i++;
  9070. + }
  9071. + else {
  9072. + return 1;
  9073. + }
  9074. + }
  9075. +
  9076. + dpy = XOpenDisplay(dpyName);
  9077. + if (!dpy) {
  9078. + printf("Error: couldn't open display %s\n",
  9079. + dpyName ? dpyName : getenv("DISPLAY"));
  9080. + return -1;
  9081. + }
  9082. +
  9083. + make_window_and_contexts(dpy, "multictx", x, y, winWidth, winHeight,
  9084. + &win, &ctx1, &ctx2);
  9085. + XMapWindow(dpy, win);
  9086. +
  9087. + if (printInfo) {
  9088. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  9089. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  9090. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  9091. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  9092. + }
  9093. +
  9094. + init(dpy, win, ctx1, ctx2);
  9095. +
  9096. + /* Set initial projection/viewing transformation.
  9097. + * We can't be sure we'll get a ConfigureNotify event when the window
  9098. + * first appears.
  9099. + */
  9100. + reshape(dpy, win, ctx1, ctx2, winWidth, winHeight);
  9101. +
  9102. + event_loop(dpy, win, ctx1, ctx2);
  9103. +
  9104. + glDeleteLists(gear1, 1);
  9105. + glDeleteLists(gear2, 1);
  9106. + glXDestroyContext(dpy, ctx1);
  9107. + glXDestroyContext(dpy, ctx2);
  9108. + XDestroyWindow(dpy, win);
  9109. + XCloseDisplay(dpy);
  9110. +
  9111. + return 0;
  9112. +}
  9113. diff -Naurp Mesa-7.8.1/progs/xdemos/offset.c Mesa-7.8.1.patched/progs/xdemos/offset.c
  9114. --- Mesa-7.8.1/progs/xdemos/offset.c 1970-01-01 01:00:00.000000000 +0100
  9115. +++ Mesa-7.8.1.patched/progs/xdemos/offset.c 2010-06-13 13:45:06.789793146 +0200
  9116. @@ -0,0 +1,343 @@
  9117. +/****************************************************************************
  9118. +Copyright 1995 by Silicon Graphics Incorporated, Mountain View, California.
  9119. +
  9120. + All Rights Reserved
  9121. +
  9122. +Permission to use, copy, modify, and distribute this software and its
  9123. +documentation for any purpose and without fee is hereby granted,
  9124. +provided that the above copyright notice appear in all copies and that
  9125. +both that copyright notice and this permission notice appear in
  9126. +supporting documentation, and that the name of Silicon Graphics not be
  9127. +used in advertising or publicity pertaining to distribution of the
  9128. +software without specific, written prior permission.
  9129. +
  9130. +SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  9131. +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  9132. +EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  9133. +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  9134. +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  9135. +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  9136. +PERFORMANCE OF THIS SOFTWARE.
  9137. +
  9138. +****************************************************************************/
  9139. +
  9140. +/*
  9141. + * Derived from code written by Kurt Akeley, November 1992
  9142. + *
  9143. + * Uses PolygonOffset to draw hidden-line images. PolygonOffset
  9144. + * shifts the z values of polygons an amount that is
  9145. + * proportional to their slope in screen z. This keeps
  9146. + * the lines, which are drawn without displacement, from
  9147. + * interacting with their respective polygons, and
  9148. + * thus eliminates line dropouts.
  9149. + *
  9150. + * The left image shows an ordinary antialiased wireframe image.
  9151. + * The center image shows an antialiased hidden-line image without
  9152. + * PolygonOffset.
  9153. + * The right image shows an antialiased hidden-line image using
  9154. + * PolygonOffset to reduce artifacts.
  9155. + *
  9156. + * Drag with a mouse button pressed to rotate the models.
  9157. + * Press the escape key to exit.
  9158. + */
  9159. +
  9160. +/*
  9161. + * Modified for OpenGL 1.1 glPolygonOffset() conventions
  9162. + */
  9163. +
  9164. +
  9165. +#include <GL/glx.h>
  9166. +#include <X11/keysym.h>
  9167. +#include <stdlib.h>
  9168. +#include <stdio.h>
  9169. +#include <string.h>
  9170. +
  9171. +#undef GL_EXT_polygon_offset /* use GL 1.1 version instead of extension */
  9172. +
  9173. +
  9174. +#ifndef EXIT_FAILURE
  9175. +# define EXIT_FAILURE 1
  9176. +#endif
  9177. +#ifndef EXIT_SUCCESS
  9178. +# define EXIT_SUCCESS 0
  9179. +#endif
  9180. +
  9181. +#define MAXQUAD 6
  9182. +
  9183. +typedef float Vertex[3];
  9184. +
  9185. +typedef Vertex Quad[4];
  9186. +
  9187. +/* data to define the six faces of a unit cube */
  9188. +Quad quads[MAXQUAD] = {
  9189. + { {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} }, /* x = 0 */
  9190. + { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} }, /* y = 0 */
  9191. + { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} }, /* z = 0 */
  9192. + { {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} }, /* x = 1 */
  9193. + { {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} }, /* y = 1 */
  9194. + { {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} } /* z = 1 */
  9195. +};
  9196. +
  9197. +#define WIREFRAME 0
  9198. +#define HIDDEN_LINE 1
  9199. +
  9200. +static void error(const char* prog, const char* msg);
  9201. +static void cubes(int mx, int my, int mode);
  9202. +static void fill(Quad quad);
  9203. +static void outline(Quad quad);
  9204. +static void draw_hidden(Quad quad, int mode, int face);
  9205. +static void process_input(Display *dpy, Window win);
  9206. +static int query_extension(char* extName);
  9207. +
  9208. +static int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
  9209. + GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None };
  9210. +
  9211. +static int dimension = 3;
  9212. +
  9213. +static float Scale = 1.0;
  9214. +
  9215. +
  9216. +int main(int argc, char** argv) {
  9217. + Display *dpy;
  9218. + XVisualInfo *vi;
  9219. + XSetWindowAttributes swa;
  9220. + Window win;
  9221. + GLXContext cx;
  9222. + GLint z;
  9223. +
  9224. + dpy = XOpenDisplay(0);
  9225. + if (!dpy) error(argv[0], "can't open display");
  9226. +
  9227. + vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
  9228. + if (!vi) error(argv[0], "no suitable visual");
  9229. +
  9230. + cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
  9231. +
  9232. + swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
  9233. + vi->visual, AllocNone);
  9234. +
  9235. + swa.border_pixel = 0;
  9236. + swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask |
  9237. + ButtonPressMask | ButtonMotionMask;
  9238. + win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 900, 300,
  9239. + 0, vi->depth, InputOutput, vi->visual,
  9240. + CWBorderPixel|CWColormap|CWEventMask, &swa);
  9241. + XStoreName(dpy, win, "hiddenline");
  9242. + XMapWindow(dpy, win);
  9243. +
  9244. + glXMakeCurrent(dpy, win, cx);
  9245. +
  9246. + /* check for the polygon offset extension */
  9247. +#ifndef GL_VERSION_1_1
  9248. + if (!query_extension("GL_EXT_polygon_offset"))
  9249. + error(argv[0], "polygon_offset extension is not available");
  9250. +#else
  9251. + (void) query_extension;
  9252. +#endif
  9253. +
  9254. + /* set up viewing parameters */
  9255. + glMatrixMode(GL_PROJECTION);
  9256. + glFrustum(-1, 1, -1, 1, 6, 20);
  9257. + glMatrixMode(GL_MODELVIEW);
  9258. + glTranslatef(0, 0, -15);
  9259. +
  9260. + /* set other relevant state information */
  9261. + glEnable(GL_DEPTH_TEST);
  9262. +
  9263. + glGetIntegerv(GL_DEPTH_BITS, &z);
  9264. + printf("GL_DEPTH_BITS = %d\n", z);
  9265. +
  9266. +#ifdef GL_EXT_polygon_offset
  9267. + printf("using 1.0 offset extension\n");
  9268. + glPolygonOffsetEXT( 1.0, 0.00001 );
  9269. +#else
  9270. + printf("using 1.1 offset\n");
  9271. + glPolygonOffset( 1.0, 0.5 );
  9272. +#endif
  9273. +
  9274. + glShadeModel( GL_FLAT );
  9275. + glDisable( GL_DITHER );
  9276. +
  9277. + /* process events until the user presses ESC */
  9278. + while (1) process_input(dpy, win);
  9279. +
  9280. + return 0;
  9281. +}
  9282. +
  9283. +static void
  9284. +draw_scene(int mx, int my) {
  9285. + glClearColor(0.25, 0.25, 0.25, 0);
  9286. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  9287. +
  9288. + glPushMatrix();
  9289. + glTranslatef(-1.7, 0.0, 0.0);
  9290. + cubes(mx, my, WIREFRAME);
  9291. + glPopMatrix();
  9292. +
  9293. + glPushMatrix();
  9294. + cubes(mx, my, HIDDEN_LINE);
  9295. + glPopMatrix();
  9296. +
  9297. + glPushMatrix();
  9298. + glTranslatef(1.7, 0.0, 0.0);
  9299. +#ifdef GL_EXT_polygon_offset
  9300. + glEnable(GL_POLYGON_OFFSET_EXT);
  9301. +#else
  9302. + glEnable(GL_POLYGON_OFFSET_FILL);
  9303. +#endif
  9304. + glScalef(Scale, Scale, Scale);
  9305. + cubes(mx, my, HIDDEN_LINE);
  9306. +#ifdef GL_EXT_polygon_offset
  9307. + glDisable(GL_POLYGON_OFFSET_EXT);
  9308. +#else
  9309. + glDisable(GL_POLYGON_OFFSET_FILL);
  9310. +#endif
  9311. + glPopMatrix();
  9312. +}
  9313. +
  9314. +
  9315. +static void
  9316. +cubes(int mx, int my, int mode) {
  9317. + int x, y, z, i;
  9318. +
  9319. + /* track the mouse */
  9320. + glRotatef(mx / 2.0, 0, 1, 0);
  9321. + glRotatef(my / 2.0, 1, 0, 0);
  9322. +
  9323. + /* draw the lines as hidden polygons */
  9324. + glTranslatef(-0.5, -0.5, -0.5);
  9325. + glScalef(1.0/dimension, 1.0/dimension, 1.0/dimension);
  9326. + for (z = 0; z < dimension; z++) {
  9327. + for (y = 0; y < dimension; y++) {
  9328. + for (x = 0; x < dimension; x++) {
  9329. + glPushMatrix();
  9330. + glTranslatef(x, y, z);
  9331. + glScalef(0.8, 0.8, 0.8);
  9332. + for (i = 0; i < MAXQUAD; i++)
  9333. + draw_hidden(quads[i], mode, i);
  9334. + glPopMatrix();
  9335. + }
  9336. + }
  9337. + }
  9338. +}
  9339. +
  9340. +static void
  9341. +fill(Quad quad) {
  9342. + /* draw a filled polygon */
  9343. + glBegin(GL_QUADS);
  9344. + glVertex3fv(quad[0]);
  9345. + glVertex3fv(quad[1]);
  9346. + glVertex3fv(quad[2]);
  9347. + glVertex3fv(quad[3]);
  9348. + glEnd();
  9349. +}
  9350. +
  9351. +static void
  9352. +outline(Quad quad) {
  9353. + /* draw an outlined polygon */
  9354. + glBegin(GL_LINE_LOOP);
  9355. + glVertex3fv(quad[0]);
  9356. + glVertex3fv(quad[1]);
  9357. + glVertex3fv(quad[2]);
  9358. + glVertex3fv(quad[3]);
  9359. + glEnd();
  9360. +}
  9361. +
  9362. +static void
  9363. +draw_hidden(Quad quad, int mode, int face) {
  9364. + static const GLfloat colors[3][3] = {
  9365. + {0.5, 0.5, 0.0},
  9366. + {0.8, 0.5, 0.0},
  9367. + {0.0, 0.5, 0.8}
  9368. + };
  9369. + if (mode == HIDDEN_LINE) {
  9370. + glColor3fv(colors[face % 3]);
  9371. + fill(quad);
  9372. + }
  9373. +
  9374. + /* draw the outline using white */
  9375. + glColor3f(1, 1, 1);
  9376. + outline(quad);
  9377. +}
  9378. +
  9379. +static void
  9380. +process_input(Display *dpy, Window win) {
  9381. + XEvent event;
  9382. + static int prevx, prevy;
  9383. + static int deltax = 90, deltay = 40;
  9384. +
  9385. + do {
  9386. + char buf[31];
  9387. + KeySym keysym;
  9388. +
  9389. + XNextEvent(dpy, &event);
  9390. + switch(event.type) {
  9391. + case Expose:
  9392. + break;
  9393. + case ConfigureNotify: {
  9394. + /* this approach preserves a 1:1 viewport aspect ratio */
  9395. + int vX, vY, vW, vH;
  9396. + int eW = event.xconfigure.width, eH = event.xconfigure.height;
  9397. + if (eW >= eH) {
  9398. + vX = 0;
  9399. + vY = (eH - eW) >> 1;
  9400. + vW = vH = eW;
  9401. + } else {
  9402. + vX = (eW - eH) >> 1;
  9403. + vY = 0;
  9404. + vW = vH = eH;
  9405. + }
  9406. + glViewport(vX, vY, vW, vH);
  9407. + }
  9408. + break;
  9409. + case KeyPress:
  9410. + (void) XLookupString(&event.xkey, buf, sizeof(buf), &keysym, NULL);
  9411. + switch (keysym) {
  9412. + case 'Z':
  9413. + Scale *= 1.1;
  9414. + break;
  9415. + case 'z':
  9416. + Scale *= 0.9;
  9417. + break;
  9418. + case XK_Escape:
  9419. + exit(EXIT_SUCCESS);
  9420. + default:
  9421. + break;
  9422. + }
  9423. + break;
  9424. + case ButtonPress:
  9425. + prevx = event.xbutton.x;
  9426. + prevy = event.xbutton.y;
  9427. + break;
  9428. + case MotionNotify:
  9429. + deltax += (event.xbutton.x - prevx); prevx = event.xbutton.x;
  9430. + deltay += (event.xbutton.y - prevy); prevy = event.xbutton.y;
  9431. + break;
  9432. + default:
  9433. + break;
  9434. + }
  9435. + } while (XPending(dpy));
  9436. +
  9437. + draw_scene(deltax, deltay);
  9438. + glXSwapBuffers(dpy, win);
  9439. +}
  9440. +
  9441. +static void
  9442. +error(const char *prog, const char *msg) {
  9443. + fprintf(stderr, "%s: %s\n", prog, msg);
  9444. + exit(EXIT_FAILURE);
  9445. +}
  9446. +
  9447. +static int
  9448. +query_extension(char* extName) {
  9449. + char *p = (char *) glGetString(GL_EXTENSIONS);
  9450. + char *end = p + strlen(p);
  9451. + while (p < end) {
  9452. + int n = strcspn(p, " ");
  9453. + if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0))
  9454. + return GL_TRUE;
  9455. + p += (n + 1);
  9456. + }
  9457. + return GL_FALSE;
  9458. +}
  9459. +
  9460. diff -Naurp Mesa-7.8.1/progs/xdemos/omlsync.c Mesa-7.8.1.patched/progs/xdemos/omlsync.c
  9461. --- Mesa-7.8.1/progs/xdemos/omlsync.c 1970-01-01 01:00:00.000000000 +0100
  9462. +++ Mesa-7.8.1.patched/progs/xdemos/omlsync.c 2010-06-13 13:45:06.788792936 +0200
  9463. @@ -0,0 +1,265 @@
  9464. +/*
  9465. + * Copyright © 2007-2010 Intel Corporation
  9466. + *
  9467. + * Permission is hereby granted, free of charge, to any person obtaining a
  9468. + * copy of this software and associated documentation files (the "Software"),
  9469. + * to deal in the Software without restriction, including without limitation
  9470. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9471. + * and/or sell copies of the Software, and to permit persons to whom the
  9472. + * Software is furnished to do so, subject to the following conditions:
  9473. + *
  9474. + * The above copyright notice and this permission notice (including the next
  9475. + * paragraph) shall be included in all copies or substantial portions of the
  9476. + * Software.
  9477. + *
  9478. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  9479. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9480. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  9481. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  9482. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  9483. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  9484. + * IN THE SOFTWARE.
  9485. + *
  9486. + * Authors:
  9487. + * Jesse Barnes <jesse.barnes@intel.com>
  9488. + *
  9489. + */
  9490. +
  9491. +/** @file omlsync.c
  9492. + * The program is simple: it paints a window alternating colors (red &
  9493. + * white) either as fast as possible or synchronized to vblank events
  9494. + *
  9495. + * If run normally, the program should display a window that exhibits
  9496. + * significant tearing between red and white colors (e.g. you might get
  9497. + * a "waterfall" effect of red and white horizontal bars).
  9498. + *
  9499. + * If run with the '-s b' option, the program should synchronize the
  9500. + * window color changes with the vertical blank period, resulting in a
  9501. + * window that looks orangish with a high frequency flicker (which may
  9502. + * be invisible). If the window is moved to another screen, this
  9503. + * property should be preserved. If the window spans two screens, it
  9504. + * shouldn't tear on whichever screen most of the window is on; the
  9505. + * portion on the other screen may show some tearing (like the
  9506. + * waterfall effect above).
  9507. + *
  9508. + * Other options include '-w <width>' and '-h <height>' to set the
  9509. + * window size.
  9510. + */
  9511. +#include <stdio.h>
  9512. +#include <stdlib.h>
  9513. +#include <string.h>
  9514. +#include <unistd.h>
  9515. +#include <GL/gl.h>
  9516. +#include <GL/glu.h>
  9517. +#include <GL/glx.h>
  9518. +#include <GL/glxext.h>
  9519. +#include <X11/X.h>
  9520. +#include <X11/Xlib.h>
  9521. +#include <X11/Xutil.h>
  9522. +
  9523. +Bool (*glXGetSyncValuesOML)(Display *dpy, GLXDrawable drawable,
  9524. + int64_t *ust, int64_t *msc, int64_t *sbc);
  9525. +Bool (*glXGetMscRateOML)(Display *dpy, GLXDrawable drawable, int32_t *numerator,
  9526. + int32_t *denominator);
  9527. +int64_t (*glXSwapBuffersMscOML)(Display *dpy, GLXDrawable drawable,
  9528. + int64_t target_msc, int64_t divisor,
  9529. + int64_t remainder);
  9530. +Bool (*glXWaitForMscOML)(Display *dpy, GLXDrawable drawable, int64_t target_msc,
  9531. + int64_t divisor, int64_t remainder, int64_t *ust,
  9532. + int64_t *msc, int64_t *sbc);
  9533. +Bool (*glXWaitForSbcOML)(Display *dpy, GLXDrawable drawable, int64_t target_sbc,
  9534. + int64_t *ust, int64_t *msc, int64_t *sbc);
  9535. +int (*glXSwapInterval)(int interval);
  9536. +
  9537. +static int GLXExtensionSupported(Display *dpy, const char *extension)
  9538. +{
  9539. + const char *extensionsString, *pos;
  9540. +
  9541. + extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
  9542. +
  9543. + pos = strstr(extensionsString, extension);
  9544. +
  9545. + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
  9546. + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
  9547. + return 1;
  9548. +
  9549. + return 0;
  9550. +}
  9551. +
  9552. +extern char *optarg;
  9553. +extern int optind, opterr, optopt;
  9554. +static char optstr[] = "w:h:vd:r:n:i:";
  9555. +
  9556. +static void usage(char *name)
  9557. +{
  9558. + printf("usage: %s [-w <width>] [-h <height>] ...\n", name);
  9559. + printf("\t-d<divisor> - divisor for OML swap\n");
  9560. + printf("\t-r<remainder> - remainder for OML swap\n");
  9561. + printf("\t-n<interval> - wait interval for OML WaitMSC\n");
  9562. + printf("\t-i<swap interval> - swap at most once every n frames\n");
  9563. + printf("\t-v: verbose (print count)\n");
  9564. + exit(-1);
  9565. +}
  9566. +
  9567. +int main(int argc, char *argv[])
  9568. +{
  9569. + Display *disp;
  9570. + XVisualInfo *pvi;
  9571. + XSetWindowAttributes swa;
  9572. + Window winGL;
  9573. + GLXContext context;
  9574. + int dummy;
  9575. + Atom wmDelete;
  9576. + int64_t ust, msc, sbc;
  9577. + int width = 500, height = 500, verbose = 0, divisor = 0, remainder = 0,
  9578. + wait_interval = 0, swap_interval = 1;
  9579. + int c, i = 1;
  9580. + int ret;
  9581. + int db_attribs[] = { GLX_RGBA,
  9582. + GLX_RED_SIZE, 1,
  9583. + GLX_GREEN_SIZE, 1,
  9584. + GLX_BLUE_SIZE, 1,
  9585. + GLX_DOUBLEBUFFER,
  9586. + GLX_DEPTH_SIZE, 1,
  9587. + None };
  9588. + XSizeHints sizehints;
  9589. +
  9590. + opterr = 0;
  9591. + while ((c = getopt(argc, argv, optstr)) != -1) {
  9592. + switch (c) {
  9593. + case 'w':
  9594. + width = atoi(optarg);
  9595. + break;
  9596. + case 'h':
  9597. + height = atoi(optarg);
  9598. + break;
  9599. + case 'v':
  9600. + verbose = 1;
  9601. + break;
  9602. + case 'd':
  9603. + divisor = atoi(optarg);
  9604. + break;
  9605. + case 'r':
  9606. + remainder = atoi(optarg);
  9607. + break;
  9608. + case 'n':
  9609. + wait_interval = atoi(optarg);
  9610. + break;
  9611. + case 'i':
  9612. + swap_interval = atoi(optarg);
  9613. + break;
  9614. + default:
  9615. + usage(argv[0]);
  9616. + break;
  9617. + }
  9618. + }
  9619. +
  9620. + disp = XOpenDisplay(NULL);
  9621. + if (!disp) {
  9622. + fprintf(stderr, "failed to open display\n");
  9623. + return -1;
  9624. + }
  9625. +
  9626. + if (!glXQueryExtension(disp, &dummy, &dummy)) {
  9627. + fprintf(stderr, "glXQueryExtension failed\n");
  9628. + return -1;
  9629. + }
  9630. +
  9631. + if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) {
  9632. + fprintf(stderr, "GLX_OML_sync_control not supported\n");
  9633. + return -1;
  9634. + }
  9635. +
  9636. + if (!GLXExtensionSupported(disp, "GLX_MESA_swap_control")) {
  9637. + fprintf(stderr, "GLX_MESA_swap_control not supported\n");
  9638. + return -1;
  9639. + }
  9640. +
  9641. + pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs);
  9642. +
  9643. + if (!pvi) {
  9644. + fprintf(stderr, "failed to choose visual, exiting\n");
  9645. + return -1;
  9646. + }
  9647. +
  9648. + pvi->screen = DefaultScreen(disp);
  9649. +
  9650. + swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
  9651. + pvi->visual, AllocNone);
  9652. + swa.border_pixel = 0;
  9653. + swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
  9654. + StructureNotifyMask;
  9655. + winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
  9656. + 0, 0,
  9657. + width, height,
  9658. + 0, pvi->depth, InputOutput, pvi->visual,
  9659. + CWBorderPixel | CWColormap | CWEventMask, &swa);
  9660. + if (!winGL) {
  9661. + fprintf(stderr, "window creation failed\n");
  9662. + return -1;
  9663. + }
  9664. + wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
  9665. + XSetWMProtocols(disp, winGL, &wmDelete, 1);
  9666. +
  9667. + sizehints.x = 0;
  9668. + sizehints.y = 0;
  9669. + sizehints.width = width;
  9670. + sizehints.height = height;
  9671. + sizehints.flags = USSize | USPosition;
  9672. +
  9673. + XSetNormalHints(disp, winGL, &sizehints);
  9674. + XSetStandardProperties(disp, winGL, "glsync test", "glsync text",
  9675. + None, NULL, 0, &sizehints);
  9676. +
  9677. + context = glXCreateContext(disp, pvi, NULL, GL_TRUE);
  9678. + if (!context) {
  9679. + fprintf(stderr, "failed to create glx context\n");
  9680. + return -1;
  9681. + }
  9682. +
  9683. + XMapWindow(disp, winGL);
  9684. + ret = glXMakeCurrent(disp, winGL, context);
  9685. + if (!ret) {
  9686. + fprintf(stderr, "failed to make context current: %d\n", ret);
  9687. + }
  9688. +
  9689. + glXGetSyncValuesOML = (void *)glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
  9690. + glXGetMscRateOML = (void *)glXGetProcAddress((unsigned char *)"glXGetMscRateOML");
  9691. + glXSwapBuffersMscOML = (void *)glXGetProcAddress((unsigned char *)"glXSwapBuffersMscOML");
  9692. + glXWaitForMscOML = (void *)glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
  9693. + glXWaitForSbcOML = (void *)glXGetProcAddress((unsigned char *)"glXWaitForSbcOML");
  9694. + glXSwapInterval = (void *)glXGetProcAddress((unsigned char *)"glXSwapIntervalMESA");
  9695. +
  9696. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  9697. +
  9698. + glXSwapInterval(swap_interval);
  9699. + fprintf(stderr, "set swap interval to %d\n", swap_interval);
  9700. +
  9701. + glXGetSyncValuesOML(disp, winGL, &ust, &msc, &sbc);
  9702. + while (i++) {
  9703. + /* Alternate colors to make tearing obvious */
  9704. + if (i & 1) {
  9705. + glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  9706. + glColor3f(1.0f, 1.0f, 1.0f);
  9707. + } else {
  9708. + glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
  9709. + glColor3f(1.0f, 0.0f, 0.0f);
  9710. + }
  9711. +
  9712. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  9713. + glRectf(0, 0, width, height);
  9714. +
  9715. + glXSwapBuffersMscOML(disp, winGL, 0, divisor, remainder);
  9716. +
  9717. + if (wait_interval) {
  9718. + glXWaitForMscOML(disp, winGL, msc + wait_interval,
  9719. + 0, 0, &ust, &msc, &sbc);
  9720. + }
  9721. + }
  9722. +
  9723. + XDestroyWindow(disp, winGL);
  9724. + glXDestroyContext(disp, context);
  9725. + XCloseDisplay(disp);
  9726. +
  9727. + return 0;
  9728. +}
  9729. diff -Naurp Mesa-7.8.1/progs/xdemos/opencloseopen.c Mesa-7.8.1.patched/progs/xdemos/opencloseopen.c
  9730. --- Mesa-7.8.1/progs/xdemos/opencloseopen.c 1970-01-01 01:00:00.000000000 +0100
  9731. +++ Mesa-7.8.1.patched/progs/xdemos/opencloseopen.c 2010-06-13 13:45:06.788792936 +0200
  9732. @@ -0,0 +1,189 @@
  9733. +/*
  9734. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  9735. + * (C) Copyright IBM Corporation 2003
  9736. + *
  9737. + * Permission is hereby granted, free of charge, to any person obtaining a
  9738. + * copy of this software and associated documentation files (the "Software"),
  9739. + * to deal in the Software without restriction, including without limitation
  9740. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9741. + * and/or sell copies of the Software, and to permit persons to whom the
  9742. + * Software is furnished to do so, subject to the following conditions:
  9743. + *
  9744. + * The above copyright notice and this permission notice shall be included
  9745. + * in all copies or substantial portions of the Software.
  9746. + *
  9747. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9748. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9749. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  9750. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  9751. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  9752. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  9753. + */
  9754. +
  9755. +#include <stdlib.h>
  9756. +#include <stdio.h>
  9757. +#include <unistd.h>
  9758. +#include <string.h>
  9759. +#include <X11/Xlib.h>
  9760. +#include <GL/gl.h>
  9761. +#include <GL/glx.h>
  9762. +
  9763. +/** \file opencloseopen.c
  9764. + * Simple test for Mesa bug #508473. Create a window and rendering context.
  9765. + * Draw a single frame. Close the window, destroy the context, and close
  9766. + * the display. Re-open the display, create a new window and context. This
  9767. + * should work, but, at least as of Mesa 5.1, it segfaults. See the bug
  9768. + * report for more details.
  9769. + *
  9770. + * Most of the code here was lifed from various other Mesa xdemos.
  9771. + */
  9772. +
  9773. +static void
  9774. +draw(void)
  9775. +{
  9776. + glViewport(0, 0, 300, 300);
  9777. + glMatrixMode(GL_PROJECTION);
  9778. + glLoadIdentity();
  9779. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  9780. + glMatrixMode(GL_MODELVIEW);
  9781. +
  9782. + glShadeModel(GL_FLAT);
  9783. + glClearColor(0.5, 0.5, 0.5, 1.0);
  9784. + glClear(GL_COLOR_BUFFER_BIT);
  9785. +
  9786. + /* draw blue quad */
  9787. + glLoadIdentity();
  9788. + glColor3f(0.3, 0.3, 1.0);
  9789. + glPushMatrix();
  9790. + glRotatef(0, 0, 0, 1);
  9791. + glBegin(GL_POLYGON);
  9792. + glVertex2f(-0.5, -0.25);
  9793. + glVertex2f( 0.5, -0.25);
  9794. + glVertex2f( 0.5, 0.25);
  9795. + glVertex2f(-0.5, 0.25);
  9796. + glEnd();
  9797. + glPopMatrix();}
  9798. +
  9799. +
  9800. +/*
  9801. + * Create an RGB, double-buffered window.
  9802. + * Return the window and context handles.
  9803. + */
  9804. +static void
  9805. +make_window( const char * dpyName, const char *name,
  9806. + int x, int y, int width, int height,
  9807. + Display **dpyRet, Window *winRet, GLXContext *ctxRet)
  9808. +{
  9809. + int attrib[] = { GLX_RGBA,
  9810. + GLX_RED_SIZE, 1,
  9811. + GLX_GREEN_SIZE, 1,
  9812. + GLX_BLUE_SIZE, 1,
  9813. + GLX_DOUBLEBUFFER,
  9814. + None };
  9815. + int scrnum;
  9816. + XSetWindowAttributes attr;
  9817. + unsigned long mask;
  9818. + Window root;
  9819. + Window win;
  9820. + GLXContext ctx;
  9821. + XVisualInfo *visinfo;
  9822. + Display *dpy;
  9823. +
  9824. + dpy = XOpenDisplay(dpyName);
  9825. + if (!dpy) {
  9826. + printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
  9827. + exit(1);
  9828. + }
  9829. +
  9830. + *dpyRet = dpy;
  9831. + scrnum = DefaultScreen( dpy );
  9832. + root = RootWindow( dpy, scrnum );
  9833. +
  9834. + visinfo = glXChooseVisual( dpy, scrnum, attrib );
  9835. + if (!visinfo) {
  9836. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  9837. + exit(1);
  9838. + }
  9839. +
  9840. + /* window attributes */
  9841. + attr.background_pixel = 0;
  9842. + attr.border_pixel = 0;
  9843. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  9844. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  9845. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  9846. +
  9847. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  9848. + 0, visinfo->depth, InputOutput,
  9849. + visinfo->visual, mask, &attr );
  9850. +
  9851. + /* set hints and properties */
  9852. + {
  9853. + XSizeHints sizehints;
  9854. + sizehints.x = x;
  9855. + sizehints.y = y;
  9856. + sizehints.width = width;
  9857. + sizehints.height = height;
  9858. + sizehints.flags = USSize | USPosition;
  9859. + XSetNormalHints(dpy, win, &sizehints);
  9860. + XSetStandardProperties(dpy, win, name, name,
  9861. + None, (char **)NULL, 0, &sizehints);
  9862. + }
  9863. +
  9864. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  9865. + if (!ctx) {
  9866. + printf("Error: glXCreateContext failed\n");
  9867. + exit(1);
  9868. + }
  9869. +
  9870. + XFree(visinfo);
  9871. +
  9872. + *winRet = win;
  9873. + *ctxRet = ctx;
  9874. +}
  9875. +
  9876. +
  9877. +static void
  9878. +destroy_window( Display *dpy, Window win, GLXContext ctx )
  9879. +{
  9880. + glXMakeCurrent(dpy, None, NULL);
  9881. + glXDestroyContext(dpy, ctx);
  9882. + XDestroyWindow(dpy, win);
  9883. + XCloseDisplay(dpy);
  9884. +}
  9885. +
  9886. +
  9887. +int
  9888. +main(int argc, char *argv[])
  9889. +{
  9890. + Display *dpy;
  9891. + Window win;
  9892. + GLXContext ctx;
  9893. + char *dpyName = NULL;
  9894. + int i;
  9895. +
  9896. + for (i = 1; i < argc; i++) {
  9897. + if (strcmp(argv[i], "-display") == 0) {
  9898. + dpyName = argv[i+1];
  9899. + i++;
  9900. + }
  9901. + }
  9902. +
  9903. + printf("If this program segfaults, then Mesa bug #508473 is probably "
  9904. + "back.\n");
  9905. + make_window(dpyName, "Open-close-open", 0, 0, 300, 300, &dpy, &win, &ctx);
  9906. + XMapWindow(dpy, win);
  9907. + glXMakeCurrent(dpy, win, ctx);
  9908. +
  9909. + draw();
  9910. + glXSwapBuffers(dpy, win);
  9911. + sleep(2);
  9912. +
  9913. + destroy_window(dpy, win, ctx);
  9914. +
  9915. + make_window(dpyName, "Open-close-open", 0, 0, 300, 300, &dpy, &win, &ctx);
  9916. + XMapWindow(dpy, win);
  9917. + glXMakeCurrent(dpy, win, ctx);
  9918. + destroy_window(dpy, win, ctx);
  9919. +
  9920. + return 0;
  9921. +}
  9922. diff -Naurp Mesa-7.8.1/progs/xdemos/overlay.c Mesa-7.8.1.patched/progs/xdemos/overlay.c
  9923. --- Mesa-7.8.1/progs/xdemos/overlay.c 1970-01-01 01:00:00.000000000 +0100
  9924. +++ Mesa-7.8.1.patched/progs/xdemos/overlay.c 2010-06-13 13:45:06.789793146 +0200
  9925. @@ -0,0 +1,246 @@
  9926. +/*
  9927. + * GLX overlay test/demo.
  9928. + *
  9929. + * Brian Paul
  9930. + * 18 July 2005
  9931. + */
  9932. +
  9933. +#include <GL/gl.h>
  9934. +#include <GL/glx.h>
  9935. +#include <X11/keysym.h>
  9936. +#include <assert.h>
  9937. +#include <stdio.h>
  9938. +#include <stdlib.h>
  9939. +
  9940. +static int WinWidth = 300, WinHeight = 300;
  9941. +static Window NormalWindow = 0;
  9942. +static Window OverlayWindow = 0;
  9943. +static GLXContext NormalContext = 0;
  9944. +static GLXContext OverlayContext = 0;
  9945. +static GLboolean RGBOverlay = GL_FALSE;
  9946. +static GLfloat Angle = 0.0;
  9947. +
  9948. +
  9949. +static void
  9950. +RedrawNormal(Display *dpy)
  9951. +{
  9952. + glXMakeCurrent(dpy, NormalWindow, NormalContext);
  9953. + glViewport(0, 0, WinWidth, WinHeight);
  9954. + glMatrixMode(GL_PROJECTION);
  9955. + glLoadIdentity();
  9956. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  9957. + glMatrixMode(GL_MODELVIEW);
  9958. + glClearColor(0.5, 0.5, 0.5, 1.0);
  9959. + glClear(GL_COLOR_BUFFER_BIT);
  9960. + glColor3f(1.0, 1.0, 0.0);
  9961. + glPushMatrix();
  9962. + glRotatef(Angle, 0, 0, 1);
  9963. + glRectf(-0.8, -0.8, 0.8, 0.8);
  9964. + glPopMatrix();
  9965. + glXSwapBuffers(dpy, NormalWindow);
  9966. +}
  9967. +
  9968. +
  9969. +static void
  9970. +RedrawOverlay(Display *dpy)
  9971. +{
  9972. + glXMakeCurrent(dpy, OverlayWindow, OverlayContext);
  9973. + glViewport(0, 0, WinWidth, WinHeight);
  9974. + glMatrixMode(GL_PROJECTION);
  9975. + glLoadIdentity();
  9976. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  9977. + glMatrixMode(GL_MODELVIEW);
  9978. + glClear(GL_COLOR_BUFFER_BIT);
  9979. + if (RGBOverlay) {
  9980. + glColor3f(0.0, 1.0, 1.0);
  9981. + }
  9982. + else {
  9983. + glIndexi(2);
  9984. + }
  9985. + glBegin(GL_LINES);
  9986. + glVertex2f(-1, -1);
  9987. + glVertex2f(1, 1);
  9988. + glVertex2f(1, -1);
  9989. + glVertex2f(-1, 1);
  9990. + glEnd();
  9991. + glXSwapBuffers(dpy, OverlayWindow);
  9992. +}
  9993. +
  9994. +
  9995. +static Window
  9996. +MakeWindow(Display *dpy, XVisualInfo *visinfo, Window parent,
  9997. + unsigned int width, unsigned int height)
  9998. +{
  9999. + int scrnum;
  10000. + XSetWindowAttributes attr;
  10001. + unsigned long mask;
  10002. + Window root;
  10003. + Window win;
  10004. +
  10005. + scrnum = DefaultScreen(dpy);
  10006. + root = RootWindow(dpy, scrnum);
  10007. +
  10008. + /* window attributes */
  10009. + attr.background_pixel = 0;
  10010. + attr.border_pixel = 0;
  10011. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  10012. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  10013. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  10014. +
  10015. + win = XCreateWindow(dpy, parent, 0, 0, width, height,
  10016. + 0, visinfo->depth, InputOutput,
  10017. + visinfo->visual, mask, &attr);
  10018. + return win;
  10019. +}
  10020. +
  10021. +
  10022. +static void
  10023. +MakeNormalWindow(Display *dpy)
  10024. +{
  10025. + int attrib[] = { GLX_RGBA,
  10026. + GLX_RED_SIZE, 1,
  10027. + GLX_GREEN_SIZE, 1,
  10028. + GLX_BLUE_SIZE, 1,
  10029. + GLX_DOUBLEBUFFER,
  10030. + None };
  10031. + int scrnum;
  10032. + Window root;
  10033. + XVisualInfo *visinfo;
  10034. +
  10035. + scrnum = DefaultScreen(dpy);
  10036. + root = RootWindow(dpy, scrnum);
  10037. +
  10038. + visinfo = glXChooseVisual(dpy, scrnum, attrib);
  10039. + if (!visinfo) {
  10040. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  10041. + exit(1);
  10042. + }
  10043. +
  10044. + NormalWindow = MakeWindow(dpy, visinfo, root, WinWidth, WinHeight);
  10045. + assert(NormalWindow);
  10046. +
  10047. + NormalContext = glXCreateContext(dpy, visinfo, NULL, True);
  10048. + assert(NormalContext);
  10049. +}
  10050. +
  10051. +
  10052. +static void
  10053. +MakeOverlayWindow(Display *dpy)
  10054. +{
  10055. + int rgbAttribs[] = {
  10056. + GLX_RGBA,
  10057. + GLX_RED_SIZE, 1,
  10058. + GLX_GREEN_SIZE, 1,
  10059. + GLX_BLUE_SIZE, 1,
  10060. + GLX_DOUBLEBUFFER,
  10061. + GLX_LEVEL, 1,
  10062. + None
  10063. + };
  10064. + int indexAttribs[] = {
  10065. + /*GLX_RGBA, leave this out */
  10066. + GLX_RED_SIZE, 1,
  10067. + GLX_GREEN_SIZE, 1,
  10068. + GLX_BLUE_SIZE, 1,
  10069. + GLX_DOUBLEBUFFER,
  10070. + GLX_LEVEL, 1,
  10071. + None
  10072. + };
  10073. + int scrnum;
  10074. + Window root;
  10075. + XVisualInfo *visinfo;
  10076. +
  10077. + scrnum = DefaultScreen(dpy);
  10078. + root = RootWindow(dpy, scrnum);
  10079. +
  10080. + visinfo = glXChooseVisual(dpy, scrnum, rgbAttribs);
  10081. + if (visinfo) {
  10082. + printf("Found RGB overlay visual 0x%x\n", (int) visinfo->visualid);
  10083. + RGBOverlay = GL_TRUE;
  10084. + }
  10085. + else {
  10086. + visinfo = glXChooseVisual(dpy, scrnum, indexAttribs);
  10087. + if (visinfo) {
  10088. + printf("Found Color Index overlay visual 0x%x\n",
  10089. + (int) visinfo->visualid);
  10090. + /* XXX setup the colormap entries! */
  10091. + }
  10092. + else {
  10093. + printf("Couldn't get an overlay visual.\n");
  10094. + printf("Your hardware probably doesn't support framebuffer overlay planes.\n");
  10095. + exit(1);
  10096. + }
  10097. + }
  10098. +
  10099. + OverlayWindow = MakeWindow(dpy, visinfo, NormalWindow, WinWidth, WinHeight);
  10100. + assert(OverlayWindow);
  10101. +
  10102. + OverlayContext = glXCreateContext(dpy, visinfo, NULL, True);
  10103. + assert(OverlayContext);
  10104. +}
  10105. +
  10106. +
  10107. +static void
  10108. +EventLoop(Display *dpy)
  10109. +{
  10110. + XEvent event;
  10111. +
  10112. + while (1) {
  10113. + XNextEvent(dpy, &event);
  10114. +
  10115. + switch (event.type) {
  10116. + case Expose:
  10117. + RedrawNormal(dpy);
  10118. + RedrawOverlay(dpy);
  10119. + break;
  10120. + case ConfigureNotify:
  10121. + WinWidth = event.xconfigure.width;
  10122. + WinHeight = event.xconfigure.height;
  10123. + if (event.xconfigure.window == NormalWindow)
  10124. + XResizeWindow(dpy, OverlayWindow, WinWidth, WinHeight);
  10125. + break;
  10126. + case KeyPress:
  10127. + {
  10128. + char buffer[10];
  10129. + int r, code;
  10130. + code = XLookupKeysym(&event.xkey, 0);
  10131. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  10132. + NULL, NULL);
  10133. + if (buffer[0] == 27) {
  10134. + /* escape */
  10135. + return;
  10136. + }
  10137. + else if (buffer[0] == ' ') {
  10138. + Angle += 5.0;
  10139. + RedrawNormal(dpy);
  10140. + }
  10141. + }
  10142. + break;
  10143. + default:
  10144. + ; /* nothing */
  10145. + }
  10146. + }
  10147. +}
  10148. +
  10149. +
  10150. +int
  10151. +main(int argc, char *argv[])
  10152. +{
  10153. + Display *dpy = XOpenDisplay(NULL);
  10154. +
  10155. + assert(dpy);
  10156. +
  10157. + MakeNormalWindow(dpy);
  10158. + MakeOverlayWindow(dpy);
  10159. +
  10160. + XMapWindow(dpy, NormalWindow);
  10161. + XMapWindow(dpy, OverlayWindow);
  10162. +
  10163. + EventLoop(dpy);
  10164. +
  10165. + glXDestroyContext(dpy, OverlayContext);
  10166. + glXDestroyContext(dpy, NormalContext);
  10167. + XDestroyWindow(dpy, OverlayWindow);
  10168. + XDestroyWindow(dpy, NormalWindow);
  10169. +
  10170. + return 0;
  10171. +}
  10172. diff -Naurp Mesa-7.8.1/progs/xdemos/pbdemo.c Mesa-7.8.1.patched/progs/xdemos/pbdemo.c
  10173. --- Mesa-7.8.1/progs/xdemos/pbdemo.c 1970-01-01 01:00:00.000000000 +0100
  10174. +++ Mesa-7.8.1.patched/progs/xdemos/pbdemo.c 2010-06-13 13:45:06.789793146 +0200
  10175. @@ -0,0 +1,493 @@
  10176. +
  10177. +/*
  10178. + * This program demonstrates how to do "off-screen" rendering using
  10179. + * the GLX pixel buffer extension.
  10180. + *
  10181. + * Written by Brian Paul for the "OpenGL and Window System Integration"
  10182. + * course presented at SIGGRAPH '97. Updated on 5 October 2002.
  10183. + *
  10184. + * Usage:
  10185. + * pbuffers width height imgfile
  10186. + * Where:
  10187. + * width is the width, in pixels, of the image to generate.
  10188. + * height is the height, in pixels, of the image to generate.
  10189. + * imgfile is the name of the PPM image file to write.
  10190. + *
  10191. + *
  10192. + * This demo draws 3-D boxes with random orientation. A pbuffer with
  10193. + * a depth (Z) buffer is prefered but if such a pbuffer can't be created
  10194. + * we use a non-depth-buffered config.
  10195. + *
  10196. + * On machines such as the SGI Indigo you may have to reconfigure your
  10197. + * display/X server to enable pbuffers. Look in the /usr/gfx/ucode/MGRAS/vof/
  10198. + * directory for display configurationswith the _pbuf suffix. Use
  10199. + * setmon -x <vof> to configure your X server and display for pbuffers.
  10200. + *
  10201. + * O2 systems seem to support pbuffers well.
  10202. + *
  10203. + * IR systems (at least 1RM systems) don't have single-buffered, RGBA,
  10204. + * Z-buffered pbuffer configs. BUT, they DO have DOUBLE-buffered, RGBA,
  10205. + * Z-buffered pbuffers. Note how we try four different fbconfig attribute
  10206. + * lists below!
  10207. + */
  10208. +
  10209. +
  10210. +#include <assert.h>
  10211. +#include <string.h>
  10212. +#include <stdio.h>
  10213. +#include <stdlib.h>
  10214. +#include <X11/Xlib.h>
  10215. +#include "pbutil.h"
  10216. +
  10217. +
  10218. +/* Some ugly global vars */
  10219. +static Display *gDpy = NULL;
  10220. +static int gScreen = 0;
  10221. +static FBCONFIG gFBconfig = 0;
  10222. +static PBUFFER gPBuffer = 0;
  10223. +static int gWidth, gHeight;
  10224. +static GLXContext glCtx;
  10225. +
  10226. +
  10227. +
  10228. +/*
  10229. + * Create the pbuffer and return a GLXPbuffer handle.
  10230. + *
  10231. + * We loop over a list of fbconfigs trying to create
  10232. + * a pixel buffer. We return the first pixel buffer which we successfully
  10233. + * create.
  10234. + */
  10235. +static PBUFFER
  10236. +MakePbuffer( Display *dpy, int screen, int width, int height )
  10237. +{
  10238. +#define NUM_FB_CONFIGS 4
  10239. + const char fbString[NUM_FB_CONFIGS][100] = {
  10240. + "Single Buffered, depth buffer",
  10241. + "Double Buffered, depth buffer",
  10242. + "Single Buffered, no depth buffer",
  10243. + "Double Buffered, no depth buffer"
  10244. + };
  10245. + int fbAttribs[NUM_FB_CONFIGS][100] = {
  10246. + {
  10247. + /* Single buffered, with depth buffer */
  10248. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  10249. + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
  10250. + GLX_RED_SIZE, 1,
  10251. + GLX_GREEN_SIZE, 1,
  10252. + GLX_BLUE_SIZE, 1,
  10253. + GLX_DEPTH_SIZE, 1,
  10254. + GLX_DOUBLEBUFFER, 0,
  10255. + GLX_STENCIL_SIZE, 0,
  10256. + None
  10257. + },
  10258. + {
  10259. + /* Double buffered, with depth buffer */
  10260. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  10261. + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
  10262. + GLX_RED_SIZE, 1,
  10263. + GLX_GREEN_SIZE, 1,
  10264. + GLX_BLUE_SIZE, 1,
  10265. + GLX_DEPTH_SIZE, 1,
  10266. + GLX_DOUBLEBUFFER, 1,
  10267. + GLX_STENCIL_SIZE, 0,
  10268. + None
  10269. + },
  10270. + {
  10271. + /* Single buffered, without depth buffer */
  10272. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  10273. + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
  10274. + GLX_RED_SIZE, 1,
  10275. + GLX_GREEN_SIZE, 1,
  10276. + GLX_BLUE_SIZE, 1,
  10277. + GLX_DEPTH_SIZE, 0,
  10278. + GLX_DOUBLEBUFFER, 0,
  10279. + GLX_STENCIL_SIZE, 0,
  10280. + None
  10281. + },
  10282. + {
  10283. + /* Double buffered, without depth buffer */
  10284. + GLX_RENDER_TYPE, GLX_RGBA_BIT,
  10285. + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
  10286. + GLX_RED_SIZE, 1,
  10287. + GLX_GREEN_SIZE, 1,
  10288. + GLX_BLUE_SIZE, 1,
  10289. + GLX_DEPTH_SIZE, 0,
  10290. + GLX_DOUBLEBUFFER, 1,
  10291. + GLX_STENCIL_SIZE, 0,
  10292. + None
  10293. + }
  10294. + };
  10295. + Bool largest = True;
  10296. + Bool preserve = False;
  10297. + FBCONFIG *fbConfigs;
  10298. + PBUFFER pBuffer = None;
  10299. + int nConfigs;
  10300. + int i;
  10301. + int attempt;
  10302. +
  10303. + for (attempt=0; attempt<NUM_FB_CONFIGS; attempt++) {
  10304. +
  10305. + /* Get list of possible frame buffer configurations */
  10306. + fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs[attempt], &nConfigs);
  10307. + if (nConfigs==0 || !fbConfigs) {
  10308. + printf("Note: glXChooseFBConfig(%s) failed\n", fbString[attempt]);
  10309. + XFree(fbConfigs);
  10310. + continue;
  10311. + }
  10312. +
  10313. +#if 0 /*DEBUG*/
  10314. + for (i=0;i<nConfigs;i++) {
  10315. + printf("Config %d\n", i);
  10316. + PrintFBConfigInfo(dpy, screen, fbConfigs[i], 0);
  10317. + }
  10318. +#endif
  10319. +
  10320. + /* Create the pbuffer using first fbConfig in the list that works. */
  10321. + for (i=0;i<nConfigs;i++) {
  10322. + pBuffer = CreatePbuffer(dpy, screen, fbConfigs[i], width, height, largest, preserve);
  10323. + if (pBuffer) {
  10324. + gFBconfig = fbConfigs[i];
  10325. + gWidth = width;
  10326. + gHeight = height;
  10327. + break;
  10328. + }
  10329. + }
  10330. +
  10331. + if (pBuffer!=None) {
  10332. + break;
  10333. + }
  10334. + }
  10335. +
  10336. + if (pBuffer) {
  10337. + printf("Using: %s\n", fbString[attempt]);
  10338. + }
  10339. +
  10340. + XFree(fbConfigs);
  10341. +
  10342. + return pBuffer;
  10343. +#undef NUM_FB_CONFIGS
  10344. +}
  10345. +
  10346. +
  10347. +
  10348. +/*
  10349. + * Do all the X / GLX setup stuff.
  10350. + */
  10351. +static int
  10352. +Setup(int width, int height)
  10353. +{
  10354. + int pbSupport;
  10355. + XVisualInfo *visInfo;
  10356. +
  10357. + /* Open the X display */
  10358. + gDpy = XOpenDisplay(NULL);
  10359. + if (!gDpy) {
  10360. + printf("Error: couldn't open default X display.\n");
  10361. + return 0;
  10362. + }
  10363. +
  10364. + /* Get default screen */
  10365. + gScreen = DefaultScreen(gDpy);
  10366. +
  10367. + /* Test that pbuffers are available */
  10368. + pbSupport = QueryPbuffers(gDpy, gScreen);
  10369. + if (pbSupport == 1) {
  10370. + printf("Using GLX 1.3 Pbuffers\n");
  10371. + }
  10372. + else if (pbSupport == 2) {
  10373. + printf("Using SGIX Pbuffers\n");
  10374. + }
  10375. + else {
  10376. + printf("Error: pbuffers not available on this screen\n");
  10377. + XCloseDisplay(gDpy);
  10378. + return 0;
  10379. + }
  10380. +
  10381. + /* Create Pbuffer */
  10382. + gPBuffer = MakePbuffer( gDpy, gScreen, width, height );
  10383. + if (gPBuffer==None) {
  10384. + printf("Error: couldn't create pbuffer\n");
  10385. + XCloseDisplay(gDpy);
  10386. + return 0;
  10387. + }
  10388. +
  10389. + /* Test drawable queries */
  10390. + {
  10391. + unsigned int v;
  10392. + glXQueryDrawable( gDpy, gPBuffer, GLX_WIDTH, &v);
  10393. + printf("GLX_WIDTH = %u\n", v);
  10394. + glXQueryDrawable( gDpy, gPBuffer, GLX_HEIGHT, &v);
  10395. + printf("GLX_HEIGHT = %u\n", v);
  10396. + glXQueryDrawable( gDpy, gPBuffer, GLX_PRESERVED_CONTENTS, &v);
  10397. + printf("GLX_PRESERVED_CONTENTS = %u\n", v);
  10398. + glXQueryDrawable( gDpy, gPBuffer, GLX_LARGEST_PBUFFER, &v);
  10399. + printf("GLX_LARGEST_PBUFFER = %u\n", v);
  10400. + glXQueryDrawable( gDpy, gPBuffer, GLX_FBCONFIG_ID, &v);
  10401. + printf("GLX_FBCONFIG_ID = %u\n", v);
  10402. + }
  10403. +
  10404. + /* Get corresponding XVisualInfo */
  10405. + visInfo = GetVisualFromFBConfig(gDpy, gScreen, gFBconfig);
  10406. + if (!visInfo) {
  10407. + printf("Error: can't get XVisualInfo from FBconfig\n");
  10408. + XCloseDisplay(gDpy);
  10409. + return 0;
  10410. + }
  10411. +
  10412. + /* Create GLX context */
  10413. + glCtx = glXCreateContext(gDpy, visInfo, NULL, True);
  10414. + if (!glCtx) {
  10415. + /* try indirect */
  10416. + glCtx = glXCreateContext(gDpy, visInfo, NULL, False);
  10417. + if (!glCtx) {
  10418. + printf("Error: Couldn't create GLXContext\n");
  10419. + XFree(visInfo);
  10420. + XCloseDisplay(gDpy);
  10421. + return 0;
  10422. + }
  10423. + else {
  10424. + printf("Warning: using indirect GLXContext\n");
  10425. + }
  10426. + }
  10427. +
  10428. + /* Bind context to pbuffer */
  10429. + if (!glXMakeCurrent(gDpy, gPBuffer, glCtx)) {
  10430. + printf("Error: glXMakeCurrent failed\n");
  10431. + XFree(visInfo);
  10432. + XCloseDisplay(gDpy);
  10433. + return 0;
  10434. + }
  10435. +
  10436. + return 1; /* Success!! */
  10437. +}
  10438. +
  10439. +
  10440. +
  10441. +/* One-time GL setup */
  10442. +static void
  10443. +InitGL(void)
  10444. +{
  10445. + static GLfloat pos[4] = {0.0, 0.0, 10.0, 0.0};
  10446. + glEnable(GL_LIGHTING);
  10447. + glEnable(GL_LIGHT0);
  10448. + glLightfv(GL_LIGHT0, GL_POSITION, pos);
  10449. + glEnable(GL_NORMALIZE);
  10450. + glEnable(GL_DEPTH_TEST);
  10451. + glEnable(GL_CULL_FACE);
  10452. +
  10453. + glViewport(0, 0, gWidth, gHeight);
  10454. + glMatrixMode( GL_PROJECTION );
  10455. + glLoadIdentity();
  10456. + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  10457. + glMatrixMode( GL_MODELVIEW );
  10458. + glLoadIdentity();
  10459. + glTranslatef( 0.0, 0.0, -15.0 );
  10460. +}
  10461. +
  10462. +
  10463. +/* Return random float in [0,1] */
  10464. +static float
  10465. +Random(void)
  10466. +{
  10467. + int i = rand();
  10468. + return (float) (i % 1000) / 1000.0;
  10469. +}
  10470. +
  10471. +
  10472. +static void
  10473. +RandomColor(void)
  10474. +{
  10475. + GLfloat c[4];
  10476. + c[0] = Random();
  10477. + c[1] = Random();
  10478. + c[2] = Random();
  10479. + c[3] = 1.0;
  10480. + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c);
  10481. +}
  10482. +
  10483. +
  10484. +/* This function borrowed from Mark Kilgard's GLUT */
  10485. +static void
  10486. +drawBox(GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1,
  10487. + GLfloat z0, GLfloat z1, GLenum type)
  10488. +{
  10489. + static GLfloat n[6][3] =
  10490. + {
  10491. + {-1.0, 0.0, 0.0},
  10492. + {0.0, 1.0, 0.0},
  10493. + {1.0, 0.0, 0.0},
  10494. + {0.0, -1.0, 0.0},
  10495. + {0.0, 0.0, 1.0},
  10496. + {0.0, 0.0, -1.0}
  10497. + };
  10498. + static GLint faces[6][4] =
  10499. + {
  10500. + {0, 1, 2, 3},
  10501. + {3, 2, 6, 7},
  10502. + {7, 6, 5, 4},
  10503. + {4, 5, 1, 0},
  10504. + {5, 6, 2, 1},
  10505. + {7, 4, 0, 3}
  10506. + };
  10507. + GLfloat v[8][3], tmp;
  10508. + GLint i;
  10509. +
  10510. + if (x0 > x1) {
  10511. + tmp = x0;
  10512. + x0 = x1;
  10513. + x1 = tmp;
  10514. + }
  10515. + if (y0 > y1) {
  10516. + tmp = y0;
  10517. + y0 = y1;
  10518. + y1 = tmp;
  10519. + }
  10520. + if (z0 > z1) {
  10521. + tmp = z0;
  10522. + z0 = z1;
  10523. + z1 = tmp;
  10524. + }
  10525. + v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0;
  10526. + v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1;
  10527. + v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
  10528. + v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
  10529. + v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0;
  10530. + v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1;
  10531. +
  10532. + for (i = 0; i < 6; i++) {
  10533. + glBegin(type);
  10534. + glNormal3fv(&n[i][0]);
  10535. + glVertex3fv(&v[faces[i][0]][0]);
  10536. + glVertex3fv(&v[faces[i][1]][0]);
  10537. + glVertex3fv(&v[faces[i][2]][0]);
  10538. + glVertex3fv(&v[faces[i][3]][0]);
  10539. + glEnd();
  10540. + }
  10541. +}
  10542. +
  10543. +
  10544. +
  10545. +/* Render a scene */
  10546. +static void
  10547. +Render(void)
  10548. +{
  10549. + int NumBoxes = 100;
  10550. + int i;
  10551. +
  10552. + glClearColor(0.2, 0.2, 0.9, 0.0);
  10553. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  10554. +
  10555. + for (i=0;i<NumBoxes;i++) {
  10556. + float tx = -2.0 + 4.0 * Random();
  10557. + float ty = -2.0 + 4.0 * Random();
  10558. + float tz = 4.0 - 16.0 * Random();
  10559. + float sx = 0.1 + Random() * 0.4;
  10560. + float sy = 0.1 + Random() * 0.4;
  10561. + float sz = 0.1 + Random() * 0.4;
  10562. + float rx = Random();
  10563. + float ry = Random();
  10564. + float rz = Random();
  10565. + float ra = Random() * 360.0;
  10566. + glPushMatrix();
  10567. + glTranslatef(tx, ty, tz);
  10568. + glRotatef(ra, rx, ry, rz);
  10569. + glScalef(sx, sy, sz);
  10570. + RandomColor();
  10571. + drawBox(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, GL_POLYGON);
  10572. + glPopMatrix();
  10573. + }
  10574. +
  10575. + glFinish();
  10576. +}
  10577. +
  10578. +
  10579. +
  10580. +static void
  10581. +WriteFile(const char *filename)
  10582. +{
  10583. + FILE *f;
  10584. + GLubyte *image;
  10585. + int i;
  10586. +
  10587. + image = malloc(gWidth * gHeight * 3 * sizeof(GLubyte));
  10588. + if (!image) {
  10589. + printf("Error: couldn't allocate image buffer\n");
  10590. + return;
  10591. + }
  10592. +
  10593. + glPixelStorei(GL_PACK_ALIGNMENT, 1);
  10594. + glReadPixels(0, 0, gWidth, gHeight, GL_RGB, GL_UNSIGNED_BYTE, image);
  10595. +
  10596. + f = fopen(filename, "w");
  10597. + if (!f) {
  10598. + printf("Couldn't open image file: %s\n", filename);
  10599. + return;
  10600. + }
  10601. + fprintf(f,"P6\n");
  10602. + fprintf(f,"# ppm-file created by %s\n", "trdemo2");
  10603. + fprintf(f,"%i %i\n", gWidth, gHeight);
  10604. + fprintf(f,"255\n");
  10605. + fclose(f);
  10606. + f = fopen(filename, "ab"); /* now append binary data */
  10607. + if (!f) {
  10608. + printf("Couldn't append to image file: %s\n", filename);
  10609. + return;
  10610. + }
  10611. +
  10612. + for (i=0;i<gHeight;i++) {
  10613. + GLubyte *rowPtr;
  10614. + /* Remember, OpenGL images are bottom to top. Have to reverse. */
  10615. + rowPtr = image + (gHeight-1-i) * gWidth*3;
  10616. + fwrite(rowPtr, 1, gWidth*3, f);
  10617. + }
  10618. +
  10619. + fclose(f);
  10620. + free(image);
  10621. +
  10622. + printf("Wrote %d by %d image file: %s\n", gWidth, gHeight, filename);
  10623. +}
  10624. +
  10625. +
  10626. +
  10627. +/*
  10628. + * Print message describing command line parameters.
  10629. + */
  10630. +static void
  10631. +Usage(const char *appName)
  10632. +{
  10633. + printf("Usage:\n");
  10634. + printf(" %s width height imgfile\n", appName);
  10635. + printf("Where imgfile is a ppm file\n");
  10636. +}
  10637. +
  10638. +
  10639. +
  10640. +int
  10641. +main(int argc, char *argv[])
  10642. +{
  10643. + if (argc!=4) {
  10644. + Usage(argv[0]);
  10645. + }
  10646. + else {
  10647. + int width = atoi(argv[1]);
  10648. + int height = atoi(argv[2]);
  10649. + char *fileName = argv[3];
  10650. + if (width<=0) {
  10651. + printf("Error: width parameter must be at least 1.\n");
  10652. + return 1;
  10653. + }
  10654. + if (height<=0) {
  10655. + printf("Error: height parameter must be at least 1.\n");
  10656. + return 1;
  10657. + }
  10658. + if (!Setup(width, height)) {
  10659. + return 1;
  10660. + }
  10661. + InitGL();
  10662. + Render();
  10663. + WriteFile(fileName);
  10664. + DestroyPbuffer(gDpy, gScreen, gPBuffer);
  10665. + }
  10666. + return 0;
  10667. +}
  10668. +
  10669. diff -Naurp Mesa-7.8.1/progs/xdemos/pbinfo.c Mesa-7.8.1.patched/progs/xdemos/pbinfo.c
  10670. --- Mesa-7.8.1/progs/xdemos/pbinfo.c 1970-01-01 01:00:00.000000000 +0100
  10671. +++ Mesa-7.8.1.patched/progs/xdemos/pbinfo.c 2010-06-13 13:45:06.789793146 +0200
  10672. @@ -0,0 +1,107 @@
  10673. +
  10674. +/*
  10675. + * Print list of fbconfigs and test each to see if a pbuffer can be created
  10676. + * for that config.
  10677. + *
  10678. + * Brian Paul
  10679. + * April 1997
  10680. + * Updated on 5 October 2002.
  10681. + */
  10682. +
  10683. +
  10684. +#include <X11/Xlib.h>
  10685. +#include <stdio.h>
  10686. +#include <string.h>
  10687. +#include "pbutil.h"
  10688. +
  10689. +
  10690. +
  10691. +
  10692. +static void
  10693. +PrintConfigs(Display *dpy, int screen, Bool horizFormat)
  10694. +{
  10695. + FBCONFIG *fbConfigs;
  10696. + int nConfigs;
  10697. + int i;
  10698. +
  10699. + fbConfigs = GetAllFBConfigs(dpy, screen, &nConfigs);
  10700. + if (!nConfigs || !fbConfigs) {
  10701. + printf("Error: glxGetFBConfigs failed\n");
  10702. + XFree(fbConfigs);
  10703. + return;
  10704. + }
  10705. +
  10706. + printf("Number of fbconfigs: %d\n", nConfigs);
  10707. +
  10708. + if (horizFormat) {
  10709. + printf(" ID VisualType Depth Lvl RGB CI DB Stereo R G B A");
  10710. + printf(" Z S AR AG AB AA MSbufs MSnum Pbuffer Float\n");
  10711. + }
  10712. +
  10713. + /* Print config info */
  10714. + for (i = 0; i < nConfigs; i++) {
  10715. + PrintFBConfigInfo(dpy, screen, fbConfigs[i], horizFormat);
  10716. + }
  10717. +
  10718. + /* free the list */
  10719. + XFree(fbConfigs);
  10720. +}
  10721. +
  10722. +
  10723. +
  10724. +static void
  10725. +PrintUsage(void)
  10726. +{
  10727. + printf("Options:\n");
  10728. + printf(" -display <display-name> specify X display name\n");
  10729. + printf(" -t print in tabular format\n");
  10730. + printf(" -v print in verbose format\n");
  10731. + printf(" -help print this information\n");
  10732. +}
  10733. +
  10734. +
  10735. +int
  10736. +main(int argc, char *argv[])
  10737. +{
  10738. + Display *dpy;
  10739. + int scrn;
  10740. + char *dpyName = NULL;
  10741. + Bool horizFormat = True;
  10742. + int i;
  10743. +
  10744. + for (i=1; i<argc; i++) {
  10745. + if (strcmp(argv[i],"-display")==0) {
  10746. + if (i+1<argc) {
  10747. + dpyName = argv[i+1];
  10748. + i++;
  10749. + }
  10750. + }
  10751. + else if (strcmp(argv[i],"-t")==0) {
  10752. + /* tabular format */
  10753. + horizFormat = True;
  10754. + }
  10755. + else if (strcmp(argv[i],"-v")==0) {
  10756. + /* verbose format */
  10757. + horizFormat = False;
  10758. + }
  10759. + else if (strcmp(argv[i],"-help")==0) {
  10760. + PrintUsage();
  10761. + return 0;
  10762. + }
  10763. + else {
  10764. + printf("Unknown option: %s\n", argv[i]);
  10765. + }
  10766. + }
  10767. +
  10768. + dpy = XOpenDisplay(dpyName);
  10769. +
  10770. + if (!dpy) {
  10771. + printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
  10772. + return 1;
  10773. + }
  10774. +
  10775. + scrn = DefaultScreen(dpy);
  10776. + PrintConfigs(dpy, scrn, horizFormat);
  10777. + XCloseDisplay(dpy);
  10778. + return 0;
  10779. +}
  10780. diff -Naurp Mesa-7.8.1/progs/xdemos/pbutil.c Mesa-7.8.1.patched/progs/xdemos/pbutil.c
  10781. --- Mesa-7.8.1/progs/xdemos/pbutil.c 1970-01-01 01:00:00.000000000 +0100
  10782. +++ Mesa-7.8.1.patched/progs/xdemos/pbutil.c 2010-06-13 13:45:06.789793146 +0200
  10783. @@ -0,0 +1,446 @@
  10784. +
  10785. +/*
  10786. + * OpenGL pbuffers utility functions.
  10787. + *
  10788. + * Brian Paul
  10789. + * Original code: April 1997
  10790. + * Updated on 5 October 2002
  10791. + * Updated again on 3 January 2005 to use GLX 1.3 functions in preference
  10792. + * to the GLX_SGIX_fbconfig/pbuffer extensions.
  10793. + */
  10794. +
  10795. +#include <stdio.h>
  10796. +#include <string.h>
  10797. +#include "pbutil.h"
  10798. +
  10799. +
  10800. +/**
  10801. + * Test if we pixel buffers are available for a particular X screen.
  10802. + * Input: dpy - the X display
  10803. + * screen - screen number
  10804. + * Return: 0 = fbconfigs not available.
  10805. + * 1 = fbconfigs are available via GLX 1.3.
  10806. + * 2 = fbconfigs and pbuffers are available via GLX_SGIX_fbconfig
  10807. + */
  10808. +int
  10809. +QueryFBConfig(Display *dpy, int screen)
  10810. +{
  10811. +#if defined(GLX_VERSION_1_3)
  10812. + {
  10813. + /* GLX 1.3 supports pbuffers */
  10814. + int glxVersionMajor, glxVersionMinor;
  10815. + if (!glXQueryVersion(dpy, &glxVersionMajor, &glxVersionMinor)) {
  10816. + /* GLX not available! */
  10817. + return 0;
  10818. + }
  10819. + if (glxVersionMajor * 100 + glxVersionMinor >= 103) {
  10820. + return 1;
  10821. + }
  10822. + /* fall-through */
  10823. + }
  10824. +#endif
  10825. +
  10826. + /* Try the SGIX extensions */
  10827. + {
  10828. + char *extensions;
  10829. + extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
  10830. + if (extensions && strstr(extensions,"GLX_SGIX_fbconfig")) {
  10831. + return 2;
  10832. + }
  10833. + }
  10834. +
  10835. + return 0;
  10836. +}
  10837. +
  10838. +/**
  10839. + * Test if we pixel buffers are available for a particular X screen.
  10840. + * Input: dpy - the X display
  10841. + * screen - screen number
  10842. + * Return: 0 = pixel buffers not available.
  10843. + * 1 = pixel buffers are available via GLX 1.3.
  10844. + * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
  10845. + */
  10846. +int
  10847. +QueryPbuffers(Display *dpy, int screen)
  10848. +{
  10849. + int ret;
  10850. +
  10851. + ret = QueryFBConfig(dpy, screen);
  10852. + if (ret == 2) {
  10853. + char *extensions;
  10854. + extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
  10855. + if (extensions && strstr(extensions, "GLX_SGIX_pbuffer"))
  10856. + return 2;
  10857. + else
  10858. + return 0;
  10859. + }
  10860. + else
  10861. + return ret;
  10862. +}
  10863. +
  10864. +FBCONFIG *
  10865. +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs)
  10866. +{
  10867. + int fbcSupport = QueryPbuffers(dpy, screen);
  10868. +#if defined(GLX_VERSION_1_3)
  10869. + if (fbcSupport == 1) {
  10870. + return glXChooseFBConfig(dpy, screen, attribs, nConfigs);
  10871. + }
  10872. +#endif
  10873. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  10874. + if (fbcSupport == 2) {
  10875. + return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs);
  10876. + }
  10877. +#endif
  10878. + return NULL;
  10879. +}
  10880. +
  10881. +
  10882. +FBCONFIG *
  10883. +GetAllFBConfigs(Display *dpy, int screen, int *nConfigs)
  10884. +{
  10885. + int fbcSupport = QueryFBConfig(dpy, screen);
  10886. +#if defined(GLX_VERSION_1_3)
  10887. + if (fbcSupport == 1) {
  10888. + return glXGetFBConfigs(dpy, screen, nConfigs);
  10889. + }
  10890. +#endif
  10891. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  10892. + if (fbcSupport == 2) {
  10893. + /* The GLX_SGIX_fbconfig extensions says to pass NULL to get list
  10894. + * of all available configurations.
  10895. + */
  10896. + return glXChooseFBConfigSGIX(dpy, screen, NULL, nConfigs);
  10897. + }
  10898. +#endif
  10899. + return NULL;
  10900. +}
  10901. +
  10902. +
  10903. +XVisualInfo *
  10904. +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config)
  10905. +{
  10906. + int fbcSupport = QueryFBConfig(dpy, screen);
  10907. +#if defined(GLX_VERSION_1_3)
  10908. + if (fbcSupport == 1) {
  10909. + return glXGetVisualFromFBConfig(dpy, config);
  10910. + }
  10911. +#endif
  10912. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  10913. + if (fbcSupport == 2) {
  10914. + return glXGetVisualFromFBConfigSGIX(dpy, config);
  10915. + }
  10916. +#endif
  10917. + return NULL;
  10918. +}
  10919. +
  10920. +
  10921. +/**
  10922. + * Either use glXGetFBConfigAttrib() or glXGetFBConfigAttribSGIX()
  10923. + * to query an fbconfig attribute.
  10924. + */
  10925. +static int
  10926. +GetFBConfigAttrib(Display *dpy, int screen,
  10927. +#if defined(GLX_VERSION_1_3)
  10928. + const GLXFBConfig config,
  10929. +#elif defined(GLX_SGIX_fbconfig)
  10930. + const GLXFBConfigSGIX config,
  10931. +#endif
  10932. + int attrib
  10933. + )
  10934. +{
  10935. + int fbcSupport = QueryFBConfig(dpy, screen);
  10936. + int value = 0;
  10937. +
  10938. +#if defined(GLX_VERSION_1_3)
  10939. + if (fbcSupport == 1) {
  10940. + /* ok */
  10941. + if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) {
  10942. + value = 0;
  10943. + }
  10944. + return value;
  10945. + }
  10946. + /* fall-through */
  10947. +#endif
  10948. +
  10949. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  10950. + if (fbcSupport == 2) {
  10951. + if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) {
  10952. + value = 0;
  10953. + }
  10954. + return value;
  10955. + }
  10956. +#endif
  10957. +
  10958. + return value;
  10959. +}
  10960. +
  10961. +
  10962. +
  10963. +/**
  10964. + * Print parameters for a GLXFBConfig to stdout.
  10965. + * Input: dpy - the X display
  10966. + * screen - the X screen number
  10967. + * fbConfig - the fbconfig handle
  10968. + * horizFormat - if true, print in horizontal format
  10969. + */
  10970. +void
  10971. +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat)
  10972. +{
  10973. + PBUFFER pBuffer;
  10974. + int width=2, height=2;
  10975. + int bufferSize, level, doubleBuffer, stereo, auxBuffers;
  10976. + int redSize, greenSize, blueSize, alphaSize;
  10977. + int depthSize, stencilSize;
  10978. + int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize;
  10979. + int sampleBuffers, samples;
  10980. + int drawableType, renderType, xRenderable, xVisual, id;
  10981. + int maxWidth, maxHeight, maxPixels;
  10982. + int optWidth, optHeight;
  10983. + int floatComponents = 0;
  10984. +
  10985. + /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */
  10986. + bufferSize = GetFBConfigAttrib(dpy, screen, config, GLX_BUFFER_SIZE);
  10987. + level = GetFBConfigAttrib(dpy, screen, config, GLX_LEVEL);
  10988. + doubleBuffer = GetFBConfigAttrib(dpy, screen, config, GLX_DOUBLEBUFFER);
  10989. + stereo = GetFBConfigAttrib(dpy, screen, config, GLX_STEREO);
  10990. + auxBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_AUX_BUFFERS);
  10991. + redSize = GetFBConfigAttrib(dpy, screen, config, GLX_RED_SIZE);
  10992. + greenSize = GetFBConfigAttrib(dpy, screen, config, GLX_GREEN_SIZE);
  10993. + blueSize = GetFBConfigAttrib(dpy, screen, config, GLX_BLUE_SIZE);
  10994. + alphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ALPHA_SIZE);
  10995. + depthSize = GetFBConfigAttrib(dpy, screen, config, GLX_DEPTH_SIZE);
  10996. + stencilSize = GetFBConfigAttrib(dpy, screen, config, GLX_STENCIL_SIZE);
  10997. + accumRedSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_RED_SIZE);
  10998. + accumGreenSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_GREEN_SIZE);
  10999. + accumBlueSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_BLUE_SIZE);
  11000. + accumAlphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_ALPHA_SIZE);
  11001. + sampleBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLE_BUFFERS);
  11002. + samples = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLES);
  11003. + drawableType = GetFBConfigAttrib(dpy, screen, config, GLX_DRAWABLE_TYPE);
  11004. + renderType = GetFBConfigAttrib(dpy, screen, config, GLX_RENDER_TYPE);
  11005. + xRenderable = GetFBConfigAttrib(dpy, screen, config, GLX_X_RENDERABLE);
  11006. + xVisual = GetFBConfigAttrib(dpy, screen, config, GLX_X_VISUAL_TYPE);
  11007. + if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX))
  11008. + xVisual = -1;
  11009. +
  11010. + id = GetFBConfigAttrib(dpy, screen, config, GLX_FBCONFIG_ID);
  11011. + maxWidth = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_WIDTH);
  11012. + maxHeight = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_HEIGHT);
  11013. + maxPixels = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_PIXELS);
  11014. +#if defined(GLX_SGIX_pbuffer)
  11015. + optWidth = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX);
  11016. + optHeight = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX);
  11017. +#else
  11018. + optWidth = optHeight = 0;
  11019. +#endif
  11020. +#if defined(GLX_NV_float_buffer)
  11021. + floatComponents = GetFBConfigAttrib(dpy, screen, config, GLX_FLOAT_COMPONENTS_NV);
  11022. +#endif
  11023. +
  11024. + /* See if we can create a pbuffer with this config */
  11025. + pBuffer = CreatePbuffer(dpy, screen, config, width, height, False, False);
  11026. +
  11027. + if (horizFormat) {
  11028. + printf("0x%-9x ", id);
  11029. + if (xVisual==GLX_STATIC_GRAY) printf("StaticGray ");
  11030. + else if (xVisual==GLX_GRAY_SCALE) printf("GrayScale ");
  11031. + else if (xVisual==GLX_STATIC_COLOR) printf("StaticColor ");
  11032. + else if (xVisual==GLX_PSEUDO_COLOR) printf("PseudoColor ");
  11033. + else if (xVisual==GLX_TRUE_COLOR) printf("TrueColor ");
  11034. + else if (xVisual==GLX_DIRECT_COLOR) printf("DirectColor ");
  11035. + else printf(" -none- ");
  11036. + printf(" %3d %3d %s %s %s %2s ", bufferSize, level,
  11037. + (renderType & GLX_RGBA_BIT_SGIX) ? "y" : ".",
  11038. + (renderType & GLX_COLOR_INDEX_BIT_SGIX) ? "y" : ".",
  11039. + doubleBuffer ? "y" : ".",
  11040. + stereo ? "y" : ".");
  11041. + printf("%2d %2d %2d %2d ", redSize, greenSize, blueSize, alphaSize);
  11042. + printf("%2d %2d ", depthSize, stencilSize);
  11043. + printf("%2d %2d %2d %2d", accumRedSize, accumGreenSize, accumBlueSize,
  11044. + accumAlphaSize);
  11045. + printf(" %2d %2d", sampleBuffers, samples);
  11046. + printf(" %s %c", pBuffer ? "y" : ".",
  11047. + ".y"[floatComponents]);
  11048. + printf("\n");
  11049. + }
  11050. + else {
  11051. + printf("Id 0x%x\n", id);
  11052. + printf(" Buffer Size: %d\n", bufferSize);
  11053. + printf(" Level: %d\n", level);
  11054. + printf(" Double Buffer: %s\n", doubleBuffer ? "yes" : "no");
  11055. + printf(" Stereo: %s\n", stereo ? "yes" : "no");
  11056. + printf(" Aux Buffers: %d\n", auxBuffers);
  11057. + printf(" Red Size: %d\n", redSize);
  11058. + printf(" Green Size: %d\n", greenSize);
  11059. + printf(" Blue Size: %d\n", blueSize);
  11060. + printf(" Alpha Size: %d\n", alphaSize);
  11061. + printf(" Depth Size: %d\n", depthSize);
  11062. + printf(" Stencil Size: %d\n", stencilSize);
  11063. + printf(" Accum Red Size: %d\n", accumRedSize);
  11064. + printf(" Accum Green Size: %d\n", accumGreenSize);
  11065. + printf(" Accum Blue Size: %d\n", accumBlueSize);
  11066. + printf(" Accum Alpha Size: %d\n", accumAlphaSize);
  11067. + printf(" Sample Buffers: %d\n", sampleBuffers);
  11068. + printf(" Samples/Pixel: %d\n", samples);
  11069. + printf(" Drawable Types: ");
  11070. + if (drawableType & GLX_WINDOW_BIT) printf("Window ");
  11071. + if (drawableType & GLX_PIXMAP_BIT) printf("Pixmap ");
  11072. + if (drawableType & GLX_PBUFFER_BIT) printf("PBuffer");
  11073. + printf("\n");
  11074. + printf(" Render Types: ");
  11075. + if (renderType & GLX_RGBA_BIT_SGIX) printf("RGBA ");
  11076. + if (renderType & GLX_COLOR_INDEX_BIT_SGIX) printf("CI ");
  11077. + printf("\n");
  11078. + printf(" X Renderable: %s\n", xRenderable ? "yes" : "no");
  11079. +
  11080. + printf(" Pbuffer: %s\n", pBuffer ? "yes" : "no");
  11081. + printf(" Max Pbuffer width: %d\n", maxWidth);
  11082. + printf(" Max Pbuffer height: %d\n", maxHeight);
  11083. + printf(" Max Pbuffer pixels: %d\n", maxPixels);
  11084. + printf(" Optimum Pbuffer width: %d\n", optWidth);
  11085. + printf(" Optimum Pbuffer height: %d\n", optHeight);
  11086. +
  11087. + printf(" Float Components: %s\n", floatComponents ? "yes" : "no");
  11088. + }
  11089. +
  11090. + if (pBuffer) {
  11091. + DestroyPbuffer(dpy, screen, pBuffer);
  11092. + }
  11093. +}
  11094. +
  11095. +
  11096. +
  11097. +GLXContext
  11098. +CreateContext(Display *dpy, int screen, FBCONFIG config)
  11099. +{
  11100. + int fbcSupport = QueryFBConfig(dpy, screen);
  11101. +#if defined(GLX_VERSION_1_3)
  11102. + if (fbcSupport == 1) {
  11103. + /* GLX 1.3 */
  11104. + GLXContext c;
  11105. + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True);
  11106. + if (!c) {
  11107. + /* try indirect */
  11108. + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, False);
  11109. + }
  11110. + return c;
  11111. + }
  11112. +#endif
  11113. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  11114. + if (fbcSupport == 2) {
  11115. + GLXContext c;
  11116. + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True);
  11117. + if (!c) {
  11118. + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, False);
  11119. + }
  11120. + return c;
  11121. + }
  11122. +#endif
  11123. + return 0;
  11124. +}
  11125. +
  11126. +
  11127. +void
  11128. +DestroyContext(Display *dpy, GLXContext ctx)
  11129. +{
  11130. + glXDestroyContext(dpy, ctx);
  11131. +}
  11132. +
  11133. +
  11134. +/* This is only used by CreatePbuffer() */
  11135. +static int XErrorFlag = 0;
  11136. +static int HandleXError(Display *dpy, XErrorEvent *event)
  11137. +{
  11138. + XErrorFlag = 1;
  11139. + return 0;
  11140. +}
  11141. +
  11142. +
  11143. +/**
  11144. + * Create a Pbuffer. Use an X error handler to deal with potential
  11145. + * BadAlloc errors.
  11146. + *
  11147. + * Input: dpy - the X display
  11148. + * fbConfig - an FBConfig as returned by glXChooseFBConfigSGIX().
  11149. + * width, height - size of pixel buffer to request, in pixels.
  11150. + * pbAttribs - list of optional pixel buffer attributes
  11151. + * Return: a Pbuffer or None.
  11152. + */
  11153. +PBUFFER
  11154. +CreatePbuffer(Display *dpy, int screen, FBCONFIG config,
  11155. + int width, int height, Bool largest, Bool preserve)
  11156. +{
  11157. + int (*oldHandler)(Display *, XErrorEvent *);
  11158. + PBUFFER pBuffer = None;
  11159. + int pbSupport = QueryPbuffers(dpy, screen);
  11160. +
  11161. + /* Catch X protocol errors with our own error handler */
  11162. + oldHandler = XSetErrorHandler(HandleXError);
  11163. + XErrorFlag = 0;
  11164. +
  11165. +#if defined(GLX_VERSION_1_3)
  11166. + if (pbSupport == 1) {
  11167. + /* GLX 1.3 */
  11168. + int attribs[100], i = 0;
  11169. + attribs[i++] = GLX_PBUFFER_WIDTH;
  11170. + attribs[i++] = width;
  11171. + attribs[i++] = GLX_PBUFFER_HEIGHT;
  11172. + attribs[i++] = height;
  11173. + attribs[i++] = GLX_PRESERVED_CONTENTS;
  11174. + attribs[i++] = preserve;
  11175. + attribs[i++] = GLX_LARGEST_PBUFFER;
  11176. + attribs[i++] = largest;
  11177. + attribs[i++] = 0;
  11178. + pBuffer = glXCreatePbuffer(dpy, config, attribs);
  11179. + }
  11180. + else
  11181. +#endif
  11182. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  11183. + if (pbSupport == 2) {
  11184. + int attribs[100], i = 0;
  11185. + attribs[i++] = GLX_PRESERVED_CONTENTS;
  11186. + attribs[i++] = preserve;
  11187. + attribs[i++] = GLX_LARGEST_PBUFFER;
  11188. + attribs[i++] = largest;
  11189. + attribs[i++] = 0;
  11190. + pBuffer = glXCreateGLXPbufferSGIX(dpy, config, width, height, attribs);
  11191. + }
  11192. + else
  11193. +#endif
  11194. + {
  11195. + pBuffer = None;
  11196. + }
  11197. +
  11198. + XSync(dpy, False);
  11199. + /* Restore original X error handler */
  11200. + (void) XSetErrorHandler(oldHandler);
  11201. +
  11202. + /* Return pbuffer (may be None) */
  11203. + if (!XErrorFlag && pBuffer != None) {
  11204. + /*printf("config %d worked!\n", i);*/
  11205. + return pBuffer;
  11206. + }
  11207. + else {
  11208. + return None;
  11209. + }
  11210. +}
  11211. +
  11212. +
  11213. +void
  11214. +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer)
  11215. +{
  11216. + int pbSupport = QueryPbuffers(dpy, screen);
  11217. +#if defined(GLX_VERSION_1_3)
  11218. + if (pbSupport == 1) {
  11219. + glXDestroyPbuffer(dpy, pbuffer);
  11220. + return;
  11221. + }
  11222. +#endif
  11223. +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  11224. + if (pbSupport == 2) {
  11225. + glXDestroyGLXPbufferSGIX(dpy, pbuffer);
  11226. + return;
  11227. + }
  11228. +#endif
  11229. +}
  11230. diff -Naurp Mesa-7.8.1/progs/xdemos/pbutil.h Mesa-7.8.1.patched/progs/xdemos/pbutil.h
  11231. --- Mesa-7.8.1/progs/xdemos/pbutil.h 1970-01-01 01:00:00.000000000 +0100
  11232. +++ Mesa-7.8.1.patched/progs/xdemos/pbutil.h 2010-06-13 13:45:06.789793146 +0200
  11233. @@ -0,0 +1,69 @@
  11234. +/*
  11235. + * OpenGL pbuffers utility functions.
  11236. + *
  11237. + * Brian Paul
  11238. + * April 1997
  11239. + */
  11240. +
  11241. +
  11242. +#ifndef PBUTIL_H
  11243. +#define PBUTIL_H
  11244. +
  11245. +
  11246. +#define GLX_GLXEXT_PROTOTYPES
  11247. +#include <GL/glx.h>
  11248. +
  11249. +
  11250. +#if defined(GLX_VERSION_1_3)
  11251. +#define PBUFFER GLXPbuffer
  11252. +#define FBCONFIG GLXFBConfig
  11253. +#elif defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
  11254. +#define PBUFFER GLXPbufferSGIX
  11255. +#define FBCONFIG GLXFBConfigSGIX
  11256. +#else
  11257. +#define PBUFFER int
  11258. +#define FBCONFIG int
  11259. +#endif
  11260. +
  11261. +
  11262. +extern int
  11263. +QueryFBConfig(Display *dpy, int screen);
  11264. +
  11265. +extern int
  11266. +QueryPbuffers(Display *dpy, int screen);
  11267. +
  11268. +
  11269. +extern void
  11270. +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat);
  11271. +
  11272. +
  11273. +extern FBCONFIG *
  11274. +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs);
  11275. +
  11276. +
  11277. +extern FBCONFIG *
  11278. +GetAllFBConfigs(Display *dpy, int screen, int *nConfigs);
  11279. +
  11280. +
  11281. +extern XVisualInfo *
  11282. +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config);
  11283. +
  11284. +
  11285. +extern GLXContext
  11286. +CreateContext(Display *dpy, int screen, FBCONFIG config);
  11287. +
  11288. +
  11289. +extern void
  11290. +DestroyContext(Display *dpy, GLXContext ctx);
  11291. +
  11292. +
  11293. +extern PBUFFER
  11294. +CreatePbuffer(Display *dpy, int screen, FBCONFIG config,
  11295. + int width, int height, Bool preserve, Bool largest);
  11296. +
  11297. +
  11298. +extern void
  11299. +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer);
  11300. +
  11301. +
  11302. +#endif /*PBUTIL_H*/
  11303. diff -Naurp Mesa-7.8.1/progs/xdemos/shape.c Mesa-7.8.1.patched/progs/xdemos/shape.c
  11304. --- Mesa-7.8.1/progs/xdemos/shape.c 1970-01-01 01:00:00.000000000 +0100
  11305. +++ Mesa-7.8.1.patched/progs/xdemos/shape.c 2010-06-13 13:45:06.789793146 +0200
  11306. @@ -0,0 +1,393 @@
  11307. +
  11308. +/*
  11309. + * Example of using the X "shape" extension with OpenGL: render a spinning
  11310. + * cube inside of a non-rectangular window.
  11311. + *
  11312. + * Press ESC to exit. Press up/down to change window shape.
  11313. + *
  11314. + * To compile add "shape" to the PROGS list in Makefile.
  11315. + *
  11316. + * Brian Paul
  11317. + * June 16, 1997
  11318. + *
  11319. + * This program is in the public domain.
  11320. + */
  11321. +
  11322. +
  11323. +#include <math.h>
  11324. +#include <stdio.h>
  11325. +#include <stdlib.h>
  11326. +#include <sys/time.h>
  11327. +#include <time.h>
  11328. +#include <unistd.h>
  11329. +#include <X11/Xlib.h>
  11330. +#include <X11/Xutil.h>
  11331. +#include <X11/keysym.h>
  11332. +#include <X11/extensions/shape.h>
  11333. +#include <GL/glx.h>
  11334. +
  11335. +#ifndef PI
  11336. +#define PI 3.1415926
  11337. +#endif
  11338. +
  11339. +
  11340. +static int Width=500, Height=500;
  11341. +
  11342. +static float Xangle = 0.0, Yangle = 0.0;
  11343. +static int Sides = 5;
  11344. +static int MinSides = 3;
  11345. +static int MaxSides = 20;
  11346. +
  11347. +
  11348. +/* return current time (in seconds) */
  11349. +static double
  11350. +current_time(void)
  11351. +{
  11352. + struct timeval tv;
  11353. +#ifdef __VMS
  11354. + (void) gettimeofday(&tv, NULL );
  11355. +#else
  11356. + struct timezone tz;
  11357. + (void) gettimeofday(&tv, &tz);
  11358. +#endif
  11359. + return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  11360. +}
  11361. +
  11362. +
  11363. +/*
  11364. + * Draw the OpenGL stuff and do a SwapBuffers.
  11365. + */
  11366. +static void display(Display *dpy, Window win)
  11367. +{
  11368. + float scale = 1.7;
  11369. +
  11370. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  11371. +
  11372. + glPushMatrix();
  11373. +
  11374. + glScalef(scale, scale, scale);
  11375. + glRotatef(Xangle, 1.0, 0.0, 0.0);
  11376. + glRotatef(Yangle, 0.0, 1.0, 0.0);
  11377. +
  11378. + /*
  11379. + * wireframe box
  11380. + */
  11381. + glColor3f(1.0, 1.0, 1.0);
  11382. + glBegin(GL_LINE_LOOP);
  11383. + glVertex3f(-1.0, -1.0, -1.0);
  11384. + glVertex3f( 1.0, -1.0, -1.0);
  11385. + glVertex3f( 1.0, 1.0, -1.0);
  11386. + glVertex3f(-1.0, 1.0, -1.0);
  11387. + glEnd();
  11388. +
  11389. + glBegin(GL_LINE_LOOP);
  11390. + glVertex3f(-1.0, -1.0, 1.0);
  11391. + glVertex3f( 1.0, -1.0, 1.0);
  11392. + glVertex3f( 1.0, 1.0, 1.0);
  11393. + glVertex3f(-1.0, 1.0, 1.0);
  11394. + glEnd();
  11395. +
  11396. + glBegin(GL_LINES);
  11397. + glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, 1.0);
  11398. + glVertex3f( 1.0, -1.0, -1.0); glVertex3f( 1.0, -1.0, 1.0);
  11399. + glVertex3f( 1.0, 1.0, -1.0); glVertex3f( 1.0, 1.0, 1.0);
  11400. + glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 1.0);
  11401. + glEnd();
  11402. +
  11403. + /*
  11404. + * Solid box
  11405. + */
  11406. + glPushMatrix();
  11407. + glScalef(0.75, 0.75, 0.75);
  11408. +
  11409. + glColor3f(1, 0, 0);
  11410. + glBegin(GL_POLYGON);
  11411. + glVertex3f(1, -1, -1);
  11412. + glVertex3f(1, 1, -1);
  11413. + glVertex3f(1, 1, 1);
  11414. + glVertex3f(1, -1, 1);
  11415. + glEnd();
  11416. +
  11417. + glColor3f(0, 1, 1);
  11418. + glBegin(GL_POLYGON);
  11419. + glVertex3f(-1, -1, -1);
  11420. + glVertex3f(-1, 1, -1);
  11421. + glVertex3f(-1, 1, 1);
  11422. + glVertex3f(-1, -1, 1);
  11423. + glEnd();
  11424. +
  11425. + glColor3f(0, 1, 0);
  11426. + glBegin(GL_POLYGON);
  11427. + glVertex3f(-1, 1, -1);
  11428. + glVertex3f( 1, 1, -1);
  11429. + glVertex3f( 1, 1, 1);
  11430. + glVertex3f(-1, 1, 1);
  11431. + glEnd();
  11432. +
  11433. + glColor3f(1, 0, 1);
  11434. + glBegin(GL_POLYGON);
  11435. + glVertex3f(-1, -1, -1);
  11436. + glVertex3f( 1, -1, -1);
  11437. + glVertex3f( 1, -1, 1);
  11438. + glVertex3f(-1, -1, 1);
  11439. + glEnd();
  11440. +
  11441. + glColor3f(0, 0, 1);
  11442. + glBegin(GL_POLYGON);
  11443. + glVertex3f(-1, -1, 1);
  11444. + glVertex3f( 1, -1, 1);
  11445. + glVertex3f( 1, 1, 1);
  11446. + glVertex3f(-1, 1, 1);
  11447. + glEnd();
  11448. +
  11449. + glColor3f(1, 1, 0);
  11450. + glBegin(GL_POLYGON);
  11451. + glVertex3f(-1, -1, -1);
  11452. + glVertex3f( 1, -1, -1);
  11453. + glVertex3f( 1, 1, -1);
  11454. + glVertex3f(-1, 1, -1);
  11455. + glEnd();
  11456. + glPopMatrix();
  11457. +
  11458. +
  11459. + glPopMatrix();
  11460. +
  11461. + glXSwapBuffers(dpy, win);
  11462. +}
  11463. +
  11464. +
  11465. +/*
  11466. + * This is called when we have to recompute the window shape bitmask.
  11467. + * We just generate an n-sided regular polygon here but any other shape
  11468. + * would be possible.
  11469. + */
  11470. +static void make_shape_mask(Display *dpy, Window win, int width, int height,
  11471. + int sides)
  11472. +{
  11473. + Pixmap shapeMask;
  11474. + XGCValues xgcv;
  11475. + GC gc;
  11476. +
  11477. + /* allocate 1-bit deep pixmap and a GC */
  11478. + shapeMask = XCreatePixmap(dpy, win, width, height, 1);
  11479. + gc = XCreateGC(dpy, shapeMask, 0, &xgcv);
  11480. +
  11481. + /* clear shapeMask to zeros */
  11482. + XSetForeground(dpy, gc, 0);
  11483. + XFillRectangle(dpy, shapeMask, gc, 0, 0, width, height);
  11484. +
  11485. + /* draw mask */
  11486. + XSetForeground(dpy, gc, 1);
  11487. + {
  11488. + int cx = width / 2;
  11489. + int cy = height / 2;
  11490. + float angle = 0.0;
  11491. + float step = 2.0 * PI / sides;
  11492. + float radius = width / 2;
  11493. + int i;
  11494. + XPoint points[100];
  11495. + for (i=0;i<sides;i++) {
  11496. + int x = cx + radius * sin(angle);
  11497. + int y = cy - radius * cos(angle);
  11498. + points[i].x = x;
  11499. + points[i].y = y;
  11500. + angle += step;
  11501. + }
  11502. + XFillPolygon(dpy, shapeMask, gc, points, sides, Convex, CoordModeOrigin);
  11503. + }
  11504. +
  11505. + /* This is the only SHAPE extension call- simple! */
  11506. + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shapeMask, ShapeSet);
  11507. +
  11508. + XFreeGC(dpy, gc);
  11509. + XFreePixmap(dpy, shapeMask);
  11510. +}
  11511. +
  11512. +
  11513. +/*
  11514. + * Called when window is resized. Do OpenGL viewport and projection stuff.
  11515. + */
  11516. +static void reshape(int width, int height)
  11517. +{
  11518. + glViewport(0, 0, width, height);
  11519. + glMatrixMode(GL_PROJECTION);
  11520. + glLoadIdentity();
  11521. + glFrustum(-1.0, 1.0, -1.0, 1.0, 3.0, 20.0);
  11522. + glMatrixMode(GL_MODELVIEW);
  11523. + glLoadIdentity();
  11524. + glTranslatef(0.0, 0.0, -10.0);
  11525. +
  11526. + glEnable(GL_DEPTH_TEST);
  11527. +}
  11528. +
  11529. +
  11530. +/*
  11531. + * Process X events.
  11532. + */
  11533. +static void event_loop(Display *dpy, Window win)
  11534. +{
  11535. + while (1) {
  11536. + XEvent event;
  11537. + if (XPending(dpy)) {
  11538. + XNextEvent(dpy, &event);
  11539. + switch (event.type) {
  11540. + case Expose:
  11541. + display(dpy, event.xexpose.window);
  11542. + break;
  11543. + case ConfigureNotify:
  11544. + Width = event.xconfigure.width;
  11545. + Height = event.xconfigure.height,
  11546. + make_shape_mask(dpy, win, Width, Height, Sides);
  11547. + reshape(Width, Height);
  11548. + break;
  11549. + case KeyPress:
  11550. + {
  11551. + char buf[100];
  11552. + KeySym keySym;
  11553. + XComposeStatus stat;
  11554. + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
  11555. + switch (keySym) {
  11556. + case XK_Escape:
  11557. + exit(0);
  11558. + break;
  11559. + case XK_Up:
  11560. + Sides++;
  11561. + if (Sides>MaxSides) Sides = MaxSides;
  11562. + make_shape_mask(dpy, win, Width, Height, Sides);
  11563. + break;
  11564. + case XK_Down:
  11565. + Sides--;
  11566. + if (Sides<MinSides) Sides = MinSides;
  11567. + make_shape_mask(dpy, win, Width, Height, Sides);
  11568. + break;
  11569. + }
  11570. + }
  11571. + break;
  11572. + default:
  11573. + ;;
  11574. + }
  11575. + }
  11576. + else {
  11577. + static double t0 = -1.0;
  11578. + double dt, t = current_time();
  11579. + if (t0 < 0.0)
  11580. + t0 = t;
  11581. + dt = t - t0;
  11582. + Xangle += 90.0 * dt; /* 90 degrees per second */
  11583. + Yangle += 70.0 * dt;
  11584. + t0 = t;
  11585. + display(dpy, win);
  11586. + }
  11587. + }
  11588. +}
  11589. +
  11590. +
  11591. +/*
  11592. + * Allocate a "nice" colormap. This could be better (HP-CR support, etc).
  11593. + */
  11594. +static Colormap alloc_colormap(Display *dpy, Window parent, Visual *vis)
  11595. +{
  11596. + Screen *scr = DefaultScreenOfDisplay(dpy);
  11597. + int scrnum = DefaultScreen(dpy);
  11598. +
  11599. + if (MaxCmapsOfScreen(scr)==1 && vis==DefaultVisual(dpy, scrnum)) {
  11600. + /* The window and root are of the same visual type so */
  11601. + /* share the root colormap. */
  11602. + return DefaultColormap(dpy, scrnum);
  11603. + }
  11604. + else {
  11605. + return XCreateColormap(dpy, parent, vis, AllocNone);
  11606. + }
  11607. +}
  11608. +
  11609. +
  11610. +int main(int argc, char *argv[])
  11611. +{
  11612. + static int glAttribs[] = {
  11613. + GLX_DOUBLEBUFFER,
  11614. + GLX_RGBA,
  11615. + GLX_DEPTH_SIZE, 1,
  11616. + None
  11617. + };
  11618. + Display *dpy;
  11619. + XVisualInfo *visInfo;
  11620. + int scrn;
  11621. + Window root;
  11622. + Colormap cmap;
  11623. + Window win;
  11624. + XSetWindowAttributes winAttribs;
  11625. + unsigned long winAttribsMask;
  11626. + GLXContext glCtx;
  11627. + int ignore;
  11628. + const char *name = "OpenGL in a Shaped Window";
  11629. +
  11630. + dpy = XOpenDisplay(NULL);
  11631. + if (!dpy) {
  11632. + fprintf(stderr, "Couldn't open default display\n");
  11633. + return 1;
  11634. + }
  11635. +
  11636. + /* check that we can use the shape extension */
  11637. + if (!XQueryExtension(dpy, "SHAPE", &ignore, &ignore, &ignore )) {
  11638. + fprintf(stderr, "Display doesn't support shape extension\n");
  11639. + return 1;
  11640. + }
  11641. +
  11642. + scrn = DefaultScreen(dpy);
  11643. +
  11644. + root = RootWindow(dpy, scrn);
  11645. +
  11646. + visInfo = glXChooseVisual(dpy, scrn, glAttribs);
  11647. + if (!visInfo) {
  11648. + fprintf(stderr, "Couldn't get RGB, DB, Z visual\n");
  11649. + return 1;
  11650. + }
  11651. +
  11652. + glCtx = glXCreateContext(dpy, visInfo, 0, True);
  11653. + if (!glCtx) {
  11654. + fprintf(stderr, "Couldn't create GL context\n");
  11655. + return 1;
  11656. + }
  11657. +
  11658. + cmap = alloc_colormap(dpy, root, visInfo->visual);
  11659. + if (!cmap) {
  11660. + fprintf(stderr, "Couln't create colormap\n");
  11661. + return 1;
  11662. + }
  11663. +
  11664. + winAttribs.border_pixel = 0;
  11665. + winAttribs.colormap = cmap;
  11666. + winAttribs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  11667. + winAttribsMask = CWBorderPixel | CWColormap | CWEventMask;
  11668. + win = XCreateWindow(dpy, root, 0, 0, Width, Height, 0,
  11669. + visInfo->depth, InputOutput,
  11670. + visInfo->visual,
  11671. + winAttribsMask, &winAttribs);
  11672. +
  11673. + {
  11674. + XSizeHints sizehints;
  11675. + /*
  11676. + sizehints.x = xpos;
  11677. + sizehints.y = ypos;
  11678. + sizehints.width = width;
  11679. + sizehints.height = height;
  11680. + */
  11681. + sizehints.flags = 0;
  11682. + XSetNormalHints(dpy, win, &sizehints);
  11683. + XSetStandardProperties(dpy, win, name, name,
  11684. + None, (char **)NULL, 0, &sizehints);
  11685. + }
  11686. +
  11687. +
  11688. + XMapWindow(dpy, win);
  11689. +
  11690. + glXMakeCurrent(dpy, win, glCtx);
  11691. +
  11692. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  11693. + printf("Press ESC to exit.\n");
  11694. + printf("Press up/down to change window shape.\n");
  11695. +
  11696. + event_loop(dpy, win);
  11697. +
  11698. + return 0;
  11699. +}
  11700. diff -Naurp Mesa-7.8.1/progs/xdemos/sharedtex.c Mesa-7.8.1.patched/progs/xdemos/sharedtex.c
  11701. --- Mesa-7.8.1/progs/xdemos/sharedtex.c 1970-01-01 01:00:00.000000000 +0100
  11702. +++ Mesa-7.8.1.patched/progs/xdemos/sharedtex.c 2010-06-13 13:45:06.789793146 +0200
  11703. @@ -0,0 +1,324 @@
  11704. +/*
  11705. + * Test sharing of texture objects by two rendering contexts.
  11706. + * In particular, test that changing a texture object in one context
  11707. + * effects the texture in the second context.
  11708. + *
  11709. + * Brian Paul
  11710. + * 30 Apr 2008
  11711. + *
  11712. + * Copyright (C) 2008 Brian Paul All Rights Reserved.
  11713. + *
  11714. + * Permission is hereby granted, free of charge, to any person obtaining a
  11715. + * copy of this software and associated documentation files (the "Software"),
  11716. + * to deal in the Software without restriction, including without limitation
  11717. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11718. + * and/or sell copies of the Software, and to permit persons to whom the
  11719. + * Software is furnished to do so, subject to the following conditions:
  11720. + *
  11721. + * The above copyright notice and this permission notice shall be included
  11722. + * in all copies or substantial portions of the Software.
  11723. + *
  11724. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11725. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  11726. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  11727. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  11728. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  11729. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11730. + */
  11731. +
  11732. +
  11733. +#include <GL/gl.h>
  11734. +#include <GL/glx.h>
  11735. +#include <assert.h>
  11736. +#include <stdio.h>
  11737. +#include <stdlib.h>
  11738. +#include <string.h>
  11739. +#include <unistd.h>
  11740. +#include <X11/keysym.h>
  11741. +
  11742. +
  11743. +#define MAX_CONTEXTS 2
  11744. +
  11745. +#define TEX_SIZE 32
  11746. +
  11747. +static const char *DisplayName = NULL;
  11748. +static Display *Dpy;
  11749. +static XVisualInfo *VisInfo;
  11750. +static Window Win;
  11751. +static GLXContext Contexts[MAX_CONTEXTS];
  11752. +static int WinWidth = 300, WinHeight = 300;
  11753. +
  11754. +static int DrawContext = 0, TexContext = 1;
  11755. +
  11756. +static GLuint TexObj = 0;
  11757. +static GLboolean NewTexture = GL_FALSE;
  11758. +
  11759. +
  11760. +static void
  11761. +Error(const char *msg)
  11762. +{
  11763. + fprintf(stderr, "sharedtex error: %s\n", msg);
  11764. + exit(1);
  11765. +}
  11766. +
  11767. +
  11768. +static void
  11769. +CreateWindow(const char *name)
  11770. +{
  11771. + int attrib[] = { GLX_RGBA,
  11772. + GLX_RED_SIZE, 1,
  11773. + GLX_GREEN_SIZE, 1,
  11774. + GLX_BLUE_SIZE, 1,
  11775. + GLX_DOUBLEBUFFER,
  11776. + None };
  11777. + int scrnum;
  11778. + XSetWindowAttributes attr;
  11779. + unsigned long mask;
  11780. + Window root;
  11781. + int xpos = 0, ypos = 0;
  11782. + static int n = 0;
  11783. +
  11784. + scrnum = DefaultScreen(Dpy);
  11785. + root = RootWindow(Dpy, scrnum);
  11786. +
  11787. + VisInfo = glXChooseVisual(Dpy, scrnum, attrib);
  11788. + if (!VisInfo) {
  11789. + Error("Unable to find RGB, double-buffered visual");
  11790. + }
  11791. +
  11792. + /* window attributes */
  11793. + xpos = (n % 10) * 100;
  11794. + ypos = (n / 10) * 100;
  11795. + n++;
  11796. +
  11797. + attr.background_pixel = 0;
  11798. + attr.border_pixel = 0;
  11799. + attr.colormap = XCreateColormap(Dpy, root, VisInfo->visual, AllocNone);
  11800. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  11801. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  11802. +
  11803. + Win = XCreateWindow(Dpy, root, xpos, ypos, WinWidth, WinHeight,
  11804. + 0, VisInfo->depth, InputOutput,
  11805. + VisInfo->visual, mask, &attr);
  11806. + if (!Win) {
  11807. + Error("Couldn't create window");
  11808. + }
  11809. +
  11810. + {
  11811. + XSizeHints sizehints;
  11812. + sizehints.x = xpos;
  11813. + sizehints.y = ypos;
  11814. + sizehints.width = WinWidth;
  11815. + sizehints.height = WinHeight;
  11816. + sizehints.flags = USSize | USPosition;
  11817. + XSetNormalHints(Dpy, Win, &sizehints);
  11818. + XSetStandardProperties(Dpy, Win, name, name,
  11819. + None, (char **)NULL, 0, &sizehints);
  11820. + }
  11821. +
  11822. + XMapWindow(Dpy, Win);
  11823. +}
  11824. +
  11825. +
  11826. +/**
  11827. + * Change texture image, using TexContext
  11828. + */
  11829. +static void
  11830. +ModifyTexture(void)
  11831. +{
  11832. + GLuint tex[TEX_SIZE][TEX_SIZE];
  11833. + GLuint c0, c1;
  11834. + int i, j;
  11835. +
  11836. + if (Win && !glXMakeCurrent(Dpy, Win, Contexts[TexContext])) {
  11837. + Error("glXMakeCurrent failed");
  11838. + }
  11839. +
  11840. + /* choose two random colors */
  11841. + c0 = rand() & 0xffffffff;
  11842. + c1 = rand() & 0xffffffff;
  11843. +
  11844. + for (i = 0; i < TEX_SIZE; i++) {
  11845. + for (j = 0; j < TEX_SIZE; j++) {
  11846. + if (((i / 4) ^ (j / 4)) & 1) {
  11847. + tex[i][j] = c0;
  11848. + }
  11849. + else {
  11850. + tex[i][j] = c1;
  11851. + }
  11852. + }
  11853. + }
  11854. +
  11855. + glBindTexture(GL_TEXTURE_2D, TexObj);
  11856. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
  11857. + GL_RGBA, GL_UNSIGNED_BYTE, tex);
  11858. +
  11859. + NewTexture = GL_TRUE;
  11860. +}
  11861. +
  11862. +
  11863. +static void
  11864. +InitContext(void)
  11865. +{
  11866. + glGenTextures(1, &TexObj);
  11867. + assert(TexObj);
  11868. + glBindTexture(GL_TEXTURE_2D, TexObj);
  11869. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  11870. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  11871. + glEnable(GL_TEXTURE_2D);
  11872. +
  11873. + printf("GL_RENDERER = %s\n", (char*) glGetString(GL_RENDERER));
  11874. +}
  11875. +
  11876. +
  11877. +static void
  11878. +Setup(void)
  11879. +{
  11880. + int i;
  11881. +
  11882. + Dpy = XOpenDisplay(DisplayName);
  11883. + if (!Dpy) {
  11884. + Error("Unable to open display");
  11885. + }
  11886. +
  11887. + CreateWindow("sharedtex");
  11888. +
  11889. + for (i = 0; i < MAX_CONTEXTS; i++) {
  11890. + GLXContext share = i > 0 ? Contexts[0] : 0;
  11891. +
  11892. + Contexts[i] = glXCreateContext(Dpy, VisInfo, share, True);
  11893. + if (!Contexts[i]) {
  11894. + Error("Unable to create GLX context");
  11895. + }
  11896. +
  11897. + if (!glXMakeCurrent(Dpy, Win, Contexts[i])) {
  11898. + Error("glXMakeCurrent failed");
  11899. + }
  11900. +
  11901. + InitContext();
  11902. + }
  11903. +
  11904. + ModifyTexture();
  11905. +}
  11906. +
  11907. +
  11908. +/**
  11909. + * Redraw window, using DrawContext
  11910. + */
  11911. +static void
  11912. +Redraw(void)
  11913. +{
  11914. + static float rot = 0.0;
  11915. + float ar;
  11916. +
  11917. + rot += 1.0;
  11918. +
  11919. + if (Win && !glXMakeCurrent(Dpy, Win, Contexts[DrawContext])) {
  11920. + Error("glXMakeCurrent failed");
  11921. + }
  11922. +
  11923. + glViewport(0, 0, WinWidth, WinHeight);
  11924. + ar = (float) WinWidth / (float) WinHeight;
  11925. + glMatrixMode(GL_PROJECTION);
  11926. + glLoadIdentity();
  11927. + glOrtho(-ar, ar, -1.0, 1.0, -1.0, 1.0);
  11928. + glMatrixMode(GL_MODELVIEW);
  11929. +
  11930. + glShadeModel(GL_FLAT);
  11931. + glClearColor(0.5, 0.5, 0.5, 1.0);
  11932. + glClear(GL_COLOR_BUFFER_BIT);
  11933. +
  11934. + glPushMatrix();
  11935. + glRotatef(rot, 0, 0, 1);
  11936. + glScalef(0.7, 0.7, 0.7);
  11937. +
  11938. + if (NewTexture) {
  11939. + /* rebind to get new contents */
  11940. + glBindTexture(GL_TEXTURE_2D, TexObj);
  11941. + NewTexture = GL_FALSE;
  11942. + }
  11943. +
  11944. + /* draw textured quad */
  11945. + glBegin(GL_POLYGON);
  11946. + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
  11947. + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
  11948. + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
  11949. + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
  11950. + glEnd();
  11951. +
  11952. + glPopMatrix();
  11953. +
  11954. + if (Win)
  11955. + glXSwapBuffers(Dpy, Win);
  11956. +}
  11957. +
  11958. +
  11959. +static void
  11960. +EventLoop(void)
  11961. +{
  11962. + while (1) {
  11963. + while (XPending(Dpy) > 0) {
  11964. + XEvent event;
  11965. + XNextEvent(Dpy, &event);
  11966. +
  11967. + switch (event.type) {
  11968. + case Expose:
  11969. + Redraw();
  11970. + break;
  11971. + case ConfigureNotify:
  11972. + WinWidth = event.xconfigure.width;
  11973. + WinHeight = event.xconfigure.height;
  11974. + break;
  11975. + case KeyPress:
  11976. + {
  11977. + char buf[100];
  11978. + KeySym keySym;
  11979. + XComposeStatus stat;
  11980. + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
  11981. + switch (keySym) {
  11982. + case XK_Escape:
  11983. + exit(0);
  11984. + break;
  11985. + case XK_t:
  11986. + case XK_T:
  11987. + ModifyTexture();
  11988. + break;
  11989. + default:
  11990. + ;
  11991. + }
  11992. + }
  11993. + Redraw();
  11994. + break;
  11995. + default:
  11996. + /*no-op*/ ;
  11997. + }
  11998. + }
  11999. +
  12000. + Redraw();
  12001. + usleep(10000);
  12002. + }
  12003. +}
  12004. +
  12005. +
  12006. +
  12007. +
  12008. +int
  12009. +main(int argc, char *argv[])
  12010. +{
  12011. + int i;
  12012. +
  12013. + for (i = 1; i < argc; i++) {
  12014. + if (strcmp(argv[i], "-display") == 0 && i < argc) {
  12015. + DisplayName = argv[i+1];
  12016. + i++;
  12017. + }
  12018. + }
  12019. +
  12020. + Setup();
  12021. +
  12022. + printf("Press 't' to change texture image/colors\n");
  12023. +
  12024. + EventLoop();
  12025. +
  12026. + return 0;
  12027. +}
  12028. diff -Naurp Mesa-7.8.1/progs/xdemos/sharedtex_mt.c Mesa-7.8.1.patched/progs/xdemos/sharedtex_mt.c
  12029. --- Mesa-7.8.1/progs/xdemos/sharedtex_mt.c 1970-01-01 01:00:00.000000000 +0100
  12030. +++ Mesa-7.8.1.patched/progs/xdemos/sharedtex_mt.c 2010-06-13 13:45:06.788792936 +0200
  12031. @@ -0,0 +1,490 @@
  12032. +/* $Id: sharedtex.c,v 1.2 2002/01/16 14:32:46 joukj Exp $ */
  12033. +
  12034. +/*
  12035. + * Test sharing of display lists and texture objects between GLX contests.
  12036. + * Brian Paul
  12037. + * Summer 2000
  12038. + *
  12039. + *
  12040. + * Copyright (C) 2000 Brian Paul All Rights Reserved.
  12041. + *
  12042. + * Permission is hereby granted, free of charge, to any person obtaining a
  12043. + * copy of this software and associated documentation files (the "Software"),
  12044. + * to deal in the Software without restriction, including without limitation
  12045. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12046. + * and/or sell copies of the Software, and to permit persons to whom the
  12047. + * Software is furnished to do so, subject to the following conditions:
  12048. + *
  12049. + * The above copyright notice and this permission notice shall be included
  12050. + * in all copies or substantial portions of the Software.
  12051. + *
  12052. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12053. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12054. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  12055. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  12056. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12057. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12058. + *
  12059. + *
  12060. + * Modified 2009 for multithreading by Thomas Hellstrom.
  12061. + */
  12062. +
  12063. +
  12064. +#include <GL/gl.h>
  12065. +#include <GL/glx.h>
  12066. +#include <stdio.h>
  12067. +#include <stdlib.h>
  12068. +#include <unistd.h>
  12069. +#include <string.h>
  12070. +#include <pthread.h>
  12071. +#include <X11/X.h>
  12072. +
  12073. +struct thread_init_arg {
  12074. + int id;
  12075. +};
  12076. +
  12077. +struct window {
  12078. + pthread_mutex_t drawMutex;
  12079. + char DisplayName[1000];
  12080. + Display *Dpy;
  12081. + Window Win;
  12082. + GLXContext Context;
  12083. + float Angle;
  12084. + int Id;
  12085. + XVisualInfo *visInfo;
  12086. +};
  12087. +
  12088. +
  12089. +#define MAX_WINDOWS 20
  12090. +static struct window Windows[MAX_WINDOWS];
  12091. +static int NumWindows = 0;
  12092. +static int terminate = 0;
  12093. +static GLXContext gCtx;
  12094. +static Display *gDpy;
  12095. +static GLuint Textures[3];
  12096. +
  12097. +
  12098. +
  12099. +static void
  12100. +Error(const char *display, const char *msg)
  12101. +{
  12102. + fprintf(stderr, "Error on display %s - %s\n", display, msg);
  12103. + exit(1);
  12104. +}
  12105. +
  12106. +
  12107. +static int
  12108. +initMainthread(Display *dpy, const char *displayName)
  12109. +{
  12110. + int scrnum;
  12111. + XVisualInfo *visinfo;
  12112. + int attrib[] = { GLX_RGBA,
  12113. + GLX_RED_SIZE, 1,
  12114. + GLX_GREEN_SIZE, 1,
  12115. + GLX_BLUE_SIZE, 1,
  12116. + GLX_DOUBLEBUFFER,
  12117. + GLX_DEPTH_SIZE, 1,
  12118. + None };
  12119. +
  12120. + scrnum = DefaultScreen(dpy);
  12121. + visinfo = glXChooseVisual(dpy, scrnum, attrib);
  12122. + if (!visinfo) {
  12123. + Error(displayName, "Unable to find RGB, double-buffered visual");
  12124. + return -1;
  12125. + }
  12126. + gCtx = glXCreateContext(dpy, visinfo, NULL, True);
  12127. + if (!gCtx) {
  12128. + Error(displayName, "Couldn't create GLX context");
  12129. + return -1;
  12130. + }
  12131. + return 0;
  12132. +}
  12133. +
  12134. +static struct window *
  12135. +AddWindow(Display *dpy, const char *displayName, int xpos, int ypos,
  12136. + GLXContext sCtx)
  12137. +{
  12138. + Window win;
  12139. + GLXContext ctx;
  12140. + int attrib[] = { GLX_RGBA,
  12141. + GLX_RED_SIZE, 1,
  12142. + GLX_GREEN_SIZE, 1,
  12143. + GLX_BLUE_SIZE, 1,
  12144. + GLX_DOUBLEBUFFER,
  12145. + GLX_DEPTH_SIZE, 1,
  12146. + None };
  12147. + int scrnum;
  12148. + XSetWindowAttributes attr;
  12149. + unsigned long mask;
  12150. + Window root;
  12151. + XVisualInfo *visinfo;
  12152. + int width = 300, height = 300;
  12153. +
  12154. + if (NumWindows >= MAX_WINDOWS)
  12155. + return NULL;
  12156. +
  12157. + scrnum = DefaultScreen(dpy);
  12158. + root = RootWindow(dpy, scrnum);
  12159. +
  12160. + visinfo = glXChooseVisual(dpy, scrnum, attrib);
  12161. + if (!visinfo) {
  12162. + Error(displayName, "Unable to find RGB, double-buffered visual");
  12163. + return NULL;
  12164. + }
  12165. +
  12166. + /* window attributes */
  12167. + attr.background_pixel = 0;
  12168. + attr.border_pixel = 0;
  12169. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  12170. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  12171. + mask = CWBorderPixel | CWColormap | CWEventMask;
  12172. +
  12173. + win = XCreateWindow(dpy, root, xpos, ypos, width, height,
  12174. + 0, visinfo->depth, InputOutput,
  12175. + visinfo->visual, mask, &attr);
  12176. + if (!win) {
  12177. + Error(displayName, "Couldn't create window");
  12178. + return NULL;
  12179. + }
  12180. +
  12181. + {
  12182. + XSizeHints sizehints;
  12183. + sizehints.x = xpos;
  12184. + sizehints.y = ypos;
  12185. + sizehints.width = width;
  12186. + sizehints.height = height;
  12187. + sizehints.flags = USSize | USPosition;
  12188. + XSetNormalHints(dpy, win, &sizehints);
  12189. + XSetStandardProperties(dpy, win, displayName, displayName,
  12190. + None, (char **)NULL, 0, &sizehints);
  12191. + }
  12192. +
  12193. +
  12194. + ctx = glXCreateContext(dpy, visinfo,
  12195. + sCtx ? sCtx : NULL, True);
  12196. +
  12197. + if (!ctx) {
  12198. + Error(displayName, "Couldn't create GLX context");
  12199. + return NULL;
  12200. + }
  12201. +
  12202. + XMapWindow(dpy, win);
  12203. +
  12204. + /* save the info for this window */
  12205. + {
  12206. + static int id = 0;
  12207. + struct window *h = &Windows[NumWindows];
  12208. + if (strlen(displayName) + 1 > sizeof(h->DisplayName)) {
  12209. + Error(displayName, "string overflow");
  12210. + return NULL;
  12211. + }
  12212. + strcpy(h->DisplayName, displayName);
  12213. + h->Dpy = dpy;
  12214. + h->Win = win;
  12215. + h->Context = ctx;
  12216. + h->Angle = 0.0;
  12217. + h->Id = id++;
  12218. + h->visInfo = visinfo;
  12219. + pthread_mutex_init(&h->drawMutex, NULL);
  12220. + NumWindows++;
  12221. + return &Windows[NumWindows-1];
  12222. + }
  12223. +}
  12224. +
  12225. +
  12226. +static void
  12227. +InitGLstuff(void)
  12228. +
  12229. +{
  12230. + glGenTextures(3, Textures);
  12231. +
  12232. + /* setup first texture object */
  12233. + {
  12234. + GLubyte image[16][16][4];
  12235. + GLint i, j;
  12236. + glBindTexture(GL_TEXTURE_2D, Textures[0]);
  12237. +
  12238. + /* red/white checkerboard */
  12239. + for (i = 0; i < 16; i++) {
  12240. + for (j = 0; j < 16; j++) {
  12241. + if ((i ^ j) & 1) {
  12242. + image[i][j][0] = 255;
  12243. + image[i][j][1] = 255;
  12244. + image[i][j][2] = 255;
  12245. + image[i][j][3] = 255;
  12246. + }
  12247. + else {
  12248. + image[i][j][0] = 255;
  12249. + image[i][j][1] = 0;
  12250. + image[i][j][2] = 0;
  12251. + image[i][j][3] = 255;
  12252. + }
  12253. + }
  12254. + }
  12255. +
  12256. + glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  12257. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
  12258. + GL_UNSIGNED_BYTE, image);
  12259. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  12260. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  12261. + }
  12262. +
  12263. + /* setup second texture object */
  12264. + {
  12265. + GLubyte image[8][8][3];
  12266. + GLint i, j;
  12267. + glBindTexture(GL_TEXTURE_2D, Textures[1]);
  12268. +
  12269. + /* green/yellow checkerboard */
  12270. + for (i = 0; i < 8; i++) {
  12271. + for (j = 0; j < 8; j++) {
  12272. + if ((i ^ j) & 1) {
  12273. + image[i][j][0] = 0;
  12274. + image[i][j][1] = 255;
  12275. + image[i][j][2] = 0;
  12276. + }
  12277. + else {
  12278. + image[i][j][0] = 255;
  12279. + image[i][j][1] = 255;
  12280. + image[i][j][2] = 0;
  12281. + }
  12282. + }
  12283. + }
  12284. +
  12285. + glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
  12286. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB,
  12287. + GL_UNSIGNED_BYTE, image);
  12288. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  12289. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  12290. + }
  12291. +
  12292. + /* setup second texture object */
  12293. + {
  12294. + GLubyte image[4][4][3];
  12295. + GLint i, j;
  12296. + glBindTexture(GL_TEXTURE_2D, Textures[2]);
  12297. +
  12298. + /* blue/gray checkerboard */
  12299. + for (i = 0; i < 4; i++) {
  12300. + for (j = 0; j < 4; j++) {
  12301. + if ((i ^ j) & 1) {
  12302. + image[i][j][0] = 0;
  12303. + image[i][j][1] = 0;
  12304. + image[i][j][2] = 255;
  12305. + }
  12306. + else {
  12307. + image[i][j][0] = 200;
  12308. + image[i][j][1] = 200;
  12309. + image[i][j][2] = 200;
  12310. + }
  12311. + }
  12312. + }
  12313. +
  12314. + glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
  12315. + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB,
  12316. + GL_UNSIGNED_BYTE, image);
  12317. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  12318. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  12319. + }
  12320. +
  12321. + /* Now make the cube object display list */
  12322. +
  12323. + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
  12324. + printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
  12325. + printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR));
  12326. +}
  12327. +
  12328. +static void
  12329. +Redraw(struct window *h)
  12330. +{
  12331. + pthread_mutex_lock(&h->drawMutex);
  12332. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  12333. + Error(h->DisplayName, "glXMakeCurrent failed in Redraw");
  12334. + pthread_mutex_unlock(&h->drawMutex);
  12335. + return;
  12336. + }
  12337. +
  12338. + h->Angle += 1.0;
  12339. +
  12340. + glShadeModel(GL_FLAT);
  12341. + glClearColor(0.25, 0.25, 0.25, 1.0);
  12342. + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  12343. +
  12344. + glEnable(GL_TEXTURE_2D);
  12345. + glEnable(GL_DEPTH_TEST);
  12346. + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  12347. +
  12348. + glColor3f(1, 1, 1);
  12349. +
  12350. + glPushMatrix();
  12351. + if (h->Id == 0)
  12352. + glRotatef(h->Angle, 0, 1, -1);
  12353. + else if (h->Id == 1)
  12354. + glRotatef(-(h->Angle), 0, 1, -1);
  12355. + else if (h->Id == 2)
  12356. + glRotatef(h->Angle, 0, 1, 1);
  12357. + else if (h->Id == 3)
  12358. + glRotatef(-(h->Angle), 0, 1, 1);
  12359. + glBindTexture(GL_TEXTURE_2D, Textures[0]);
  12360. + glBegin(GL_POLYGON);
  12361. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  12362. + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
  12363. + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
  12364. + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  12365. + glEnd();
  12366. + glBegin(GL_POLYGON);
  12367. + glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
  12368. + glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
  12369. + glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
  12370. + glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
  12371. + glEnd();
  12372. +
  12373. + glBindTexture(GL_TEXTURE_2D, Textures[1]);
  12374. + glBegin(GL_POLYGON);
  12375. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  12376. + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  12377. + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
  12378. + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  12379. + glEnd();
  12380. + glBegin(GL_POLYGON);
  12381. + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
  12382. + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
  12383. + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  12384. + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  12385. + glEnd();
  12386. +
  12387. + glBindTexture(GL_TEXTURE_2D, Textures[2]);
  12388. + glBegin(GL_POLYGON);
  12389. + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  12390. + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  12391. + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
  12392. + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
  12393. + glEnd();
  12394. + glBegin(GL_POLYGON);
  12395. + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
  12396. + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
  12397. + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  12398. + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  12399. + glEnd();
  12400. +
  12401. + glPopMatrix();
  12402. +
  12403. + glXSwapBuffers(h->Dpy, h->Win);
  12404. +
  12405. + if (!glXMakeCurrent(h->Dpy, None, NULL)) {
  12406. + Error(h->DisplayName, "glXMakeCurrent failed in Redraw");
  12407. + }
  12408. + pthread_mutex_unlock(&h->drawMutex);
  12409. +}
  12410. +
  12411. +static void *threadRunner (void *arg)
  12412. +{
  12413. + struct thread_init_arg *tia = (struct thread_init_arg *) arg;
  12414. + struct window *win;
  12415. +
  12416. + win = &Windows[tia->id];
  12417. +
  12418. + while(!terminate) {
  12419. + usleep(1000);
  12420. + Redraw(win);
  12421. + }
  12422. +
  12423. + return NULL;
  12424. +}
  12425. +
  12426. +static void
  12427. +Resize(struct window *h, unsigned int width, unsigned int height)
  12428. +{
  12429. + pthread_mutex_lock(&h->drawMutex);
  12430. +
  12431. + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
  12432. + Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
  12433. + pthread_mutex_unlock(&h->drawMutex);
  12434. + return;
  12435. + }
  12436. +
  12437. + glViewport(0, 0, width, height);
  12438. + glMatrixMode(GL_PROJECTION);
  12439. + glLoadIdentity();
  12440. + glFrustum(-1, 1, -1, 1, 2, 10);
  12441. + glMatrixMode(GL_MODELVIEW);
  12442. + glLoadIdentity();
  12443. + glTranslatef(0, 0, -4.5);
  12444. + if (!glXMakeCurrent(h->Dpy, None, NULL)) {
  12445. + Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
  12446. + }
  12447. + pthread_mutex_unlock(&h->drawMutex);
  12448. +}
  12449. +
  12450. +
  12451. +static void
  12452. +EventLoop(void)
  12453. +{
  12454. + while (1) {
  12455. + int i;
  12456. + XEvent event;
  12457. + XNextEvent(gDpy, &event);
  12458. + for (i = 0; i < NumWindows; i++) {
  12459. + struct window *h = &Windows[i];
  12460. + if (event.xany.window == h->Win) {
  12461. + switch (event.type) {
  12462. + case Expose:
  12463. + Redraw(h);
  12464. + break;
  12465. + case ConfigureNotify:
  12466. + Resize(h, event.xconfigure.width, event.xconfigure.height);
  12467. + break;
  12468. + case KeyPress:
  12469. + terminate = 1;
  12470. + return;
  12471. + default:
  12472. + /*no-op*/ ;
  12473. + }
  12474. + }
  12475. + }
  12476. + }
  12477. +}
  12478. +
  12479. +int
  12480. +main(int argc, char *argv[])
  12481. +{
  12482. + const char *dpyName = XDisplayName(NULL);
  12483. + pthread_t t0, t1, t2, t3;
  12484. + struct thread_init_arg tia0, tia1, tia2, tia3;
  12485. + struct window *h0;
  12486. +
  12487. + XInitThreads();
  12488. +
  12489. + gDpy = XOpenDisplay(dpyName);
  12490. + if (!gDpy) {
  12491. + Error(dpyName, "Unable to open display");
  12492. + return -1;
  12493. + }
  12494. +
  12495. + if (initMainthread(gDpy, dpyName))
  12496. + return -1;
  12497. +
  12498. + /* four windows and contexts sharing display lists and texture objects */
  12499. + h0 = AddWindow(gDpy, dpyName, 10, 10, gCtx);
  12500. + (void) AddWindow(gDpy, dpyName, 330, 10, gCtx);
  12501. + (void) AddWindow(gDpy, dpyName, 10, 350, gCtx);
  12502. + (void) AddWindow(gDpy, dpyName, 330, 350, gCtx);
  12503. +
  12504. + if (!glXMakeCurrent(gDpy, h0->Win, gCtx)) {
  12505. + Error(dpyName, "glXMakeCurrent failed for init thread.");
  12506. + return -1;
  12507. + }
  12508. +
  12509. + InitGLstuff();
  12510. +
  12511. + tia0.id = 0;
  12512. + pthread_create(&t0, NULL, threadRunner, &tia0);
  12513. + tia1.id = 1;
  12514. + pthread_create(&t1, NULL, threadRunner, &tia1);
  12515. + tia2.id = 2;
  12516. + pthread_create(&t2, NULL, threadRunner, &tia2);
  12517. + tia3.id = 3;
  12518. + pthread_create(&t3, NULL, threadRunner, &tia3);
  12519. + EventLoop();
  12520. + return 0;
  12521. +}
  12522. diff -Naurp Mesa-7.8.1/progs/xdemos/texture_from_pixmap.c Mesa-7.8.1.patched/progs/xdemos/texture_from_pixmap.c
  12523. --- Mesa-7.8.1/progs/xdemos/texture_from_pixmap.c 1970-01-01 01:00:00.000000000 +0100
  12524. +++ Mesa-7.8.1.patched/progs/xdemos/texture_from_pixmap.c 2010-06-13 13:45:06.789793146 +0200
  12525. @@ -0,0 +1,396 @@
  12526. +/*
  12527. + * Mesa 3-D graphics library
  12528. + * Version: 7.1
  12529. + *
  12530. + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
  12531. + *
  12532. + * Permission is hereby granted, free of charge, to any person obtaining a
  12533. + * copy of this software and associated documentation files (the "Software"),
  12534. + * to deal in the Software without restriction, including without limitation
  12535. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12536. + * and/or sell copies of the Software, and to permit persons to whom the
  12537. + * Software is furnished to do so, subject to the following conditions:
  12538. + *
  12539. + * The above copyright notice and this permission notice shall be included
  12540. + * in all copies or substantial portions of the Software.
  12541. + *
  12542. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12543. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12544. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  12545. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  12546. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12547. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12548. + */
  12549. +
  12550. +
  12551. +/*
  12552. + * Test the GLX_EXT_texture_from_pixmap extension
  12553. + * Brian Paul
  12554. + * 19 May 2007
  12555. + */
  12556. +
  12557. +
  12558. +#define GL_GLEXT_PROTOTYPES
  12559. +#define GLX_GLXEXT_PROTOTYPES
  12560. +#include <GL/gl.h>
  12561. +#include <GL/glx.h>
  12562. +#include <X11/keysym.h>
  12563. +#include <stdio.h>
  12564. +#include <stdlib.h>
  12565. +#include <string.h>
  12566. +#include <unistd.h>
  12567. +
  12568. +
  12569. +static float top, bottom;
  12570. +
  12571. +static PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT_func = NULL;
  12572. +static PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT_func = NULL;
  12573. +
  12574. +
  12575. +static Display *
  12576. +OpenDisplay(void)
  12577. +{
  12578. + int screen;
  12579. + Display *dpy;
  12580. + const char *ext;
  12581. +
  12582. + dpy = XOpenDisplay(NULL);
  12583. + if (!dpy) {
  12584. + printf("Couldn't open default display!\n");
  12585. + exit(1);
  12586. + }
  12587. +
  12588. + screen = DefaultScreen(dpy);
  12589. + ext = glXQueryExtensionsString(dpy, screen);
  12590. + if (!strstr(ext, "GLX_EXT_texture_from_pixmap")) {
  12591. + fprintf(stderr, "GLX_EXT_texture_from_pixmap not supported.\n");
  12592. + exit(1);
  12593. + }
  12594. +
  12595. + glXBindTexImageEXT_func = (PFNGLXBINDTEXIMAGEEXTPROC)
  12596. + glXGetProcAddress((GLubyte *) "glXBindTexImageEXT");
  12597. + glXReleaseTexImageEXT_func = (PFNGLXRELEASETEXIMAGEEXTPROC)
  12598. + glXGetProcAddress((GLubyte*) "glXReleaseTexImageEXT");
  12599. +
  12600. + if (!glXBindTexImageEXT_func || !glXReleaseTexImageEXT_func) {
  12601. + fprintf(stderr, "glXGetProcAddress failed!\n");
  12602. + exit(1);
  12603. + }
  12604. +
  12605. + return dpy;
  12606. +}
  12607. +
  12608. +
  12609. +static GLXFBConfig
  12610. +ChoosePixmapFBConfig(Display *display)
  12611. +{
  12612. + int screen = DefaultScreen(display);
  12613. + GLXFBConfig *fbconfigs;
  12614. + int i, nfbconfigs = 0, value;
  12615. +
  12616. + fbconfigs = glXGetFBConfigs(display, screen, &nfbconfigs);
  12617. + for (i = 0; i < nfbconfigs; i++) {
  12618. +
  12619. + glXGetFBConfigAttrib(display, fbconfigs[i], GLX_DRAWABLE_TYPE, &value);
  12620. + if (!(value & GLX_PIXMAP_BIT))
  12621. + continue;
  12622. +
  12623. + glXGetFBConfigAttrib(display, fbconfigs[i],
  12624. + GLX_BIND_TO_TEXTURE_TARGETS_EXT, &value);
  12625. + if (!(value & GLX_TEXTURE_2D_BIT_EXT))
  12626. + continue;
  12627. +
  12628. + glXGetFBConfigAttrib(display, fbconfigs[i],
  12629. + GLX_BIND_TO_TEXTURE_RGBA_EXT, &value);
  12630. + if (value == False) {
  12631. + glXGetFBConfigAttrib(display, fbconfigs[i],
  12632. + GLX_BIND_TO_TEXTURE_RGB_EXT, &value);
  12633. + if (value == False)
  12634. + continue;
  12635. + }
  12636. +
  12637. + glXGetFBConfigAttrib(display, fbconfigs[i],
  12638. + GLX_Y_INVERTED_EXT, &value);
  12639. + if (value == True) {
  12640. + top = 0.0f;
  12641. + bottom = 1.0f;
  12642. + }
  12643. + else {
  12644. + top = 1.0f;
  12645. + bottom = 0.0f;
  12646. + }
  12647. +
  12648. + break;
  12649. + }
  12650. +
  12651. + if (i == nfbconfigs) {
  12652. + printf("Unable to find FBconfig for texturing\n");
  12653. + exit(1);
  12654. + }
  12655. +
  12656. + return fbconfigs[i];
  12657. +}
  12658. +
  12659. +
  12660. +static GLXPixmap
  12661. +CreatePixmap(Display *dpy, GLXFBConfig config, int w, int h, Pixmap *p)
  12662. +{
  12663. + GLXPixmap gp;
  12664. + const int pixmapAttribs[] = {
  12665. + GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
  12666. + GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
  12667. + None
  12668. + };
  12669. + Window root = RootWindow(dpy, 0);
  12670. +
  12671. + *p = XCreatePixmap(dpy, root, w, h, 24);
  12672. + XSync(dpy, 0);
  12673. + gp = glXCreatePixmap(dpy, config, *p, pixmapAttribs);
  12674. + XSync(dpy, 0);
  12675. +
  12676. + return gp;
  12677. +}
  12678. +
  12679. +
  12680. +static void
  12681. +DrawPixmapImage(Display *dpy, Pixmap pm, int w, int h)
  12682. +{
  12683. + XGCValues gcvals;
  12684. + GC gc;
  12685. +
  12686. + gcvals.background = 0;
  12687. + gc = XCreateGC(dpy, pm, GCBackground, &gcvals);
  12688. +
  12689. + XSetForeground(dpy, gc, 0x0);
  12690. + XFillRectangle(dpy, pm, gc, 0, 0, w, h);
  12691. +
  12692. + XSetForeground(dpy, gc, 0xff0000);
  12693. + XFillRectangle(dpy, pm, gc, 0, 0, 50, 50);
  12694. +
  12695. + XSetForeground(dpy, gc, 0x00ff00);
  12696. + XFillRectangle(dpy, pm, gc, w - 50, 0, 50, 50);
  12697. +
  12698. + XSetForeground(dpy, gc, 0x0000ff);
  12699. + XFillRectangle(dpy, pm, gc, 0, h - 50, 50, 50);
  12700. +
  12701. + XSetForeground(dpy, gc, 0xffffff);
  12702. + XFillRectangle(dpy, pm, gc, h - 50, h - 50, 50, 50);
  12703. +
  12704. + XSetForeground(dpy, gc, 0xffff00);
  12705. + XSetLineAttributes(dpy, gc, 3, LineSolid, CapButt, JoinBevel);
  12706. + XDrawLine(dpy, pm, gc, 0, 0, w, h);
  12707. + XDrawLine(dpy, pm, gc, 0, h, w, 0);
  12708. +
  12709. + XFreeGC(dpy, gc);
  12710. +}
  12711. +
  12712. +
  12713. +static XVisualInfo *
  12714. +ChooseWindowVisual(Display *dpy)
  12715. +{
  12716. + int screen = DefaultScreen(dpy);
  12717. + XVisualInfo *visinfo;
  12718. + int attribs[] = {
  12719. + GLX_RGBA,
  12720. + GLX_RED_SIZE, 1,
  12721. + GLX_GREEN_SIZE, 1,
  12722. + GLX_BLUE_SIZE, 1,
  12723. + GLX_DOUBLEBUFFER,
  12724. + None
  12725. + };
  12726. +
  12727. + visinfo = glXChooseVisual(dpy, screen, attribs);
  12728. + if (!visinfo) {
  12729. + printf("Unable to find RGB, double-buffered visual\n");
  12730. + exit(1);
  12731. + }
  12732. +
  12733. + return visinfo;
  12734. +}
  12735. +
  12736. +
  12737. +static Window
  12738. +CreateWindow(Display *dpy, XVisualInfo *visinfo,
  12739. + int width, int height, const char *name)
  12740. +{
  12741. + int screen = DefaultScreen(dpy);
  12742. + Window win;
  12743. + XSetWindowAttributes attr;
  12744. + unsigned long mask;
  12745. + Window root;
  12746. +
  12747. + root = RootWindow(dpy, screen);
  12748. +
  12749. + /* window attributes */
  12750. + attr.background_pixel = 0;
  12751. + attr.border_pixel = 0;
  12752. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  12753. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  12754. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  12755. +
  12756. + win = XCreateWindow(dpy, root, 0, 0, width, height,
  12757. + 0, visinfo->depth, InputOutput,
  12758. + visinfo->visual, mask, &attr);
  12759. + if (win) {
  12760. + XSizeHints sizehints;
  12761. + sizehints.width = width;
  12762. + sizehints.height = height;
  12763. + sizehints.flags = USSize;
  12764. + XSetNormalHints(dpy, win, &sizehints);
  12765. + XSetStandardProperties(dpy, win, name, name,
  12766. + None, (char **)NULL, 0, &sizehints);
  12767. +
  12768. + XMapWindow(dpy, win);
  12769. + }
  12770. + return win;
  12771. +}
  12772. +
  12773. +
  12774. +static void
  12775. +BindPixmapTexture(Display *dpy, GLXPixmap gp)
  12776. +{
  12777. + GLuint texture;
  12778. +
  12779. + glGenTextures(1, &texture);
  12780. + glBindTexture(GL_TEXTURE_2D, texture);
  12781. +
  12782. + glXBindTexImageEXT_func(dpy, gp, GLX_FRONT_LEFT_EXT, NULL);
  12783. +
  12784. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  12785. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  12786. +
  12787. + glEnable(GL_TEXTURE_2D);
  12788. + /*
  12789. + glXReleaseTexImageEXT_func(display, glxpixmap, GLX_FRONT_LEFT_EXT);
  12790. + */
  12791. +}
  12792. +
  12793. +
  12794. +static void
  12795. +Resize(Window win, unsigned int width, unsigned int height)
  12796. +{
  12797. + float sz = 1.5;
  12798. + glViewport(0, 0, width, height);
  12799. + glMatrixMode(GL_PROJECTION);
  12800. + glLoadIdentity();
  12801. + glOrtho(-sz, sz, -sz, sz, -1.0, 1.0);
  12802. + glMatrixMode(GL_MODELVIEW);
  12803. +}
  12804. +
  12805. +
  12806. +static void
  12807. +Redraw(Display *dpy, Window win, float rot)
  12808. +{
  12809. + glClearColor(0.25, 0.25, 0.25, 0.0);
  12810. + glClear(GL_COLOR_BUFFER_BIT);
  12811. + glPushMatrix();
  12812. + glRotatef(rot, 0, 0, 1);
  12813. + glRotatef(2.0 * rot, 1, 0, 0);
  12814. +
  12815. + glBegin(GL_QUADS);
  12816. + glTexCoord2d(0.0, bottom);
  12817. + glVertex2f(-1, -1);
  12818. + glTexCoord2d(1.0, bottom);
  12819. + glVertex2f( 1, -1);
  12820. + glTexCoord2d(1.0, top);
  12821. + glVertex2d(1.0, 1.0);
  12822. + glTexCoord2d(0.0, top);
  12823. + glVertex2f(-1.0, 1.0);
  12824. + glEnd();
  12825. +
  12826. + glPopMatrix();
  12827. +
  12828. + glXSwapBuffers(dpy, win);
  12829. +}
  12830. +
  12831. +
  12832. +static void
  12833. +EventLoop(Display *dpy, Window win)
  12834. +{
  12835. + GLfloat rot = 0.0;
  12836. + int anim = 0;
  12837. +
  12838. + while (1) {
  12839. + if (!anim || XPending(dpy) > 0) {
  12840. + XEvent event;
  12841. + XNextEvent(dpy, &event);
  12842. +
  12843. + switch (event.type) {
  12844. + case Expose:
  12845. + Redraw(dpy, win, rot);
  12846. + break;
  12847. + case ConfigureNotify:
  12848. + Resize(event.xany.window,
  12849. + event.xconfigure.width,
  12850. + event.xconfigure.height);
  12851. + break;
  12852. + case KeyPress:
  12853. + {
  12854. + char buf[100];
  12855. + KeySym keySym;
  12856. + XComposeStatus stat;
  12857. + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
  12858. + if (keySym == XK_Escape) {
  12859. + return; /* exit */
  12860. + }
  12861. + else if (keySym == XK_r) {
  12862. + rot += 1.0;
  12863. + Redraw(dpy, win, rot);
  12864. + }
  12865. + else if (keySym == XK_a) {
  12866. + anim = !anim;
  12867. + }
  12868. + else if (keySym == XK_R) {
  12869. + rot -= 1.0;
  12870. + Redraw(dpy, win, rot);
  12871. + }
  12872. + }
  12873. + break;
  12874. + default:
  12875. + ; /*no-op*/
  12876. + }
  12877. + }
  12878. + else {
  12879. + /* animate */
  12880. + rot += 1.0;
  12881. + Redraw(dpy, win, rot);
  12882. + }
  12883. + }
  12884. +}
  12885. +
  12886. +
  12887. +
  12888. +int
  12889. +main(int argc, char *argv[])
  12890. +{
  12891. + Display *dpy;
  12892. + GLXFBConfig pixmapConfig;
  12893. + XVisualInfo *windowVis;
  12894. + GLXPixmap gp;
  12895. + Window win;
  12896. + GLXContext ctx;
  12897. + Pixmap p;
  12898. +
  12899. + dpy = OpenDisplay();
  12900. +
  12901. + pixmapConfig = ChoosePixmapFBConfig(dpy);
  12902. + windowVis = ChooseWindowVisual(dpy);
  12903. + win = CreateWindow(dpy, windowVis, 500, 500, "Texture From Pixmap");
  12904. +
  12905. + gp = CreatePixmap(dpy, pixmapConfig, 512, 512, &p);
  12906. + DrawPixmapImage(dpy, p, 512, 512);
  12907. +
  12908. + ctx = glXCreateContext(dpy, windowVis, NULL, True);
  12909. + if (!ctx) {
  12910. + printf("Couldn't create GLX context\n");
  12911. + exit(1);
  12912. + }
  12913. +
  12914. + glXMakeCurrent(dpy, win, ctx);
  12915. +
  12916. + BindPixmapTexture(dpy, gp);
  12917. +
  12918. + EventLoop(dpy, win);
  12919. +
  12920. + return 0;
  12921. +}
  12922. diff -Naurp Mesa-7.8.1/progs/xdemos/wincopy.c Mesa-7.8.1.patched/progs/xdemos/wincopy.c
  12923. --- Mesa-7.8.1/progs/xdemos/wincopy.c 1970-01-01 01:00:00.000000000 +0100
  12924. +++ Mesa-7.8.1.patched/progs/xdemos/wincopy.c 2010-06-13 13:45:06.789793146 +0200
  12925. @@ -0,0 +1,328 @@
  12926. +/*
  12927. + * Mesa 3-D graphics library
  12928. + * Version: 6.5.2
  12929. + *
  12930. + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
  12931. + *
  12932. + * Permission is hereby granted, free of charge, to any person obtaining a
  12933. + * copy of this software and associated documentation files (the "Software"),
  12934. + * to deal in the Software without restriction, including without limitation
  12935. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12936. + * and/or sell copies of the Software, and to permit persons to whom the
  12937. + * Software is furnished to do so, subject to the following conditions:
  12938. + *
  12939. + * The above copyright notice and this permission notice shall be included
  12940. + * in all copies or substantial portions of the Software.
  12941. + *
  12942. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12943. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12944. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  12945. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  12946. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12947. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12948. + */
  12949. +
  12950. +
  12951. +/*
  12952. + * This program opens two GLX windows, renders into one and uses
  12953. + * glCopyPixels to copy the image from the first window into the
  12954. + * second by means of the GLX 1.3 function glxMakeContextCurrent().
  12955. + * This function works just like the glXMakeCurrentReadSGI() function
  12956. + * in the GLX_SGI_make_current_read extension.
  12957. + */
  12958. +
  12959. +
  12960. +#define GL_GLEXT_PROTOTYPES
  12961. +#define GLX_GLXEXT_PROTOTYPES
  12962. +#include <GL/gl.h>
  12963. +#include <GL/glx.h>
  12964. +#include <X11/keysym.h>
  12965. +#include <stdio.h>
  12966. +#include <stdlib.h>
  12967. +#include <string.h>
  12968. +#include <unistd.h>
  12969. +
  12970. +
  12971. +#ifdef GLX_VERSION_1_3
  12972. +
  12973. +
  12974. +static Display *Dpy;
  12975. +static int ScrNum;
  12976. +static GLXContext Context;
  12977. +static Window Win[2]; /* Win[0] = source, Win[1] = dest */
  12978. +static GLint Width[2], Height[2];
  12979. +static GLboolean TestClipping = GL_FALSE;
  12980. +static GLfloat Angle = 0.0;
  12981. +
  12982. +static GLboolean DrawFront = GL_FALSE;
  12983. +
  12984. +PFNGLXMAKECURRENTREADSGIPROC make_context_current = NULL;
  12985. +
  12986. +static Window
  12987. +CreateWindow(Display *dpy, int scrnum, XVisualInfo *visinfo,
  12988. + int xpos, int ypos, int width, int height,
  12989. + const char *name)
  12990. +{
  12991. + Window win;
  12992. + XSetWindowAttributes attr;
  12993. + unsigned long mask;
  12994. + Window root;
  12995. +
  12996. + root = RootWindow(dpy, scrnum);
  12997. +
  12998. + /* window attributes */
  12999. + attr.background_pixel = 0;
  13000. + attr.border_pixel = 0;
  13001. + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  13002. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  13003. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  13004. +
  13005. + win = XCreateWindow(dpy, root, xpos, ypos, width, height,
  13006. + 0, visinfo->depth, InputOutput,
  13007. + visinfo->visual, mask, &attr);
  13008. + if (win) {
  13009. + XSizeHints sizehints;
  13010. + sizehints.x = xpos;
  13011. + sizehints.y = ypos;
  13012. + sizehints.width = width;
  13013. + sizehints.height = height;
  13014. + sizehints.flags = USSize | USPosition;
  13015. + XSetNormalHints(dpy, win, &sizehints);
  13016. + XSetStandardProperties(dpy, win, name, name,
  13017. + None, (char **)NULL, 0, &sizehints);
  13018. +
  13019. + XMapWindow(dpy, win);
  13020. + }
  13021. + return win;
  13022. +}
  13023. +
  13024. +
  13025. +static void
  13026. +Redraw(void)
  13027. +{
  13028. + /* make the first window the current one */
  13029. + if (! (*make_context_current)(Dpy, Win[0], Win[0], Context)) {
  13030. + printf("glXMakeContextCurrent failed in Redraw()\n");
  13031. + return;
  13032. + }
  13033. +
  13034. + Angle += 1.0;
  13035. +
  13036. + if (DrawFront) {
  13037. + glDrawBuffer(GL_FRONT);
  13038. + glReadBuffer(GL_FRONT);
  13039. + }
  13040. + else {
  13041. + glDrawBuffer(GL_BACK);
  13042. + glReadBuffer(GL_BACK);
  13043. + }
  13044. +
  13045. + glViewport(0, 0, Width[0], Height[0]);
  13046. + glMatrixMode(GL_PROJECTION);
  13047. + glLoadIdentity();
  13048. + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  13049. + glMatrixMode(GL_MODELVIEW);
  13050. +
  13051. + glShadeModel(GL_FLAT);
  13052. + glClearColor(0.5, 0.5, 0.5, 0.0);
  13053. + glClear(GL_COLOR_BUFFER_BIT);
  13054. +
  13055. + /* draw blue quad */
  13056. + glColor3f(0.3, 0.3, 1.0);
  13057. + glPushMatrix();
  13058. + glRotatef(Angle, 0, 0, 1);
  13059. + glBegin(GL_POLYGON);
  13060. + glVertex2f(-0.5, -0.25);
  13061. + glVertex2f( 0.5, -0.25);
  13062. + glVertex2f( 0.5, 0.25);
  13063. + glVertex2f(-0.5, 0.25);
  13064. + glEnd();
  13065. + glPopMatrix();
  13066. +
  13067. + if (DrawFront)
  13068. + glFinish();
  13069. + else
  13070. + glXSwapBuffers(Dpy, Win[0]);
  13071. +
  13072. +
  13073. + /* copy image from window 0 to window 1 */
  13074. + if (!(*make_context_current)(Dpy, Win[1], Win[0], Context)) {
  13075. + printf("glXMakeContextCurrent failed in Redraw()\n");
  13076. + return;
  13077. + }
  13078. +
  13079. + /* copy the image between windows */
  13080. + glClearColor(0.0, 0.0, 0.0, 0.0);
  13081. + glClear(GL_COLOR_BUFFER_BIT);
  13082. +
  13083. + if (TestClipping) {
  13084. + glWindowPos2iARB(-2, -2);
  13085. + glCopyPixels(-2, -2, Width[0] + 4, Height[0] + 4, GL_COLOR);
  13086. + }
  13087. + else {
  13088. + glWindowPos2iARB(0, 0);
  13089. + glCopyPixels(0, 0, Width[0], Height[0], GL_COLOR);
  13090. + }
  13091. +
  13092. + if (DrawFront)
  13093. + glFinish();
  13094. + else
  13095. + glXSwapBuffers(Dpy, Win[1]);
  13096. +}
  13097. +
  13098. +
  13099. +
  13100. +static void
  13101. +Resize(Window win, unsigned int width, unsigned int height)
  13102. +{
  13103. + int i;
  13104. + if (win == Win[0]) {
  13105. + i = 0;
  13106. + }
  13107. + else {
  13108. + i = 1;
  13109. + }
  13110. + Width[i] = width;
  13111. + Height[i] = height;
  13112. + if (!glXMakeCurrent(Dpy, Win[i], Context)) {
  13113. + printf("glXMakeCurrent failed in Resize()\n");
  13114. + return;
  13115. + }
  13116. +}
  13117. +
  13118. +
  13119. +
  13120. +static void
  13121. +EventLoop(void)
  13122. +{
  13123. + XEvent event;
  13124. + while (1) {
  13125. + if (XPending(Dpy) > 0) {
  13126. + XNextEvent( Dpy, &event );
  13127. + switch (event.type) {
  13128. + case Expose:
  13129. + Redraw();
  13130. + break;
  13131. + case ConfigureNotify:
  13132. + Resize(event.xany.window, event.xconfigure.width, event.xconfigure.height);
  13133. + break;
  13134. + case KeyPress:
  13135. + {
  13136. + char buf[100];
  13137. + KeySym keySym;
  13138. + XComposeStatus stat;
  13139. + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
  13140. + if (keySym == XK_Escape) {
  13141. + /* exit */
  13142. + return;
  13143. + }
  13144. + else if (buf[0] == 'f') {
  13145. + DrawFront = !DrawFront;
  13146. + printf("Drawing to %s buffer\n",
  13147. + DrawFront ? "GL_FRONT" : "GL_BACK");
  13148. + }
  13149. + }
  13150. + break;
  13151. + default:
  13152. + /*no-op*/ ;
  13153. + }
  13154. + }
  13155. + else {
  13156. + /* animate */
  13157. + Redraw();
  13158. + }
  13159. + }
  13160. +}
  13161. +
  13162. +
  13163. +static void
  13164. +Init(void)
  13165. +{
  13166. + XVisualInfo *visinfo;
  13167. + int attrib[] = { GLX_RGBA,
  13168. + GLX_RED_SIZE, 1,
  13169. + GLX_GREEN_SIZE, 1,
  13170. + GLX_BLUE_SIZE, 1,
  13171. + GLX_DOUBLEBUFFER,
  13172. + None };
  13173. + int major, minor;
  13174. +
  13175. + Dpy = XOpenDisplay(NULL);
  13176. + if (!Dpy) {
  13177. + printf("Couldn't open default display!\n");
  13178. + exit(1);
  13179. + }
  13180. +
  13181. + ScrNum = DefaultScreen(Dpy);
  13182. +
  13183. + glXQueryVersion(Dpy, &major, &minor);
  13184. +
  13185. + if (major * 100 + minor >= 103) {
  13186. + make_context_current = (PFNGLXMAKECURRENTREADSGIPROC)
  13187. + glXGetProcAddressARB( (GLubyte *) "glXMakeContextCurrent" );
  13188. + }
  13189. + else {
  13190. + const char * const glxExtensions = glXQueryExtensionsString(Dpy, ScrNum);
  13191. + const char * ext = strstr( glxExtensions, "GLX_SGI_make_current_read" );
  13192. + const size_t len = strlen( "GLX_SGI_make_current_read" );
  13193. +
  13194. + if ( (ext != NULL)
  13195. + && ((ext[len] == ' ') || (ext[len] == '\0')) ) {
  13196. + make_context_current = (PFNGLXMAKECURRENTREADSGIPROC)
  13197. + glXGetProcAddressARB( (GLubyte *) "glXMakeCurrentReadSGI" );
  13198. + }
  13199. + }
  13200. +
  13201. + if (make_context_current == NULL) {
  13202. + fprintf(stderr, "Sorry, this program requires either GLX 1.3 "
  13203. + "or GLX_SGI_make_current_read.\n");
  13204. + exit(1);
  13205. + }
  13206. +
  13207. + visinfo = glXChooseVisual(Dpy, ScrNum, attrib);
  13208. + if (!visinfo) {
  13209. + printf("Unable to find RGB, double-buffered visual\n");
  13210. + exit(1);
  13211. + }
  13212. +
  13213. + Context = glXCreateContext(Dpy, visinfo, NULL, True);
  13214. + if (!Context) {
  13215. + printf("Couldn't create GLX context\n");
  13216. + exit(1);
  13217. + }
  13218. +
  13219. +
  13220. + Win[0] = CreateWindow(Dpy, ScrNum, visinfo,
  13221. + 0, 0, 300, 300, "source window");
  13222. +
  13223. + Win[1] = CreateWindow(Dpy, ScrNum, visinfo,
  13224. + 350, 0, 300, 300, "dest window");
  13225. +
  13226. + printf("Press Esc to exit\n");
  13227. + printf("Press 'f' to toggle front/back buffer drawing\n");
  13228. +}
  13229. +
  13230. +
  13231. +int
  13232. +main(int argc, char *argv[])
  13233. +{
  13234. + if (argc > 1 && strcmp(argv[1], "-clip") == 0)
  13235. + TestClipping = GL_TRUE;
  13236. + Init();
  13237. + EventLoop();
  13238. + return 0;
  13239. +}
  13240. +
  13241. +
  13242. +#else
  13243. +
  13244. +
  13245. +int
  13246. +main(int argc, char *argv[])
  13247. +{
  13248. + printf("This program requires GLX 1.3!\n");
  13249. + return 0;
  13250. +}
  13251. +
  13252. +
  13253. +#endif /* GLX_VERSION_1_3 */
  13254. diff -Naurp Mesa-7.8.1/progs/xdemos/xdemo.c Mesa-7.8.1.patched/progs/xdemos/xdemo.c
  13255. --- Mesa-7.8.1/progs/xdemos/xdemo.c 1970-01-01 01:00:00.000000000 +0100
  13256. +++ Mesa-7.8.1.patched/progs/xdemos/xdemo.c 2010-06-13 13:45:06.788792936 +0200
  13257. @@ -0,0 +1,334 @@
  13258. +
  13259. +/*
  13260. + * Very simple demo of how to use the Mesa/X11 interface instead of the
  13261. + * glx, tk or aux toolkits. I highly recommend using the GLX interface
  13262. + * instead of the X/Mesa interface, however.
  13263. + *
  13264. + * This program is in the public domain.
  13265. + *
  13266. + * Brian Paul
  13267. + */
  13268. +
  13269. +#include <stdio.h>
  13270. +#include <stdlib.h>
  13271. +#include <string.h>
  13272. +#include <X11/Xlib.h>
  13273. +#include <X11/Xutil.h>
  13274. +#include "GL/xmesa.h"
  13275. +#include "GL/gl.h"
  13276. +
  13277. +
  13278. +
  13279. +static GLint Black, Red, Green, Blue;
  13280. +
  13281. +
  13282. +
  13283. +static void make_window( char *title, int color_flag )
  13284. +{
  13285. + int x = 10, y = 10, width = 400, height = 300;
  13286. + Display *dpy;
  13287. + int scr;
  13288. + Window root, win;
  13289. + Colormap cmap;
  13290. + XColor xcolor;
  13291. + int attr_flags;
  13292. + XVisualInfo *visinfo;
  13293. + XSetWindowAttributes attr;
  13294. + XTextProperty tp;
  13295. + XSizeHints sh;
  13296. + XEvent e;
  13297. + XMesaContext context;
  13298. + XMesaVisual visual;
  13299. + XMesaBuffer buffer;
  13300. +
  13301. +
  13302. + /*
  13303. + * Do the usual X things to make a window.
  13304. + */
  13305. +
  13306. + dpy = XOpenDisplay(NULL);
  13307. + if (!dpy) {
  13308. + printf("Couldn't open default display!\n");
  13309. + exit(1);
  13310. + }
  13311. +
  13312. + scr = DefaultScreen(dpy);
  13313. + root = RootWindow(dpy, scr);
  13314. +
  13315. + /* alloc visinfo struct */
  13316. + visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) );
  13317. +
  13318. + /* Get a visual and colormap */
  13319. + if (color_flag) {
  13320. + /* Open TrueColor window */
  13321. +
  13322. +/*
  13323. + if (!XMatchVisualInfo( dpy, scr, 24, TrueColor, visinfo )) {
  13324. + printf("Couldn't get 24-bit TrueColor visual!\n");
  13325. + exit(1);
  13326. + }
  13327. +*/
  13328. + if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
  13329. + printf("Couldn't get 8-bit PseudoColor visual!\n");
  13330. + exit(1);
  13331. + }
  13332. +
  13333. + cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
  13334. + Black = Red = Green = Blue = 0;
  13335. + }
  13336. + else {
  13337. + /* Open color index window */
  13338. +
  13339. + if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
  13340. + printf("Couldn't get 8-bit PseudoColor visual\n");
  13341. + exit(1);
  13342. + }
  13343. +
  13344. + cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
  13345. +
  13346. + /* Allocate colors */
  13347. + xcolor.red = 0x0;
  13348. + xcolor.green = 0x0;
  13349. + xcolor.blue = 0x0;
  13350. + xcolor.flags = DoRed | DoGreen | DoBlue;
  13351. + if (!XAllocColor( dpy, cmap, &xcolor )) {
  13352. + printf("Couldn't allocate black!\n");
  13353. + exit(1);
  13354. + }
  13355. + Black = xcolor.pixel;
  13356. +
  13357. + xcolor.red = 0xffff;
  13358. + xcolor.green = 0x0;
  13359. + xcolor.blue = 0x0;
  13360. + xcolor.flags = DoRed | DoGreen | DoBlue;
  13361. + if (!XAllocColor( dpy, cmap, &xcolor )) {
  13362. + printf("Couldn't allocate red!\n");
  13363. + exit(1);
  13364. + }
  13365. + Red = xcolor.pixel;
  13366. +
  13367. + xcolor.red = 0x0;
  13368. + xcolor.green = 0xffff;
  13369. + xcolor.blue = 0x0;
  13370. + xcolor.flags = DoRed | DoGreen | DoBlue;
  13371. + if (!XAllocColor( dpy, cmap, &xcolor )) {
  13372. + printf("Couldn't allocate green!\n");
  13373. + exit(1);
  13374. + }
  13375. + Green = xcolor.pixel;
  13376. +
  13377. + xcolor.red = 0x0;
  13378. + xcolor.green = 0x0;
  13379. + xcolor.blue = 0xffff;
  13380. + xcolor.flags = DoRed | DoGreen | DoBlue;
  13381. + if (!XAllocColor( dpy, cmap, &xcolor )) {
  13382. + printf("Couldn't allocate blue!\n");
  13383. + exit(1);
  13384. + }
  13385. + Blue = xcolor.pixel;
  13386. + }
  13387. +
  13388. + /* set window attributes */
  13389. + attr.colormap = cmap;
  13390. + attr.event_mask = ExposureMask | StructureNotifyMask;
  13391. + attr.border_pixel = BlackPixel( dpy, scr );
  13392. + attr.background_pixel = BlackPixel( dpy, scr );
  13393. + attr_flags = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel;
  13394. +
  13395. + /* Create the window */
  13396. + win = XCreateWindow( dpy, root, x,y, width, height, 0,
  13397. + visinfo->depth, InputOutput,
  13398. + visinfo->visual,
  13399. + attr_flags, &attr);
  13400. + if (!win) {
  13401. + printf("Couldn't open window!\n");
  13402. + exit(1);
  13403. + }
  13404. +
  13405. + XStringListToTextProperty(&title, 1, &tp);
  13406. + sh.flags = USPosition | USSize;
  13407. + XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
  13408. + XMapWindow(dpy, win);
  13409. + while (1) {
  13410. + XNextEvent( dpy, &e );
  13411. + if (e.type == MapNotify && e.xmap.window == win) {
  13412. + break;
  13413. + }
  13414. + }
  13415. +
  13416. +
  13417. + /*
  13418. + * Now do the special Mesa/Xlib stuff!
  13419. + */
  13420. +
  13421. + visual = XMesaCreateVisual( dpy, visinfo,
  13422. + (GLboolean) color_flag,
  13423. + GL_FALSE, /* alpha_flag */
  13424. + GL_FALSE, /* db_flag */
  13425. + GL_FALSE, /* stereo flag */
  13426. + GL_FALSE, /* ximage_flag */
  13427. + 0, /* depth size */
  13428. + 0, /* stencil size */
  13429. + 0,0,0,0, /* accum_size */
  13430. + 0, /* num samples */
  13431. + 0, /* level */
  13432. + 0 /* caveat */
  13433. + );
  13434. + if (!visual) {
  13435. + printf("Couldn't create Mesa/X visual!\n");
  13436. + exit(1);
  13437. + }
  13438. +
  13439. + /* Create a Mesa rendering context */
  13440. + context = XMesaCreateContext( visual,
  13441. + NULL /* share_list */
  13442. + );
  13443. + if (!context) {
  13444. + printf("Couldn't create Mesa/X context!\n");
  13445. + exit(1);
  13446. + }
  13447. +
  13448. + buffer = XMesaCreateWindowBuffer( visual, win );
  13449. + if (!buffer) {
  13450. + printf("Couldn't create Mesa/X buffer!\n");
  13451. + exit(1);
  13452. + }
  13453. +
  13454. +
  13455. + XMesaMakeCurrent( context, buffer );
  13456. +
  13457. + /* Ready to render! */
  13458. +}
  13459. +
  13460. +
  13461. +
  13462. +static void draw_cube( void )
  13463. +{
  13464. + /* X faces */
  13465. + glIndexi( Red );
  13466. + glColor3f( 1.0, 0.0, 0.0 );
  13467. + glBegin( GL_POLYGON );
  13468. + glVertex3f( 1.0, 1.0, 1.0 );
  13469. + glVertex3f( 1.0, -1.0, 1.0 );
  13470. + glVertex3f( 1.0, -1.0, -1.0 );
  13471. + glVertex3f( 1.0, 1.0, -1.0 );
  13472. + glEnd();
  13473. +
  13474. + glBegin( GL_POLYGON );
  13475. + glVertex3f( -1.0, 1.0, 1.0 );
  13476. + glVertex3f( -1.0, 1.0, -1.0 );
  13477. + glVertex3f( -1.0, -1.0, -1.0 );
  13478. + glVertex3f( -1.0, -1.0, 1.0 );
  13479. + glEnd();
  13480. +
  13481. + /* Y faces */
  13482. + glIndexi( Green );
  13483. + glColor3f( 0.0, 1.0, 0.0 );
  13484. + glBegin( GL_POLYGON );
  13485. + glVertex3f( 1.0, 1.0, 1.0 );
  13486. + glVertex3f( 1.0, 1.0, -1.0 );
  13487. + glVertex3f( -1.0, 1.0, -1.0 );
  13488. + glVertex3f( -1.0, 1.0, 1.0 );
  13489. + glEnd();
  13490. +
  13491. + glBegin( GL_POLYGON );
  13492. + glVertex3f( 1.0, -1.0, 1.0 );
  13493. + glVertex3f( -1.0, -1.0, 1.0 );
  13494. + glVertex3f( -1.0, -1.0, -1.0 );
  13495. + glVertex3f( 1.0, -1.0, -1.0 );
  13496. + glEnd();
  13497. +
  13498. + /* Z faces */
  13499. + glIndexi( Blue );
  13500. + glColor3f( 0.0, 0.0, 1.0 );
  13501. + glBegin( GL_POLYGON );
  13502. + glVertex3f( 1.0, 1.0, 1.0 );
  13503. + glVertex3f( -1.0, 1.0, 1.0 );
  13504. + glVertex3f( -1.0, -1.0, 1.0 );
  13505. + glVertex3f( 1.0, -1.0, 1.0 );
  13506. + glEnd();
  13507. +
  13508. + glBegin( GL_POLYGON );
  13509. + glVertex3f( 1.0, 1.0, -1.0 );
  13510. + glVertex3f( 1.0,-1.0, -1.0 );
  13511. + glVertex3f( -1.0,-1.0, -1.0 );
  13512. + glVertex3f( -1.0, 1.0, -1.0 );
  13513. + glEnd();
  13514. +}
  13515. +
  13516. +
  13517. +
  13518. +
  13519. +static void display_loop( void )
  13520. +{
  13521. + GLfloat xrot, yrot, zrot;
  13522. +
  13523. + xrot = yrot = zrot = 0.0;
  13524. +
  13525. + glClearColor( 0.0, 0.0, 0.0, 0.0 );
  13526. + glClearIndex( Black );
  13527. +
  13528. + glMatrixMode( GL_PROJECTION );
  13529. + glLoadIdentity();
  13530. + glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 10.0 );
  13531. + glTranslatef( 0.0, 0.0, -5.0 );
  13532. +
  13533. + glMatrixMode( GL_MODELVIEW );
  13534. + glLoadIdentity();
  13535. +
  13536. + glCullFace( GL_BACK );
  13537. + glEnable( GL_CULL_FACE );
  13538. +
  13539. + glShadeModel( GL_FLAT );
  13540. +
  13541. + while (1) {
  13542. + glClear( GL_COLOR_BUFFER_BIT );
  13543. + glPushMatrix();
  13544. + glRotatef( xrot, 1.0, 0.0, 0.0 );
  13545. + glRotatef( yrot, 0.0, 1.0, 0.0 );
  13546. + glRotatef( zrot, 0.0, 0.0, 1.0 );
  13547. +
  13548. + draw_cube();
  13549. +
  13550. + glPopMatrix();
  13551. + glFinish();
  13552. +
  13553. + xrot += 10.0;
  13554. + yrot += 7.0;
  13555. + zrot -= 3.0;
  13556. + }
  13557. +
  13558. +}
  13559. +
  13560. +
  13561. +
  13562. +
  13563. +int main( int argc, char *argv[] )
  13564. +{
  13565. + int mode = 0;
  13566. +
  13567. + if (argc >= 2)
  13568. + {
  13569. + if (strcmp(argv[1],"-ci")==0)
  13570. + mode = 0;
  13571. + else if (strcmp(argv[1],"-rgb")==0)
  13572. + mode = 1;
  13573. + else
  13574. + {
  13575. + printf("Bad flag: %s\n", argv[1]);
  13576. + printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
  13577. + exit(1);
  13578. + }
  13579. + }
  13580. + else
  13581. + {
  13582. + printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
  13583. + printf("Defaulting to 8-bit color index\n");
  13584. + }
  13585. +
  13586. + make_window( argv[0], mode );
  13587. +
  13588. + display_loop();
  13589. + return 0;
  13590. +}
  13591. +
  13592. diff -Naurp Mesa-7.8.1/progs/xdemos/xfont.c Mesa-7.8.1.patched/progs/xdemos/xfont.c
  13593. --- Mesa-7.8.1/progs/xdemos/xfont.c 1970-01-01 01:00:00.000000000 +0100
  13594. +++ Mesa-7.8.1.patched/progs/xdemos/xfont.c 2010-06-13 13:45:06.788792936 +0200
  13595. @@ -0,0 +1,206 @@
  13596. +
  13597. +/*
  13598. + * Mesa 3-D graphics library
  13599. + *
  13600. + * Copyright (C) 1999 Brian Paul All Rights Reserved.
  13601. + *
  13602. + * Permission is hereby granted, free of charge, to any person obtaining a
  13603. + * copy of this software and associated documentation files (the "Software"),
  13604. + * to deal in the Software without restriction, including without limitation
  13605. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13606. + * and/or sell copies of the Software, and to permit persons to whom the
  13607. + * Software is furnished to do so, subject to the following conditions:
  13608. + *
  13609. + * The above copyright notice and this permission notice shall be included
  13610. + * in all copies or substantial portions of the Software.
  13611. + *
  13612. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13613. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13614. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  13615. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  13616. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  13617. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13618. + */
  13619. +
  13620. +
  13621. +/*
  13622. + * Example of using glXUseXFont().
  13623. + * 5 November 1999
  13624. + * Brian Paul
  13625. + */
  13626. +
  13627. +
  13628. +#include <GL/gl.h>
  13629. +#include <GL/glx.h>
  13630. +#include <stdio.h>
  13631. +#include <stdlib.h>
  13632. +#include <string.h>
  13633. +
  13634. +
  13635. +static const char *ProgramName = "xfont";
  13636. +
  13637. +static const char *FontName = "fixed";
  13638. +
  13639. +static GLuint FontBase = 0;
  13640. +
  13641. +
  13642. +
  13643. +static void redraw( Display *dpy, Window w )
  13644. +{
  13645. + static const char *text = "This is glXUseXFont()";
  13646. +
  13647. + glClear( GL_COLOR_BUFFER_BIT );
  13648. +
  13649. + /* triangle */
  13650. + glColor3f( 0.2, 0.2, 1.0 );
  13651. + glBegin(GL_TRIANGLES);
  13652. + glVertex2f( 0, 0.8 );
  13653. + glVertex2f( -0.8, -0.7 );
  13654. + glVertex2f( 0.8, -0.7 );
  13655. + glEnd();
  13656. +
  13657. + /* text */
  13658. + glColor3f( 1, 1, 1 );
  13659. + glRasterPos2f(-0.8, 0);
  13660. + glListBase(FontBase);
  13661. + glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
  13662. +
  13663. + glXSwapBuffers( dpy, w );
  13664. +}
  13665. +
  13666. +
  13667. +
  13668. +static void resize( unsigned int width, unsigned int height )
  13669. +{
  13670. + glViewport( 0, 0, width, height );
  13671. + glMatrixMode( GL_PROJECTION );
  13672. + glLoadIdentity();
  13673. + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
  13674. +}
  13675. +
  13676. +
  13677. +
  13678. +static void setup_font( Display *dpy )
  13679. +{
  13680. + XFontStruct *fontInfo;
  13681. + Font id;
  13682. + unsigned int first, last;
  13683. +
  13684. + fontInfo = XLoadQueryFont(dpy, FontName);
  13685. + if (!fontInfo) {
  13686. + printf("Error: font %s not found\n", FontName);
  13687. + exit(0);
  13688. + }
  13689. +
  13690. + id = fontInfo->fid;
  13691. + first = fontInfo->min_char_or_byte2;
  13692. + last = fontInfo->max_char_or_byte2;
  13693. +
  13694. + FontBase = glGenLists((GLuint) last + 1);
  13695. + if (!FontBase) {
  13696. + printf("Error: unable to allocate display lists\n");
  13697. + exit(0);
  13698. + }
  13699. + glXUseXFont(id, first, last - first + 1, FontBase + first);
  13700. +}
  13701. +
  13702. +static Window make_rgb_db_window( Display *dpy, int xpos, int ypos,
  13703. + unsigned int width, unsigned int height )
  13704. +{
  13705. + int attrib[] = { GLX_RGBA,
  13706. + GLX_RED_SIZE, 1,
  13707. + GLX_GREEN_SIZE, 1,
  13708. + GLX_BLUE_SIZE, 1,
  13709. + GLX_DOUBLEBUFFER,
  13710. + None };
  13711. + int scrnum;
  13712. + XSetWindowAttributes attr;
  13713. + unsigned long mask;
  13714. + Window root;
  13715. + Window win;
  13716. + GLXContext ctx;
  13717. + XVisualInfo *visinfo;
  13718. +
  13719. + scrnum = DefaultScreen( dpy );
  13720. + root = RootWindow( dpy, scrnum );
  13721. +
  13722. + visinfo = glXChooseVisual( dpy, scrnum, attrib );
  13723. + if (!visinfo) {
  13724. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  13725. + exit(1);
  13726. + }
  13727. +
  13728. + /* window attributes */
  13729. + attr.background_pixel = 0;
  13730. + attr.border_pixel = 0;
  13731. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  13732. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  13733. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  13734. +
  13735. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  13736. + 0, visinfo->depth, InputOutput,
  13737. + visinfo->visual, mask, &attr );
  13738. +
  13739. + {
  13740. + XSizeHints sizehints;
  13741. + sizehints.x = xpos;
  13742. + sizehints.y = ypos;
  13743. + sizehints.width = width;
  13744. + sizehints.height = height;
  13745. + sizehints.flags = USSize | USPosition;
  13746. + XSetNormalHints(dpy, win, &sizehints);
  13747. + XSetStandardProperties(dpy, win, ProgramName, ProgramName,
  13748. + None, (char **)NULL, 0, &sizehints);
  13749. + }
  13750. +
  13751. +
  13752. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  13753. +
  13754. + glXMakeCurrent( dpy, win, ctx );
  13755. +
  13756. + return win;
  13757. +}
  13758. +
  13759. +
  13760. +static void event_loop( Display *dpy )
  13761. +{
  13762. + XEvent event;
  13763. +
  13764. + while (1) {
  13765. + XNextEvent( dpy, &event );
  13766. +
  13767. + switch (event.type) {
  13768. + case Expose:
  13769. + redraw( dpy, event.xany.window );
  13770. + break;
  13771. + case ConfigureNotify:
  13772. + resize( event.xconfigure.width, event.xconfigure.height );
  13773. + break;
  13774. + case KeyPress:
  13775. + exit(0);
  13776. + default:
  13777. + ; /* no-op */
  13778. + }
  13779. + }
  13780. +}
  13781. +
  13782. +
  13783. +
  13784. +int main( int argc, char *argv[] )
  13785. +{
  13786. + Display *dpy;
  13787. + Window win;
  13788. +
  13789. + dpy = XOpenDisplay(NULL);
  13790. +
  13791. + win = make_rgb_db_window( dpy, 0, 0, 300, 300 );
  13792. + setup_font( dpy );
  13793. +
  13794. + glShadeModel( GL_FLAT );
  13795. + glClearColor( 0.5, 0.5, 1.0, 1.0 );
  13796. +
  13797. + XMapWindow( dpy, win );
  13798. +
  13799. + event_loop( dpy );
  13800. + return 0;
  13801. +}
  13802. diff -Naurp Mesa-7.8.1/progs/xdemos/xrotfontdemo.c Mesa-7.8.1.patched/progs/xdemos/xrotfontdemo.c
  13803. --- Mesa-7.8.1/progs/xdemos/xrotfontdemo.c 1970-01-01 01:00:00.000000000 +0100
  13804. +++ Mesa-7.8.1.patched/progs/xdemos/xrotfontdemo.c 2010-06-13 13:45:06.789793146 +0200
  13805. @@ -0,0 +1,220 @@
  13806. +/*
  13807. + * Mesa 3-D graphics library
  13808. + *
  13809. + * Copyright (C) 1999 Brian Paul All Rights Reserved.
  13810. + *
  13811. + * Permission is hereby granted, free of charge, to any person obtaining a
  13812. + * copy of this software and associated documentation files (the "Software"),
  13813. + * to deal in the Software without restriction, including without limitation
  13814. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13815. + * and/or sell copies of the Software, and to permit persons to whom the
  13816. + * Software is furnished to do so, subject to the following conditions:
  13817. + *
  13818. + * The above copyright notice and this permission notice shall be included
  13819. + * in all copies or substantial portions of the Software.
  13820. + *
  13821. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13822. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13823. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  13824. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  13825. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  13826. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13827. + */
  13828. +
  13829. +
  13830. +/*
  13831. + * Example of using glXUseRotatedXFontMESA().
  13832. + * 24 Jan 2004
  13833. + * Brian Paul
  13834. + */
  13835. +
  13836. +
  13837. +#include <GL/gl.h>
  13838. +#include <GL/glx.h>
  13839. +#include <stdio.h>
  13840. +#include <stdlib.h>
  13841. +#include <string.h>
  13842. +#include "xuserotfont.h"
  13843. +
  13844. +
  13845. +static const char *ProgramName = "xfont";
  13846. +
  13847. +static const char *FontName = "fixed";
  13848. +
  13849. +static GLuint FontBase[4];
  13850. +
  13851. +
  13852. +static void redraw( Display *dpy, Window w )
  13853. +{
  13854. + static const char *text = " Rotated bitmap text";
  13855. + int i;
  13856. +
  13857. + glClear( GL_COLOR_BUFFER_BIT );
  13858. +
  13859. + /* triangle */
  13860. + glColor3f( 0.2, 0.2, 1.0 );
  13861. + glBegin(GL_TRIANGLES);
  13862. + glVertex2f( -0.8, 0.7 );
  13863. + glVertex2f( -0.8, -0.7 );
  13864. + glVertex2f( 0.8, 0.0 );
  13865. + glEnd();
  13866. +
  13867. + /* marker */
  13868. + glColor3f( 0, 1, 0 );
  13869. + glBegin(GL_POINTS);
  13870. + glVertex2f(0, 0);
  13871. + glEnd();
  13872. +
  13873. + /* text */
  13874. + glColor3f( 1, 1, 1 );
  13875. +
  13876. + for (i = 0; i < 4; i++) {
  13877. + glRasterPos2f(0, 0);
  13878. + glListBase(FontBase[i]);
  13879. + glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
  13880. + }
  13881. +
  13882. + glXSwapBuffers( dpy, w );
  13883. +}
  13884. +
  13885. +
  13886. +
  13887. +static void resize( unsigned int width, unsigned int height )
  13888. +{
  13889. + glViewport( 0, 0, width, height );
  13890. + glMatrixMode( GL_PROJECTION );
  13891. + glLoadIdentity();
  13892. + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
  13893. +}
  13894. +
  13895. +
  13896. +
  13897. +static void setup_font( Display *dpy )
  13898. +{
  13899. + XFontStruct *fontInfo;
  13900. + Font id;
  13901. + unsigned int first, last;
  13902. + int i;
  13903. +
  13904. + fontInfo = XLoadQueryFont(dpy, FontName);
  13905. + if (!fontInfo) {
  13906. + printf("Error: font %s not found\n", FontName);
  13907. + exit(0);
  13908. + }
  13909. +
  13910. + id = fontInfo->fid;
  13911. + first = fontInfo->min_char_or_byte2;
  13912. + last = fontInfo->max_char_or_byte2;
  13913. +
  13914. + for (i = 0; i < 4; i++) {
  13915. + FontBase[i] = glGenLists((GLuint) last + 1);
  13916. + if (!FontBase[i]) {
  13917. + printf("Error: unable to allocate display lists\n");
  13918. + exit(0);
  13919. + }
  13920. + glXUseRotatedXFontMESA(id, first, last - first + 1, FontBase[i] + first,
  13921. + i * 90);
  13922. + }
  13923. +}
  13924. +
  13925. +
  13926. +static Window make_rgb_db_window( Display *dpy, int xpos, int ypos,
  13927. + unsigned int width, unsigned int height )
  13928. +{
  13929. + int attrib[] = { GLX_RGBA,
  13930. + GLX_RED_SIZE, 1,
  13931. + GLX_GREEN_SIZE, 1,
  13932. + GLX_BLUE_SIZE, 1,
  13933. + GLX_DOUBLEBUFFER,
  13934. + None };
  13935. + int scrnum;
  13936. + XSetWindowAttributes attr;
  13937. + unsigned long mask;
  13938. + Window root;
  13939. + Window win;
  13940. + GLXContext ctx;
  13941. + XVisualInfo *visinfo;
  13942. +
  13943. + scrnum = DefaultScreen( dpy );
  13944. + root = RootWindow( dpy, scrnum );
  13945. +
  13946. + visinfo = glXChooseVisual( dpy, scrnum, attrib );
  13947. + if (!visinfo) {
  13948. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  13949. + exit(1);
  13950. + }
  13951. +
  13952. + /* window attributes */
  13953. + attr.background_pixel = 0;
  13954. + attr.border_pixel = 0;
  13955. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  13956. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  13957. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  13958. +
  13959. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  13960. + 0, visinfo->depth, InputOutput,
  13961. + visinfo->visual, mask, &attr );
  13962. +
  13963. + {
  13964. + XSizeHints sizehints;
  13965. + sizehints.x = xpos;
  13966. + sizehints.y = ypos;
  13967. + sizehints.width = width;
  13968. + sizehints.height = height;
  13969. + sizehints.flags = USSize | USPosition;
  13970. + XSetNormalHints(dpy, win, &sizehints);
  13971. + XSetStandardProperties(dpy, win, ProgramName, ProgramName,
  13972. + None, (char **)NULL, 0, &sizehints);
  13973. + }
  13974. +
  13975. +
  13976. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  13977. +
  13978. + glXMakeCurrent( dpy, win, ctx );
  13979. +
  13980. + return win;
  13981. +}
  13982. +
  13983. +
  13984. +static void event_loop( Display *dpy )
  13985. +{
  13986. + XEvent event;
  13987. +
  13988. + while (1) {
  13989. + XNextEvent( dpy, &event );
  13990. +
  13991. + switch (event.type) {
  13992. + case Expose:
  13993. + redraw( dpy, event.xany.window );
  13994. + break;
  13995. + case ConfigureNotify:
  13996. + resize( event.xconfigure.width, event.xconfigure.height );
  13997. + break;
  13998. + case KeyPress:
  13999. + exit(0);
  14000. + default:
  14001. + ; /* no-op */
  14002. + }
  14003. + }
  14004. +}
  14005. +
  14006. +
  14007. +
  14008. +int main( int argc, char *argv[] )
  14009. +{
  14010. + Display *dpy;
  14011. + Window win;
  14012. +
  14013. + dpy = XOpenDisplay(NULL);
  14014. +
  14015. + win = make_rgb_db_window( dpy, 0, 0, 300, 300 );
  14016. + setup_font( dpy );
  14017. +
  14018. + glShadeModel( GL_FLAT );
  14019. + glClearColor( 0.5, 0.5, 1.0, 1.0 );
  14020. +
  14021. + XMapWindow( dpy, win );
  14022. +
  14023. + event_loop( dpy );
  14024. + return 0;
  14025. +}
  14026. diff -Naurp Mesa-7.8.1/progs/xdemos/xuserotfont.c Mesa-7.8.1.patched/progs/xdemos/xuserotfont.c
  14027. --- Mesa-7.8.1/progs/xdemos/xuserotfont.c 1970-01-01 01:00:00.000000000 +0100
  14028. +++ Mesa-7.8.1.patched/progs/xdemos/xuserotfont.c 2010-06-13 13:45:06.789793146 +0200
  14029. @@ -0,0 +1,399 @@
  14030. +/*
  14031. + * Mesa 3-D graphics library
  14032. + * Version: 6.1
  14033. + *
  14034. + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
  14035. + *
  14036. + * Permission is hereby granted, free of charge, to any person obtaining a
  14037. + * copy of this software and associated documentation files (the "Software"),
  14038. + * to deal in the Software without restriction, including without limitation
  14039. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14040. + * and/or sell copies of the Software, and to permit persons to whom the
  14041. + * Software is furnished to do so, subject to the following conditions:
  14042. + *
  14043. + * The above copyright notice and this permission notice shall be included
  14044. + * in all copies or substantial portions of the Software.
  14045. + *
  14046. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14047. + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14048. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14049. + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14050. + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14051. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  14052. + */
  14053. +
  14054. +
  14055. +/* \file xuserotfont.c
  14056. + *
  14057. + * A function like glXUseXFont() but takes a 0, 90, 180 or 270 degree
  14058. + * rotation angle for rotated text display.
  14059. + *
  14060. + * Based on Mesa's glXUseXFont implementation written by Thorsten Ohl.
  14061. + */
  14062. +
  14063. +#include <assert.h>
  14064. +#include <stdlib.h>
  14065. +#include <string.h>
  14066. +#include <GL/glx.h>
  14067. +#include "xuserotfont.h"
  14068. +
  14069. +
  14070. +/**
  14071. + * Generate OpenGL-compatible bitmap by drawing an X character glyph
  14072. + * to an off-screen pixmap, then getting the image and testing pixels.
  14073. + * \param width bitmap width in pixels
  14074. + * \param height bitmap height in pixels
  14075. + */
  14076. +static void
  14077. +fill_bitmap(Display *dpy, Pixmap pixmap, GC gc,
  14078. + unsigned int bitmapWidth, unsigned int bitmapHeight,
  14079. + unsigned int charWidth, unsigned int charHeight,
  14080. + int xPos, int yPos, unsigned int c, GLubyte * bitmap,
  14081. + int rotation)
  14082. +{
  14083. + const int bytesPerRow = (bitmapWidth + 7) / 8;
  14084. + XImage *image;
  14085. + XChar2b char2b;
  14086. +
  14087. + /* clear pixmap to 0 */
  14088. + XSetForeground(dpy, gc, 0);
  14089. + XFillRectangle(dpy, pixmap, gc, 0, 0, charWidth, charHeight);
  14090. +
  14091. + /* The glyph is drawn snug up against the left/top edges of the pixmap */
  14092. + XSetForeground(dpy, gc, 1);
  14093. + char2b.byte1 = (c >> 8) & 0xff;
  14094. + char2b.byte2 = (c & 0xff);
  14095. + XDrawString16(dpy, pixmap, gc, xPos, yPos, &char2b, 1);
  14096. +
  14097. + /* initialize GL bitmap */
  14098. + memset(bitmap, 0, bytesPerRow * bitmapHeight);
  14099. +
  14100. + image = XGetImage(dpy, pixmap, 0, 0, charWidth, charHeight, 1, XYPixmap);
  14101. + if (image) {
  14102. + /* Set appropriate bits in the GL bitmap.
  14103. + * Note: X11 and OpenGL are upside down wrt each other).
  14104. + */
  14105. + unsigned int x, y;
  14106. + if (rotation == 0) {
  14107. + for (y = 0; y < charHeight; y++) {
  14108. + for (x = 0; x < charWidth; x++) {
  14109. + if (XGetPixel(image, x, y)) {
  14110. + int y2 = bitmapHeight - y - 1;
  14111. + bitmap[bytesPerRow * y2 + x / 8] |= (1 << (7 - (x % 8)));
  14112. + }
  14113. + }
  14114. + }
  14115. + }
  14116. + else if (rotation == 90) {
  14117. + for (y = 0; y < charHeight; y++) {
  14118. + for (x = 0; x < charWidth; x++) {
  14119. + if (XGetPixel(image, x, y)) {
  14120. + int x2 = y;
  14121. + int y2 = x;
  14122. + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8)));
  14123. + }
  14124. + }
  14125. + }
  14126. + }
  14127. + else if (rotation == 180) {
  14128. + for (y = 0; y < charHeight; y++) {
  14129. + for (x = 0; x < charWidth; x++) {
  14130. + if (XGetPixel(image, x, y)) {
  14131. + int x2 = charWidth - x - 1;
  14132. + bitmap[bytesPerRow * y + x2 / 8] |= (1 << (7 - (x2 % 8)));
  14133. + }
  14134. + }
  14135. + }
  14136. + }
  14137. + else {
  14138. + assert(rotation == 270);
  14139. + for (y = 0; y < charHeight; y++) {
  14140. + for (x = 0; x < charWidth; x++) {
  14141. + if (XGetPixel(image, x, y)) {
  14142. + int x2 = charHeight - y - 1;
  14143. + int y2 = charWidth - x - 1;
  14144. + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8)));
  14145. + }
  14146. + }
  14147. + }
  14148. + }
  14149. + XDestroyImage(image);
  14150. + }
  14151. +}
  14152. +
  14153. +
  14154. +/*
  14155. + * Determine if a given glyph is valid and return the
  14156. + * corresponding XCharStruct.
  14157. + */
  14158. +static const XCharStruct *
  14159. +isvalid(const XFontStruct * fs, unsigned int which)
  14160. +{
  14161. + unsigned int rows, pages;
  14162. + unsigned int byte1 = 0, byte2 = 0;
  14163. + int i, valid = 1;
  14164. +
  14165. + rows = fs->max_byte1 - fs->min_byte1 + 1;
  14166. + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
  14167. +
  14168. + if (rows == 1) {
  14169. + /* "linear" fonts */
  14170. + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which))
  14171. + valid = 0;
  14172. + }
  14173. + else {
  14174. + /* "matrix" fonts */
  14175. + byte2 = which & 0xff;
  14176. + byte1 = which >> 8;
  14177. + if ((fs->min_char_or_byte2 > byte2) ||
  14178. + (fs->max_char_or_byte2 < byte2) ||
  14179. + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1))
  14180. + valid = 0;
  14181. + }
  14182. +
  14183. + if (valid) {
  14184. + if (fs->per_char) {
  14185. + if (rows == 1) {
  14186. + /* "linear" fonts */
  14187. + return fs->per_char + (which - fs->min_char_or_byte2);
  14188. + }
  14189. + else {
  14190. + /* "matrix" fonts */
  14191. + i = ((byte1 - fs->min_byte1) * pages) +
  14192. + (byte2 - fs->min_char_or_byte2);
  14193. + return fs->per_char + i;
  14194. + }
  14195. + }
  14196. + else {
  14197. + return &fs->min_bounds;
  14198. + }
  14199. + }
  14200. + return NULL;
  14201. +}
  14202. +
  14203. +
  14204. +void
  14205. +glXUseRotatedXFontMESA(Font font, int first, int count, int listbase,
  14206. + int rotation)
  14207. +{
  14208. + Display *dpy;
  14209. + Window win;
  14210. + Pixmap pixmap;
  14211. + GC gc;
  14212. + XFontStruct *fs;
  14213. + GLint swapbytes, lsbfirst, rowlength;
  14214. + GLint skiprows, skippixels, alignment;
  14215. + unsigned int maxCharWidth, maxCharHeight;
  14216. + GLubyte *bm;
  14217. + int i;
  14218. +
  14219. + if (rotation != 0 &&
  14220. + rotation != 90 &&
  14221. + rotation != 180 &&
  14222. + rotation != 270)
  14223. + return;
  14224. +
  14225. + dpy = glXGetCurrentDisplay();
  14226. + if (!dpy)
  14227. + return; /* I guess glXMakeCurrent wasn't called */
  14228. + win = RootWindow(dpy, DefaultScreen(dpy));
  14229. +
  14230. + fs = XQueryFont(dpy, font);
  14231. + if (!fs) {
  14232. + /*
  14233. + _mesa_error(NULL, GL_INVALID_VALUE,
  14234. + "Couldn't get font structure information");
  14235. + */
  14236. + return;
  14237. + }
  14238. +
  14239. + /* Allocate a GL bitmap that can fit any character */
  14240. + maxCharWidth = fs->max_bounds.rbearing - fs->min_bounds.lbearing;
  14241. + maxCharHeight = fs->max_bounds.ascent + fs->max_bounds.descent;
  14242. + /* use max, in case we're rotating */
  14243. + if (rotation == 90 || rotation == 270) {
  14244. + /* swap width/height */
  14245. + bm = (GLubyte *) malloc((maxCharHeight + 7) / 8 * maxCharWidth);
  14246. + }
  14247. + else {
  14248. + /* normal or upside down */
  14249. + bm = (GLubyte *) malloc((maxCharWidth + 7) / 8 * maxCharHeight);
  14250. + }
  14251. + if (!bm) {
  14252. + XFreeFontInfo(NULL, fs, 1);
  14253. + /*
  14254. + _mesa_error(NULL, GL_OUT_OF_MEMORY,
  14255. + "Couldn't allocate bitmap in glXUseXFont()");
  14256. + */
  14257. + return;
  14258. + }
  14259. +
  14260. +#if 0
  14261. + /* get the page info */
  14262. + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
  14263. + firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2;
  14264. + lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2;
  14265. + rows = fs->max_byte1 - fs->min_byte1 + 1;
  14266. + unsigned int first_char, last_char, pages, rows;
  14267. +#endif
  14268. +
  14269. + /* Save the current packing mode for bitmaps. */
  14270. + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
  14271. + glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
  14272. + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
  14273. + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
  14274. + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
  14275. + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
  14276. +
  14277. + /* Enforce a standard packing mode which is compatible with
  14278. + fill_bitmap() from above. This is actually the default mode,
  14279. + except for the (non)alignment. */
  14280. + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
  14281. + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
  14282. + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  14283. + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
  14284. + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
  14285. + glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  14286. +
  14287. + /* Create pixmap and GC */
  14288. + pixmap = XCreatePixmap(dpy, win, maxCharWidth, maxCharHeight, 1);
  14289. + {
  14290. + XGCValues values;
  14291. + unsigned long valuemask;
  14292. + values.foreground = BlackPixel(dpy, DefaultScreen(dpy));
  14293. + values.background = WhitePixel(dpy, DefaultScreen(dpy));
  14294. + values.font = fs->fid;
  14295. + valuemask = GCForeground | GCBackground | GCFont;
  14296. + gc = XCreateGC(dpy, pixmap, valuemask, &values);
  14297. + }
  14298. +
  14299. +#ifdef DEBUG_XROT
  14300. + if (debug_xfonts)
  14301. + dump_font_struct(fs);
  14302. +#endif
  14303. +
  14304. + for (i = 0; i < count; i++) {
  14305. + const unsigned int c = first + i;
  14306. + const int list = listbase + i;
  14307. + unsigned int charWidth, charHeight;
  14308. + unsigned int bitmapWidth = 0, bitmapHeight = 0;
  14309. + GLfloat xOrig, yOrig, xStep, yStep, dtemp;
  14310. + const XCharStruct *ch;
  14311. + int xPos, yPos;
  14312. + int valid;
  14313. +
  14314. + /* check on index validity and get the bounds */
  14315. + ch = isvalid(fs, c);
  14316. + if (!ch) {
  14317. + ch = &fs->max_bounds;
  14318. + valid = 0;
  14319. + }
  14320. + else {
  14321. + valid = 1;
  14322. + }
  14323. +
  14324. +#ifdef DEBUG_XROT
  14325. + if (debug_xfonts) {
  14326. + char s[7];
  14327. + sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
  14328. + dump_char_struct(ch, s);
  14329. + }
  14330. +#endif
  14331. +
  14332. + /* glBitmap()' parameters:
  14333. + straight from the glXUseXFont(3) manpage. */
  14334. + charWidth = ch->rbearing - ch->lbearing;
  14335. + charHeight = ch->ascent + ch->descent;
  14336. + xOrig = -ch->lbearing;
  14337. + yOrig = ch->descent;
  14338. + xStep = ch->width;
  14339. + yStep = 0;
  14340. +
  14341. + /* X11's starting point. */
  14342. + xPos = -ch->lbearing;
  14343. + yPos = ch->ascent;
  14344. +
  14345. + /* Apply rotation */
  14346. + switch (rotation) {
  14347. + case 0:
  14348. + /* nothing */
  14349. + bitmapWidth = charWidth;
  14350. + bitmapHeight = charHeight;
  14351. + break;
  14352. + case 90:
  14353. + /* xStep, yStep */
  14354. + dtemp = xStep;
  14355. + xStep = -yStep;
  14356. + yStep = dtemp;
  14357. + /* xOrig, yOrig */
  14358. + yOrig = xOrig;
  14359. + xOrig = charHeight - (charHeight - yPos);
  14360. + /* width, height */
  14361. + bitmapWidth = charHeight;
  14362. + bitmapHeight = charWidth;
  14363. + break;
  14364. + case 180:
  14365. + /* xStep, yStep */
  14366. + xStep = -xStep;
  14367. + yStep = -yStep;
  14368. + /* xOrig, yOrig */
  14369. + xOrig = charWidth - xOrig - 1;
  14370. + yOrig = charHeight - yOrig - 1;
  14371. + bitmapWidth = charWidth;
  14372. + bitmapHeight = charHeight;
  14373. + break;
  14374. + case 270:
  14375. + /* xStep, yStep */
  14376. + dtemp = xStep;
  14377. + xStep = yStep;
  14378. + yStep = -dtemp;
  14379. + /* xOrig, yOrig */
  14380. + dtemp = yOrig;
  14381. + yOrig = charWidth - xOrig;
  14382. + xOrig = dtemp;
  14383. + /* width, height */
  14384. + bitmapWidth = charHeight;
  14385. + bitmapHeight = charWidth;
  14386. + break;
  14387. + default:
  14388. + /* should never get here */
  14389. + ;
  14390. + }
  14391. +
  14392. + glNewList(list, GL_COMPILE);
  14393. + if (valid && bitmapWidth > 0 && bitmapHeight > 0) {
  14394. +
  14395. + fill_bitmap(dpy, pixmap, gc, bitmapWidth, bitmapHeight,
  14396. + charWidth, charHeight,
  14397. + xPos, yPos, c, bm, rotation);
  14398. +
  14399. + glBitmap(bitmapWidth, bitmapHeight, xOrig, yOrig, xStep, yStep, bm);
  14400. +
  14401. +#ifdef DEBUG_XROT
  14402. + if (debug_xfonts) {
  14403. + printf("width/height = %u/%u\n", bitmapWidth, bitmapHeight);
  14404. + dump_bitmap(bitmapWidth, bitmapHeight, bm);
  14405. + }
  14406. +#endif
  14407. + }
  14408. + else {
  14409. + glBitmap(0, 0, 0.0, 0.0, xStep, yStep, NULL);
  14410. + }
  14411. + glEndList();
  14412. + }
  14413. +
  14414. + free(bm);
  14415. + XFreeFontInfo(NULL, fs, 1);
  14416. + XFreePixmap(dpy, pixmap);
  14417. + XFreeGC(dpy, gc);
  14418. +
  14419. + /* Restore saved packing modes. */
  14420. + glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
  14421. + glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
  14422. + glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
  14423. + glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
  14424. + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
  14425. + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
  14426. +}
  14427. +
  14428. +
  14429. diff -Naurp Mesa-7.8.1/progs/xdemos/xuserotfont.h Mesa-7.8.1.patched/progs/xdemos/xuserotfont.h
  14430. --- Mesa-7.8.1/progs/xdemos/xuserotfont.h 1970-01-01 01:00:00.000000000 +0100
  14431. +++ Mesa-7.8.1.patched/progs/xdemos/xuserotfont.h 2010-06-13 13:45:06.789793146 +0200
  14432. @@ -0,0 +1,12 @@
  14433. +#ifndef XUSEROTFONT_H
  14434. +#define XUSEROTFONT_H
  14435. +
  14436. +#include <X11/Xlib.h>
  14437. +
  14438. +
  14439. +extern void
  14440. +glXUseRotatedXFontMESA(Font font, int first, int count, int listbase,
  14441. + int rotation);
  14442. +
  14443. +
  14444. +#endif
  14445. diff -Naurp Mesa-7.8.1/progs/xdemos/yuvrect_client.c Mesa-7.8.1.patched/progs/xdemos/yuvrect_client.c
  14446. --- Mesa-7.8.1/progs/xdemos/yuvrect_client.c 1970-01-01 01:00:00.000000000 +0100
  14447. +++ Mesa-7.8.1.patched/progs/xdemos/yuvrect_client.c 2010-06-13 13:45:06.789793146 +0200
  14448. @@ -0,0 +1,326 @@
  14449. +/*
  14450. + * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions and GLX_MESA_allocate-memory
  14451. + *
  14452. + * Dave Airlie - Feb 2005
  14453. + */
  14454. +
  14455. +#include <assert.h>
  14456. +#include <math.h>
  14457. +#include <stdio.h>
  14458. +#include <stdlib.h>
  14459. +#include <string.h>
  14460. +#include <X11/Xlib.h>
  14461. +#include <X11/keysym.h>
  14462. +#define GL_GLEXT_PROTOTYPES
  14463. +#include <GL/glx.h>
  14464. +
  14465. +#include "../util/readtex.c" /* I know, this is a hack. */
  14466. +
  14467. +#define TEXTURE_FILE "../images/girl2.rgb"
  14468. +
  14469. +static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
  14470. +static GLint ImgWidth, ImgHeight;
  14471. +static GLushort *ImageYUV = NULL;
  14472. +static void *glx_memory;
  14473. +
  14474. +static void DrawObject(void)
  14475. +{
  14476. + glBegin(GL_QUADS);
  14477. +
  14478. + glTexCoord2f(0, 0);
  14479. + glVertex2f(-1.0, -1.0);
  14480. +
  14481. + glTexCoord2f(ImgWidth, 0);
  14482. + glVertex2f(1.0, -1.0);
  14483. +
  14484. + glTexCoord2f(ImgWidth, ImgHeight);
  14485. + glVertex2f(1.0, 1.0);
  14486. +
  14487. + glTexCoord2f(0, ImgHeight);
  14488. + glVertex2f(-1.0, 1.0);
  14489. +
  14490. + glEnd();
  14491. +}
  14492. +
  14493. +
  14494. +static void scr_Display( void )
  14495. +{
  14496. + glClear( GL_COLOR_BUFFER_BIT );
  14497. +
  14498. + glPushMatrix();
  14499. + glRotatef(Xrot, 1.0, 0.0, 0.0);
  14500. + glRotatef(Yrot, 0.0, 1.0, 0.0);
  14501. + glRotatef(Zrot, 0.0, 0.0, 1.0);
  14502. + DrawObject();
  14503. + glPopMatrix();
  14504. +
  14505. +}
  14506. +
  14507. +
  14508. +static void Reshape( int width, int height )
  14509. +{
  14510. + glViewport( 0, 0, width, height );
  14511. + glMatrixMode( GL_PROJECTION );
  14512. + glLoadIdentity();
  14513. + glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
  14514. + glMatrixMode( GL_MODELVIEW );
  14515. + glLoadIdentity();
  14516. + glTranslatef( 0.0, 0.0, -15.0 );
  14517. +}
  14518. +
  14519. +static int queryClient(Display *dpy, int screen)
  14520. +{
  14521. +#ifdef GLX_MESA_allocate_memory
  14522. + char *extensions;
  14523. +
  14524. + extensions = (char *)glXQueryExtensionsString(dpy, screen);
  14525. + if (!extensions || !strstr(extensions,"GLX_MESA_allocate_memory")) {
  14526. + return 0;
  14527. + }
  14528. +
  14529. + return 1;
  14530. +#else
  14531. + return 0;
  14532. +#endif
  14533. +}
  14534. +
  14535. +static int
  14536. +query_extension(char* extName) {
  14537. + char *p = (char *) glGetString(GL_EXTENSIONS);
  14538. + char *end = p + strlen(p);
  14539. + while (p < end) {
  14540. + int n = strcspn(p, " ");
  14541. + if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0))
  14542. + return GL_TRUE;
  14543. + p += (n + 1);
  14544. + }
  14545. + return GL_FALSE;
  14546. +}
  14547. +
  14548. +static void Init( int argc, char *argv[] , Display *dpy, int screen, Window win)
  14549. +{
  14550. + GLuint texObj = 100;
  14551. + const char *file;
  14552. + void *glx_memory;
  14553. +
  14554. + if (!query_extension("GL_NV_texture_rectangle")) {
  14555. + printf("Sorry, GL_NV_texture_rectangle is required\n");
  14556. + exit(0);
  14557. + }
  14558. +
  14559. + if (!query_extension("GL_MESA_ycbcr_texture")) {
  14560. + printf("Sorry, GL_MESA_ycbcr_texture is required\n");
  14561. + exit(0);
  14562. + }
  14563. +
  14564. + if (!queryClient(dpy, screen)) {
  14565. + printf("Sorry, GLX_MESA_allocate_memory is required\n");
  14566. + exit(0);
  14567. + }
  14568. +
  14569. + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
  14570. + glBindTexture(GL_TEXTURE_RECTANGLE_NV, texObj);
  14571. +#ifdef LINEAR_FILTER
  14572. + /* linear filtering looks much nicer but is much slower for Mesa */
  14573. + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  14574. + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  14575. +#else
  14576. + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  14577. + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  14578. +#endif
  14579. +
  14580. + if (argc > 1)
  14581. + file = argv[1];
  14582. + else
  14583. + file = TEXTURE_FILE;
  14584. +
  14585. + ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight);
  14586. + if (!ImageYUV) {
  14587. + printf("Couldn't read %s\n", TEXTURE_FILE);
  14588. + exit(0);
  14589. + }
  14590. +
  14591. + glx_memory = glXAllocateMemoryMESA(dpy, screen, ImgWidth * ImgHeight * 2, 0, 0 ,0);
  14592. + if (!glx_memory)
  14593. + {
  14594. + fprintf(stderr,"Failed to allocate MESA memory\n");
  14595. + exit(-1);
  14596. + }
  14597. +
  14598. + memcpy(glx_memory, ImageYUV, ImgWidth * ImgHeight * 2);
  14599. +
  14600. + printf("Image: %dx%d\n", ImgWidth, ImgHeight);
  14601. +
  14602. + glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0,
  14603. + GL_YCBCR_MESA, ImgWidth, ImgHeight, 0,
  14604. + GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_APPLE, glx_memory);
  14605. +
  14606. + assert(glGetError() == GL_NO_ERROR);
  14607. +
  14608. + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  14609. +
  14610. + glEnable(GL_TEXTURE_RECTANGLE_NV);
  14611. +
  14612. + glShadeModel(GL_FLAT);
  14613. + glClearColor(0.3, 0.3, 0.4, 1.0);
  14614. +
  14615. +}
  14616. +
  14617. +/*
  14618. + * Create an RGB, double-buffered window.
  14619. + * Return the window and context handles.
  14620. + */
  14621. +static void
  14622. +make_window( Display *dpy, const char *name,
  14623. + int x, int y, int width, int height,
  14624. + Window *winRet, GLXContext *ctxRet)
  14625. +{
  14626. + int attribs[] = { GLX_RGBA,
  14627. + GLX_RED_SIZE, 1,
  14628. + GLX_GREEN_SIZE, 1,
  14629. + GLX_BLUE_SIZE, 1,
  14630. + GLX_DOUBLEBUFFER,
  14631. + GLX_DEPTH_SIZE, 1,
  14632. + None };
  14633. + int scrnum;
  14634. + XSetWindowAttributes attr;
  14635. + unsigned long mask;
  14636. + Window root;
  14637. + Window win;
  14638. + GLXContext ctx;
  14639. + XVisualInfo *visinfo;
  14640. +
  14641. + scrnum = DefaultScreen( dpy );
  14642. + root = RootWindow( dpy, scrnum );
  14643. +
  14644. + visinfo = glXChooseVisual( dpy, scrnum, attribs );
  14645. + if (!visinfo) {
  14646. + printf("Error: couldn't get an RGB, Double-buffered visual\n");
  14647. + exit(1);
  14648. + }
  14649. +
  14650. + /* window attributes */
  14651. + attr.background_pixel = 0;
  14652. + attr.border_pixel = 0;
  14653. + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  14654. + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  14655. + attr.override_redirect = 0;
  14656. + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
  14657. +
  14658. + win = XCreateWindow( dpy, root, 0, 0, width, height,
  14659. + 0, visinfo->depth, InputOutput,
  14660. + visinfo->visual, mask, &attr );
  14661. +
  14662. + /* set hints and properties */
  14663. + {
  14664. + XSizeHints sizehints;
  14665. + sizehints.x = x;
  14666. + sizehints.y = y;
  14667. + sizehints.width = width;
  14668. + sizehints.height = height;
  14669. + sizehints.flags = USSize | USPosition;
  14670. + XSetNormalHints(dpy, win, &sizehints);
  14671. + XSetStandardProperties(dpy, win, name, name,
  14672. + None, (char **)NULL, 0, &sizehints);
  14673. + }
  14674. +
  14675. + ctx = glXCreateContext( dpy, visinfo, NULL, True );
  14676. + if (!ctx) {
  14677. + printf("Error: glXCreateContext failed\n");
  14678. + exit(1);
  14679. + }
  14680. +
  14681. + XFree(visinfo);
  14682. +
  14683. + *winRet = win;
  14684. + *ctxRet = ctx;
  14685. +}
  14686. +
  14687. +
  14688. +static void
  14689. +event_loop(Display *dpy, Window win)
  14690. +{
  14691. + while (1) {
  14692. + while (XPending(dpy) > 0) {
  14693. + XEvent event;
  14694. + XNextEvent(dpy, &event);
  14695. + switch (event.type) {
  14696. + case Expose:
  14697. + /* we'll redraw below */
  14698. + break;
  14699. + case ConfigureNotify:
  14700. + Reshape(event.xconfigure.width, event.xconfigure.height);
  14701. + break;
  14702. + case KeyPress:
  14703. + {
  14704. + char buffer[10];
  14705. + int r, code;
  14706. + code = XLookupKeysym(&event.xkey, 0);
  14707. + r = XLookupString(&event.xkey, buffer, sizeof(buffer),
  14708. + NULL, NULL);
  14709. + if (buffer[0] == 27) {
  14710. + /* escape */
  14711. + return;
  14712. +
  14713. + }
  14714. + }
  14715. + }
  14716. + }
  14717. +
  14718. + }
  14719. +}
  14720. +
  14721. +
  14722. +int
  14723. +main(int argc, char *argv[])
  14724. +{
  14725. + Display *dpy;
  14726. + Window win;
  14727. + GLXContext ctx;
  14728. + char *dpyName = NULL;
  14729. + GLboolean printInfo = GL_FALSE;
  14730. + int i;
  14731. +
  14732. + for (i = 1; i < argc; i++) {
  14733. + if (strcmp(argv[i], "-display") == 0) {
  14734. + dpyName = argv[i+1];
  14735. + i++;
  14736. + }
  14737. + else if (strcmp(argv[i], "-info") == 0) {
  14738. + printInfo = GL_TRUE;
  14739. + }
  14740. + else
  14741. + printf("Warrning: unknown parameter: %s\n", argv[i]);
  14742. + }
  14743. +
  14744. + dpy = XOpenDisplay(dpyName);
  14745. + if (!dpy) {
  14746. + printf("Error: couldn't open display %s\n",
  14747. + XDisplayName(dpyName));
  14748. + return -1;
  14749. + }
  14750. +
  14751. + make_window(dpy, "yuvrect_client", 0, 0, 300, 300, &win, &ctx);
  14752. + XMapWindow(dpy, win);
  14753. + glXMakeCurrent(dpy, win, ctx);
  14754. +
  14755. + if (printInfo) {
  14756. + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  14757. + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  14758. + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  14759. + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  14760. + }
  14761. +
  14762. + Init(argc, argv, dpy, DefaultScreen(dpy), win);
  14763. +
  14764. + scr_Display();
  14765. + glXSwapBuffers(dpy, win);
  14766. + event_loop(dpy, win);
  14767. +
  14768. + glXFreeMemoryMESA(dpy, DefaultScreen(dpy), glx_memory);
  14769. + glXDestroyContext(dpy, ctx);
  14770. + XDestroyWindow(dpy, win);
  14771. + XCloseDisplay(dpy);
  14772. +
  14773. + return 0;
  14774. +}