Add OpenGL array class

This commit is contained in:
Nikita Lisitsa 2020-10-04 12:23:01 +03:00
parent 6709792abf
commit b0ecc6c056
2 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,34 @@
#pragma once
#include <psemek/gfx/gl.hpp>
#include <cstddef>
namespace psemek::gfx
{
struct array
{
array();
array(array &&);
array & operator = (array &&);
~array();
array(array const &) = delete;
array & operator = (array const &) = delete;
static array null();
GLuint id() const { return id_; }
void bind() const;
void reset();
private:
GLuint id_;
explicit array(std::nullptr_t);
};
}

54
libs/gfx/source/array.cpp Normal file
View file

@ -0,0 +1,54 @@
#include <psemek/gfx/array.hpp>
#include <utility>
namespace psemek::gfx
{
array::array()
{
gl::GenVertexArrays(1, &id_);
}
array::array(array && other)
: id_{other.id_}
{
other.id_ = 0;
}
array & array::operator = (array && other)
{
if (this == &other) return *this;
reset();
std::swap(id_, other.id_);
return *this;
}
array::~array()
{
reset();
}
array array::null()
{
return array(nullptr);
}
void array::bind() const
{
gl::BindVertexArray(id_);
}
void array::reset()
{
if (id_ != 0)
gl::DeleteVertexArrays(1, &id_);
id_ = 0;
}
array::array(std::nullptr_t)
: id_{0}
{}
}