Sign in to follow this  
whereisumar

VertexBuffer and ZBuffer

Recommended Posts

Hi i had a question, in order for the zbuffer to work and hide geometry behind other geometery properly, do you HAVE to use a vertexbuffer? In Direct3D with c# do you always have to have a vertex buffer contain all the vertex data in order for the zbuffer to work properly, or can u draw just using drawprimitives and have seperate objects holding seperate vertex data?

Share this post


Link to post
Share on other sites
Hi whereisumar!

Welcome to GameDev.net. I'll see if I can answer your question. It appears as though you're asking two questions, "Can I render without vertex buffers in DirectX?" and "how can I use zbuffering?" I'll answer your questions separately.

For the first question...yes, you CAN render in Direct3D without using vertex buffers, but its significantly slower. Depending upon which pool of memory you use to create the vertex buffers, the device can create the vertex buffer either in system memory, video memory, or shared memory. By creating the vertex buffer in video memory, and to a degree in shared memory, the device has significantly faster access to the data - and thus, faster renders.

With that being said, Direct3D will allow you to feed it vertex data by using "user data." This is done by calling "DrawUserPrimitives" rather than DrawPrimitives (DrawPrimitives requires a stream be set to an existing vertex buffer).

For your second question, you can use zbuffering with either DrawPrimitives or DrawUserPrimitives, it doesn’t matter. By using zbuffering the device creates a depth buffer which it uses to determine whether a primitive should be drawn in front of, or in back of what's currently on screen by performing a depth test.

To use zbuffering, just enable it on the device with.
Device.SetRenderState(ZEnable, true);

One you do this, make sure to clear the depth buffer during the clear phase.

Cheers!
Jeromy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this