Nebula
Loading...
Searching...
No Matches
vertexcomponent.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "util/string.h"
13namespace CoreGraphics
14{
15
16struct VertexLayoutId;
17struct VertexLayoutCreateInfo;
18const VertexLayoutId CreateVertexLayout(const VertexLayoutCreateInfo& info);
19
21{
22public:
24 enum Format
25 {
26 Float, //> one-component float
27 Float2, //> two-component float
28 Float3, //> three-component float
29 Float4, //> four-component float
30 Half, //> one-component 16-bit float
31 Half2, //> two-component 16-bit float
32 Half3, //> three-component 16-bit float
33 Half4, //> four-component 16-bit float
34 UInt, //> one-component unsigned integer
35 UInt2, //> two-component unsigned integer
36 UInt3, //> three-component unsigned integer
37 UInt4, //> four-component unsigned integer
38 Int, //> one-component unsigned integer
39 Int2, //> two-component unsigned integer
40 Int3, //> three-component unsigned integer
41 Int4, //> four-component unsigned integer
42 Short, //> one-component signed short
43 Short2, //> two-component signed short
44 Short3, //> three-component signed short
45 Short4, //> four-component signed short
46 UShort, //> one-component unsigned short
47 UShort2, //> two-component unsigned short
48 UShort3, //> three-component unsigned short
49 UShort4, //> four-component unsigned short
50
51 UByte4, //> four-component unsigned byte
52 Byte4, //> four-component signed byte
53 UByte4N, //> four-component normalized unsigned byte (value / 255.0f)
54 Byte4N, //> four-component normalized signed byte (value / 127.0f)
55
56 Short2N, //> two-component normalized signed short (value / 32767.0f)
57 Short4N, //> four-component normalized signed short (value / 32767.0f)
58 UShort2N, //> two-component unnormalized signed short
59 UShort4N, //> four-component unnormalized signed short
60
61
63 };
64
81
88
93
95 IndexT GetIndex() const;
97 Format GetFormat() const;
99 IndexT GetStreamIndex() const;
101 SizeT GetByteSize() const;
107 SizeT GetStride() const;
109 static Format StringToFormat(const Util::String& str);
115 IndexT GetByteOffset() const;
116
117protected:
118
120
122 void SetByteOffset(IndexT offset);
123
130};
131
132//------------------------------------------------------------------------------
135inline
137 index(0),
138 format(Float),
139 strideType(PerVertex),
140 stride(0),
141 streamIndex(0),
142 byteOffset(0)
143{
144 // empty
145}
146
147//------------------------------------------------------------------------------
150inline
151VertexComponent::VertexComponent(IndexT semIndex_, Format format_, IndexT streamIndex_, StrideType strideType_, SizeT stride_) :
152 index(semIndex_),
153 format(format_),
154 strideType(strideType_),
155 stride(stride_),
156 streamIndex(streamIndex_),
157 byteOffset(0)
158{
159 // empty
160}
161
162//------------------------------------------------------------------------------
165inline IndexT
167{
168 return this->index;
169}
170
171//------------------------------------------------------------------------------
176{
177 return this->format;
178}
179
180//------------------------------------------------------------------------------
183inline IndexT
185{
186 return this->streamIndex;
187}
188
189//------------------------------------------------------------------------------
194{
195 return this->strideType;
196}
197
198//------------------------------------------------------------------------------
201inline SizeT
203{
204 return this->stride;
205}
206
207//------------------------------------------------------------------------------
210inline SizeT
212{
213 switch (this->format)
214 {
215 case Float: return 4;
216 case Float2: return 8;
217 case Float3: return 12;
218 case Float4: return 16;
219 case Half: return 2;
220 case Half2: return 4;
221 case Half3: return 6;
222 case Half4: return 8;
223 case UInt: return 4;
224 case UInt2: return 8;
225 case UInt3: return 12;
226 case UInt4: return 16;
227 case Int: return 4;
228 case Int2: return 8;
229 case Int3: return 12;
230 case Int4: return 16;
231 case Short: return 2;
232 case Short2: return 4;
233 case Short3: return 6;
234 case Short4: return 8;
235 case UShort: return 2;
236 case UShort2: return 4;
237 case UShort3: return 6;
238 case UShort4: return 8;
239
240 case UByte4: return 4;
241 case Byte4: return 4;
242 case UByte4N: return 4;
243 case Byte4N: return 4;
244 case UShort2N: return 4;
245 case UShort4N: return 8;
246 case Short2N: return 4;
247 case Short4N: return 8;
248 default: break;
249 }
250 n_error("Can't happen");
251 return 0;
252}
253
254//------------------------------------------------------------------------------
257inline Util::String
259{
260 switch (f)
261 {
262 case Float: return "Float";
263 case Float2: return "Float2";
264 case Float3: return "Float3";
265 case Float4: return "Float4";
266 case Half: return "Half";
267 case Half2: return "Half2";
268 case Half3: return "Half3";
269 case Half4: return "Half4";
270 case UInt: return "UInt";
271 case UInt2: return "UInt2";
272 case UInt3: return "UInt3";
273 case UInt4: return "UInt4";
274 case Int: return "Int";
275 case Int2: return "Int2";
276 case Int3: return "Int3";
277 case Int4: return "Int4";
278 case Short: return "Short";
279 case Short2: return "Short2";
280 case Short3: return "Short3";
281 case Short4: return "Short4";
282 case UShort: return "UShort";
283 case UShort2: return "UShort2";
284 case UShort3: return "UShort3";
285 case UShort4: return "UShort4";
286
287 case UByte4: return "UByte4";
288 case Byte4: return "Byte4";
289 case UByte4N: return "UByte4N";
290 case Byte4N: return "Byte4N";
291 case UShort2N: return "UShort2N";
292 case UShort4N: return "UShort4N";
293 case Short2N: return "Short2N";
294 case Short4N: return "Short4N";
295
296 default:
297 n_error("VertexComponent::FormatToString(): invalid Format code!");
298 return "";
299 }
300}
301
302//------------------------------------------------------------------------------
305inline Util::String
307{
308 switch (f)
309 {
310 case Float: return "f";
311 case Float2: return "f2";
312 case Float3: return "f3";
313 case Float4: return "f4";
314 case Half: return "h";
315 case Half2: return "h2";
316 case Half3: return "h3";
317 case Half4: return "h4";
318 case UInt: return "ui";
319 case UInt2: return "ui2";
320 case UInt3: return "ui3";
321 case UInt4: return "ui4";
322 case Int: return "i";
323 case Int2: return "i2";
324 case Int3: return "i3";
325 case Int4: return "i4";
326 case Short: return "s";
327 case Short2: return "s2";
328 case Short3: return "s3";
329 case Short4: return "s4";
330 case UShort: return "us";
331 case UShort2: return "us2";
332 case UShort3: return "us3";
333 case UShort4: return "s4";
334
335 case UByte4: return "ub4";
336 case Byte4: return "b4";
337 case UByte4N: return "ub4n";
338 case Byte4N: return "b4n";
339 case UShort2N: return "us2n";
340 case UShort4N: return "us4n";
341 case Short2N: return "s2n";
342 case Short4N: return "s4n";
343
344
345 default:
346 n_error("VertexComponent::FormatToString(): invalid Format code!");
347 return "";
348 }
349}
350
351//------------------------------------------------------------------------------
356{
357 if (str == "Float") return Float;
358 else if (str == "Float2") return Float2;
359 else if (str == "Float3") return Float3;
360 else if (str == "Float4") return Float4;
361 else if (str == "Half") return Half;
362 else if (str == "Half2") return Half2;
363 else if (str == "Half3") return Half3;
364 else if (str == "Half4") return Half4;
365 else if (str == "UInt") return UInt;
366 else if (str == "UInt2") return UInt2;
367 else if (str == "UInt3") return UInt3;
368 else if (str == "UInt4") return UInt4;
369 else if (str == "Int") return Int;
370 else if (str == "Int2") return Int2;
371 else if (str == "Int3") return Int3;
372 else if (str == "Int4") return Int4;
373 else if (str == "Short") return Short;
374 else if (str == "Short2") return Short2;
375 else if (str == "Short3") return Short3;
376 else if (str == "Short4") return Short4;
377 else if (str == "UShort") return UShort;
378 else if (str == "UShort2") return UShort2;
379 else if (str == "UShort3") return UShort3;
380 else if (str == "UShort4") return UShort4;
381
382 else if (str == "UByte4") return UByte4;
383 else if (str == "Byte4") return Byte4;
384 else if (str == "UByte4N") return UByte4N;
385 else if (str == "Byte4N") return Byte4N;
386 else if (str == "UShort2N") return UShort2N;
387 else if (str == "UShort4N") return UShort4N;
388 else if (str == "Short2N") return Short2N;
389 else if (str == "Short4N") return Short4N;
390
391 else
392 {
393 n_error("VertexComponent::StringToFormat(): invalid string '%s'!\n", str.AsCharPtr());
394 return Float;
395 }
396}
397
398//------------------------------------------------------------------------------
401inline Util::String
403{
404 Util::String str;
405 str.AppendInt(this->streamIndex);
406 str.Append(FormatToSignature(this->format));
407 return str;
408}
409
410//------------------------------------------------------------------------------
413inline void
415{
416 this->byteOffset = offset;
417}
418
419//------------------------------------------------------------------------------
422inline IndexT
424{
425 return this->byteOffset;
426}
427
428} // namespace CoreGraphics
429
Describes a single vertex component in a vertex layout description.
Definition vertexcomponent.h:21
Format
component format
Definition vertexcomponent.h:25
@ Short2
Definition vertexcomponent.h:43
@ Short2N
Definition vertexcomponent.h:56
@ UInt4
Definition vertexcomponent.h:37
@ UInt2
Definition vertexcomponent.h:35
@ UShort2
Definition vertexcomponent.h:47
@ Byte4N
Definition vertexcomponent.h:54
@ Short3
Definition vertexcomponent.h:44
@ UByte4N
Definition vertexcomponent.h:53
@ UShort
Definition vertexcomponent.h:46
@ Half4
Definition vertexcomponent.h:33
@ UInt3
Definition vertexcomponent.h:36
@ Int4
Definition vertexcomponent.h:41
@ Int3
Definition vertexcomponent.h:40
@ UShort4N
Definition vertexcomponent.h:59
@ Float3
Definition vertexcomponent.h:28
@ Half3
Definition vertexcomponent.h:32
@ Byte4
Definition vertexcomponent.h:52
@ Float4
Definition vertexcomponent.h:29
@ Int2
Definition vertexcomponent.h:39
@ UInt
Definition vertexcomponent.h:34
@ UShort4
Definition vertexcomponent.h:49
@ UShort3
Definition vertexcomponent.h:48
@ Short4
Definition vertexcomponent.h:45
@ Float2
Definition vertexcomponent.h:27
@ UByte4
Definition vertexcomponent.h:51
@ Short4N
Definition vertexcomponent.h:57
@ InvalidFormat
Definition vertexcomponent.h:62
@ Int
Definition vertexcomponent.h:38
@ UShort2N
Definition vertexcomponent.h:58
@ Half
Definition vertexcomponent.h:30
@ Half2
Definition vertexcomponent.h:31
@ Short
Definition vertexcomponent.h:42
@ Float
Definition vertexcomponent.h:26
IndexT GetStreamIndex() const
get stream index
Definition vertexcomponent.h:184
static Format StringToFormat(const Util::String &str)
convert string to format
Definition vertexcomponent.h:355
SizeT stride
Definition vertexcomponent.h:127
StrideType
stride type tells if the compoent should be per-instance or per-vertex
Definition vertexcomponent.h:84
@ PerVertex
Definition vertexcomponent.h:85
@ PerInstance
Definition vertexcomponent.h:86
IndexName
Definition vertexcomponent.h:66
@ Binormal
Definition vertexcomponent.h:71
@ SkinWeights
Definition vertexcomponent.h:74
@ Position
Definition vertexcomponent.h:67
@ SkinJIndices
Definition vertexcomponent.h:75
@ Normal
Definition vertexcomponent.h:68
@ Tangent
Definition vertexcomponent.h:70
@ Color
Definition vertexcomponent.h:72
@ Invalid
Definition vertexcomponent.h:79
@ TexCoord3
Definition vertexcomponent.h:76
@ TexCoord4
Definition vertexcomponent.h:77
@ TexCoord1
Definition vertexcomponent.h:69
@ TexCoord2
Definition vertexcomponent.h:73
SizeT GetStride() const
get stride between instances
Definition vertexcomponent.h:202
VertexComponent()
default constructor
Definition vertexcomponent.h:136
IndexT GetByteOffset() const
get the byte offset of this component (only valid when part of a VertexLayout)
Definition vertexcomponent.h:423
IndexT byteOffset
Definition vertexcomponent.h:129
Util::String GetSignature() const
get a unique signature of the vertex component
Definition vertexcomponent.h:402
static Util::String FormatToSignature(Format f)
convert format to signature
Definition vertexcomponent.h:306
Format GetFormat() const
get vertex component format
Definition vertexcomponent.h:175
Format format
Definition vertexcomponent.h:125
SizeT GetByteSize() const
get the byte size of the vertex component
Definition vertexcomponent.h:211
IndexT index
Definition vertexcomponent.h:124
IndexT GetIndex() const
get semantic index
Definition vertexcomponent.h:166
StrideType strideType
Definition vertexcomponent.h:126
void SetByteOffset(IndexT offset)
set the vertex byte offset (called from VertexLayoutBase::Setup())
Definition vertexcomponent.h:414
StrideType GetStrideType() const
get stride type
Definition vertexcomponent.h:193
IndexT streamIndex
Definition vertexcomponent.h:128
static Util::String FormatToString(Format f)
convert format to string
Definition vertexcomponent.h:258
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
const VertexLayoutId CreateVertexLayout(const VertexLayoutCreateInfo &info)
create new vertex layout
Definition vkvertexlayout.cc:36
Definition vertexlayout.h:22
Definition vertexlayout.h:16
Nebula's universal string class.
Definition string.h:50
void Append(const String &str)
append string
Definition string.h:615
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:540
void AppendInt(int val)
append int value
Definition string.h:1104
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48