question about clearing a depth buffer
how long / intensive is it to clear a depth buffer? because i''m writing a system where the graphics are displayed by layers and i would like to clear the buffer after each successive layer so each layer is written on top of each other and this would involve a few depth buffer clears per frame and i was wondering just how expensive the clearing is.
The hardware can do it VERY quickly...
...however, on some hardware a 32bit frame buffer, a 24bit depth buffer and an 8bit stencil buffer are actually combined into a single 64bit entity so each "pixel" you see is really 64bits, half depth and stencil, half rendered image. Doing that helps speed up the hardware access of memory.
This means that it''s always quicker to clear all of the buffers you use at the same time. Clearing just the depth buffer multiple times should be ok, but will have _some_ hit.
Also since it''s not such a common thing to do (clear frame buffer once and depth multiple times), make sure to test on a number of chips/drivers because the manufacturers may not have tested that case!
There are some other alternatives too:
1) Partition the Z space, either in your projection matrix or in the viewport parameters.
2) Render each layer to a texture, apply that texture to some polygons in your main frame buffer (that''s actually also part of the work needed to implement impostors).
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
...however, on some hardware a 32bit frame buffer, a 24bit depth buffer and an 8bit stencil buffer are actually combined into a single 64bit entity so each "pixel" you see is really 64bits, half depth and stencil, half rendered image. Doing that helps speed up the hardware access of memory.
This means that it''s always quicker to clear all of the buffers you use at the same time. Clearing just the depth buffer multiple times should be ok, but will have _some_ hit.
Also since it''s not such a common thing to do (clear frame buffer once and depth multiple times), make sure to test on a number of chips/drivers because the manufacturers may not have tested that case!
There are some other alternatives too:
1) Partition the Z space, either in your projection matrix or in the viewport parameters.
2) Render each layer to a texture, apply that texture to some polygons in your main frame buffer (that''s actually also part of the work needed to implement impostors).
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
hmm, that first option seems like it could introduce either unwanted clipping or distortion in perspective.
second option seems to be at least as intensive as a buffer clear... you have to write at least as much data to a texture as you need in a clear and then you have to render that again to the backbuffer
second option seems to be at least as intensive as a buffer clear... you have to write at least as much data to a texture as you need in a clear and then you have to render that again to the backbuffer
1) shouldn''t be any distortion - it would however reduce the usable z depth, so depending on what you were doing you may suffer Z artifacts.
2) the point of this is that if the particular chip you''re using is indeed storing colour and depth in single 64bit pixels, then to clear just the depth leaving the colour it has to do:
a) a 64bit read to get the current contents
b) a mask and set the value
c) a write
rather than just a single 64bit write.
Those were more suggestions if the clear colour once, clear z many times failed in some way due to performance (see above) or due to bad driver/chip support (i.e. nobody ever expected someone to do that so they never tested it...)
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
2) the point of this is that if the particular chip you''re using is indeed storing colour and depth in single 64bit pixels, then to clear just the depth leaving the colour it has to do:
a) a 64bit read to get the current contents
b) a mask and set the value
c) a write
rather than just a single 64bit write.
Those were more suggestions if the clear colour once, clear z many times failed in some way due to performance (see above) or due to bad driver/chip support (i.e. nobody ever expected someone to do that so they never tested it...)
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement