mirror of
https://github.com/guezoloic/LearnOpenGL.git
synced 2026-01-25 04:34:14 +00:00
feat: rework ebo, vao and vbo
This commit is contained in:
12
src/ebo.cpp
12
src/ebo.cpp
@@ -1,14 +1,16 @@
|
||||
#include "ebo.hpp"
|
||||
|
||||
EBO::EBO(unsigned int* indices, size_t size)
|
||||
EBO::EBO() : id(0) {}
|
||||
|
||||
void EBO::setData(unsigned int* indices, size_t size)
|
||||
{
|
||||
glGenBuffers(1, &id);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
if (this->id == 0) glGenBuffers(1, &this->id);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->id);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
EBO::~EBO() { glDeleteBuffers(1, &id); }
|
||||
EBO::~EBO() { glDeleteBuffers(1, &this->id); }
|
||||
|
||||
void EBO::bind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); }
|
||||
void EBO::bind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->id); }
|
||||
|
||||
void EBO::unbind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
|
||||
@@ -11,7 +11,6 @@ void VAO::unbind() { glBindVertexArray(0); }
|
||||
void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type,
|
||||
GLsizei stride, const void* offset)
|
||||
{
|
||||
bind();
|
||||
glEnableVertexAttribArray(index);
|
||||
glVertexAttribPointer(index, size, type, GL_FALSE, stride, offset);
|
||||
}
|
||||
@@ -19,12 +18,10 @@ void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type,
|
||||
void VAO::drawElement(GLenum mode, GLsizei count, GLenum type,
|
||||
const void* indices)
|
||||
{
|
||||
bind();
|
||||
glDrawElements(mode, count, type, indices);
|
||||
}
|
||||
|
||||
void VAO::drawArray(GLenum mode, GLint first, GLsizei count)
|
||||
{
|
||||
bind();
|
||||
glDrawArrays(mode, first, count);
|
||||
}
|
||||
12
src/vbo.cpp
12
src/vbo.cpp
@@ -1,14 +1,16 @@
|
||||
#include "vbo.hpp"
|
||||
|
||||
VBO::VBO(GLfloat* vertices, size_t size)
|
||||
VBO::VBO() : id(0) {}
|
||||
|
||||
void VBO::setData(GLfloat* vertices, size_t size)
|
||||
{
|
||||
glGenBuffers(1, &id);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
if (this->id == 0) glGenBuffers(1, &this->id);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->id);
|
||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
VBO::~VBO() { glDeleteBuffers(1, &id); }
|
||||
VBO::~VBO() { glDeleteBuffers(1, &this->id); }
|
||||
|
||||
void VBO::bind() { glBindBuffer(GL_ARRAY_BUFFER, id); }
|
||||
void VBO::bind() { glBindBuffer(GL_ARRAY_BUFFER, this->id); }
|
||||
|
||||
void VBO::unbind() { glBindBuffer(GL_ARRAY_BUFFER, 0); }
|
||||
Reference in New Issue
Block a user