Carna Version 3.3.3
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
Carna::base::PVertex Struct Reference

Defines simple-most vertex that only consists of a positional attribute. More...

#include <Vertex.h>

+ Inheritance diagram for Carna::base::PVertex:
+ Collaboration diagram for Carna::base::PVertex:

Public Member Functions

 VERTEX_NULL_COMPONENT (Normal)
 
 VERTEX_NULL_COMPONENT (Color)
 
- Public Member Functions inherited from Carna::base::VertexPosition
 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

- Public Attributes inherited from Carna::base::VertexPosition
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.
 

Detailed Description

Defines simple-most vertex that only consists of a positional attribute.

Custom Vertex Formats

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:

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
Author
Leonid Kostrykin
Date
1.9.14 - 10.3.15

Definition at line 276 of file Vertex.h.

Member Function Documentation

◆ VERTEX_NULL_COMPONENT() [1/2]

Carna::base::PVertex::VERTEX_NULL_COMPONENT ( Color  )

Declares missing component.

Since
API Version 3.2.0

◆ VERTEX_NULL_COMPONENT() [2/2]

Carna::base::PVertex::VERTEX_NULL_COMPONENT ( Normal  )

Declares missing component.

Since
API Version 3.2.0

Member Data Documentation

◆ attributes

const VertexAttributes Carna::base::PVertex::attributes
static

Holds the declaration of the vertex format.

Definition at line 282 of file Vertex.h.


The documentation for this struct was generated from the following file: