RunicVTT
Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
VertexArray.cpp
Go to the documentation of this file.
1
#pragma once
2
#include "
VertexArray.h
"
3
#include "
Renderer.h
"
4
#include "
VertexBufferLayout.h
"
5
6
VertexArray::VertexArray
()
7
{
8
GLCall
(glGenVertexArrays(1, &
m_RendererID
));
9
}
10
11
VertexArray::~VertexArray
()
12
{
13
GLCall
(glDeleteVertexArrays(1, &
m_RendererID
));
14
}
15
16
void
VertexArray::AddBuffer
(
const
VertexBuffer
& vb,
const
VertexBufferLayout
& layout)
17
{
18
Bind
();
19
vb.Bind();
20
const
auto
& elements = layout.GetElements();
21
unsigned
int
offset = 0;
22
for
(
unsigned
int
i = 0; i < elements.size(); i++)
23
{
24
const
auto
& element = elements[i];
25
GLCall
(glEnableVertexAttribArray(i));
26
GLCall
(glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (
const
void
*)offset));
27
offset += element.count *
VertexBufferElement::GetSizeOfType
(element.type);
28
}
29
}
30
31
void
VertexArray::Bind
()
const
32
{
33
GLCall
(glBindVertexArray(
m_RendererID
));
34
}
35
36
void
VertexArray::Unbind
()
const
37
{
38
GLCall
(glBindVertexArray(0));
39
}
Renderer.h
GLCall
#define GLCall(x)
Definition
Renderer.h:12
VertexArray.h
VertexBufferLayout.h
VertexArray::Unbind
void Unbind() const
Definition
VertexArray.cpp:36
VertexArray::~VertexArray
~VertexArray()
Definition
VertexArray.cpp:11
VertexArray::m_RendererID
unsigned int m_RendererID
Definition
VertexArray.h:9
VertexArray::AddBuffer
void AddBuffer(const VertexBuffer &vb, const VertexBufferLayout &layout)
Definition
VertexArray.cpp:16
VertexArray::VertexArray
VertexArray()
Definition
VertexArray.cpp:6
VertexArray::Bind
void Bind() const
Definition
VertexArray.cpp:31
VertexBufferLayout
Definition
VertexBufferLayout.h:31
VertexBuffer
Definition
VertexBuffer.h:4
VertexBufferElement::GetSizeOfType
static unsigned int GetSizeOfType(unsigned int type)
Definition
VertexBufferLayout.h:14
src
renderer
VertexArray.cpp
Generated by
1.10.0