diff --git a/src/engine/Buffer.cpp b/src/engine/Buffer.cpp index 22c48e2..527a0b0 100644 --- a/src/engine/Buffer.cpp +++ b/src/engine/Buffer.cpp @@ -18,6 +18,10 @@ void Buffer::bind() { glBindBuffer(this->bufferType, this->bufferId); } +void Buffer::unbind() { + glBindBuffer(this->bufferType, 0); +} + void* Buffer::map(GLenum access = GL_READ_WRITE) { if (glMapNamedBuffer) { if (access != GL_READ_ONLY) { diff --git a/src/engine/Buffer.h b/src/engine/Buffer.h index f2d65a4..f685296 100644 --- a/src/engine/Buffer.h +++ b/src/engine/Buffer.h @@ -14,17 +14,22 @@ namespace Engine { GLint size; GLenum dataType = GL_FLOAT; GLsizei stride; + GLenum valuesPerIndex = 3; Buffer(GLenum bufferType); Buffer() : Buffer(GL_ARRAY_BUFFER) {}; virtual ~Buffer(); void bind(); + void unbind(); void pushData(void* data, int size); void* map(GLenum access); bool unmap(); + + GLuint getId() { return bufferId; } + }; } diff --git a/src/engine/VertexArrayObject.cpp b/src/engine/VertexArrayObject.cpp index 042c0d6..30d8f9c 100644 --- a/src/engine/VertexArrayObject.cpp +++ b/src/engine/VertexArrayObject.cpp @@ -20,13 +20,15 @@ void VertexArrayObject::addBuffer(std::shared_ptr& buffer) { if (glEnableVertexArrayAttrib) { glEnableVertexArrayAttrib(this->vaoId, index); + glVertexArrayVertexBuffer(this->vaoId, index, buffer->getId(), 0, buffer->stride); + glVertexArrayAttribFormat(this->vaoId, index, buffer->valuesPerIndex, GL_FLOAT, GL_FALSE, 0); } else { glEnableVertexAttribArray(index); + buffer->bind(); + bind(); + glVertexAttribPointer(index, buffer->valuesPerIndex, buffer->dataType, GL_FALSE, buffer->stride, 0); } - buffer->bind(); - bind(); - glVertexAttribPointer(index, 3, buffer->dataType, GL_FALSE, buffer->stride, 0); this->buffers.push_back(buffer); } diff --git a/src/engine/model/3ds/Model3DS.cpp b/src/engine/model/3ds/Model3DS.cpp index 4c56dbb..ec5d3db 100644 --- a/src/engine/model/3ds/Model3DS.cpp +++ b/src/engine/model/3ds/Model3DS.cpp @@ -9,8 +9,8 @@ using namespace Engine; Model3DS::Model3DS(std::string&& filename) { - this->vertexVBO = std::make_shared(); - this->normalsVBO = std::make_shared(); + this->vertexVBO = std::make_shared(Buffer()); + this->normalsVBO = std::make_shared(Buffer()); this->model = lib3ds_file_load(filename.c_str()); if (!model) { diff --git a/src/main.cpp b/src/main.cpp index 562e6f8..6503f42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ int main(int argc, char** argv) { vbo->pushData(points, 9 * sizeof(float)); vbo->stride = 3 * sizeof(float); + //vao.addBuffer(dragon.vertexVBO); vao.addBuffer(vbo); while (win->loop()) {