Diligent Engine  v.2.4.g
InputLayout.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 // clang-format off
31 
34 
35 #include <string.h>
36 
37 #include "GraphicsTypes.h"
38 
40 
41 
42 static const Uint32 MAX_LAYOUT_ELEMENTS = 16;
43 static const Uint32 LAYOUT_ELEMENT_AUTO_OFFSET = 0xFFFFFFFF;
44 static const Uint32 LAYOUT_ELEMENT_AUTO_STRIDE = 0xFFFFFFFF;
45 
48 {
51 
54 
57 
60 };
61 
64 {
69  const char* HLSLSemantic DEFAULT_INITIALIZER("ATTRIB");
70 
73  Uint32 InputIndex DEFAULT_INITIALIZER(0);
74 
76  Uint32 BufferSlot DEFAULT_INITIALIZER(0);
77 
80 
83 
89  Bool IsNormalized DEFAULT_INITIALIZER(True);
90 
94  Uint32 RelativeOffset DEFAULT_INITIALIZER(LAYOUT_ELEMENT_AUTO_OFFSET);
95 
101  Uint32 Stride DEFAULT_INITIALIZER(LAYOUT_ELEMENT_AUTO_STRIDE);
102 
104 
107  Uint32 InstanceDataStepRate DEFAULT_INITIALIZER(1);
108 
109 
110 #if DILIGENT_CPP_INTERFACE
111 
112  LayoutElement()noexcept{}
113 
115  LayoutElement(Uint32 _InputIndex,
116  Uint32 _BufferSlot,
117  Uint32 _NumComponents,
118  VALUE_TYPE _ValueType,
119  Bool _IsNormalized = LayoutElement{}.IsNormalized,
120  Uint32 _RelativeOffset = LayoutElement{}.RelativeOffset,
121  Uint32 _Stride = LayoutElement{}.Stride,
123  Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept :
124  InputIndex {_InputIndex },
125  BufferSlot {_BufferSlot },
126  NumComponents {_NumComponents },
127  ValueType {_ValueType },
128  IsNormalized {_IsNormalized },
129  RelativeOffset {_RelativeOffset },
130  Stride {_Stride },
131  Frequency {_Frequency },
132  InstanceDataStepRate{_InstanceDataStepRate}
133  {}
134 
136  LayoutElement(const char* _HLSLSemantic,
137  Uint32 _InputIndex,
138  Uint32 _BufferSlot,
139  Uint32 _NumComponents,
140  VALUE_TYPE _ValueType,
141  Bool _IsNormalized = LayoutElement{}.IsNormalized,
142  Uint32 _RelativeOffset = LayoutElement{}.RelativeOffset,
143  Uint32 _Stride = LayoutElement{}.Stride,
145  Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept :
146  HLSLSemantic {_HLSLSemantic },
147  InputIndex {_InputIndex },
148  BufferSlot {_BufferSlot },
149  NumComponents {_NumComponents },
150  ValueType {_ValueType },
151  IsNormalized {_IsNormalized },
152  RelativeOffset {_RelativeOffset },
153  Stride {_Stride },
154  Frequency {_Frequency },
155  InstanceDataStepRate{_InstanceDataStepRate}
156  {}
157 
159  LayoutElement(Uint32 _InputIndex,
160  Uint32 _BufferSlot,
161  Uint32 _NumComponents,
162  VALUE_TYPE _ValueType,
163  Bool _IsNormalized,
164  INPUT_ELEMENT_FREQUENCY _Frequency,
165  Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept :
166  InputIndex {_InputIndex },
167  BufferSlot {_BufferSlot },
168  NumComponents {_NumComponents },
169  ValueType {_ValueType },
170  IsNormalized {_IsNormalized },
171  RelativeOffset {LayoutElement{}.RelativeOffset},
172  Stride {LayoutElement{}.Stride },
173  Frequency {_Frequency },
174  InstanceDataStepRate{_InstanceDataStepRate }
175  {}
176 
177  bool operator == (const LayoutElement& rhs) const
178  {
179  return strcmp(HLSLSemantic, rhs.HLSLSemantic) == 0 &&
180  InputIndex == rhs.InputIndex &&
181  BufferSlot == rhs.BufferSlot &&
182  NumComponents == rhs.NumComponents &&
183  ValueType == rhs.ValueType &&
184  IsNormalized == rhs.IsNormalized &&
185  RelativeOffset == rhs.RelativeOffset &&
186  Stride == rhs.Stride &&
187  Frequency == rhs.Frequency &&
188  InstanceDataStepRate == rhs.InstanceDataStepRate;
189  }
190 
191  bool operator != (const LayoutElement& rhs) const
192  {
193  return !(*this == rhs);
194  }
195 #endif
196 };
198 
199 
201 
204 {
206  const LayoutElement* LayoutElements DEFAULT_INITIALIZER(nullptr);
208  Uint32 NumElements DEFAULT_INITIALIZER(0);
209 
210 #if DILIGENT_CPP_INTERFACE
211  InputLayoutDesc()noexcept{}
212 
213  InputLayoutDesc(const LayoutElement* _LayoutElements,
214  Uint32 _NumElements)noexcept :
215  LayoutElements{_LayoutElements},
216  NumElements {_NumElements }
217  {}
218 
219  bool operator == (const InputLayoutDesc& rhs) const
220  {
221  if (NumElements != rhs.NumElements)
222  return false;
223 
224  for (Uint32 i=0; i < NumElements; ++i)
225  {
226  if (LayoutElements[i] != rhs.LayoutElements[i])
227  return false;
228  }
229 
230  return true;
231  }
232 
233  bool operator != (const InputLayoutDesc& rhs) const
234  {
235  return !(*this == rhs);
236  }
237 #endif
238 };
240 
Diligent::LayoutElement
Description of a single element of the input layout.
Definition: InputLayout.h:63
Diligent::InputLayoutDesc::InputLayoutDesc
InputLayoutDesc(const LayoutElement *_LayoutElements, Uint32 _NumElements) noexcept
Definition: InputLayout.h:213
Diligent::INPUT_ELEMENT_FREQUENCY_UNDEFINED
@ INPUT_ELEMENT_FREQUENCY_UNDEFINED
Frequency is undefined.
Definition: InputLayout.h:50
Diligent::INPUT_ELEMENT_FREQUENCY_PER_INSTANCE
@ INPUT_ELEMENT_FREQUENCY_PER_INSTANCE
Input data is per-instance data.
Definition: InputLayout.h:56
Diligent::LayoutElement::BufferSlot
Uint32 BufferSlot
Buffer slot index that this element is read from.
Definition: InputLayout.h:76
Diligent::LayoutElement::HLSLSemantic
const char * HLSLSemantic
HLSL semantic. Default value ("ATTRIB") allows HLSL shaders to be converted to GLSL and used in OpenG...
Definition: InputLayout.h:69
Diligent::INPUT_ELEMENT_FREQUENCY_NUM_FREQUENCIES
@ INPUT_ELEMENT_FREQUENCY_NUM_FREQUENCIES
Helper value that stores the total number of frequencies in the enumeration.
Definition: InputLayout.h:59
Diligent::LayoutElement::InstanceDataStepRate
Uint32 InstanceDataStepRate
The number of instances to draw using the same per-instance data before advancing in the buffer by on...
Definition: InputLayout.h:107
Diligent::LayoutElement::NumComponents
Uint32 NumComponents
Number of components in the element. Allowed values are 1, 2, 3, and 4.
Definition: InputLayout.h:79
Diligent::operator==
bool operator==(const Plane3D &p1, const Plane3D &p2)
Definition: AdvancedMath.hpp:442
Diligent::LayoutElement::LayoutElement
LayoutElement() noexcept
Definition: InputLayout.h:112
Diligent::LayoutElement::Stride
Uint32 Stride
Stride, in bytes, between two elements, for this buffer slot. If this value is set to LAYOUT_ELEMENT_...
Definition: InputLayout.h:101
Diligent::InputLayoutDesc
Layout description.
Definition: InputLayout.h:203
DILIGENT_END_NAMESPACE
#define DILIGENT_END_NAMESPACE
Definition: CommonDefinitions.h:86
Diligent::VALUE_TYPE
VALUE_TYPE
Value type.
Definition: GraphicsTypes.h:49
NumComponents
D3D10_SB_OPERAND_NUM_COMPONENTS NumComponents
Definition: DXBCUtils.cpp:519
Diligent::LayoutElement
struct LayoutElement LayoutElement
Definition: InputLayout.h:197
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
DEFAULT_INITIALIZER
#define DEFAULT_INITIALIZER(x)
Definition: CommonDefinitions.h:93
Diligent::Bool
bool Bool
Boolean.
Definition: BasicTypes.h:59
Diligent::INPUT_ELEMENT_FREQUENCY_PER_VERTEX
@ INPUT_ELEMENT_FREQUENCY_PER_VERTEX
Input data is per-vertex data.
Definition: InputLayout.h:53
Diligent::LayoutElement::LayoutElement
LayoutElement(Uint32 _InputIndex, Uint32 _BufferSlot, Uint32 _NumComponents, VALUE_TYPE _ValueType, Bool _IsNormalized=LayoutElement{}.IsNormalized, Uint32 _RelativeOffset=LayoutElement{}.RelativeOffset, Uint32 _Stride=LayoutElement{}.Stride, INPUT_ELEMENT_FREQUENCY _Frequency=LayoutElement{}.Frequency, Uint32 _InstanceDataStepRate=LayoutElement{}.InstanceDataStepRate) noexcept
Initializes the structure.
Definition: InputLayout.h:115
Diligent::LayoutElement::InputIndex
Uint32 InputIndex
Input index of the element that is specified in the vertex shader. In Direct3D11 and Direct3D12 backe...
Definition: InputLayout.h:73
Diligent::LayoutElement::IsNormalized
Bool IsNormalized
For signed and unsigned integer value types (VT_INT8, VT_INT16, VT_INT32, VT_UINT8,...
Definition: InputLayout.h:89
Diligent::LayoutElement::Frequency
enum INPUT_ELEMENT_FREQUENCY Frequency
Definition: InputLayout.h:103
Diligent::LayoutElement::LayoutElement
LayoutElement(const char *_HLSLSemantic, Uint32 _InputIndex, Uint32 _BufferSlot, Uint32 _NumComponents, VALUE_TYPE _ValueType, Bool _IsNormalized=LayoutElement{}.IsNormalized, Uint32 _RelativeOffset=LayoutElement{}.RelativeOffset, Uint32 _Stride=LayoutElement{}.Stride, INPUT_ELEMENT_FREQUENCY _Frequency=LayoutElement{}.Frequency, Uint32 _InstanceDataStepRate=LayoutElement{}.InstanceDataStepRate) noexcept
Initializes the structure.
Definition: InputLayout.h:136
DILIGENT_BEGIN_NAMESPACE
#define DILIGENT_BEGIN_NAMESPACE(Name)
Definition: CommonDefinitions.h:82
GraphicsTypes.h
Diligent::InputLayoutDesc::NumElements
Uint32 NumElements
Number of layout elements.
Definition: InputLayout.h:208
Diligent::VT_FLOAT32
@ VT_FLOAT32
Full-precision 32-bit floating point.
Definition: GraphicsTypes.h:59
Diligent::InputLayoutDesc::LayoutElements
const LayoutElement * LayoutElements
Array of layout elements.
Definition: InputLayout.h:206
Diligent::INPUT_ELEMENT_FREQUENCY
INPUT_ELEMENT_FREQUENCY
Input frequency.
Definition: InputLayout.h:47
Diligent::LayoutElement::RelativeOffset
Uint32 RelativeOffset
Relative offset, in bytes, to the element bits. If this value is set to LAYOUT_ELEMENT_AUTO_OFFSET (d...
Definition: InputLayout.h:94
Diligent::LayoutElement::ValueType
VALUE_TYPE ValueType
Type of the element components, see Diligent::VALUE_TYPE for details.
Definition: InputLayout.h:82
Diligent::LayoutElement::LayoutElement
LayoutElement(Uint32 _InputIndex, Uint32 _BufferSlot, Uint32 _NumComponents, VALUE_TYPE _ValueType, Bool _IsNormalized, INPUT_ELEMENT_FREQUENCY _Frequency, Uint32 _InstanceDataStepRate=LayoutElement{}.InstanceDataStepRate) noexcept
Initializes the structure.
Definition: InputLayout.h:159
Diligent::operator!=
bool operator!=(const STDAllocator< T, A > &left, const STDAllocator< U, A > &right)
Definition: STDAllocator.hpp:173
Diligent::InputLayoutDesc::InputLayoutDesc
InputLayoutDesc() noexcept
Definition: InputLayout.h:211
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37