VPP  0.7
A high-level modern C++ API for Vulkan
vpp::UniformStruct< TAG, TDef > Class Template Reference

Base class for uniform data structures. More...

#include <vppLangIntUniform.hpp>

Detailed Description

template<ETag TAG, template< vpp::ETag TAG > class TDef>
class vpp::UniformStruct< TAG, TDef >

Base class for uniform data structures.

Inherit from this class to define your uniform data structure template. The first template argument should be passed from your template. The second one should be the name of your template which is being derived.

Use UniformFld template to define fields inside the structure.

Instantiating the template with GPU tag argument gives GPU-side version of the structure, while CPU tag gives the host version. The CPU version can be directly used to fill data buffers meant to be transfered to GPU.

Unlike VertexStruct and InstanceStruct, CPU flavor of UniformStruct does not use Vulkan format to specify the data layout. You provide directly the data type. This is because Vulkan does not need to interpret uniform data as thoroughly as in case of vertex and instance streams.

Example of type definition:

template< ETag TAG >
struct TFramePar : public UniformStruct< TAG, TFramePar >
{
UniformFld< TAG, glm::mat4 > m_world2projected;
UniformFld< TAG, glm::mat4 > m_world2view;
UniformFld< TAG, glm::mat4 > m_view2projected;
UniformFld< TAG, glm::mat4 > m_projected2vport;
UniformFld< TAG, glm::mat4 > m_projected2world;
UniformFld< TAG, glm::mat4 > m_vport2world;
UniformFld< TAG, glm::mat4 > m_viewPosition;
};
typedef TFramePar< GPU > GFramePar;
typedef TFramePar< CPU > CFramePar;
// use this vector as a container and transport for the data
typedef gvector< CFramePar, Buf::UNIFORM > CFrameParBuffer;

The glm::mat4 type in the code above is an example of custom matrix data type. GLM types are supported by VPP. You can add your own types support by defining the StructMemberTraits template specializations.

Using the CPU-side flavor to create and fill the vector:

CFrameParBuffer frameParBuf ( 2, MemProfile::DEVICE_STATIC, hDevice );
frameParBuf [ 0 ].m_world2projected = glm::mat4 ( ... );
frameParBuf [ 0 ].m_world2view = glm::mat4 ( ... );
// ...

Example of CPU-side data binding for the defined type:

class MyPipeline : public PipelineConfig
{
public:
void bindBuffers (
ShaderDataBlock* pDataBlock,
const CFrameParBuffer& frameParBuf )
{
pDataBlock->update ( (
m_frameParBindingPoint = UniformBufferView ( frameParBuf )
) );
}
private:
inUniformBuffer m_frameParBindingPoint;
};

Inside shader code, use UniformVar or UniformArray to access the fields. The GPU-level type to represent the value is inferred from CPU-level type with help of StructMemberTraits specialization. In this case, VPP knows that GPU counterpart of glm::mat4 is Mat4.

Example:

// ....
UniformArray< TFramePar, inUniformBuffer > framePar ( m_frameParBindingPoint );
// Note that you use GFramePar member pointer here, as this is GPU code.
const Mat4 w2p = framePar [ 0 ][ & GFramePar::m_world2projected ];

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