/
VertexDeclarations.cpp
103 lines (88 loc) · 3.69 KB
/
VertexDeclarations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//=============================================================================
// Vertex.cpp by Frank Luna (C) 2005 All Rights Reserved.
//=============================================================================
#include "VertexDeclarations.h"
#include "d3dUtil.h"
// Initialize static variables.
IDirect3DVertexDeclaration9* VertexPos::Decl = 0;
IDirect3DVertexDeclaration9* VertexCol::Decl = 0;
IDirect3DVertexDeclaration9* VertexPN::Decl = 0;
IDirect3DVertexDeclaration9* VertexPNT::Decl = 0;
IDirect3DVertexDeclaration9* VertexPTN::Decl = 0;
IDirect3DVertexDeclaration9* VertexPTBNT::Decl = 0;
IDirect3DVertexDeclaration9* VertexPCI::Decl = 0;
void InitAllVertexDeclarations()
{
//===============================================================
// VertexPos
D3DVERTEXELEMENT9 VertexPosElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexPosElements, &VertexPos::Decl));
//===============================================================
// VertexCol
D3DVERTEXELEMENT9 VertexColElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexColElements, &VertexCol::Decl));
//===============================================================
// VertexPN
D3DVERTEXELEMENT9 VertexPNElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexPNElements, &VertexPN::Decl));
//===============================================================
// VertexPNT
D3DVERTEXELEMENT9 VertexPNTElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexPNTElements, &VertexPNT::Decl));
//===============================================================
// VertexPTN
D3DVERTEXELEMENT9 VertexPTNElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexPTNElements, &VertexPTN::Decl));
D3DVERTEXELEMENT9 VertexNormalMapElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
{0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 48, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexNormalMapElements, &VertexPTBNT::Decl));
D3DVERTEXELEMENT9 VertexColInstElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexColInstElements, &VertexPCI::Decl));
}
void DestroyAllVertexDeclarations()
{
ReleaseCOM(VertexPos::Decl);
ReleaseCOM(VertexCol::Decl);
ReleaseCOM(VertexPN::Decl);
ReleaseCOM(VertexPNT::Decl);
ReleaseCOM(VertexPTN::Decl);
ReleaseCOM(VertexPTBNT::Decl);
}