Framebuffer Object - OpenGL Wiki

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

Framebuffer Objects are OpenGL Objects, which allow for the creation of user-defined Framebuffers. With them, one can render to non-Default Framebuffer ... FramebufferObject FromOpenGLWiki Jumptonavigation Jumptosearch FramebufferObject Coreinversion 4.6 Coresinceversion 3.0 CoreARBextension GL_ARB_framebuffer_object EXTextension GL_EXT_framebuffer_object,GL_EXT_framebuffer_blit,GL_EXT_framebuffer_multisample,GL_EXT_packed_depth_stencil FramebufferObjectsareOpenGLObjects,whichallowforthecreationofuser-definedFramebuffers.Withthem,onecanrendertonon-DefaultFramebufferlocations,andthusrenderwithoutdisturbingthemainscreen. Contents 1Semantics 2FramebufferObjectStructure 3AttachingImages 3.1LayeredImages 4Emptyframebuffers 5FramebufferCompleteness 5.1AttachmentCompleteness 5.2CompletenessRules 6FeedbackLoops 7PseudoImplementation 8EXT_Framebuffer_object 9SeeAlso 10Reference Semantics Framebufferobjectsareacollectionofattachments.Tohelpexplainletsexplicitlydefinecertainterminology. Image Forthepurposesofthisarticle,animageisasingle2Darrayofpixels.Ithasaspecificformatforthesepixels. LayeredImage Forthepurposesofthisarticle,alayeredimageisasequenceofimagesofaparticularsizeandformat.LayeredimagescomefromsinglemipmaplevelsofcertainTexturetypes. Texture Forthepurposesofthisarticle,atextureisanobjectthatcontainssomenumberofimages,asdefinedabove.Alloftheimageshavethesameformat,buttheydonothavetohavethesamesize(differentmip-maps,forexample).TexturescanbeaccessedfromShadersviavariousmethods. Renderbuffer Arenderbufferisanobjectthatcontainsasingleimage.RenderbufferscannotbeaccessedbyShadersinanyway.Theonlywaytoworkwitharenderbuffer,besidescreatingit,istoputitintoanFBO. Attach Toconnectoneobjecttoanother.ThistermisusedacrossallofOpenGL,butFBOsmakethemostuseoftheconcept.Attachmentisdifferentfrombinding.Objectsareboundtothecontext;objectsareattachedtooneanother. Attachmentpoint Anamedlocationwithinaframebufferobjectthataframebuffer-attachableimageorlayeredimagecanbeattachedto.AttachmentpointsrestrictthegeneralkindofImageFormatforimagesattachedtothem. Framebuffer-attachableimage Anyimage,aspreviouslydescribed,thatcanbeattachedtoaframebufferobject. Framebuffer-attachablelayeredimage Anylayeredimage,aspreviouslydescribed,thatcanbeattachedtoaframebufferobject. FramebufferObjectStructure AsstandardOpenGLObjects,FBOshavetheusualglGenFramebuffersandglDeleteFramebuffersfunctions.Asexpected,italsohastheusualglBindFramebufferfunction,tobindanFBOtothecontext. Thetarget​parameterforthisobjectcantakeoneof3values:GL_FRAMEBUFFER,GL_READ_FRAMEBUFFER,orGL_DRAW_FRAMEBUFFER.ThelasttwoallowyoutobindanFBOsothatreadingcommands(glReadPixels,etc)andwritingcommands(allrenderingcommands)canhappentotwodifferentframebuffers.TheGL_FRAMEBUFFERbindingtargetsimplysetsboththereadandthewritetothesameFBO. ThedefaultframebufferhasbuffernameslikeGL_FRONT,GL_BACK,GL_AUXi,GL_ACCUM,andsoforth.FBOsdonotusethese. Instead,FBOshaveadifferentsetofimagenames.EachFBOimagerepresentsanattachmentpoint,alocationintheFBOwhereanimagecanbeattached.FBOshavethefollowingattachmentpoints: GL_COLOR_ATTACHMENTi:Theseareanimplementation-dependentnumberofattachmentpoints.YoucanqueryGL_MAX_COLOR_ATTACHMENTStodeterminethenumberofcolorattachmentsthatanimplementationwillallow.Theminimumvalueforthisis8,soyouareguaranteedtobeabletohaveatleastcolorattachments0-7.Theseattachmentpointscanonlyhaveimagesboundtothemwithcolor-renderableformats.Allcompressedimageformatsarenotcolor-renderable,andthuscannotbeattachedtoanFBO. GL_DEPTH_ATTACHMENT:Thisattachmentpointcanonlyhaveimageswithdepthformatsboundtoit.TheimageattachedbecomestheDepthBufferfortheFBO.Notethatifnodepthimageisattached,DepthTestingwillbedisabledwhenrenderingtothisFBO. GL_STENCIL_ATTACHMENT:Thisattachmentpointcanonlyhaveimageswithstencilformatsboundtoit.TheimageattachedbecomesthestencilbufferfortheFBO. GL_DEPTH_STENCIL_ATTACHMENT:Thisisshorthandfor"bothdepthandstencil".Theimageattachedbecomesboththedepthandstencilbuffers. Note:IfyouuseGL_DEPTH_STENCIL_ATTACHMENT,youshoulduseapackeddepth-stencilinternalformatforthetextureorrenderbufferyouareattaching. AttachingImages NowthatweknowwhereimagescanbeattachedtoFBOs,wecanstarttalkingabouthowtoactuallyattachimagestothese.InordertoattachimagestoanFBO,wemustfirstbindtheFBOtothecontextwithglBindFramebuffer. Youcanattachimagesfrommosttexturetypestotheframebufferobject.However,framebuffersaredesignedfor2Drendering.Sothereisaneedtoconsiderhowdifferenttexturetypesmaptoframebufferimages.Rememberthattexturesareasetofimages.Texturescanhavemipmaps,andindividualmipmaplevelscouldcontainoneormoreimages. Thewaydifferenttexturetypesmaptoframebufferimagesisasfollows: Imagesina1Dtextureareconsidered2Dimageswithaverticalheightof1.Eachindividualimagecanbeuniquelyidentifiedbyamipmaplevel​. Imagesina2Dtexturearetakenasnormal.Eachindividualimagecanbeuniquelyidentifiedbyamipmaplevel​. Amipmaplevelofa3Dtextureisconsideredtobeasetof2Dimages,withthenumberoftheseimagesbeingtheextentoftheZcoordinateforthatmipmaplevel.EachintegervaluefortheZofa3Dtexturemipmaplevelisaseparate2Dlayer.Soeachimageina3Dtextureisuniquelyidentifiedbyalayer​andamipmaplevel​.Recallthatdifferentmipmaplevelsina3DtexturewillhavedifferentcountsofZcoordinates. RectangleTexturescontainasingle2Dimage,whichisidentifiedbyalevel​of0. CubemapTexturescontain62Dimagespermipmap.Thus,eachimageinacubemaptexturecanbeuniquelyidentifiedbyafacetarget​andamipmaplevel​.However,insomeAPIfunctions,individualfacesinamipmaplevelareidentifiedbyalayer​indexinsteadofatarget​. Eachmipmaplevelof1Dor2DArrayTexturescontainsanumberofimages,equaltothecountimagesinthearray.Thus,eachindividualimageisuniquelyidentifiedbyalayer​(thearrayindex)andamipmaplevel​.For1Darraytextures,eachimagehasaheightof1.Unlike3Dtextures,thelayer​doesn'tchangewhengoingdownthemipmaphierarchy. CubemapArrayTexturesworklike2Darraytextures,onlywithanimagecount6timesthenumberofitslayers.A2Dimageinthecubemaparrayisidentifiedbythelayer-faceindexlayer​andamipmaplevel​. BufferTexturescannotbeattachedtoframebuffers. Thewordslevel​,layer​,andtarget​abovearesignificant,astheymatchtheparametersofthefollowingfunctionsusedforattachingtextures: voidglFramebufferTexture1D(GLenumtarget​,GLenumattachment​,GLenumtextarget​,GLuinttexture​,GLintlevel​); voidglFramebufferTexture2D(GLenumtarget​,GLenumattachment​,GLenumtextarget​,GLuinttexture​,GLintlevel​); voidglFramebufferTextureLayer(GLenumtarget​,GLenumattachment​,GLuinttexture​,GLintlevel​,GLintlayer​); Thetarget​parameterhereisthesameastheoneforbind.However,GL_FRAMEBUFFERdoesn'tmeanbothreadanddraw(asthatwouldmakenosense);instead,itisthesameasGL_DRAW_FRAMEBUFFER.Theattachment​parameterisoneoftheaboveattachmentpoints. Thetexture​argumentisthetextureobjectnameyouwanttoattachfrom.Ifyoupasszeroastexture​,thishastheeffectofclearingtheattachmentforthisattachment​,regardlessofwhatkindofimagewasattachedthere. Becausetextureobjectscanholdmultipleimages,youmustspecifyexactlywhichimagetoattachtothisattachmentpoint.Theparametersmatchtheirabovedefinitions,withtheexceptionoftextarget​. Whenattachinganon-cubemap,textarget​shouldbethepropertexturetype:GL_TEXTURE_1D,GL_TEXTURE_2D_MULTISAMPLE,etc.Whenattachinga(non-array)cubemap,youmustusetheTexture2Dfunction,andthetextarget​mustbeoneofthe6targetsforcubemapbinding.Whenattachinganimagefromacubemaparray,youmustuseTextureLayer,withthelayer​beingalayer-face. Note:IfOpenGL4.5orARB_direct_state_accessisavailable,thenglFramebufferTextureLayermaytakenon-arraycubemaptextures.Theyaretreatedasthoughtheywereanarraycubemapwithonelayer(so6layer-faces).ThismeansthatyouneverneedtousetheTexture2D​orTexture1D​functionsforanything. LegacyNote:Thereisafunction,glFramebufferTexture3D,specificallyfor3Dtextures.However,youshouldn'tbotherwithit,astheTextureLayerfunctioncandoeverythingitcanandmore. RenderbufferscanalsobeattachedtoFBOs.Indeed,thisistheonlywaytousethembesidesjustcreatingthestorageforthem. Onceyouhavecreatedarenderbufferobjectandmadestorageforit(givenasizeandformat),youcanattachittoanFBOwiththisfunction: voidglFramebufferRenderbuffer(GLenumtarget​,GLenumattachment​,GLenumrenderbuffertarget​,GLuintrenderbuffer​); Theparametersworkmostlythesameaswithtextureattachment.Therenderbuffertarget​parammustbeGL_RENDERBUFFER.Therenderbuffer​parameteristherenderbufferobject'sname. LayeredImages Alayeredimage,aspreviouslydefined,isanorderedsequenceofimagesofaparticularsize.Anumberofdifferentkindsoftexturescanbeconsideredlayered. Asinglemipmaplevelofa1Dor2DArrayTexturecanbeattachedasalayeredimage,wherethenumberoflayersisthearraysize.Asinglemipmaplevelofa3Dtexturelikewisecanbeattachedasalayeredimage,wherethenumberoflayersisthedepthofthatparticularmipmaplevel.Also,amipmaplevelofaCubemapTexturecanbeattachedasalayeredimage.Forcubemaps,yougetexactly6layers,oneforeachface.Andtheorderofthefacesisthesameastheorderoftheenumerators: Layernumber Cubemapface 0 GL_TEXTURE_CUBE_MAP_POSITIVE_X 1 GL_TEXTURE_CUBE_MAP_NEGATIVE_X 2 GL_TEXTURE_CUBE_MAP_POSITIVE_Y 3 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 4 GL_TEXTURE_CUBE_MAP_POSITIVE_Z 5 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z Forcubemaparrays,thevaluethatgl_Layerrepresentsisthelayer-faceindex.Thusitisthefacewithinalayer,orderedasabove.Soifyouwanttorendertothe3rdlayer,+zface,youwouldsetgl_Layerto(2*6)+4,or16. Eachmipmaplevel,whencanbeattachedasalayeredimage,hasaspecificnumberoflayers.For1Dand2Darraytextures,itisthenumberoflayersinthetextureasawhole.For3Dtextures,thisisthedepthofthatparticularmipmaplevel.Forcubemaps,thisisalwaysexactly6layers:oneperface.Cubemaparrayshave6*thenumberoflayers,whichisthenumberoflayer-faces. Toattachamipmaplevelofatextureasalayeredimage,usethefollowingcommand: voidglFramebufferTexture(GLenumtarget​,GLenumattachment​,GLuinttexture​,GLintlevel​); Theparametershavethesamemeaningasabove.Indeed,thisfunctioncanreplacemanyoftheusesforglFramebufferTexture1D,2D,orLayer,aslongasyoudonotintendtoattachspecificlayersofarraytextures,cubemaps,or3Dtexturesasregular,non-layeredimages.Ifthetexture​isoneofthesekindsoftextures,thenthegivenmipmaplevel​willbeattachedasalayeredimagewiththenumberoflayersthatthegiventexturehas. LayeredimagesareusedwithLayeredRendering,whichsendsdifferentprimitivestodifferentlayerswithintheframebuffer. Emptyframebuffers EmptyFramebuffers Coreinversion 4.6 Coresinceversion 4.3 CoreARBextension ARB_framebuffer_no_attachments Itispossibletorendertoaframebufferobjectthathasnoattachments.Obviouslynoneofthefragmentshaderoutputswillbewrittentoanywhereinthiscase,butrenderingcanotherwiseproceedasnormal.Thisisusefulforusingarbitraryreadingandwritingofimagedatafromshaders,ratherthanwritingtoaboundframebuffer. However,therasterizationofprimitivesisalwaysbasedontheareaandcharacteristicsoftheboundframebuffer.Thesecharacteristics(size,numberofsamplesformultisamplerendering,etc)wouldnormallybedefinedbytheattachedimages.Ifnoimagesareattached,thesecharacteristicsmustbedefinedinsomeotherfashion. ThecharacteristicsforanFBOwithnoattachmentscanbesetwiththisfunction: voidglFramebufferParameteri(GLenumtarget​,GLenumpname​,GLintparam​); target​isthelocationwheretheframebufferobjectisbound.Tosetthewidth,setpname​toGL_FRAMEBUFFER_DEFAULT_WIDTH;tosettheheight,useGL_FRAMEBUFFER_DEFAULT_HEIGHT. LayeredframebufferscanbesimulatedbysettingGL_FRAMEBUFFER_DEFAULT_LAYERStoalayercountotherthan0.MultisampleframebufferscanbesimulatedbysettingGL_FRAMEBUFFER_DEFAULT_SAMPLEStoanumberofsamplesotherthan0.FixedmultisamplelocationcansimilarlybesimulatedbysettingGL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONStoanon-zerovalue. NotethatrenderingisonlylimitedtotheseparametersifnoimagesareattachedtotheFBO.Ifimagesareattached,thentheseparametersareignored.YoushouldonlysetthesevaluesifyouintendtousetheFBOwithoutimages. FramebufferCompleteness EachattachmentpointinaFBOhasspecificrestrictionsontheformatofimagesthatcanbeattachedtoit.However,itisnotanimmediateGLerrortoattachanimagetoanattachmentpointthatdoesn'tsupportthatformat.ItisanerrortotrytouseanFBOthathasbeenimproperlysetup.TherearealsoanumberofotherissueswithregardtosizesofimagesandsoforththatmustbedetectedinordertobeabletosafelyusetheFBO. AnFBOthatisvalidforuseissaidtobe"framebuffercomplete".Totestframebuffercompleteness,callthisfunction: GLenumglCheckFramebufferStatus(GLenumtarget​); Youarenotrequiredtocallthismanually.However,usinganincompleteFBOisanerror,soit'salwaysagoodideatocheck. ThereturnvalueisGL_FRAMEBUFFER_COMPLETEiftheFBOcanbeused.Ifitissomethingelse,thenthereisaproblem.Belowaretherulesforcompletenessandtheassociatedreturnvaluesyouwillreceiveiftheyarenotfollowed. AttachmentCompleteness Eachattachmentpointitselfmustbecompleteaccordingtotheserules.Emptyattachments(attachmentswithnoimageattached)arecompletebydefault.Ifanimageisattached,itmustadheretothefollowingrules: Thesourceobjectfortheimagestillexistsandhasthesametypeitwasattachedwith. Theimagehasanon-zerowidthandheight(theheightofa1Dimageisassumedtobe1).Thewidth/heightmustalsobelessthanGL_MAX_FRAMEBUFFER_WIDTHandGL_MAX_FRAMEBUFFER_HEIGHTrespectively(ifGL4.3/ARB_framebuffer_no_attachments). Thelayerfor3Dorarraytexturesattachmentsislessthanthedepthofthetexture.ItmustalsobelessthanGL_MAX_FRAMEBUFFER_LAYERS(ifGL4.3/ARB_framebuffer_no_attachments). ThenumberofsamplesmustbelessthanGL_MAX_FRAMEBUFFER_SAMPLES(ifGL4.3/ARB_framebuffer_no_attachments). Theimage'sformatmustmatchtheattachmentpoint'srequirements,asdefinedabove.Color-renderableformatsforcolorattachments,etc. CompletenessRules Thesearetherulesforframebuffercompleteness.Theorderoftheserulesmatters. Ifthetarget​ofglCheckFramebufferStatusreferencestheDefaultFramebuffer(ie:FBOobjectnumber0isbound),andthedefaultframebufferdoesnotexist,thenyouwillgetGL_FRAMEBUFFER_UNDEFINED.Ifthedefaultframebufferexists,thenyoualwaysgetGL_FRAMEBUFFER_COMPLETE.TherestoftherulesapplywhenanFBOisbound. Allattachmentsmustbeattachmentcomplete.(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTwhenfalse). TheremustbeatleastoneimageattachedtotheFBO,orifOpenGL4.3orARB_framebuffer_no_attachmentsisavailable,theGL_FRAMEBUFFER_DEFAULT_WIDTHandGL_FRAMEBUFFER_DEFAULT_HEIGHTparametersoftheframebuffermustbothbenon-zero.(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENTwhenfalse). EachdrawbuffermusteitherspecifycolorattachmentpointsthathaveimagesattachedormustbeGL_NONE.(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFERwhenfalse).NotethatthistestisnotperformedifOpenGL4.1orARB_ES2_compatibilityisavailable. Ifthereadbufferisset,thenitmustspecifyanattachmentpointthathasanimageattached.(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFERwhenfalse).NotethatthistestisnotperformedifOpenGL4.1orARB_ES2_compatibilityisavailable. Allimagesmusthavethesamenumberofmultisamplesamples.Allimagesmustalsousethesamefixedsamplelayoutsetting.(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLEwhenfalse). Ifalayeredimageisattachedtooneattachment,thenallattachmentsmustbelayeredattachments.Theattachedlayersdonothavetohavethesamenumberoflayers,nordothelayershavetocomefromthesamekindoftexture(acubemapcolortexturecanbepairedwithanarraydepthtexture)(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETSwhenfalse). Noticethatthereisnorestrictionbasedonsize.TheeffectivesizeoftheFBOistheintersectionofallofthesizesoftheboundimages(ie:thesmallestineachdimension). Theserulesareallcode-based.IfyouevergetanyofthesevaluesfromglCheckFramebufferStatus,itisbecauseyourprogramhasdonesomethingwronginsettinguptheFBO.Eachonehasaspecificremedyforit. There'sonemorerulethatcantripyouup: Theimplementationlikesyourcombinationofattachedimageformats.(GL_FRAMEBUFFER_UNSUPPORTEDwhenfalse). OpenGLallowsimplementationstostatethattheydonotsupportsomecombinationofimageformatsfortheattachedimages;theydothisbyreturningGL_FRAMEBUFFER_UNSUPPORTEDwhenyouattempttouseanunsupportedformatcombination. However,theOpenGLspecificationalsorequiresthatimplementationssupportcertainformatcombinations;ifyouusethese,implementationsareforbiddentoreturnGL_FRAMEBUFFER_UNSUPPORTED.Implementationsmustallowanycombinationofcolorformats,solongasallofthosecolorformatscomefromtherequiredsetofcolorformats. Thesecolorformatscanbecombinedwithadepthattachmentwithanyoftherequireddepthformats.Stencilattachmentscanalsobeused,againwiththerequiredstencilformats,aswellasthecombineddepth/stencilformats.However,implementationsareonlyrequiredtosupportbothadepthandstencilattachmentsimultaneouslyifbothattachmentsrefertothesameimage. Thismeansthatifyouwantstencilwithnodepth,youcanuseoneoftherequiredstencilformats.Ifyouwantdepthwithnostencil,youcanuseoneoftherequireddepthformats.Butifyouwantdepthandstencil,youmustuseadepth/stencilformatandthesameimageinthattexturemustbeattachedtoboththedepthandstencilattachments. Stayingwithintheselimitsmeansyouwon'tseeGL_FRAMEBUFFER_UNSUPPORTED.Goingoutsideoftheselimitsmakesitentirelypossibletogetthisincompleteness. LegacyNote:GL_FRAMEBUFFER_UNSUPPORTEDwas,inthedaysofEXT_framebuffer_object,muchlessforgiving.Thespecificationdidn'thavealistofrequiredimageformats.Indeed,theonlyguaranteethattheEXT_FBOspecmadewasthattherewasatleastonecombinationofformatsthatimplementationssupported;itprovidednohintsastowhatthatcombinationmightbe.ThecoreextensionARB_framebuffer_objectdoesdifferfromthecorespecificationinonecrucialway:itusestheEXTwordingforGL_FRAMEBUFFER_UNSUPPORTED.Soifyou'reusing3.0,justusetherequiredformatsasabove.Ifyou'reusingARB_framebuffer_object,thenyoushouldbeconcernedanddoappropriatetesting. FeedbackLoops Mainarticle:MemoryModel#Framebufferobjects ItispossibletobindatexturetoanFBO,bindthatsametexturetoashader,andthentrytorenderwithitatthesametime. ItisperfectlyvalidtobindoneimagefromatexturetoanFBOandthenrenderwiththattexture,aslongasyoupreventyourselffromsamplingfromthatimage.Ifyoudotrytoreadandwritetothesameimage,yougetundefinedresults.Meaningitmaydowhatyouwant,thesamplermaygetolddata,thesamplermaygethalfoldandhalfnewdata,oritmaygetgarbagedata.Anyofthesearepossibleoutcomes. Note:"image"hererefersessentiallytoamipmaplevel.Soseparate"images"withinasinglemipmaplevelofanarraytexturedonotcountasseparate,soyouwillgetUBifyoutrytowritetoonewhilereadingfromanother.Viewtexturescanhelpresolvethis,asyoucangetanarraylayertocountasaseparateimage. Donotdothis.Whatyouwillgetisundefinedbehavior. OpenGLOpenGL4.5orARB_texture_barrierreducesthecasesoffeedbackloopstojustreading/writingfromthesamepixels,andevenallowsalimitedabilitytoread/writethesamepixels. PseudoImplementation Apseudoimplementationwillmakeframebuffersmucheasiertounderstand. structFramebuffer{ mapattachments; GLenumdraw_buffers[]={GL_COLOR_ATTACHMENT0,GL_NONE,GL_NONE,GL_NONE,....}; GLenumread_buffer=GL_COLOR_ATTACHMENT0; } WhereAttachmentcanbeoneof structTextureAttachment:publicAttachment{ GLuinttexture_id; GLenumtexture_target; GLuintmip_level; GLuintlayer; }; structRenderbufferAttachment:publicAttachment{ GLuintrenderbuffer_id; Glenumrenderbuffer_target; }; Bindingaframebufferconceptuallyworkslikethis classGLContext{ GLuintread_framebuffer_binding; GLuintdraw_framebuffer_binding: } GLContextcurrentContext=... glBindFramebuffer(target,framebuffer_id){ switch(target){ caseGL_READ_FRAMEBUFFER: currentContext.read_framebuffer_binding=framebuffer_id; break; caseGL_DRAW_FRAMEBUFFER: currentContext.draw_framebuffer_binding=framebuffer_id; break; caseGL_FRAMEBUFFER: currentContext.read_framebuffer_binding=framebuffer_id; currentContext.draw_framebuffer_binding=framebuffer_id; break; } } Attachingatextureorrenderbufferworkslikethis //Pseudocode FramebuffergetFramebufferByTarget(GLenumtarget){ GLuintframebuffer_id; switch(target){ caseGL_READ_FRAMEBUFFER: framebuffer_id=currentContext.read_framebuffer_binding; caseGL_DRAW_FRAMEBUFFER: caseGL_FRAMEBUFFER: framebuffer_id=currentContext.draw_framebuffer_binding; } Framebufferframebuffer=getFramebufferById(framebuffer_id); returnframebuffer; } glFramebufferTexture2D(GLenumtarget,GLenumattachmentPoint,GLenumtextarget​,GLuinttexture​,GLintmip_level​){ Framebufferframe_buffer=getFramebufferByTarget(target); frame_buffer.attachments.set(attachmentPoint,newTextureAttachment(textarget,texture,mip_level,0)); } glFramebufferTextureLayer(GLenumtarget​,GLenumattachment​,GLuinttexture​,GLintmip_level​,GLintlayer​){ Framebufferframe_buffer=getFramebufferByTarget(target); frame_buffer.attachments.set(attachment,newTextureAttachment(getTextureTargetFromTexture(texture),texture,mip_level,layer)); } glFramebufferRenderbuffer(GLenumtarget​,GLenumattachment​,GLenumrenderbuffertarget​,GLuintrenderbuffer​){ Framebufferframe_buffer=getFramebufferByTarget(target); frame_buffer.attachments.set(attachment,newRenderbufferAttachment(renderbuffertarget,renderbuffer)); } Settingthedrawbuffersandreadbuffersettingsworkslikethis //Pseudocode glDrawBuffers(GLsizein,constGLenum*bufs){ Framebufferframe_buffer=getFramebufferByTarget(GL_DRAW_FRAMEBUFFER); for(GLsizeii=0;i



請為這篇文章評分?