Panda3D
vertexElementArray.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file vertexElementArray.cxx
10  * @author aignacio
11  * @date 2006-01
12  */
13 
15 #include "vertexElementArray.h"
16 
17 
18 VertexElementArray::VertexElementArray(int maximum_vertex_elements) {
19  _total_elements = 0;
20  _maximum_vertex_elements = maximum_vertex_elements;
21 
22  _vertex_element_array = new D3DVERTEXELEMENT9[maximum_vertex_elements];
23  memset(_vertex_element_array, 0, sizeof(D3DVERTEXELEMENT9) * maximum_vertex_elements);
24 }
25 
26 VertexElementArray::~VertexElementArray() {
27  delete _vertex_element_array;
28 }
29 
30 void VertexElementArray::add_position_xyz_vertex_element(int stream_index, int offset) {
31  if (_total_elements >= _maximum_vertex_elements) {
32  return;
33  }
34 
35  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
36 
37  vertex_element->Stream = stream_index;
38  vertex_element->Offset = offset;
39  vertex_element->Type = D3DDECLTYPE_FLOAT3;
40  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
41 
42  vertex_element->Usage = D3DDECLUSAGE_POSITION;
43  vertex_element->UsageIndex = 0;
44 
45  _total_elements++;
46 }
47 
48 void VertexElementArray::add_position_xyzw_vertex_element(int stream_index, int offset) {
49  if (_total_elements >= _maximum_vertex_elements) {
50  return;
51  }
52 
53  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
54 
55  vertex_element->Stream = stream_index;
56  vertex_element->Offset = offset;
57  vertex_element->Type = D3DDECLTYPE_FLOAT4;
58  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
59 
60  vertex_element->Usage = D3DDECLUSAGE_POSITION;
61  vertex_element->UsageIndex = 0;
62 
63  _total_elements++;
64 }
65 
66 void VertexElementArray::add_normal_vertex_element(int stream_index, int offset) {
67  if (_total_elements >= _maximum_vertex_elements) {
68  return;
69  }
70 
71  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
72 
73  vertex_element->Stream = stream_index;
74  vertex_element->Offset = offset;
75  vertex_element->Type = D3DDECLTYPE_FLOAT3;
76  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
77 
78  vertex_element->Usage = D3DDECLUSAGE_NORMAL;
79  vertex_element->UsageIndex = 0;
80 
81  _total_elements++;
82 }
83 
84 void VertexElementArray::add_binormal_vertex_element(int stream_index, int offset) {
85  if (_total_elements >= _maximum_vertex_elements) {
86  return;
87  }
88 
89  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
90 
91  vertex_element->Stream = stream_index;
92  vertex_element->Offset = offset;
93  vertex_element->Type = D3DDECLTYPE_FLOAT3;
94  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
95 
96  vertex_element->Usage = D3DDECLUSAGE_BINORMAL;
97  vertex_element->UsageIndex = 0;
98 
99  _total_elements++;
100 }
101 
102 void VertexElementArray::add_tangent_vertex_element(int stream_index, int offset) {
103  if (_total_elements >= _maximum_vertex_elements) {
104  return;
105  }
106 
107  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
108 
109  vertex_element->Stream = stream_index;
110  vertex_element->Offset = offset;
111  vertex_element->Type = D3DDECLTYPE_FLOAT3;
112  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
113 
114  vertex_element->Usage = D3DDECLUSAGE_TANGENT;
115  vertex_element->UsageIndex = 0;
116 
117  _total_elements++;
118 }
119 
120 void VertexElementArray::add_diffuse_color_vertex_element(int stream_index, int offset) {
121  if (_total_elements >= _maximum_vertex_elements) {
122  return;
123  }
124 
125  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
126 
127  vertex_element->Stream = stream_index;
128  vertex_element->Offset = offset;
129  vertex_element->Type = D3DDECLTYPE_D3DCOLOR;
130  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
131 
132  vertex_element->Usage = D3DDECLUSAGE_COLOR;
133  vertex_element->UsageIndex = 0;
134 
135  _total_elements++;
136 }
137 
138 void VertexElementArray::add_specular_color_vertex_element(int stream_index, int offset) {
139  if (_total_elements >= _maximum_vertex_elements) {
140  return;
141  }
142 
143  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
144 
145  vertex_element->Stream = stream_index;
146  vertex_element->Offset = offset;
147  vertex_element->Type = D3DDECLTYPE_D3DCOLOR;
148  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
149 
150  vertex_element->Usage = D3DDECLUSAGE_COLOR;
151  vertex_element->UsageIndex = 1;
152 
153  _total_elements++;
154 }
155 
156 void VertexElementArray::add_u_vertex_element(int stream_index, int offset, int texture_stage) {
157  if (_total_elements >= _maximum_vertex_elements) {
158  return;
159  }
160 
161  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
162 
163  vertex_element->Stream = stream_index;
164  vertex_element->Offset = offset;
165  vertex_element->Type = D3DDECLTYPE_FLOAT1;
166  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
167 
168  vertex_element->Usage = D3DDECLUSAGE_TEXCOORD;
169  vertex_element->UsageIndex = texture_stage;
170 
171  _total_elements++;
172 }
173 
174 void VertexElementArray::add_uv_vertex_element(int stream_index, int offset, int texture_stage) {
175  if (_total_elements >= _maximum_vertex_elements) {
176  return;
177  }
178 
179  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
180 
181  vertex_element->Stream = stream_index;
182  vertex_element->Offset = offset;
183  vertex_element->Type = D3DDECLTYPE_FLOAT2;
184  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
185 
186  vertex_element->Usage = D3DDECLUSAGE_TEXCOORD;
187  vertex_element->UsageIndex = texture_stage;
188 
189  _total_elements++;
190 }
191 
192 void VertexElementArray::add_uvw_vertex_element(int stream_index, int offset, int texture_stage) {
193  if (_total_elements >= _maximum_vertex_elements) {
194  return;
195  }
196 
197  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
198 
199  vertex_element->Stream = stream_index;
200  vertex_element->Offset = offset;
201  vertex_element->Type = D3DDECLTYPE_FLOAT3;
202  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
203 
204  vertex_element->Usage = D3DDECLUSAGE_TEXCOORD;
205  vertex_element->UsageIndex = texture_stage;
206 
207  _total_elements++;
208 }
209 
210 void VertexElementArray::add_xyzw_vertex_element(int stream_index, int offset, int texture_stage) {
211  if (_total_elements >= _maximum_vertex_elements) {
212  return;
213  }
214 
215  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
216 
217  vertex_element->Stream = stream_index;
218  vertex_element->Offset = offset;
219  vertex_element->Type = D3DDECLTYPE_FLOAT4;
220  vertex_element->Method = D3DDECLMETHOD_DEFAULT;
221 
222  vertex_element->Usage = D3DDECLUSAGE_TEXCOORD;
223  vertex_element->UsageIndex = texture_stage;
224 
225  _total_elements++;
226 }
227 
228 bool VertexElementArray::add_end_vertex_element(void) {
229  if (_total_elements >= _maximum_vertex_elements) {
230  return false;
231  }
232 
233  LPD3DVERTEXELEMENT9 vertex_element = &_vertex_element_array[_total_elements];
234 
235  vertex_element->Stream = 0xFF;
236  vertex_element->Offset = 0;
237  vertex_element->Type = D3DDECLTYPE_UNUSED;
238  vertex_element->Method = 0;
239 
240  vertex_element->Usage = 0;
241  vertex_element->UsageIndex = 0;
242 
243  return true;
244 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.