NAP
Public Member Functions | Public Attributes | Protected Attributes | List of all members
BufferBinding Class Reference

#include <bufferbinding.h>

Public Member Functions

virtual bool init (utility::ErrorState &errorState) override
 
virtual int getCount () const
 
virtual size_t getSize () const
 
const GPUBuffergetBuffer () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

std::string mName
 Property: 'Name' name of buffer binding uniform in shader. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Protected Attributes

const GPUBuffermBuffer = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Buffer Binding resource base class.

Buffer bindings, unlike uniforms, store a reference to the underlying data as opposed to the data itself. This allows for any compute shader to read from and write to the same data storage. Buffer bindings always refer to a single nap::GPUBuffer, whether this is simple a nap::VertexBufferVec4 or a more complex nap::StructGPUBuffer.

A single vec4 array can be addressed as a nap::VertexBufferVec4:

layout(std430) buffer PositionSSBO
{
vec4 positions[100000];
} pos_ssbo;
layout(std430) buffer NormalSSBO
{
vec4 normals[100000];
} norm_ssbo;

If you intend to pack some data types together, you can do so with a nap::StructGPUBuffer:

struct Item
{
vec4 position;
vec4 normal;
};
layout(std430) buffer ItemSSBO
{
Item items[100000];
} item_ssbo;

Declaring multiple shader variables outside of a struct is currently not supported:

// ERROR
layout(std430) buffer ExampleComputeBuffer
{
vec4 positions[100000];
vec4 normals[100000];
};
Inheritance diagram for BufferBinding:
[legend]
Collaboration diagram for BufferBinding:
[legend]

Member Function Documentation

◆ getBuffer()

const GPUBuffer* getBuffer ( ) const
Returns
the base GPU buffer, nullptr if not set

◆ getCount()

virtual int getCount ( ) const
virtual
Returns
The number of elements in this array

◆ getSize()

virtual size_t getSize ( ) const
virtual
Returns
The size in bytes

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Ensures the buffer is set.

Parameters
errorStatecontains the error if the binding can't be initialized
Returns
if the binding initialized

Reimplemented from Object.

Reimplemented in BufferBindingStruct, BufferBindingNumeric, and TypedBufferBindingNumeric< T >.

Member Data Documentation

◆ mBuffer

const GPUBuffer* mBuffer = nullptr
protected

◆ mName

std::string mName

Property: 'Name' name of buffer binding uniform in shader.