hx3d
1
2D/3D Simple Game Framework
Main Page
Namespaces
Classes
Files
File List
engine
src
graphics
mesh.cpp
1
/*
2
Mesh.
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/mesh.hpp"
22
23
#include "hx3d/graphics/texture.hpp"
24
25
namespace
hx3d
{
26
namespace
graphics {
27
28
Mesh::Mesh() {}
29
30
void
Mesh::draw
(
Ptr<Shader>
shader) {
31
32
if
(
_geometry
->getAttribute(
"Texture"
).size() == 0) {
33
Texture::use
(
Texture::Blank
);
34
_geometry
->draw(shader);
35
Texture::disable
();
36
}
37
38
else
{
39
_geometry
->draw(shader);
40
}
41
}
42
43
void
Mesh::setTint
(
Color
tint) {
44
_tint
= tint;
45
46
updateColor
();
47
}
48
49
void
Mesh::setGeometry
(
Ptr<geom::BaseGeometry>
geometry) {
50
_geometry
= geometry;
51
}
52
53
Ptr<geom::BaseGeometry>
&
Mesh::getGeometry
() {
54
return
_geometry
;
55
}
56
57
void
Mesh::updateColor
() {
58
59
glm::vec4 floatColor =
_tint
.
toFloat
();
60
61
AttributeArrayBuffer
& colors =
_geometry
->getAttribute(
"Color"
);
62
float
* colorsData = colors.
data
();
63
if
(colorsData[0] == floatColor.r
64
&& colorsData[1] == floatColor.g
65
&& colorsData[2] == floatColor.b
66
&& colorsData[3] == floatColor.a)
67
return
;
68
69
for
(
unsigned
int
i = 0; i < colors.
size
(); i += 4) {
70
colorsData[i] = floatColor.r;
71
colorsData[i+1] = floatColor.g;
72
colorsData[i+2] = floatColor.b;
73
colorsData[i+3] = floatColor.a;
74
}
75
76
_geometry
->uploadAll();
77
}
78
79
Color
&
Mesh::getTint
() {
80
return
_tint
;
81
}
82
83
}
/* graphics */
84
}
/* hx3d */
hx3d::graphics::Color::toFloat
glm::vec4 toFloat()
Convert the color to a float format (between 0 and 1).
Definition:
color.cpp:42
hx3d::graphics::Mesh::_tint
Color _tint
Tint color.
Definition:
mesh.hpp:94
hx3d::graphics::Mesh::setTint
void setTint(Color tint)
Set the mesh tint.
Definition:
mesh.cpp:43
hx3d::graphics::Mesh::updateColor
void updateColor()
Update the mesh color from the tint.
Definition:
mesh.cpp:57
hx3d::graphics::Mesh::getTint
Color & getTint()
Get the mesh tint.
Definition:
mesh.cpp:79
hx3d::graphics::Color
Four [0..255] components defined color.
Definition:
color.hpp:32
hx3d
hx3d framework namespace
Definition:
audio.hpp:26
hx3d::graphics::buffers::AttributeArrayBuffer
Attribute specialized array buffer.
Definition:
attribute_array_buffer.hpp:34
hx3d::graphics::Mesh::setGeometry
void setGeometry(Ptr< geom::BaseGeometry > geometry)
Set the mesh geometry.
Definition:
mesh.cpp:49
hx3d::graphics::Mesh::_geometry
Ptr< geom::BaseGeometry > _geometry
Current geometry.
Definition:
mesh.hpp:96
hx3d::graphics::Texture::Blank
static Ptr< Texture > Blank
Default blank texture.
Definition:
texture.hpp:92
hx3d::graphics::Mesh::draw
virtual void draw(Ptr< Shader > shader)
Draw the mesh using a shader.
Definition:
mesh.cpp:30
hx3d::graphics::Mesh::getGeometry
Ptr< geom::BaseGeometry > & getGeometry()
Get the mesh geometry.
Definition:
mesh.cpp:53
hx3d::graphics::Texture::disable
static void disable()
Clear the current texture for drawing.
Definition:
texture.cpp:136
hx3d::graphics::Texture::use
static void use(Ptr< Texture > texture)
Use the current texture for drawing.
Definition:
texture.cpp:127
hx3d::graphics::buffers::Buffer::data
T * data()
Get the buffer values.
Definition:
buffer.inl.hpp:57
hx3d::graphics::buffers::Buffer::size
unsigned int size()
Get the buffer size.
Definition:
buffer.inl.hpp:62
hx3d::Ptr
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition:
ptr.hpp:34
Generated by
1.8.11