smk::VertexArray Class Reference

#include <VertexArray.hpp>

An array of smk::Vertex moved to the GPU memory. This represent a set of triangles to be drawn by the GPU. More...

Description

An array of smk::Vertex moved to the GPU memory. This represent a set of triangles to be drawn by the GPU.

This class is movable and copyable. It is refcounted. The GPU data is automatically released when the last smk::VertextArray is deleted.

Definition at line 20 of file VertexArray.hpp.

Public Member Functions

 VertexArray (const std::vector< Vertex2D > &array)
 
 VertexArray (const std::vector< Vertex3D > &array)
 
void Bind () const
 
void UnBind () const
 
 VertexArray (VertexArray &&) noexcept
 
 VertexArray (const VertexArray &)
 
VertexArrayoperator= (VertexArray &&) noexcept
 
VertexArrayoperator= (const VertexArray &)
 
bool operator== (const smk::VertexArray &) const
 
bool operator!= (const smk::VertexArray &) const
 
size_t size () const
 The size of the GPU array. More...
 

Constructor & Destructor Documentation

◆ VertexArray() [1/4]

smk::VertexArray::VertexArray ( const std::vector< Vertex2D > &  array)

Constructor for a vector of 2D vertices.

Parameters
arrayA set of 2D triangles.

Definition at line 76 of file VertexArray.cpp.

76 {
77 size_ = array.size();
78 Allocate(sizeof(Vertex2D), (void*)array.data());
79 Vertex2D::Bind();
80}

◆ VertexArray() [2/4]

smk::VertexArray::VertexArray ( const std::vector< Vertex3D > &  array)

Constructor for a vector of 3D vertices.

Parameters
arrayA set of 3D triangles.

Definition at line 84 of file VertexArray.cpp.

84 {
85 size_ = array.size();
86 Allocate(sizeof(Vertex3D), (void*)array.data());
87 Vertex3D::Bind();
88}

◆ ~VertexArray()

smk::VertexArray::~VertexArray ( )

Definition at line 23 of file VertexArray.cpp.

23 {
24 Release();
25}

◆ VertexArray() [3/4]

smk::VertexArray::VertexArray ( VertexArray &&  other)
noexcept

Definition at line 40 of file VertexArray.cpp.

40 {
41 this->operator=(std::move(other));
42}

◆ VertexArray() [4/4]

smk::VertexArray::VertexArray ( const VertexArray other)

Definition at line 36 of file VertexArray.cpp.

36 {
37 this->operator=(other);
38}

Member Function Documentation

◆ Bind()

void smk::VertexArray::Bind ( ) const

Definition at line 27 of file VertexArray.cpp.

27 {
28 glBindVertexArray(vao_);
29}

◆ operator!=()

bool smk::VertexArray::operator!= ( const smk::VertexArray other) const

Definition at line 100 of file VertexArray.cpp.

100 {
101 return vbo_ != other.vbo_;
102}

◆ operator=() [1/2]

VertexArray & smk::VertexArray::operator= ( const VertexArray other)

Definition at line 44 of file VertexArray.cpp.

44 {
45 if (&other == this) {
46 return *this;
47 }
48 Release();
49 if (!other.vbo_) {
50 return *this;
51 }
52
53 if (!other.ref_count_) {
54 other.ref_count_ = new int(1); // NOLINT
55 }
56
57 vbo_ = other.vbo_;
58 vao_ = other.vao_;
59 ref_count_ = other.ref_count_;
60 size_ = other.size_;
61
62 (*ref_count_)++;
63 return *this;
64}

◆ operator=() [2/2]

VertexArray & smk::VertexArray::operator= ( VertexArray &&  other)
noexcept

Definition at line 66 of file VertexArray.cpp.

66 {
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_);
71 return *this;
72}

◆ operator==()

bool smk::VertexArray::operator== ( const smk::VertexArray other) const

Definition at line 96 of file VertexArray.cpp.

96 {
97 return vbo_ == other.vbo_;
98}

◆ size()

size_t smk::VertexArray::size ( ) const

The size of the GPU array.

Returns
the number of vertices in the GPU array.

Definition at line 92 of file VertexArray.cpp.

92 {
93 return size_;
94}

◆ UnBind()

void smk::VertexArray::UnBind ( ) const

Definition at line 32 of file VertexArray.cpp.

32 {
33 glBindVertexArray(0);
34}

The documentation for this class was generated from the following files: