Horde3D http://horde3d.org/forums/ |
|
Copying the framebuffer to texture http://horde3d.org/forums/viewtopic.php?f=1&t=1215 |
Page 1 of 1 |
Author: | MistaED [ 10.08.2010, 14:29 ] |
Post subject: | Copying the framebuffer to texture |
Hi all, I've been thinking a bit on what would be the most efficient way to make a copy of the framebuffer to a lower res texture. The Horde3D way I am guessing is to do a h3dMapResStream of the main framebuffer, copy out the colour or depth buffer to system memory, unmap the stream, resize the image on the CPU to fit something like 512x256 (if the source was like 800x480), then create a texture and h3dMapResStream this to copy over the result. I'm a bit worried about the performance drop of this technique especially on ES devices. Would this be the way to go about copying colour & depth to a texture, or is there another way with the pipeline system where I can just set XML to do this for me? My other idea was to not draw to the framebuffer but render to texture RGB and have alpha contain a linear 8-bit depth made from a shader, while having an additional 16/24-bit depth renderbuffer attachment and then later apply the result as one quad to the framebuffer. What do you think? Almost forgot to mention, this is on hardware which only supports 1 colour attachment for textures but can have a few renderbuffer storage attachments (eg. depth/stencil). The reason to my madness is more or less having good source data to do fancy shaders without drawing the scene more than once or at most only drawing twice. Thanks! It's a bit of a pain having no shader access of the framebuffer itself for blending! Unless I'm missing something... |
Author: | DarkAngel [ 10.08.2010, 16:11 ] |
Post subject: | Re: Copying the framebuffer to texture |
You should be able to do that using the DrawQuad pipeline command. e.g. to copy from one render-target to another: Code: <SwitchTarget target="MY_LOW_RES" /> Or if you want to input a color/depth render and combine them into one output:<BindBuffer sampler="color" sourceRT="MY_HIGH_RES" bufIndex="0" /> <DrawQuad material="materials/myPostProcessing.material.xml" context="COPY_RGBA" /> Code: <SwitchTarget target="MY_LOW_RES" /> (n.b. You'd have to make the myPostProcessing.material.xml file, and the COPY_RGBA/COPY_RGB_AND_DEPTH_TO_RGBA contexts )
<BindBuffer sampler="color" sourceRT="MY_HIGH_RES" bufIndex="0" /> <BindBuffer sampler="depth" sourceRT="MY_HIGH_RES" bufIndex="32" /> <DrawQuad material="materials/myPostProcessing.material.xml" context="COPY_RGB_AND_DEPTH_TO_RGBA" /> |
Author: | MistaED [ 10.08.2010, 17:29 ] |
Post subject: | Re: Copying the framebuffer to texture |
Thanks for the tips DarkAngel! I've been studying the existing pipelines and noticed this technique, very clever. I suppose you can't do the same with the window's framebuffer because it's a renderbuffer? To get around that I've made a SCRATCHBUF render target which is a texture with RGBA8 and has renderbuffer storage of stencil/depth (had to hack horde to do this) and will just store the additional linear depth to alpha. Apparently NPOT render targets are like 10x slower than POT ones on PowerVR SGX hardware so I hope 512x256 for an 800x480 display is good enough! 1024x512 is an option, but that's quite a bit of fillrate wastage, although it would give a bit of fake AA... Does this make sense: could horde be extended to have an easy option where DrawQuad could have its verts set for an 800x480 texture area on a 1024x512 framebuffer, and could just glScissor this so it doesn't draw beyond the 800x480 area? |
Author: | marciano [ 11.08.2010, 07:58 ] |
Post subject: | Re: Copying the framebuffer to texture |
For copying the window framebuffer to a texture, you could try out glCopyTexSubImage2D. On PC you also have glBlitFramebufferEXT to copy the framebuffer to an FBO, however, I assume this function is not available on ES. MistaED wrote: Does this make sense: could horde be extended to have an easy option where DrawQuad could have its verts set for an 800x480 texture area on a 1024x512 framebuffer, and could just glScissor this so it doesn't draw beyond the 800x480 area? You would probably want to use glViewport rather than glScissor in that case so that your image does not get cut off but is scaled accordingly. You can set the viewport before rendering using h3dSetupViewport but the setting is global and not for specific render targets. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |