VPP  0.7
A high-level modern C++ API for Vulkan
Public Member Functions | List of all members
vpp::inVertexData< TDef > Struct Template Reference

Binding point class for vertex and instance input to shaders. Place in your pipeline configuration class to declare a vertex or instance data source. More...

#include <vppLangIntVertex.hpp>

Public Member Functions

auto operator= (const VertexBufferView &hVertexBufferView)
 CPU-side binding operator. Use to bind actual data buffer to the binding point. More...
 
template<typename MemberT >
auto operator[] (MemberT YourDefinition::*pMember) const
 GPU-side access operator. Use to read a field (Attribute) in the shader. More...
 

Detailed Description

template<template< vpp::ETag TAG > class TDef>
struct vpp::inVertexData< TDef >

Binding point class for vertex and instance input to shaders. Place in your pipeline configuration class to declare a vertex or instance data source.

Specify the name of your vertex or instance data structure template as the argument. Accepts templates derived both from VertexStruct and InstanceStruct.

This class should be used only to define a binding point inside your custom pipeline configuration (a PipelineConfig subclass).

Vertex and instance data has exactly the same syntax, except for the structure definition (VertexStruct vs InstanceStruct).

An example:

template< vpp::ETag TAG = CPU >
struct TVertexPos : public vpp::VertexStruct< TAG, TVertexPos >
{
};
typedef TVertexPos< vpp::CPU > KVertexPos;
typedef TVertexPos< vpp::GPU > GVertexPos;
template< ETag TAG >
struct TInstancePar : public InstanceStruct< TAG, TInstancePar >
{
};
typedef TInstancePar< vpp::CPU > CInstancePar;
typedef TInstancePar< vpp::GPU > GInstancePar;
class MyPipelineConfig : public vpp::PipelineConfig
{
// ...
// this defines the binding point
void bindInstances (
const vpp::VertexBufferView& inst )
{
// Helper method to bind actual instance buffer view to binding point
// Call this method from your rendering sequence in render graph.
cmdBindVertexInput (( m_inInstanceData = inst ));
}
void bindVertices (
const vpp::VertexBufferView& vert,
{
// Helper method to bind actual vertex buffer views to binding points.
// Call this method from your rendering sequence in render graph.
cmdBindVertexInput (( m_inVertexData = vert ));
cmdBindIndexInput ( ind );
}
void fVertexShader ( vpp::VertexShader* pShader )
{
using namespace vpp;
// ...
// This vertex shader processes one vertex from m_inVertexData
// a time. It can access the data as presented below. The data
// is read-only.
// read the value of m_modelPosition attribute for current vertex.
Vec4 vpos = m_inVertexData [ & GVertexPos::m_modelPosition ];
// The vertex shader also processes one instance a time. Usually
// a number of vertices is associated with single instance. Therefore
// the call below will read the same value for some vertices, until
// they run out and the next instance is loaded.
// read the value of m_model2world attribute for current instance.
Mat4 modelMatrix = m_inInstanceData [ & GInstancePar::m_model2world ];
}
};

Member Function Documentation

◆ operator=()

template<template< vpp::ETag TAG > class TDef>
auto vpp::inVertexData< TDef >::operator= ( const VertexBufferView hVertexBufferView)

CPU-side binding operator. Use to bind actual data buffer to the binding point.

This operator returns a value that must be passed to cmdBindVertexInput method of PipelineConfig class. You can also make a list of more assignments, joining them with comma operator. The cmdBindVertexInput method accepts such a list.

The cmdBindVertexInput and cmdBindIndexInput are meant to be used mainly inside the rendering sequence within render graph (lambda function supplied to the Process object). They generate Vulkan commands into default command buffer. Actual binding of the vertex and instance data occurs at command execution time.

The example below also shows how to bind index data for indexed draws. It is very similar to vertex data, but indices do not need to have explicitly defined binding point. The binding point for indices is implicitly provided by each PipelineConfig instance.

Example:

class MyPipelineConfig : public vpp::PipelineConfig
{
// ...
// this defines the binding point
void bindVertices (
const vpp::VertexBufferView& vert,
{
// Helper method to bind actual vertex buffer views to binding points
// call this method from your rendering sequence in render graph.
cmdBindVertexInput (( m_inVertexData = vert ));
cmdBindIndexInput ( ind );
}
};

Another example for multiple vertex buffers:

class MyPipelineConfig : public vpp::PipelineConfig
{
// ...
void bindVertices (
const vpp::VertexBufferView& vertPos,
const vpp::VertexBufferView& verAttr,
{
cmdBindVertexInput ((
m_inVertexPosData = vertPos,
m_inVertexAttrData = vertAttr
));
cmdBindIndexInput ( ind );
}
};

◆ operator[]()

template<template< vpp::ETag TAG > class TDef>
template<typename MemberT >
auto vpp::inVertexData< TDef >::operator[] ( MemberT YourDefinition::*  pMember) const

GPU-side access operator. Use to read a field (Attribute) in the shader.

Supply a member pointer to the attribute (inside GPU level version of the structure) which you wish to read.

This operator returns a R-value of appropriate GPU-side type, corresponding to the format of the attribute.

Example:

template< vpp::ETag TAG = CPU >
struct TVertexPos : public vpp::VertexStruct< TAG, TVertexPos >
{
};
typedef TVertexPos< vpp::CPU > KVertexPos;
typedef TVertexPos< vpp::GPU > GVertexPos;
class MyPipelineConfig : public vpp::PipelineConfig
{
// ...
void fVertexShader ( vpp::VertexShader* pShader )
{
using namespace vpp;
// ...
// This vertex shader processes one vertex from m_inVertexData
// a time. It can access the data as presented below. The data
// is read-only.
// read the value of m_modelPosition attribute for current vertex
Vec4 vpos = m_inVertexData [ & GVertexPos::m_modelPosition ];
}
};

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