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

#include <gl_vertex_array.h>

Inheritance diagram for scl::gl_vertex_array:
scl::vertex_array

Public Member Functions

render_primitive::handle GetHandle () const override
 
void SetVertexBuffer (const shared< vertex_buffer > &VertexBuffer)
 
void SetIndexBuffer (const shared< index_buffer > &IndexBuffer)
 
 gl_vertex_array (mesh_type MeshType)
 
 ~gl_vertex_array ()
 
void Bind () const override
 
void Unbind () const override
 
- Public Member Functions inherited from scl::vertex_array
mesh_type GetType () const
 
const shared< vertex_buffer > & GetVertexBuffer () const
 
const shared< index_buffer > & GetIndexBuffer () const
 
virtual void SetVertexBuffer (const shared< vertex_buffer > &VertexBuffer)=0
 
virtual void SetIndexBuffer (const shared< index_buffer > &IndexBuffer)=0
 
 vertex_array (mesh_type MeshType)
 
virtual ~vertex_array ()=default
 
virtual void Bind () const =0
 
virtual void Unbind () const =0
 

Additional Inherited Members

- Static Public Member Functions inherited from scl::vertex_array
static shared< vertex_arrayCreate (mesh_type Mesh_type)
 
- Protected Attributes inherited from scl::vertex_array
mesh_type Type {}
 
shared< vertex_bufferVertexBuffer {}
 
shared< index_bufferIndexBuffer {}
 

Detailed Description

OpenGL vertex array class.

Definition at line 18 of file gl_vertex_array.h.

Constructor & Destructor Documentation

◆ gl_vertex_array()

scl::gl_vertex_array::gl_vertex_array ( mesh_type  MeshType)
  • Vertex buffer default constructor.
Parameters
Type- creating mesh type.
VertexBuffer- vertex buffer to be linked to vertex array.
IndexBuffer- index array to be linked to vertex array.

Definition at line 111 of file gl_vertex_array.cpp.

111 :
112 vertex_array(MeshType)
113{
114 glCreateVertexArrays(1, &Id);
115 SCL_CORE_ASSERT(Id != 0, "Vertex array OpenGL primitive creation error.");
116 SCL_CORE_SUCCES("OpenGL Vertex array with id {} created.", Id);
117}
#define SCL_CORE_ASSERT(expr,...)
Definition: assert.h:69
vertex_array(mesh_type MeshType)
#define SCL_CORE_SUCCES(...)
Definition: log.h:42

◆ ~gl_vertex_array()

scl::gl_vertex_array::~gl_vertex_array ( )

Default destructor.

Definition at line 119 of file gl_vertex_array.cpp.

120{
121 glDeleteVertexArrays(1, &Id);
122 SCL_CORE_INFO("OpenGL Vertex array with id {} freed.", Id);
123}
#define SCL_CORE_INFO(...)
Definition: log.h:41

Member Function Documentation

◆ Bind()

void scl::gl_vertex_array::Bind ( ) const
overridevirtual
  • Bind vertex array to current render stage function.
Parameters
None.
Returns
None.

Implements scl::vertex_array.

Definition at line 125 of file gl_vertex_array.cpp.

126{
127 glBindVertexArray(Id);
128}

◆ GetHandle()

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

Vertex array methods.

Backend api render primitive hadnle getter function.

Definition at line 33 of file gl_vertex_array.h.

33{ return Id; }

◆ SetIndexBuffer()

void scl::gl_vertex_array::SetIndexBuffer ( const shared< index_buffer > &  IndexBuffer)
virtual

Link index buffer to vertex array function.

Implements scl::vertex_array.

Definition at line 102 of file gl_vertex_array.cpp.

103{
104 this->IndexBuffer = IndexBuffer;
105 this->Bind();
106 IndexBuffer->Bind();
107 this->Unbind();
108 IndexBuffer->Unbind();
109}
void Unbind() const override
void Bind() const override
shared< index_buffer > IndexBuffer
Definition: vertex_array.h:32

◆ SetVertexBuffer()

void scl::gl_vertex_array::SetVertexBuffer ( const shared< vertex_buffer > &  VertexBuffer)
virtual

Link vertex buffer to vertex array function.

Implements scl::vertex_array.

Definition at line 38 of file gl_vertex_array.cpp.

39{
40 SCL_CORE_ASSERT(VertexBuffer->GetVertexLayout().GetCount() != 0,
41 "Vertex Buffer has no layout!");
42
44 this->Bind();
45 VertexBuffer->Bind();
46
47 const auto &layout = VertexBuffer->GetVertexLayout();
48 for (const auto &element : layout)
49 {
50 switch (element.Type)
51 {
57 glEnableVertexAttribArray(element.Index);
58 glVertexAttribIPointer(element.Index,
60 GetGLShaderVariableType(element.Type),
61 layout.GetSize(),
62 (const void *)(u64)element.Offset);
63 break;
68 glEnableVertexAttribArray(element.Index);
69 glVertexAttribPointer(element.Index,
71 GetGLShaderVariableType(element.Type),
72 GL_FALSE,
73 layout.GetSize(),
74 (const void *)(u64)element.Offset);
75 break;
77 {
79 for (uint8_t i = 0; i < count; i++)
80 {
81 glEnableVertexAttribArray(element.Index);
82 glVertexAttribPointer(element.Index,
83 count,
84 GetGLShaderVariableType(element.Type),
85 GL_FALSE,
86 layout.GetSize(),
87 (const void *)(element.Offset + sizeof(float) * count * i));
88 glVertexAttribDivisor(element.Index, 1);
89 }
90 break;
91 }
92 default:
93 SCL_CORE_ASSERT(0, "Unknown element type!");
94 break;
95 }
96 }
97
98 VertexBuffer->Unbind();
99 this->Unbind();
100}
static u32 GetShaderVariableComponentsCount(shader_variable_type Type)
shared< vertex_buffer > VertexBuffer
Definition: vertex_array.h:31
uint32_t u32
Definition: math_common.h:21
uint64_t u64
Definition: math_common.h:23

◆ Unbind()

void scl::gl_vertex_array::Unbind ( ) const
overridevirtual
  • Unbind vertex array from current render stage function.
Parameters
None.
Returns
None.

Implements scl::vertex_array.

Definition at line 130 of file gl_vertex_array.cpp.

131{
132 glBindVertexArray(0);
133}

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