NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
OpenGLVertexArray.cpp
Go to the documentation of this file.
1
#include "
Engine/Platform/OpenGL/OpenGLVertexArray.h
"
2
3
#include "
Engine/Renderer/Buffer.h
"
4
5
#include <glad/gl.h>
6
#include <cstdint>
7
8
namespace
NoJob
9
{
10
OpenGLVertexArray::OpenGLVertexArray
()
11
{
12
glCreateVertexArrays(1, &m_RendererID);
13
}
14
15
OpenGLVertexArray::~OpenGLVertexArray
()
16
{
17
glDeleteVertexArrays(1, &m_RendererID);
18
}
19
20
void
OpenGLVertexArray::Bind
()
const
21
{
22
glBindVertexArray(m_RendererID);
23
}
24
25
void
OpenGLVertexArray::Unbind
()
const
26
{
27
glBindVertexArray(0);
28
}
29
30
void
OpenGLVertexArray::SetVertexBuffer
(
31
const
std::shared_ptr<VertexBuffer>& vertexBuffer)
32
{
33
// Position-only layout retained for the editor grid.
34
SetVertexBuffer
(
35
vertexBuffer,
36
BufferLayout
{
37
{
ShaderDataType::Float3
,
"a_Position"
}
38
});
39
}
40
41
void
OpenGLVertexArray::SetVertexBuffer
(
42
const
std::shared_ptr<VertexBuffer>& vertexBuffer,
43
const
BufferLayout
& layout)
44
{
45
m_VertexBuffer = vertexBuffer;
46
47
Bind
();
48
vertexBuffer->Bind();
49
50
std::uint32_t index = 0;
51
52
for
(
const
BufferElement
& element : layout.
GetElements
())
53
{
54
glEnableVertexAttribArray(index);
55
56
glVertexAttribPointer(
57
index,
58
static_cast<
GLint
>
(element.GetComponentCount()),
59
GL_FLOAT,
60
element.Normalized ? GL_TRUE : GL_FALSE,
61
static_cast<
GLsizei
>
(layout.
GetStride
()),
62
reinterpret_cast<
const
void
*
>
(
63
static_cast<
std::uintptr_t
>
(element.Offset)));
64
65
++index;
66
}
67
}
68
69
void
OpenGLVertexArray::SetIndexBuffer
(
70
const
std::shared_ptr<IndexBuffer>& indexBuffer)
71
{
72
Bind
();
73
indexBuffer->Bind();
74
m_IndexBuffer = indexBuffer;
75
}
76
}
Buffer.h
Buffer declarations for the Rendering subsystem.
OpenGLVertexArray.h
OpenGLVertexArray declarations for the OpenGL Backend subsystem.
NoJob::BufferLayout
Definition
BufferLayout.h:71
NoJob::BufferLayout::GetElements
const std::vector< BufferElement > & GetElements() const
Definition
BufferLayout.h:81
NoJob::BufferLayout::GetStride
std::uint32_t GetStride() const
Definition
BufferLayout.h:86
NoJob::OpenGLVertexArray::Unbind
void Unbind() const override
Definition
OpenGLVertexArray.cpp:25
NoJob::OpenGLVertexArray::~OpenGLVertexArray
~OpenGLVertexArray() override
Definition
OpenGLVertexArray.cpp:15
NoJob::OpenGLVertexArray::Bind
void Bind() const override
Definition
OpenGLVertexArray.cpp:20
NoJob::OpenGLVertexArray::SetVertexBuffer
void SetVertexBuffer(const std::shared_ptr< VertexBuffer > &vertexBuffer) override
Definition
OpenGLVertexArray.cpp:30
NoJob::OpenGLVertexArray::SetIndexBuffer
void SetIndexBuffer(const std::shared_ptr< IndexBuffer > &indexBuffer) override
Definition
OpenGLVertexArray.cpp:69
NoJob::OpenGLVertexArray::OpenGLVertexArray
OpenGLVertexArray()
Definition
OpenGLVertexArray.cpp:10
NoJob
Definition
BTActionNode.h:13
NoJob::ShaderDataType::Float3
@ Float3
Definition
BufferLayout.h:20
NoJob::BufferElement
Definition
BufferLayout.h:37
Engine
Platform
OpenGL
OpenGLVertexArray.cpp
Generated by
1.18.0