#define GLFW_INCLUDE_NONE #include "OpenGLVertexArray.h" #include #include namespace XCEngine { namespace RHI { OpenGLVertexArray::OpenGLVertexArray() : m_vao(0) , m_indexBuffer(0) , m_indexCount(0) , m_vertexBufferCount(0) { } OpenGLVertexArray::~OpenGLVertexArray() { Shutdown(); } bool OpenGLVertexArray::Initialize() { glGenVertexArrays(1, &m_vao); return true; } void OpenGLVertexArray::AddVertexBuffer(unsigned int buffer, const VertexAttribute& attribute) { glBindVertexArray(m_vao); glBindBuffer(GL_ARRAY_BUFFER, buffer); glEnableVertexAttribArray(attribute.index); glVertexAttribPointer(attribute.index, attribute.count, attribute.type, attribute.normalized ? GL_TRUE : GL_FALSE, attribute.stride, (void*)attribute.offset); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); m_vertexBufferCount++; } void OpenGLVertexArray::SetIndexBuffer(unsigned int buffer, unsigned int type) { glBindVertexArray(m_vao); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); glBindVertexArray(0); m_indexBuffer = buffer; } void OpenGLVertexArray::Shutdown() { if (m_vao) { glDeleteVertexArrays(1, &m_vao); m_vao = 0; } } void OpenGLVertexArray::Bind() const { glBindVertexArray(m_vao); } void OpenGLVertexArray::Unbind() const { glBindVertexArray(0); } } // namespace RHI } // namespace XCEngine