Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


direct 3d Clear method question

This topic is 5412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I still don''t understand what the use of these parameters in IDIrect3DDevice::Clear method Flags [in] Flags that indicate which surfaces should be cleared. This parameter can be any combination of the following flags, but at least one flag must be used. D3DCLEAR_STENCIL Clear the stencil buffer to the value in the Stencil parameter. D3DCLEAR_TARGET Clear the render target to the color in the Color parameter. D3DCLEAR_ZBUFFER Clear the depth buffer to the value in the Z parameter. I don''t get it what should I use althoght the tutorial use D3DCLEAR_TARGET and Z [in] New z value that this method stores in the depth buffer. This parameter can be in the range from 0.0 through 1.0 (for z-based or w-based depth buffers). A value of 0.0 represents the nearest distance to the viewer, and 1.0 the farthest distance. Stencil [in] Integer value to store in each stencil-buffer entry. This parameter can be in the range from 0 through 2n–1, where n is the bit depth of the stencil buffer. I still don''t understand the use of those two parameters.....

Share this post

Link to post
Share on other sites
Usually you will want to clear the colour buffer, z-buffer and the stencil buffer if you have one.


ISTR though that trying to clear the stencil buffer when you dont have one produces an error.

You pretty much have to clear the z-buffer each frame for your scene to render correctly. As an optimisation some people will not clear the colour buffer. This can actually be slower though, because the hardware is optimised to clear the colour buffer and the z-buffer at the same time.

The other two parameters seem pretty self-explanatory.. You understand what a z-buffer and stencil buffer are don''t you? A z-buffer stores depth information of polygons that are rendered to the screen. The value you use in Clear is just used to initialise the values in that buffer.

Share this post

Link to post
Share on other sites
Use target if you want to clear the visible back buffer pixels. If you draw every pixel each frame (no background ever shows) then don''t use this, it''s just a waste of time to clear something you''ll draw over top of.

Use ZBuffer if you want to clear the Z (depth) buffer. Typically this will be used along with a Z value of 1.0f. This means to fill the Z buffer with 1.0f (furthest point from camera). Basically it means, forget the depth of anything I rendered previously, we''re starting fresh.

Many depth buffers also contain stencil information (D24S8 is 24 depth bits and 8 stencil bits, D15S1 is 15 depth bits and 1 stencil bit, D24X8, D16, D32 contain no stencil bits).

Use Stencil if you want to clear the stencil buffer. If you have no stencil buffer, don''t set this or the clear will fail. If you have a stencil buffer, and don''t want to preserve it''s values, then include stencil in your flags, typically with 0 as the extra parameter.

If you have stencil bits and don''t clear the stencil buffer when you clear the Z buffer, then your card must read each pixel, change the depth, and write each pixel... If you specify both the card doesn''t care what used to be there and just quickly writes over everything.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!