blob: 4aa0144342c31e0df93fc062adfd09cb10811814 (
plain) (
blame)
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
104
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A set of utilities to render standard shapes
//
//===========================================================================//
#include "tier2/meshutils.h"
//-----------------------------------------------------------------------------
// Helper methods to create various standard index buffer types
//-----------------------------------------------------------------------------
void GenerateSequentialIndexBuffer( unsigned short* pIndices, int nIndexCount, int nFirstVertex )
{
if ( !pIndices )
return;
// Format the sequential buffer
for ( int i = 0; i < nIndexCount; ++i )
{
pIndices[i] = (unsigned short)( i + nFirstVertex );
}
}
void GenerateQuadIndexBuffer( unsigned short* pIndices, int nIndexCount, int nFirstVertex )
{
if ( !pIndices )
return;
// Format the quad buffer
int i;
int numQuads = nIndexCount / 6;
int baseVertex = nFirstVertex;
for ( i = 0; i < numQuads; ++i)
{
// Triangle 1
pIndices[0] = (unsigned short)( baseVertex );
pIndices[1] = (unsigned short)( baseVertex + 1 );
pIndices[2] = (unsigned short)( baseVertex + 2 );
// Triangle 2
pIndices[3] = (unsigned short)( baseVertex );
pIndices[4] = (unsigned short)( baseVertex + 2 );
pIndices[5] = (unsigned short)( baseVertex + 3 );
baseVertex += 4;
pIndices += 6;
}
}
void GeneratePolygonIndexBuffer( unsigned short* pIndices, int nIndexCount, int nFirstVertex )
{
if ( !pIndices )
return;
int i;
int numPolygons = nIndexCount / 3;
for ( i = 0; i < numPolygons; ++i)
{
// Triangle 1
pIndices[0] = (unsigned short)( nFirstVertex );
pIndices[1] = (unsigned short)( nFirstVertex + i + 1 );
pIndices[2] = (unsigned short)( nFirstVertex + i + 2 );
pIndices += 3;
}
}
void GenerateLineStripIndexBuffer( unsigned short* pIndices, int nIndexCount, int nFirstVertex )
{
if ( !pIndices )
return;
int i;
int numLines = nIndexCount / 2;
for ( i = 0; i < numLines; ++i)
{
pIndices[0] = (unsigned short)( nFirstVertex + i );
pIndices[1] = (unsigned short)( nFirstVertex + i + 1 );
pIndices += 2;
}
}
void GenerateLineLoopIndexBuffer( unsigned short* pIndices, int nIndexCount, int nFirstVertex )
{
if ( !pIndices )
{
return;
}
int i;
int numLines = nIndexCount / 2;
pIndices[0] = (unsigned short)( nFirstVertex + numLines - 1 );
pIndices[1] = (unsigned short)( nFirstVertex );
pIndices += 2;
for ( i = 1; i < numLines; ++i)
{
pIndices[0] = (unsigned short)( nFirstVertex + i - 1 );
pIndices[1] = (unsigned short)( nFirstVertex + i );
pIndices += 2;
}
}
|