VertexBuffer and ZBuffer
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?
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement