NoJobEngine 2.0.7
Loading...
Searching...
No Matches
OpenGLVertexArray.cpp
Go to the documentation of this file.
2
4
5#include <glad/gl.h>
6#include <cstdint>
7
8namespace NoJob
9{
11 {
12 glCreateVertexArrays(1, &m_RendererID);
13 }
14
16 {
17 glDeleteVertexArrays(1, &m_RendererID);
18 }
19
21 {
22 glBindVertexArray(m_RendererID);
23 }
24
26 {
27 glBindVertexArray(0);
28 }
29
31 const std::shared_ptr<VertexBuffer>& vertexBuffer)
32 {
33 // Position-only layout retained for the editor grid.
35 vertexBuffer,
37 { ShaderDataType::Float3, "a_Position" }
38 });
39 }
40
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
70 const std::shared_ptr<IndexBuffer>& indexBuffer)
71 {
72 Bind();
73 indexBuffer->Bind();
74 m_IndexBuffer = indexBuffer;
75 }
76}
Buffer declarations for the Rendering subsystem.
OpenGLVertexArray declarations for the OpenGL Backend subsystem.
const std::vector< BufferElement > & GetElements() const
std::uint32_t GetStride() const
void Unbind() const override
void Bind() const override
void SetVertexBuffer(const std::shared_ptr< VertexBuffer > &vertexBuffer) override
void SetIndexBuffer(const std::shared_ptr< IndexBuffer > &indexBuffer) override