![]() |
Carna Version 3.3.3
|
Defines simple-most vertex that only consists of a positional attribute. More...
#include <Vertex.h>
Public Member Functions | |
VERTEX_NULL_COMPONENT (Normal) | |
VERTEX_NULL_COMPONENT (Color) | |
![]() | |
VertexPosition () | |
template<typename VectorType > | |
void | setPosition (const VectorType &position) |
Static Public Attributes | |
static const VertexAttributes | attributes |
Holds the declaration of the vertex format. | |
Additional Inherited Members | |
![]() | |
float | x |
Holds the positional x-component of this vertex. | |
float | y |
Holds the positional y-component of this vertex. | |
float | z |
Holds the positional z-component of this vertex. | |
float | w |
Holds the positional w-component of this vertex. This will be 1 usually. | |
Defines simple-most vertex that only consists of a positional attribute.
It is easy to define custom vertex formats. The procedure is best explained with an example. Lets assume you want to define a vertex that has additional properties for normal vectors and 2D texture coordinates.
The first step is to define the missing vertex components. The VertexNormal type already provides a vertex component for normal vectors, so lets define a component for 2D texture coordinates:
\code struct VertexTexCoord2 { float u, v; }; \endcode
It is necessary that a vertex component is implemented as a POD, i.e. plain old data type. Virtual methods would mess up the memory layout. However, you might define a constructor that initializes default values, if you wanted.
The next step is to compose the vertex format:
\code using namespace Carna::base; struct PNT2Vertex // P for Position, N for Normal, T2 for TexCoord2 : public VertexPosition , public VertexNormal , public VertexTexCoord2 { static const VertexAttributes attributes; }; \endcode
The order of the base classes is arbitrary, but it must be consistent with what comes next, namely the specification of the vertex format.
\code #include <vector> using namespace Carna::base; const VertexAttributes PNT2Vertex::attributes = []()->VertexAttributes { using Carna::base::VertexAttribute; // msvc++ requires us to repeat this std::vector< VertexAttribute > attributes; attributes.push_back( VertexAttribute( 0, 4, VertexAttribute::TYPE_FLOAT ) ); attributes.push_back( VertexAttribute( 4, 4, VertexAttribute::TYPE_FLOAT ) ); attributes.push_back( VertexAttribute( 8, 2, VertexAttribute::TYPE_FLOAT ) ); return attributes; }(); \endcode
You should read the above like:
x
, y
, z
, w
.nx
, ny
, nz
, nw
of the normal vector.u
, v
of the texture coordinates vector.When writing your shader, you must declare the vertex format consistently:
\code layout( location = 0 ) in vec4 inPosition; layout( location = 1 ) in vec4 inNormal; layout( location = 2 ) in vec2 inTexCoord; \endcode
Carna::base::PVertex::VERTEX_NULL_COMPONENT | ( | Color | ) |
Declares missing component.
Carna::base::PVertex::VERTEX_NULL_COMPONENT | ( | Normal | ) |
Declares missing component.
|
static |
Holds the declaration of the vertex format.
Documentation generated by Doxygen