2D_Game_Engine
Loading...
Searching...
No Matches
src
indexbuffer.cpp
Go to the documentation of this file.
1
#include <pch.hpp>
2
#include <
indexbuffer.hpp
>
3
4
IndexBuffer::IndexBuffer
(){
5
m_Indices=(
unsigned
int
*)
AllocateMemory
(
MAX_INDICES
*
sizeof
(
unsigned
int
));
6
7
glGenBuffers(1,&m_ID);
8
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ID);
9
10
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
MAX_INDICES
*
sizeof
(GLuint),
nullptr
,GL_DYNAMIC_DRAW);
11
}
12
13
IndexBuffer::~IndexBuffer
(){
14
glDeleteBuffers(1,&m_ID);
15
FreeMemory
(m_Indices);
16
}
17
18
void
IndexBuffer::Set
(
unsigned
int
num_elem){
19
Bind
();
20
m_NumElem=num_elem/4*6;
21
unsigned
int
offset=0;
22
for
(
unsigned
int
i
=0;
i
<m_NumElem;
i
+=6){
23
m_Indices[
i
+0]=offset;
24
m_Indices[
i
+1]=1+offset;
25
m_Indices[
i
+2]=2+offset;
26
27
m_Indices[
i
+3]=2+offset;
28
m_Indices[
i
+4]=3+offset;
29
m_Indices[
i
+5]=offset;
30
31
offset+=4;
32
}
33
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,m_NumElem*
sizeof
(GLuint),(
const
void
*)m_Indices);
34
}
35
36
void
IndexBuffer::Bind
()
const
{
37
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ID);
38
}
39
40
void
IndexBuffer::Unbind
()
const
{
41
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
42
}
IndexBuffer::~IndexBuffer
~IndexBuffer()
Definition
indexbuffer.cpp:13
IndexBuffer::Set
void Set(unsigned int num_elem)
Definition
indexbuffer.cpp:18
IndexBuffer::Unbind
void Unbind() const
Definition
indexbuffer.cpp:40
IndexBuffer::IndexBuffer
IndexBuffer()
Definition
indexbuffer.cpp:4
IndexBuffer::Bind
void Bind() const
Definition
indexbuffer.cpp:36
MAX_INDICES
constexpr unsigned int MAX_INDICES
Max number of indices per draw call.
Definition
global.hpp:5
indexbuffer.hpp
FreeMemory
void FreeMemory(void *ptr, std::source_location src=std::source_location::current())
Definition
memory.cpp:11
AllocateMemory
void * AllocateMemory(size_t size, std::source_location src=std::source_location::current())
Definition
memory.cpp:3
i
int i
Definition
sceneserializer.cpp:451
Generated by
1.10.0