sculpto
Main Page
Namespaces
Classes
Files
File List
File Members
core
resources
vertex.h
Go to the documentation of this file.
1
/*!****************************************************************/
/*!*
2
* \file vertex.h
3
* \brief Vertex description and storage classes definition module.
4
*
5
* \author Sabitov Kirill
6
* \date 28 June 2022
7
*********************************************************************/
8
9
#pragma once
10
11
#include "
core/render/render_context.h
"
12
13
namespace
scl
14
{
16
struct
vertex_element
17
{
19
shader_variable_type
Type
;
20
u32
Size
;
21
u32
Index
;
22
u32
Offset
;
24
/*!*
25
* Vertex element default constrictor.
26
*
27
* \param Type - vertex element data type.
28
* \param Index - vertex element index in vertex layer.
29
* \param Offset - vertex element offset by vertex layer start pointer.
30
*/
31
vertex_element
(
shader_variable_type
Type
,
const
std::string &Name) :
32
Type
(
Type
),
Size
(
render_context
::GetShaderVariableTypeSize(
Type
)),
Index
(-1),
Offset
(-1) {}
33
};
34
36
class
vertex_layout
37
{
38
protected
:
39
std::vector<vertex_element>
Elements
{};
40
u32
Size
{};
41
42
public
:
44
const
std::vector<vertex_element> &
GetElements
()
const
{
return
Elements
; }
46
u32
GetSize
()
const
{
return
Size
; }
48
size_t
GetCount
()
const
{
return
Elements
.size(); }
49
50
std::vector<vertex_element>::iterator
begin
() {
return
Elements
.begin(); }
51
std::vector<vertex_element>::iterator
end
() {
return
Elements
.end(); }
52
std::vector<vertex_element>::const_iterator
begin
()
const
{
return
Elements
.begin(); }
53
std::vector<vertex_element>::const_iterator
end
()
const
{
return
Elements
.end(); }
54
55
public
:
57
vertex_layout
() =
default
;
58
59
/*!*
60
* Vertex layout default constructor.
61
*
62
* \param Elements - array of vertex layout elements.
63
*/
64
vertex_layout
(
const
std::initializer_list<vertex_element> &
Elements
) :
65
Elements
(
Elements
)
66
{
67
// Calculating index and offset of each element
68
u32
offset = 0;
69
for
(
int
i = 0; i <
Elements
.size(); i++)
70
{
71
this->Elements[i].Index = i;
72
this->Elements[i].Offset = offset;
73
offset += this->Elements[i].Size;
74
}
75
Size
= offset;
76
}
77
};
78
80
struct
vertex
81
{
82
vec3
Position
{};
83
vec3
Normal
{};
84
vec3
Tangent
{};
85
vec3
Bitangent
{};
86
vec2
TexCoords
{};
89
vertex
() =
default
;
90
91
/*!*
92
* Veretex contructor by texture coordinates.
93
* It is implied that the color attribute will not be used.
94
*
95
* \param Position - vertex position.
96
* \param Normal - vertex surface normal.
97
* \param Tangent, Bitangent - vertex surface tangent space basis vectors.
98
* \param TexCoords - vertex texture coordinates.
99
*/
100
vertex
(
const
vec3
&
Position
,
const
vec3
&
Normal
,
const
vec3
&
Tangent
,
const
vec3
&
Bitangent
,
const
vec2
&
TexCoords
) :
101
Position
(
Position
),
Normal
(
Normal
),
TexCoords
(
TexCoords
),
Tangent
(
Tangent
),
Bitangent
(
Bitangent
) {}
102
103
/*!*
104
* Veretex contructor by texture coordinates.
105
* It is implied that the color attribute will not be used.
106
*
107
* \param Position - vertex position.
108
* \param Normal - vertex surface normal.
109
* \param TexCoords - vertex texture coordinates.
110
*/
111
vertex
(
const
vec3
&
Position
,
const
vec3
&
Normal
,
const
vec2
&
TexCoords
) :
112
Position
(
Position
),
Normal
(
Normal
),
TexCoords
(
TexCoords
) {}
113
114
/*!*
115
* Vertex layout, describing all vertex atributes getter function.
116
*
117
* \param None.
118
* \return vertex layout.
119
*/
120
static
vertex_layout
GetVertexLayout
()
121
{
122
return
vertex_layout
({
123
{
shader_variable_type::FLOAT3
,
"Position"
},
124
{
shader_variable_type::FLOAT3
,
"Normal"
},
125
{
shader_variable_type::FLOAT3
,
"Tangent"
},
126
{
shader_variable_type::FLOAT3
,
"Bitangent"
},
127
{
shader_variable_type::FLOAT2
,
"TexCoord"
},
128
});
129
};
130
};
131
133
struct
vertex_point
134
{
135
vec3
Position
{};
136
vec3
Color
{};
139
vertex_point
() =
default
;
140
141
/*!*
142
* Veretex contructor by texture coordinates.
143
* It is implied that the color attribute will not be used.
144
*
145
* \param Position - vertex position.
146
* \param Normal - vertex surface normal.
147
* \param TexCoords - vertex texture coordinates.
148
*/
149
vertex_point
(
const
vec3
&
Position
,
const
vec3
&
Color
) :
150
Position
(
Position
),
Color
(
Color
) {}
151
152
/*!*
153
* Vertex layout, describing all vertex atributes getter function.
154
*
155
* \param None.
156
* \return vertex layout.
157
*/
158
static
vertex_layout
GetVertexLayout
()
159
{
160
return
vertex_layout
({
161
{
shader_variable_type::FLOAT3
,
"Position"
},
162
{
shader_variable_type::FLOAT3
,
"Color"
},
163
});
164
};
165
};
166
}
scl::math::vec2< float >
scl::math::vec3< float >
scl::render_context
Definition:
render_context.h:55
scl::vertex_layout
Definition:
vertex.h:37
scl::vertex_layout::Size
u32 Size
Definition:
vertex.h:40
scl::vertex_layout::GetSize
u32 GetSize() const
Definition:
vertex.h:46
scl::vertex_layout::vertex_layout
vertex_layout()=default
scl::vertex_layout::end
std::vector< vertex_element >::const_iterator end() const
Definition:
vertex.h:53
scl::vertex_layout::begin
std::vector< vertex_element >::iterator begin()
Definition:
vertex.h:50
scl::vertex_layout::vertex_layout
vertex_layout(const std::initializer_list< vertex_element > &Elements)
Definition:
vertex.h:64
scl::vertex_layout::begin
std::vector< vertex_element >::const_iterator begin() const
Definition:
vertex.h:52
scl::vertex_layout::GetCount
size_t GetCount() const
Definition:
vertex.h:48
scl::vertex_layout::GetElements
const std::vector< vertex_element > & GetElements() const
Definition:
vertex.h:44
scl::vertex_layout::Elements
std::vector< vertex_element > Elements
Definition:
vertex.h:39
scl::vertex_layout::end
std::vector< vertex_element >::iterator end()
Definition:
vertex.h:51
scl
Definition:
base.h:33
scl::shader_variable_type
shader_variable_type
Definition:
render_context.h:24
scl::shader_variable_type::FLOAT3
@ FLOAT3
scl::shader_variable_type::FLOAT2
@ FLOAT2
scl::u32
uint32_t u32
Definition:
math_common.h:21
render_context.h
Base, abstract, backend render api independent render context class implementation module.
scl::vertex_element
Definition:
vertex.h:17
scl::vertex_element::Offset
u32 Offset
Definition:
vertex.h:22
scl::vertex_element::Size
u32 Size
Definition:
vertex.h:20
scl::vertex_element::vertex_element
vertex_element(shader_variable_type Type, const std::string &Name)
Definition:
vertex.h:31
scl::vertex_element::Type
shader_variable_type Type
Definition:
vertex.h:19
scl::vertex_element::Index
u32 Index
Definition:
vertex.h:21
scl::vertex_point
Definition:
vertex.h:134
scl::vertex_point::vertex_point
vertex_point(const vec3 &Position, const vec3 &Color)
Definition:
vertex.h:149
scl::vertex_point::GetVertexLayout
static vertex_layout GetVertexLayout()
Definition:
vertex.h:158
scl::vertex_point::Position
vec3 Position
Definition:
vertex.h:135
scl::vertex_point::Color
vec3 Color
Definition:
vertex.h:136
scl::vertex_point::vertex_point
vertex_point()=default
scl::vertex
Definition:
vertex.h:81
scl::vertex::vertex
vertex()=default
scl::vertex::vertex
vertex(const vec3 &Position, const vec3 &Normal, const vec3 &Tangent, const vec3 &Bitangent, const vec2 &TexCoords)
Definition:
vertex.h:100
scl::vertex::GetVertexLayout
static vertex_layout GetVertexLayout()
Definition:
vertex.h:120
scl::vertex::vertex
vertex(const vec3 &Position, const vec3 &Normal, const vec2 &TexCoords)
Definition:
vertex.h:111
scl::vertex::Normal
vec3 Normal
Definition:
vertex.h:83
scl::vertex::Bitangent
vec3 Bitangent
Definition:
vertex.h:85
scl::vertex::Position
vec3 Position
Definition:
vertex.h:82
scl::vertex::TexCoords
vec2 TexCoords
Definition:
vertex.h:86
scl::vertex::Tangent
vec3 Tangent
Definition:
vertex.h:84
Generated by
1.9.4