Nebula
Loading...
Searching...
No Matches
vertexcomponentbase.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/types.h"
15#include "util/string.h"
16
17//------------------------------------------------------------------------------
18namespace CoreGraphics
19{
20struct VertexLayoutId;
21struct VertexLayoutCreateInfo;
22const VertexLayoutId CreateVertexLayout(const VertexLayoutCreateInfo& info);
23}
24
25namespace Base
26{
28{
29public:
30
32 enum Format
33 {
34 Float, //> one-component float
35 Float2, //> two-component float
36 Float3, //> three-component float
37 Float4, //> four-component float
38 Half, //> one-component 16-bit float
39 Half2, //> two-component 16-bit float
40 Half3, //> three-component 16-bit float
41 Half4, //> four-component 16-bit float
42 UInt, //> one-component unsigned integer
43 UInt2, //> two-component unsigned integer
44 UInt3, //> three-component unsigned integer
45 UInt4, //> four-component unsigned integer
46 Int, //> one-component unsigned integer
47 Int2, //> two-component unsigned integer
48 Int3, //> three-component unsigned integer
49 Int4, //> four-component unsigned integer
50 Short, //> one-component signed short
51 Short2, //> two-component signed short
52 Short3, //> three-component signed short
53 Short4, //> four-component signed short
54 UShort, //> one-component unsigned short
55 UShort2, //> two-component unsigned short
56 UShort3, //> three-component unsigned short
57 UShort4, //> four-component unsigned short
58
59 UByte4, //> four-component unsigned byte
60 Byte4, //> four-component signed byte
61 UByte4N, //> four-component normalized unsigned byte (value / 255.0f)
62 Byte4N, //> four-component normalized signed byte (value / 127.0f)
63
64 Short2N, //> two-component normalized signed short (value / 32767.0f)
65 Short4N, //> four-component normalized signed short (value / 32767.0f)
66 UShort2N, //> two-component unnormalized signed short
67 UShort4N, //> four-component unnormalized signed short
68
69
71 };
72
73
80
85
87 IndexT GetIndex() const;
89 Format GetFormat() const;
91 IndexT GetStreamIndex() const;
93 SizeT GetByteSize() const;
99 SizeT GetStride() const;
101 static Format StringToFormat(const Util::String& str);
107 IndexT GetByteOffset() const;
108
109protected:
110
112
114 void SetByteOffset(IndexT offset);
115
122};
123
124//------------------------------------------------------------------------------
127inline
129 index(0),
130 format(Float),
131 streamIndex(0),
132 byteOffset(0),
133 strideType(PerVertex),
134 stride(0)
135{
136 // empty
137}
138
139//------------------------------------------------------------------------------
142inline
143VertexComponentBase::VertexComponentBase(IndexT semIndex_, Format format_, IndexT streamIndex_, StrideType strideType_, SizeT stride_) :
144 index(semIndex_),
145 format(format_),
146 streamIndex(streamIndex_),
147 byteOffset(0),
148 strideType(strideType_),
149 stride(stride_)
150{
151 // empty
152}
153
154//------------------------------------------------------------------------------
157inline IndexT
159{
160 return this->index;
161}
162
163//------------------------------------------------------------------------------
168{
169 return this->format;
170}
171
172//------------------------------------------------------------------------------
175inline IndexT
177{
178 return this->streamIndex;
179}
180
181//------------------------------------------------------------------------------
186{
187 return this->strideType;
188}
189
190//------------------------------------------------------------------------------
193inline SizeT
195{
196 return this->stride;
197}
198
199//------------------------------------------------------------------------------
202inline SizeT
204{
205 switch (this->format)
206 {
207 case Float: return 4;
208 case Float2: return 8;
209 case Float3: return 12;
210 case Float4: return 16;
211 case Half: return 2;
212 case Half2: return 4;
213 case Half3: return 6;
214 case Half4: return 8;
215 case UInt: return 4;
216 case UInt2: return 8;
217 case UInt3: return 12;
218 case UInt4: return 16;
219 case Int: return 4;
220 case Int2: return 8;
221 case Int3: return 12;
222 case Int4: return 16;
223 case Short: return 2;
224 case Short2: return 4;
225 case Short3: return 6;
226 case Short4: return 8;
227 case UShort: return 2;
228 case UShort2: return 4;
229 case UShort3: return 6;
230 case UShort4: return 8;
231
232 case UByte4: return 4;
233 case Byte4: return 4;
234 case UByte4N: return 4;
235 case Byte4N: return 4;
236 case UShort2N: return 4;
237 case UShort4N: return 8;
238 case Short2N: return 4;
239 case Short4N: return 8;
240 }
241 n_error("Can't happen");
242 return 0;
243}
244
245//------------------------------------------------------------------------------
248inline Util::String
250{
251 switch (f)
252 {
253 case Float: return "Float";
254 case Float2: return "Float2";
255 case Float3: return "Float3";
256 case Float4: return "Float4";
257 case Half: return "Half";
258 case Half2: return "Half2";
259 case Half3: return "Half3";
260 case Half4: return "Half4";
261 case UInt: return "UInt";
262 case UInt2: return "UInt2";
263 case UInt3: return "UInt3";
264 case UInt4: return "UInt4";
265 case Int: return "Int";
266 case Int2: return "Int2";
267 case Int3: return "Int3";
268 case Int4: return "Int4";
269 case Short: return "Short";
270 case Short2: return "Short2";
271 case Short3: return "Short3";
272 case Short4: return "Short4";
273 case UShort: return "UShort";
274 case UShort2: return "UShort2";
275 case UShort3: return "UShort3";
276 case UShort4: return "UShort4";
277
278 case UByte4: return "UByte4";
279 case Byte4: return "Byte4";
280 case UByte4N: return "UByte4N";
281 case Byte4N: return "Byte4N";
282 case UShort2N: return "UShort2N";
283 case UShort4N: return "UShort4N";
284 case Short2N: return "Short2N";
285 case Short4N: return "Short4N";
286
287 default:
288 n_error("VertexComponent::FormatToString(): invalid Format code!");
289 return "";
290 }
291}
292
293//------------------------------------------------------------------------------
296inline Util::String
298{
299 switch (f)
300 {
301 case Float: return "f";
302 case Float2: return "f2";
303 case Float3: return "f3";
304 case Float4: return "f4";
305 case Half: return "h";
306 case Half2: return "h2";
307 case Half3: return "h3";
308 case Half4: return "h4";
309 case UInt: return "ui";
310 case UInt2: return "ui2";
311 case UInt3: return "ui3";
312 case UInt4: return "ui4";
313 case Int: return "i";
314 case Int2: return "i2";
315 case Int3: return "i3";
316 case Int4: return "i4";
317 case Short: return "s";
318 case Short2: return "s2";
319 case Short3: return "s3";
320 case Short4: return "s4";
321 case UShort: return "us";
322 case UShort2: return "us2";
323 case UShort3: return "us3";
324 case UShort4: return "s4";
325
326 case UByte4: return "ub4";
327 case Byte4: return "b4";
328 case UByte4N: return "ub4n";
329 case Byte4N: return "b4n";
330 case UShort2N: return "us2n";
331 case UShort4N: return "us4n";
332 case Short2N: return "s2n";
333 case Short4N: return "s4n";
334
335
336 default:
337 n_error("VertexComponent::FormatToString(): invalid Format code!");
338 return "";
339 }
340}
341
342//------------------------------------------------------------------------------
347{
348 if (str == "Float") return Float;
349 else if (str == "Float2") return Float2;
350 else if (str == "Float3") return Float3;
351 else if (str == "Float4") return Float4;
352 else if (str == "Half") return Half;
353 else if (str == "Half2") return Half2;
354 else if (str == "Half3") return Half3;
355 else if (str == "Half4") return Half4;
356 else if (str == "UInt") return UInt;
357 else if (str == "UInt2") return UInt2;
358 else if (str == "UInt3") return UInt3;
359 else if (str == "UInt4") return UInt4;
360 else if (str == "Int") return Int;
361 else if (str == "Int2") return Int2;
362 else if (str == "Int3") return Int3;
363 else if (str == "Int4") return Int4;
364 else if (str == "Short") return Short;
365 else if (str == "Short2") return Short2;
366 else if (str == "Short3") return Short3;
367 else if (str == "Short4") return Short4;
368 else if (str == "UShort") return UShort;
369 else if (str == "UShort2") return UShort2;
370 else if (str == "UShort3") return UShort3;
371 else if (str == "UShort4") return UShort4;
372
373 else if (str == "UByte4") return UByte4;
374 else if (str == "Byte4") return Byte4;
375 else if (str == "UByte4N") return UByte4N;
376 else if (str == "Byte4N") return Byte4N;
377 else if (str == "UShort2N") return UShort2N;
378 else if (str == "UShort4N") return UShort4N;
379 else if (str == "Short2N") return Short2N;
380 else if (str == "Short4N") return Short4N;
381
382 else
383 {
384 n_error("VertexComponent::StringToFormat(): invalid string '%s'!\n", str.AsCharPtr());
385 return Float;
386 }
387}
388
389//------------------------------------------------------------------------------
392inline Util::String
394{
395 Util::String str;
396 str.AppendInt(this->streamIndex);
397 str.Append(FormatToSignature(this->format));
398 return str;
399}
400
401//------------------------------------------------------------------------------
404inline void
406{
407 this->byteOffset = offset;
408}
409
410//------------------------------------------------------------------------------
413inline IndexT
415{
416 return this->byteOffset;
417}
418
419} // namespace Base
420//------------------------------------------------------------------------------
421
Definition vertexcomponentbase.h:28
static Util::String FormatToSignature(Format f)
convert format to signature
Definition vertexcomponentbase.h:297
Util::String GetSignature() const
get a unique signature of the vertex component
Definition vertexcomponentbase.h:393
SizeT GetByteSize() const
get the byte size of the vertex component
Definition vertexcomponentbase.h:203
Format GetFormat() const
get vertex component format
Definition vertexcomponentbase.h:167
IndexT byteOffset
Definition vertexcomponentbase.h:121
IndexT index
Definition vertexcomponentbase.h:116
static Format StringToFormat(const Util::String &str)
convert string to format
Definition vertexcomponentbase.h:346
StrideType GetStrideType() const
get stride type
Definition vertexcomponentbase.h:185
void SetByteOffset(IndexT offset)
set the vertex byte offset (called from VertexLayoutBase::Setup())
Definition vertexcomponentbase.h:405
IndexT GetIndex() const
get semantic index
Definition vertexcomponentbase.h:158
IndexT GetStreamIndex() const
get stream index
Definition vertexcomponentbase.h:176
static Util::String FormatToString(Format f)
convert format to string
Definition vertexcomponentbase.h:249
IndexT GetByteOffset() const
get the byte offset of this component (only valid when part of a VertexLayout)
Definition vertexcomponentbase.h:414
IndexT streamIndex
Definition vertexcomponentbase.h:120
StrideType
stride type tells if the compoent should be per-instance or per-vertex
Definition vertexcomponentbase.h:76
@ PerVertex
Definition vertexcomponentbase.h:77
@ PerInstance
Definition vertexcomponentbase.h:78
Format format
Definition vertexcomponentbase.h:117
VertexComponentBase()
default constructor
Definition vertexcomponentbase.h:128
StrideType strideType
Definition vertexcomponentbase.h:118
SizeT GetStride() const
get stride between instances
Definition vertexcomponentbase.h:194
SizeT stride
Definition vertexcomponentbase.h:119
Format
component format
Definition vertexcomponentbase.h:33
@ Int3
Definition vertexcomponentbase.h:48
@ Int2
Definition vertexcomponentbase.h:47
@ InvalidFormat
Definition vertexcomponentbase.h:70
@ Int
Definition vertexcomponentbase.h:46
@ Half2
Definition vertexcomponentbase.h:39
@ Short
Definition vertexcomponentbase.h:50
@ Short2
Definition vertexcomponentbase.h:51
@ UInt4
Definition vertexcomponentbase.h:45
@ UInt3
Definition vertexcomponentbase.h:44
@ UByte4N
Definition vertexcomponentbase.h:61
@ UShort4N
Definition vertexcomponentbase.h:67
@ Half3
Definition vertexcomponentbase.h:40
@ UShort4
Definition vertexcomponentbase.h:57
@ Short3
Definition vertexcomponentbase.h:52
@ Float4
Definition vertexcomponentbase.h:37
@ UInt2
Definition vertexcomponentbase.h:43
@ Float3
Definition vertexcomponentbase.h:36
@ UShort
Definition vertexcomponentbase.h:54
@ UInt
Definition vertexcomponentbase.h:42
@ Short2N
Definition vertexcomponentbase.h:64
@ UByte4
Definition vertexcomponentbase.h:59
@ UShort2N
Definition vertexcomponentbase.h:66
@ Int4
Definition vertexcomponentbase.h:49
@ UShort3
Definition vertexcomponentbase.h:56
@ Half4
Definition vertexcomponentbase.h:41
@ UShort2
Definition vertexcomponentbase.h:55
@ Byte4
Definition vertexcomponentbase.h:60
@ Short4N
Definition vertexcomponentbase.h:65
@ Half
Definition vertexcomponentbase.h:38
@ Float2
Definition vertexcomponentbase.h:35
@ Short4
Definition vertexcomponentbase.h:53
@ Float
Definition vertexcomponentbase.h:34
@ Byte4N
Definition vertexcomponentbase.h:62
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
Definition gamecontentserverbase.cc:10
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