How to read back stencil buffer - OpenGL: Advanced Coding
文章推薦指數: 80 %
Hi all, I'm need read back the stencil buffer, see the below code ... // Disable depth buffer updates. Pass pixels if nearer than stored ... Howtoreadbackstencilbuffer OpenGL OpenGL:AdvancedCoding yalmar November20,2006,10:34am #1 Hiall, I’mneedreadbackthestencilbuffer,seethebelowcode ... //Disabledepthbufferupdates.Passpixelsifnearerthanstoreddepthvalue glDepthMask(GL_FALSE); glDepthFunc(GL_LESS); //IncrementstencilbufferforobjectAfrontfaces glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); glCullFace(GL_BACK); DrawObject(A); //DecrementstencilbufferforobjectAbackfaces glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); glCullFace(GL_FRONT); DrawObject(A); //Readbackstencilbuffer. ... Ineeditfordeterminingiftwoobjectsarecollidingornot. Thanks, Yalmar. Humus November20,2006,4:50pm #2 Readbackasincopytosystemmemory?YoucanuseglReadPixels()forthat.It’llmostlikelybeawfullyslowthough. yalmar November20,2006,7:17pm #3 exactly,usingglReadPixels.Butwhatparamsshouldiuse?I’mnotsureofusingGL_STENCIL_INDEX,anybodyhaveanillustrativeexample? Humus November21,2006,9:14am #4 Thisshoulddo: glDrawPixels(width,height,GL_STENCIL_INDEX,GL_UNSIGNED_BYTE,data); jide November21,2006,10:02am #5 @Humus:whywoulditbeawfullyslow?Ihaven’tdoneityet.But,frommypointofview,itshouldbefasterthandoingforexamplereal-timeshadowmappingoranythinginvolvingread/write/copyfromtexturesandFBOs:thestencilbufferisonly8bitssized.Hasitsomethingtodowithnon-hardwaresupport? yalmar November21,2006,12:12pm #6 ThanksHumus, IwouldliketoknowifnowadaysexistsomewayofrendertoStencilBufferandattachitasatexture,forinstance,usingEXT_packed_depth_stencil. Humus November21,2006,7:28pm #7 Originallypostedbyjide: @Humus:whywoulditbeawfullyslow? glReadPixels()isalwaysslowbecauseitforcesaglFinish()andthuskillsallparallelism,anditcopiesthedatatosystemmemory,whichisslow.Soevenwhenit’saccelerated,thingsarequiteslow.WithstencilreadbackIdon’tthinkit’llbeacceleratedeither. jide November22,2006,3:08am #8 ThanksHumus. yalmar,youcanuseFBOtodealwithrendertostencil,usingstencilrenderbufferobjects.ButAFAIK,youcan’tdirectlyattachittoatexture.Iguessyou’llhavetodealwithread/writepixelsona8bitsmonochromatictexture. yalmar November22,2006,12:04pm #9 whatapity, Thanks. Humus November23,2006,2:28pm #10 Areyousureyoureallyneedtoreadbackstencilthough?Can’tyouuseanocclusionquerytosolvetheproblem? JeffJ November27,2006,6:46am #11 Originallypostedbyjide: IwouldliketoknowifnowadaysexistsomewayofrendertoStencilBufferandattachitasatexture,forinstance,usingEXT_packed_depth_stencil. Yes.EXT_packed_depth_stencilenablesyoutorenderyourstencilcontenttoanFBOthathasaDEPTH_STENCILattachment.Thedepth_stencilformatissupportedforbothtextureandrenderbufferobjects. Also,ifyoumustdoReadPixelsofstencildata,youarebestoffusingReadPixelsofDEPTH_STENCILdataformatandUNSIGNED_INT_24_8packeddatatype.ThisReadPixelsusagewasfirstsupportedlongagobytheNV_packed_depth_stenciluponwhichEXT_packed_depth_stencilisbased. jide November27,2006,9:16am #12 JeffJ,Ihaven’twrotethatquote! JeffJ November27,2006,12:43pm #13 Oops,sorry,yalmarwrotethetextIquoted.Ihadacopy/pastetypothatIfailedtonoticewhenpreviewing. yalmar November29,2006,3:38am #14 Thanksforyourreplies.Iwillattempttousethatextension(EXT_packed_depth_stencil).
延伸文章資訊
- 1How to use the stencil buffer - WebGL Fundamentals
I have read many different themes about it, but I not found a detailed guide about it. I want to ...
- 2Depth and stencils - OpenGL
The drawing operation of the cube uses the values from the stencil buffer to only draw fragments ...
- 3Chapter 14 - OpenGL Programming Guide
The stencil buffer is used to keep the fill color of each polygon from overwriting its outline. T...
- 4How to read back stencil buffer - OpenGL: Advanced Coding
Hi all, I'm need read back the stencil buffer, see the below code ... // Disable depth buffer upd...
- 5Read depth values while stencil testing(same texture) - Stack ...
In my opinion there should not be any problems, because i'm not reading the stencil buffer values...