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

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

#include <Vertex.hpp>

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

Public Member Functions

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

{
float u, v;
};
Represents an association.

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 LibCarna::base;
struct PNT2Vertex // P for Position, N for Normal, T2 for TexCoord2
: public VertexPosition
, public VertexNormal
, public VertexTexCoord2
{
static const VertexAttributes attributes;
};
Contains the core framework components.
std::vector< VertexAttribute > VertexAttributes
Defines VertexAttribute vector.
Defines vertex component for normal vectors. Usage is explained here.
Definition Vertex.hpp:94
Defines vertex component for position vectors. Usage is explained here.
Definition Vertex.hpp:46

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 LibCarna::base;
const VertexAttributes PNT2Vertex::attributes = []()->VertexAttributes
{
using LibCarna::base::VertexAttribute; // msvc++ requires us to repeat this
std::vector< VertexAttribute > attributes;
return attributes;
}();
static const VertexAttributes attributes
Holds the declaration of the vertex format.
Definition Vertex.hpp:279
Declares a vertex attribute.
static const unsigned int TYPE_FLOAT
Indicates vertex attribute of GL_FLOAT type.

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

Definition at line 273 of file Vertex.hpp.

Member Function Documentation

◆ VERTEX_NULL_COMPONENT() [1/2]

LibCarna::base::PVertex::VERTEX_NULL_COMPONENT ( Color  )

Declares missing component.

◆ VERTEX_NULL_COMPONENT() [2/2]

LibCarna::base::PVertex::VERTEX_NULL_COMPONENT ( Normal  )

Declares missing component.

Member Data Documentation

◆ attributes

const VertexAttributes LibCarna::base::PVertex::attributes
static

Holds the declaration of the vertex format.

Definition at line 279 of file Vertex.hpp.


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