diff --git a/include/render/Renderer.h b/include/render/Renderer.h index 36b26ff..5e85437 100644 --- a/include/render/Renderer.h +++ b/include/render/Renderer.h @@ -22,7 +22,7 @@ public: static constexpr float m_AnimationSpeed = 2.0f; struct Model { - GL::VAO* vao; + GL::VertexArray* vao; glm::vec2 positon; }; private: @@ -41,7 +41,7 @@ public: void prepare(); void resize(const int width, const int height); - void renderVAO(const GL::VAO& vao); + void renderVAO(const GL::VertexArray& vao); void renderModel(const Model& model); void setZoom(float zoom); diff --git a/include/render/loader/GLLoader.h b/include/render/loader/GLLoader.h index 775355c..c7bdde2 100644 --- a/include/render/loader/GLLoader.h +++ b/include/render/loader/GLLoader.h @@ -21,44 +21,44 @@ struct VertexAttribPointer{ int m_Offset; }; -class VBO{ +class VertexBuffer{ private: unsigned int m_ID, m_DataStride; std::vector m_VertexAttribs; public: - REMOVE_COPY(VBO); - VBO(VBO&& other){ + REMOVE_COPY(VertexBuffer); + VertexBuffer(VertexBuffer&& other){ m_VertexAttribs = std::move(other.m_VertexAttribs); m_ID = other.m_ID; m_DataStride = other.m_DataStride; other.m_ID = 0; other.m_DataStride = 0; } - VBO(const std::vector& data, unsigned int stride); - ~VBO(); + VertexBuffer(const std::vector& data, unsigned int stride); + ~VertexBuffer(); void bind() const; void unbind() const; void addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset); void bindVertexAttribs() const; }; -class VAO{ +class VertexArray{ private: unsigned int m_ID, m_VertexCount; - std::vector m_Vbos; //use to destroy vbos when become unused + std::vector m_VertexBuffers; //use to destroy vbos when become unused public: - REMOVE_COPY(VAO); - VAO(VAO&& other){ + REMOVE_COPY(VertexArray); + VertexArray(VertexArray&& other){ m_ID = other.m_ID; m_VertexCount = other.m_VertexCount; - m_Vbos = std::move(other.m_Vbos); + m_VertexBuffers = std::move(other.m_VertexBuffers); other.m_VertexCount = 0; other.m_ID = 0; } - VAO(unsigned int vertexCount); - ~VAO(); + VertexArray(unsigned int vertexCount); + ~VertexArray(); unsigned int getVertexCount() const {return m_VertexCount;} - void bindVBO(VBO& vbo); + void bindVertexBuffer(VertexBuffer& vbo); void bind() const; void unbind() const; }; diff --git a/include/render/loader/WorldLoader.h b/include/render/loader/WorldLoader.h index 34b4fb1..59ed145 100644 --- a/include/render/loader/WorldLoader.h +++ b/include/render/loader/WorldLoader.h @@ -8,9 +8,9 @@ namespace render { namespace WorldLoader { -GL::VAO loadMobModel(); -GL::VAO loadWorldModel(const td::game::World* world); -GL::VAO loadTileSelectModel(); +GL::VertexArray loadMobModel(); +GL::VertexArray loadWorldModel(const td::game::World* world); +GL::VertexArray loadTileSelectModel(); } // namespace WorldLoader diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 21c21bb..4bf91fb 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -51,7 +51,7 @@ bool Renderer::init(){ return true; } -void Renderer::renderVAO(const GL::VAO& vao){ +void Renderer::renderVAO(const GL::VertexArray& vao){ m_WorldShader->start(); vao.bind(); glDrawArrays(GL_TRIANGLES, 0, vao.getVertexCount()); diff --git a/src/render/WorldRenderer.cpp b/src/render/WorldRenderer.cpp index f743dbe..4242edd 100644 --- a/src/render/WorldRenderer.cpp +++ b/src/render/WorldRenderer.cpp @@ -11,9 +11,9 @@ namespace render { void WorldRenderer::loadModels(){ std::cout << "World Created !\n"; - m_WorldVao = std::make_unique(std::move(WorldLoader::loadWorldModel(m_World))); - m_MobVao = std::make_unique(std::move(WorldLoader::loadMobModel())); - m_SelectTileVao = std::make_unique(std::move(WorldLoader::loadTileSelectModel())); + m_WorldVao = std::make_unique(std::move(WorldLoader::loadWorldModel(m_World))); + m_MobVao = std::make_unique(std::move(WorldLoader::loadMobModel())); + m_SelectTileVao = std::make_unique(std::move(WorldLoader::loadTileSelectModel())); std::cout << "Vertex Count : " << m_WorldVao->getVertexCount() << std::endl; } diff --git a/src/render/loader/GLLoader.cpp b/src/render/loader/GLLoader.cpp index 4c8d14d..867b63f 100644 --- a/src/render/loader/GLLoader.cpp +++ b/src/render/loader/GLLoader.cpp @@ -13,35 +13,35 @@ using namespace gl; namespace GL{ - VAO::~VAO(){ + VertexArray::~VertexArray(){ if(m_ID != 0) glDeleteVertexArrays(1, &m_ID); } - VAO::VAO(unsigned int vertexCount) : m_VertexCount(vertexCount){ + VertexArray::VertexArray(unsigned int vertexCount) : m_VertexCount(vertexCount){ glGenVertexArrays(1, &m_ID); } - void VAO::bind() const{ + void VertexArray::bind() const{ glBindVertexArray(m_ID); } - void VAO::unbind() const{ + void VertexArray::unbind() const{ glBindVertexArray(0); } - void VAO::bindVBO(VBO& vbo){ - vbo.bind(); - vbo.bindVertexAttribs(); - m_Vbos.push_back(std::move(vbo)); + void VertexArray::bindVertexBuffer(VertexBuffer& VertexBuffer){ + VertexBuffer.bind(); + VertexBuffer.bindVertexAttribs(); + m_VertexBuffers.push_back(std::move(VertexBuffer)); } - VBO::~VBO(){ + VertexBuffer::~VertexBuffer(){ if(m_ID != 0) glDeleteBuffers(1, &m_ID); } - VBO::VBO(const std::vector& data, unsigned int stride) : m_DataStride(stride){ + VertexBuffer::VertexBuffer(const std::vector& data, unsigned int stride) : m_DataStride(stride){ glGenBuffers(1, &m_ID); bind(); glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), nullptr, GL_STATIC_DRAW); @@ -49,15 +49,15 @@ namespace GL{ unbind(); } - void VBO::bind() const{ + void VertexBuffer::bind() const{ glBindBuffer(GL_ARRAY_BUFFER, m_ID); } - void VBO::unbind() const{ + void VertexBuffer::unbind() const{ glBindBuffer(GL_ARRAY_BUFFER, 0); } - void VBO::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset){ + void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset){ VertexAttribPointer pointer; pointer.m_Index = index; pointer.m_Size = coordinateSize; @@ -65,7 +65,7 @@ namespace GL{ m_VertexAttribs.push_back(pointer); } - void VBO::bindVertexAttribs() const{ + void VertexBuffer::bindVertexAttribs() const{ for(const VertexAttribPointer& pointer : m_VertexAttribs){ glEnableVertexAttribArray(pointer.m_Index); glVertexAttribPointer(pointer.m_Index, pointer.m_Size, GL_FLOAT, false, m_DataStride * sizeof(float), (void*)(intptr_t) pointer.m_Offset); diff --git a/src/render/loader/WorldLoader.cpp b/src/render/loader/WorldLoader.cpp index d24b983..52cbb39 100644 --- a/src/render/loader/WorldLoader.cpp +++ b/src/render/loader/WorldLoader.cpp @@ -10,7 +10,7 @@ namespace render { namespace WorldLoader { -GL::VAO loadMobModel(){ +GL::VertexArray loadMobModel(){ std::vector positions = { -0.5, -0.5, 0.5, -0.5, @@ -35,20 +35,20 @@ GL::VAO loadMobModel(){ yellowFloat }; - GL::VBO positionVBO(positions, 2); + GL::VertexBuffer positionVBO(positions, 2); positionVBO.addVertexAttribPointer(0, 2, 0); - GL::VBO colorVBO(colors, 1); + GL::VertexBuffer colorVBO(colors, 1); colorVBO.addVertexAttribPointer(1, 1, 0); - GL::VAO mobVao(colors.size()); // each pos = 1 color + GL::VertexArray mobVao(colors.size()); // each pos = 1 color mobVao.bind(); - mobVao.bindVBO(positionVBO); - mobVao.bindVBO(colorVBO); + mobVao.bindVertexBuffer(positionVBO); + mobVao.bindVertexBuffer(colorVBO); mobVao.unbind(); return mobVao; } -GL::VAO loadWorldModel(const td::game::World* world){ +GL::VertexArray loadWorldModel(const td::game::World* world){ std::vector positions; std::vector colors; @@ -143,20 +143,20 @@ GL::VAO loadWorldModel(const td::game::World* world){ } } - GL::VBO positionVBO(positions, 2); + GL::VertexBuffer positionVBO(positions, 2); positionVBO.addVertexAttribPointer(0, 2, 0); - GL::VBO colorVBO(colors, 1); + GL::VertexBuffer colorVBO(colors, 1); colorVBO.addVertexAttribPointer(1, 1, 0); - GL::VAO worldVao(positions.size() / 2); // each pos = 2 vertecies + GL::VertexArray worldVao(positions.size() / 2); // each pos = 2 vertecies worldVao.bind(); - worldVao.bindVBO(positionVBO); - worldVao.bindVBO(colorVBO); + worldVao.bindVertexBuffer(positionVBO); + worldVao.bindVertexBuffer(colorVBO); worldVao.unbind(); return worldVao; } -GL::VAO loadTileSelectModel(){ +GL::VertexArray loadTileSelectModel(){ std::vector positions = { 0, 0, 1, 0, @@ -174,15 +174,15 @@ GL::VAO loadTileSelectModel(){ std::vector colors(6, colorFloat); - GL::VBO positionVBO(positions, 2); + GL::VertexBuffer positionVBO(positions, 2); positionVBO.addVertexAttribPointer(0, 2, 0); - GL::VBO colorVBO(colors, 1); + GL::VertexBuffer colorVBO(colors, 1); colorVBO.addVertexAttribPointer(1, 1, 0); - GL::VAO tileSelectVao(positions.size() / 2); // each pos = 2 vertecies + GL::VertexArray tileSelectVao(positions.size() / 2); // each pos = 2 vertecies tileSelectVao.bind(); - tileSelectVao.bindVBO(positionVBO); - tileSelectVao.bindVBO(colorVBO); + tileSelectVao.bindVertexBuffer(positionVBO); + tileSelectVao.bindVertexBuffer(colorVBO); tileSelectVao.unbind(); return tileSelectVao;