HPC_Voxel_Engine 0.2.0
High-Performance C++ Voxel Engine
Loading...
Searching...
No Matches
VertexArray.h
Go to the documentation of this file.
1#pragma once
2#include <glad/glad.h>
3#include "Buffer.h"
4#include "IndexBuffer.h"
5
6namespace Renderer {
7
14public:
15 unsigned int m_RendererID;
16
17 VertexArray() { glCreateVertexArrays(1, &m_RendererID); }
18 ~VertexArray() { glDeleteVertexArrays(1, &m_RendererID); }
19
20 VertexArray(const VertexArray &) = delete;
21 VertexArray &operator=(const VertexArray &) = delete;
22
23 void Bind() const { glBindVertexArray(m_RendererID); }
24 void Unbind() const { glBindVertexArray(0); }
25
34 void LinkAttribute(const VertexBuffer &vbo,
35 unsigned int iLayoutIndex,
36 int iNumComponents,
37 int iStride,
38 int iOffset) const {
39 // 1. Enable the attribute index on the VAO explicitly
40 glEnableVertexArrayAttrib(m_RendererID, iLayoutIndex);
41
42 // 2. Specify the FORMAT of the data (Components, Type, Normalized, Relative Offset)
43 glVertexArrayAttribFormat(m_RendererID,
44 iLayoutIndex,
45 iNumComponents,
46 GL_FLOAT,
47 GL_FALSE,
48 static_cast<GLuint>(iOffset * sizeof(float)));
49
50 // 3. Attach the VBO to a "Binding Point" on the VAO.
51 // We use iLayoutIndex as the binding point index for simplicity.
52 // Signature: (VAO_ID, BindingIndex, VBO_ID, BufferStartOffset, Stride)
53 glVertexArrayVertexBuffer(
54 m_RendererID, iLayoutIndex, vbo.m_RendererID, 0, iStride * sizeof(float));
55
56 // 4. Link the Attribute Index to that Binding Point
57 glVertexArrayAttribBinding(m_RendererID, iLayoutIndex, iLayoutIndex);
58 }
63 void AttachIndexBuffer(const IndexBuffer &ibo) const {
64 glVertexArrayElementBuffer(m_RendererID, ibo.m_RendererID);
65 }
66};
67} // namespace Renderer
Definition IndexBuffer.h:6
unsigned int m_RendererID
Definition IndexBuffer.h:8
Wrapper for OpenGL VAO (Vertex Array Object). Stores the configuration of vertex attributes (layout) ...
Definition VertexArray.h:13
void LinkAttribute(const VertexBuffer &vbo, unsigned int iLayoutIndex, int iNumComponents, int iStride, int iOffset) const
Configures a vertex attribute layout.
Definition VertexArray.h:34
~VertexArray()
Definition VertexArray.h:18
VertexArray()
Definition VertexArray.h:17
VertexArray(const VertexArray &)=delete
void AttachIndexBuffer(const IndexBuffer &ibo) const
Attaches an IndexBuffer to this VAO using DSA.
Definition VertexArray.h:63
void Unbind() const
Definition VertexArray.h:24
VertexArray & operator=(const VertexArray &)=delete
void Bind() const
Definition VertexArray.h:23
unsigned int m_RendererID
Definition VertexArray.h:15
Wrapper for OpenGL VBO (Vertex Buffer Object). Stores raw vertex data (positions, colors,...
Definition Buffer.h:11
unsigned int m_RendererID
Definition Buffer.h:13
Definition Buffer.h:4