Move OpenGL backend classes from tests/OpenGL to engine/
- Relocated OpenGLDevice, OpenGLShader, OpenGLBuffer, OpenGLVertexArray, OpenGLTexture to engine/ - Updated engine/CMakeLists.txt to include OpenGL backend source files - Updated tests/OpenGL/CMakeLists.txt to use engine backend - Added OpenGLTexture class implementation
This commit is contained in:
60
engine/src/RHI/OpenGL/OpenGLVertexArray.cpp
Normal file
60
engine/src/RHI/OpenGL/OpenGLVertexArray.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLVertexArray.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.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
|
||||
Reference in New Issue
Block a user