sculpto
Public Member Functions | List of all members
scl::gl_constant_buffer Class Reference

#include <gl_buffer.h>

Inheritance diagram for scl::gl_constant_buffer:
scl::constant_buffer

Public Member Functions

render_primitive::handle GetHandle () const override
 
 gl_constant_buffer (u32 Size)
 
 gl_constant_buffer (const void *Data, u32 Size)
 
 ~gl_constant_buffer () override
 
void Bind (u32 BindingPoint) const override
 
void Unbind () const override
 
void Update (void *Data, u32 Size) override
 
void Free () override
 
- Public Member Functions inherited from scl::constant_buffer
virtual ~constant_buffer ()=default
 
virtual void Bind (u32 BindingPoint) const =0
 
virtual void Unbind () const =0
 
virtual void Update (void *Data, u32 Size)=0
 
virtual void Free ()=0
 

Additional Inherited Members

- Static Public Member Functions inherited from scl::constant_buffer
static shared< constant_bufferCreate (u32 Size)
 
static shared< constant_bufferCreate (const void *Data, u32 Size)
 

Detailed Description

Constant (uniform) buffer class.

Definition at line 17 of file gl_buffer.h.

Constructor & Destructor Documentation

◆ gl_constant_buffer() [1/2]

scl::gl_constant_buffer::gl_constant_buffer ( u32  Size)
  • Constant (uniform) empty buffer constructor.
Parameters
BindingPoint- shader_props binding point of buffer.
Size- buffer data size.

Definition at line 12 of file gl_buffer.cpp.

13{
14 this->Size = Size;
15
16 glGenBuffers(1, &Id);
17 glBindBuffer(GL_UNIFORM_BUFFER, Id);
18 glBufferData(GL_UNIFORM_BUFFER, Size, nullptr, GL_STATIC_DRAW);
19 glBindBuffer(GL_UNIFORM_BUFFER, 0);
20
21 SCL_CORE_SUCCES("OpenGL Constant buffer with id {} and size {} created.", Id, Size);
22}
#define SCL_CORE_SUCCES(...)
Definition: log.h:42

◆ gl_constant_buffer() [2/2]

scl::gl_constant_buffer::gl_constant_buffer ( const void *  Data,
u32  Size 
)
  • Constant (uniform) buffer filled with data constructor.
Parameters
BindingPoint- shader_props binding point of buffer.
Data- buffer data pointer.
Size- buffer data size.

Definition at line 24 of file gl_buffer.cpp.

25{
26 this->Size = Size;
27
28 glGenBuffers(1, &Id);
29 glBindBuffer(GL_UNIFORM_BUFFER, Id);
30 glBufferData(GL_UNIFORM_BUFFER, Size, Data, GL_STATIC_DRAW);
31 glBindBuffer(GL_UNIFORM_BUFFER, 0);
32
33 SCL_CORE_SUCCES("OpenGL Constant buffer with id {} and size {} created.", Id, Size);
34}

◆ ~gl_constant_buffer()

scl::gl_constant_buffer::~gl_constant_buffer ( )
override

Constant buffer default destructor.

Definition at line 36 of file gl_buffer.cpp.

37{
38 Free();
39}
void Free() override
Definition: gl_buffer.cpp:65

Member Function Documentation

◆ Bind()

void scl::gl_constant_buffer::Bind ( u32  BindingPoint) const
overridevirtual
  • Bind buffer to current render stage function.
Parameters
None.
Returns
None.

Implements scl::constant_buffer.

Definition at line 41 of file gl_buffer.cpp.

42{
43 this->BindingPoint = BindingPoint;
44 if (Id != 0) glBindBufferBase(GL_UNIFORM_BUFFER, BindingPoint, Id);
45}

◆ Free()

void scl::gl_constant_buffer::Free ( )
overridevirtual
  • Clear buffer from GPU memory function.
Parameters
None.
Returns
None.

Implements scl::constant_buffer.

Definition at line 65 of file gl_buffer.cpp.

66{
67 if (Id != 0)
68 {
69 glDeleteBuffers(1, &Id);
70
71 SCL_CORE_INFO("OpenGL Constant buffer with id {} freed.", Id);
72 Id = 0, BindingPoint = 0, Size = 0;
73 }
74}
#define SCL_CORE_INFO(...)
Definition: log.h:41

◆ GetHandle()

render_primitive::handle scl::gl_constant_buffer::GetHandle ( ) const
inlineoverride

Backend api render primitive hadnle getter function.

Definition at line 26 of file gl_buffer.h.

26{ return Id; }

◆ Unbind()

void scl::gl_constant_buffer::Unbind ( ) const
overridevirtual
  • Unbind buffer from current render stage function.
Parameters
None.
Returns
None.

Implements scl::constant_buffer.

Definition at line 47 of file gl_buffer.cpp.

48{
49 glBindBufferBase(GL_UNIFORM_BUFFER, BindingPoint, 0);
50 this->BindingPoint = 0;
51}

◆ Update()

void scl::gl_constant_buffer::Update ( void *  Data,
u32  Size 
)
overridevirtual
  • Update buffer data function.
Parameters
Data- buffer data pointer.
Size- buffer data size.
Returns
None.

Implements scl::constant_buffer.

Definition at line 53 of file gl_buffer.cpp.

54{
55 if (Id != 0)
56 {
57 SCL_CORE_ASSERT(this->Size == Size, "Constant buffer size can't be changed.");
58
59 glBindBuffer(GL_UNIFORM_BUFFER, Id);
60 glBufferSubData(GL_UNIFORM_BUFFER, 0, Size, Data);
61 glBindBuffer(GL_UNIFORM_BUFFER, 0);
62 }
63}
#define SCL_CORE_ASSERT(expr,...)
Definition: assert.h:69

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