Neatware Header
Home   Products   Forums   Partners   Buy   Company   Contact   Blog   

9. Vertex Declaration and Struct

9.1 Vertex Declaration

Vertex declaration expresses the vertice data structure and the tessellator operations. In DirectX 9.0 vertex declaration is an array of D3DVERTEXELEMENT9 structures. In mCL the D3DVERTEXELEMENT9 is expressed as a list. Its format is

[list Stream Offset Type Method Semantic UsageIndex]

Stream is the stream number. Offset is the location of an element in bytes. The size of float is 4 bytes. Type specifies the element type with FLOAT1, FLOAT2, FLOAT3, FLOAT4, SHORT2, etc. Method described the predefined operations. Without using the prefix in D3D, they are DEFAULT, PARTIALU, PARTIALV, CROSSUV, UV, LOOKUP, and LOOKUPPRESAMPLED. Semantic specifies the usage of the element. It can be the value of POSITION, BLENDWEIGHT, NORMAL, PSIZE, TEXCOORD, BINORMAL, TESSFACTOR, POSITIONT, COLOR, FOG, DEPTH, and SAMPLE. UsageIndex is used in conjunction with Usage. Refer to DirectX 9.0 document for more details.

An example of vertex declaration,

set vDecl(Object) [list \
  [
list 0  0 FLOAT3 DEFAULT POSITION 0] \
  [
list 0 12 FLOAT3 DEFAULT NORMAL 0] \
  [
list 0 24 FLOAT2 DEFAULT TEXCOORD 0] \
  [
list 0 32 FLOAT2 DEFAULT TEXCOORD 1]]

Then using decl command in $app to create a vertex declaration object.

set decl(Object) [$app decl $vDecl(Object)]

This vertex declaration is corresponding to the below vertex structure declaration in HLSL.

struct a2v {
  
float3 Position : POSITION; // Position in model space
  
float3 Normal : NORMAL; // Normal in model space
  
float2 TexCoord0 : TEXCOORD0; // Texture coordinate 1
  
float2 TexCoord1 : TEXCOORD1; // Texture coordinate 2
};

$decl set command along with $vt active command made the shader validation during the render of a scene.

9.2 Struct

Struct is a declaration of a set of data elements. An application command $app struct lselem

creates a struct object. The lselem is a list of (type item) pair. Assume st is the variable of a struct object.

  • $st set item value

    sets item to the value which has the type specified in the element list.


  • $st release

    frees struct object.


  • $st size

    returns the size of struct in bytes.


  • $st get item

    returns the value of the item with type specified in the element list.


  • $st init ptr

    initializes struct st points to the pointer ptr so the item can be accessed relatively to the position of the ptr.


  • $st next n

moves current struct st to next n units. The size of unit is the size of struct st.