Microsoft DirectX 8.0 (Visual Basic) |
The declaration portion of a vertex shader defines the static external interface of the shader. A vertex shader declaration includes the following information.
Declaration arrays are single-dimensional arrays of Longs composed of multiple tokens, each of which is one or more Longs. The single-Long token value 0xFFFFFFFF is a special token used to indicate the end of the declaration array. The single Long token value 0x00000000 is a padding token that is ignored during the declaration parsing. This pad token enables more complex in-place editing of declarations. Note that 0x00000000 is a valid value for Longs following the first Long for multiple word tokens.
The following code example demonstrates how to write declarators. It shows how to define a vertex using a simple structure.
Type Vertex Position As D3DVECTOR Normal As D3DVECTOR Diffuse As D3DCOLORVALUE TexCoord0 As D3DVECTOR2 End Type
Now consider the following code example, which shows how to define the same vertex structure above as a declarator.
Dim Decl(5) As Long Dim FVF as Long Decl(0) = D3DVSD_STREAM(0) Decl(1)= D3DVSD_STREAM( 0 )D3DVSD_REG( D3DVSDE_POSITION, D3DVSDT_FLOAT3 ), Decl(2)= D3DVSD_STREAM( 0 )D3DVSD_REG( D3DVSDE_NORMAL, D3DVSDT_FLOAT3 ), Decl(3)= D3DVSD_STREAM( 0 )D3DVSD_REG( D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR ), Decl(4)= D3DVSD_STREAM( 0 )D3DVSD_REG( D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2 ), Decl(5)= D3DVSD_STREAM( 0 )D3DVSD_END() FVF = D3DFVF_POSITION Or D3DFVF_NORMAL Or D3DFVF_DIFFUSE Or _ D3DFVF_TEX0 Or D3DFVF_TEXCOORDSIZE2(0);
The declarator sets data stream 0, defines a position and normal vector composed of three Long values, defines a diffuse component composed of a four component unsigned byte, and defines a pair of texture coordinates composed of two Long values.
When you use the fixed-function vertex shader, the mapping of the vertex input registers is fixed so that specific vertex elements, such as position or normal, must be placed in specific register locations in the vertex input memory. These assignments are made automatically when passing an FVF code to Direct3DDevice8.SetVertexShader. When you use an explicit shader declaration, the D3DVSDE preprocessor macros define the vertex input location into which specific elements must be loaded. See \Samples\Multimedia\VBSamples\Common\D3DShaders.bas for a definition of the macros used to generate the declaration token array.
For information on the shader declaration token types and bit definitions, see Vertex Shader Declarator Functions.
Notes When using fixed-function vertex shaders, the vertex stride set in Direct3DDevice8.SetStreamSource and vertex size must be the same size. For vertex shaders that use declarations, the stream stride can be greater than the declaration stride.