]> git.tdb.fi Git - libs/gl.git/blob - source/geometrybuilder.cpp
Add support for cube map textures
[libs/gl.git] / source / geometrybuilder.cpp
1 #include "geometrybuilder.h"
2 #include "meshbuilder.h"
3
4 namespace Msp {
5 namespace GL {
6
7 GeometryBuilder::GeometryBuilder():
8         tangent_attr(-1),
9         binormal_attr(-1),
10         tex_fit(STRETCH)
11 { }
12
13 GeometryBuilder &GeometryBuilder::tangent(unsigned t)
14 {
15         tangent_attr = t;
16         return *this;
17 }
18
19 GeometryBuilder &GeometryBuilder::binormal(unsigned b)
20 {
21         binormal_attr = b;
22         return *this;
23 }
24
25 GeometryBuilder &GeometryBuilder::texture_fit(TextureFit tf)
26 {
27         tex_fit = tf;
28         return *this;
29 }
30
31 void GeometryBuilder::adjust_texture_scale(float &u_scale, float &v_scale, float width, float height) const
32 {
33         if(tex_fit!=STRETCH)
34         {
35                 if((width<height)==(tex_fit==CROP))
36                         u_scale *= width/height;
37                 else
38                         v_scale *= height/width;
39         }
40 }
41
42 void GeometryBuilder::build(Mesh &mesh) const
43 {
44         MeshBuilder builder(mesh);
45         builder.auto_offset();
46         build(builder);
47 }
48
49 } // namespace GL
50 } // namespace Msp