5#include <smk/VertexArray.hpp>
9VertexArray::VertexArray() =
default;
11void VertexArray::Allocate(
int element_size,
void* data) {
12 glGenVertexArrays(1, &vao_);
13 glBindVertexArray(vao_);
15 glGenBuffers(1, &vbo_);
16 glBindBuffer(GL_ARRAY_BUFFER, vbo_);
18 glBufferData(GL_ARRAY_BUFFER, GLsizeiptr(size_ * element_size), data,
20 glEnableVertexAttribArray(0);
23VertexArray::~VertexArray() {
27void VertexArray::Bind()
const {
28 glBindVertexArray(vao_);
32void VertexArray::UnBind()
const {
36VertexArray::VertexArray(
const VertexArray& other) {
37 this->operator=(other);
40VertexArray::VertexArray(VertexArray&& other)
noexcept {
41 this->operator=(std::move(other));
44VertexArray& VertexArray::operator=(
const VertexArray& other) {
53 if (!other.ref_count_) {
54 other.ref_count_ =
new int(1);
59 ref_count_ = other.ref_count_;
66VertexArray& VertexArray::operator=(VertexArray&& other)
noexcept {
67 std::swap(vbo_, other.vbo_);
68 std::swap(vao_, other.vao_);
69 std::swap(size_, other.size_);
70 std::swap(ref_count_, other.ref_count_);
76VertexArray::VertexArray(
const std::vector<Vertex2D>& array) {
78 Allocate(
sizeof(
Vertex2D), (
void*)array.data());
84VertexArray::VertexArray(
const std::vector<Vertex3D>& array) {
86 Allocate(
sizeof(
Vertex3D), (
void*)array.data());
97 return vbo_ == other.vbo_;
101 return vbo_ != other.vbo_;
104void VertexArray::Release() {
113 int* ref_count =
nullptr;
114 std::swap(vbo, vbo_);
115 std::swap(vao, vao_);
116 std::swap(ref_count, ref_count_);
130 glDeleteBuffers(1, &vbo);
131 glDeleteVertexArrays(1, &vao);
An array of smk::Vertex moved to the GPU memory. This represent a set of triangles to be drawn by the...
size_t size() const
The size of the GPU array.
The vertex structure suitable for a 2D shader.
The vertex structure suitable for a 2D shader.