- Simplify OpenGL integration test structure - Enable CTest registration for OpenGL tests - Refactor test fixtures and device enumeration - Minor code cleanup and improvements
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#include "XCEngine/RHI/OpenGL/OpenGLVertexArray.h"
|
|
#include <glad/glad.h>
|
|
|
|
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
|