VertexBuffer and ZBuffer

Started by
0 comments, last by JWalsh 17 years, 11 months ago
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?
Advertisement
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
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

This topic is closed to new replies.

Advertisement