hx3d  1
2D/3D Simple Game Framework
base_geometry.cpp
1 /*
2  Base geometry.
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/geometries/base_geometry.hpp"
22 
23 namespace hx3d {
24 namespace graphics {
25 namespace geom {
26 
27 BaseGeometry::BaseGeometry(): _cullingType(Culling::Disabled) {
28  addAttribute("Position", Attribute("a_position", GL_FLOAT, 3));
29  addAttribute("Color", Attribute("a_color", GL_FLOAT, 4));
30  addAttribute("Texture", Attribute("a_texture", GL_FLOAT, 2));
31  addAttribute("Normal", Attribute("a_normal", GL_FLOAT, 3));
32 }
33 
34 void BaseGeometry::addAttribute(std::string name, Attribute attribute) {
35  _attributes[name].create(attribute);
36 }
37 
38 void BaseGeometry::setAttribute(std::string name, std::vector<float> values) {
39  _attributes[name].set(values);
40 }
41 
42 AttributeArrayBuffer& BaseGeometry::getAttribute(std::string name) {
43  return _attributes[name];
44 }
45 
46 void BaseGeometry::setIndices(std::vector<GLushort> values) {
47  _indices.set(values);
48 }
49 
50 IndexArrayBuffer& BaseGeometry::getIndices() {
51  return _indices;
52 }
53 
54 void BaseGeometry::setFaceCulling(Culling culling) {
55  _cullingType = culling;
56 }
57 
58 void BaseGeometry::uploadAll() {
59  for (auto& a: _attributes) {
60  a.second.upload();
61  }
62 
63  _indices.upload();
64 }
65 
66 } /* geom */
67 } /* graphics */
68 } /* hx3d */
Culling
Face culling type.
hx3d framework namespace
Definition: audio.hpp:26
OpenGL buffer attribute.
Definition: attribute.hpp:35
void set(const std::vector< T > &values)
Set the buffer values.
Definition: buffer.inl.hpp:41
virtual void upload() override
Upload the data to the GPU.