VERTEX DATA STREAMS

When you render a primitive, you have to specify the source of the vertex data. This can be something as simple as the address of an array of positional data to be rendered in order; or something more complicated such as a set of arrays for positional, color, and perhaps texture coordinates; or a custom vertex format (which can be truly custom or a combination of FVF flags) where you have the positional, color, texture coordinate, vertex normal, and maybe some blending weights all interleaved to make up each element of the vertex array. You also have the option of adding in space for your own data.

Although it may seem odd to force the programmer to interleave all the various positional, color, and texture coordinate data, the reason this is done is to greatly increase the cache coherency. Since all the data that's about to be used together is contiguous in memory, there's an excellent chance that it'll be in the cache as opposed to being in system or GPU memory somewhere where the processor will stall waiting for the memory to be brought in. It's tedious to assemble the data in this way, but once you make the effort, you'll see a real improvement in your rendering speed. It's for your own good, really!

There can be more than one input stream—the exact number depending upon the D3DCAPS.MaxStreams capabilities bit—that you can query as shown next.

 // DirectX 8! // Querying the maximum number of streams // Assumes m_d3dDevice is a valid device pointer D3DCAPS8 d3dCaps; m_d3dDevice->GetDeviceCaps( &d3dCaps ); printf(''This device supports %d streams\n'',          d3dCaps.MaxStreams ); 

The minimum number of streams supported in DirectX 8 and 9 software vertex processor is 16. Unless you're doing some pretty complicated vertex blending operations, you'll probably need no more than one to four simultaneous vertex streams. Using multiple streams can hurt performance. It's a tradeoff between sending extra data along the stream and missing data in the cache. If you're thinking about multiple streams, it's a good idea to set up some test cases.

DirectX 9 stream can also specify a stride value, for which you'd also query the D3DCAPS.MaxStreamStride capabilities bit, that you can query as shown next.

 // DirectX 9! // Querying the maximum stream stride // Assumes m_d3dDevice is a valid device pointer D3DCAPS9 d3dCaps; m_d3dDevice->GetDeviceCaps( &d3dCaps ); printf(''This largest stream stride is %d bytes\n'',          d3dCaps.MaxStreamStride ); 



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net