feat: render per-vertex color triangle
- Add shader class for vertex/fragment program compilation - Add vao class for vertex array object management - Render RGB gradient triangle with interpolated vertex colors
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#include "cbt/opengl/vao.hpp"
|
||||
|
||||
namespace cbt::opengl {
|
||||
|
||||
vao::vao() {
|
||||
glGenVertexArrays(1, &m_id);
|
||||
}
|
||||
|
||||
vao::~vao() {
|
||||
if (m_id) {
|
||||
glDeleteVertexArrays(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
vao::vao(vao&& other) noexcept
|
||||
: m_id(other.m_id) {
|
||||
other.m_id = 0;
|
||||
}
|
||||
|
||||
vao& vao::operator=(vao&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (m_id) {
|
||||
glDeleteVertexArrays(1, &m_id);
|
||||
}
|
||||
m_id = other.m_id;
|
||||
other.m_id = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto vao::bind() const -> void {
|
||||
glBindVertexArray(m_id);
|
||||
}
|
||||
|
||||
auto vao::unbind() const -> void {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
auto vao::id() const -> GLuint {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
auto vao::valid() const -> bool {
|
||||
return m_id != 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user