hx3d  1
2D/3D Simple Game Framework
index_array_buffer.cpp
1 /*
2  Index array buffer.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #include "hx3d/graphics/buffers/index_array_buffer.hpp"
22 
23 namespace hx3d {
24 namespace graphics {
25 namespace buffers {
26 
28  ArrayBuffer<GLushort>()
29 {}
30 
31 IndexArrayBuffer::IndexArrayBuffer(const std::vector<GLushort> values):
32  ArrayBuffer<GLushort>()
33 {
34  set(values);
35 }
36 
37 IndexArrayBuffer::~IndexArrayBuffer()
38 {}
39 
41  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buf);
42  glBufferData(GL_ELEMENT_ARRAY_BUFFER, _vector.size() * sizeof(GLushort), _vector.data(), GL_STATIC_DRAW);
43 
44  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
45 }
46 
47 void IndexArrayBuffer::begin(const Ptr<Shader>& shader) {
48  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buf);
49  glDrawElements(GL_TRIANGLES, _vector.size(), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
50 
51  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
52 }
53 
55 {}
56 
57 } /* buffers */
58 } /* graphics */
59 } /* hx3d */
std::vector< GLushort > _vector
Data.
Definition: buffer.hpp:114
hx3d framework namespace
Definition: audio.hpp:26
virtual void begin(const Ptr< Shader > &shader) override
Begin the use with a shader.
virtual void upload() override
Upload the data to the GPU.
IndexArrayBuffer()
Build an empty index buffer.
virtual void end(const Ptr< Shader > &shader) override
End the use with a shader.
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
OpenGL GPU uploadable buffer.