2D_Game_Engine
Loading...
Searching...
No Matches
indexbuffer.cpp
Go to the documentation of this file.
1#include <pch.hpp>
2#include <indexbuffer.hpp>
3
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
14 glDeleteBuffers(1,&m_ID);
15 FreeMemory(m_Indices);
16}
17
18void 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
36void IndexBuffer::Bind() const{
37 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ID);
38}
39
41 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
42}
void Set(unsigned int num_elem)
void Unbind() const
void Bind() const
constexpr unsigned int MAX_INDICES
Max number of indices per draw call.
Definition global.hpp:5
void FreeMemory(void *ptr, std::source_location src=std::source_location::current())
Definition memory.cpp:11
void * AllocateMemory(size_t size, std::source_location src=std::source_location::current())
Definition memory.cpp:3
int i