Carna  Version 3.0.1
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Carna::base::VertexBase Struct Reference

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

#include <Vertex.h>

+ Inheritance diagram for Carna::base::VertexBase:

Public Member Functions

 VertexBase ()
 Initializes position to \(\left(0, 0, 0, 1\right)\).
 

Public Attributes

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.
 

Static Public Attributes

static const VertexAttributes attributes
 Holds the declaration of the vertex format.
 

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:

struct VertexTexCoord2
{
float u, v;
};

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:

using namespace Carna::base;
struct LightedTexturedVertex
: public VertexBase
, public VertexNormal
, public VertexTexCoord2
{
};

The order of the base classes is arbitrary, but it must be consistent with what comes next, namely the specification of the vertex format.

#include <vector>
using namespace Carna::base;
const VertexAttributes LightedTexturedVertex::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;
}();

You should read the above like:

When writing your shader, you must declare the vertex format consistently:

layout( location = 0 ) in vec4 inPosition;
layout( location = 1 ) in vec4 inNormal;
layout( location = 2 ) in vec2 inTexCoord;
Author
Leonid Kostrykin
Date
1.9.14 - 10.3.15

Definition at line 108 of file Vertex.h.


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