Dependencies: Pyglet vs PyOpenGL - Google Groups

文章推薦指數: 80 %
投票人數:10人

We basically have two choices: Pyglet or PyOpenGL. The former being a bit basic, the latter being easier to use (and therefore possibly a bit slower if you have ... GroupsvispyConversationsAboutDependencies:PygletvsPyOpenGL578viewsSkiptofirstunreadmessageAlmarKleinunread,Apr14,2013,7:55:19PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetopyv...@googlegroups.com,NicolasRougierWhilewe'rediscussingthehighestlevelsofourprojectinanotherthread,I'dliketoreopenthediscussionwithregardtothelowestlevel:ourdependenciesfortheOpenGLAPI.IthinkthatweshouldaddressthisissuebeforewestartworkingonourooGLlayer. Webasicallyhavetwochoices:PygletorPyOpenGL.Theformerbeingabitbasic,thelatterbeingeasiertouse(andthereforepossiblyabitslowerifyouhavemanyopenglcalls).Pygletalsocomeswithfunctionalitytocreatewindowsanddetectscreensetc. ItseemsthatNicolashasmostexperiencewithPygley,andheseemedabitreluctanttowardsPyglet(correctmeifI'mwrong!).Iinitiallylikedtheideaofalwayshavingwindowbackendtorendertoo,withoutneedingadditionaldependencies.Ontheotherhand,ifweimplementabackendforpyglet,glut,PyQt4,PySide,WxPython,Gtk,FLTK,usersarealmostboundtohaveoneoftheseavailable.Andifnot,installingoneofthesewouldbeverysimple.(PygletispurePython). Sowoulditbefairtosaythatwe'regoingtousePyOpenGL? Ifso.ourdependenciesbecome:pyopengl,numpy,andoneoftheabovementionedbackendstoprovideawindowtorenderin.Optionally,wemayincludepygletinthepackagedistributionandinstallifnecessary. -Almar CyrilleRossantunread,Apr14,2013,8:04:26PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoAlmarKlein,[email protected],NicolasRougier2013/4/14AlmarKleinHowdoesoneinstallGLUT?IsitalwaysbundledinPyOpenGLornot?IthinkIcanuseGLUTwithPyOpenGLonWindowswhereasIdidn'tdoanythingtoinstallitspecifically.IfabackendwindowcanbecreatedonlywithPyOpenGL/GLUT,itwouldmeanthatpyopengl+numpyaretheonlymandatorydependencies. Cyrille CyrilleRossantunread,Apr14,2013,8:11:20PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoAlmarKlein,[email protected],NicolasRougier Webasicallyhavetwochoices:PygletorPyOpenGL.Theformerbeingabitbasic,thelatterbeingeasiertouse(andthereforepossiblyabitslowerifyouhavemanyopenglcalls).Pygletalsocomeswithfunctionalitytocreatewindowsanddetectscreensetc. Anotherthing:dowewantanadditionallayerbetweenourrawGLcallsandthePyOpenGLcalls?ForinstanceasimpleproxyclassthatwouldjustredirectProxy.gl*()toOpenGL.gl*().Thiswouldmakepossiblethefollowingthings:  *log/captureallGLcalls,whichcanbeusefulfordebuggingandunittesting(i.e.switchofftheactualGLcallswhenarendererisnotavailable,whichmayhappeninacontinuousintegrationscenario)  *useeitherPyOpenGLorPyglet(meaningthatnumpy+pygletwouldbesufficient) **might*beusedforoffscreenrenderingorsimilar(basicallysendingallGLcommandstoanexternalrenderer) Maybethere'sanoverheadbutIdon'tthinkitwouldbesignificant.Cyrille LukeCampagnolaunread,Apr14,2013,8:12:57PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoCyrilleRossant,AlmarKlein,[email protected],NicolasRougierOnUbuntu,GLUTisincludedwiththepython-openglpackage.   LukeCampagnolaunread,Apr14,2013,8:33:35PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoCyrilleRossant,AlmarKlein,[email protected],NicolasRougier\OnSun,Apr14,2013at8:11AM,CyrilleRossantwrote: Webasicallyhavetwochoices:PygletorPyOpenGL.Theformerbeingabitbasic,thelatterbeingeasiertouse(andthereforepossiblyabitslowerifyouhavemanyopenglcalls).Pygletalsocomeswithfunctionalitytocreatewindowsanddetectscreensetc. Anotherthing:dowewantanadditionallayerbetweenourrawGLcallsandthePyOpenGLcalls?ForinstanceasimpleproxyclassthatwouldjustredirectProxy.gl*()toOpenGL.gl*().Thiswouldmakepossiblethefollowingthings:  *log/captureallGLcalls,whichcanbeusefulfordebuggingandunittesting(i.e.switchofftheactualGLcallswhenarendererisnotavailable,whichmayhappeninacontinuousintegrationscenario) Thiswouldbeveryuseful.   *useeitherPyOpenGLorPyglet(meaningthatnumpy+pygletwouldbesufficient)Ilikethisidea,butIamtoldthattheAPIsareverydifferent.Itwouldtakesomeefforttoreconcilethedifferences(IwouldrecommendwrappingthepygletcallstomakethemlookmorelikePyOpenGL).Anawesomebonusofthisisthatthe_only_dependencyofthelibrarywouldbenumpy.    Maybethere'sanoverheadbutIdon'tthinkitwouldbesignificant.Iwouldworryaboutthis,butIthinkthesameeffectscouldbeachievedwithoutusingaproxy--justdecideatthebeginningwhichmoduletoimporttoasharedlocation,like(PyOpenGL,Pyglet,GLDebugProxy)->vispy.opengl Luke CyrilleRossantunread,Apr14,2013,8:40:55PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoLukeCampagnola,AlmarKlein,[email protected],NicolasRougierIlikethisidea,butIamtoldthattheAPIsareverydifferent.Itwouldtakesomeefforttoreconcilethedifferences(IwouldrecommendwrappingthepygletcallstomakethemlookmorelikePyOpenGL).Anawesomebonusofthisisthatthe_only_dependencyofthelibrarywouldbenumpy. You'reright,itmaybenotthatsimplethen.Butindeed,theperspectiveofbeingableto"compile"avisualizationintoasequenceofOpenGLcallscouldbeinteresting.Forinstance,maybetherewouldbeawaytoautomaticallyconvertastaticsceneintoanotherlanguage,usingtherawOpenGLcalls. Cyrille NicolasRougierunread,Apr14,2013,8:47:29PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoCyrilleRossant,LukeCampagnola,AlmarKlein,[email protected] Onethirdoption(forOpenGL)couldbetoprovideourownbindingsviactype.Thisiswhatpyglet'sdoingandifweofferalow-levelapi,userwon'tseenthemmuchanyway.Ithinkwecangetextracttherelevantcodefrompyglet. BTW,sorryfornotbeingtooresponsivebutI'mabitoverloadedwithworkrightnow. Nicolas AlmarKleinunread,Apr14,2013,9:48:54PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoNicolasRougier,CyrilleRossant,LukeCampagnola,[email protected] HowdoesoneinstallGLUT?IsitalwaysbundledinPyOpenGLornot?IthinkIcanuseGLUTwithPyOpenGLonWindowswhereasIdidn'tdoanythingtoinstallitspecifically.IfabackendwindowcanbecreatedonlywithPyOpenGL/GLUT,itwouldmeanthatpyopengl+numpyaretheonlymandatorydependencies. PyOpenGLdocssaythatthepre-buildbinariescomewithGLUT.IremembernotbeingabletouseitonPy3korsomething(cantrememberthedetails),sowewouldneedtolookintoit.Nevertheless,IthinkwecannotrelyonGLUTalwaysbeinginstalled(GLUT!=opengl).ButoneofourbackendsisboundtobethereatleastwiththecommonscientificPythondistributions. ...theperspectiveofbeingableto"compile"avisualizationintoasequenceofOpenGLcallscouldbeinteresting.Forinstance,maybetherewouldbeawaytoautomaticallyconvertastaticsceneintoanotherlanguage,usingtherawOpenGLcalls. Veryinterestingidea! Onethirdoption(forOpenGL)couldbetoprovideourownbindingsviactype.Thisiswhatpyglet'sdoingandifweofferalow-levelapi,userwon'tseenthemmuchanyway.Ithinkwecangetextracttherelevantcodefrompyglet. Theyauto-generatethebindingIbelieve,right?Sowebetterextractthecodethatcreatesthebindings.Buthowisthisbetterthanusingpyglet.gldirectly,apartfromhavingpygletasadependency?(itwouldmeanextramaintenancetoo!) -Almar  LukeCampagnolaunread,Apr14,2013,9:50:09PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoCyrilleRossant,AlmarKlein,[email protected],NicolasRougierOnSun,Apr14,2013at8:40AM,CyrilleRossantwrote: Ilikethisidea,butIamtoldthattheAPIsareverydifferent.Itwouldtakesomeefforttoreconcilethedifferences(IwouldrecommendwrappingthepygletcallstomakethemlookmorelikePyOpenGL).Anawesomebonusofthisisthatthe_only_dependencyofthelibrarywouldbenumpy. You'reright,itmaybenotthatsimplethen.Butindeed,theperspectiveofbeingableto"compile"avisualizationintoasequenceofOpenGLcallscouldbeinteresting.Forinstance,maybetherewouldbeawaytoautomaticallyconvertastaticsceneintoanotherlanguage,usingtherawOpenGLcalls. Howaboutthis: Fornow,wekeepitsimpleandplanonusingPyOpenGL,butinsuchawaythatitiseasytoswapoutforalternativelibrarieslateron.Rightnowwehavepyvis.opengl,whichiswhereIproposetheOOopenglobjectsgo:pyvis.opengl.VertexBuffer,ShaderProgram,ect.Theactualopenglapicouldbemadeavailableaspyvis.opengl.GL.glEnable,.glDrawArrays,.GL_FLOAT,etc.  Then,ifwedecidetoaddsupportforpyglet/debugging/proxyfeatureslater,thiscanbesupportedbysettingaglobalconfigurationoptionbeforeimportingpyvis.opengl:   importpyvis   pyvis.config['opengl_backend']='pyglet'  importpyvis.opengl.GLasGL #wouldtakecareofimportingpygletsymbolsinsteadofPyOpenGL   GL.glClear(...) CyrilleRossantunread,Apr14,2013,9:51:56PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoLukeCampagnola,AlmarKlein,[email protected],NicolasRougier2013/4/14LukeCampagnolaSoundsgood!Cyrille  LukeCampagnolaunread,Apr14,2013,10:13:14PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoAlmarKlein,NicolasRougier,CyrilleRossant,[email protected],Apr14,2013at9:48AM,AlmarKleinwrote: Onethirdoption(forOpenGL)couldbetoprovideourownbindingsviactype.Thisiswhatpyglet'sdoingandifweofferalow-levelapi,userwon'tseenthemmuchanyway.Ithinkwecangetextracttherelevantcodefrompyglet. Theyauto-generatethebindingIbelieve,right?Sowebetterextractthecodethatcreatesthebindings.Buthowisthisbetterthanusingpyglet.gldirectly,apartfromhavingpygletasadependency?(itwouldmeanextramaintenancetoo!) Iagree--copyingpygletcodeshouldbethelastoption.Bettertoincludepygletasadependencyorsub-package.WecanaddawrappertomaketheAPIcompatiblewithPyOpenGL,orevenbetter:workdirectlywiththepygletfolkstomaketheirAPIworkforus(addingpython3compatibility,bettersupportfornumpyarrays,etc).  AlmarKleinunread,Apr14,2013,10:35:36PM4/14/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoLukeCampagnola,CyrilleRossant,[email protected],NicolasRougier Howaboutthis: Fornow,wekeepitsimpleandplanonusingPyOpenGL,butinsuchawaythatitiseasytoswapoutforalternativelibrarieslateron.Rightnowwehavepyvis.opengl,whichiswhereIproposetheOOopenglobjectsgo:pyvis.opengl.VertexBuffer,ShaderProgram,ect.Theactualopenglapicouldbemadeavailableaspyvis.opengl.GL.glEnable,.glDrawArrays,.GL_FLOAT,etc.  Goodidea.Exceptperhapsnotputitinsidetheoogllayer.Somethinglikevispy.glandavispy.oogl.  workdirectlywiththepygletfolkstomaketheirAPIworkforus(addingpython3compatibility,bettersupportfornumpyarrays,etc).  Pygletdoesworkonpy3k. -Almar AdamGriffithsunread,Apr17,2013,10:01:34AM4/17/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetovi...@googlegroups.com,AlmarKlein,NicolasRougier,CyrilleRossant,[email protected],I'mthecreatorofPyGLy.JustthoughtI'dthrowinmy2cents.IusedPyglet'sGLwrapperandfoundittobequitegood.ItstickstothepythonAPIwhichisnice,albeitc-like.Pyglet'sAPIusesctypes...alot.TakealookatglGetIntergerv,andotherfunctions.>>>x=GLint()>>>glGetIntegerv(GL_MAX_LIGHTS,x)src=(c_char_p*count)(*strings)glShaderSource(shader,count,cast(pointer(src),POINTER(POINTER(c_char))),None) ThemainproblemIhadwasthatitdoesntsupportnumpydirectly.Iwasunabletopassinmixeddatatypestobuffers/textures,etcwhichcanbeimportantforefficientopenglcodingQuiteoftenyouneedtopassfloat16,int16,int32'setcinthesamebuffertoOpenGL.Thisismainlyformeshes/animation.InPyglet,youneedtopassinactype,thisconversionmandatesthevaluesbethesametype.Ie,glBufferData(...,(GLfloat*100)(*floatArray),...)Itriedforawhiletofixthis,butfoundnoway(I'mnotthatexperiencedwithpython'sctypevoodoo).Perhapsyouguysknowofsomemethodtodothis(perhapsjust'np.array.data'woulddothetrick?).Pyglet'scoredesignisvery...complex.It'soverlyOOandIfounditincrediblydifficulttofollow.Agoodexampleisthetexturefunctions,tracingthroughthemisanightmare.Usingthemisoverlycomplextoo.YouneedtogothroughanImageobject,thenpullaGLtextureobjectoutofit.ThedocumentationcanbereallypoorandIhadalotoftroublefiguringouthowtoloadanumpyarrayintoatexturebecausethisusecaseisjustnotfoundinthedocs.IhadtomonkeypatchittogetOpenGL3workingbecausePygletisOpenGLlegacydowntothecorewindowingcallsformousecursorrendering.ThisalsomeantIhadtoditchallofpyglet'shigherlevelfucntionsbecausetheyarelegacybased.Theidleloophadtobemonkeypatchedtoobecauseitperformsarendereverytimeitclearstheeventqueue,somovingyourmouseonthewindowcauses100%cpuusageduetoinsaneamountsofrendercalls.I'vealsohaveproblemswithbugsinPyglet.OS-Xsupportisnotgood.IhadtoforkPyglettogetOpenGL3.0workingonOS-X.Idon'tbelievethepatcheshavebeenappliedafter6+months.PyOpenGLissupportedby99%ofpythonglwindowingtoolkits(Qt,PyGame,PyGLFW,etc.)EvenPygletworkswithPyOpenGLbecausethesameOpenGLcontextisbeingused,sothecallsareirrelevant.YoucouldperhapsusePyglet'sopenglcallswhileusinganotherplatform,butIfoundtheextradependencytobeunneccessary.PyOpenGLalsosupportsnumpyasafirstclasscitizen,soIcannowsupportmixeddatatypesbeingallocated.Mostfunctionsarewrappedinpythonandremovetheneedforctypesandotherc-typequirkslikeintegerlength,stringlength,returnedvaluelength,etc.Soplatformindependenceandnumpysupportwerebigreasonstomoveawayfrompyglet.Thisalsomeantdroppingpyglet'seventsystem.It'strivialtoconvertpygleteventstoanothereventsystemwithawrapper.Thispythonicwrappinghasadown-side,thedocumentation.ThisisthemainproblemwithPyOpenGL.Thedocumentationisacopyoftheopenglwebsitesdocs(albeituglier).ManyOpenGLfunctionshavebeenmademorepythonic,butthesignaturechangesarerarelydocumentedandthequirksareNEVERdocumented.Forexample,glBufferData-passing0foroffset=crash,mustpassNone.OtherthingslikeglGetbeingwrapped,someglGetfunctionsarewrapped,somearestillctypes.IusedaLOToftrialanderrortofigureouttheAPIcallsI'mcurrentlyusing.Iwantedtolovepygletbecauseit's100%pythonandsimpletoinstall,butithascostmealotoftimeandefforttogetitworking.I'mthinkingofusingPyFLGWbecauseitsasimplewrapper,andthepythonbindingsaretrivialtopatch.Itmaynotbeappropriateforyouguys,butditchingpygletwasthebestthingIdid.JusthopingtoprovidesomeinsightintotheissuesI'vehadoverthelastfewyearswithpyglet,etal.Cheers,AdamAlmarKleinunread,Apr17,2013,6:50:01PM4/17/13ReplytoauthorSignintoreplytoauthorForwardSignintoforwardDeleteYoudonothavepermissiontodeletemessagesinthisgroupLinkReportmessageasabuseSignintoreportmessageasabuseShoworiginalmessageEitheremailaddressesareanonymousforthisgrouporyouneedtheviewmemberemailaddressespermissiontoviewtheoriginalmessagetoAdamGriffiths,[email protected],NicolasRougier,CyrilleRossant,[email protected],thanksforsharingyourexperience.Thisisveryinsightful. Willhavealookatpyflgw.Ithinkyoumisspelledthename(whataterribleacronym,anyway),makingitabithardtogoogle:)  Here'salinktothegithubrepo:https://github.com/nightcracker/pyglfw-AlmarReplyallReplytoauthorForward0newmessages



請為這篇文章評分?